android development for different screens and devices rohit ghatol

83
Android Development for Different Screens and Devices Rohit Ghatol

Upload: doreen-stafford

Post on 24-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Android Development for Different Screens and Devices Rohit Ghatol

Android Development for Different Screens and Devices

Rohit Ghatol

Page 2: Android Development for Different Screens and Devices Rohit Ghatol

About MeRohit Ghatol

1. Architect @QuickOffice2. Project Mgr @Synerzip3. Certified Scrum Master4. Author “Beginning PhoneGap” @Apress5. Founder TechNext Pune (Pune Developer

Community)

LinkedIn ProfileLinkedIn Profile

Page 3: Android Development for Different Screens and Devices Rohit Ghatol

Topics

• Understanding UI Terms and Concepts• Building for Different Screen Sizes• Building for Different Tablets and Phone• Getting ready for Ice Cream Sandwich• Making your app run on all devices• Reference Material

3

Page 4: Android Development for Different Screens and Devices Rohit Ghatol

Diversity on Android

Android Devices•Handsets•Tablets•TV

4

Page 5: Android Development for Different Screens and Devices Rohit Ghatol

Diversity on Android

• Screen– Screen Size (2 inch to 50 inch)– DPI (120 – 320 )

• Optional Hardware (Telephony, Camera, GPS)• User Interaction

– Touch, DPAD, Trackball, Keyboard

5

Page 6: Android Development for Different Screens and Devices Rohit Ghatol

Making App work for different Screens

6

Page 7: Android Development for Different Screens and Devices Rohit Ghatol

UI Terms and Concepts

7

Page 8: Android Development for Different Screens and Devices Rohit Ghatol

Screen Size

8

Measured in Diagonal

SmallSmall

MediumMedium

LargeLarge

Extra LargeExtra Large

Categories

Page 9: Android Development for Different Screens and Devices Rohit Ghatol

Screen Density

9

CategoriesDPI – Dots per inches

Low Normal

High Extra High

Page 10: Android Development for Different Screens and Devices Rohit Ghatol

Orientation

10

Portrait Landscape

Page 11: Android Development for Different Screens and Devices Rohit Ghatol

Density Independent Pixel (dp)

11

160 DPI Screen 240 DPI Screen

1 dp = 1.5 pixels1 dp = 1 pixels

Page 12: Android Development for Different Screens and Devices Rohit Ghatol

Range

12

• 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

Page 13: Android Development for Different Screens and Devices Rohit Ghatol

Density Independence

13

px

dp

Page 14: Android Development for Different Screens and Devices Rohit Ghatol

Building for Different Screen Sizes

14

Page 15: Android Development for Different Screens and Devices Rohit Ghatol

<supports-screen>

15

Page 16: Android Development for Different Screens and Devices Rohit Ghatol

Screen Compatibility Mode

16

For Android 3.2 and above

Page 17: Android Development for Different Screens and Devices Rohit Ghatol

Screen Compatibility Mode

17

For Android 3.2 and above

Stretch to Fill Zoom to Fill

Page 18: Android Development for Different Screens and Devices Rohit Ghatol

18

Page 19: Android Development for Different Screens and Devices Rohit Ghatol

Compatibility Modes

android:requiresSmallestWidthDp•Small Width Required for this application to be installed on the given device•Currently Android Market does not use it

19

Page 20: Android Development for Different Screens and Devices Rohit Ghatol

Compatibility Modes

android:compatibleWidthLimitDp•Small Width supported by the application.•If Smallest Side of Device > compatibleWidthLimitDp, user is offered to run application in Compatibility mode

20

Page 21: Android Development for Different Screens and Devices Rohit Ghatol

Compatibility Modes

android:largestWidthLimitDpSmall Width supported by the application.•If Smallest Side of Device > largestWidthLimitDp, application is forced run application in Compatibility mode (without any option)

21

Page 22: Android Development for Different Screens and Devices Rohit Ghatol

Different Layouts

22

Page 23: Android Development for Different Screens and Devices Rohit Ghatol

UI Guidelines

• Keep Business logic separate• Keep Views independent• Keep Navigation logic out of Views

