[Droidcon]Developing Apps for Android on 2.x/3.x/4.x
1. Droidcon London 2012
Developing Apps
for Android on 2.x/3.x/4.x
Kenichi Kambara (@korodroid)
October 26, 2012
2. Who am I?
l Kenichi Kambara (Twitter @korodroid)
l iplatform.org(http://www.iplatform.org/) (Personal)
l NTT Software Corporation (Official)
l Activity(iplatform.org as Personal)
- My Android Apps on Google Play (20+ Apps)
9 10
2
3. Who am I?
l Kenichi Kambara (Twitter @korodroid)
l iplatform.org(http://www.iplatform.org/) (Personal)
l NTT Software Corporation (Official)
l Activity(iplatform.org as Personal)
-
My Android Apps on Google Play (20+ Apps)
9 10
“Sekai Phone”
l Google Developer Day 2011 Tokyo Keynote Demo
l Google Android Developer Lab Tokyo 2011 5th prize
3
7. What is “Sekai Phone”?
Real time translation phone services
(Supports Android 2.x/3.x/4.x & multi devices)
)
English German
Japanese
○
○
○
Italian
French
○
○
Chinese
Publishe Date: Jan, 2010, over 20+ ver.up
7
8. Use Case (1)
Phone mode
(Auto translating to receiver’s native language)
English Japanese
Hello!
Talking
Konnichiwa!
Talking
Paul
Kenichi
Thanks! Arigatou!
8
9. Use Case (2)
Talk mode
(Auto translating on the spot)
English Japanese
9
10. App Demos (1.Phone mode)
English Japanese
Hello!
Talking
Konnichiwa!
Talking
Paul
Kenichi
Thanks! Arigatou!
10
18. Platform Versions?
Honeycomb
ICS
JB
Gingerbread
Others
Froyo
This data by Google on October 1, 2012
In my App:
Main Target: Android 2.2+ (2.2,2.3,3.x,4.x)
18
19. Screen Sizes & Densities?
xhdpi
Normal
Small
ldpi
Xlarge
hdpi
Large
mdpi
This data by Google on October 1, 2012
19
20. Screen Sizes & Densities?
This data by Google on October 1, 2012
In my App:
Main Target: (normal,large,xlarge)x(mdpi,hdpi,xhdpi)
20
26. Support multi versions and multi devices?
1.Designing User Interface
l Screen size
l Screen density
l Screen orientation
…
2.Using APIs
l Fragment
l Menu
… 26
28. [UI]1 st Approach
Using layout-small/normal/large/xlarge
Screen Size
Classification
l Supports Android 1.6+
l Both 7” tablet and 5” handset mapped to “large”
l Pre 3.0 some devices mis-classified
28
33. [UI]2 nd Approach
Using sw<N>dp,w<N>dp,h<N>dp
(a)layout-sw600dp Width & Height ≥ 600dp
(b)layout-w720dp Width ≥ 720dp
(c)layout-h480dp Height ≥ 480dp
l Recommended by Google
l Supports only Android 3.2+
Note: Effect by Screen Orientation
33
34. [UI]3 rd Approach
Combination of 1st and 2nd
l res/layout-sw600dp/main.xml <- 3.2+ tablets
l res/layout-xlarge/main.xml <- 3.0/3.1 tablets
l res/layout/main.xml <- The others (Handsets)
l Supports Android 1.6
l Supports many devices (compared to 1st or 2nd)
l Any Problem?
34
35. [UI]3 rd Approach
It looks good but…
l res/layout-sw600dp/main.xml <- 3.2+ tablets
l res/layout-xlarge/main.xml <- 3.0/3.1 tablets
l res/layout/main.xml <- The others (Handsets)
• Needs to put the same file for tablets.
(Maintenance headache…)
35
36. [UI]3 rd Approach
It looks good but…
if ([Size is xlarge] or [width & height is at least 600dp])
// codes for tablets
}else{
// codes for others
}
• Complicated Java codes
(Development is complicated…)
36
38. [UI]4 th Approach
Based on 3rd , plus some tips
• Put minimum requirement
for layouts
38
39. [UI]4 th Approach
Based on 3rd , plus some tips (Layout Aliases)
// for Tablets
<resources>
<item name "main_layout" type="layout">
@layout/main_twopanes
</item>
<bool name="has_two_panes">
true
</bool>
</resources> 39
40. [UI]4 th Approach
Based on 3rd , plus some tips (Layout Aliases)
// for Tablets
<resources>
<item name "main_layout" type="layout">
@layout/main_twopanes
</item>
<bool name="has_two_panes">
true
</bool>
</resources>
boolean hasTwoPanes =getResources().
getBoolean(R.bool.has_two_panes);
if (hasTwoPanes)
…
• Simple Java codes
40
42. [API]Fragment
Using Support Library?
2.x
3.x
4.x
Without
Support Library
With
Support Library
42
43. [API]Fragment
Comparing Using with No-Using
With Without
Support Library
Support Library
• android.support.v4.Fragment
• android.app.Fragment
Class
• android.support.v4.FragmentActivity
• android.app.Activity
…
…
• getSupportFragmentManager() • getFragmentManager()
Method
(FragmentActivity)
(Activity)
…
…
43
44. [API]Options Menu vs Action Bar
Action Bar is good…
2.x
3.x
4.x
Options Menu
Action Bar
Note: ActionBarSherlock lib, Effect by style
44
51. [API]Multi-Versioning
How to use the newest API on Single APK
Reflection Well known approach
Lazy loading One of Design Patterns
51
52. [API]Multi-Versioning
How to use the newest API on Single APK
Reflection Well known approach
Lazy loading One of Design Patterns
In my App:
Compatibility with Lazy loading
52
53. [API]Multi-Versioning
Code Examples of Lazy loading
1 st step
public
abstract
class
NotificationUtilAbstract
{
public
static
NotificationUtilAbstract
newInstance()
{
NotificationUtilAbstract
instance
=
null;
if
(Integer.parseInt(Build.VERSION.SDK)=
16)
{
instance
=
new
NotificationUtilJB();
}
else
{
instance
=
new
NotificationUtilDefault();
}
return
instance;
}
public
abstract
void
showCaller;
} 53
54. [API]Multi-Versioning
2 nd step
public
class
NotificationUtilJB
extends
NotificationUtilAbstract{
@Override
public
void
showCaller(){
//
Code
by
Jelly
Bean
(API
16)
}
}
public
class
NotificationUtilDefault
extends
NotificationUtilAbstract{
@Override
public
void
showCaller(){
//
Code
by
Old
API
}
• Compatible
}
54