summaryrefslogtreecommitdiffstats
path: root/samples/Home
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:29:09 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 19:29:09 -0800
commit52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98 (patch)
tree2eb01432fa3da41550dd622d29fb672509122b51 /samples/Home
parentd4aee0c0caa00aa02d4c50ed28151591ac0456b5 (diff)
downloadandroid_development-52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98.tar.gz
android_development-52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98.tar.bz2
android_development-52d4c30ca52320ec92d1d1ddc8db3f07f69c4f98.zip
auto import from //depot/cupcake/@135843
Diffstat (limited to 'samples/Home')
-rw-r--r--samples/Home/Android.mk12
-rw-r--r--samples/Home/AndroidManifest.xml60
-rw-r--r--samples/Home/MODULE_LICENSE_APACHE20
-rw-r--r--samples/Home/NOTICE190
-rw-r--r--samples/Home/res/anim/fade_in.xml19
-rw-r--r--samples/Home/res/anim/fade_out.xml19
-rw-r--r--samples/Home/res/anim/grid_entry.xml27
-rw-r--r--samples/Home/res/anim/grid_exit.xml19
-rw-r--r--samples/Home/res/anim/hide_applications.xml20
-rw-r--r--samples/Home/res/anim/show_applications.xml21
-rw-r--r--samples/Home/res/color/bright_text_dark_focused.xml23
-rw-r--r--samples/Home/res/drawable-land/bg_android.jpgbin0 -> 12002 bytes
-rw-r--r--samples/Home/res/drawable-land/bg_android_icon.jpgbin0 -> 1497 bytes
-rw-r--r--samples/Home/res/drawable-land/bg_sunrise.jpgbin0 -> 29562 bytes
-rw-r--r--samples/Home/res/drawable-land/bg_sunrise_icon.jpgbin0 -> 4252 bytes
-rw-r--r--samples/Home/res/drawable-land/bg_sunset.jpgbin0 -> 29717 bytes
-rw-r--r--samples/Home/res/drawable-land/bg_sunset_icon.jpgbin0 -> 4343 bytes
-rw-r--r--samples/Home/res/drawable-port/bg_android.jpgbin0 -> 15330 bytes
-rw-r--r--samples/Home/res/drawable-port/bg_android_icon.jpgbin0 -> 1248 bytes
-rw-r--r--samples/Home/res/drawable-port/bg_sunrise.jpgbin0 -> 29443 bytes
-rw-r--r--samples/Home/res/drawable-port/bg_sunrise_icon.jpgbin0 -> 3771 bytes
-rw-r--r--samples/Home/res/drawable-port/bg_sunset.jpgbin0 -> 20041 bytes
-rw-r--r--samples/Home/res/drawable-port/bg_sunset_icon.jpgbin0 -> 3674 bytes
-rw-r--r--samples/Home/res/drawable/all_applications.xml25
-rw-r--r--samples/Home/res/drawable/all_applications_background.xml23
-rw-r--r--samples/Home/res/drawable/all_applications_button_background.xml27
-rw-r--r--samples/Home/res/drawable/all_applications_label_background.9.pngbin0 -> 2833 bytes
-rw-r--r--samples/Home/res/drawable/application_background.9.pngbin0 -> 3083 bytes
-rw-r--r--samples/Home/res/drawable/application_background_static.pngbin0 -> 3029 bytes
-rw-r--r--samples/Home/res/drawable/favorite_background.xml26
-rw-r--r--samples/Home/res/drawable/focused_application_background_static.pngbin0 -> 3792 bytes
-rw-r--r--samples/Home/res/drawable/grid_selector.xml25
-rw-r--r--samples/Home/res/drawable/hide_all_applications.pngbin0 -> 6577 bytes
-rwxr-xr-xsamples/Home/res/drawable/ic_launcher_allhide.pngbin0 -> 5343 bytes
-rwxr-xr-xsamples/Home/res/drawable/ic_launcher_allshow.pngbin0 -> 5208 bytes
-rwxr-xr-xsamples/Home/res/drawable/ic_launcher_home.pngbin0 -> 2696 bytes
-rw-r--r--samples/Home/res/drawable/pressed_application_background_static.pngbin0 -> 4560 bytes
-rw-r--r--samples/Home/res/drawable/show_all_applications.pngbin0 -> 6700 bytes
-rw-r--r--samples/Home/res/layout-land/home.xml50
-rw-r--r--samples/Home/res/layout-port/home.xml50
-rw-r--r--samples/Home/res/layout/all_applications_button.xml42
-rw-r--r--samples/Home/res/layout/application.xml26
-rw-r--r--samples/Home/res/layout/favorite.xml29
-rw-r--r--samples/Home/res/layout/wallpaper.xml46
-rw-r--r--samples/Home/res/values-cs/strings.xml11
-rw-r--r--samples/Home/res/values-de-rDE/strings.xml11
-rw-r--r--samples/Home/res/values-es-rUS/strings.xml11
-rw-r--r--samples/Home/res/values-land/strings.xml21
-rw-r--r--samples/Home/res/values-nl-rNL/strings.xml11
-rw-r--r--samples/Home/res/values/attrs.xml30
-rw-r--r--samples/Home/res/values/strings.xml30
-rw-r--r--samples/Home/res/values/styles.xml7
-rw-r--r--samples/Home/src/com/example/android/home/ApplicationInfo.java84
-rw-r--r--samples/Home/src/com/example/android/home/ApplicationsStackLayout.java342
-rw-r--r--samples/Home/src/com/example/android/home/Home.java743
-rw-r--r--samples/Home/src/com/example/android/home/Wallpaper.java151
56 files changed, 2231 insertions, 0 deletions
diff --git a/samples/Home/Android.mk b/samples/Home/Android.mk
new file mode 100644
index 000000000..ddc1851b6
--- /dev/null
+++ b/samples/Home/Android.mk
@@ -0,0 +1,12 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := samples
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := Home
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
diff --git a/samples/Home/AndroidManifest.xml b/samples/Home/AndroidManifest.xml
new file mode 100644
index 000000000..229171f35
--- /dev/null
+++ b/samples/Home/AndroidManifest.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/Home/AndroidManifest.xml
+**
+** Copyright 2006, 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.
+*/
+-->
+
+<!-- Declare the contents of this Android application. The namespace
+ attribute brings in the Android platform namespace, and the package
+ supplies a unique name for the application. When writing your
+ own application, the package name must be changed from "com.example.*"
+ to come from a domain that you own or have control over. -->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.home">
+ <uses-permission android:name="android.permission.CALL_PHONE"/>
+ <uses-permission android:name="android.permission.GET_TASKS"/>
+ <uses-permission android:name="android.permission.READ_CONTACTS"/>
+ <uses-permission android:name="android.permission.SET_WALLPAPER" />
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
+
+ <application android:persistent="true"
+ android:label="@string/home_title"
+ android:icon="@drawable/ic_launcher_home">
+
+ <activity android:name="Home"
+ android:theme="@style/Theme"
+ android:launchMode="singleInstance"
+ android:stateNotNeeded="true">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.HOME"/>
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
+ <activity android:name="Wallpaper"
+ android:label="Wallpaper"
+ android:icon="@drawable/bg_android_icon">
+ <intent-filter>
+ <action android:name="android.intent.action.SET_WALLPAPER" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
+ </application>
+</manifest>
diff --git a/samples/Home/MODULE_LICENSE_APACHE2 b/samples/Home/MODULE_LICENSE_APACHE2
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/samples/Home/MODULE_LICENSE_APACHE2
diff --git a/samples/Home/NOTICE b/samples/Home/NOTICE
new file mode 100644
index 000000000..c5b1efa7a
--- /dev/null
+++ b/samples/Home/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, 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.
+
+ 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.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/samples/Home/res/anim/fade_in.xml b/samples/Home/res/anim/fade_in.xml
new file mode 100644
index 000000000..fe38ab1a0
--- /dev/null
+++ b/samples/Home/res/anim/fade_in.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<alpha xmlns:android="http://schemas.android.com/apk/res/android"
+ android:interpolator="@android:anim/accelerate_interpolator"
+ android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="50" />
diff --git a/samples/Home/res/anim/fade_out.xml b/samples/Home/res/anim/fade_out.xml
new file mode 100644
index 000000000..64ac4f940
--- /dev/null
+++ b/samples/Home/res/anim/fade_out.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<alpha xmlns:android="http://schemas.android.com/apk/res/android"
+ android:interpolator="@android:anim/accelerate_interpolator"
+ android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="50" />
diff --git a/samples/Home/res/anim/grid_entry.xml b/samples/Home/res/anim/grid_entry.xml
new file mode 100644
index 000000000..330c07dc2
--- /dev/null
+++ b/samples/Home/res/anim/grid_entry.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/res/anim/fade_in.xml
+**
+** Copyright 2007, 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.
+*/
+-->
+
+<set xmlns:android="http://schemas.android.com/apk/res/android"
+ android:interpolator="@android:anim/decelerate_interpolator">
+ <scale android:fromXScale="0.8" android:toXScale="1.0"
+ android:fromYScale="0.9" android:toYScale="1.0"
+ android:pivotX="100%" android:pivotY="100%" android:duration="200" />
+ <alpha android:fromAlpha="0.5" android:toAlpha="1.0" android:duration="200" />
+</set>
diff --git a/samples/Home/res/anim/grid_exit.xml b/samples/Home/res/anim/grid_exit.xml
new file mode 100644
index 000000000..c9baf2a80
--- /dev/null
+++ b/samples/Home/res/anim/grid_exit.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<alpha xmlns:android="http://schemas.android.com/apk/res/android"
+ android:interpolator="@android:anim/accelerate_interpolator"
+ android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="200" />
diff --git a/samples/Home/res/anim/hide_applications.xml b/samples/Home/res/anim/hide_applications.xml
new file mode 100644
index 000000000..93039a86d
--- /dev/null
+++ b/samples/Home/res/anim/hide_applications.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
+ android:rowDelay="25%"
+ android:directionPriority="column"
+ android:animation="@anim/fade_out" />
diff --git a/samples/Home/res/anim/show_applications.xml b/samples/Home/res/anim/show_applications.xml
new file mode 100644
index 000000000..a97c99c5d
--- /dev/null
+++ b/samples/Home/res/anim/show_applications.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
+ android:rowDelay="25%"
+ android:directionPriority="column"
+ android:direction="right_to_left|bottom_to_top"
+ android:animation="@anim/fade_in" />
diff --git a/samples/Home/res/color/bright_text_dark_focused.xml b/samples/Home/res/color/bright_text_dark_focused.xml
new file mode 100644
index 000000000..3b54573e0
--- /dev/null
+++ b/samples/Home/res/color/bright_text_dark_focused.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2008 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.
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_selected="true" android:color="#000" />
+ <item android:state_focused="true" android:color="#000" />
+ <item android:state_pressed="true" android:color="#000" />
+ <item android:color="#FFF" />
+</selector>
+
diff --git a/samples/Home/res/drawable-land/bg_android.jpg b/samples/Home/res/drawable-land/bg_android.jpg
new file mode 100644
index 000000000..0bd005fb8
--- /dev/null
+++ b/samples/Home/res/drawable-land/bg_android.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-land/bg_android_icon.jpg b/samples/Home/res/drawable-land/bg_android_icon.jpg
new file mode 100644
index 000000000..2619ef975
--- /dev/null
+++ b/samples/Home/res/drawable-land/bg_android_icon.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-land/bg_sunrise.jpg b/samples/Home/res/drawable-land/bg_sunrise.jpg
new file mode 100644
index 000000000..aa5a7d111
--- /dev/null
+++ b/samples/Home/res/drawable-land/bg_sunrise.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-land/bg_sunrise_icon.jpg b/samples/Home/res/drawable-land/bg_sunrise_icon.jpg
new file mode 100644
index 000000000..4972d8db6
--- /dev/null
+++ b/samples/Home/res/drawable-land/bg_sunrise_icon.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-land/bg_sunset.jpg b/samples/Home/res/drawable-land/bg_sunset.jpg
new file mode 100644
index 000000000..0fc885b24
--- /dev/null
+++ b/samples/Home/res/drawable-land/bg_sunset.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-land/bg_sunset_icon.jpg b/samples/Home/res/drawable-land/bg_sunset_icon.jpg
new file mode 100644
index 000000000..939edf75f
--- /dev/null
+++ b/samples/Home/res/drawable-land/bg_sunset_icon.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-port/bg_android.jpg b/samples/Home/res/drawable-port/bg_android.jpg
new file mode 100644
index 000000000..cbbf3b923
--- /dev/null
+++ b/samples/Home/res/drawable-port/bg_android.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-port/bg_android_icon.jpg b/samples/Home/res/drawable-port/bg_android_icon.jpg
new file mode 100644
index 000000000..d5742b6af
--- /dev/null
+++ b/samples/Home/res/drawable-port/bg_android_icon.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-port/bg_sunrise.jpg b/samples/Home/res/drawable-port/bg_sunrise.jpg
new file mode 100644
index 000000000..a69d5daa8
--- /dev/null
+++ b/samples/Home/res/drawable-port/bg_sunrise.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-port/bg_sunrise_icon.jpg b/samples/Home/res/drawable-port/bg_sunrise_icon.jpg
new file mode 100644
index 000000000..96968bc9d
--- /dev/null
+++ b/samples/Home/res/drawable-port/bg_sunrise_icon.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-port/bg_sunset.jpg b/samples/Home/res/drawable-port/bg_sunset.jpg
new file mode 100644
index 000000000..7135bd399
--- /dev/null
+++ b/samples/Home/res/drawable-port/bg_sunset.jpg
Binary files differ
diff --git a/samples/Home/res/drawable-port/bg_sunset_icon.jpg b/samples/Home/res/drawable-port/bg_sunset_icon.jpg
new file mode 100644
index 000000000..4ced6a9da
--- /dev/null
+++ b/samples/Home/res/drawable-port/bg_sunset_icon.jpg
Binary files differ
diff --git a/samples/Home/res/drawable/all_applications.xml b/samples/Home/res/drawable/all_applications.xml
new file mode 100644
index 000000000..5703c688c
--- /dev/null
+++ b/samples/Home/res/drawable/all_applications.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/res/drawable/checkbox.xml
+**
+** Copyright 2007, 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.
+*/
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_checked="false" android:drawable="@drawable/ic_launcher_allshow" />
+ <item android:state_checked="true" android:drawable="@drawable/ic_launcher_allhide" />
+</selector>
+
diff --git a/samples/Home/res/drawable/all_applications_background.xml b/samples/Home/res/drawable/all_applications_background.xml
new file mode 100644
index 000000000..69f5114ca
--- /dev/null
+++ b/samples/Home/res/drawable/all_applications_background.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/res/drawable/checkbox_background.xml
+**
+** Copyright 2007, 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.
+*/
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@drawable/all_applications_label_background" />
+</selector>
diff --git a/samples/Home/res/drawable/all_applications_button_background.xml b/samples/Home/res/drawable/all_applications_button_background.xml
new file mode 100644
index 000000000..d7bdbd8dd
--- /dev/null
+++ b/samples/Home/res/drawable/all_applications_button_background.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/res/drawable/checkbox.xml
+**
+** Copyright 2007, 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.
+*/
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/pressed_application_background_static" />
+ <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/pressed_application_background_static" />
+ <item android:state_focused="true" android:drawable="@drawable/focused_application_background_static" />
+ <item android:state_focused="false" android:drawable="@drawable/application_background_static" />
+</selector>
+
diff --git a/samples/Home/res/drawable/all_applications_label_background.9.png b/samples/Home/res/drawable/all_applications_label_background.9.png
new file mode 100644
index 000000000..b1bf466ca
--- /dev/null
+++ b/samples/Home/res/drawable/all_applications_label_background.9.png
Binary files differ
diff --git a/samples/Home/res/drawable/application_background.9.png b/samples/Home/res/drawable/application_background.9.png
new file mode 100644
index 000000000..29ae09af4
--- /dev/null
+++ b/samples/Home/res/drawable/application_background.9.png
Binary files differ
diff --git a/samples/Home/res/drawable/application_background_static.png b/samples/Home/res/drawable/application_background_static.png
new file mode 100644
index 000000000..9af69833e
--- /dev/null
+++ b/samples/Home/res/drawable/application_background_static.png
Binary files differ
diff --git a/samples/Home/res/drawable/favorite_background.xml b/samples/Home/res/drawable/favorite_background.xml
new file mode 100644
index 000000000..6d6a69c55
--- /dev/null
+++ b/samples/Home/res/drawable/favorite_background.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/res/drawable/checkbox.xml
+**
+** Copyright 2007, 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.
+*/
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/pressed_application_background_static" />
+ <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/pressed_application_background_static" />
+ <item android:state_focused="true" android:drawable="@drawable/focused_application_background_static" />
+ <item android:state_focused="false" android:drawable="@android:color/transparent" />
+</selector>
diff --git a/samples/Home/res/drawable/focused_application_background_static.png b/samples/Home/res/drawable/focused_application_background_static.png
new file mode 100644
index 000000000..3a6d47cb0
--- /dev/null
+++ b/samples/Home/res/drawable/focused_application_background_static.png
Binary files differ
diff --git a/samples/Home/res/drawable/grid_selector.xml b/samples/Home/res/drawable/grid_selector.xml
new file mode 100644
index 000000000..1116d3547
--- /dev/null
+++ b/samples/Home/res/drawable/grid_selector.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2007, 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.
+*/
+-->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_pressed="true" android:drawable="@drawable/pressed_application_background_static" />
+ <item android:state_window_focused="false" android:drawable="@drawable/focused_application_background_static" />
+ <item android:state_window_focused="true" android:drawable="@drawable/focused_application_background_static" />
+</selector>
diff --git a/samples/Home/res/drawable/hide_all_applications.png b/samples/Home/res/drawable/hide_all_applications.png
new file mode 100644
index 000000000..a67cf78de
--- /dev/null
+++ b/samples/Home/res/drawable/hide_all_applications.png
Binary files differ
diff --git a/samples/Home/res/drawable/ic_launcher_allhide.png b/samples/Home/res/drawable/ic_launcher_allhide.png
new file mode 100755
index 000000000..38e125dcc
--- /dev/null
+++ b/samples/Home/res/drawable/ic_launcher_allhide.png
Binary files differ
diff --git a/samples/Home/res/drawable/ic_launcher_allshow.png b/samples/Home/res/drawable/ic_launcher_allshow.png
new file mode 100755
index 000000000..5803d32f5
--- /dev/null
+++ b/samples/Home/res/drawable/ic_launcher_allshow.png
Binary files differ
diff --git a/samples/Home/res/drawable/ic_launcher_home.png b/samples/Home/res/drawable/ic_launcher_home.png
new file mode 100755
index 000000000..84af2a2f1
--- /dev/null
+++ b/samples/Home/res/drawable/ic_launcher_home.png
Binary files differ
diff --git a/samples/Home/res/drawable/pressed_application_background_static.png b/samples/Home/res/drawable/pressed_application_background_static.png
new file mode 100644
index 000000000..b086a3f4b
--- /dev/null
+++ b/samples/Home/res/drawable/pressed_application_background_static.png
Binary files differ
diff --git a/samples/Home/res/drawable/show_all_applications.png b/samples/Home/res/drawable/show_all_applications.png
new file mode 100644
index 000000000..ed581e1b7
--- /dev/null
+++ b/samples/Home/res/drawable/show_all_applications.png
Binary files differ
diff --git a/samples/Home/res/layout-land/home.xml b/samples/Home/res/layout-land/home.xml
new file mode 100644
index 000000000..d723c69a2
--- /dev/null
+++ b/samples/Home/res/layout-land/home.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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"
+ xmlns:home="http://schemas.android.com/apk/res/com.example.android.home"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <!-- All applications on the top side of the screen -->
+ <GridView android:id="@+id/all_apps"
+ android:background="@drawable/application_background"
+ android:persistentDrawingCache="animation|scrolling"
+ android:alwaysDrawnWithCache="true"
+ android:scrollbars="none"
+ android:drawSelectorOnTop="false"
+ android:listSelector="@drawable/grid_selector"
+ android:numColumns="auto_fit"
+ android:columnWidth="78dp"
+ android:stretchMode="spacingWidth"
+ android:layout_weight="1.0"
+ android:layout_height="0dip"
+ android:layout_width="fill_parent"
+ android:stackFromBottom="true"
+ android:visibility="invisible" />
+
+ <!-- Favorites and Recents -->
+ <com.example.android.home.ApplicationsStackLayout android:id="@+id/faves_and_recents"
+ home:stackOrientation="horizontal"
+ home:marginLeft="1dip"
+ home:marginRight="1dip"
+ android:layout_marginTop="0dip"
+ android:layout_width="fill_parent"
+ android:layout_height="65dip"
+ android:background="@drawable/application_background" />
+
+</LinearLayout>
diff --git a/samples/Home/res/layout-port/home.xml b/samples/Home/res/layout-port/home.xml
new file mode 100644
index 000000000..d723c69a2
--- /dev/null
+++ b/samples/Home/res/layout-port/home.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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"
+ xmlns:home="http://schemas.android.com/apk/res/com.example.android.home"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <!-- All applications on the top side of the screen -->
+ <GridView android:id="@+id/all_apps"
+ android:background="@drawable/application_background"
+ android:persistentDrawingCache="animation|scrolling"
+ android:alwaysDrawnWithCache="true"
+ android:scrollbars="none"
+ android:drawSelectorOnTop="false"
+ android:listSelector="@drawable/grid_selector"
+ android:numColumns="auto_fit"
+ android:columnWidth="78dp"
+ android:stretchMode="spacingWidth"
+ android:layout_weight="1.0"
+ android:layout_height="0dip"
+ android:layout_width="fill_parent"
+ android:stackFromBottom="true"
+ android:visibility="invisible" />
+
+ <!-- Favorites and Recents -->
+ <com.example.android.home.ApplicationsStackLayout android:id="@+id/faves_and_recents"
+ home:stackOrientation="horizontal"
+ home:marginLeft="1dip"
+ home:marginRight="1dip"
+ android:layout_marginTop="0dip"
+ android:layout_width="fill_parent"
+ android:layout_height="65dip"
+ android:background="@drawable/application_background" />
+
+</LinearLayout>
diff --git a/samples/Home/res/layout/all_applications_button.xml b/samples/Home/res/layout/all_applications_button.xml
new file mode 100644
index 000000000..88430b355
--- /dev/null
+++ b/samples/Home/res/layout/all_applications_button.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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:id="@+id/show_all_apps"
+ android:layout_width="78dip"
+ android:layout_height="65dip"
+ android:orientation="vertical"
+ android:gravity="center_vertical"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="@drawable/all_applications_button_background">
+
+ <CheckBox
+ android:id="@+id/show_all_apps_check"
+ android:focusable="false"
+ android:clickable="false"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:background="@drawable/all_applications_background"
+ android:button="@drawable/all_applications"
+ android:text="@string/show_all_apps"
+ android:textSize="12dip"
+ android:maxLines="1"
+ android:duplicateParentState="true"
+ android:textColor="@color/bright_text_dark_focused"
+ android:gravity="center_horizontal" />
+
+</LinearLayout>
diff --git a/samples/Home/res/layout/application.xml b/samples/Home/res/layout/application.xml
new file mode 100644
index 000000000..4ddc96ee2
--- /dev/null
+++ b/samples/Home/res/layout/application.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/label"
+ android:layout_width="78dip"
+ android:layout_height="65dip"
+ android:paddingTop="4dip"
+ android:textSize="12dip"
+ android:singleLine="true"
+ android:ellipsize="end"
+ android:textColor="@color/bright_text_dark_focused"
+ android:gravity="center_horizontal|center_vertical" />
diff --git a/samples/Home/res/layout/favorite.xml b/samples/Home/res/layout/favorite.xml
new file mode 100644
index 000000000..e100a43e4
--- /dev/null
+++ b/samples/Home/res/layout/favorite.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="78dip"
+ android:layout_height="65dip"
+ android:paddingTop="3dip"
+ android:paddingBottom="3dip"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="@drawable/favorite_background"
+ android:textSize="12dip"
+ android:maxLines="1"
+ android:ellipsize="end"
+ android:textColor="@color/bright_text_dark_focused"
+ android:gravity="center_horizontal|bottom" />
diff --git a/samples/Home/res/layout/wallpaper.xml b/samples/Home/res/layout/wallpaper.xml
new file mode 100644
index 000000000..92dc65e00
--- /dev/null
+++ b/samples/Home/res/layout/wallpaper.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/samples/SampleCode/res/layout/image_switcher_1.xml
+**
+** Copyright 2007, 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.
+*/
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:padding="5dip"
+ android:background="#70000000"
+ android:text="@string/wallpaper_instructions"
+ android:layout_alignParentTop="true"
+ android:layout_centerHorizontal="true"
+ />
+
+ <Gallery android:id="@+id/gallery"
+ android:background="#70000000"
+ android:layout_width="fill_parent"
+ android:layout_height="60dip"
+ android:layout_alignParentBottom="true"
+ android:layout_alignParentLeft="true"
+ android:gravity="center_vertical"
+ android:spacing="16dp"
+ />
+
+</RelativeLayout>
+
diff --git a/samples/Home/res/values-cs/strings.xml b/samples/Home/res/values-cs/strings.xml
new file mode 100644
index 000000000..28305341c
--- /dev/null
+++ b/samples/Home/res/values-cs/strings.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="home_title">"Domů"</string>
+ <string name="show_all_apps">"Vše"</string>
+ <string name="menu_wallpaper">"Tapeta"</string>
+ <string name="menu_search">"Hledat"</string>
+ <!-- no translation found for menu_settings (1769059051084007158) -->
+ <skip />
+ <string name="wallpaper_instructions">"Klepnutím na obrázek nastavíte tapetu portrétu"</string>
+</resources>
diff --git a/samples/Home/res/values-de-rDE/strings.xml b/samples/Home/res/values-de-rDE/strings.xml
new file mode 100644
index 000000000..28a1b7cff
--- /dev/null
+++ b/samples/Home/res/values-de-rDE/strings.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="home_title">"Startseite"</string>
+ <string name="show_all_apps">"Alle"</string>
+ <string name="menu_wallpaper">"Bildschirmhintergrund"</string>
+ <string name="menu_search">"Suchen"</string>
+ <!-- no translation found for menu_settings (1769059051084007158) -->
+ <skip />
+ <string name="wallpaper_instructions">"Tippen Sie auf Bild, um Porträt-Bildschirmhintergrund einzustellen"</string>
+</resources>
diff --git a/samples/Home/res/values-es-rUS/strings.xml b/samples/Home/res/values-es-rUS/strings.xml
new file mode 100644
index 000000000..63252cced
--- /dev/null
+++ b/samples/Home/res/values-es-rUS/strings.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="home_title">"Casa"</string>
+ <string name="show_all_apps">"Todo"</string>
+ <string name="menu_wallpaper">"Papel tapiz"</string>
+ <string name="menu_search">"Búsqueda"</string>
+ <!-- no translation found for menu_settings (1769059051084007158) -->
+ <skip />
+ <string name="wallpaper_instructions">"Puntee en la imagen para establecer papel tapiz vertical"</string>
+</resources>
diff --git a/samples/Home/res/values-land/strings.xml b/samples/Home/res/values-land/strings.xml
new file mode 100644
index 000000000..a435f41ef
--- /dev/null
+++ b/samples/Home/res/values-land/strings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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>
+ <!-- Wallpaper -->
+ <string name="wallpaper_instructions">Tap image to set landscape wallpaper</string>
+</resources>
+
diff --git a/samples/Home/res/values-nl-rNL/strings.xml b/samples/Home/res/values-nl-rNL/strings.xml
new file mode 100644
index 000000000..4a5ae4f94
--- /dev/null
+++ b/samples/Home/res/values-nl-rNL/strings.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="home_title">"Start"</string>
+ <string name="show_all_apps">"Alles"</string>
+ <string name="menu_wallpaper">"Achtergrond"</string>
+ <string name="menu_search">"Zoeken"</string>
+ <!-- no translation found for menu_settings (1769059051084007158) -->
+ <skip />
+ <string name="wallpaper_instructions">"Tik op afbeelding om portretachtergrond in te stellen"</string>
+</resources>
diff --git a/samples/Home/res/values/attrs.xml b/samples/Home/res/values/attrs.xml
new file mode 100644
index 000000000..d14e4fed6
--- /dev/null
+++ b/samples/Home/res/values/attrs.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* Copyright 2007, 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>
+ <declare-styleable name="ApplicationsStackLayout">
+ <attr name="stackOrientation">
+ <enum name="horizontal" value="0" />
+ <enum name="vertical" value="1" />
+ </attr>
+ <attr name="marginLeft" format="dimension" />
+ <attr name="marginTop" format="dimension" />
+ <attr name="marginRight" format="dimension" />
+ <attr name="marginBottom" format="dimension" />
+ </declare-styleable>
+</resources>
diff --git a/samples/Home/res/values/strings.xml b/samples/Home/res/values/strings.xml
new file mode 100644
index 000000000..f173434fc
--- /dev/null
+++ b/samples/Home/res/values/strings.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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>
+ <!-- Home -->
+ <string name="home_title">Home Sample</string>
+ <string name="show_all_apps">All</string>
+
+ <!-- Home Menus -->
+ <string name="menu_wallpaper">Wallpaper</string>
+ <string name="menu_search">Search</string>
+ <string name="menu_settings">Settings</string>
+
+ <!-- Wallpaper -->
+ <string name="wallpaper_instructions">Tap picture to set portrait wallpaper</string>
+</resources>
+
diff --git a/samples/Home/res/values/styles.xml b/samples/Home/res/values/styles.xml
new file mode 100644
index 000000000..e87aa58e2
--- /dev/null
+++ b/samples/Home/res/values/styles.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<resources>
+ <style name="Theme" parent="android:Theme">
+ <item name="android:windowNoTitle">true</item>
+ </style>
+</resources>
diff --git a/samples/Home/src/com/example/android/home/ApplicationInfo.java b/samples/Home/src/com/example/android/home/ApplicationInfo.java
new file mode 100644
index 000000000..79f6234c8
--- /dev/null
+++ b/samples/Home/src/com/example/android/home/ApplicationInfo.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2007 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.home;
+
+import android.content.ComponentName;
+import android.content.Intent;
+import android.graphics.drawable.Drawable;
+
+/**
+ * Represents a launchable application. An application is made of a name (or title), an intent
+ * and an icon.
+ */
+class ApplicationInfo {
+ /**
+ * The application name.
+ */
+ CharSequence title;
+
+ /**
+ * The intent used to start the application.
+ */
+ Intent intent;
+
+ /**
+ * The application icon.
+ */
+ Drawable icon;
+
+ /**
+ * When set to true, indicates that the icon has been resized.
+ */
+ boolean filtered;
+
+ /**
+ * Creates the application intent based on a component name and various launch flags.
+ *
+ * @param className the class name of the component representing the intent
+ * @param launchFlags the launch flags
+ */
+ final void setActivity(ComponentName className, int launchFlags) {
+ intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(Intent.CATEGORY_LAUNCHER);
+ intent.setComponent(className);
+ intent.setFlags(launchFlags);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof ApplicationInfo)) {
+ return false;
+ }
+
+ ApplicationInfo that = (ApplicationInfo) o;
+ return title.equals(that.title) &&
+ intent.getComponent().getClassName().equals(
+ that.intent.getComponent().getClassName());
+ }
+
+ @Override
+ public int hashCode() {
+ int result;
+ result = (title != null ? title.hashCode() : 0);
+ final String name = intent.getComponent().getClassName();
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ return result;
+ }
+}
diff --git a/samples/Home/src/com/example/android/home/ApplicationsStackLayout.java b/samples/Home/src/com/example/android/home/ApplicationsStackLayout.java
new file mode 100644
index 000000000..ccc1f435b
--- /dev/null
+++ b/samples/Home/src/com/example/android/home/ApplicationsStackLayout.java
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2007 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.home;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.LayoutInflater;
+import android.widget.TextView;
+import android.*;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The ApplicationsStackLayout is a specialized layout used for the purpose of the home screen
+ * only. This layout stacks various icons in three distinct areas: the recents, the favorites
+ * (or faves) and the button.
+ *
+ * This layout supports two different orientations: vertical and horizontal. When horizontal,
+ * the areas are laid out this way:
+ *
+ * [RECENTS][FAVES][BUTTON]
+ *
+ * When vertical, the layout is the following:
+ *
+ * [RECENTS]
+ * [FAVES]
+ * [BUTTON]
+ *
+ * The layout operates from the "bottom up" (or from right to left.) This means that the button
+ * area will first be laid out, then the faves area, then the recents. When there are too many
+ * favorites, the recents area is not displayed.
+ *
+ * The following attributes can be set in XML:
+ *
+ * orientation: horizontal or vertical
+ * marginLeft: the left margin of each element in the stack
+ * marginTop: the top margin of each element in the stack
+ * marginRight: the right margin of each element in the stack
+ * marginBottom: the bottom margin of each element in the stack
+ */
+public class ApplicationsStackLayout extends ViewGroup implements View.OnClickListener {
+ public static final int HORIZONTAL = 0;
+ public static final int VERTICAL = 1;
+
+ private View mButton;
+ private LayoutInflater mInflater;
+
+ private int mFavoritesEnd;
+ private int mFavoritesStart;
+
+ private List<ApplicationInfo> mFavorites;
+ private List<ApplicationInfo> mRecents;
+
+ private int mOrientation = VERTICAL;
+
+ private int mMarginLeft;
+ private int mMarginTop;
+ private int mMarginRight;
+ private int mMarginBottom;
+
+ private Rect mDrawRect = new Rect();
+
+ private Drawable mBackground;
+ private int mIconSize;
+
+ public ApplicationsStackLayout(Context context) {
+ super(context);
+ initLayout();
+ }
+
+ public ApplicationsStackLayout(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ TypedArray a =
+ context.obtainStyledAttributes(attrs, R.styleable.ApplicationsStackLayout);
+
+ mOrientation = a.getInt(R.styleable.ApplicationsStackLayout_stackOrientation, VERTICAL);
+
+ mMarginLeft = a.getDimensionPixelSize(R.styleable.ApplicationsStackLayout_marginLeft, 0);
+ mMarginTop = a.getDimensionPixelSize(R.styleable.ApplicationsStackLayout_marginTop, 0);
+ mMarginRight = a.getDimensionPixelSize(R.styleable.ApplicationsStackLayout_marginRight, 0);
+ mMarginBottom = a.getDimensionPixelSize(R.styleable.ApplicationsStackLayout_marginBottom, 0);
+
+ a.recycle();
+
+ mIconSize = 42; //(int) getResources().getDimension(android.R.dimen.app_icon_size);
+
+ initLayout();
+ }
+
+ private void initLayout() {
+ mInflater = LayoutInflater.from(getContext());
+ mButton = mInflater.inflate(R.layout.all_applications_button, this, false);
+ addView(mButton);
+
+ mBackground = getBackground();
+ setBackgroundDrawable(null);
+ setWillNotDraw(false);
+ }
+
+ /**
+ * Return the current orientation, either VERTICAL (default) or HORIZONTAL.
+ *
+ * @return the stack orientation
+ */
+ public int getOrientation() {
+ return mOrientation;
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ final Drawable background = mBackground;
+
+ final int right = getWidth();
+ final int bottom = getHeight();
+
+ // Draw behind recents
+ if (mOrientation == VERTICAL) {
+ mDrawRect.set(0, 0, right, mFavoritesStart);
+ } else {
+ mDrawRect.set(0, 0, mFavoritesStart, bottom);
+ }
+ background.setBounds(mDrawRect);
+ background.draw(canvas);
+
+ // Draw behind favorites
+ if (mFavoritesStart > -1) {
+ if (mOrientation == VERTICAL) {
+ mDrawRect.set(0, mFavoritesStart, right, mFavoritesEnd);
+ } else {
+ mDrawRect.set(mFavoritesStart, 0, mFavoritesEnd, bottom);
+ }
+ background.setBounds(mDrawRect);
+ background.draw(canvas);
+ }
+
+ super.onDraw(canvas);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+
+ final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+ final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
+
+ final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
+ final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
+
+ if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY) {
+ throw new IllegalStateException("ApplicationsStackLayout can only be used with "
+ + "measure spec mode=EXACTLY");
+ }
+
+ setMeasuredDimension(widthSize, heightSize);
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ removeAllApplications();
+
+ LayoutParams layoutParams = mButton.getLayoutParams();
+ final int widthSpec = MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.EXACTLY);
+ final int heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY);
+ mButton.measure(widthSpec, heightSpec);
+
+ if (mOrientation == VERTICAL) {
+ layoutVertical();
+ } else {
+ layoutHorizontal();
+ }
+ }
+
+ private void layoutVertical() {
+ int childLeft = 0;
+ int childTop = getHeight();
+
+ int childWidth = mButton.getMeasuredWidth();
+ int childHeight = mButton.getMeasuredHeight();
+
+ childTop -= childHeight + mMarginBottom;
+ mButton.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
+ childTop -= mMarginTop;
+ mFavoritesEnd = childTop - mMarginBottom;
+
+ int oldChildTop = childTop;
+ childTop = stackApplications(mFavorites, childLeft, childTop);
+ if (childTop != oldChildTop) {
+ mFavoritesStart = childTop + mMarginTop;
+ } else {
+ mFavoritesStart = -1;
+ }
+
+ stackApplications(mRecents, childLeft, childTop);
+ }
+
+ private void layoutHorizontal() {
+ int childLeft = getWidth();
+ int childTop = 0;
+
+ int childWidth = mButton.getMeasuredWidth();
+ int childHeight = mButton.getMeasuredHeight();
+
+ childLeft -= childWidth;
+ mButton.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
+ childLeft -= mMarginLeft;
+ mFavoritesEnd = childLeft - mMarginRight;
+
+ int oldChildLeft = childLeft;
+ childLeft = stackApplications(mFavorites, childLeft, childTop);
+ if (childLeft != oldChildLeft) {
+ mFavoritesStart = childLeft + mMarginLeft;
+ } else {
+ mFavoritesStart = -1;
+ }
+
+ stackApplications(mRecents, childLeft, childTop);
+ }
+
+ private int stackApplications(List<ApplicationInfo> applications, int childLeft, int childTop) {
+ LayoutParams layoutParams;
+ int widthSpec;
+ int heightSpec;
+ int childWidth;
+ int childHeight;
+
+ final boolean isVertical = mOrientation == VERTICAL;
+
+ final int count = applications.size();
+ for (int i = count - 1; i >= 0; i--) {
+ final ApplicationInfo info = applications.get(i);
+ final View view = createApplicationIcon(mInflater, this, info);
+
+ layoutParams = view.getLayoutParams();
+ widthSpec = MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.EXACTLY);
+ heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY);
+ view.measure(widthSpec, heightSpec);
+
+ childWidth = view.getMeasuredWidth();
+ childHeight = view.getMeasuredHeight();
+
+ if (isVertical) {
+ childTop -= childHeight + mMarginBottom;
+
+ if (childTop < 0) {
+ childTop += childHeight + mMarginBottom;
+ break;
+ }
+ } else {
+ childLeft -= childWidth + mMarginRight;
+
+ if (childLeft < 0) {
+ childLeft += childWidth + mMarginRight;
+ break;
+ }
+ }
+
+ addViewInLayout(view, -1, layoutParams);
+
+ view.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
+
+ if (isVertical) {
+ childTop -= mMarginTop;
+ } else {
+ childLeft -= mMarginLeft;
+ }
+ }
+
+ return isVertical ? childTop : childLeft;
+ }
+
+ private void removeAllApplications() {
+ final int count = getChildCount();
+ for (int i = count - 1; i >= 0; i--) {
+ final View view = getChildAt(i);
+ if (view != mButton) {
+ removeViewAt(i);
+ }
+ }
+ }
+
+ private View createApplicationIcon(LayoutInflater inflater,
+ ViewGroup group, ApplicationInfo info) {
+
+ TextView textView = (TextView) inflater.inflate(R.layout.favorite, group, false);
+
+ info.icon.setBounds(0, 0, mIconSize, mIconSize);
+ textView.setCompoundDrawables(null, info.icon, null, null);
+ textView.setText(info.title);
+
+ textView.setTag(info.intent);
+ textView.setOnClickListener(this);
+
+ return textView;
+ }
+
+ /**
+ * Sets the list of favorites.
+ *
+ * @param applications the applications to put in the favorites area
+ */
+ public void setFavorites(List<ApplicationInfo> applications) {
+ mFavorites = applications;
+ requestLayout();
+ }
+
+ /**
+ * Sets the list of recents.
+ *
+ * @param applications the applications to put in the recents area
+ */
+ public void setRecents(List<ApplicationInfo> applications) {
+ mRecents = applications;
+ requestLayout();
+ }
+
+ public void onClick(View v) {
+ getContext().startActivity((Intent) v.getTag());
+ }
+}
diff --git a/samples/Home/src/com/example/android/home/Home.java b/samples/Home/src/com/example/android/home/Home.java
new file mode 100644
index 000000000..7e94cc388
--- /dev/null
+++ b/samples/Home/src/com/example/android/home/Home.java
@@ -0,0 +1,743 @@
+/*
+ * Copyright (C) 2007 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.home;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.app.SearchManager;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.PaintFlagsDrawFilter;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.graphics.ColorFilter;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.PaintDrawable;
+import android.os.Bundle;
+import android.os.Environment;
+import android.util.Log;
+import android.util.Xml;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.view.animation.LayoutAnimationController;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.CheckBox;
+import android.widget.GridView;
+import android.widget.TextView;
+
+import java.io.IOException;
+import java.io.FileReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+public class Home extends Activity {
+ /**
+ * Tag used for logging errors.
+ */
+ private static final String LOG_TAG = "Home";
+
+ /**
+ * Keys during freeze/thaw.
+ */
+ private static final String KEY_SAVE_GRID_OPENED = "grid.opened";
+
+ private static final String DEFAULT_FAVORITES_PATH = "etc/favorites.xml";
+
+ private static final String TAG_FAVORITES = "favorites";
+ private static final String TAG_FAVORITE = "favorite";
+ private static final String TAG_PACKAGE = "package";
+ private static final String TAG_CLASS = "class";
+
+ // Identifiers for option menu items
+ private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1;
+ private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
+ private static final int MENU_SETTINGS = MENU_SEARCH + 1;
+
+ /**
+ * Maximum number of recent tasks to query.
+ */
+ private static final int MAX_RECENT_TASKS = 20;
+
+ private static boolean mWallpaperChecked;
+ private static ArrayList<ApplicationInfo> mApplications;
+ private static LinkedList<ApplicationInfo> mFavorites;
+
+ private final BroadcastReceiver mWallpaperReceiver = new WallpaperIntentReceiver();
+ private final BroadcastReceiver mApplicationsReceiver = new ApplicationsIntentReceiver();
+
+ private GridView mGrid;
+
+ private LayoutAnimationController mShowLayoutAnimation;
+ private LayoutAnimationController mHideLayoutAnimation;
+
+ private boolean mBlockAnimation;
+
+ private View mShowApplications;
+ private CheckBox mShowApplicationsCheck;
+
+ private ApplicationsStackLayout mApplicationsStack;
+
+ private Animation mGridEntry;
+ private Animation mGridExit;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
+
+ setContentView(R.layout.home);
+
+ registerIntentReceivers();
+
+ setDefaultWallpaper();
+
+ loadApplications(true);
+
+ bindApplications();
+ bindFavorites(true);
+ bindRecents();
+ bindButtons();
+
+ mGridEntry = AnimationUtils.loadAnimation(this, R.anim.grid_entry);
+ mGridExit = AnimationUtils.loadAnimation(this, R.anim.grid_exit);
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+
+ // Close the menu
+ if (Intent.ACTION_MAIN.equals(intent.getAction())) {
+ getWindow().closeAllPanels();
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ // Remove the callback for the cached drawables or we leak
+ // the previous Home screen on orientation change
+ final int count = mApplications.size();
+ for (int i = 0; i < count; i++) {
+ mApplications.get(i).icon.setCallback(null);
+ }
+
+ unregisterReceiver(mWallpaperReceiver);
+ unregisterReceiver(mApplicationsReceiver);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ bindRecents();
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle state) {
+ super.onRestoreInstanceState(state);
+ final boolean opened = state.getBoolean(KEY_SAVE_GRID_OPENED, false);
+ if (opened) {
+ showApplications(false);
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(KEY_SAVE_GRID_OPENED, mGrid.getVisibility() == View.VISIBLE);
+ }
+
+ /**
+ * Registers various intent receivers. The current implementation registers
+ * only a wallpaper intent receiver to let other applications change the
+ * wallpaper.
+ */
+ private void registerIntentReceivers() {
+ IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
+ registerReceiver(mWallpaperReceiver, filter);
+
+ filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+ filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+ filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+ filter.addDataScheme("package");
+ registerReceiver(mApplicationsReceiver, filter);
+ }
+
+ /**
+ * Creates a new appplications adapter for the grid view and registers it.
+ */
+ private void bindApplications() {
+ if (mGrid == null) {
+ mGrid = (GridView) findViewById(R.id.all_apps);
+ }
+ mGrid.setAdapter(new ApplicationsAdapter(this, mApplications));
+ mGrid.setSelection(0);
+
+ if (mApplicationsStack == null) {
+ mApplicationsStack = (ApplicationsStackLayout) findViewById(R.id.faves_and_recents);
+ }
+ }
+
+ /**
+ * Binds actions to the various buttons.
+ */
+ private void bindButtons() {
+ mShowApplications = findViewById(R.id.show_all_apps);
+ mShowApplications.setOnClickListener(new ShowApplications());
+ mShowApplicationsCheck = (CheckBox) findViewById(R.id.show_all_apps_check);
+
+ mGrid.setOnItemClickListener(new ApplicationLauncher());
+ }
+
+ /**
+ * When no wallpaper was manually set, a default wallpaper is used instead.
+ */
+ private void setDefaultWallpaper() {
+ if (!mWallpaperChecked) {
+ Drawable wallpaper = peekWallpaper();
+ if (wallpaper == null) {
+ try {
+ clearWallpaper();
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "Failed to clear wallpaper " + e);
+ }
+ } else {
+ getWindow().setBackgroundDrawable(new ClippedDrawable(wallpaper));
+ }
+ mWallpaperChecked = true;
+ }
+ }
+
+ /**
+ * Refreshes the favorite applications stacked over the all apps button.
+ * The number of favorites depends on the user.
+ */
+ private void bindFavorites(boolean isLaunching) {
+ if (!isLaunching || mFavorites == null) {
+
+ FileReader favReader;
+
+ // Environment.getRootDirectory() is a fancy way of saying ANDROID_ROOT or "/system".
+ final File favFile = new File(Environment.getRootDirectory(), DEFAULT_FAVORITES_PATH);
+ try {
+ favReader = new FileReader(favFile);
+ } catch (FileNotFoundException e) {
+ Log.e(LOG_TAG, "Couldn't find or open favorites file " + favFile);
+ return;
+ }
+
+ if (mFavorites == null) {
+ mFavorites = new LinkedList<ApplicationInfo>();
+ } else {
+ mFavorites.clear();
+ }
+
+ final Intent intent = new Intent(Intent.ACTION_MAIN, null);
+ intent.addCategory(Intent.CATEGORY_LAUNCHER);
+
+ final PackageManager packageManager = getPackageManager();
+
+ try {
+ final XmlPullParser parser = Xml.newPullParser();
+ parser.setInput(favReader);
+
+ beginDocument(parser, TAG_FAVORITES);
+
+ ApplicationInfo info;
+
+ while (true) {
+ nextElement(parser);
+
+ String name = parser.getName();
+ if (!TAG_FAVORITE.equals(name)) {
+ break;
+ }
+
+ final String favoritePackage = parser.getAttributeValue(null, TAG_PACKAGE);
+ final String favoriteClass = parser.getAttributeValue(null, TAG_CLASS);
+
+ final ComponentName cn = new ComponentName(favoritePackage, favoriteClass);
+ intent.setComponent(cn);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ info = getApplicationInfo(packageManager, intent);
+ if (info != null) {
+ info.intent = intent;
+ mFavorites.addFirst(info);
+ }
+ }
+ } catch (XmlPullParserException e) {
+ Log.w(LOG_TAG, "Got exception parsing favorites.", e);
+ } catch (IOException e) {
+ Log.w(LOG_TAG, "Got exception parsing favorites.", e);
+ }
+ }
+
+ mApplicationsStack.setFavorites(mFavorites);
+ }
+
+ private static void beginDocument(XmlPullParser parser, String firstElementName)
+ throws XmlPullParserException, IOException {
+
+ int type;
+ while ((type = parser.next()) != XmlPullParser.START_TAG &&
+ type != XmlPullParser.END_DOCUMENT) {
+ // Empty
+ }
+
+ if (type != XmlPullParser.START_TAG) {
+ throw new XmlPullParserException("No start tag found");
+ }
+
+ if (!parser.getName().equals(firstElementName)) {
+ throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() +
+ ", expected " + firstElementName);
+ }
+ }
+
+ private static void nextElement(XmlPullParser parser) throws XmlPullParserException, IOException {
+ int type;
+ while ((type = parser.next()) != XmlPullParser.START_TAG &&
+ type != XmlPullParser.END_DOCUMENT) {
+ // Empty
+ }
+ }
+
+ /**
+ * Refreshes the recently launched applications stacked over the favorites. The number
+ * of recents depends on how many favorites are present.
+ */
+ private void bindRecents() {
+ final PackageManager manager = getPackageManager();
+ final ActivityManager tasksManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
+ final List<ActivityManager.RecentTaskInfo> recentTasks = tasksManager.getRecentTasks(
+ MAX_RECENT_TASKS, 0);
+
+ final int count = recentTasks.size();
+ final ArrayList<ApplicationInfo> recents = new ArrayList<ApplicationInfo>();
+
+ for (int i = count - 1; i >= 0; i--) {
+ final Intent intent = recentTasks.get(i).baseIntent;
+
+ if (Intent.ACTION_MAIN.equals(intent.getAction()) &&
+ !intent.hasCategory(Intent.CATEGORY_HOME)) {
+
+ ApplicationInfo info = getApplicationInfo(manager, intent);
+ if (info != null) {
+ info.intent = intent;
+ if (!mFavorites.contains(info)) {
+ recents.add(info);
+ }
+ }
+ }
+ }
+
+ mApplicationsStack.setRecents(recents);
+ }
+
+ private static ApplicationInfo getApplicationInfo(PackageManager manager, Intent intent) {
+ final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);
+
+ if (resolveInfo == null) {
+ return null;
+ }
+
+ final ApplicationInfo info = new ApplicationInfo();
+ final ActivityInfo activityInfo = resolveInfo.activityInfo;
+ info.icon = activityInfo.loadIcon(manager);
+ if (info.title == null || info.title.length() == 0) {
+ info.title = activityInfo.loadLabel(manager);
+ }
+ if (info.title == null) {
+ info.title = "";
+ }
+ return info;
+ }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ switch (event.getKeyCode()) {
+ case KeyEvent.KEYCODE_BACK:
+ return true;
+ case KeyEvent.KEYCODE_HOME:
+ return true;
+ }
+ }
+
+ return super.dispatchKeyEvent(event);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+
+ menu.add(0, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper)
+ .setIcon(android.R.drawable.ic_menu_gallery)
+ .setAlphabeticShortcut('W');
+ menu.add(0, MENU_SEARCH, 0, R.string.menu_search)
+ .setIcon(android.R.drawable.ic_search_category_default)
+ .setAlphabeticShortcut(SearchManager.MENU_KEY);
+ menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
+ .setIcon(android.R.drawable.ic_menu_preferences)
+ .setIntent(new Intent(android.provider.Settings.ACTION_SETTINGS));
+
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case MENU_WALLPAPER_SETTINGS:
+ startWallpaper();
+ return true;
+ case MENU_SEARCH:
+ onSearchRequested();
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ private void startWallpaper() {
+ final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
+ startActivity(Intent.createChooser(pickWallpaper, getString(R.string.menu_wallpaper)));
+ }
+
+ /**
+ * Loads the list of installed applications in mApplications.
+ */
+ private void loadApplications(boolean isLaunching) {
+ if (isLaunching && mApplications != null) {
+ return;
+ }
+
+ PackageManager manager = getPackageManager();
+
+ Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
+ mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+
+ final List<ResolveInfo> apps = manager.queryIntentActivities(mainIntent, 0);
+ Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
+
+ if (apps != null) {
+ final int count = apps.size();
+
+ if (mApplications == null) {
+ mApplications = new ArrayList<ApplicationInfo>(count);
+ }
+ mApplications.clear();
+
+ for (int i = 0; i < count; i++) {
+ ApplicationInfo application = new ApplicationInfo();
+ ResolveInfo info = apps.get(i);
+
+ application.title = info.loadLabel(manager);
+ application.setActivity(new ComponentName(
+ info.activityInfo.applicationInfo.packageName,
+ info.activityInfo.name),
+ Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+ application.icon = info.activityInfo.loadIcon(manager);
+
+ mApplications.add(application);
+ }
+ }
+ }
+
+ /**
+ * Shows all of the applications by playing an animation on the grid.
+ */
+ private void showApplications(boolean animate) {
+ if (mBlockAnimation) {
+ return;
+ }
+ mBlockAnimation = true;
+
+ mShowApplicationsCheck.toggle();
+
+ if (mShowLayoutAnimation == null) {
+ mShowLayoutAnimation = AnimationUtils.loadLayoutAnimation(
+ this, R.anim.show_applications);
+ }
+
+ // This enables a layout animation; if you uncomment this code, you need to
+ // comment the line mGrid.startAnimation() below
+// mGrid.setLayoutAnimationListener(new ShowGrid());
+// mGrid.setLayoutAnimation(mShowLayoutAnimation);
+// mGrid.startLayoutAnimation();
+
+ if (animate) {
+ mGridEntry.setAnimationListener(new ShowGrid());
+ mGrid.startAnimation(mGridEntry);
+ }
+
+ mGrid.setVisibility(View.VISIBLE);
+
+ if (!animate) {
+ mBlockAnimation = false;
+ }
+
+ // ViewDebug.startHierarchyTracing("Home", mGrid);
+ }
+
+ /**
+ * Hides all of the applications by playing an animation on the grid.
+ */
+ private void hideApplications() {
+ if (mBlockAnimation) {
+ return;
+ }
+ mBlockAnimation = true;
+
+ mShowApplicationsCheck.toggle();
+
+ if (mHideLayoutAnimation == null) {
+ mHideLayoutAnimation = AnimationUtils.loadLayoutAnimation(
+ this, R.anim.hide_applications);
+ }
+
+ mGridExit.setAnimationListener(new HideGrid());
+ mGrid.startAnimation(mGridExit);
+ mGrid.setVisibility(View.INVISIBLE);
+ mShowApplications.requestFocus();
+
+ // This enables a layout animation; if you uncomment this code, you need to
+ // comment the line mGrid.startAnimation() above
+// mGrid.setLayoutAnimationListener(new HideGrid());
+// mGrid.setLayoutAnimation(mHideLayoutAnimation);
+// mGrid.startLayoutAnimation();
+ }
+
+ /**
+ * Receives intents from other applications to change the wallpaper.
+ */
+ private class WallpaperIntentReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ getWindow().setBackgroundDrawable(new ClippedDrawable(getWallpaper()));
+ }
+ }
+
+ /**
+ * Receives notifications when applications are added/removed.
+ */
+ private class ApplicationsIntentReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ loadApplications(false);
+ bindApplications();
+ bindRecents();
+ bindFavorites(false);
+ }
+ }
+
+ /**
+ * GridView adapter to show the list of all installed applications.
+ */
+ private class ApplicationsAdapter extends ArrayAdapter<ApplicationInfo> {
+ private Rect mOldBounds = new Rect();
+
+ public ApplicationsAdapter(Context context, ArrayList<ApplicationInfo> apps) {
+ super(context, 0, apps);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ final ApplicationInfo info = mApplications.get(position);
+
+ if (convertView == null) {
+ final LayoutInflater inflater = getLayoutInflater();
+ convertView = inflater.inflate(R.layout.application, parent, false);
+ }
+
+ Drawable icon = info.icon;
+
+ if (!info.filtered) {
+ //final Resources resources = getContext().getResources();
+ int width = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);
+ int height = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);
+
+ final int iconWidth = icon.getIntrinsicWidth();
+ final int iconHeight = icon.getIntrinsicHeight();
+
+ if (icon instanceof PaintDrawable) {
+ PaintDrawable painter = (PaintDrawable) icon;
+ painter.setIntrinsicWidth(width);
+ painter.setIntrinsicHeight(height);
+ }
+
+ if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) {
+ final float ratio = (float) iconWidth / iconHeight;
+
+ if (iconWidth > iconHeight) {
+ height = (int) (width / ratio);
+ } else if (iconHeight > iconWidth) {
+ width = (int) (height * ratio);
+ }
+
+ final Bitmap.Config c =
+ icon.getOpacity() != PixelFormat.OPAQUE ?
+ Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
+ final Bitmap thumb = Bitmap.createBitmap(width, height, c);
+ final Canvas canvas = new Canvas(thumb);
+ canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0));
+ // Copy the old bounds to restore them later
+ // If we were to do oldBounds = icon.getBounds(),
+ // the call to setBounds() that follows would
+ // change the same instance and we would lose the
+ // old bounds
+ mOldBounds.set(icon.getBounds());
+ icon.setBounds(0, 0, width, height);
+ icon.draw(canvas);
+ icon.setBounds(mOldBounds);
+ icon = info.icon = new BitmapDrawable(thumb);
+ info.filtered = true;
+ }
+ }
+
+ final TextView textView = (TextView) convertView.findViewById(R.id.label);
+ textView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
+ textView.setText(info.title);
+
+ return convertView;
+ }
+ }
+
+ /**
+ * Shows and hides the applications grid view.
+ */
+ private class ShowApplications implements View.OnClickListener {
+ public void onClick(View v) {
+ if (mGrid.getVisibility() != View.VISIBLE) {
+ showApplications(true);
+ } else {
+ hideApplications();
+ }
+ }
+ }
+
+ /**
+ * Hides the applications grid when the layout animation is over.
+ */
+ private class HideGrid implements Animation.AnimationListener {
+ public void onAnimationStart(Animation animation) {
+ }
+
+ public void onAnimationEnd(Animation animation) {
+ mBlockAnimation = false;
+ }
+
+ public void onAnimationRepeat(Animation animation) {
+ }
+ }
+
+ /**
+ * Shows the applications grid when the layout animation is over.
+ */
+ private class ShowGrid implements Animation.AnimationListener {
+ public void onAnimationStart(Animation animation) {
+ }
+
+ public void onAnimationEnd(Animation animation) {
+ mBlockAnimation = false;
+ // ViewDebug.stopHierarchyTracing();
+ }
+
+ public void onAnimationRepeat(Animation animation) {
+ }
+ }
+
+ /**
+ * Starts the selected activity/application in the grid view.
+ */
+ private class ApplicationLauncher implements AdapterView.OnItemClickListener {
+ public void onItemClick(AdapterView parent, View v, int position, long id) {
+ ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
+ startActivity(app.intent);
+ }
+ }
+
+ /**
+ * When a drawable is attached to a View, the View gives the Drawable its dimensions
+ * by calling Drawable.setBounds(). In this application, the View that draws the
+ * wallpaper has the same size as the screen. However, the wallpaper might be larger
+ * that the screen which means it will be automatically stretched. Because stretching
+ * a bitmap while drawing it is very expensive, we use a ClippedDrawable instead.
+ * This drawable simply draws another wallpaper but makes sure it is not stretched
+ * by always giving it its intrinsic dimensions. If the wallpaper is larger than the
+ * screen, it will simply get clipped but it won't impact performance.
+ */
+ private class ClippedDrawable extends Drawable {
+ private final Drawable mWallpaper;
+
+ public ClippedDrawable(Drawable wallpaper) {
+ mWallpaper = wallpaper;
+ }
+
+ @Override
+ public void setBounds(int left, int top, int right, int bottom) {
+ super.setBounds(left, top, right, bottom);
+ // Ensure the wallpaper is as large as it really is, to avoid stretching it
+ // at drawing time
+ mWallpaper.setBounds(left, top, left + mWallpaper.getIntrinsicWidth(),
+ top + mWallpaper.getIntrinsicHeight());
+ }
+
+ public void draw(Canvas canvas) {
+ mWallpaper.draw(canvas);
+ }
+
+ public void setAlpha(int alpha) {
+ mWallpaper.setAlpha(alpha);
+ }
+
+ public void setColorFilter(ColorFilter cf) {
+ mWallpaper.setColorFilter(cf);
+ }
+
+ public int getOpacity() {
+ return mWallpaper.getOpacity();
+ }
+ }
+}
diff --git a/samples/Home/src/com/example/android/home/Wallpaper.java b/samples/Home/src/com/example/android/home/Wallpaper.java
new file mode 100644
index 000000000..3401c49c0
--- /dev/null
+++ b/samples/Home/src/com/example/android/home/Wallpaper.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2006 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.home;
+
+import android.app.Activity;
+import android.content.Context;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.Gallery;
+import android.widget.ImageView;
+import android.widget.Gallery.LayoutParams;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Wallpaper picker for the Home application. User can choose from
+ * a gallery of stock photos.
+ */
+public class Wallpaper extends Activity implements
+ AdapterView.OnItemSelectedListener, AdapterView.OnItemClickListener {
+
+ private static final String LOG_TAG = "Home";
+
+ private static final Integer[] THUMB_IDS = {
+ R.drawable.bg_android_icon,
+ R.drawable.bg_sunrise_icon,
+ R.drawable.bg_sunset_icon,
+ };
+
+ private static final Integer[] IMAGE_IDS = {
+ R.drawable.bg_android,
+ R.drawable.bg_sunrise,
+ R.drawable.bg_sunset,
+ };
+
+ private Gallery mGallery;
+ private boolean mIsWallpaperSet;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+
+ setContentView(R.layout.wallpaper);
+
+ mGallery = (Gallery) findViewById(R.id.gallery);
+ mGallery.setAdapter(new ImageAdapter(this));
+ mGallery.setOnItemSelectedListener(this);
+ mGallery.setOnItemClickListener(this);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mIsWallpaperSet = false;
+ }
+
+ public void onItemSelected(AdapterView parent, View v, int position, long id) {
+ getWindow().setBackgroundDrawableResource(IMAGE_IDS[position]);
+ }
+
+ public void onItemClick(AdapterView parent, View v, int position, long id) {
+ selectWallpaper(position);
+ }
+
+ /*
+ * When using touch if you tap an image it triggers both the onItemClick and
+ * the onTouchEvent causing the wallpaper to be set twice. Synchronize this
+ * method and ensure we only set the wallpaper once.
+ */
+ private synchronized void selectWallpaper(int position) {
+ if (mIsWallpaperSet) {
+ return;
+ }
+ mIsWallpaperSet = true;
+ try {
+ InputStream stream = getResources().openRawResource(IMAGE_IDS[position]);
+ setWallpaper(stream);
+ setResult(RESULT_OK);
+ finish();
+ } catch (IOException e) {
+ Log.e(LOG_TAG, "Failed to set wallpaper " + e);
+ }
+ }
+
+ public void onNothingSelected(AdapterView parent) {
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ selectWallpaper(mGallery.getSelectedItemPosition());
+ return true;
+ }
+
+ public class ImageAdapter extends BaseAdapter {
+
+ private Context mContext;
+
+ public ImageAdapter(Context c) {
+ mContext = c;
+ }
+
+ public int getCount() {
+ return THUMB_IDS.length;
+ }
+
+ public Object getItem(int position) {
+ return position;
+ }
+
+ public long getItemId(int position) {
+ return position;
+ }
+
+ public View getView(final int position, View convertView, ViewGroup parent) {
+ ImageView i = new ImageView(mContext);
+
+ i.setImageResource(THUMB_IDS[position]);
+ i.setAdjustViewBounds(true);
+ i.setLayoutParams(new Gallery.LayoutParams(
+ LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+ i.setBackgroundResource(android.R.drawable.picture_frame);
+ return i;
+ }
+
+ }
+
+}
+
+