diff options
| author | Scott Main <smain@google.com> | 2012-04-04 16:25:14 -0700 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-04-04 16:25:14 -0700 |
| commit | dfd2ae2278fba8654d9c8f81a16e8fb833c6e4f0 (patch) | |
| tree | 3a83d9ab39806eec4905111b9eee7de292f556df /samples/training | |
| parent | 96f6139c59b30755ca4e7d70bc34d6391eea8c2b (diff) | |
| parent | 87a714c17c3838173c238b90e78a9e04f22a2a9a (diff) | |
| download | android_development-dfd2ae2278fba8654d9c8f81a16e8fb833c6e4f0.tar.gz android_development-dfd2ae2278fba8654d9c8f81a16e8fb833c6e4f0.tar.bz2 android_development-dfd2ae2278fba8654d9c8f81a16e8fb833c6e4f0.zip | |
Merge "uploading sample code for AU class on Activity Lifecycle" into ics-mr1
Diffstat (limited to 'samples/training')
26 files changed, 1258 insertions, 0 deletions
diff --git a/samples/training/basic/activity-lifecycle/AndroidManifest.xml b/samples/training/basic/activity-lifecycle/AndroidManifest.xml new file mode 100644 index 000000000..d929179b7 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/AndroidManifest.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (C) 2012 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.example.android" + android:versionCode="1" + android:versionName="1.0"> + + <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" /> + <application android:label="@string/app_name" + android:icon="@drawable/ic_launcher"> + + <activity android:name=".lifecycle.ActivityA" + android:launchMode="singleTask"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <activity android:name=".lifecycle.ActivityB" /> + + <activity android:name=".lifecycle.ActivityC" /> + + <activity android:name=".lifecycle.DialogActivity" + android:theme="@android:style/Theme.Dialog"> + </activity> + + </application> +</manifest> diff --git a/samples/training/basic/activity-lifecycle/ant.properties b/samples/training/basic/activity-lifecycle/ant.properties new file mode 100644 index 000000000..ee52d86d9 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/ant.properties @@ -0,0 +1,17 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked in Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + diff --git a/samples/training/basic/activity-lifecycle/build.properties b/samples/training/basic/activity-lifecycle/build.properties new file mode 100644 index 000000000..17e3798d1 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/build.properties @@ -0,0 +1,18 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked in Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. +extensible.classpath=${sdk.dir}/extras/android/support/v13/android-support-v13.jar + diff --git a/samples/training/basic/activity-lifecycle/build.xml b/samples/training/basic/activity-lifecycle/build.xml new file mode 100644 index 000000000..a317a2b25 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/build.xml @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="101 Course" default="help"> + + <!-- The local.properties file is created and updated by the 'android' tool. + It contains the path to the SDK. It should *NOT* be checked into + Version Control Systems. --> + <property file="local.properties" /> + + <!-- The ant.properties file can be created by you. It is only edited by the + 'android' tool to add properties to it. + This is the place to change some Ant specific build properties. + Here are some properties you may want to change/update: + + source.dir + The name of the source directory. Default is 'src'. + out.dir + The name of the output directory. Default is 'bin'. + + For other overridable properties, look at the beginning of the rules + files in the SDK, at tools/ant/build.xml + + Properties related to the SDK location or the project target should + be updated using the 'android' tool with the 'update' action. + + This file is an integral part of the build system for your + application and should be checked into Version Control Systems. + + --> + <property file="ant.properties" /> + + <!-- The project.properties file is created and updated by the 'android' + tool, as well as ADT. + + This contains project specific properties such as project target, and library + dependencies. Lower level build properties are stored in ant.properties + (or in .classpath for Eclipse projects). + + This file is an integral part of the build system for your + application and should be checked into Version Control Systems. --> + <loadproperties srcFile="project.properties" /> + + <!-- quick check on sdk.dir --> + <fail + message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var" + unless="sdk.dir" + /> + + +<!-- extension targets. Uncomment the ones where you want to do custom work + in between standard targets --> +<!-- + <target name="-pre-build"> + </target> + <target name="-pre-compile"> + </target> + + /* This is typically used for code obfuscation. + Compiled code location: ${out.classes.absolute.dir} + If this is not done in place, override ${out.dex.input.absolute.dir} */ + <target name="-post-compile"> + </target> +--> + + <!-- Import the actual build file. + + To customize existing targets, there are two options: + - Customize only one target: + - copy/paste the target into this file, *before* the + <import> task. + - customize it to your needs. + - Customize the whole content of build.xml + - copy/paste the content of the rules files (minus the top node) + into this file, replacing the <import> task. + - customize to your needs. + + *********************** + ****** IMPORTANT ****** + *********************** + In all cases you must update the value of version-tag below to read 'custom' instead of an integer, + in order to avoid having your file be overridden by tools such as "android update project" + --> + <!-- version-tag: 1 --> + <import file="${sdk.dir}/tools/ant/build.xml" /> + +</project> diff --git a/samples/training/basic/activity-lifecycle/default.properties b/samples/training/basic/activity-lifecycle/default.properties new file mode 100644 index 000000000..e2e8061f2 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/default.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "build.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-8 diff --git a/samples/training/basic/activity-lifecycle/libs/android-support-v13.jar b/samples/training/basic/activity-lifecycle/libs/android-support-v13.jar Binary files differnew file mode 100644 index 000000000..3d7f8410f --- /dev/null +++ b/samples/training/basic/activity-lifecycle/libs/android-support-v13.jar diff --git a/samples/training/basic/activity-lifecycle/local.properties b/samples/training/basic/activity-lifecycle/local.properties new file mode 100644 index 000000000..838a83145 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/local.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must *NOT* be checked in Version Control Systems, +# as it contains information specific to your local configuration. + +# location of the SDK. This is only used by Ant +# For customization when using a Version Control System, please read the +# header note. +sdk.dir=/Users/brutledge/android-sdk-macosx +extensible.classpath=./libs/android-support-v13.jar diff --git a/samples/training/basic/activity-lifecycle/proguard.cfg b/samples/training/basic/activity-lifecycle/proguard.cfg new file mode 100644 index 000000000..b1cdf17b5 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/proguard.cfg @@ -0,0 +1,40 @@ +-optimizationpasses 5 +-dontusemixedcaseclassnames +-dontskipnonpubliclibraryclasses +-dontpreverify +-verbose +-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* + +-keep public class * extends android.app.Activity +-keep public class * extends android.app.Application +-keep public class * extends android.app.Service +-keep public class * extends android.content.BroadcastReceiver +-keep public class * extends android.content.ContentProvider +-keep public class * extends android.app.backup.BackupAgentHelper +-keep public class * extends android.preference.Preference +-keep public class com.android.vending.licensing.ILicensingService + +-keepclasseswithmembernames class * { + native <methods>; +} + +-keepclasseswithmembers class * { + public <init>(android.content.Context, android.util.AttributeSet); +} + +-keepclasseswithmembers class * { + public <init>(android.content.Context, android.util.AttributeSet, int); +} + +-keepclassmembers class * extends android.app.Activity { + public void *(android.view.View); +} + +-keepclassmembers enum * { + public static **[] values(); + public static ** valueOf(java.lang.String); +} + +-keep class * implements android.os.Parcelable { + public static final android.os.Parcelable$Creator *; +} diff --git a/samples/training/basic/activity-lifecycle/project.properties b/samples/training/basic/activity-lifecycle/project.properties new file mode 100644 index 000000000..730e911f2 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/project.properties @@ -0,0 +1,11 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system use, +# "ant.properties", and override values to adapt the script to your +# project structure. + +# Project target. +target=android-14 diff --git a/samples/training/basic/activity-lifecycle/res/drawable-hdpi/ic_launcher.png b/samples/training/basic/activity-lifecycle/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100755 index 000000000..6bb06c479 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/drawable-hdpi/ic_launcher.png diff --git a/samples/training/basic/activity-lifecycle/res/drawable-ldpi/ic_launcher.png b/samples/training/basic/activity-lifecycle/res/drawable-ldpi/ic_launcher.png Binary files differnew file mode 100755 index 000000000..70ca1bf45 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/drawable-ldpi/ic_launcher.png diff --git a/samples/training/basic/activity-lifecycle/res/drawable-mdpi/ic_launcher.png b/samples/training/basic/activity-lifecycle/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100755 index 000000000..085b783c3 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/drawable-mdpi/ic_launcher.png diff --git a/samples/training/basic/activity-lifecycle/res/drawable-xhdpi/ic_launcher.png b/samples/training/basic/activity-lifecycle/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100755 index 000000000..bfa4007c0 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/drawable-xhdpi/ic_launcher.png diff --git a/samples/training/basic/activity-lifecycle/res/layout/activity_a.xml b/samples/training/basic/activity-lifecycle/res/layout/activity_a.xml new file mode 100644 index 000000000..96185a89f --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/layout/activity_a.xml @@ -0,0 +1,117 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (C) 2012 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/dark_blue" + android:padding="8dip" + > + + <TextView android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/activity_a" + android:gravity="center_horizontal" + android:textSize="@dimen/font_large" + android:textColor="@color/light_blue" + android:paddingBottom="16dip" + /> + + <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + > + <Button + android:id="@+id/btn_start_b" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_start_b_label" + android:onClick="startActivityB" + /> + + <Button + android:id="@+id/btn_start_c" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_start_c_label" + android:layout_toRightOf="@id/btn_start_b" + android:onClick="startActivityC" + /> + + <Button + android:id="@+id/btn_finish_a" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_finish_a_label" + android:layout_toRightOf="@id/btn_start_c" + android:onClick="finishActivityA" + /> + + <Button + android:id="@+id/btn_start_dialog" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_start_dialog_label" + android:layout_toRightOf="@id/btn_finish_a" + android:onClick="startDialog" + /> + + </RelativeLayout> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="@dimen/font_medium" + android:text="@string/lifecycle_method_list" + android:textColor="@color/light_blue" + /> + + <ScrollView + android:layout_width="match_parent" + android:layout_height="160dp"> + <TextView + android:id="@+id/status_view_a" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/white" + android:textColor="@color/black" + android:padding="4dip" + android:typeface="monospace" + /> + </ScrollView> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="@dimen/font_medium" + android:text="@string/activity_status" + android:textColor="@color/light_blue" + /> + + <TextView + android:id="@+id/status_view_all_a" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/white" + android:textColor="@color/black" + android:padding="4dip" + android:typeface="monospace" + /> +</LinearLayout> + diff --git a/samples/training/basic/activity-lifecycle/res/layout/activity_b.xml b/samples/training/basic/activity-lifecycle/res/layout/activity_b.xml new file mode 100644 index 000000000..aa71fba40 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/layout/activity_b.xml @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (C) 2012 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/dark_green" + android:padding="8dip" + > + <TextView android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/activity_b_label" + android:gravity="center_horizontal" + android:textSize="@dimen/font_large" + android:textColor="@color/light_green" + android:paddingBottom="16dip" + /> + + + <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + > + <Button + android:id="@+id/btn_start_a" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_start_a_label" + android:onClick="startActivityA" + /> + + <Button + android:id="@+id/btn_start_c" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_start_c_label" + android:layout_toRightOf="@id/btn_start_a" + android:onClick="startActivityC" + /> + + <Button + android:id="@+id/btn_finish_b" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_finish_b_label" + android:layout_toRightOf="@id/btn_start_c" + android:onClick="finishActivityB" + /> + + <Button + android:id="@+id/btn_start_dialog" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_start_dialog_label" + android:layout_toRightOf="@id/btn_finish_b" + android:onClick="startDialog" + /> + + + </RelativeLayout> + + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="@dimen/font_medium" + android:text="@string/lifecycle_method_list" + android:textColor="@color/light_green" + /> + + <ScrollView + android:layout_width="match_parent" + android:layout_height="160dp"> + <TextView + android:id="@+id/status_view_b" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/white" + android:textColor="@color/black" + android:padding="4dip" + android:typeface="monospace" + /> + </ScrollView> + + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="@dimen/font_medium" + android:text="@string/activity_status" + android:textColor="@color/light_green" + /> + + <TextView + android:id="@+id/status_view_all_b" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/white" + android:textColor="@color/black" + android:padding="4dip" + android:typeface="monospace" + /> +</LinearLayout> + diff --git a/samples/training/basic/activity-lifecycle/res/layout/activity_c.xml b/samples/training/basic/activity-lifecycle/res/layout/activity_c.xml new file mode 100644 index 000000000..ccc0e06d4 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/layout/activity_c.xml @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (C) 2012 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/dark_red" + android:padding="8dip" + > +<TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/activity_c_label" + android:gravity="center_horizontal" + android:textSize="@dimen/font_large" + android:textColor="@color/light_red" + android:paddingBottom="16dip" + /> + + +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + > + <Button + android:id="@+id/btn_start_a" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_start_a_label" + android:onClick="startActivityA" + /> + + <Button + android:id="@+id/btn_start_b" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_start_b_label" + android:layout_toRightOf="@id/btn_start_a" + android:onClick="startActivityB" + /> + + <Button + android:id="@+id/btn_finish_c" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_finish_c_label" + android:layout_toRightOf="@id/btn_start_b" + android:onClick="finishActivityC" + /> + + <Button + android:id="@+id/btn_start_dialog" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_start_dialog_label" + android:layout_toRightOf="@id/btn_finish_c" + android:onClick="startDialog" + /> + +</RelativeLayout> + + +<TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="@dimen/font_medium" + android:text="@string/lifecycle_method_list" + android:textColor="@color/light_red" + /> + +<ScrollView + android:layout_width="match_parent" + android:layout_height="160dp"> + <TextView + android:id="@+id/status_view_c" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/white" + android:textColor="@color/black" + android:padding="4dip" + android:typeface="monospace" + /> +</ScrollView> + +<TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="@dimen/font_medium" + android:text="@string/activity_status" + android:textColor="@color/light_red" + /> + +<TextView + android:id="@+id/status_view_all_c" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="@color/white" + android:textColor="@color/black" + android:padding="4dip" + android:typeface="monospace" + /> +</LinearLayout> + diff --git a/samples/training/basic/activity-lifecycle/res/layout/activity_dialog.xml b/samples/training/basic/activity-lifecycle/res/layout/activity_dialog.xml new file mode 100644 index 000000000..f1613b44a --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/layout/activity_dialog.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (C) 2012 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="225dp" + android:layout_height="120dp" + android:background="@color/dark_yellow" + android:padding="12dip" + > + +<TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/dialog_text" + android:gravity="center_horizontal" + android:textSize="@dimen/font_medium" + android:textColor="@color/light_yellow" + android:paddingBottom="12dip" + /> + + <Button + android:id="@+id/btn_finish_dialog" + android:layout_height="wrap_content" + android:layout_width="wrap_content" + android:text="@string/btn_finish_dialog_label" + android:layout_gravity="center_horizontal" + android:onClick="finishDialog" + /> +</LinearLayout> + diff --git a/samples/training/basic/activity-lifecycle/res/values/colors.xml b/samples/training/basic/activity-lifecycle/res/values/colors.xml new file mode 100644 index 000000000..d8c2c89d5 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/values/colors.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (C) 2012 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<resources> + <color name="white">#FFFFFF</color> + <color name="black">#000000</color> + + <color name="light_blue">#A8DFF4</color> + <color name="light_green">#D3E992</color> + <color name="light_red">#FFAFAF</color> + <color name="light_yellow">#FFECC0</color> + + <color name="dark_blue">#0099CC</color> + <color name="dark_green">#669900</color> + <color name="dark_red">#CC0000</color> + <color name="dark_yellow">#FF8A00</color> +</resources>
\ No newline at end of file diff --git a/samples/training/basic/activity-lifecycle/res/values/dimensions.xml b/samples/training/basic/activity-lifecycle/res/values/dimensions.xml new file mode 100644 index 000000000..72ef859fc --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/values/dimensions.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (C) 2012 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<resources> + <dimen name="font_large">44dp</dimen> + <dimen name="font_medium">24dp</dimen> + <dimen name="font_small">10dp</dimen> +</resources>
\ No newline at end of file diff --git a/samples/training/basic/activity-lifecycle/res/values/strings.xml b/samples/training/basic/activity-lifecycle/res/values/strings.xml new file mode 100644 index 000000000..1858fe1da --- /dev/null +++ b/samples/training/basic/activity-lifecycle/res/values/strings.xml @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +Copyright (C) 2012 The Android Open Source Project + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> +<resources> + <string name="app_name">Activity Lifecycle</string> + + <string name="lifecycle_method_list">Lifecycle Method List</string> + <string name="activity_status">Activity Status</string> + <string name="dialog_text">Simple Dialog</string> + + <string name="on_create">onCreate</string> + <string name="on_destroy">onDestroy</string> + <string name="on_start">onStart</string> + <string name="on_restart">onRestart</string> + <string name="on_stop">onStop</string> + <string name="on_pause">onPause</string> + <string name="on_resume">onResume</string> + + <string name="activity_a_label">Activity A</string> + <string name="activity_b_label">Activity B</string> + <string name="activity_c_label">Activity C</string> + + <string name="btn_start_a_label">Start A</string> + <string name="btn_start_b_label">Start B</string> + <string name="btn_start_c_label">Start C</string> + <string name="btn_start_dialog_label">Dialog</string> + + <string name="btn_finish_a_label">Finish A</string> + <string name="btn_finish_b_label">Finish B</string> + <string name="btn_finish_c_label">Finish C</string> + <string name="btn_finish_dialog_label">Close</string> + + <string name="on_activity_created">onActivityCreated</string> + <string name="on_attach">onAttach</string> + <string name="on_create_view">onCreateView</string> + <string name="on_destroy_view">onDestroyView</string> + <string name="on_detach">onDetach</string> + <string name="on_view_created">onViewCreated</string> + <string name="activity_a">Activity A</string> + + <string name="start_a">Start A</string> + <string name="start_b">Start B</string> + <string name="start_c">Start C</string> + + <string name="close">Close</string> + <string name="dialog">Dialog</string> +</resources> diff --git a/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/ActivityA.java b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/ActivityA.java new file mode 100644 index 000000000..daf46ea7c --- /dev/null +++ b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/ActivityA.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.lifecycle; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +import com.example.android.R; +import com.example.android.lifecycle.util.StatusTracker; +import com.example.android.lifecycle.util.Utils; + +/** + * Example Activity to demonstrate the lifecycle callback methods. + */ +public class ActivityA extends Activity { + + private String mActivityName; + private TextView mStatusView; + private TextView mStatusAllView; + private StatusTracker mStatusTracker = StatusTracker.getInstance(); + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_a); + mActivityName = getString(R.string.activity_a); + mStatusView = (TextView)findViewById(R.id.status_view_a); + mStatusAllView = (TextView)findViewById(R.id.status_view_all_a); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_create)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onStart() { + super.onStart(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_start)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onRestart() { + super.onRestart(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_restart)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onResume() { + super.onResume(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_resume)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onPause() { + super.onPause(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_pause)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onStop() { + super.onStop(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_stop)); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_destroy)); + mStatusTracker.clear(); + } + + public void startDialog(View v) { + Intent intent = new Intent(ActivityA.this, DialogActivity.class); + startActivity(intent); + } + + public void startActivityB(View v) { + Intent intent = new Intent(ActivityA.this, ActivityB.class); + startActivity(intent); + } + + public void startActivityC(View v) { + Intent intent = new Intent(ActivityA.this, ActivityC.class); + startActivity(intent); + } + + public void finishActivityA(View v) { + ActivityA.this.finish(); + } + +} diff --git a/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/ActivityB.java b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/ActivityB.java new file mode 100644 index 000000000..92d4c2cda --- /dev/null +++ b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/ActivityB.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.lifecycle; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +import com.example.android.R; +import com.example.android.lifecycle.util.StatusTracker; +import com.example.android.lifecycle.util.Utils; + +/** + * Example Activity to demonstrate the lifecycle callback methods. + */ +public class ActivityB extends Activity { + + private String mActivityName; + private TextView mStatusView; + private TextView mStatusAllView; + private StatusTracker mStatusTracker = StatusTracker.getInstance(); + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_b); + mActivityName = getString(R.string.activity_b_label); + mStatusView = (TextView)findViewById(R.id.status_view_b); + mStatusAllView = (TextView)findViewById(R.id.status_view_all_b); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_create)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onStart() { + super.onStart(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_start)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onRestart() { + super.onRestart(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_restart)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onResume() { + super.onResume(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_resume)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onPause() { + super.onPause(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_pause)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onStop() { + super.onStop(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_stop)); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_destroy)); + } + + public void startDialog(View v) { + Intent intent = new Intent(ActivityB.this, DialogActivity.class); + startActivity(intent); + } + + public void startActivityA(View v) { + Intent intent = new Intent(ActivityB.this, ActivityA.class); + startActivity(intent); + } + + public void startActivityC(View v) { + Intent intent = new Intent(ActivityB.this, ActivityC.class); + startActivity(intent); + } + + public void finishActivityB(View v) { + ActivityB.this.finish(); + } +} diff --git a/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/ActivityC.java b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/ActivityC.java new file mode 100644 index 000000000..590671b94 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/ActivityC.java @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.lifecycle; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.TextView; + +import com.example.android.R; +import com.example.android.lifecycle.util.StatusTracker; +import com.example.android.lifecycle.util.Utils; + +/** + * Example Activity to demonstrate the lifecycle callback methods. + */ +public class ActivityC extends Activity { + + private String mActivityName; + private TextView mStatusView; + private TextView mStatusAllView; + private StatusTracker mStatusTracker = StatusTracker.getInstance(); + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_c); + mActivityName = getString(R.string.activity_c_label); + mStatusView = (TextView)findViewById(R.id.status_view_c); + mStatusAllView = (TextView)findViewById(R.id.status_view_all_c); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_create)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onStart() { + super.onStart(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_start)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onRestart() { + super.onRestart(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_restart)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onResume() { + super.onResume(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_resume)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onPause() { + super.onPause(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_pause)); + Utils.printStatus(mStatusView, mStatusAllView); + } + + @Override + protected void onStop() { + super.onStop(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_stop)); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mStatusTracker.setStatus(mActivityName, getString(R.string.on_destroy)); + } + + public void startDialog(View v) { + Intent intent = new Intent(ActivityC.this, DialogActivity.class); + startActivity(intent); + } + + public void startActivityA(View v) { + Intent intent = new Intent(ActivityC.this, ActivityA.class); + startActivity(intent); + } + + public void startActivityB(View v) { + Intent intent = new Intent(ActivityC.this, ActivityB.class); + startActivity(intent); + } + + public void finishActivityC(View v) { + ActivityC.this.finish(); + } +} diff --git a/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/DialogActivity.java b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/DialogActivity.java new file mode 100644 index 000000000..7929b4458 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/DialogActivity.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.lifecycle; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.view.Window; +import com.example.android.R; + +public class DialogActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.activity_dialog); + } + + /** + * Callback method defined by the View + * @param v + */ + public void finishDialog(View v) { + DialogActivity.this.finish(); + } +} diff --git a/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/util/StatusTracker.java b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/util/StatusTracker.java new file mode 100644 index 000000000..7a4da3aa2 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/util/StatusTracker.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.lifecycle.util; + +import java.util.*; + +public class StatusTracker { + private Map<String, String> mStatusMap; + private List<String> mMethodList; + private static StatusTracker ourInstance = new StatusTracker(); + private static final String STATUS_SUFFIX = "ed"; + + public static StatusTracker getInstance() { + return ourInstance; + } + + private StatusTracker() { + mStatusMap = new LinkedHashMap<String, String>(); + mMethodList = new ArrayList<String>(); + } + + public List<String> getMethodList() { + return mMethodList; + } + + public void clear() { + mMethodList.clear(); + mStatusMap.clear(); + } + + /** + * Adds the status value for the given activityName into the Map. + * + * @param activityName + * @param status + */ + public void setStatus(String activityName, String status) { + mMethodList.add(activityName + "." + status + "()"); + if (mStatusMap.containsKey(activityName)) mStatusMap.remove(activityName); + mStatusMap.put(activityName, status); + } + + /** + * Gets the status value for the given activityName. + * + * @param activityName + * @return + */ + public String getStatus(String activityName) { + String status = mStatusMap.get(activityName); + status = status.substring(2, status.length()); + + // String manipulation to ensure the status value is spelled correctly. + if (status.endsWith("e")) { + status = status.substring(0, status.length() - 1); + } + if (status.endsWith("p")) { + status = status + "p"; + } + status = status + STATUS_SUFFIX; + return status; + } + + public Set<String> keySet() { + return mStatusMap.keySet(); + } +} diff --git a/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/util/Utils.java b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/util/Utils.java new file mode 100644 index 000000000..c1de149f1 --- /dev/null +++ b/samples/training/basic/activity-lifecycle/src/com/example/android/lifecycle/util/Utils.java @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.android.lifecycle.util; + +import android.os.Handler; +import android.widget.TextView; + +import java.util.List; + +public class Utils { + + private static StatusTracker mStatusTracker = StatusTracker.getInstance(); + + /** + * Helper method to print out the lifecycle state of each Activity. Note this has + * been wrapped in a Handler to delay the output due to overlaps in lifecycle state + * changes as one Activity launches another. + * @link http://developer.android.com/guide/topics/fundamentals/activities.html#CoordinatingActivities + * @param viewMethods TextView to list out the lifecycle methods called + * @param viewStatus TextView to list out the status of all Activity classes + */ + public static void printStatus(final TextView viewMethods, final TextView viewStatus) { + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + public void run() { + // Get the stack of Activity lifecycle methods called and print to TextView + StringBuilder sbMethods = new StringBuilder(); + List<String> listMethods = mStatusTracker.getMethodList(); + for (String method : listMethods) { + sbMethods.insert(0, method + "\r\n"); + } + if(viewMethods != null) { + viewMethods.setText(sbMethods.toString()); + } + + // Get the status of all Activity classes and print to TextView + StringBuilder sbStatus = new StringBuilder(); + for (String key : mStatusTracker.keySet()) { + sbStatus.insert(0,key + ": " + mStatusTracker.getStatus(key) + "\n"); + } + if(viewStatus != null) { + viewStatus.setText(sbStatus.toString()); + } + } + }, 750); + } +} + + + + |
