• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Android Developer Days 2013 - MultiDevice Nightmare
 

Android Developer Days 2013 - MultiDevice Nightmare

on

  • 1,296 views

Here you can gain advances knowledge on how to survive the Multi-Device Nightmare. It gives an introduction and samples of using different resource/ layout folders for filter specific configurations, ...

Here you can gain advances knowledge on how to survive the Multi-Device Nightmare. It gives an introduction and samples of using different resource/ layout folders for filter specific configurations, referencing other resources and using layout aliases. This session aims at people with knowledge of coding for Android.

Statistics

Views

Total Views
1,296
Views on SlideShare
1,296
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Android Developer Days 2013 - MultiDevice Nightmare Android Developer Days 2013 - MultiDevice Nightmare Presentation Transcript

    • www.immobilienscout24.dewww.immobilienscout24.deThe Multi-Device Nightmare- and how to clear the Elm StreetAndroid Developer Days | Ankara | 15.06.2013 | Hasan Hosgel
    • About meHasan HosgelTwitter: @alosdevGithub: alosdevGoogle+: Hasan HosgelSlideshare: hosgeldeveloper @ ImmobilienScout24,CO-Organizer @ GDG Berlin Android,Organizer @ community events &SpeakerAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel
    • FragmentationAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel
    • FragmentationAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel> 3100 Android Devices
    • Here comes The NightmareAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelImage source:http://www.flickr.com/photos/boogeyman13/4553188509/
    • Here comes The NightmareAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelFor developersImage source:http://www.flickr.com/photos/boogeyman13/4553188509/
    • Device ClassificationAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelImages sources:https://play.google.com/store/devices
    • Device ClassificationAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelImages sources:https://play.google.com/store/deviceshttp://www.htc.com/de/
    • Device ClassificationAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelImages sources:http://www.sony.de/hub/google-tv
    • Device ClassificationAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelImages Sourceshttps://developer.ford.com/
    • Resource FoldersAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelYou can use several qualifiers in the resource folders name for servingthe best matching resource. Most used qualifiers:● Language (-en)● Language & Region (-en-rUS)● Smallest Width (-swXXXdp, e.g. –sw600dp)● Screensize (-small, -normal, -large)● Screen Orientation (-port, -land)● Screen Pixel Densitiy (-mdpi, -hdpi, -xhdpi, -xxhdpi)● Platform Version (-v11, -v13)
    • Resource FoldersAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelIf you have several resource folders, the one with the greatestmatching number qualifiers will be used. e.g. :1. res/values/strings.xml2. res/values-en-rUS/strings.xml3. res/values-large/strings.xml4. res/values-sw600dp/strings.xml
    • Resource FoldersAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelIf you have several resource folders, the one with the greatestmatching number qualifiers will be used. e.g. :1. res/values/strings.xml2. res/values-en-rUS/strings.xml3. res/values-large/strings.xml4. res/values-sw600dp/strings.xmlIf two resources have the same number of matching qualifiers, theordering in the previous slide will rank the qualifiers.e.g. Device configurations:Nexus One, Turkish: 1.Galaxy Tab 7.0 in German: 3.Nexus 7: 4.
    • ImagesAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel● Use the different qualifiers for the screen pixel density (mdpi, hdpi,etc.)● If you are forced to use text on images use language and region(en, es-rUs, en-rUS, etc.)● Better approach is to use 9-patch drawables, which stretchesautomatically depending on the content inside.More about it: developer.android.com● You must provide different launcher icons for Froyo, Honeycomband above? Use the platform version. (v4, v11, v14)
    • Classifications For LayoutsAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelIf your minimum SDK is at least platform version 13 (Honeycomb MR2)project-folder/res/layout/  small phoneslayout-sw320dp/  other phoneslayout-sw600dp/  tablets 7”layout-sw720dp/  tablets 10”You should also use orientation
    • Classifications For LayoutsAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelIf your minimum SDK is lower than platform version 11 (Honeycomb)project-folder/res/layout/  phoneslayout-v11/  tablets 10”layout-v13/  small phoneslayout-sw320dp/  other phoneslayout-sw600dp/  tablets 7”layout-sw720dp/  tablets 10”The smallest width qualifier gets automatically platform version “v13”through the packager, for avoiding problems with the number ofmatching qualifiers.You can also use the screen size qualifier, if you want to reach small,medium and large screens previous to Honeycomb.
    • Classifications In CodeAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelYou can read the configurations from the device.Smarter Approach: use boolean resourcesproject-folder/res/values/layouts.xml<resources><bool name="is_phone_small”>false</bool><bool name="is_phone_other">true</bool><bool name="is_tablet_7”>false</bool><bool name="is_tablet_10”>false</bool></resources>
    • Classifications In CodeAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelYou can read the configurations from the device.Smarter Approach: use boolean resourcesproject-folder/res/values/layouts.xml<resources><bool name="is_phone_small”>false</bool><bool name="is_phone_other">true</bool><bool name="is_tablet_7”>false</bool><bool name="is_tablet_10”>false</bool></resources>Usage in code:getResources().getBoolean(R.bool.is_phone_small)
    • Current Layout File StructureAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgelproject-folder/res/layout/main.xmllayout-v11/main.xmllayout-v13/main.xmllayout-sw320dp/main.xmllayout-sw600dp/main.xmllayout-sw720dp/main.xml
    • Current Layout File StructureAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgelproject-folder/res/layout/main.xmllayout-v11/main.xmllayout-v13/main.xmllayout-sw320dp/main.xmllayout-sw600dp/main.xmllayout-sw720dp/main.xmlFixing one bug in the 10“ layout has to be done in two files.
    • Current Layout File StructureAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgelproject-folder/res/layout/main.xmllayout-v11/main.xmllayout-v13/main.xmllayout-sw320dp/main.xmllayout-sw600dp/main.xmllayout-sw720dp/main.xmlFixing one bug in the 10“ layout has to be done in two files. error prone
    • Resource AliasAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel1. Put your layout files in the default folder.project-folder/res/layout/main_phone_small.xmllayout/main_phone_other.xmllayout/main_tablet_7.xmllayout/main_tablet_10.xml
    • Resource AliasAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel1. Put your layout files in the default folder.project-folder/res/layout/main_phone_small.xmllayout/main_phone_other.xmllayout/main_tablet_7.xmllayout/main_tablet_10.xml2. Create an item with the needed classification in the previouslydefined values folder.project-folder/res/values-sw600dp/layouts.xml<item name=“main” type=“layout”>@layout/main_tablet7</item>
    • Sample ScreenAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel
    • Sample ScreenAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelUse <includes>
    • Sample ScreenAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelUse <includes>Create custom view
    • Custom ViewAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgelpublic class CustomView extends LinearLayout {public CustomView(Context context, AttributeSet attrs) {super(context, attrs);LayoutParams lp = …addView(createText(context, "label"), lp);addView(createText(context, ”desc"), lp);if (getResources().getBoolean(R.bool.is_phone_small) ||getResources().getBoolean(R.bool.is_phone_other)) {setOrientation(VERTICAL);} else {setOrientation(HORIZONTAL);}}private TextView createText(Context context, String text) {TextView textView = new TextView(context);textView.setText(text);return textView;}}
    • Sample ScreenAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelUse <includes>Create custom view
    • Sample ScreenAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelUse <includes>Create custom viewIf custom view has much morebusiness logic and need lifecycles Create a Fragment
    • Custom XML Attribute (attrs.xml)Android Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel<resources><declare-styleable name=”CustomView"><attr name="label" format="reference|string" /><attr name="value" format="reference|string" /><attr name="orientation" format="enum"><enum name="horizontal" value="0" /><enum name="vertical" value="1" /></attr></declare-styleable><resources>
    • Custom XML Attribute (main.xml)Android Developer Days 2013 | Mutli-Device Nightmare | Hasan HosgelAdd to root XML nodexmlns:app="http://schemas.android.com/apk/res/de.alosdev"Usage in custom view<de.alosdev.CustomViewandroid:id="@+id/customView"android:layout_width="wrap_content"android:layout_height="wrap_content"app:label="label 1"app:orientation="vertical"app:value="value 1" />
    • Custom XML Attribute (CustomView.java)Android Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgelpublic class CustomView extends LinearLayout {static final int[] ORIENTATION = new int[] { HORIZONTAL, VERTICAL};public CustomView(Context context, AttributeSet attrs) {super(context, attrs);…TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.CustomView);try {setOrientation(ORIENTATION[a.getInt(R.styleable.CustomView_orientation, 0)]);} finally {a.recycle();}}…}
    • Custom XML Attribute (Screenshot)Android Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel
    • Best Practiceswhich learned painfullyAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel● You have already an applicationRemove orientation fixation and suppressing of orientationchange from manifest to avoid long bug analyzing.● You start from the scratchFocus on main classification for faster time to marketBut create an overall concept for better modularization● If you support both orientations, save the instance state whileorientation changes for more responsivenessEspecially for states, need a long computation for creation.Make the state object Parcelable for faster write & read and alsoto have a smaller memory footprint
    • Mission AccomplishedAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgelhttp://www.flickr.com/photos/ianaberle/5729561934/
    • Mission AccomplishedAndroid Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgelhttp://www.flickr.com/photos/ianaberle/5729561934/
    • Q & ASource: http://www.flickr.com/photos/21496790@N06/5065834411/ Droidcon 2013 | Mutli-Device Nightmare | Hasan HosgelPage 37Android Developer Days 2013 | Mutli-Device Nightmare | Hasan Hosgel
    • www.immobilienscout24.dewww.immobilienscout24.deThanks for your attention& we are hiring!Contact:Hasan HosgelTwitter: @alosdevGithub: alosdevMultidevice NightmareRepo: https://github.com/alosdev/multidevice-nightmare-demoSlideShare: http://de.slideshare.net/hosgel/add-2013-multidevice-nightmare