Android Application Development Advanced

40 %
60 %
Information about Android Application Development Advanced
Technology

Published on March 10, 2014

Author: OESF_Education

Source: slideshare.net

Description

OESF Authorized Training Course official textbook
Course: Android Application Development Advanced
Language: English


Contributed by
Created by: TOPGATE Inc.
Edited by: ISB Vietnam Co.,Ltd.

[Attention!]
This textbook is licensed under the Creative Commons License BY-NC-SA 4.0. It is prohibited to use this material for commercial use otherwise you are OESF member or OESF education consortium member.

Android Application Development Practical Training Course This material is licensed under the Creative Commons License BY-NC-SA 4.0. Ver2.00(03) 1

About textbook usage 2 This material is licensed under the Creative Commons License BY-NC-SA 4.0. ・This textbook is licensed under the Creative Commons License BY-NC-SA 4.0. It is prohibited to use this material for commercial use otherwise you are OESF member or OESF education consortium member. ・This training program including all the provided documents are provided without any warranty from OESF. OESF assume no responsibility whatsoever for any damages/ occurrence of legal action resulting from the use or misuse of this course content/ detailed information of course.

• To learn the practical knowledge, technology in developing Android application – Component of Android – Practical development • To bring up the power of execution in application development through seminar. – The main purpose is the developing skill 3 This material is licensed under the Creative Commons License BY-NC-SA 4.0. Purpose of training course

Training schedule • The 1st day – Chapter 1 Introduction – Chapter 2 Android component – Chapter 3 Practical development • The 2nd day – Chapter 4 Practical development 2 – Chapter 5 Outside solidarity – Chapter 6 Practical debug – Chapter 7 Summary 4 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

The necessary skills for attending this course • Unless attended OESFcertificated Android application development basic training course, need following skills: – Precondition: having the basic skills of Android application – Be able to create the a simple application with several screens – Understand the syntax of JavaSE briefly and have actual experience – Understand the basic Eclipse operations 5 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

1. Introduction 6 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

Chapter 1 - Outline • Development environment • Practice used in this course • Practice outline 7 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

1.1. Development environment • In this training course, the following development tools will be used • They are installed already • The path is ready for running on the tools of SDK 8 Software Version Integrated development environment Eclipse 3.5 (Galileo) Java SDK JDK 6 Update 21 Android SDK 2.2 Android Plug-in Android Development Tools (ADT) Ver.0.9.6 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

1.1. Development environment • Eclipse workspace Specify C:android_training_appliedworkspace • Emulator The emulator used for practicing will be WVGA-normal-hdpi if no particular one is specified • SDK path C:android_trainingtoolsandroid-sdk-windows This material is licensed under the Creative Commons License BY-NC-SA 4.0. 9

1.2. Application used in practice • In the 1st day of practice, the RSS reader created in Android application development basic training course will be added with extension 10 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

• Outline of screens & functions of RSS reader – This includes 3 screens This material is licensed under the Creative Commons License BY-NC-SA 4.0. 11 Start up # Screen name Function outline 1 Menu • Start up List view • Display option menu • When open menu is clicked, get RSS feed from Internet and register to database • After getting RSS feed, display the finish message by dialog 2 List • Display the RSS feed registered in database in list type 3 Detail • Display title, distributed date time, distributor name, detailed content of the RSS feed selected in list view 1.2. Application used in this course RSS reader ・・・ Direction of screen transition ① Menu screen ② List screen ③ Detail screen

1.3. Practice outline This material is licensed under the Creative Commons License BY-NC-SA 4.0. 12 Internet Database Get RSS feed from Internet Register RSS feed to database Search RSS feed from database Click List displaying button Select list data Display dialog after registering to database Get with service Start the processing with broadcast receiver Access with content provider Display notification of getting finished Multi resolution Support multi-language Menu screen List screen Detail screen

1.3. Practice outline Table layout – RSS_FEED table This material is licensed under the Creative Commons License BY-NC-SA 4.0. 13 String name type remarks _id INTEGER • Primary key • Auto increment GUID TEXT • Identifier allocated to RSS fee TITLE TEXT • Title PUBLISH_DATE TEXT • Distributed date time DESCRIPTION TEXT • Detailed content LINK TEXT • Link SENDER_NAME TEXT • Name of distributor

2. Android component 14 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

Chapter 2 - Outline • Activity • Intent • Service • Broadcast receiver • Content provider ※ Only consolidate on Activity and Intent The others will be practiced after the lecture 15 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

2.1. Activity • What is activity? – The Android application screen is created by placing many parts such as Button, Checkbox, … on Activity – 1 screen is constructed based on 1 activity – Activity has 2 status: running and pausing 16 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

• Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 17 package jp.oesf.mtgeduwg.training.rssreader; import android.app.Activity; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; public class RssReaderActivity extends Activity implements OnClickListener { public void onClick(View view) { Log.v("RssReaderActivity","Clicked"); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); View listButton = findViewById(R.id.list_button); listButton.setOnClickListener(this); } } • Set Activity class as super class • Execute call back method if needed 2.1. Activity

• Sample code of AndroidManifest.xml This material is licensed under the Creative Commons License BY-NC-SA 4.0. 18 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="jp.oesf.mtgeduwg.training.rssreader" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"> ・・・ <activity android:label="@string/app_name" android:name="RssListActivity"></activity> </application> <uses-sdk android:minSdkVersion=“7" /> <uses-permission android:name="android.permission.INTERNET"></uses-permission> </manifest> •Creates the tag name as activity tag •Specify attribute android:name=“activity name” 2.1. Activity

• [Ref] Life cycle which includes the notified events 19 This material is licensed under the Creative Commons License BY-NC-SA 4.0. 2.1. Activity

This material is licensed under the Creative Commons License BY-NC-SA 4.0. 20 • [Ref] It is possible to set AndroidManifest.xml with resource editor 2.1. Activity

2.2. Intent • What is intent? – The mechanism for requesting process or exchanging message between components • The components which can use intent are activity, broadcast receiver, service – Intent use cases • Start up activity B from activity A(screen transition) • Request telephone call to the application of calling from Address book application 21 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

2.2. Intent • When component is called by intent, in the intent the calling destination component information will be added and request to Android – Example of calling component B from component A 22 This material is licensed under the Creative Commons License BY-NC-SA 4.0. B is started up

