My study group slide in 2009 for Google Android Development, describing the following topics:
Designing the Obvious,
Resources and Internationalization,
Orientation,
Adapter,
How to Troubleshoot Apps for the Modern Connected Worker
Â
viWave Study Group - Introduction to Google Android Development - Chapter 23 ~ Chapter 29
1. viWave Study Group
Introduction to Google Android Development
Chap. 23~Chap.29
Ted Chien
#7151
ted.chien@viwav.com
Supervisory Engineer
viWave Co. Ltd.
2. Agenda
⢠Designing the Obvious
⢠Resource and Internationalization
⢠Orientation
⢠Adapter
⢠Spinner
⢠Signing Application Key
⢠Publish to Android Market
3. Designing the Obvious
Make It Simple and Easy-to-Use
ď Only provides features that users need.
ď Match user behaviors.
ď Help users to get advanced.
ď Easy to recover from mistakes.
ď Consistence UI elements.
5. Resources
All resource files are in /res folder.
Default folders for different resources:
Values: res/values/<filename>.xml
Layout: res/layout/<filename>.xml
Drawables: res/drawable/<filename>.png
What if we want to have customized
resources for different situations?
6. Resources
Resources can be used for different or specified
situations by setting different qualifiers in folder
name:
Mobile Country Code and Mobile Network Code.
Language Code and Region Code.
Screen types, dimensions, densities and orientations.
Touch screen types.
Keyboard states and types.
Navigation control types.
SDK version.
Possible resource folder name:
res/layout-zh-rTW-large-port-mdpi-finger-qwerty-dpad-
480x320/main.xml
7. Localization
Default: res/values/string.xml
If we need other languages:
res/values-<language-code>-r<region-code>/string.xml
Language code (ISO-639): en, ja, zh,...
Region code (ISO-3166): US, UK, CN, TW,....
Example:
Chinese (Taiwan): res/values-zh-rTW/string.xml
Chinese (PRC): res/values-zh-rCN/string.xml
8. Change UI Locale
Change by UI:
Menu -> Settings -> Locale & Text -> Select Locale
Change by Code:
Resources res = getResources();
Configuration config = res.getConfiguration();
config.locale = Locale.TRADITIONAL_CHINESE; // or Locale.TAIWAN;
DisplayMetrics dm = res.getDisplayMetrics();
res.updateConfiguration(config, dm);
9. Writing code for different
Locales
Resources res = getResources();
Configuration config = res.getConfiguration();
if (config.locale == Locale.TRADITIONAL_CHINESE) {
// do something related to Traditional Chinese;
}
10. Screen Layout and Orientation
Orientation Navigation
Portrait: port notouch
Landscape: land dpad
Square: square trackball
wheel
Touch Screen Type
notouch Resolution
finger 320x240 (QVGA)
stylus 320x480 (HVGA)
400x800
Text Input 400x854
nokeys
qwerty
12key (numbers)
11. Screen Layout and Orientation
Sample: T-Mobile G1
Normal: port-finger-trackball-320x480
Slide out the keyboard: land-finger-qwerty-trackball-320x480
When screen orientation is changed, activity will be re-created
because device configuration is changed.
Solution:
Use SharedPreferences to keep settings in onPause() / onStop().
12. Screen Layout and Orientation
How to fix the screen orientation?
AndroidManifest.xml
Add android:screenOrientation value to <activity> tag.
Values: portrait, landscape, sensor.
In code:
Import android.content.pm.ActivityInfo;
Call setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE )
or
setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ) in
activity.
13. Adapter
Act as an bridge between AdapterView and the data for the
view.
Provides access to different types of data via single interface
to the view.
Types
ArrayAdapter
SimpleAdapter (read array from XML file)
CursorAdapter (read array from content provider)
14. ArrayAdapter
How to Define String Array?
By code
static final String[] strArray = new String[] {
âitem1â,
âitem2â,
âŚ
};
ArrayAdapter<CharSequence> adapter_string = new
ArrayAdapter<String>(this, android.R.layout.simple_list_item,
strArray);
15. ArrayAdapter
How to define string array?
By XML
res/values/string.xml
<resource>
<string-array name=âstrArrayâ>
<item>1st</item>
âŚ.
</string-array>
</resource>
Code:
ArrayAdapter<CharSequence> adapter_string =
ArrayAdapter.createFromResource( this, R.array.strArray,
andorid.R.layout.simple_list_item);
16. Spinner
Spinner is like pull-down menu.
How to add a Spinner?
Layout XML
Add Spinner control.
Set android:drawSelectorOnTop=âtrueâ.
Set android:prompt with title string id.
Code
Call getViewbyId() to get the view and cast to Spinner.
Create ArrayAdapter instance to prepare the data.
Call ArrayAdapter.setDropDownViewResource() to make the resource
of the Drop-Down view.
Set the data adapter to the Spinner control.
17. Spinner
How to select an item in Spinner?
private Spinner.OnItemSelectedListener select = new
Spinner.OnItemSelectedListener() {
public void onItemSelected(AdapterView parent, View v, int position, long id)
{
// something selected.
}
public void onNothingSelected(AdapterView parent) {
// nothing selected.
}
}
Call setOnItemSelectedListener(select) to set the listener to the Spinner control so it
can listen to user behaviors.
After selection, use Spinner.getSelectedItemPosition() to get the selected count.
Select item by code: Spinner.setSelection().
Sample: API Demo - Spinner
19. Things to Know
All applications must be signed.
We can use self-signed certificates to sign applications.
Must sign application with private key before releasing the
application.
System will check certificateâs expiration date at install time.
Signing tool: Keytool and Jarsigner, all in JDK.
After application is signed, we can use zipalign tool to
optimize the apk file.
20. Signing Strategy
Sign all applications with the same certification, throughout
the lifespan of the applications (25 years suggested).
Reasons:
Users can upgrade application seamlessly.
New certification would require new package name, system would
consider your AP as an new one.
APs can run in the same process, and will be treated as single AP.
APs can share code/data with each other.
If AP will be released to Android Market, the valid date of
the certification must be later than October 22, 2033.
21. Signing the Application
Export the unsigned We can do this by using
APK. the Export Wizard in
Eclipse!
Obtain the signing key.
We can also do this by
Signing the key. exporting signed APK in
Package Explorer in
Verifying the key.
Eclipse!
Install the Application
Publish the Application
22. Checking List in
AndroidManifest.xml
⢠Version defined correctly?
â android:versionCode
â android:versionName
⢠Activities defined correctly?
⢠Permissions defined correctly?
⢠SDK version defined correctly?
â android:minSDKVersion
â android:targetSDKVersion (optional)
â android:maxSDKVersion (optional)
24. Methods to Release
Applications
⢠Publish to Android Market.
⢠Publish to 3rd-Party Market.
â SlideMe: http://www.slideme.org
â Camangi Market (for Camangi
WebStation):http://www.camangimarket.com/
â FET Smart Market: http://www.smartapp.tw
â ChinaMobile Mobile Market: http://www.mmarket.com
â AndAppStore: http://andappstore.com
⢠Put it on our own website for download.
25. How Android Market Works?
⢠Just upload signed Program.apk to Android Market and click
on Publish, users will see the application to download
immediately.
⢠Revenue Sharing:
â Paid AP Developer: 70%
â Operators and e-Commerce Providers: 30%
⢠Users can refund paid application in 24 hours.
26. How to Register for Android
Market?
⢠Registration Fee: USD 25 for lifetime.
⢠Where to register for Android Market?
â http://market.android.com/publish
⢠Must have Google account.
⢠Must pay the registration fee via Google Checkout.
⢠Must use international cell phone number.
27. How to Upload AP to Android
Market?
⢠Must upload Release mode and signed APK file.
⢠Can publish through different locales, countries, operators,
and categories.
28. Managing AP on Android
Market
⢠We can see how many applications we have published.
⢠We can also see how many downloads and ratings of our
applications on Android Market.
⢠We can view user comments on our applications through 3rd-
Party website:
â Cyket: http://www.cyket.com
â aTrackDog: http://atrackdog.a0soft.com
â Android Stats: http://androidstats.com/ranking/applications