23

Page 24: Android Development for Different Screens and Devices Rohit Ghatol

< Android 3.1

• layout-small• layout-normal• layout-large• layout-xlarge

24

Page 25: Android Development for Different Screens and Devices Rohit Ghatol

>= Android 3.2

• layout-sw600dp• layout-w720dp• layout-h500dp

25http://developer.android.com/guide/practices/screens_support.html#DeclaringTabletLayouts

Now you can declare which layout to use at which width and not more vague partitions like layout-small, layout-normal, layout-large and layout-xlarge

Page 26: Android Development for Different Screens and Devices Rohit Ghatol

Different Bitmaps

26

Page 27: Android Development for Different Screens and Devices Rohit Ghatol

Drawable-Resolution

• drawable• drawble-nodpi – Not Scaled at all• drawable-ldpi ~ 120 dpi (.75x scale)• drawable-mdpi ~ 160 dpi (baseline scale)• drawable-hdpi ~ 240 dpi (1.5x scale)• drawable-xhdpi ~ 320 dpi (2x scale)

27

Page 28: Android Development for Different Screens and Devices Rohit Ghatol

Icon GuideLines

28

As of Android 3.0, Options menu has been superseded by Action bar

For Android 3.0+

Page 29: Android Development for Different Screens and Devices Rohit Ghatol

Menu Icons Guidelines

29For Android 2.3

Page 30: Android Development for Different Screens and Devices Rohit Ghatol

Status Bar Icons

30For Android 3.0+

Page 31: Android Development for Different Screens and Devices Rohit Ghatol

Status Bar Icons

31For Android 2.3

Page 32: Android Development for Different Screens and Devices Rohit Ghatol

Nine Patch Images

32

Page 33: Android Development for Different Screens and Devices Rohit Ghatol

Nine Patch Images

33

Page 34: Android Development for Different Screens and Devices Rohit Ghatol

Shapes XML

34

Page 35: Android Development for Different Screens and Devices Rohit Ghatol

35

Best part is these are Density Independent

Page 36: Android Development for Different Screens and Devices Rohit Ghatol

MultiResolution App

36

Page 37: Android Development for Different Screens and Devices Rohit Ghatol

37

Page 38: Android Development for Different Screens and Devices Rohit Ghatol

38

Page 39: Android Development for Different Screens and Devices Rohit Ghatol

Config Qualifier

39

Page 40: Android Development for Different Screens and Devices Rohit Ghatol

40

1. Mcc & mnc

2. Lang & Regionen,fr,en-rUS

3.Smallest WidthSw320dp,Sw600dp,sw720dp

4.Available WidthW720dp,w1024dp

5.Available HeightH720dp,h1024dp

6. ScreenSizesmall,normal,large,xlarge

7.Screen Aspectlong, notlong

8.Screen Orientport,land

9.Doc Modecar, desk

10.Night Modenight,notnight

11. DPIldpi,mdpi,ldpi,xldpi,tvdpi,nodpi

12.Touch Typenotouchstylusfinger

13.Keyboard Availabilitykeysexposedkeyshiddenkeyssoft

14.Primary Text Input Methodnokeysqwerty12key

15.Navigation key Availabilitynavexposednavhidden

16. Primary NonTouch Input Method

nonavdpadtrackballwheel

17. API Levelv3v4v7

Page 41: Android Development for Different Screens and Devices Rohit Ghatol

How Android finds best resource?

41

Page 42: Android Development for Different Screens and Devices Rohit Ghatol

42

Page 43: Android Development for Different Screens and Devices Rohit Ghatol

Available Resources

drawable/drawable-en/drawable-fr-rCA/drawable-en-port/drawable-en-notouch-12key/drawable-port-ldpi/drawable-port-notouch-12key/

43

Page 44: Android Development for Different Screens and Devices Rohit Ghatol

Device Configuration

Locale = en-GB Screen orientation = port Screen pixel density = hdpi Touchscreen type = notouch Primary text input method = 12key

44

Page 45: Android Development for Different Screens and Devices Rohit Ghatol

Step 1 Remove Contradictory Entry