2.2. Intent • Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 23 package jp.oesf.mtgeduwg.training.rssreader; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; public class RssReaderActivity extends Activity implements OnClickListener { ・・・・・・・・ public void onClick(View view) { if (R.id.list_button == view.getId()) { Intent intent = new Intent(this, RssListActivity.class); startActivity(intent); } } } •Generate object of intent •Pass intent

2.3. Service • What is service? – The mechanism for the processing by the independent thread – Service is implemented by the thread different with activity of foreground. Therefore, even the interruption occurs by other activity the processing can be continued 24 This material is licensed under the Creative Commons License BY-NC-SA 4.0. Play music (not use Service) Play music (use Service) The difference in operating when Activity interrupt occurred by receiving mail in case of playing music directly from Activity or through service.

2.3. Service • How to implement service – Create newly service – Register the created service to AndroidManifest.xml – Start the created service by startService method This material is licensed under the Creative Commons License BY-NC-SA 4.0. 25

2.3. Service • How to implement service 1. Create new service class • Create the service class inherited from Service base class • It is necessary to implement abstract onBind method. Binding is not used here, so null is returned Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 26 import android.app.Service; import android.content.Intent; import android.os.IBinder; public class SampleService extends Service { @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } } ・・・1

2.3. Service 2. Implement call back method if needed • There are 3 methods: onCreate, onStart, onDestroy • Recognize life cycle and implement appropriately • onStart will be called each time when starting • The other 2 methods will be called once when creating and destroying object This material is licensed under the Creative Commons License BY-NC-SA 4.0. 27 # Events name Content 1 onCreate The event occurs in the first startup 2 onStart The event occurs just before the Service is started 3 onDestroy The event occurs just before the Service is destroyed

2.3. Service • Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 28 @Override public void onCreate() { super.onCreate(); Log.v(“SampleService", "onCreate"); } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Thread t = new Thread() { @Override public void run() { try { Thread.sleep(5 * 1000); } catch (InterruptedException e) { Log.e("RegisterService", e.toString()); } } }; t.start(); } @Override public void onDestroy() { super.onDestroy(); Log.v(“SampleService", "onDestroy"); } ・・・2

2.3. Service 2. Register the created service in AndroidManifest.xml • Creating steps i. Open AndroidManifest.xml and select Application tab ii. Click [Add] button of Application Nodes This material is licensed under the Creative Commons License BY-NC-SA 4.0. 29 i ⅱ

2.3. Service iii. Select Service from the displayed screen, click 「OK」 button ※ In case cursor is in the registered node, the layer will be checked, so please select upon radio button This material is licensed under the Creative Commons License BY-NC-SA 4.0. 30 ⅲ ※

2.3. Service iv. After checking that the added service is selected, input name of class of the service created in [Name] field This material is licensed under the Creative Commons License BY-NC-SA 4.0. 31 ⅳ Clicking Browse button, browsing is convenient

2.3. Service ※ The following will be added to AndroidManifest.xml The class of service becomes registered by this Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 32 ・・・ <application ・・・> ・・・ <service android:name=“SampleService"></service> ・・・ </application> ・・・

2.3. Service 3. Start up the created service by startService method i. Create new intent object by setting to the argument of Intent the calling source object and the class of calling destination service ii. Execute Context#startService. Set Intent object created in i. to argument of method • Sample code (extracted from code of activity) This material is licensed under the Creative Commons License BY-NC-SA 4.0. 33 Intent intent = new Intent(this, SampleService.class); startService(intent); ・・・ⅰ ・・・ⅱ

Practice 2.3. Service Practice 1 • Practice theme – In menu screen, create the processing of starting RSS getting method with service when pushing 「menu」 button => 「Get RSS」 button This material is licensed under the Creative Commons License BY-NC-SA 4.0. 34 Screen can be operated as it is Started as service No affect to screen

Practice 2.3. Service Practice 1 • Steps: 1. Create new service RegisterService class 2. Get RSS with onStart method of RegisterService 3. Output log of starting/ending to RegisterService#onStart • Tag:「 RegisterService 」 • Message:when starting 「onStart start」 and when ending 「onStart end」 4. Delete logic of RSS getting existed in onOptionsItemSelected method of RssReaderActivity, use Intent to call RegisterService 5. Output log of starting/ending to RssReaderActivity#onOptionsItemSelected • Tag: 「 RssReaderActivity 」 • Message:「onOptionsItemSelected start」 and 「onOptionsItemSelected end」 6. Add setting of RegisterService to AndroidManifest.xml This material is licensed under the Creative Commons License BY-NC-SA 4.0. 35

Practice 2.3. Service Practice 1 – Setting information 1 • Execute the following class, method This material is licensed under the Creative Commons License BY-NC-SA 4.0. 36 Target Class Method Outline Service RegisterService • Create newly • Package is jp.oesf.mtgeduwg.training.rssreader onStart • Get RSS • Output starting & ending log Menu screen RssReaderActivity onOptionsItemSelected • Delete the existed RSS getting log • Start RegisterService • Output starting & ending log

Practice 2.3. Service Practice 1 – Setting information 2 • Edit the following file This material is licensed under the Creative Commons License BY-NC-SA 4.0. 37 File name Outline AndroidManifest.xml • Register RegisterService as service

Practice 2.3. Service Practice 1 • How to check – When pushing 「Get RSS」 button, the following log output will be checked with LogCat • RegisterService#onStart – Starting log 「onStart start 」 – Ending log 「 onStart end」 • RssReaderActivity#onOptionsItemSelected – Starting log 「onOptionsItemSelected start 」 – Ending log 「 onOptionsItemSelected end」 – Close log of RssReaderActivity#onOptionsItemSelected will be checked with the output after close log of RegisterService#onStart This material is licensed under the Creative Commons License BY-NC-SA 4.0. 38

Practice 2.3. Service Practice 1 • Answer of Practice – RegisterService This material is licensed under the Creative Commons License BY-NC-SA 4.0. 39 package jp.oesf.mtgeduwg.training.rssreader; import jp.oesf.mtgeduwg.training.rssreader.helper.RssFeedRegister; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.util.Log; public class RegisterService extends Service { @Override public IBinder onBind(Intent intent) { return null; } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); Log.v("RegisterService", "onStart start"); new RssFeedRegister(this).registration("http://www.oesf.jp/modules/news/index.php?page=rss"); Log.v("RegisterService", "onStart end"); } }

