Presentation is loading. Please wait.

Presentation is loading. Please wait.

HUJI Post PC Workshop 1 Introduction to Android Development Ari Sprung

Similar presentations


Presentation on theme: "HUJI Post PC Workshop 1 Introduction to Android Development Ari Sprung"— Presentation transcript:

1 HUJI Post PC Workshop 1 Introduction to Android Development Ari Sprung

2 Workshops Structure Workshop 1 – Introduction
Setting up, basic app, views, layouts Workshop 2 – Adapters and Menus Resources, adapter views, menus, unit testing Workshop 3 – Activities Multiple activities, dialogs, intents Workshop 4 – Persistence SQLite, cursors, backend-as-a-service Workshop 5 – Threading Files, threads, web services

3 Prerequisites and Homework
What you need to know: Java programming, collections, files, etc. Database basics, tables, SQL Homework will involve: Application development Activity testing Using source control

4 Make Sure You’re OK With This:
Thread t = new Thread(new Runnable() { public void run() { Connection c = DriverManager.getConnection(...); Statement s = c.createStatement(); ResultSet r = s.executeQuery( “SELECT name, AVERAGE(grade) avg “ “FROM students GROUP BY grade “ “ORDER BY avg DESC”); while (r.next()) { ... } } }); t.start();

5 Before We Begin… You can’t learn from the slides. The slides are a learning aid, and they will not contain all the information discussed in class. You still have to come to class and use additional reading to fill the gaps.

6 Android Architecture

7 Versions and API Levels
Considerable fragmentation API levels correspond to each version

8 Setting Up Dev Environment
Download the Android Studio for your OS Contains Eclipse and Android SDK Use SDK Manager to download multiple versions of Android Use AVD Manager to create emulator images for various versions(not recommend). Genny Motion

9 Demonstration: Dev Tools
Studio SDK Manager Gradle Emulator

10 Hello World App Components
src – your package’s sources gen – code generated by the compiler Do not touch this res – resources: images, strings, layouts res/layout/main.xml – your main UI AndroidManifest.xml – app description bin – binary products, including your apk

11 Application Components
Activity Screen, form – usually full-screen, one at a time Activity subclass View Anything that appears on the screen: button, edit box (EditText), label (TextView) Layout A component that manages a bunch of views and decides how to position and draw them

12 Code-Layout Separation
Your view lives in XML files (layouts) Your code lives in Java files Your view communicates with your code through listeners Your code communicates with your view through object references <Button android:text=“Click me” /> final Button b = (Button) findViewById(R.id.btn1); b.setOnClickListener( new OnClickListener() { public void onClick(View v) { b.setText(“Thanks!”); } });

13 Basic Views Explore the standard Android views and how they are declared in XML <Button android:text=“Button” /> <EditText android:hint=“phone” /> <CheckBox android:checked=“true” />

14 Basic Layouts LinearLayout stacks elements horizontally/vertically (orientation) It’s often very useful to nest layouts <LinearLayout android:orientation=“horizontal”> <ImageView android:layout_weight=“1” android:layout_height=“fill_parent” ... /> <TextView android:layout_weight=“2” <WebView ... /> </LinearLayout>

15 Basic Layouts RelativeLayout allows relative positioning of child elements <RelativeLayout> <ImageView android:layout_width=“fill_parent” ... /> <TextView android:layout_alignParentLeft=“true” <Button ... /> </RelativeLayout>

16 Demonstration: UI Events
Your activity class’ onCreate method creates the UI from an XML file Then, retrieve views and use listeners public class MyActivity extends Activity { @Override public void onCreate(Bundle unused) { super.onCreate(unused); setContentView(R.layout.main); EditText ed = (EditText)findViewById(R.id.ed); ed.setOnTextChangeListener(...); Button btn = (Button)findViewById(R.id.btn); btn.setTextSize(14.0f); }

17 Demonstration: Source Control
Source control: management of changes to source code Logical branching and versioning Development history, rollback Change tracking You will be using GitHub for your homework assignments and final projects Go to create an account For each homework, associate your username with the GitHub repository

18 Homework 1 Tip (12%) Calculator Fill submission form
12:38 Tip (12%) Calculator Package: il.ac.huji.tipcalculator Repo tag: v1 Activity: TipCalculatorActivity Fill submission form Pay attention to view ids: edtBillAmount chkRound btnCalculate txtTipResult 42.20 Bill Amount Round to nearest dollar Calculate Tip: $5 When rounding to nearest dollar, do not print decimal separator and any trailing digits. When not rounding to nearest dollar, ALWAYS print decimal separator and two trailing digits, e.g.: $6.00, $6.12

19 Additional Resources Tools workflow App fundamentals Layouts
App fundamentals Layouts Handling input events Stack Overflow


Download ppt "HUJI Post PC Workshop 1 Introduction to Android Development Ari Sprung"

Similar presentations


Ads by Google