66
Multi Screen Hell DevFest 2013, Ankara / Abdullah Cetin CAVDAR @accavdar

Multi Screen Hell

Embed Size (px)

DESCRIPTION

This presentation summarizes multiple screen development difficulties, optimizations for different kinds of devices and screen sizes and gives best practices to handle multi screen problems in Android.

Citation preview

Page 1: Multi Screen Hell

Multi Screen HellDevFest 2013, Ankara

/ Abdullah Cetin CAVDAR @accavdar

Page 2: Multi Screen Hell

Why Hell?

Page 3: Multi Screen Hell

ManufacturersAcerAsusHTCLGMotorolaSamsungSony...

Page 4: Multi Screen Hell

Fragmentation

Page 5: Multi Screen Hell

Device Types11.868 distinct Android devices

seen in 2013Open Signal Fragmentation Report 2013

Page 6: Multi Screen Hell

Phones

Page 7: Multi Screen Hell

Tablets

Page 8: Multi Screen Hell

Laptops

Page 9: Multi Screen Hell

TV

Page 10: Multi Screen Hell

Set-Top-Box

Page 11: Multi Screen Hell

Consoles

Page 12: Multi Screen Hell

EverywhereInternet of Things (IoT)?

Behind the 'Internet of Things' Is Android and It's Everywhere

Page 13: Multi Screen Hell

Size & Resolution2.8 in, 3.2 in, 3.5 in, 3.6 in, 3.7 in, 4.0 in, 4.3 in, 4.5 in, 4.7 in, 4.8 in, 5.0 in,

6.4 in, 7.0, 9.7 in, 10.1 in, ...

320x240 QVGA, 480x320 HVGA, 800x480 WVGA, 960x540 qHD,1280x768 WXGA, 1280x720 HD, 1920x1080 HD, ...

Page 14: Multi Screen Hell

API Versions

Android Dashboards

Page 15: Multi Screen Hell

OrientationLandscape or Portrait?

Page 16: Multi Screen Hell

Keep Calmand

Çare Drogba

Page 17: Multi Screen Hell

SupportingMultiple Screens

Page 18: Multi Screen Hell

Range of Screens Supportedsizes: small, normal, large, and xlargedensities: ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high)

Page 19: Multi Screen Hell

Size and Density Group

Page 20: Multi Screen Hell

Density-independent Pixel (dp)A virtual pixel unit that you should use when defining UI layout, to

express layout dimensions or position in a density-independent way.

The density-independent pixel is equivalent to one physical pixel on a160 dpi screen (medium density)

Page 21: Multi Screen Hell

Conversionpx = dp * (dpi / 160)

Ex: on a 240 dpi screen, 1 dp equals 1.5 physical pixels

Page 22: Multi Screen Hell

Density IndependenceIt preserves the physical size of user interface elements when displayed

on screens with different densities

The system scales dp units as appropriate for the current screendensityThe system scales drawable resources to the appropriate size, basedon the current screen density, if necessary

Page 23: Multi Screen Hell

Bad

Good

Page 24: Multi Screen Hell

How to Support MultipleScreens?

Page 25: Multi Screen Hell

Use <supports-screen>Explicitly declare in the manifest which screen sizes your application

supports

Page 26: Multi Screen Hell

Provide different layouts fordifferent screen sizes

Provide size-specific resources: small, normal, large, and xlargeEx: layout-xlarge/

Use the sw<N>dp configuration qualifier to define the smallestavailable width (beginning API 13)

Ex: layout-sw600dp/ (at least 600dp screen width)

Page 27: Multi Screen Hell

Provide different bitmapsBy default, Android scales drawables (.png, .jpg, .gif and .9.png files)Include alternative versions at different resolutions for differentscreen densitiesDensity-specific resources are ldpi (low), mdpi (medium), hdpi (high),and xhdpi (extra high)

Ex: drawable-hdpi/

Page 28: Multi Screen Hell

Configuration QualifiersUsage: <resources_name>-<qualifier>

<resources_name> is the standard resource name (such as drawableor layout)<qualifier> is a configuration qualifier (such as hdpi or xlarge)

Page 29: Multi Screen Hell

Layouts & Drawables

Page 30: Multi Screen Hell

Alternative DrawablesYou only need to provide density-specific drawables (.png, .jpg, .gif or.9.png)Follow the 3:4:6:8 scaling ratio between the four generalized densities

36x36 for low-density48x48 for medium-density72x72 for high-density96x96 for extra high-density

See Icon Design Guideline

Page 31: Multi Screen Hell

Relative Sizes

Page 32: Multi Screen Hell

Tablet Layouts for Android 3.2Android 3.2 introduces a new way to specify resources for more discrete

screen sizes

Page 33: Multi Screen Hell

New Size QualifierssmallestWidth: sw<N>dp

Ex: sw600dpAvailable screen width: w<N>dp

Ex: w1024dpAvailable screen height: h<N>dp

Ex: h720dp

Page 34: Multi Screen Hell

Configuration Examples