Practice 2.3. Service Practice 1 • Answer of Practice – RssReaderActivity (Only the corresponding part extracted) This material is licensed under the Creative Commons License BY-NC-SA 4.0. 40 ・・・ @Override public boolean onOptionsItemSelected(MenuItem item) { Log.v("RssReaderActivity", "onOptionsItemSelected start"); if (item.getItemId() == R.id.main_menu_add) { // new RssFeedRegister(this).registration("http://www.oesf.jp/modules/news/index.php?page=rss"); // new AlertDialog.Builder(this).setTitle(R.string.ok_dialog_label).show(); Intent intent = new Intent(this, RegisterService.class); startService(intent); Log.v("RssReaderActivity", "onOptionsItemSelected end"); return true; } return false; } ・・・

Practice 2.3. Service Practice 1 • Answer of Practice – AndroidManifest.xml (Only the corresponding part extracted) This material is licensed under the Creative Commons License BY-NC-SA 4.0. 41 ・・・ <application> ・・・ <service android:name="RegisterService"></service> ・・・ </application> ・・・

Practice 2.3. Service Practice 1[Supplement] • Practice theme – Use toast to notify that service processing is completed This material is licensed under the Creative Commons License BY-NC-SA 4.0. 42 Screen will be operated as it is Service logic Toast will be explained from the next page

Practice 2.3. Service • What is toast? – The function to display message on screen for a short time – This is the function for displaying message only and can not operate combining with cursor – It is convenient if you use the component without UI such as service This material is licensed under the Creative Commons License BY-NC-SA 4.0. 43

Practice 2.3. Service • Execute toast – Use 1 of the 2 methods as below: public static Toast makeText (Context context, CharSequence text, int duration) public static Toast makeText (Context context, int resId, int duration) + context: context + text: the displayed text resId: the resource ID of the displayed text + duration: Toast.LENGTH_SHORT (short time) or Toast.LENGTH_LONG(long time) – For the return value of the above methods, it is displayed that Toast#show method is implemented Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 44 Toast.makeText(this, “TEST", Toast.LENGTH_SHORT).show(); Toast.makeText(this, R.string.test, Toast.LENGTH_LONG).show();

Practice 2.3. Service Practice 1[Supplement] 1. When service logic is completed, try to display the favorite message with toast 2. Change duration and check if the display time is changed or not 3. Try to use all makeText methods with the different 2nd argument This material is licensed under the Creative Commons License BY-NC-SA 4.0. 45

2.4. Broadcast receiver • What is broadcast receiver? – Broadcast receiver is the mechanism to response the broadcasted intent – Can inherit broadcast receiver class to create the original broadcast receiver 46 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

2.4. Broadcast receiver • Use cases of broadcast receiver – Check mail when starting Android device 1. Receive broadcast intent when starting Android device completed with broadcast receiver ※ Describe IntentFilter in AndroidManifest.xml about receiving which broadcast intent 2. Call mail checking service from broadcast receiver ※ It is possible to check mail directly from broadcast receiver, but in case of long time processing it is better to use service 47 This material is licensed under the Creative Commons License BY-NC-SA 4.0. Broadcast receiver Send broadcast intent Send intent ② Execute mail checking service Intent ① Starting completed message Intent Mail checking service

2.4. Broadcast receiver • How to implement service – Create newly broadcast receiver class – Register the created broadcast receiver to AndroidManifest.xml This material is licensed under the Creative Commons License BY-NC-SA 4.0. 48

2.4. Broadcast receiver • How to implement broadcast receiver 1. Create newly broadcast receiver class • Create the class inherited from BroadcastReceiver base class • It is necessary to implement abstract onReceive method • Implement actual process which you want in onReceive method • Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 49 import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class SampleStarter extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent serviceIntent = new Intent(context, SampleService.class); context.startService(serviceIntent); } } ・・・1

2.4. Broadcast receiver ※ In case you want to divide the processing according to the receiving intent, check if which intent will be received by checking action caused by Intent#getAction, and describe the divided processing Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 50 import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class SampleStarter extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){ Intent serviceIntent = new Intent(context, SampleService.class); context.startService(serviceIntent); } } } ・・・※

2.4. Broadcast receiver 2. Register the created broadcast receiver to AndroidManifest.xml • Steps i. Open AndroidManifest.xml, select Application tab ii. Click [Add] button of Application Nodes This material is licensed under the Creative Commons License BY-NC-SA 4.0. 51 ⅰ ⅱ

2.4. Broadcast receiver iii. Select Receiver from the displayed screen and click 「OK」 button This material is licensed under the Creative Commons License BY-NC-SA 4.0. 52 ⅲ

2.4. Broadcast receiver iv. After checking if the added receiver is selected or not, input the name of the created broadcast receiver into Name field This material is licensed under the Creative Commons License BY-NC-SA 4.0. 53 ⅳ It is convenient if you click Browse button

2.4. Broadcast receiver v. After checking if the added receiver is selected or not, click 「Add」 button This material is licensed under the Creative Commons License BY-NC-SA 4.0. 54 ⅴ

2.4. Broadcast receiver vi. After checking if the lower radio button is selected on the displayed screen or not, select Intent Filter and click 「OK」 button This material is licensed under the Creative Commons License BY-NC-SA 4.0. 55 ⅵ

2.4. Broadcast receiver vii. After checking if the added Intent Filter is selected or not, click 「Add 」 button This material is licensed under the Creative Commons License BY-NC-SA 4.0. 56 ⅶ

2.4. Broadcast receiver viii. After checking if the lower radio button is selected on the displayed screen or not, select Intent Filter and click 「OK」 button This material is licensed under the Creative Commons License BY-NC-SA 4.0. 57 Ⅷ

2.4. Broadcast receiver ix. After checking if the added receiver is selected or not, input name of class of the created service into Name field This material is licensed under the Creative Commons License BY-NC-SA 4.0. 58 Can select by pull down ⅸ

2.4. Broadcast receiver ※ It is added to AndroidManifest.xml as below: In the following, broadcast intent of android.intent.action.BOOT_COMPLETED is captured and the service class – SampleServiceStart is started up Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 59 ・・・ <application ・・・> ・・・ <receiver android:name=“SampleServiceStarter"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"></action> </intent-filter> </receiver> ・・・ </application> ・・・

Practice 2.4. Broadcast receiver Practice 2 • Practice theme – When system finished starting, create the starting processing for RSS getting method with service This material is licensed under the Creative Commons License BY-NC-SA 4.0. 60 System finished starting Start as service No impact to screen