45

Page 46: Android Development for Different Screens and Devices Rohit Ghatol

Step 2-5 Start Filtering

Locale = en-GB Screen orientation = port Screen pixel density = hdpi Touchscreen type = notouch Primary text input method = 12key

46

22

88

1111

1212

1414

## Config Precedence order

Page 47: Android Development for Different Screens and Devices Rohit Ghatol

Step 2- 5 Filter by Language

47

Page 48: Android Development for Different Screens and Devices Rohit Ghatol

Step 2-5 Filter by Orientation

48

Page 49: Android Development for Different Screens and Devices Rohit Ghatol

Building for Tablets & Handsets

49

Page 50: Android Development for Different Screens and Devices Rohit Ghatol

HoneyComb UI

New UI Elements•Fragments•Action Bar

50

Page 51: Android Development for Different Screens and Devices Rohit Ghatol

Before Fragments

51

Page 52: Android Development for Different Screens and Devices Rohit Ghatol

Before Fragments

52

Page 53: Android Development for Different Screens and Devices Rohit Ghatol

Let’s see some code

53

Page 54: Android Development for Different Screens and Devices Rohit Ghatol

Fragments Example

54

ActionBar

Fragment

ListFragment

Page 55: Android Development for Different Screens and Devices Rohit Ghatol

55Portrait Landscape

Afghanistan….Bhutan….Cuba….Germany

Afghanistan….Bhutan….Cuba….Germany

This Country is a Independent

State. The Capital is Kabul.

This Country is a Independent

State. The Capital is Kabul.

CountryList

CountryInfo

Afghanistan….Bhutan….Cuba….Germany

Afghanistan….Bhutan….Cuba….Germany

This Country is a Independent

State. The Capital is Kabul.

This Country is a Independent

State. The Capital is Kabul.

Activity

Fragment

Page 56: Android Development for Different Screens and Devices Rohit Ghatol

Afghanistan….Bhutan….Cuba….Germany

Afghanistan….Bhutan….Cuba….Germany

This Country is a Independent

State. The Capital is Kabul.

This Country is a Independent

State. The Capital is Kabul.

CountryListFragment CountryInfoFragment

OnCountrySelectedListenerOnCountrySelectedListener

void onCountrySelect(int position)

Page 57: Android Development for Different Screens and Devices Rohit Ghatol

Afghanistan….Bhutan….Cuba….Germany

Afghanistan….Bhutan….Cuba….Germany

CountryListFragment

OnCountrySelectedListenerOnCountrySelectedListener

void onCountrySelect(int position)

CountryListActivity

Country Select Event

Country Select Event

Page 58: Android Development for Different Screens and Devices Rohit Ghatol

58Portrait Landscape

Afghanistan….Bhutan….Cuba….Germany

Afghanistan….Bhutan….Cuba….Germany

This Country is a Independent

State. The Capital is Kabul.

This Country is a Independent

State. The Capital is Kabul.

CountryList

CountryInfo

Afghanistan….Bhutan….Cuba….Germany

Afghanistan….Bhutan….Cuba….Germany

This Country is a Independent

State. The Capital is Kabul.

This Country is a Independent

State. The Capital is Kabul.

Activity

Fragment

Send Intent

Directly Tell Fragment

Page 59: Android Development for Different Screens and Devices Rohit Ghatol

Let’s see some code

59

Page 60: Android Development for Different Screens and Devices Rohit Ghatol

ActionBar Example

60

Page 61: Android Development for Different Screens and Devices Rohit Ghatol

Let’s see some code

61

Page 62: Android Development for Different Screens and Devices Rohit Ghatol

But all this is for > Android 3.x

Welcome Android Compatibility Pack

62

Page 63: Android Development for Different Screens and Devices Rohit Ghatol

Android Compatibility Pack

• Provides limited support for HoneyComb widgets for pre 3.0 Android devices

• Support for Fragments present (with some api change)

• No Support for ActionBar

63

Page 64: Android Development for Different Screens and Devices Rohit Ghatol

Fragments on Android 2.x

64

Page 65: Android Development for Different Screens and Devices Rohit Ghatol

