490 likes | 594 Views
Tackling Android Fragmentation Dev : Mobile 2012 @ Glennbech , Inmeta consulting. 16 klocs – not rocket science. Source: Twitter / http ://en.wikipedia.org/wiki/Mobile_operating_system#Market_share. Nairobi. HTC 3G SLIDE. X. Got Gingerbread May 2011. On sale May 2010.
E N D
TacklingAndroid FragmentationDev:Mobile 2012 @Glennbech , Inmeta consulting 16 klocs – not rocket science
Source: Twitter / http://en.wikipedia.org/wiki/Mobile_operating_system#Market_share
HTC 3G SLIDE X Got GingerbreadMay 2011 On saleMay 2010
Situation report June 2012 Android • ICS 7.3% (All versions) • Honeycomb 2.7% • Gingerbread (2.3) dominant @ 65% • Froyo (2.2) still at 19.1 % • As ofFebruary 2012 Phones withno ICS upgrade plan still sold • This willcontinue iOS • 61% oniOS 5 or above in 15. days! Source: http://developer.android.com/resources/dashboard/platform-versions.html
Agenda «Prove that it is feasable, and not overlydifficult to, write single APK, native androidappsthatworkswellacrossandroidversions and form factors»
ActionBar& HomeNavigation ICS/Honeycomb tabs ViewPager Action Items https://play.google.com/store/apps/details?id=com.glennbech.nutrinfo
ContextualActionbar Tab Navigation … withListViewmultiselect https://play.google.com/store/apps/details?id=com.glennbech.nutrinfo
https://play.google.com/store/apps/details?id=com.glennbech.nutrinfohttps://play.google.com/store/apps/details?id=com.glennbech.nutrinfo
Situation report June 2012 Android • ICS 7.3% (All versions) • Honeycomb 2.7% • Gingerbread (2.3) dominant @ 65% • Froyo (2.2) still at 19.1 % • As ofFebruary 2012 Phones withno ICS upgrade plan still sold • This willcontinue iOS • 61% oniOS 5 or above in 15. days! Source: http://developer.android.com/resources/dashboard/platform-versions.html
Androidmanifest.xml <uses-sdk android:minSdkVersion=”7" android:targetSdkVersion="14” />
Example. Helloworld publicclassTargetSDKVersionExampleextends Activity { publicvoidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override publicbooleanonCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; } }
Example. Menu.xml <menu> <item android:id="@+id/menu_save« android:icon="@drawable/ic_menu_save" android:title="@string/menu_save" android:showAsAction="ifRoom|withText" /> </menu>
ICS Gingrerbread
Androidmanifest.xml <uses-sdk android:minSdkVersion=”7" android:targetSdkVersion="10” />
ICS Gingrerbread
Android Support Libraries • Official Android 3 & 4 featuresbackported • Very simple to use; downloadusing SDK manager and include JAR file in projectIncludes • Fragment API & DialogFragment • Loader API • ViewPager, Pager Adapter & FragmentPagerAdapter • SearchView • Simple Actionbarimplementationprovided in samples source: http://developer.android.com/sdk/compatibility-library.html#SettingUp
Limitationsofthe support libraries • No action bar • Code «infection» • CannotextendMapActivitysinceyou have to extendscustom Activity class
ActionbarSherlock • Written by Jake Whorton • Easy to use (git clone) • Includes & based on support libraries • Elaborate. Support for wide range of Honeycomb and ICS features • Actionbar • Navigation Modes, Tabs and spinners in the action bar. • Contextual Action Bar / ActionModeThe ICS feature "split action bar“ • Pluginfor MapActvity(!) • www.actionbarsherlock.com • Apache License Version 2.0
A quicksummary • We have used the support libraries, throughActionBarSherlock to get ICS lookingappson pre-ICS phones (back to 1.6 supported) • The price • Must use a customtheme • Must extendsSherlockActivityclasses • Must useoverloadedmethods, and usegetSuppportMenuInflater() etc.
Fragments crashcourse WHAT • Introducedin Android 3.0 • Reusable UI components • Have theirownlifecycle • Canaddtheirownitems to actionbar etc. WHY • Code Reuse • Fragments areintegratedintothe ICS SDK
Why - Reuse http://developer.android.com/guide/topics/fundamentals/fragments.html
onTabSelected(ActionBar.Tabtab, FragmentTransactionft) ActionbarusesTabListeners for tab navigation Source: http://developer.android.com/reference/android/app/ActionBar.TabListener.html
Using fragments - example • Declared in layout • Added/removed from code using FragmentManager
Button (100dpx100dp) HTC Sensation
Definitions • xlarge screens are at least 960dp x 720dp. • large screens are at least 640dp x 480dp. • normal screens are at least 470dp x 320dp. • small screens are at least 426dp x 320dp
Best Match layout picking • Excellent support for providing resourcesbasedondeviceconfiguration • Versions • mcc310-mnc004(US/Verizon) • Car/desk (docking) • Night mode • ETC Source: http://developer.android.com/guide/topics/resources/providing-resources.html
In practice • Providediffernet layout for different screens and orientations - backed by the same activity • Provide a different Activity class for a different device/layout. Exampleone for phone and one for tablet
Dispatch Activity idiom PhoneActivity New Intent DispatchActivity (condition) Intent TabletActivity New Intent
Conclusion • The Android OS and devicesareboth forward- and backwardscompatible in regard to OS versions • Android has excellent support for layout ondeviceswith different screen sizes and densities • By usingtheActionbarSherlock/Fragment activitiesyoucanwritecodethatuse fragments and deployontablets and phones • By usingActionbarSherlockyoucangetthe «ICS look» onyour Android 1.X + devicestoday. Includingthekindle fire.
“I am an old man and have known a great many troubles, but most of them never happened” – Mark Twain