Practice 2.4. Broadcast receiver Practice 2 • Steps 1. Create newly RegisterServiceStarter class which is the broadcast receiver 2. Call RegisterService with onReceive method of RegisterServiceStarter#onReceive 3. Add setting of RegisterServiceStarter to AndroidManifest.xml • Register RegisterServiceStarter as broadcast receiver • As setting of Intent Filter of RegisterServiceStarter, set android.intent.action.BOOT_COMPLETED(starting completed) to Action This material is licensed under the Creative Commons License BY-NC-SA 4.0. 61

Practice 2.4. Broadcast receiver Practice 2 – Setting information • Execute the following class, method This material is licensed under the Creative Commons License BY-NC-SA 4.0. 62 Target Class Method Outline Broadcast receiver RegisterServiceStart er • Create newly • Package is jp.oesf.mtgeduwg.training.rssreader onReceive • Start up RegisterService

Practice 2.4. Broadcast receiver Practice 2 – Setting information 2 • Edit the following file This material is licensed under the Creative Commons License BY-NC-SA 4.0. 63 File name Outline AndroidManifest.x ml • Register RegisterServiceStarter as service • As setting of Intent Filter, set android.intent.action.BOOT_COMPLETED (starting completed) to Android

Practice 2.4. Broadcast receiver Practice 2 • How to check – After starting application once, close emulator once, and re-start. Check if the log at that time output or not • RegisterService#onStart – Starting log 「onStart start 」 – Ending log 「 onStart end」 This material is licensed under the Creative Commons License BY-NC-SA 4.0. 64

Practice 2.4. Broadcast receiver Practice 2 • Answer of Practice – RegisterServiceStarter This material is licensed under the Creative Commons License BY-NC-SA 4.0. 65 package jp.oesf.mtgeduwg.training.rssreader; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; public class RegisterServiceStarter extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { if(Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){ Intent serviceIntent = new Intent(context, RegisterService.class); context.startService(serviceIntent); } } } ※This case only 1 intent will come, so it is ok with non-if statement

Practice 2.4. Broadcast receiver Practice 2 • Answer of Practice – AndroidManifest.xml (Only the corresponding part extracted) This material is licensed under the Creative Commons License BY-NC-SA 4.0. 66 ・・・ <application> ・・・ <receiver android:name="RegisterServiceStarter"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"></action> </intent-filter> </receiver> ・・・ </application>

Practice 2.4. Broadcast receiver Practice 2[Supplement] 1. Check code of SendBroadcast project, check if the broadcast of the given action will be thrown or not when pushing button of this application. 2. For that action, modify the file of RssReader project in order to start RegisterServiceStarter 3. After starting RssReader, check with log if service of RssReader started or not when starting SendBroadcast and pushing button This material is licensed under the Creative Commons License BY-NC-SA 4.0. 67

