[Droidcon]Developing Apps for Android on 2.x/3.x/4.x

3,723 views

Published on

"Developing Apps for Android on 2.x/3.x/4.x"
->The presentation file on droidcon London 2012

[Droidcon]Developing Apps for Android on 2.x/3.x/4.x

  1. 1. Droidcon London 2012 Developing Apps for Android on 2.x/3.x/4.x Kenichi Kambara (@korodroid) October 26, 2012
  2. 2. Who am I? l  Kenichi Kambara (Twitter @korodroid)l  iplatform.org(http://www.iplatform.org/) (Personal)l  NTT Software Corporation (Official)l  Activity(iplatform.org as Personal)     -  My Android Apps on Google Play (20+ Apps) 9 10 2
  3. 3. Who am I? l  Kenichi Kambara (Twitter @korodroid)l  iplatform.org(http://www.iplatform.org/) (Personal)l  NTT Software Corporation (Official)l  Activity(iplatform.org as Personal)     -  My Android Apps on Google Play (20+ Apps) 9 10“Sekai Phone” l Google Developer Day 2011 Tokyo Keynote Demo l Google Android Developer Lab Tokyo 2011 5th prize 3
  4. 4. Agenda • Introduction • Background • Android Fundamentals • Application Development Tips 4
  5. 5. My session topics Some tips on developing Apps for multi versions and multi devices.2.x 3.x 4.x Handsets Tablets 5
  6. 6. Introduction(Sekai Phone) 6
  7. 7. What is “Sekai Phone”? Real time translation phone services(Supports Android 2.x/3.x/4.x & multi devices) ) English German Japanese ○ ○ ○ Italian French ○ ○ Chinese Publishe Date: Jan, 2010, over 20+ ver.up 7
  8. 8. Use Case (1) Phone mode(Auto translating to receiver’s native language) English Japanese Hello! Talking Konnichiwa! Talking Paul Kenichi Thanks! Arigatou! 8
  9. 9. Use Case (2) Talk mode (Auto translating on the spot) English Japanese 9
  10. 10. App Demos (1.Phone mode) English Japanese Hello! Talking Konnichiwa! Talking Paul Kenichi Thanks! Arigatou! 10
  11. 11. App Demos (2.Talk mode) 11
  12. 12. App Screenshots on Android 2.x Portrait Landscape 12
  13. 13. App Screenshots on Android 3.x Portrait Landscape 13
  14. 14. App Screenshots on Android 4.x Portrait Landscape 14
  15. 15. Background 15
  16. 16. Current Android Devices Handsets Handsets (Almost all) & Tablets2.x Tablets 4.x (All)3.x 16
  17. 17. Platform Versions? This data by Google on October 1, 2012 17
  18. 18. Platform Versions? Honeycomb ICS JB Gingerbread Others Froyo This data by Google on October 1, 2012 In my App: Main Target: Android 2.2+ (2.2,2.3,3.x,4.x) 18
  19. 19. Screen Sizes & Densities? xhdpi Normal Small ldpi Xlarge hdpi Large mdpi This data by Google on October 1, 2012 19
  20. 20. Screen Sizes & Densities? This data by Google on October 1, 2012 In my App: Main Target: (normal,large,xlarge)x(mdpi,hdpi,xhdpi) 20
  21. 21. Android Fundamentals 21
  22. 22. Fragment? Handset Tablet Activity A Activity B Activity A 22
  23. 23. Fragment? Handset Tablet Fragment X Fragment Y Fragment X Fragment YActivity A Activity B Activity A 23
  24. 24. Menu? Options Menu Action Bar (2.x) (3.0+) 24
  25. 25. Application Development Tips 25
  26. 26. Support multi versions and multi devices? 1.Designing User Interface l  Screen size l  Screen density l  Screen orientation …2.Using APIs l  Fragment l  Menu … 26
  27. 27. 1.  Designing User Interface [Some Approaches] 27
  28. 28. [UI]1 st Approach Using layout-small/normal/large/xlargeScreen Size Classification l  Supports Android 1.6+ l  Both 7” tablet and 5” handset mapped to “large” l  Pre 3.0 some devices mis-classified 28
  29. 29. [UI]Introduction of 2nd Approach Using “dp(Density-Independent pixel)”Width sizes Devices 320dp Typical Handsets 600dp 7” tablet 720dp 10” tablet 29
  30. 30. [UI]2 nd Approach e.g.)Supporting Handsets & 2 TabletsHandsets 7’’ Tablet 10’’ Tablet l  res/layout/main.xml l  res/layout-sw600dp/main.xml l  res/layout-sw720dp/main.xml 30
  31. 31. [UI]2 nd Approach sw<N>dp?, w<N>dp?, h<N>dp?(a)layout-sw600dp Width & Height ≥ 600dp(b)layout-w720dp Width ≥ 720dp (c)layout-h480dp Height ≥ 480dp 31
  32. 32. [UI]2 nd Approach Using sw<N>dp,w<N>dp,h<N>dp400 dp 960 dp (a)layout-sw600dp false (b)layout-w720dp true (c)layout-h480dp false 32
  33. 33. [UI]2 nd Approach Using sw<N>dp,w<N>dp,h<N>dp(a)layout-sw600dp Width & Height ≥ 600dp(b)layout-w720dp Width ≥ 720dp (c)layout-h480dp Height ≥ 480dp l  Recommended by Google l  Supports only Android 3.2+ Note: Effect by Screen Orientation 33
  34. 34. [UI]3 rd Approach Combination of 1st and 2ndl  res/layout-sw600dp/main.xml <- 3.2+ tablets l  res/layout-xlarge/main.xml <- 3.0/3.1 tabletsl  res/layout/main.xml <- The others (Handsets)l  Supports Android 1.6l  Supports many devices (compared to 1st or 2nd)l  Any Problem? 34
  35. 35. [UI]3 rd Approach It looks good but…l  res/layout-sw600dp/main.xml <- 3.2+ tablets l  res/layout-xlarge/main.xml <- 3.0/3.1 tabletsl  res/layout/main.xml <- The others (Handsets) •  Needs to put the same file for tablets. (Maintenance headache…) 35
  36. 36. [UI]3 rd Approach It looks good but…if ([Size is xlarge] or [width & height is at least 600dp]) // codes for tablets}else{ // codes for others} •  Complicated Java codes (Development is complicated…) 36
  37. 37. Which is the Better Approach? 37
  38. 38. [UI]4 th Approach Based on 3rd , plus some tips•  Put minimum requirement for layouts 38
  39. 39. [UI]4 th Approach Based on 3rd , plus some tips (Layout Aliases) // for Tablets <resources> <item name "main_layout" type="layout"> @layout/main_twopanes </item> <bool name="has_two_panes"> true </bool> </resources> 39
  40. 40. [UI]4 th Approach Based on 3rd , plus some tips (Layout Aliases)// for Tablets <resources> <item name "main_layout" type="layout"> @layout/main_twopanes </item> <bool name="has_two_panes"> true </bool> </resources> boolean hasTwoPanes =getResources(). getBoolean(R.bool.has_two_panes); if (hasTwoPanes) … •  Simple Java codes 40
  41. 41. 2.Using APIs? [Some Points] 41
  42. 42. [API]Fragment Using Support Library? 2.x 3.x 4.x WithoutSupport Library WithSupport Library 42
  43. 43. [API]Fragment Comparing Using with No-Using With Without Support Library Support Library • android.support.v4.Fragment • android.app.Fragment Class • android.support.v4.FragmentActivity • android.app.Activity … … • getSupportFragmentManager() • getFragmentManager()Method (FragmentActivity) (Activity) … … 43
  44. 44. [API]Options Menu vs Action Bar Action Bar is good… 2.x 3.x 4.x Options Menu Action Bar Note: ActionBarSherlock lib, Effect by style 44
  45. 45. [API]Effect by AndroidManifest On Android 2.x / 3.x Min Target 2.x 3.x Sdk Sdk Pattern 1 - -   (Fail 1)Pattern 2 8 8   (Fail 2)Pattern 3 8 16 Fail 2 Fail 1 45
  46. 46. [API]Effect by AndroidManifest On Android 2.x / 4.x Min Target 2.x 4.x Sdk Sdk Pattern 1 - -   (Fail 3)Pattern 2 8 8   (Fail 4)Pattern 3 8 16 Fail 3 Fail 4 46
  47. 47. [API]Effect by AndroidManifest On Android 2.x / 3.x / 4.x Min Target 2.x 3.x 4.x Sdk Sdk Pattern 1 - - Pattern 2 8 8 Pattern 3 8 16 4.x 2.x 3.x 47
  48. 48. [API]Effect by AndroidManifest On Android 2.x / 3.x / 4.x Min Target 2.x 3.x 4.x Sdk Sdk Pattern 1 - - Pattern 2 8 8 Pattern 3 8 16 Note: Google Official blogs, Split Action Bar 48
  49. 49. [API]Multi-Versioning Development?, Management?, APK Size?Single APK Multiple APK 49
  50. 50. [API]Multi-Versioning Single APK In my App: Developed by Single APK 50
  51. 51. [API]Multi-Versioning How to use the newest API on Single APK Reflection Well known approach Lazy loading One of Design Patterns 51
  52. 52. [API]Multi-Versioning How to use the newest API on Single APK Reflection Well known approach Lazy loading One of Design Patterns In my App: Compatibility with Lazy loading 52
  53. 53. [API]Multi-Versioning Code Examples of Lazy loading1 st step public abstract class NotificationUtilAbstract { public static NotificationUtilAbstract newInstance() { NotificationUtilAbstract instance = null; if (Integer.parseInt(Build.VERSION.SDK)= 16) { instance = new NotificationUtilJB(); } else { instance = new NotificationUtilDefault(); } return instance; } public abstract void showCaller; } 53
  54. 54. [API]Multi-Versioning 2 nd step public class NotificationUtilJB
 extends NotificationUtilAbstract{
 @Override
 public void showCaller(){ // Code by Jelly Bean (API 16) } } public class NotificationUtilDefault
 extends NotificationUtilAbstract{
 @Override
 public void showCaller(){ // Code by Old API } •  Compatible } 54
  55. 55. Appendix 1.  Use “wrap_content”/“match_parent”,”sp”/”dp”   2.  Supply alternative drawables / Use 9-patch 3.  Use Fragment 4.  Use “Dimension (Customize component size)” 5.  Consider either “1 apk” or “multiple apk” 55
  56. 56. References Android Developers Site• Supporting Tablets and Handsets http://developer.android.com/guide/practices/tablets-and-handsets.html • Supporting Multiple Screens http://developer.android.com/guide/practices/screens_support.html • Supporting Different Screen Sizes http://developer.android.com/training/multiscreen/screensizes.html 56
  57. 57. References“Android Programming Nyumon v2” •  Language: Japanese (Sorry…) •  Release Date: August 30, 2012 •  Publisher:ASCII MEDIA WORKS Inc. •  Authors: - Takashi Egawa - Kenichi Kambara - Akimichi Yamada - Tetsurou Sano - Mariko Goda 57
  58. 58. Thank you!• Facebook:http://fb.com/kanbara.kenichi• Google+:+Kenichi Kambara • Twitter:@korodroid

×