Android Development GeekCamp Singapore 22 nd  August 2009 Leong Hean Hong (CC) BY-SA Some rights preserved.
About <ul><li>Usernames: hongster, ahhong
DOB: 490204800 (GMT +8)
Work: LAMP | Android | iPhone
Interest: Python, Rubik Cube, Number Theory, Web Technologies
Groups: SG PHP User Group, KL Google Technology User Group </li></ul>
Content <ul><li>Intro
Development Tools
Setup
4 Component Types
Views
Intents
Demo </li></ul>
Intro <ul><li>Android  !=  OS “ Android™ delivers a complete set of software for mobile devices: an operating system, midd...
Android Architecture ( http://bit.ly/s73P2 )
Dalvik_VM  !=  JVM </li><ul><li>Designed and written by Dan Bornstein with contributions from other Google engineers
Bytecode on which it operates is not Java bytecode. </li></ul></ul>
Development Tools <ul><li>Android 1.5 SDK
Optional, recommended </li><ul><li>Eclipse  (Java or RCP version recommended)
Android Development Tools ( ADT ) eclipse plugin (http s ://dl-ssl.google.com/android/eclipse/) </li></ul></ul>
Setup <ul><li>Download and unzip Android SDK.
Install Eclipse.
Install ADT.
Set SDK path in Eclipse preference section.
Create Android Virtual Device ( AVD ).
Upcoming SlideShare
Loading in …5
×

Geekcamp Android

3,920 views
3,835 views

Published on

Introduction to Android. These slides are presented at Geekcamp Singapore, on 22th August at Yahoo! office.

Published in: Education, Technology, Sports
2 Comments
1 Like
Statistics
Notes
No Downloads
Views
Total views
3,920
On SlideShare
0
From Embeds
0
Number of Embeds
96
Actions
Shares
0
Downloads
208
Comments
2
Likes
1
Embeds 0
No embeds

No notes for slide

Geekcamp Android

  1. 1. Android Development GeekCamp Singapore 22 nd August 2009 Leong Hean Hong (CC) BY-SA Some rights preserved.
  2. 2. About <ul><li>Usernames: hongster, ahhong
  3. 3. DOB: 490204800 (GMT +8)
  4. 4. Work: LAMP | Android | iPhone
  5. 5. Interest: Python, Rubik Cube, Number Theory, Web Technologies
  6. 6. Groups: SG PHP User Group, KL Google Technology User Group </li></ul>
  7. 7. Content <ul><li>Intro
  8. 8. Development Tools
  9. 9. Setup
  10. 10. 4 Component Types
  11. 11. Views
  12. 12. Intents
  13. 13. Demo </li></ul>
  14. 14. Intro <ul><li>Android != OS “ Android™ delivers a complete set of software for mobile devices: an operating system, middleware and key mobile applications. ”
  15. 15. Android Architecture ( http://bit.ly/s73P2 )
  16. 16. Dalvik_VM != JVM </li><ul><li>Designed and written by Dan Bornstein with contributions from other Google engineers
  17. 17. Bytecode on which it operates is not Java bytecode. </li></ul></ul>
  18. 18. Development Tools <ul><li>Android 1.5 SDK
  19. 19. Optional, recommended </li><ul><li>Eclipse (Java or RCP version recommended)
  20. 20. Android Development Tools ( ADT ) eclipse plugin (http s ://dl-ssl.google.com/android/eclipse/) </li></ul></ul>
  21. 21. Setup <ul><li>Download and unzip Android SDK.
  22. 22. Install Eclipse.
  23. 23. Install ADT.
  24. 24. Set SDK path in Eclipse preference section.
  25. 25. Create Android Virtual Device ( AVD ).
  26. 26. RTFM and start coding.
  27. 27. Reference: http://bit.ly/3T24gE </li></ul>
  28. 28. Linux Tips <ul><li>Don’t use package manger, download Eclipse and unzip it.
  29. 29. Use Sun Java ( “requires plug-in org.eclipse.wst.sse.ui” error )
  30. 30. If installed Eclipse using root , update using root .
  31. 31. Run <android-sdk>/tools/ddms once, before installing ADT. (solved in ADT 0.9.1 http://bit.ly/15FdZt ) </li></ul>
  32. 32. Application Components <ul><li>Activity </li><ul><li>Presents a visual UI for user to interact with.
  33. 33. Similar to UIViewController. </li></ul><li>Service </li><ul><li>No visual UI, run in background for an indefinite period of time.
  34. 34. Similar to daemon. </li></ul><li>Broadcast Receiver </li><ul><li>Does nothing but receive and react to broadcast announcements (E.g. Timezone changed, battery low, ...). </li></ul><li>Content Provider </li><ul><li>Makes a specific set of the application's data available to other applications. (E.g. Wrapper for data in file system or DB) </li></ul></ul>
  35. 36. Android Project Folders <ul><li>src/ </li><ul><li>Source code. </li></ul><li>Android 1.5/ </li><ul><li>Library you will use. </li></ul><li>gen/ </li><ul><li>AIDL (Android Interface Definition Language), auto generated. </li></ul><li>asset/ </li><ul><li>Save data as asset when you need to read raw bytes. </li></ul></ul>
  36. 37. Android Project Files <ul><li>res/ (application resources access through R class) </li><ul><li>drawable/ (bitmap files)
  37. 38. layout/ (design Views , similar to HTML)
  38. 39. values/ (predefined values, can be referenced in application) </li></ul><li>AndroidManifest.xml </li><ul><li>Similar to iPhone’s Info.plist.
  39. 40. Contains application settings (E.g. Intent filters, permission, activities, …) </li></ul><li>default.properties </li><ul><li>Contains project settings such as build target. </li></ul></ul>
  40. 41. /res/layout/main.xml <ul><li>Layout for main activity.
  41. 42. Contains: </li><ul><li>LinearLayout for arranging subviews
  42. 43. TextView for displaying text
  43. 44. Button </li></ul><li>An ID (helloButton) is assigned to the button. Can be referenced through R.id.helloButton .
  44. 45. Button text is defined in /res/values/string.xml . </li></ul>
  45. 46. Add Button (main.xml) <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; android:orientation=&quot;vertical&quot; android:gravity=&quot;center&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot;> <TextView android:layout_width=&quot; wrap_content &quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;@string/hello&quot; /> <Button android:id=&quot;@+id/helloButton&quot; android:layout_width=&quot;wrap_content&quot; android:layout_height=&quot;wrap_content&quot; android:text=&quot;@string/hello_button&quot; /> </LinearLayout>
  46. 47. Launch Image Gallery private static final int REQUEST_PICK_IMAGE = 1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button)findViewById(R.id.helloButton); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent pickImage = new Intent(Intent.ACTION_PICK); pickImage.setType(&quot;image/*&quot;); startActivityForResult(pickImage, REQUEST_PICK_IMAGE); } }); }
  47. 48. Intent <ul><li>Abstract description of an action to be preformed.
  48. 49. Intent messaging is a facility for late run-time binding between components in the same or different applications.
  49. 50. Activity , Service , BroadcastReceiver are activated through Intent .
  50. 51. Intent Resolution </li></ul>
  51. 52. New Activity <ul><li>Create a new Activity called PhotoViewer
  52. 53. Create a Layout to display the photo (photo_viewer.xml)
  53. 54. Use a ImageView to display photo
  54. 55. GoodByeWorld launch PhotoViewer by sending it an Intent
  55. 56. The Intent contains the URI of the selected image
  56. 57. ImageView load image from the URI </li></ul>
  57. 58. /res/layout/photo_viewer.xml <ul><li>Layout for the PhotoViewer Activity
  58. 59. Contains an ImageView for displaying image
  59. 60. The ImageView is given an ID ( photoView ) </li></ul>
  60. 61. photo_viewer.xml <?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?> <LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot; android:orientation=&quot;vertical&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot;> < ImageView android:id=&quot;@+id/photoView&quot; android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot; /> </LinearLayout>
  61. 62. PhotoViewer.java protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView( R.layout.photo_viewer ); ImageView photoView = (ImageView)findViewById( R.id.photoView ); photoView.setImageURI( getIntent().getData() ); }
  62. 63. AndroidManifest.xml <application android:icon=&quot;@drawable/icon&quot; android:label=&quot;@string/app_name&quot;> <activity android:name=&quot;.GoodByeWorld&quot; android:label=&quot;@string/app_name&quot;> <intent-filter> <action android:name=&quot;android.intent.action.MAIN&quot; /> <category android:name=&quot;android.intent.category.LAUNCHER&quot; /> </intent-filter> </activity> <activity android:name=&quot;.PhotoViewer&quot;></activity> </application>
  63. 64. Create Menu private static final int MENU_RED = Menu.FIRST; private static final int MENU_GREEN = Menu.FIRST + 1; private static final int MENU_BLUE = Menu.FIRST + 2; private static final int MENU_RAND = Menu.FIRST + 3; public boolean onCreateOptionsMenu (Menu menu) { super.onCreateOptionsMenu(menu); menu.add(Menu.NONE, MENU_RED, Menu.NONE, &quot;Filter Red&quot;); menu.add(Menu.NONE, MENU_GREEN, Menu.NONE, &quot;Filter Green&quot;); menu.add(Menu.NONE, MENU_BLUE, Menu.NONE, &quot;Filter Blue&quot;); menu.add(Menu.NONE, MENU_RAND, Menu.NONE, &quot;Random Filter&quot;); return true; }
  64. 65. Response to Menu Selection public boolean onMenuItemSelected (int featureId, MenuItem item) { super.onMenuItemSelected(featureId, item); switch(item.getItemId()) { case MENU_RED: photoView. setColorFilter (redFilter()); break; case MENU_GREEN: photoView. setColorFilter (greenFilter()); break; case MENU_BLUE: photoView. setColorFilter (blueFilter()); break; case MENU_RAND: photoView. setColorFilter (randFilter()); break; } return true; }
  65. 66. Color Filter Matrix
  66. 67. ColorMatrixColorFilter private ColorMatrixColorFilter redFilter() { return new ColorMatrixColorFilter(new float[] { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 }); }
  67. 68. Q & A Any question?

×