2.5. Content provider • What is content provider? – The mechanism which can access (search, add, update, delete the data kept by application※ from other application – Detailed example: • Refer the telephone call log from application • Add Website from application to bookmark of browser • Refer the address book from application • Refer calendar from application ※Data is the information shown by application in file, database permanently 68 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

2.5 Content provider • Content provider will decide interface in order to execute the safe accessing – Main interface 69 Content provider query insert update delete External application Interface is decided# Event name Content 1 Search (query) Search data, return searching result 2 Add (insert) Add data 3 Update (update) Update data 4 Delete (delete) Delete data This material is licensed under the Creative Commons License BY-NC-SA 4.0. ■Refer to development guide for Android Developers http://developer.android.com/intl/ja/reference/android/content/ContentProvider.html

2.5 Content provider • How to implement content provider – Create newly class of content provider – Implement the abstract method of content provider if needed – Register the created content provider to AndroidManifest.xml This material is licensed under the Creative Commons License BY-NC-SA 4.0. 70

2.5 Content provider • How to implement content provider 1. Create new content provider class • Create the content provider class inherited from ContentProvider base class • The following 6 methods are defined as the abstract methods of ContentProvider class, so all methods are supposed to be implemented This material is licensed under the Creative Commons License BY-NC-SA 4.0. 71 Method Return value type Outline onCreate boolean • Run when starting content provider • When provider initialization is stopped abnormally, true will be returned getType String • Return the handling text string in MIME type query cursor • Search • Return result as Cursor object Insert int • Insert • Return the inserted number update int • Update • Return the updated number delete int • Delete • Return the deleted number

2.5 Content provider This material is licensed under the Creative Commons License BY-NC-SA 4.0. 72 import android.content.ContentProvider; import android.content.ContentValues; import android.database.Cursor; import android.net.Uri; public class SampleProvider extends ContentProvider { @Override public int delete(Uri uri, String selection, String[] selectionArgs) { return 0; } @Override public String getType(Uri uri) { return null; } @Override public Uri insert(Uri uri, ContentValues values) { return null; } ・Sample code

2.5 Content provider This material is licensed under the Creative Commons License BY-NC-SA 4.0. 73 @Override public boolean onCreate() { return false; } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { return null; } @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { return 0; } } ・Sample code (continue)

2.5 Content provider 2. Implement the abstract method of content provider if needed i. Generate object of normal SQLiteOpenHelper with onCreate and save as instance variable The context specified to argument of constructor will use getContext method ii. With 4 methods operate database, get object of SQLiteDatabase from SQLiteOpenHelper object Use the gotten SQLiteDatabase object to operate for database ※ SQLiteDatabase object can be got by the one who implement with onCreate also. iii. onType is the method of returning MIME type, and in case of dividing type with the specified URI, it will be implemented as a means to inform that type to user In not complicated case, it is OK with usual-unused (return null;) This material is licensed under the Creative Commons License BY-NC-SA 4.0. 74

2.5 Content provider • Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 75 ・・・ private SampleSqliteOpenHelper sqliteOpenHelper; private SQLiteDatabase db; @Override public boolean onCreate() { sqliteOpenHelper = new DatabaseOpenHelper(getContext()); return true; } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { db = sqliteOpenHelper.getReadableDatabase(); return db.query("RSS_FEED", projection, selection, selectionArgs, null, null, sortOrder); } ・・・ ・・・1 ・・・2

2.5 Content provider 3. Register the created content provider to AndroidManifest.xml • Steps i. Open AndroidManifest.xml and select Application tab ii. Click [Add] button of Application Nodes This material is licensed under the Creative Commons License BY-NC-SA 4.0. 76 i ⅱ

2.5 Content provider iii. Select Provider from the displayed screen, click 「OK」 button ※ In case cursor is in the registered node, the layer will be checked, so please select upon radio button This material is licensed under the Creative Commons License BY-NC-SA 4.0. 77 ⅲ ※

2.5 Content provider iv. After checking that the added Provider is selected, input name of class of the Provider created in [Name] field This material is licensed under the Creative Commons License BY-NC-SA 4.0. 78 ⅳ It is convenient to browse if clicking Browse button

2.5 Content provider v. Scroll down Attribute for Provider, specify the unique content provider name to Authorities tag Normally it is the same with package name This material is licensed under the Creative Commons License BY-NC-SA 4.0. 79 ⅴ

2.5 Content provider ※ It is added to AndroidManifest.xml as below: By doing this, it could be registered as class of content provider Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 80 ・・・ <application ・・・> ・・・ <provider android:authorities="jp.oesf.sample.sampleprovider“ android:name=“SampleProvider"> </provider> ・・・ </application> ・・・

2.5 Content provider 3. The created content provider will use ContentResolver object i. Pass URI for accessing to content provider to parse method of Uri object to generate Uri object The specified URI is content:// the value of Authorities of content provider ii. Use Context#getContentResolver method to get ContentResolver object In ContentResolver, query, Insert, update, delete, getType methods are prepared in the same form with ContentProvider • Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 81 Uri uri = Uri.parse("content:// jp.oesf.sample.sampleprovider”); Cursor cursor = getContentResolver().query(uri, null, null, null, null); ・・・ⅰ ・・・ⅱ

2.5 Content provider • Reference – In case of diverging the processing according to value of URI (for example: specifying table name, simple authentication), it is necessary to check URI with logic At that time, it is better to use android.content.UriMatcher class This material is licensed under the Creative Commons License BY-NC-SA 4.0. 82 import android.content.UriMatcher; private static final UriMatcher uriMatcher; static{ uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);uriMatcher.addURI("jp.oesf.mtgeduwg.traini ng.rssreader", "FOO", 1); uriMatcher.addURI("jp.oesf.mtgeduwg.training.rssreader", “FOO/#", 2); } Inside method switch(uriMatcher.match(uri)){ case 1: ・・・ case 2: ・・・ default: ・・・ Sample code

Practice 2.5 Content provider Practice 3 • Practice theme – Create content provider in RssReader, make it is possible to search information of RSS_FEED table from external application. This material is licensed under the Creative Commons License BY-NC-SA 4.0. 83 Click button

Practice 2.5 Content provider Practice 3 • Practicing steps 1. Create newly RssProvider which is content provider 2. With onCreate of RssProvider, get SQLiteOpenHelper object 3. With query method of RssProvider, get SQLiteDatabase object with SQLiteOpenHelper#getReadableDatabase method 4. With query method of RssProvider, call SQLiteDatabase#query, return the recorded Cursor 5. Add setting of RssProvider to AndroidManifest.xml 6. Check Main# onClickGetList method of TestContentProvider project (It is implemented already so check only) This material is licensed under the Creative Commons License BY-NC-SA 4.0. 84

Practice 2.5 Content provider Practice 3 – Setting information 1 • Execute the following class, method This material is licensed under the Creative Commons License BY-NC-SA 4.0. 85 Target Class Method Outline Content Provider RssProvider • Create newly • Package is jp.oesf.mtgeduwg.training.rssreader onCreate • Get SQLiteOpenHelper object query • Search the condition of argument as it is from RSS_FEED table, and return that result

Practice 2.5 Content provider Practice 3 – Setting information 2 • Edit the following file This material is licensed under the Creative Commons License BY-NC-SA 4.0. 86 File name Outline AndroidManifest.xml • Register RssProvider as content provider • Set jp.oesf.mtgeduwg.training.rssreader to android:authorities

Practice 2.5 Content provider Practice 3 • How to check – When launching TestContentProvider application, and pushing 「GET LIST」 button, get the value from database via content provider and make it display list on screen This material is licensed under the Creative Commons License BY-NC-SA 4.0. 87 Click button

Practice 2.5 Content provider Practice 3 • Answer of Practice – RssProvider.java This material is licensed under the Creative Commons License BY-NC-SA 4.0. 88 package jp.oesf.mtgeduwg.training.rssreader; import jp.oesf.mtgeduwg.training.rssreader.helper.DatabaseOpenHelper; import android.content.ContentProvider; import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.net.Uri; public class RssProvider extends ContentProvider { private DatabaseOpenHelper databaseOpenHelper; private SQLiteDatabase db;

Practice 2.5 Content provider Practice 3 • Answer of Practice – RssProvider (continue) This material is licensed under the Creative Commons License BY-NC-SA 4.0. 89 @Override public boolean onCreate() { databaseOpenHelper = new DatabaseOpenHelper(getContext()); return true; } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { db = databaseOpenHelper.getReadableDatabase(); return db.query("RSS_FEED", projection, selection, selectionArgs, null, null, sortOrder); } ・・・

Practice 2.5 Content provider Practice 3 • Answer of Practice – AndroidManifest.xml This material is licensed under the Creative Commons License BY-NC-SA 4.0. 90 ・・・ <application> ・・・ <provider android:authorities="jp.oesf.mtgeduwg.training.rssreader" android:name="RssProvider"></provider> ・・・ </application> ・・・

Practice 2.5 Content provider Practice 3[Supplement] • Practice theme – Try to implement as below: • Make it specifies with URI, not writing without spaces in code content://jp.oesf.mtgeduwg.training.rssreader/RSS_FEED This material is licensed under the Creative Commons License BY-NC-SA 4.0. 91 There is no answer, please refer to sample

3. Practical development 92 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

Chapter 3 - Outline • Notification • Support multi-resolution • Support multi-language • adb tool 93 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

3.1. Notification • What is notification? – The function to display information in a given time on status bar of the upper part of screen – When opening status bar, the list screen of notification will be displayed, and then it is possible to start up activity 94 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

3.1. Notification • How to implement notification – Get NotificationManager class which handles notification – Generate Notification object – Generate the pending intent which started when notification list is clicked – Set event information in Notification object – Display notification This material is licensed under the Creative Commons License BY-NC-SA 4.0. 95

3.1. Notification • How to implement notification 1. Get NotificationManager class which handles notification – Can get NotificationManager by invoking Context#getSystemService – Specify constant of Context.NOTIFICATION_SERVICE to argument of the above method – Return value is Object type so typecast in NotificationManager type Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 96 import android.app.NotificationManager; import android.content.Context; ・・・ NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); ・・・1

3.1. Notification 2. Generate Notification object • Call constructor and generate object • Specify resource ID of icon, message displayed on status bar in argument of constructor, and time (milliseconds) displayed in list Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 97 import android.app.Notification; ・・・ Notification notification = new Notification(R.drawable.icon,“Could get RSS", System.currentTimeMillis()); ・・・2

3.1. Notification 3. Generate the pending intent which started when notification list is clicked • Generate PendingIntent by getActivity method (static method) of PendingIntent • There are 4 arguments of getActivity, so specify context, request code (now it is unused, so it is usually 0), intent, flag (it is 0 in case of not used ) Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 98 import android.app.PendingIntent; import android.content.Intent; ・・・ PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,RssListActivity.class), 0); About flag: PendingIntent.FLAG_UPDATE_CURRENT,… Refer to: http://developer.android.com/reference/android/app/PendingIntent.html ・・・3

3.1. Notification 4. Set event information in Notification object • Set event information with Notification#setLatestEventInfo • There are 4 arguments of setLatestEventInfo, so specify context, title, ticker text, pending intent Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 99 notification.setLatestEventInfo(this, "RssReader", “RSS got", pendingIntent); ・・・4

3.1. Notification 5. Display notification • Display notification actually with NotificationManager#notify • There are 2 arguments of notifying, so specify id(the number unified with that notification inside application), Notification object Sample code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 100 nm.notify(0,notification); ・・・5

3.1. Notification The sample code until 1-5 are summarized and shown as below: This material is licensed under the Creative Commons License BY-NC-SA 4.0. 101 import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; ・・・ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon,“Could get RSS", System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,RssListActivity.class), 0); notification.setLatestEventInfo(this, "RssReader", “RSS got", pendingIntent); nm.notify(0,notification); ・・・

Practice 3.1. Notification Practice 4 • Practice theme – Use notification to create the processing to notify the ending when logic of getting RSS with service is ended – Click to the applicable notification on screen of notification list, it will transit to list screen (RssListActivity) This material is licensed under the Creative Commons License BY-NC-SA 4.0. 102 Logic ended Start as service Click

Practice 3.1. Notification Practice 4 • Practicing steps 1. Execute the following steps after logic of getting RSS of RegisterService#onStart i. Get NotificationManager ii. Generate Notification object iii. Generate PendingIntent like transiting to list screen(RssListActivity) iv. Set event information to Notification object v. Display notification This material is licensed under the Creative Commons License BY-NC-SA 4.0. 103

Practice 3.1. Notification Practice 4 – Setting information 1 • Execute the following class, method This material is licensed under the Creative Commons License BY-NC-SA 4.0. 104 Target Class Method Outline Get RSS RegisterService onStart • Display notification • Flag of PendingIntent is 0 Supplemental notes In case of specifying text string to display by strings.xml without describing directly to Java, CharSequence will be required as argument in Java, so it is OK if using Context#getText(int resId) Eg: getText(R.string.app_name)

Practice 3.1. Notification Practice 4 – Setting information 2 • It should be displayed as below: This material is licensed under the Creative Commons License BY-NC-SA 4.0. 105 Display image of R.drawable.icon Display 「could get RSS」 Display 「RSS getting completed」 Display 「RssReader」 Display time at displaying timing

Practice 3.1. Notification Practice 4 • How to check – When getting RSS by pushing 「Get RSS」 button…, the following notification will be displayed – Tap to the applicable notification from list of notification, it will transit to list screen of RSS reader This material is licensed under the Creative Commons License BY-NC-SA 4.0. 106 Click

Practice 3.1. Notification Practice 4 • Practice answers – RegisterService This material is licensed under the Creative Commons License BY-NC-SA 4.0. 107 import jp.oesf.mtgeduwg.training.rssreader.helper.RssFeedRegister; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; ・・・ @Override public void onStart(Intent intent, int startId) { ・・・ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon,getText(R.string.notification_ticker_text), System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,RssListActivity.class), 0); notification.setLatestEventInfo(this, getText(R.string.notification_title), getText(R.string.notification_text), pendingIntent); nm.notify(0,notification); ・・・

