Here you can experience the learnings, which the presenter got during development of the ImmobilienScout24 Android application. The presentation doesn't cover Design, UX or Fragments, but it gives an introduction and samples of using different resources, in special layouts. These folders can be used for filtering specific configurations, referencing other resources and using layout aliases. This session aims at people with knowledge of coding for Android.
13. Resource Folders
You can use several qualifiers in the
resource folders name for serving the
best matching resource.
14. Qualifiers
• Language (-en)
• Language & Region (-en-rUS)
• Smallest Width (sw600dp)
• Screensize (-small, -normal, -large)
• Screen Orientation (-port, -land)
• Screen Pixel Densitiy (-mdpi, -hdpi,...)
• Platform Version (-v11, -v13)
15. Best Matching Resources Win
1. res/values/strings.xml
2. res/values-en-rUS/strings.xml
3. res/values-large/strings.xml
4. res/values-sw600dp/strings.xml
The order of the qualifiers in the previous slides
gives the ranking, if two resources have the
same matching number of qualifiers.
16. Images Resources
• 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
stretches automatically depending on the content
inside.
• You must provide different launcher icons for
Froyo, Honeycomb and above? Use the platform
version. (v4, v11, v14)
17. Classifications for Layouts
Platform version at least v13
project-folder/res/
layout/ è small phones
layout-sw320dp/ è other phones
layout-sw600dp/ è tablets 7”
layout-sw720dp/ è tablets 10”
18. Platform version at lower v11
project-folder/res/
layout/ è phones
layout-v11/ è tablets 10”
layout-v13/ è small phones
layout-sw320dp/ è other phones
layout-sw600dp/ è tablets 7”
layout-sw720dp/ è tablets 10”
19. hint
The smallest width qualifier gets
automatically platform version "-v13"
through the packager, for avoiding
problems with the number of matching
qualifiers.
20. Howto Classify In Code
• Read configuration from the device
• Smarter approach use boolean
resources
28. Fixing one bug in the 10" layout has to
be done in two files
29. Fixing one bug in the 10" layout has to
be done in two files
è error prone
30. Fixing one bug in the 10" layout has to
be done in two files
è error prone
How to avoid this?
31. Fixing one bug in the 10" layout has to
be done in two files
è error prone
How to avoid this?
- Use resource aliasing.
32. Resource Alias
Put your layout files in the default folder.
project-folder/res/
layout/main_phone_small.xml
layout/main_phone_other.xml
layout/main_tablet_7.xml
layout/main_tablet_10.xml
33. Resource Alias
2. Create an item with the needed
classification in the previously defined
values folder.
project-folder/res/values-sw720dp/
layouts.xml
<item name="main"
type="layout">@layout/main_tablet10</item>
34. Resource Alias
2. Create an item with the needed
classification in the previously defined
values folder.
project-folder/res/values-sw720dp/
layouts.xml
<item name="main"
type="layout">@layout/main_tablet10</item>
35. Resource Alias
2. Create an item with the needed
classification in the previously defined
values folder.
project-folder/res/values-sw720dp/
layouts.xml
<item name="main"
type="layout">@layout/main_tablet10</item>
36. Resource Alias
2. Create an item with the needed
classification in the previously defined
values folder.
project-folder/res/values-sw720dp/
layouts.xml
<item name="main"
type="layout">@layout/main_tablet10</item>
64. Best Practices
• You have already an application
» Remove orientation fixation and suppressing
of orientation change from manifest to avoid
long bug analyzing.
• You start from the scratch
» Focus on main classification for faster time
to market
» But create an overall concept for better
modularization
65. Best Practices
• If you support both orientations, save
the instance state while orientation
changes for more responsiveness
» Especially for states, that need a long
computation for creation.
» Make the state object Parcelable for
faster write & read and also to have a
smaller memory footprint
66. Developer Hints
• You can start an activity for result from
a fragment, so the response can be
handled in the fragment.
• If you want to register a special service
on every onCreate method of an activity
give the ActivityLivecycleCallbacks a
try. You can register them in the
onCreate method of the application.
(min v14)
67. • If you get a BadParcelableException
with the cause ClassNotFound-
Exception, the source can be a
NullPointerException during the read or
write of the Parcelable. Exceptions are
hidden during the parcel process.
68. Listener Hell
If you have to many listeners or you think
the programming model is old school like
the “goto statements”. Give message/
event/ service bus a try. For Android:
• Otto from Square
• EventBus from greenrobot
See also: Callbacks as our Generations' Go To Statement
73. Q & A
Source: http://www.flickr.com/photos/21496790@N06/5065834411/
74. www.immobilienscout24.dewww.immobilienscout24.de
Thanks for your attention
& we are hiring!
Contact:
Hasan Hosgel
Twitter: @alosdev
Github: alosdev
Best Practices to develop the Layouts for different Android Device Classifications
Repo: https://github.com/alosdev/multidevice-nightmare-demo
SlideShare: http://www.slideshare.net/hosgel/mtc-2013-berlin-best-practices-for-multi-devices