Page 35: Multi Screen Hell

Best Practises

Page 36: Multi Screen Hell

1. Use wrap_content,match_parent, or the dp unit

for layout dimensionsUsing wrap_content, match_parent or dp units guarantees that the view

is given an appropriate size on the current device screen

PS: Use sp for font sizes

Page 37: Multi Screen Hell

2. Do not use hard-coded pixelvalues in your application code

Page 38: Multi Screen Hell

3. Use RelativeLayoutIt uses relative positioning to lay out its child views

For instance, you can specify that a button widget should appear "to theright of" a text widget

Page 39: Multi Screen Hell

4. Use size and density-specificresources

PS: To avoid pre-scaling, put the resource in a resource directory withthe nodpi configuration qualifier

Page 40: Multi Screen Hell

5. Use Nine-patch BitmapsThey are specially formatted PNG files that indicate which areas can and

cannot be stretched

Page 41: Multi Screen Hell

Tablets&

Handsets

Page 42: Multi Screen Hell

Basic Guideline

Page 43: Multi Screen Hell

1. Build your activity designsbased on Fragments

Page 44: Multi Screen Hell

FragmentIntroduced in Android 3.0 (API Level 11)It allows you to separate distinct behavioral components of your UIinto separate partsProvides modular UI developmentPS: Use Android to use fragments in older Androidversions

Support Libraries

Page 45: Multi Screen Hell

Multiple Fragments, MultipleActivities

Page 46: Multi Screen Hell

Handsetsres/layout/main.xml

Page 47: Multi Screen Hell

Tabletsres/layout-large/main.xml

PS: You should also use the new minimum width size qualifiers in orderto more precisely control the screen size

Page 48: Multi Screen Hell

How does it work?If Fragment B is in the layout, Activity A notifies Fragment B to updateitselfIf Fragment B is not in the layout, Activity A starts Activity B (whichhosts Fragment B)Important Note: Define a callback interface in each fragment class tocommunicate with host activity

Page 49: Multi Screen Hell

2. Use the Action BarThe action bar is a window feature that Action Baridentifies the user

location, and Action Barprovides user actions and Action Barnavigationmodes

Introduced in Android 3.0 (API Level 11). However, you can use t usingAndroid Support Libraries

Page 50: Multi Screen Hell

Why Action Bar?Android system does all the work to gracefully adapt the action bar for

different screen sizes

Page 51: Multi Screen Hell

Tips for creating Action Bar

Page 52: Multi Screen Hell

1. Avoid using the always valueForcing too many action items into the action bar can create acluttered UIAction items may overlap with other action bar elements such as thetitle or navigation itemsUse ifRoom for the android:showAsAction attribute

Page 53: Multi Screen Hell

2. Provide an IconAlways provide an icon for the action itemsUse showAsAction="ifRoom|withText"

Page 54: Multi Screen Hell

3. Provide a TitleAlways provide a titleUsers view the title as a tooltip on long-clickIt is critical for accessibility: Screen readers read aloud the item titleeven when not visisble

Page 55: Multi Screen Hell

4. Avoid using customnavigation modes when

possibleUse the built-in tab and drop-down navigation modes when possibleSystem can adapt their presentation to different screen sizesautomatically

Ex: stacked action bar in handsets

Page 56: Multi Screen Hell

Split Action BarAvailable in Android 4.0 (API level 14) and higherAdd uiOptions="splitActionBarWhenNarrow" to your <activity> or<application> manifest elementCall setDisplayShowHomeEnabled(false) to disable the applicationicon in the action bar

Page 57: Multi Screen Hell

Testing

Page 58: Multi Screen Hell

Use Emulator with differentconfigs

emulator -avd <avd_name> -scale 96dpi

Page 59: Multi Screen Hell

Android StudioBuilt in device previews (landscape and portrait modes)

Page 60: Multi Screen Hell

CompatibilityMost important characteristic of a compatible device is the ability to

install and correctly run an Android .apk file

Page 61: Multi Screen Hell

Apps Availability<uses-feature> in manifest file

<uses-feature android:name="android.hardware.bluetooth" />

<uses-feature android:name="android.hardware.camera" />

The other filters for apps availability in Google Play:

<supports-gl-texture><uses-configuration><uses-library><uses-permission><uses-sdk>

Page 62: Multi Screen Hell

Package ManagerCheck feature availabilities at runtime

PackageManager packageManager = this.getPackageManager();

if (packageManager.hasSystemFeature(PackageManager.FEATURE_NFC)) {

Log.d(TAG, "Oh yeah, NFC is available. :)");

} else {

Log.d(TAG, "Shit, no NFC. :(");

}

Page 63: Multi Screen Hell

Business ReasonsList the countries an app is available inSelect which carrier’s users are able to access the app

Page 64: Multi Screen Hell

Slideshttp://github.com/accavdar/MultiScreenHell

Page 65: Multi Screen Hell

Questions?

Page 66: Multi Screen Hell

THE ENDby Abdullah Cetin CAVDAR / @accavdar