Practice 3.1. Notification Practice 4 • Answer of Practice – strings.xml This material is licensed under the Creative Commons License BY-NC-SA 4.0. 108 ・・・ <resources> ・・・ <string name="notification_title">RssReader</string> <string name="notification_ticker_text">Could not get RSS</string> <string name="notification_text">RSS getting finished</string> ・・・ </resources> ※ In answer example, the displaying text is defined in resource file of text string The correct answer is the value of String written directly to code of Java Or key name of resource(notification_title…)

Practice 3.1. Notification Practice 4[Supplement] • Practice theme – Delete notification when transiting to list screen This material is licensed under the Creative Commons License BY-NC-SA 4.0. 109 There is no answer example Please refer to sample

3.2. Support multi-resolution • Support multi-resolution – Android support multi-resolution officially from version 1.6 – In case the version installed to Android terminal is unknown, if the application doesn’t support multi-resolution, it may display incorrectly – It is necessary to know how one Android application can support multi-resolution 110 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

3.2. Support multi-resolution • Density and screen server • DIP (Density Independent Pixel) • Scaling • Multi-resolution-supported Tips This material is licensed under the Creative Commons License BY-NC-SA 4.0. 111

3.2. Support multi-resolution • Density and screen size – In Android, devices are categorized according to Density and screen size – Density is divided according to value of DPI (Dots Per Inch/ Number of dots per inch) to 3 types as below – According to 3 types, the directory of the photo file to be called will be divided and it is possible to display the photo suitable to that Density. This material is licensed under the Creative Commons License BY-NC-SA 4.0. 112 Density DPI range Deemed DPI value Supported photo file directory Low-Density 100dpi-140dpi 120dpi res/drawable-ldpi Medium-Density 140dpi-180dpi 160dpi res/drawable-mdpi High-Density 190dpi-250dpi 240dpi res/drawable-hdpi ※ Deemed DPI value Eg: In Low-Density device, all DPI are 120dpi

3.2. Support multi-resolution – Screen sizes are divided into 3 types according size of screen – By dividing the layout directory to be called according to 3 types, the layout suitable to that screen size can be called out. This material is licensed under the Creative Commons License BY-NC-SA 4.0. 113 Name Screen size Supported layout file directory Small Screen - 3.0 inch res/layout-small Normal Screen 3.0 inch – 4.0 inch res/layout Large Screen 4.0 inch- res/layout-large Low-Density Medium-Density High-Density Small Screen QVGA (240x320), 2.6"-3.0" inch Normal Screen WQVGA (240x400), 3.2"-3.5" inch FWQVGA (240x432), 3.5"-3.8" inch HVGA (320x480), 3.0"-3.5" inch WVGA (480x800), 3.3"-4.0" inch FWVGA (480x854), 3.5"-4.0" inch Large Screen WVGA (480x800), 4.8"-5.5" inch FWVGA (480x854), 5.0"-5.8" inch – The following table is the result of summarizing 2 types Refer to: http://developer.android.com/intl/ja/guide/topics/resources/providing-resources.html#AlternativeResources