Let’s see some code

65

Page 66: Android Development for Different Screens and Devices Rohit Ghatol

What about ActionBar Support for Android 2.x

Welcome ActionBarSherlock

66

Page 67: Android Development for Different Screens and Devices Rohit Ghatol

ActionBarSherLock Example

67

Page 68: Android Development for Different Screens and Devices Rohit Ghatol

Let’s see some code

68

Page 69: Android Development for Different Screens and Devices Rohit Ghatol

Getting ready for Ice-cream sandwich

http://android-developers.blogspot.com/2011/09/

preparing-for-handsets.html

69

Page 70: Android Development for Different Screens and Devices Rohit Ghatol

What happens to Honey Comb Apps?

70

Make Apps Tablets Only Support Smaller Screens

Page 71: Android Development for Different Screens and Devices Rohit Ghatol

Make Apps Tablet Only

71

Page 72: Android Development for Different Screens and Devices Rohit Ghatol

Support Smaller Screens

72

Page 73: Android Development for Different Screens and Devices Rohit Ghatol

Support Smaller Screens

• Keep Business logic separate• Keep Views(Fragments) independent• Keep Navigation logic out of Views

(Fragments)

73

Page 74: Android Development for Different Screens and Devices Rohit Ghatol

ActionBar on Smaller Screens

• Use ifRoom instead of “always”• Provide icons for all action items and use

showAsAction=“ifRoom|withText”.

74

Page 75: Android Development for Different Screens and Devices Rohit Ghatol

ActionBar on Smaller Screens

75

Page 76: Android Development for Different Screens and Devices Rohit Ghatol

ListViews

• Use different layouts for list items for– Tablets (show more information)– Handsets (show less information)

76

Page 77: Android Development for Different Screens and Devices Rohit Ghatol

Making App work on all devices

77

Page 78: Android Development for Different Screens and Devices Rohit Ghatol

Maximum Reach, Assume nothing

78

Type/Capabilities

Telephony

2G/3G/4G

Wifi GPS Accelerometer/Compass

Camera

Phone Yes Yes Yes Yes Yes Yes

Tablets No Optional

Yes Yes Yes Yes

Google TV

No No Optional

No No Nohttp://www.google.com/events/developerday/2010/moscow/sessions/your-app-can-run-on-every-android.html

Page 79: Android Development for Different Screens and Devices Rohit Ghatol

Use <uses-feature> judiciary

In the Application Manifest: <uses-feature>•For any hardware your app uses •For any hardware which your app does NOT need to execute, explicitly specify a value of required=false•(Remember TV does not have telephony,GPS or Camera)

79

Page 80: Android Development for Different Screens and Devices Rohit Ghatol

Currently available Features to be declared by<uses-feature>:(see PackageManager class)

• CAMERA• CAMERA_AUTOFOCUS• CAMERA_FLASH• LOCATION• LOCATION_GPS• LOCATION_NETWORK• MICROPHONE• SENSOR_COMPASS• SENSOR_ACCELEROMETER• SENSOR_LIGHT SENSOR_PROXIMITY

• TELEPHONY • TELEPHONY_CDMA • TELEPHONY_GSM TOUCHSCREEN

TOUCHSCREEN_MULTITOUCH • TOUCHSCREEN_MULTITOUCH_DISTI

NCT• WIFI • BLUETOOTH

80

Page 81: Android Development for Different Screens and Devices Rohit Ghatol

Feature availability at runtime

• PackageManager.hasSystemFeature(FEATURE_NAME)

• Check if feature present then only expose the feature to end user (like menu item for it)

• Build a Degradable App

81

Page 82: Android Development for Different Screens and Devices Rohit Ghatol

Q & A

82

Page 83: Android Development for Different Screens and Devices Rohit Ghatol

More about Me• Twitter - http://twitter.com/#!/rohitghatol • TechGig -

http://www.techgig.com/rohitghatol • LinkedIn -

http://www.linkedin.com/in/rohitghatol• Presentations -

www.slideshare.net/rohitsghatol/ • YouTube Tutorials -

http://www.youtube.com/user/rohitssghatol