3.2. Support multi-resolution • DIP (Density Independent Pixel) – When specifying size directly, normally Pixel/px is used, but in case of pixel the UI will be not intended by Density – In Android the concept of DIP(Density Independent Pixel) _ the virtual pixel unit is introduced, and it can be supported for that. – Unit of DIP is described as dip or dp, but dp is suggested. – It is calculated with the formula: pixels = dips * (density / 160) It means with 160dpi= Medium-Density, 1px=1dp – Scale-independent Pixels (sp) is a concept like DIP, but it is the value added by not only Density but also font size of user. But currently in Android, there is no 「User font size setting」, so it is 1dp=1sp – [Supplement] In all methods of Java prepared in Android, only pixel can be used. Therefore, it is necessary to convert with the above formula in code of Java This material is licensed under the Creative Commons License BY-NC-SA 4.0. 114

3.2. Support multi-resolution • Scaling – 3 directories to be called according to Photo file Density are prepared, but sometimes only res/drawable not all of them are prepared. – In the above case, Scale Density of Medium-Density will be 1, and the scaling function to enlarge/reduce the size of photo according to Density will be prepared. – If the photo which no need to scale is stored in res/drawable-nodpi, it will be displayed with that resolution as it is without scaling. This material is licensed under the Creative Commons License BY-NC-SA 4.0. 115 Density Scale Density High-Density 1.5 Medium-Density 1 Low-Density 0.75 Scale Density

3.2. Support multi-resolution • Multi-resolution-supported Tips – Use wrap_content or fill_parent (match_parent from 2.2) to specify size of width/height of layout In case it is necessary to specify numeric value, use dp not px – Photo file is prepared suitable with Density – Recognize the different of screen size in order not to fill over in horizontal direction In case of filling by force, prepare layout file for Small Screen separately – Convert the pixel value in Java code to DIP which do not hard code This material is licensed under the Creative Commons License BY-NC-SA 4.0. 116

3.2. Support multi-resolution • Multi-resolution-supported Tips (continue) – When the screen not supported is set in the 3 types of screen size, it is no problem if describing the setting of supports-screens of AndroidManifest.xml Sample of AndroidManifest.xml (Not support Small Screen) This material is licensed under the Creative Commons License BY-NC-SA 4.0. 117 ・・・ <application> ・・・ <supports-screens android:largeScreens=“true”> android:normalScreens=“true”> android:smallScreens=“false” /> ・・・ </application> ・・・

Practice 3.2. Support multi-resolution Practice 5 • Practice theme – Run the application of Multi Resolution project on each emulator which is different in screen size and Density, and check that screen and source. This material is licensed under the Creative Commons License BY-NC-SA 4.0. 118 ldpi mdpi hdpi

Practice 3.2. Support multi-resolution Practice 5 • Checking point of practice – Check in Small-Screen if buttons are 2-stage group or not => res/layout-small/main.xml is read – Check if R.drawable.droid is displayed by other photo prepared for each resolution or not => res/drawable-Xdpi/droid.jpg is displayed – Check if R.drawable.droid_nodpi is displayed by one photo without scaling or not => res/drawable-nodpi/droid_nodpi.jpg is displayed This material is licensed under the Creative Commons License BY-NC-SA 4.0. 119

Practice 3.2. Support multi-resolution • Checking point of practice (continue) – Check if R.drawable.droid_scaling is scaled and displayed with enlarged/reduced size combining with resolution or not => res/drawable/droid_scaling.jpg is scaled and displayed – The displayed text is specified as px for the upper one, dp for the lower, so that check if the lower text ‘s size is changed combining with the resolution or not. => res/layout/main.xml is read – The margin of photo is dp specified, so check if the size is changed combining with resolution or not. => res/layout/main.xml is read This material is licensed under the Creative Commons License BY-NC-SA 4.0. 120

Practice 3.2. Support multi-resolution This material is licensed under the Creative Commons License BY-NC-SA 4.0. 121 R.drawable.droid Different photo is prepared for each Density R.drawable.droid_nodpi All are displayed with the same resolution without scaling R.drawable.droid_scaling scaled to be displayed In Small-Screen buttons are divided into 2 stage to be displayed Upper is px specified Lower is dp specified Lower will be changed according to resolution Margin of photo is dp specified

Practice 3.2. Support multi-resolution Practice 5 • Practice steps 1. The following 3 emulators are prepared, so start up that, launch application Multi Resolution project and check the displayed screen and source This material is licensed under the Creative Commons License BY-NC-SA 4.0. 122 Emulator name Screen size and Density QVGA-small-ldpi Small Screen, Low-Density HVGA-normal-mdpi Normal Screen, Medium-Density WVGA-normal-hdpi Normal Screen, High-Density

Practice 3.2. Support multi-resolution Practice 5 • How to check – Check the checking point of practice This material is licensed under the Creative Commons License BY-NC-SA 4.0. 123

3.3. Support multi-language • Support multi-language – Android application would be used in many countries on the world, so it should support multi-language. – If the text string is described in Android as resource file in advance, the mechanism to support multi-language will be prepared simply. – Combining with language setting in device, the resource file under directory of res/values-[language code] or res/values-[language code]- r[region code] can be read – In case device has no directory for language setting, it will be read under res/values 124 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

3.3. Support multi-language • In case of English(Australia): values-en- rAU • In case of English (not Australia: values-en • In case of Japanese: values-ja • In the cases other than above: values will be read This material is licensed under the Creative Commons License BY-NC-SA 4.0. 125 Example Specify language code ISO 639-1 form http://www.loc.gov/standards/iso639-2/php/code_list.php Specify region code ISO 3166-1-alpha-2 form http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm

Practice 3.3. Support multi-language Practice 6 • Practice theme – When changing language setting of emulator, check if the text string resource file called corresponded to that is changed or not This material is licensed under the Creative Commons License BY-NC-SA 4.0. 126

Practice 3.3. Support multi-language Practice 6 • Practice steps 1. Create res/values-en, res/values-en-rAU, res/values-ja 2. Copy res/values/strings.xml to the created 3 directories 3. Change strings.xml/go_to_list_page_button_label key value of each strings.xml as below: 4. Start up emulator, check if the display of changing language setting is changed or not This material is licensed under the Creative Commons License BY-NC-SA 4.0. 127 Target Key Value res/values/strings.xml go_to_list_page_button_label List displaying (Default) res/values-en/strings.xml go_to_list_page_button_label List displaying (English) res/values-en-rAU/strings.xml go_to_list_page_button_label List displaying (Australia) res/values-ja/strings.xml go_to_list_page_button_label List displaying (Japan)

Practice 3.3. Support multi-language Practice 6 • How to check – Launch RssReader on emulator Change language setting and check if the displaying text of button in menu screen is changed or not This material is licensed under the Creative Commons License BY-NC-SA 4.0. 128 Language Displaying text string Value Japan go_to_list_page_button_label List displaying (Japan) English(Australia) go_to_list_page_button_label List displaying (Australia) English ※not Australia go_to_list_page_button_label List displaying (English) All above go_to_list_page_button_label List displaying (Default)

Practice 3.3. Support multi-language Practice 6 • How to set up language i. In Home screen, 「menu」 button =>Push 「Setting」 ii. In Setting screen, push 「Language & Keyboard」 This material is licensed under the Creative Commons License BY-NC-SA 4.0. 129 ⅰ ⅱ

Practice 3.3. Support multi-language iii. On Language & Keyboard setting screen, push 「Select language」 iv. Push target language on Locale screen This material is licensed under the Creative Commons License BY-NC-SA 4.0. 130 ⅲ ⅳ

Practice 3.3. Support multi-language Practice 6 • Answer of Practice (only the applicable part) – res/values/strings.xml – res/values-en/strings.xml – res/values-en-rAU/strings.xml – res/values-ja/strings.xml This material is licensed under the Creative Commons License BY-NC-SA 4.0. 131 <string name=“go_to_list_page_button_label”>List displaying (Default)</string> <string name=“go_to_list_page_button_label”>List displaying (English)</string> <string name=“go_to_list_page_button_label”>List displaying (Australia)</string> <string name="go_to_list_page_button_label">List displaying (Japan)</string>

3.4.adb tool • What is adb tool? – This is the tool to manage the status of device of emulator which belong to SDK – Input command by command prompt to use – In case of passing path in <SDK_ROOT>/tools, recognize adb command in every directory 132 This material is licensed under the Creative Commons License BY-NC-SA 4.0.

Practice 3.4.adb tool Practice 7 • Practice theme – Operate actually what described in explanation to learn how to use adb tool 1. adb -help Help of adb tool is displayed This material is licensed under the Creative Commons License BY-NC-SA 4.0. 133

Practice 3.4.adb tool Practice 7 2. adb devices Display the list of the running emulator and real device 3. adb uninstall <Package name> Uninstall the application applicable to package name 4. adb install <apk path> Install application This material is licensed under the Creative Commons License BY-NC-SA 4.0. 134

Practice 3.4.adb tool Practice 7 5. adb push <local path> <remote path> Copy <remote path> of <local path> 6. adb pull <Remote path> <local path> Copy <remote path> file to <local path> 7. adb shell Connect with Terminal(emulator) and launch shell This material is licensed under the Creative Commons License BY-NC-SA 4.0. 135

Practice 3.4.adb tool Practice 7 (Shell operation is as below:) 8. cd <direct path> Direct to current directory 9. ls Display information of file or directory 10.rm <Target file path> Delete file This material is licensed under the Creative Commons License BY-NC-SA 4.0. 136

Practice 3.4.adb tool Practice 7 (sqlite3 command is as below:) 11.sqlite3 <Database file path> Direct to current directory 12. .help Display Help 13..dump Display dump file This material is licensed under the Creative Commons License BY-NC-SA 4.0. 137

Practice 3.4.adb tool Practice 7 11..schema Display CREATE sentence 12. <SQL sentence>; Issue SQL sentence 13..exit Exit sqlite3 command This material is licensed under the Creative Commons License BY-NC-SA 4.0. 138

3.5.JUnit • What is JUnit? – It is the testing framework to carry out unit test of Java program – It can create test code for confirming the behavior of the created program runs as expected or not, and carry out verification by executing test code – Testing is made to a program, and can be executed many times mechanically, so it is helpful for securing quality 139 This material is licensed under the Creative Commons License BY-NC-SA 4.0. 139

3.5.JUnit • What is JUnit for Android? – In Android, the JUnit is customized from JUnit3 – It is able to issue user’s screen operation and event( onCreate, etc) of Life cycle => It reaches beyond unit test partially to able to use in scenario test – Normal JUnit will run in Java VM on development machine, but Android JUnit runner implements testing by installing and running testing application on Emulator and real machine. 140 This material is licensed under the Creative Commons License BY-NC-SA 4.0. 140

3.5.JUnit • Structure of JUnit base class – It is necessary to make test class extended from junit.framework.TestCase base class – In Android, the class inherited from TestCase class above is prepared after matching to test target – It is up to purpose for using this inherited class 141 This material is licensed under the Creative Commons License BY-NC-SA 4.0. 141

3.5.JUnit – The relation of TestCase class and class for testing being provided by Android junit.framework.TestCase InstrumentationTestCase ActivityTestCase ActivityInstrumentationTestCase2 ActivityUnitTestCase SingleLaunchActivityTestCase AndroidTestCase ServiceTestCase ProviderTestCase2 ApplicationTestCase 142 This material is licensed under the Creative Commons License BY-NC-SA 4.0. 142

3.5.JUnit – Outline of each basis class • ActivityInstrumentationTestCase2 – Screen operation such as push button is possible • ActivityUnitTestCase – It is possible to execute event( such as onCrete) on Life cycle of Activity • ServiceTestCase – It is possible to execute service • ProviderTestCase2 – It is possible to execute Content Provider • ApplicationTestCase – It is possible to use it in testing application 143 This material is licensed under the Creative Commons License BY-NC-SA 4.0. 143

3.5.JUnit • JUnit real code sample – At first, general JUnit code without relation with Android 144 public class Foo { public int add(int x, int y){ return x + y; } } • Code of test target Method that returns after adding 2 arguments This material is licensed under the Creative Commons License BY-NC-SA 4.0. 144

3.5.JUnit • Test code 145 import junit.framework.TestCase; public class FooTest extends TestCase { private Foo foo = null;

Add a comment

Related presentations