merge from open-source master
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..a9fa30a
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+#LOCAL_MODULE_TAGS := user
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := Launcher2
+
+LOCAL_OVERRIDES_PACKAGES := Launcher
+
+include $(BUILD_PACKAGE)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
new file mode 100644
index 0000000..af66610
--- /dev/null
+++ b/AndroidManifest.xml
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 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.
+*/
+-->
+<manifest
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.launcher2"
+ >
+
+ <permission
+ android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
+ android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
+ android:protectionLevel="normal"
+ android:label="@string/permlab_install_shortcut"
+ android:description="@string/permdesc_install_shortcut" />
+ <permission
+ android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"
+ android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
+ android:protectionLevel="normal"
+ android:label="@string/permlab_uninstall_shortcut"
+ android:description="@string/permdesc_uninstall_shortcut"/>
+ <permission
+ android:name="com.android.launcher.permission.READ_SETTINGS"
+ android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
+ android:protectionLevel="normal"
+ android:label="@string/permlab_read_settings"
+ android:description="@string/permdesc_read_settings"/>
+ <permission
+ android:name="com.android.launcher.permission.WRITE_SETTINGS"
+ android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
+ android:protectionLevel="normal"
+ android:label="@string/permlab_write_settings"
+ android:description="@string/permdesc_write_settings"/>
+
+ <uses-permission android:name="android.permission.CALL_PHONE" />
+ <uses-permission android:name="android.permission.EXPAND_STATUS_BAR" />
+ <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.SET_WALLPAPER_HINTS" />
+ <uses-permission android:name="android.permission.VIBRATE" />
+ <uses-permission android:name="android.permission.WRITE_SETTINGS" />
+ <uses-permission android:name="android.permission.BIND_APPWIDGET" />
+ <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
+ <uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS" />
+
+ <application
+ android:name="LauncherApplication"
+ android:label="@string/application_name"
+ android:icon="@drawable/ic_launcher_home">
+
+ <activity
+ android:name="Launcher"
+ android:launchMode="singleTask"
+ android:clearTaskOnLaunch="true"
+ android:stateNotNeeded="true"
+ android:theme="@style/Theme"
+ android:screenOrientation="nosensor"
+ android:windowSoftInputMode="stateUnspecified|adjustPan">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.HOME" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.MONKEY"/>
+ </intent-filter>
+ </activity>
+
+ <activity
+ android:name="WallpaperChooser"
+ android:label="@string/pick_wallpaper"
+ android:icon="@drawable/ic_launcher_wallpaper"
+ android:screenOrientation="nosensor"
+ android:finishOnCloseSystemDialogs="true">
+ <intent-filter>
+ <action android:name="android.intent.action.SET_WALLPAPER" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ </activity>
+
+ <!-- Enable system-default search mode for any activity in Home -->
+ <meta-data
+ android:name="android.app.default_searchable"
+ android:value="*" />
+
+ <!-- Intent received used to install shortcuts from other applications -->
+ <receiver
+ android:name=".InstallShortcutReceiver"
+ android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
+ <intent-filter>
+ <action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
+ </intent-filter>
+ </receiver>
+
+ <!-- Intent received used to uninstall shortcuts from other applications -->
+ <receiver
+ android:name=".UninstallShortcutReceiver"
+ android:permission="com.android.launcher.permission.UNINSTALL_SHORTCUT">
+ <intent-filter>
+ <action android:name="com.android.launcher.action.UNINSTALL_SHORTCUT" />
+ </intent-filter>
+ </receiver>
+
+ <!-- The settings provider contains Home's data, like the workspace favorites -->
+ <provider
+ android:name="LauncherProvider"
+ android:authorities="com.android.launcher2.settings"
+ android:writePermission="com.android.launcher.permission.WRITE_SETTINGS"
+ android:readPermission="com.android.launcher.permission.READ_SETTINGS" />
+
+ </application>
+</manifest>
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/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/res/anim/fade_in_fast.xml b/res/anim/fade_in_fast.xml
new file mode 100644
index 0000000..5faef96
--- /dev/null
+++ b/res/anim/fade_in_fast.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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="@android:integer/config_shortAnimTime" />
diff --git a/res/anim/fade_out_fast.xml b/res/anim/fade_out_fast.xml
new file mode 100644
index 0000000..310e007
--- /dev/null
+++ b/res/anim/fade_out_fast.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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="@android:integer/config_shortAnimTime" />
diff --git a/res/color/bright_text_dark_focused.xml b/res/color/bright_text_dark_focused.xml
new file mode 100644
index 0000000..4beb72c
--- /dev/null
+++ b/res/color/bright_text_dark_focused.xml
@@ -0,0 +1,24 @@
+<?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_window_focused="true" android:state_focused="true" android:color="#000" />
+ <item android:state_window_focused="false" android:state_focused="true" android:color="#FFF" />
+ <item android:state_window_focused="false" android:color="#FFF" />
+ <item android:state_selected="true" android:color="#000" />
+ <item android:state_pressed="true" android:color="#000" />
+ <item android:color="#FFF" />
+</selector>
diff --git a/res/drawable-hdpi/all_apps_button_focused.png b/res/drawable-hdpi/all_apps_button_focused.png
new file mode 100644
index 0000000..94f7b08
--- /dev/null
+++ b/res/drawable-hdpi/all_apps_button_focused.png
Binary files differ
diff --git a/res/drawable-hdpi/all_apps_button_normal.png b/res/drawable-hdpi/all_apps_button_normal.png
new file mode 100644
index 0000000..188d528
--- /dev/null
+++ b/res/drawable-hdpi/all_apps_button_normal.png
Binary files differ
diff --git a/res/drawable-hdpi/all_apps_button_pressed.png b/res/drawable-hdpi/all_apps_button_pressed.png
new file mode 100644
index 0000000..600dea9
--- /dev/null
+++ b/res/drawable-hdpi/all_apps_button_pressed.png
Binary files differ
diff --git a/res/drawable-hdpi/bg_appwidget_error.9.png b/res/drawable-hdpi/bg_appwidget_error.9.png
new file mode 100644
index 0000000..59d9822
--- /dev/null
+++ b/res/drawable-hdpi/bg_appwidget_error.9.png
Binary files differ
diff --git a/res/drawable-hdpi/box_launcher_bottom.9.png b/res/drawable-hdpi/box_launcher_bottom.9.png
new file mode 100644
index 0000000..f08c7a2
--- /dev/null
+++ b/res/drawable-hdpi/box_launcher_bottom.9.png
Binary files differ
diff --git a/res/drawable-hdpi/box_launcher_top_normal.9.png b/res/drawable-hdpi/box_launcher_top_normal.9.png
new file mode 100644
index 0000000..98997ad
--- /dev/null
+++ b/res/drawable-hdpi/box_launcher_top_normal.9.png
Binary files differ
diff --git a/res/drawable-hdpi/box_launcher_top_pressed.9.png b/res/drawable-hdpi/box_launcher_top_pressed.9.png
new file mode 100644
index 0000000..f52fd48
--- /dev/null
+++ b/res/drawable-hdpi/box_launcher_top_pressed.9.png
Binary files differ
diff --git a/res/drawable-hdpi/box_launcher_top_selected.9.png b/res/drawable-hdpi/box_launcher_top_selected.9.png
new file mode 100644
index 0000000..8cacf0e
--- /dev/null
+++ b/res/drawable-hdpi/box_launcher_top_selected.9.png
Binary files differ
diff --git a/res/drawable-hdpi/focused_application_background.9.png b/res/drawable-hdpi/focused_application_background.9.png
new file mode 100644
index 0000000..7bf37ef
--- /dev/null
+++ b/res/drawable-hdpi/focused_application_background.9.png
Binary files differ
diff --git a/res/drawable-hdpi/home_button_focused.png b/res/drawable-hdpi/home_button_focused.png
new file mode 100644
index 0000000..08b1fcb
--- /dev/null
+++ b/res/drawable-hdpi/home_button_focused.png
Binary files differ
diff --git a/res/drawable-hdpi/home_button_normal.png b/res/drawable-hdpi/home_button_normal.png
new file mode 100644
index 0000000..4afcce8
--- /dev/null
+++ b/res/drawable-hdpi/home_button_normal.png
Binary files differ
diff --git a/res/drawable-hdpi/home_button_pressed.png b/res/drawable-hdpi/home_button_pressed.png
new file mode 100644
index 0000000..aa91732
--- /dev/null
+++ b/res/drawable-hdpi/home_button_pressed.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_1_focus.png b/res/drawable-hdpi/ic_home_arrows_1_focus.png
new file mode 100644
index 0000000..fd95862
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_1_focus.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_1_focus_right.png b/res/drawable-hdpi/ic_home_arrows_1_focus_right.png
new file mode 100644
index 0000000..2a7059f
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_1_focus_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_1_normal.png b/res/drawable-hdpi/ic_home_arrows_1_normal.png
new file mode 100644
index 0000000..c72a4bf
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_1_normal.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_1_normal_right.png b/res/drawable-hdpi/ic_home_arrows_1_normal_right.png
new file mode 100644
index 0000000..90819e6
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_1_normal_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_1_press.png b/res/drawable-hdpi/ic_home_arrows_1_press.png
new file mode 100644
index 0000000..70011d7
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_1_press.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_1_press_right.png b/res/drawable-hdpi/ic_home_arrows_1_press_right.png
new file mode 100644
index 0000000..45ea6f8
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_1_press_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_2_focus.png b/res/drawable-hdpi/ic_home_arrows_2_focus.png
new file mode 100644
index 0000000..1f1164a
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_2_focus.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_2_focus_right.png b/res/drawable-hdpi/ic_home_arrows_2_focus_right.png
new file mode 100644
index 0000000..330ee39
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_2_focus_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_2_normal.png b/res/drawable-hdpi/ic_home_arrows_2_normal.png
new file mode 100644
index 0000000..dc01737
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_2_normal.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_2_normal_right.png b/res/drawable-hdpi/ic_home_arrows_2_normal_right.png
new file mode 100644
index 0000000..dc843c6
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_2_normal_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_2_press.png b/res/drawable-hdpi/ic_home_arrows_2_press.png
new file mode 100644
index 0000000..294b331
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_2_press.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_2_press_right.png b/res/drawable-hdpi/ic_home_arrows_2_press_right.png
new file mode 100644
index 0000000..4fc9d0f
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_2_press_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_3_focus.png b/res/drawable-hdpi/ic_home_arrows_3_focus.png
new file mode 100644
index 0000000..7ada5ca
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_3_focus.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_3_focus_right.png b/res/drawable-hdpi/ic_home_arrows_3_focus_right.png
new file mode 100644
index 0000000..98d76ef
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_3_focus_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_3_normal.png b/res/drawable-hdpi/ic_home_arrows_3_normal.png
new file mode 100644
index 0000000..1ee2372
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_3_normal.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_3_normal_right.png b/res/drawable-hdpi/ic_home_arrows_3_normal_right.png
new file mode 100644
index 0000000..90a93fa
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_3_normal_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_3_press.png b/res/drawable-hdpi/ic_home_arrows_3_press.png
new file mode 100644
index 0000000..7c98a29
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_3_press.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_3_press_right.png b/res/drawable-hdpi/ic_home_arrows_3_press_right.png
new file mode 100644
index 0000000..5cfd28c
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_3_press_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_4_focus.png b/res/drawable-hdpi/ic_home_arrows_4_focus.png
new file mode 100644
index 0000000..84f3a7b
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_4_focus.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_4_focus_right.png b/res/drawable-hdpi/ic_home_arrows_4_focus_right.png
new file mode 100644
index 0000000..813f863
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_4_focus_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_4_normal.png b/res/drawable-hdpi/ic_home_arrows_4_normal.png
new file mode 100644
index 0000000..477f725
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_4_normal.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_4_normal_right.png b/res/drawable-hdpi/ic_home_arrows_4_normal_right.png
new file mode 100644
index 0000000..f8a8612
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_4_normal_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_4_press.png b/res/drawable-hdpi/ic_home_arrows_4_press.png
new file mode 100644
index 0000000..7b8f207
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_4_press.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_home_arrows_4_press_right.png b/res/drawable-hdpi/ic_home_arrows_4_press_right.png
new file mode 100644
index 0000000..4d9c2ca
--- /dev/null
+++ b/res/drawable-hdpi/ic_home_arrows_4_press_right.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_launcher_application.png b/res/drawable-hdpi/ic_launcher_application.png
new file mode 100644
index 0000000..8074c4c
--- /dev/null
+++ b/res/drawable-hdpi/ic_launcher_application.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_launcher_appwidget.png b/res/drawable-hdpi/ic_launcher_appwidget.png
new file mode 100644
index 0000000..3dc8b20
--- /dev/null
+++ b/res/drawable-hdpi/ic_launcher_appwidget.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_launcher_folder.png b/res/drawable-hdpi/ic_launcher_folder.png
new file mode 100644
index 0000000..dd71327
--- /dev/null
+++ b/res/drawable-hdpi/ic_launcher_folder.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_launcher_folder_open.png b/res/drawable-hdpi/ic_launcher_folder_open.png
new file mode 100644
index 0000000..5b3fcec
--- /dev/null
+++ b/res/drawable-hdpi/ic_launcher_folder_open.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_launcher_home.png b/res/drawable-hdpi/ic_launcher_home.png
new file mode 100644
index 0000000..74f6bd7
--- /dev/null
+++ b/res/drawable-hdpi/ic_launcher_home.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_launcher_shortcut.png b/res/drawable-hdpi/ic_launcher_shortcut.png
new file mode 100644
index 0000000..93ab2df
--- /dev/null
+++ b/res/drawable-hdpi/ic_launcher_shortcut.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_launcher_wallpaper.png b/res/drawable-hdpi/ic_launcher_wallpaper.png
new file mode 100644
index 0000000..dcd8709
--- /dev/null
+++ b/res/drawable-hdpi/ic_launcher_wallpaper.png
Binary files differ
diff --git a/res/drawable-hdpi/ic_search_widget.png b/res/drawable-hdpi/ic_search_widget.png
new file mode 100644
index 0000000..06b9b25
--- /dev/null
+++ b/res/drawable-hdpi/ic_search_widget.png
Binary files differ
diff --git a/res/drawable-hdpi/pattern_carbon_fiber_dark.png b/res/drawable-hdpi/pattern_carbon_fiber_dark.png
new file mode 100644
index 0000000..427936f
--- /dev/null
+++ b/res/drawable-hdpi/pattern_carbon_fiber_dark.png
Binary files differ
diff --git a/res/drawable-hdpi/placeholder_google.png b/res/drawable-hdpi/placeholder_google.png
new file mode 100644
index 0000000..923c8b8
--- /dev/null
+++ b/res/drawable-hdpi/placeholder_google.png
Binary files differ
diff --git a/res/drawable-hdpi/preview_bg.9.png b/res/drawable-hdpi/preview_bg.9.png
new file mode 100644
index 0000000..5647144
--- /dev/null
+++ b/res/drawable-hdpi/preview_bg.9.png
Binary files differ
diff --git a/res/drawable-hdpi/preview_bg_focus.9.png b/res/drawable-hdpi/preview_bg_focus.9.png
new file mode 100644
index 0000000..31200fd
--- /dev/null
+++ b/res/drawable-hdpi/preview_bg_focus.9.png
Binary files differ
diff --git a/res/drawable-hdpi/preview_bg_press.9.png b/res/drawable-hdpi/preview_bg_press.9.png
new file mode 100644
index 0000000..9cb1266
--- /dev/null
+++ b/res/drawable-hdpi/preview_bg_press.9.png
Binary files differ
diff --git a/res/drawable-hdpi/search_button_bg.9.png b/res/drawable-hdpi/search_button_bg.9.png
new file mode 100644
index 0000000..9fba3d1
--- /dev/null
+++ b/res/drawable-hdpi/search_button_bg.9.png
Binary files differ
diff --git a/res/drawable-hdpi/search_button_voice.png b/res/drawable-hdpi/search_button_voice.png
new file mode 100644
index 0000000..a60f7d9
--- /dev/null
+++ b/res/drawable-hdpi/search_button_voice.png
Binary files differ
diff --git a/res/drawable-hdpi/search_floater.9.png b/res/drawable-hdpi/search_floater.9.png
new file mode 100644
index 0000000..02441d0
--- /dev/null
+++ b/res/drawable-hdpi/search_floater.9.png
Binary files differ
diff --git a/res/drawable-hdpi/textfield_searchwidget_default.9.png b/res/drawable-hdpi/textfield_searchwidget_default.9.png
new file mode 100644
index 0000000..2fe637d
--- /dev/null
+++ b/res/drawable-hdpi/textfield_searchwidget_default.9.png
Binary files differ
diff --git a/res/drawable-hdpi/textfield_searchwidget_pressed.9.png b/res/drawable-hdpi/textfield_searchwidget_pressed.9.png
new file mode 100644
index 0000000..58af9ba
--- /dev/null
+++ b/res/drawable-hdpi/textfield_searchwidget_pressed.9.png
Binary files differ
diff --git a/res/drawable-hdpi/textfield_searchwidget_selected.9.png b/res/drawable-hdpi/textfield_searchwidget_selected.9.png
new file mode 100644
index 0000000..8a84fdc
--- /dev/null
+++ b/res/drawable-hdpi/textfield_searchwidget_selected.9.png
Binary files differ
diff --git a/res/drawable-hdpi/trashcan.png b/res/drawable-hdpi/trashcan.png
new file mode 100644
index 0000000..d356f45
--- /dev/null
+++ b/res/drawable-hdpi/trashcan.png
Binary files differ
diff --git a/res/drawable-hdpi/trashcan_hover.png b/res/drawable-hdpi/trashcan_hover.png
new file mode 100644
index 0000000..7dda19e
--- /dev/null
+++ b/res/drawable-hdpi/trashcan_hover.png
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_bluedotgrid.jpg b/res/drawable-hdpi/wallpaper_bluedotgrid.jpg
new file mode 100644
index 0000000..468edfe
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_bluedotgrid.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_bluedotgrid_small.jpg b/res/drawable-hdpi/wallpaper_bluedotgrid_small.jpg
new file mode 100644
index 0000000..1ff9568
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_bluedotgrid_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_brown.jpg b/res/drawable-hdpi/wallpaper_brown.jpg
new file mode 100644
index 0000000..9b7ef20
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_brown.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_brown_small.jpg b/res/drawable-hdpi/wallpaper_brown_small.jpg
new file mode 100644
index 0000000..e5b417e
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_brown_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_canyon.jpg b/res/drawable-hdpi/wallpaper_canyon.jpg
new file mode 100644
index 0000000..1b129fd
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_canyon.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_canyon_small.jpg b/res/drawable-hdpi/wallpaper_canyon_small.jpg
new file mode 100644
index 0000000..fd4d72f
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_canyon_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_cloud.jpg b/res/drawable-hdpi/wallpaper_cloud.jpg
new file mode 100644
index 0000000..f3b5545
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_cloud.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_cloud_small.jpg b/res/drawable-hdpi/wallpaper_cloud_small.jpg
new file mode 100644
index 0000000..0e4c14c
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_cloud_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_desert.jpg b/res/drawable-hdpi/wallpaper_desert.jpg
new file mode 100644
index 0000000..47daa79
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_desert.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_desert_small.jpg b/res/drawable-hdpi/wallpaper_desert_small.jpg
new file mode 100644
index 0000000..9252d36
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_desert_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_despair.jpg b/res/drawable-hdpi/wallpaper_despair.jpg
new file mode 100644
index 0000000..57e8235
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_despair.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_despair_small.jpg b/res/drawable-hdpi/wallpaper_despair_small.jpg
new file mode 100644
index 0000000..fc8e3c6
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_despair_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_electric.jpg b/res/drawable-hdpi/wallpaper_electric.jpg
new file mode 100644
index 0000000..f7800af
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_electric.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_electric_small.jpg b/res/drawable-hdpi/wallpaper_electric_small.jpg
new file mode 100644
index 0000000..66dd573
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_electric_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_field.jpg b/res/drawable-hdpi/wallpaper_field.jpg
new file mode 100644
index 0000000..5bab9b5
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_field.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_field_small.jpg b/res/drawable-hdpi/wallpaper_field_small.jpg
new file mode 100644
index 0000000..20d9a48
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_field_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_galaxy.jpg b/res/drawable-hdpi/wallpaper_galaxy.jpg
new file mode 100644
index 0000000..de0f3ff
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_galaxy.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_galaxy_small.jpg b/res/drawable-hdpi/wallpaper_galaxy_small.jpg
new file mode 100644
index 0000000..69d48a2
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_galaxy_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_goldengate.jpg b/res/drawable-hdpi/wallpaper_goldengate.jpg
new file mode 100644
index 0000000..2271091
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_goldengate.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_goldengate_small.jpg b/res/drawable-hdpi/wallpaper_goldengate_small.jpg
new file mode 100644
index 0000000..e9aca1e
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_goldengate_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_grass.jpg b/res/drawable-hdpi/wallpaper_grass.jpg
new file mode 100644
index 0000000..e9dc541
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_grass.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_grass_night.jpg b/res/drawable-hdpi/wallpaper_grass_night.jpg
new file mode 100644
index 0000000..b9c74c9
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_grass_night.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_grass_night_small.jpg b/res/drawable-hdpi/wallpaper_grass_night_small.jpg
new file mode 100644
index 0000000..353eb18
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_grass_night_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_grass_small.jpg b/res/drawable-hdpi/wallpaper_grass_small.jpg
new file mode 100644
index 0000000..dc45738
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_grass_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_gray.jpg b/res/drawable-hdpi/wallpaper_gray.jpg
new file mode 100644
index 0000000..913f053
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_gray.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_gray_small.jpg b/res/drawable-hdpi/wallpaper_gray_small.jpg
new file mode 100644
index 0000000..d083a74
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_gray_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_greengray.jpg b/res/drawable-hdpi/wallpaper_greengray.jpg
new file mode 100644
index 0000000..1f3c86c
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_greengray.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_greengray_small.jpg b/res/drawable-hdpi/wallpaper_greengray_small.jpg
new file mode 100644
index 0000000..ebf7066
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_greengray_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_hazybluedots.jpg b/res/drawable-hdpi/wallpaper_hazybluedots.jpg
new file mode 100644
index 0000000..fe6aeb4
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_hazybluedots.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_hazybluedots_small.jpg b/res/drawable-hdpi/wallpaper_hazybluedots_small.jpg
new file mode 100644
index 0000000..c645dea
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_hazybluedots_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_lightgrad.jpg b/res/drawable-hdpi/wallpaper_lightgrad.jpg
new file mode 100644
index 0000000..35a45fa
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_lightgrad.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_lightgrad_small.jpg b/res/drawable-hdpi/wallpaper_lightgrad_small.jpg
new file mode 100644
index 0000000..f909da7
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_lightgrad_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_monumentvalley.jpg b/res/drawable-hdpi/wallpaper_monumentvalley.jpg
new file mode 100644
index 0000000..1bb5f2c
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_monumentvalley.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_monumentvalley_small.jpg b/res/drawable-hdpi/wallpaper_monumentvalley_small.jpg
new file mode 100644
index 0000000..9ea3309
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_monumentvalley_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_nexuspattern.jpg b/res/drawable-hdpi/wallpaper_nexuspattern.jpg
new file mode 100644
index 0000000..212a7b1
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_nexuspattern.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_nexuspattern_small.jpg b/res/drawable-hdpi/wallpaper_nexuspattern_small.jpg
new file mode 100644
index 0000000..8e474a5
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_nexuspattern_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_nexusrain.jpg b/res/drawable-hdpi/wallpaper_nexusrain.jpg
new file mode 100644
index 0000000..46c2971
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_nexusrain.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_nexusrain_small.jpg b/res/drawable-hdpi/wallpaper_nexusrain_small.jpg
new file mode 100644
index 0000000..a239339
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_nexusrain_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_nexuswallpaper1.png b/res/drawable-hdpi/wallpaper_nexuswallpaper1.png
new file mode 100644
index 0000000..2856da0
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_nexuswallpaper1.png
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_nexuswallpaper1_small.jpg b/res/drawable-hdpi/wallpaper_nexuswallpaper1_small.jpg
new file mode 100644
index 0000000..70882bb
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_nexuswallpaper1_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_pcut.jpg b/res/drawable-hdpi/wallpaper_pcut.jpg
new file mode 100644
index 0000000..bb9914d
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_pcut.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_pcut_small.jpg b/res/drawable-hdpi/wallpaper_pcut_small.jpg
new file mode 100644
index 0000000..bd19775
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_pcut_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_ropelights.jpg b/res/drawable-hdpi/wallpaper_ropelights.jpg
new file mode 100644
index 0000000..ca7862f
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_ropelights.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_ropelights_small.jpg b/res/drawable-hdpi/wallpaper_ropelights_small.jpg
new file mode 100644
index 0000000..ac6fb29
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_ropelights_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_tree.jpg b/res/drawable-hdpi/wallpaper_tree.jpg
new file mode 100644
index 0000000..f998bea
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_tree.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_tree_small.jpg b/res/drawable-hdpi/wallpaper_tree_small.jpg
new file mode 100644
index 0000000..425305a
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_tree_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_x67.jpg b/res/drawable-hdpi/wallpaper_x67.jpg
new file mode 100644
index 0000000..400aa27
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_x67.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_x67_small.jpg b/res/drawable-hdpi/wallpaper_x67_small.jpg
new file mode 100644
index 0000000..10e0faa
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_x67_small.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_zanzibar.jpg b/res/drawable-hdpi/wallpaper_zanzibar.jpg
new file mode 100644
index 0000000..9218895
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_zanzibar.jpg
Binary files differ
diff --git a/res/drawable-hdpi/wallpaper_zanzibar_small.jpg b/res/drawable-hdpi/wallpaper_zanzibar_small.jpg
new file mode 100644
index 0000000..affdc8c
--- /dev/null
+++ b/res/drawable-hdpi/wallpaper_zanzibar_small.jpg
Binary files differ
diff --git a/res/drawable/all_apps_button.xml b/res/drawable/all_apps_button.xml
new file mode 100644
index 0000000..9f6b8ac
--- /dev/null
+++ b/res/drawable/all_apps_button.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_pressed="true" android:drawable="@drawable/all_apps_button_pressed" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/all_apps_button_focused" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/all_apps_button_normal" />
+ <item android:drawable="@drawable/all_apps_button_normal" />
+</selector>
+
diff --git a/res/drawable/box_launcher_top.xml b/res/drawable/box_launcher_top.xml
new file mode 100644
index 0000000..20c07c4
--- /dev/null
+++ b/res/drawable/box_launcher_top.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_pressed="true" android:drawable="@drawable/box_launcher_top_pressed" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/box_launcher_top_selected" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/box_launcher_top_normal" />
+ <item android:drawable="@drawable/box_launcher_top_normal" />
+</selector>
+
diff --git a/res/drawable/delete_zone_selector.xml b/res/drawable/delete_zone_selector.xml
new file mode 100644
index 0000000..0c54b1d7
--- /dev/null
+++ b/res/drawable/delete_zone_selector.xml
@@ -0,0 +1,24 @@
+<?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.
+*/
+-->
+
+<transition xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@drawable/trashcan" />
+ <item android:drawable="@drawable/trashcan_hover" />
+</transition>
diff --git a/res/drawable/grid_selector.xml b/res/drawable/grid_selector.xml
new file mode 100644
index 0000000..009cfe1
--- /dev/null
+++ b/res/drawable/grid_selector.xml
@@ -0,0 +1,26 @@
+<?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" />
+ <item android:state_focused="false" android:drawable="@drawable/focused_application_background" />
+ <item android:state_window_focused="true" android:drawable="@drawable/focused_application_background" />
+ <item android:state_window_focused="false" android:drawable="@android:color/transparent" />
+</selector>
diff --git a/res/drawable/home_arrows_left.xml b/res/drawable/home_arrows_left.xml
new file mode 100644
index 0000000..82df258
--- /dev/null
+++ b/res/drawable/home_arrows_left.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<level-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:maxLevel="0" android:drawable="@android:color/transparent" />
+ <item android:maxLevel="1" android:drawable="@drawable/home_arrows_left_1" />
+ <item android:maxLevel="2" android:drawable="@drawable/home_arrows_left_2" />
+ <item android:maxLevel="3" android:drawable="@drawable/home_arrows_left_3" />
+ <item android:maxLevel="4" android:drawable="@drawable/home_arrows_left_4" />
+</level-list>
diff --git a/res/drawable/home_arrows_left_1.xml b/res/drawable/home_arrows_left_1.xml
new file mode 100644
index 0000000..f61f39e
--- /dev/null
+++ b/res/drawable/home_arrows_left_1.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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/ic_home_arrows_1_press" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/ic_home_arrows_1_focus" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/ic_home_arrows_1_normal" />
+ <item android:drawable="@drawable/ic_home_arrows_1_normal" />
+</selector>
diff --git a/res/drawable/home_arrows_left_2.xml b/res/drawable/home_arrows_left_2.xml
new file mode 100644
index 0000000..888a258
--- /dev/null
+++ b/res/drawable/home_arrows_left_2.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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/ic_home_arrows_2_press" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/ic_home_arrows_2_focus" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/ic_home_arrows_2_normal" />
+ <item android:drawable="@drawable/ic_home_arrows_2_normal" />
+</selector>
diff --git a/res/drawable/home_arrows_left_3.xml b/res/drawable/home_arrows_left_3.xml
new file mode 100644
index 0000000..4dbdf15
--- /dev/null
+++ b/res/drawable/home_arrows_left_3.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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/ic_home_arrows_3_press" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/ic_home_arrows_3_focus" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/ic_home_arrows_3_normal" />
+ <item android:drawable="@drawable/ic_home_arrows_3_normal" />
+</selector>
diff --git a/res/drawable/home_arrows_left_4.xml b/res/drawable/home_arrows_left_4.xml
new file mode 100644
index 0000000..31b381d
--- /dev/null
+++ b/res/drawable/home_arrows_left_4.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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/ic_home_arrows_4_press" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/ic_home_arrows_4_focus" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/ic_home_arrows_4_normal" />
+ <item android:drawable="@drawable/ic_home_arrows_4_normal" />
+</selector>
diff --git a/res/drawable/home_arrows_right.xml b/res/drawable/home_arrows_right.xml
new file mode 100644
index 0000000..8ab0dec
--- /dev/null
+++ b/res/drawable/home_arrows_right.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<level-list xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:maxLevel="0" android:drawable="@drawable/home_arrows_right_4" />
+ <item android:maxLevel="1" android:drawable="@drawable/home_arrows_right_3" />
+ <item android:maxLevel="2" android:drawable="@drawable/home_arrows_right_2" />
+ <item android:maxLevel="3" android:drawable="@drawable/home_arrows_right_1" />
+ <item android:maxLevel="4" android:drawable="@android:color/transparent" />
+</level-list>
diff --git a/res/drawable/home_arrows_right_1.xml b/res/drawable/home_arrows_right_1.xml
new file mode 100644
index 0000000..f49b760
--- /dev/null
+++ b/res/drawable/home_arrows_right_1.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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/ic_home_arrows_1_press_right" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/ic_home_arrows_1_focus_right" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/ic_home_arrows_1_normal_right" />
+ <item android:drawable="@drawable/ic_home_arrows_1_normal_right" />
+</selector>
diff --git a/res/drawable/home_arrows_right_2.xml b/res/drawable/home_arrows_right_2.xml
new file mode 100644
index 0000000..17318a3
--- /dev/null
+++ b/res/drawable/home_arrows_right_2.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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/ic_home_arrows_2_press_right" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/ic_home_arrows_2_focus_right" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/ic_home_arrows_2_normal_right" />
+ <item android:drawable="@drawable/ic_home_arrows_2_normal_right" />
+</selector>
diff --git a/res/drawable/home_arrows_right_3.xml b/res/drawable/home_arrows_right_3.xml
new file mode 100644
index 0000000..375f8e3
--- /dev/null
+++ b/res/drawable/home_arrows_right_3.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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/ic_home_arrows_3_press_right" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/ic_home_arrows_3_focus_right" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/ic_home_arrows_3_normal_right" />
+ <item android:drawable="@drawable/ic_home_arrows_3_normal_right" />
+</selector>
diff --git a/res/drawable/home_arrows_right_4.xml b/res/drawable/home_arrows_right_4.xml
new file mode 100644
index 0000000..06627c6
--- /dev/null
+++ b/res/drawable/home_arrows_right_4.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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/ic_home_arrows_4_press_right" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/ic_home_arrows_4_focus_right" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/ic_home_arrows_4_normal_right" />
+ <item android:drawable="@drawable/ic_home_arrows_4_normal_right" />
+</selector>
diff --git a/res/drawable/pressed_application_background.9.png b/res/drawable/pressed_application_background.9.png
new file mode 100644
index 0000000..b09f595
--- /dev/null
+++ b/res/drawable/pressed_application_background.9.png
Binary files differ
diff --git a/res/drawable/preview_background.xml b/res/drawable/preview_background.xml
new file mode 100644
index 0000000..0054aa0
--- /dev/null
+++ b/res/drawable/preview_background.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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/preview_bg_press" />
+ <item android:state_focused="true" android:state_window_focused="true" android:drawable="@drawable/preview_bg_focus" />
+ <item android:state_focused="true" android:state_window_focused="false" android:drawable="@drawable/preview_bg" />
+ <item android:drawable="@drawable/preview_bg" />
+</selector>
diff --git a/res/drawable/shortcut_selector.xml b/res/drawable/shortcut_selector.xml
new file mode 100644
index 0000000..884bccf
--- /dev/null
+++ b/res/drawable/shortcut_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" />
+ <item android:state_window_focused="true" android:state_focused="true" android:drawable="@drawable/focused_application_background" />
+ <item android:state_window_focused="false" android:state_focused="true" android:drawable="@android:color/transparent" />
+</selector>
diff --git a/res/drawable/textfield_searchwidget.xml b/res/drawable/textfield_searchwidget.xml
new file mode 100644
index 0000000..80f3dca
--- /dev/null
+++ b/res/drawable/textfield_searchwidget.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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_window_focused="false" android:state_enabled="true"
+ android:drawable="@drawable/textfield_searchwidget_default" />
+
+ <item android:state_pressed="true"
+ android:drawable="@drawable/textfield_searchwidget_pressed" />
+
+ <item android:state_enabled="true" android:state_focused="true"
+ android:drawable="@drawable/textfield_searchwidget_selected" />
+
+ <item android:state_enabled="true"
+ android:drawable="@drawable/textfield_searchwidget_default" />
+
+</selector>
diff --git a/res/layout-land/application.xml b/res/layout-land/application.xml
new file mode 100644
index 0000000..6de5658
--- /dev/null
+++ b/res/layout-land/application.xml
@@ -0,0 +1,18 @@
+<?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.
+-->
+
+<com.android.launcher2.BubbleTextView xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/WorkspaceIcon.Landscape" />
diff --git a/res/layout-land/application_boxed.xml b/res/layout-land/application_boxed.xml
new file mode 100644
index 0000000..7656b58
--- /dev/null
+++ b/res/layout-land/application_boxed.xml
@@ -0,0 +1,33 @@
+<?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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/name"
+ android:layout_width="fill_parent"
+ android:layout_height="88dip"
+
+ android:paddingLeft="2dip"
+ android:paddingRight="2dip"
+ android:paddingTop="5dip"
+ android:paddingBottom="2dip"
+ android:drawablePadding="0dip"
+
+ android:textSize="13dip"
+ android:maxLines="2"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal"
+ android:textColor="@color/bright_text_dark_focused"
+ android:gravity="top|center_horizontal" />
diff --git a/res/layout-land/folder_icon.xml b/res/layout-land/folder_icon.xml
new file mode 100644
index 0000000..c76a756
--- /dev/null
+++ b/res/layout-land/folder_icon.xml
@@ -0,0 +1,18 @@
+<?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.
+-->
+
+<com.android.launcher2.FolderIcon xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/WorkspaceIcon.Landscape" />
diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml
new file mode 100644
index 0000000..d2009b8
--- /dev/null
+++ b/res/layout-land/launcher.xml
@@ -0,0 +1,107 @@
+<?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.
+-->
+
+<com.android.launcher2.DragLayer
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher2"
+
+ android:id="@+id/drag_layer"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <com.android.launcher2.AllAppsView
+ android:id="@+id/all_apps_view"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+
+ android:scrollbarStyle="outsideInset"
+ android:drawSelectorOnTop="false"
+ android:listSelector="@drawable/grid_selector"
+
+ android:verticalSpacing="10dip"
+ android:numColumns="4" />
+
+ <!-- The workspace contains 3 screens of cells -->
+ <com.android.launcher2.Workspace
+ android:id="@+id/workspace"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:scrollbars="horizontal"
+ android:fadeScrollbars="true"
+ launcher:defaultScreen="2">
+
+ <include android:id="@+id/cell1" layout="@layout/workspace_screen" />
+ <include android:id="@+id/cell2" layout="@layout/workspace_screen" />
+ <include android:id="@+id/cell3" layout="@layout/workspace_screen" />
+ <include android:id="@+id/cell4" layout="@layout/workspace_screen" />
+ <include android:id="@+id/cell5" layout="@layout/workspace_screen" />
+
+ </com.android.launcher2.Workspace>
+
+ <ImageView
+ android:id="@+id/previous_screen"
+ android:layout_width="93dip"
+ android:layout_height="@dimen/button_bar_height"
+ android:layout_gravity="bottom|left"
+ android:layout_marginLeft="6dip"
+
+ android:src="@drawable/home_arrows_left"
+
+ android:onClick="previousScreen"
+
+ android:focusable="true"
+ android:clickable="true" />
+
+ <ImageView
+ android:id="@+id/next_screen"
+ android:layout_width="93dip"
+ android:layout_height="@dimen/button_bar_height"
+ android:layout_gravity="bottom|right"
+ android:layout_marginRight="6dip"
+
+ android:src="@drawable/home_arrows_right"
+
+ android:onClick="nextScreen"
+
+ android:focusable="true"
+ android:clickable="true" />
+
+ <com.android.launcher2.HandleView
+ android:id="@+id/all_apps_button"
+ android:layout_width="@dimen/button_bar_height"
+ android:layout_height="fill_parent"
+ android:layout_gravity="right|center_vertical"
+
+ android:focusable="true"
+ android:clickable="true"
+
+ android:scaleType="center"
+ android:src="@drawable/all_apps_button"
+ launcher:direction="vertical"
+ />
+
+ <com.android.launcher2.DeleteZone
+ android:id="@+id/delete_zone"
+ android:layout_width="49dip"
+ android:layout_height="fill_parent"
+
+ android:scaleType="center"
+ android:src="@drawable/delete_zone_selector"
+ android:visibility="invisible"
+ launcher:direction="vertical"
+ />
+
+</com.android.launcher2.DragLayer>
diff --git a/res/layout-land/live_folder_grid.xml b/res/layout-land/live_folder_grid.xml
new file mode 100644
index 0000000..572c295
--- /dev/null
+++ b/res/layout-land/live_folder_grid.xml
@@ -0,0 +1,50 @@
+<?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.
+ */
+-->
+
+<com.android.launcher2.LiveFolder xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical">
+
+ <Button
+ android:id="@+id/folder_close"
+ android:background="@drawable/box_launcher_top"
+ android:gravity="left|center_vertical"
+ android:textSize="14sp"
+ android:textColor="#404040"
+ android:textStyle="bold"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <GridView
+ android:id="@+id/folder_content"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+
+ android:cacheColorHint="#ff333333"
+ android:background="@drawable/box_launcher_bottom"
+
+ android:scrollbarAlwaysDrawVerticalTrack="true"
+ android:scrollbarStyle="insideInset"
+ android:drawSelectorOnTop="false"
+ android:listSelector="@drawable/grid_selector"
+
+ android:verticalSpacing="10dip"
+ android:numColumns="5" />
+
+</com.android.launcher2.LiveFolder>
diff --git a/res/layout-land/live_folder_icon.xml b/res/layout-land/live_folder_icon.xml
new file mode 100644
index 0000000..64c2d44
--- /dev/null
+++ b/res/layout-land/live_folder_icon.xml
@@ -0,0 +1,21 @@
+<?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.
+ */
+-->
+
+<com.android.launcher2.LiveFolderIcon xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/WorkspaceIcon.Landscape" />
diff --git a/res/layout-land/user_folder.xml b/res/layout-land/user_folder.xml
new file mode 100644
index 0000000..645c02f
--- /dev/null
+++ b/res/layout-land/user_folder.xml
@@ -0,0 +1,47 @@
+<?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.
+-->
+
+<com.android.launcher2.UserFolder xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical">
+
+ <Button
+ android:id="@+id/folder_close"
+ android:background="@drawable/box_launcher_top"
+ android:gravity="left|center_vertical"
+ android:textSize="14sp"
+ android:textColor="#404040"
+ android:textStyle="bold"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <GridView
+ android:id="@id/folder_content"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+
+ android:cacheColorHint="#ff333333"
+ android:background="@drawable/box_launcher_bottom"
+
+ android:scrollbarAlwaysDrawVerticalTrack="true"
+ android:scrollbarStyle="insideInset"
+ android:drawSelectorOnTop="false"
+ android:listSelector="@drawable/grid_selector"
+
+ android:verticalSpacing="10dip"
+ android:numColumns="5" />
+
+</com.android.launcher2.UserFolder>
diff --git a/res/layout-land/workspace_screen.xml b/res/layout-land/workspace_screen.xml
new file mode 100644
index 0000000..531bac2
--- /dev/null
+++ b/res/layout-land/workspace_screen.xml
@@ -0,0 +1,31 @@
+<?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.
+-->
+
+<com.android.launcher2.CellLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher2"
+
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+
+ launcher:cellWidth="@dimen/workspace_cell_width"
+ launcher:cellHeight="@dimen/workspace_cell_height"
+ launcher:longAxisStartPadding="0dip"
+ launcher:longAxisEndPadding="55dip"
+ launcher:shortAxisStartPadding="0dip"
+ launcher:shortAxisEndPadding="0dip"
+ launcher:shortAxisCells="4"
+ launcher:longAxisCells="4" />
diff --git a/res/layout-port/application.xml b/res/layout-port/application.xml
new file mode 100644
index 0000000..f904a66
--- /dev/null
+++ b/res/layout-port/application.xml
@@ -0,0 +1,18 @@
+<?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.
+-->
+
+<com.android.launcher2.BubbleTextView xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/WorkspaceIcon.Portrait" />
diff --git a/res/layout-port/application_boxed.xml b/res/layout-port/application_boxed.xml
new file mode 100644
index 0000000..a6991d5
--- /dev/null
+++ b/res/layout-port/application_boxed.xml
@@ -0,0 +1,33 @@
+<?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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/name"
+ android:layout_width="fill_parent"
+ android:layout_height="88dip"
+
+ android:paddingLeft="2dip"
+ android:paddingRight="2dip"
+ android:paddingTop="5dip"
+ android:paddingBottom="2dip"
+ android:drawablePadding="0dip"
+
+ android:textSize="13dip"
+ android:maxLines="2"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal"
+ android:textColor="@color/bright_text_dark_focused"
+ android:gravity="top|center_horizontal" />
diff --git a/res/layout-port/folder_icon.xml b/res/layout-port/folder_icon.xml
new file mode 100644
index 0000000..49049cf
--- /dev/null
+++ b/res/layout-port/folder_icon.xml
@@ -0,0 +1,18 @@
+<?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.
+-->
+
+<com.android.launcher2.FolderIcon xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/WorkspaceIcon.Portrait" />
diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml
new file mode 100644
index 0000000..001f3e3
--- /dev/null
+++ b/res/layout-port/launcher.xml
@@ -0,0 +1,107 @@
+<?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.
+-->
+
+<com.android.launcher2.DragLayer
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher2"
+
+ android:id="@+id/drag_layer"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <com.android.launcher2.AllAppsView
+ android:id="@+id/all_apps_view"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+
+ android:scrollbarStyle="outsideInset"
+ android:drawSelectorOnTop="false"
+ android:listSelector="@drawable/grid_selector"
+
+ android:verticalSpacing="10dip"
+ android:numColumns="4"
+ />
+
+ <!-- The workspace contains 3 screens of cells -->
+ <com.android.launcher2.Workspace
+ android:id="@+id/workspace"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ launcher:defaultScreen="2">
+
+ <include android:id="@+id/cell1" layout="@layout/workspace_screen" />
+ <include android:id="@+id/cell2" layout="@layout/workspace_screen" />
+ <include android:id="@+id/cell3" layout="@layout/workspace_screen" />
+ <include android:id="@+id/cell4" layout="@layout/workspace_screen" />
+ <include android:id="@+id/cell5" layout="@layout/workspace_screen" />
+
+ </com.android.launcher2.Workspace>
+
+ <ImageView
+ android:id="@+id/previous_screen"
+ android:layout_width="93dip"
+ android:layout_height="@dimen/button_bar_height"
+ android:layout_gravity="bottom|left"
+ android:layout_marginLeft="6dip"
+
+ android:src="@drawable/home_arrows_left"
+
+ android:onClick="previousScreen"
+
+ android:focusable="true"
+ android:clickable="true" />
+
+ <ImageView
+ android:id="@+id/next_screen"
+ android:layout_width="93dip"
+ android:layout_height="@dimen/button_bar_height"
+ android:layout_gravity="bottom|right"
+ android:layout_marginRight="6dip"
+
+ android:src="@drawable/home_arrows_right"
+
+ android:onClick="nextScreen"
+
+ android:focusable="true"
+ android:clickable="true" />
+
+ <com.android.launcher2.HandleView
+ android:id="@+id/all_apps_button"
+ android:layout_width="wrap_content"
+ android:layout_height="@dimen/button_bar_height"
+ android:layout_gravity="bottom|center_horizontal"
+
+ android:focusable="true"
+ android:clickable="true"
+
+ android:scaleType="center"
+ android:src="@drawable/all_apps_button"
+ launcher:direction="horizontal"
+ />
+
+ <com.android.launcher2.DeleteZone
+ android:id="@+id/delete_zone"
+ android:layout_width="wrap_content"
+ android:layout_height="@dimen/button_bar_height"
+ android:layout_gravity="bottom|center_horizontal"
+
+ android:scaleType="center"
+ android:src="@drawable/delete_zone_selector"
+ android:visibility="invisible"
+ launcher:direction="horizontal"
+ />
+
+</com.android.launcher2.DragLayer>
diff --git a/res/layout-port/live_folder_grid.xml b/res/layout-port/live_folder_grid.xml
new file mode 100644
index 0000000..51e5e47
--- /dev/null
+++ b/res/layout-port/live_folder_grid.xml
@@ -0,0 +1,50 @@
+<?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.
+ */
+-->
+
+<com.android.launcher2.LiveFolder xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical">
+
+ <Button
+ android:id="@+id/folder_close"
+ android:background="@drawable/box_launcher_top"
+ android:gravity="left|center_vertical"
+ android:textSize="14sp"
+ android:textColor="#404040"
+ android:textStyle="bold"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <GridView
+ android:id="@id/folder_content"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+
+ android:cacheColorHint="#ff333333"
+ android:background="@drawable/box_launcher_bottom"
+
+ android:scrollbarAlwaysDrawVerticalTrack="true"
+ android:scrollbarStyle="insideInset"
+ android:drawSelectorOnTop="false"
+ android:listSelector="@drawable/grid_selector"
+
+ android:verticalSpacing="10dip"
+ android:numColumns="4" />
+
+</com.android.launcher2.LiveFolder>
diff --git a/res/layout-port/live_folder_icon.xml b/res/layout-port/live_folder_icon.xml
new file mode 100644
index 0000000..e3cd49e
--- /dev/null
+++ b/res/layout-port/live_folder_icon.xml
@@ -0,0 +1,21 @@
+<?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.
+ */
+-->
+
+<com.android.launcher2.LiveFolderIcon xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/WorkspaceIcon.Portrait" />
diff --git a/res/layout-port/user_folder.xml b/res/layout-port/user_folder.xml
new file mode 100644
index 0000000..6a189dc
--- /dev/null
+++ b/res/layout-port/user_folder.xml
@@ -0,0 +1,47 @@
+<?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.
+-->
+
+<com.android.launcher2.UserFolder xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical">
+
+ <Button
+ android:id="@+id/folder_close"
+ android:background="@drawable/box_launcher_top"
+ android:gravity="left|center_vertical"
+ android:textSize="14sp"
+ android:textColor="#404040"
+ android:textStyle="bold"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <GridView
+ android:id="@id/folder_content"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+
+ android:cacheColorHint="#ff333333"
+ android:background="@drawable/box_launcher_bottom"
+
+ android:scrollbarAlwaysDrawVerticalTrack="true"
+ android:scrollbarStyle="insideInset"
+ android:drawSelectorOnTop="false"
+ android:listSelector="@drawable/grid_selector"
+
+ android:verticalSpacing="10dip"
+ android:numColumns="4" />
+
+</com.android.launcher2.UserFolder>
diff --git a/res/layout-port/workspace_screen.xml b/res/layout-port/workspace_screen.xml
new file mode 100644
index 0000000..531bac2
--- /dev/null
+++ b/res/layout-port/workspace_screen.xml
@@ -0,0 +1,31 @@
+<?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.
+-->
+
+<com.android.launcher2.CellLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher2"
+
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+
+ launcher:cellWidth="@dimen/workspace_cell_width"
+ launcher:cellHeight="@dimen/workspace_cell_height"
+ launcher:longAxisStartPadding="0dip"
+ launcher:longAxisEndPadding="55dip"
+ launcher:shortAxisStartPadding="0dip"
+ launcher:shortAxisEndPadding="0dip"
+ launcher:shortAxisCells="4"
+ launcher:longAxisCells="4" />
diff --git a/res/layout/add_list_item.xml b/res/layout/add_list_item.xml
new file mode 100644
index 0000000..f276511
--- /dev/null
+++ b/res/layout/add_list_item.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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="fill_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:textAppearance="?android:attr/textAppearanceLargeInverse"
+ android:gravity="center_vertical"
+ android:drawablePadding="14dip"
+ android:paddingLeft="15dip"
+ android:paddingRight="15dip" />
diff --git a/res/layout/application_list.xml b/res/layout/application_list.xml
new file mode 100644
index 0000000..29f7400
--- /dev/null
+++ b/res/layout/application_list.xml
@@ -0,0 +1,69 @@
+<?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.
+ */
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="?android:attr/listPreferredItemHeight"
+
+ android:paddingLeft="10dip"
+
+ android:orientation="horizontal">
+
+ <ImageView android:id="@+id/icon"
+ android:layout_width="@android:dimen/app_icon_size"
+ android:layout_height="@android:dimen/app_icon_size"
+ android:layout_gravity="center_vertical"
+ android:scaleType="fitCenter" />
+
+ <LinearLayout
+ android:layout_width="0dip"
+ android:layout_weight="1.0"
+ android:layout_height="fill_parent"
+
+ android:paddingLeft="8dip"
+ android:paddingRight="8dip"
+
+ android:orientation="vertical"
+ android:gravity="center_vertical">
+
+ <TextView android:id="@+id/name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+
+ android:singleLine="true"
+ android:ellipsize="end"
+
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <TextView android:id="@+id/description"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+
+ android:layout_below="@id/name"
+ android:layout_alignLeft="@id/name"
+
+ android:singleLine="true"
+ android:ellipsize="end"
+
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="?android:attr/textColorSecondary" />
+
+ </LinearLayout>
+
+</LinearLayout>
diff --git a/res/layout/appwidget_error.xml b/res/layout/appwidget_error.xml
new file mode 100644
index 0000000..03d4ae4
--- /dev/null
+++ b/res/layout/appwidget_error.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="10dip"
+ android:paddingBottom="10dip"
+ android:paddingLeft="20dip"
+ android:paddingRight="20dip"
+ android:gravity="center"
+ android:background="@drawable/bg_appwidget_error"
+ android:textAppearance="?android:attr/textAppearanceMediumInverse"
+ android:textColor="@color/appwidget_error_color"
+ android:text="@string/gadget_error_text"
+ />
diff --git a/res/layout/list_category.xml b/res/layout/list_category.xml
new file mode 100644
index 0000000..1e8d04c
--- /dev/null
+++ b/res/layout/list_category.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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"
+ style="?android:attr/listSeparatorTextViewStyle" />
diff --git a/res/layout/list_checkbox_2lines.xml b/res/layout/list_checkbox_2lines.xml
new file mode 100644
index 0000000..ed80c5f
--- /dev/null
+++ b/res/layout/list_checkbox_2lines.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:gravity="center_vertical"
+ android:paddingRight="?android:attr/scrollbarSize">
+
+ <RelativeLayout
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginLeft="15dip"
+ android:layout_marginRight="6dip"
+ android:layout_marginTop="6dip"
+ android:layout_marginBottom="6dip"
+ android:layout_weight="1">
+
+ <TextView android:id="@+id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:ellipsize="marquee"
+ android:fadingEdge="horizontal" />
+
+ <TextView android:id="@+id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@id/title"
+ android:layout_alignLeft="@id/title"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:maxLines="2" />
+
+ </RelativeLayout>
+
+ <CheckBox
+ android:id="@+id/checkbox"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginRight="4dip"
+ android:layout_gravity="center_vertical"
+ android:focusable="false"
+ android:clickable="false" />
+
+</LinearLayout>
diff --git a/res/layout/live_folder_list.xml b/res/layout/live_folder_list.xml
new file mode 100644
index 0000000..cf3d2f1
--- /dev/null
+++ b/res/layout/live_folder_list.xml
@@ -0,0 +1,42 @@
+<?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.
+ */
+-->
+
+<com.android.launcher2.LiveFolder xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical">
+
+ <Button
+ android:id="@+id/folder_close"
+ android:background="@drawable/box_launcher_top"
+ android:gravity="left|center_vertical"
+ android:textSize="14sp"
+ android:textColor="#404040"
+ android:textStyle="bold"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <ListView
+ android:id="@id/folder_content"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1"
+
+ android:cacheColorHint="#ff333333"
+ android:background="@drawable/box_launcher_bottom" />
+
+</com.android.launcher2.LiveFolder>
diff --git a/res/layout/pick_item.xml b/res/layout/pick_item.xml
new file mode 100644
index 0000000..f276511
--- /dev/null
+++ b/res/layout/pick_item.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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="fill_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="?android:attr/listPreferredItemHeight"
+ android:textAppearance="?android:attr/textAppearanceLargeInverse"
+ android:gravity="center_vertical"
+ android:drawablePadding="14dip"
+ android:paddingLeft="15dip"
+ android:paddingRight="15dip" />
diff --git a/res/layout/rename_folder.xml b/res/layout/rename_folder.xml
new file mode 100644
index 0000000..cbb42b4
--- /dev/null
+++ b/res/layout/rename_folder.xml
@@ -0,0 +1,42 @@
+<?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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:padding="20dip"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/label"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:text="@string/rename_folder_label"
+ android:gravity="left"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <EditText
+ android:id="@+id/folder_name"
+ android:layout_height="wrap_content"
+ android:layout_width="fill_parent"
+ android:scrollHorizontally="true"
+ android:autoText="false"
+ android:capitalize="none"
+ android:gravity="fill_horizontal"
+ android:maxLength="30"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+</LinearLayout>
diff --git a/res/layout/wallpaper_chooser.xml b/res/layout/wallpaper_chooser.xml
new file mode 100644
index 0000000..7267246
--- /dev/null
+++ b/res/layout/wallpaper_chooser.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 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.
+*/
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent">
+
+ <ImageView android:id="@+id/wallpaper"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
+ android:layout_weight="1.0"
+ android:scaleType="fitCenter" />
+
+ <Gallery android:id="@+id/gallery"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <Button android:id="@+id/set"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/wallpaper_instructions"
+ android:layout_gravity="center_horizontal" />
+
+</LinearLayout>
+
diff --git a/res/layout/wallpaper_item.xml b/res/layout/wallpaper_item.xml
new file mode 100644
index 0000000..6727483
--- /dev/null
+++ b/res/layout/wallpaper_item.xml
@@ -0,0 +1,22 @@
+<?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.
+-->
+
+<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:background="?android:attr/galleryItemBackground"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:scaleType="fitXY"
+ android:focusable="true" />
diff --git a/res/layout/widget_search.xml b/res/layout/widget_search.xml
new file mode 100644
index 0000000..a346723
--- /dev/null
+++ b/res/layout/widget_search.xml
@@ -0,0 +1,61 @@
+<?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.
+-->
+
+<com.android.launcher2.Search
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher2"
+ android:id="@+id/widget_search"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical"
+ android:gravity="center">
+
+ <LinearLayout
+ android:id="@+id/search_plate"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:paddingLeft="14dip"
+ android:paddingRight="14dip"
+ android:paddingTop="13dip"
+ android:paddingBottom="12dip"
+ android:background="@drawable/search_floater" >
+
+ <TextView
+ android:id="@+id/search_src_text"
+ android:layout_width="0dip"
+ android:layout_height="42dip"
+ android:layout_weight="1.0"
+ android:editable="false"
+ android:focusable="true"
+ android:inputType="none"
+ android:background="@drawable/textfield_searchwidget"
+ android:textAppearance="?android:attr/textAppearanceMediumInverse"
+ android:textColor="@android:color/primary_text_light"
+ />
+
+ <ImageButton
+ android:id="@+id/search_voice_btn"
+ android:layout_width="wrap_content"
+ android:layout_height="42dip"
+ android:layout_marginLeft="4dip"
+ android:background="@*android:drawable/btn_search_dialog_voice"
+ android:src="@*android:drawable/ic_btn_speak_now"
+ />
+
+ </LinearLayout>
+
+</com.android.launcher2.Search>
diff --git a/res/raw/rollo.c b/res/raw/rollo.c
new file mode 100644
index 0000000..6a41727
--- /dev/null
+++ b/res/raw/rollo.c
@@ -0,0 +1,432 @@
+#pragma version(1)
+#pragma stateVertex(PV)
+#pragma stateFragment(PFTexLinear)
+#pragma stateStore(PSIcons)
+
+#define PI 3.14159f
+
+
+// Attraction to center values from page edge to page center.
+float g_AttractionTable[9];
+float g_FrictionTable[9];
+float g_PhysicsTableSize;
+
+float g_PosPage;
+float g_PosVelocity;
+float g_LastPositionX;
+int g_LastTouchDown;
+float g_DT;
+int g_LastTime;
+int g_PageCount;
+float g_Zoom;
+
+// Drawing constants, should be parameters ======
+#define VIEW_ANGLE 1.28700222f
+
+float g_OldPosPage;
+float g_OldPosVelocity;
+float g_OldZoom;
+
+int g_DrawLastFrame;
+int lastFrame(int draw) {
+ // We draw one extra frame to work around the last frame post bug.
+ // We also need to track if we drew the last frame to deal with large DT
+ // in the physics.
+ int ret = g_DrawLastFrame | draw;
+ g_DrawLastFrame = draw;
+ return ret; // should return draw instead.
+}
+
+void updateReadback() {
+ if ((g_OldPosPage != g_PosPage) ||
+ (g_OldPosVelocity != g_PosVelocity) ||
+ (g_OldZoom != g_Zoom)) {
+
+ g_OldPosPage = g_PosPage;
+ g_OldPosVelocity = g_PosVelocity;
+ g_OldZoom = g_Zoom;
+
+ int i[3];
+ i[0] = g_PosPage * (1 << 16);
+ i[1] = g_PosVelocity * (1 << 16);
+ i[2] = g_OldZoom * (1 << 16);
+ sendToClient(&i[0], 1, 12, 1);
+ }
+}
+
+void init() {
+ g_AttractionTable[0] = 6.5f;
+ g_AttractionTable[1] = 6.5f;
+ g_AttractionTable[2] = 7.0f;
+ g_AttractionTable[3] = 6.0f;
+ g_AttractionTable[4] = -6.0f;
+ g_AttractionTable[5] = -7.0f;
+ g_AttractionTable[6] = -6.5f;
+ g_AttractionTable[7] = -6.5f;
+ g_AttractionTable[8] = -6.5f; // dup 7 to avoid a clamp later
+ g_FrictionTable[0] = 3.5f;
+ g_FrictionTable[1] = 3.6f;
+ g_FrictionTable[2] = 4.0f;
+ g_FrictionTable[3] = 5.0f;
+ g_FrictionTable[4] = 5.0f;
+ g_FrictionTable[5] = 4.0f;
+ g_FrictionTable[6] = 3.6f;
+ g_FrictionTable[7] = 3.5f;
+ g_FrictionTable[8] = 3.5f; // dup 7 to avoid a clamp later
+ g_PhysicsTableSize = 7;
+
+ g_PosVelocity = 0;
+ g_PosPage = 0;
+ g_LastTouchDown = 0;
+ g_LastPositionX = 0;
+ g_Zoom = 0;
+}
+
+void resetHWWar() {
+}
+
+void move() {
+ if (g_LastTouchDown) {
+ float dx = -(state->newPositionX - g_LastPositionX);
+ g_PosVelocity = 0;
+ g_PosPage += dx;
+
+ float pmin = -0.25f;
+ float pmax = (g_PageCount - 1) + 0.25f;
+ g_PosPage = clampf(g_PosPage, pmin, pmax);
+ }
+ g_LastTouchDown = state->newTouchDown;
+ g_LastPositionX = state->newPositionX;
+ //debugF("Move P", g_PosPage);
+}
+
+void fling() {
+ g_LastTouchDown = 0;
+ g_PosVelocity = -state->flingVelocityX;
+ float av = fabsf(g_PosVelocity);
+ float minVel = 3.5f;
+
+ minVel *= 1.f - (fabsf(fracf(g_PosPage + 0.5f) - 0.5f) * 0.45f);
+
+ if (av < minVel && av > 0.2f) {
+ if (g_PosVelocity > 0) {
+ g_PosVelocity = minVel;
+ } else {
+ g_PosVelocity = -minVel;
+ }
+ }
+
+ if (g_PosPage <= 0) {
+ g_PosVelocity = maxf(0, g_PosVelocity);
+ }
+ if (g_PosPage > (g_PageCount - 1)) {
+ g_PosVelocity = minf(0, g_PosVelocity);
+ }
+ //debugF("fling v", g_PosVelocity);
+}
+
+void touchUp() {
+ g_LastTouchDown = 0;
+}
+
+int
+count_pages(int iconCount)
+{
+ int iconsPerPage = COLUMNS_PER_PAGE * ROWS_PER_PAGE;
+ int pages = iconCount / iconsPerPage;
+ if (pages*iconsPerPage != iconCount) {
+ pages++;
+ }
+ return pages;
+}
+
+float
+modf(float x, float y)
+{
+ return x-(y*floorf(x/y));
+}
+
+void updatePos() {
+ if (g_LastTouchDown) {
+ return;
+ }
+
+ float tablePosNorm = fracf(g_PosPage + 0.5f);
+ float tablePosF = tablePosNorm * g_PhysicsTableSize;
+ int tablePosI = tablePosF;
+ float tablePosFrac = tablePosF - tablePosI;
+ float accel = lerpf(g_AttractionTable[tablePosI],
+ g_AttractionTable[tablePosI + 1],
+ tablePosFrac) * g_DT;
+ float friction = lerpf(g_FrictionTable[tablePosI],
+ g_FrictionTable[tablePosI + 1],
+ tablePosFrac) * g_DT;
+ //debugF(" accel", accel);
+ //debugF(" friction", friction);
+
+ // If our velocity is low OR acceleration is opposing it, apply it.
+ if (fabsf(g_PosVelocity) < 1.0f || (g_PosVelocity * accel) < 0) {
+ g_PosVelocity += accel;
+ }
+
+ if ((friction > fabsf(g_PosVelocity)) && (friction > fabsf(accel))) {
+ // Special get back to center and overcome friction physics.
+ float t = tablePosNorm - 0.5f;
+ if (fabsf(t) < (friction * g_DT)) {
+ // really close, just snap
+ g_PosPage = roundf(g_PosPage);
+ g_PosVelocity = 0;
+ } else {
+ if (t > 0) {
+ g_PosVelocity = -friction;
+ } else {
+ g_PosVelocity = friction;
+ }
+ }
+ } else {
+ // Normal physics
+ if (g_PosVelocity > 0) {
+ g_PosVelocity -= friction;
+ g_PosVelocity = maxf(g_PosVelocity, 0);
+ } else {
+ g_PosVelocity += friction;
+ g_PosVelocity = minf(g_PosVelocity, 0);
+ }
+ }
+ g_PosPage += g_PosVelocity * g_DT;
+
+ // Check for out of boundry conditions.
+ if (g_PosPage < 0 && g_PosVelocity < 0) {
+ float damp = 1.0 + (g_PosPage * 4);
+ damp = clampf(damp, 0.f, 0.9f);
+ g_PosVelocity *= damp;
+ }
+ if (g_PosPage > (g_PageCount-1) && g_PosVelocity > 0) {
+ float damp = 1.0 - ((g_PosPage - g_PageCount + 1) * 4);
+ damp = clampf(damp, 0.f, 0.9f);
+ g_PosVelocity *= damp;
+ }
+}
+
+float
+far_size(float sizeAt0)
+{
+ return sizeAt0 * (RADIUS+2) / 2; // -2 is the camera z=(z-camZ)/z
+}
+
+void
+draw_page(int icon, int lastIcon, float centerAngle, float scale)
+{
+ int row;
+ int col;
+
+ //debugF("center angle", centerAngle);
+
+ float iconTextureWidth = ICON_WIDTH_PX / (float)ICON_TEXTURE_WIDTH_PX;
+ float iconTextureHeight = ICON_HEIGHT_PX / (float)ICON_TEXTURE_HEIGHT_PX;
+
+ float iconWidthAngle = VIEW_ANGLE * ICON_WIDTH_PX / SCREEN_WIDTH_PX;
+ float columnGutterAngle = iconWidthAngle * 0.9f;
+
+ float farIconSize = FAR_ICON_SIZE;
+ float iconGutterHeight = farIconSize * 1.3f;
+
+ float farIconTextureSize = far_size(2 * ICON_TEXTURE_WIDTH_PX / (float)SCREEN_WIDTH_PX);
+
+ float normalizedLabelWidth = 2 * params->bubbleWidth / (float)SCREEN_WIDTH_PX;
+ float farLabelHeight = far_size(params->bubbleHeight * (normalizedLabelWidth / params->bubbleWidth));
+
+ for (row=0; row<ROWS_PER_PAGE && icon<=lastIcon; row++) {
+ float angle = centerAngle;
+ angle -= (columnGutterAngle + iconWidthAngle) * 1.5f;
+
+ float iconTop = (farIconSize + iconGutterHeight) * (1.85f + ICON_TOP_OFFSET)
+ - row * (farIconSize + iconGutterHeight);
+ float iconBottom = iconTop - farIconSize;
+
+ float labelY = iconBottom - farLabelHeight;
+ float iconTextureTop = iconTop + (0.5f * (farIconTextureSize - farIconSize));
+ float iconTextureBottom = iconTextureTop - farIconTextureSize;
+
+ for (col=0; col<COLUMNS_PER_PAGE && icon<=lastIcon; col++) {
+ // icon
+ float sine = sinf(angle);
+ float cosine = cosf(angle);
+
+ float centerX = sine * RADIUS;
+ float centerZ = cosine * RADIUS / scale;
+
+ if (scale > 1.f) {
+ centerX *= scale;
+ }
+
+ float iconLeftX = centerX - (/*cosine * */ farIconTextureSize * .5);
+ float iconRightX = centerX + (/*cosine * */ farIconTextureSize * .5);
+ float iconLeftZ = centerZ;// + (sine * farIconTextureSize * .5);
+ float iconRightZ = centerZ;// - (sine * farIconTextureSize * .5);
+
+ color(1.0f, 1.0f, 1.0f, 0.99f);
+ if (state->selectedIconIndex == icon) {
+ bindTexture(NAMED_PFTexLinear, 0, state->selectedIconTexture);
+ drawQuadTexCoords(
+ iconLeftX, iconTextureTop, iconLeftZ, 0.0f, 0.0f,
+ iconRightX, iconTextureTop, iconRightZ, 1.0f, 0.0f,
+ iconRightX, iconTextureBottom, iconRightZ, 1.0f, 1.0f,
+ iconLeftX, iconTextureBottom, iconLeftZ, 0.0f, 1.0f);
+ } else {
+ bindTexture(NAMED_PFTexLinear, 0, loadI32(ALLOC_ICON_IDS, icon));
+ drawQuadTexCoords(
+ iconLeftX, iconTextureTop, iconLeftZ, 0.0f, 0.0f,
+ iconRightX, iconTextureTop, iconRightZ, 1.0f, 0.0f,
+ iconRightX, iconTextureBottom, iconRightZ, 1.0f, 1.0f,
+ iconLeftX, iconTextureBottom, iconLeftZ, 0.0f, 1.0f);
+ }
+
+ // label
+ if (scale < 1.2f) {
+ float a = (1.2f - maxf(scale, 1.0f)) * 5;
+ color(1.0f, 1.0f, 1.0f, a);
+ bindTexture(NAMED_PFTexLinear, 0, loadI32(ALLOC_LABEL_IDS, icon));
+ drawSprite(centerX, labelY, centerZ,
+ params->bubbleBitmapWidth, params->bubbleBitmapHeight);
+ }
+
+ angle += columnGutterAngle + iconWidthAngle;
+ icon++;
+ }
+ }
+}
+
+void
+draw_home_button()
+{
+ color(1.0f, 1.0f, 1.0f, 1.0f);
+ bindTexture(NAMED_PFTexLinear, 0, state->homeButtonId);
+
+ float scale = 2.0f / SCREEN_WIDTH_PX;
+
+ float x = 0.0f;
+
+ float y = -(SCREEN_HEIGHT_PX / (float)SCREEN_WIDTH_PX);
+ y += g_Zoom * (scale * params->homeButtonTextureHeight / 2);
+
+ float z = 0.0f;
+ drawSprite(x, y, z, params->homeButtonTextureWidth, params->homeButtonTextureHeight);
+}
+
+int
+main(int launchID)
+{
+ // Compute dt in seconds.
+ int newTime = uptimeMillis();
+ g_DT = (newTime - g_LastTime) / 1000.f;
+ g_LastTime = newTime;
+
+ if (!g_DrawLastFrame) {
+ // If we stopped rendering we cannot use DT.
+ // assume 30fps in this case.
+ g_DT = 0.033f;
+ }
+ if (g_DT > 0.2f) {
+ // physics may break if DT is large.
+ g_DT = 0.2f;
+ }
+
+ //debugF("zoom", g_Zoom);
+ if (g_Zoom != state->zoomTarget) {
+ float dz = (state->zoomTarget - g_Zoom) * g_DT * 5;
+ if (dz && (fabsf(dz) < 0.03f)) {
+ if (dz > 0) {
+ dz = 0.03f;
+ } else {
+ dz = -0.03f;
+ }
+ }
+ if (fabsf(g_Zoom - state->zoomTarget) < fabsf(dz)) {
+ g_Zoom = state->zoomTarget;
+ } else {
+ g_Zoom += dz;
+ }
+ updateReadback();
+ }
+
+ // Set clear value to dim the background based on the zoom position.
+ if ((g_Zoom < 0.001f) && (state->zoomTarget < 0.001f)) {
+ pfClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ // When we're zoomed out and not tracking motion events, reset the pos to 0.
+ if (!g_LastTouchDown) {
+ g_PosPage = 0;
+ }
+ return lastFrame(0);
+ } else if (g_Zoom < 0.85f) {
+ pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
+ } else {
+ pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
+ }
+
+ // icons & labels
+ int iconCount = state->iconCount;
+ g_PageCount = count_pages(iconCount);
+
+ updatePos(0.1f);
+ updateReadback();
+
+ //debugF(" draw g_PosPage", g_PosPage);
+
+ // Draw the icons ========================================
+
+ // Bug makes 1.0f alpha fail.
+ color(1.0f, 1.0f, 1.0f, 0.99f);
+
+ if (iconCount <= 0) {
+ return lastFrame(0);
+ }
+ int lastIcon = iconCount-1;
+
+ int page = g_PosPage;
+ float currentPagePosition = g_PosPage - page;
+
+ int iconsPerPage = COLUMNS_PER_PAGE * ROWS_PER_PAGE;
+ int icon = clamp(iconsPerPage * page, 0, lastIcon);
+
+ float scale = (1 / g_Zoom);
+
+ float pageAngle = VIEW_ANGLE * 1.2f;
+ draw_page(icon, lastIcon, -pageAngle*currentPagePosition, scale);
+ draw_page(icon+iconsPerPage, lastIcon, (-pageAngle*currentPagePosition)+pageAngle, scale);
+
+ // Draw the border lines for debugging ========================================
+ /*
+ bindProgramVertex(NAMED_PVOrtho);
+ bindProgramFragment(NAMED_PFOrtho);
+ bindProgramFragmentStore(NAMED_PFSText);
+
+ color(1.0f, 1.0f, 0.0f, 0.99f);
+ int i;
+ for (i=0; i<ROWS_PER_PAGE+1; i++) {
+ int y = loadI32(ALLOC_Y_BORDERS, i);
+ drawRect(0, y, SCREEN_WIDTH_PX, y+1, 0.0f);
+ }
+ for (i=0; i<COLUMNS_PER_PAGE+1; i++) {
+ int x = loadI32(ALLOC_X_BORDERS, i);
+ drawRect(x, 0, x+1, SCREEN_HEIGHT_PX, 0.0f);
+ }
+ */
+
+ // Draw the home button ========================================
+ draw_home_button();
+
+ /*
+ bindTexture(NAMED_PFOrtho, 0, loadI32(ALLOC_PARAMS, PARAM_SCROLL_HANDLE_ID));
+ float handleLeft = 40 + (320 * (scrollXPx/(float)(maxScrollXPx)));
+ float handleTop = 680;
+ float handleWidth = loadI32(ALLOC_PARAMS, PARAM_SCROLL_HANDLE_TEX_WIDTH);
+ float handleHeight = loadI32(ALLOC_PARAMS, PARAM_SCROLL_HANDLE_TEX_HEIGHT);
+ drawRect(handleLeft, handleTop, handleLeft+handleWidth, handleTop+handleHeight, 0.0f);
+ */
+
+ // Bug workaround where the last frame is not always displayed
+ // So we keep rendering until the bug is fixed.
+ return lastFrame((g_PosVelocity != 0) || fracf(g_PosPage) || (g_Zoom != state->zoomTarget));
+}
+
diff --git a/res/raw/rollo2.c b/res/raw/rollo2.c
new file mode 100644
index 0000000..eb87063
--- /dev/null
+++ b/res/raw/rollo2.c
@@ -0,0 +1,404 @@
+#pragma version(1)
+#pragma stateVertex(PV)
+#pragma stateFragment(PFTexLinear)
+#pragma stateStore(PSIcons)
+
+#define PI 3.14159f
+
+
+// Attraction to center values from page edge to page center.
+float g_AttractionTable[9];
+float g_FrictionTable[9];
+float g_PhysicsTableSize;
+
+float g_PosPage;
+float g_PosVelocity;
+float g_LastPositionX;
+int g_LastTouchDown;
+float g_DT;
+int g_LastTime;
+int g_PageCount;
+float g_Zoom;
+float g_OldPosPage;
+float g_OldPosVelocity;
+float g_OldZoom;
+
+// Drawing constants, should be parameters ======
+#define VIEW_ANGLE 1.28700222f
+
+int g_DrawLastFrame;
+int lastFrame(int draw) {
+ // We draw one extra frame to work around the last frame post bug.
+ // We also need to track if we drew the last frame to deal with large DT
+ // in the physics.
+ int ret = g_DrawLastFrame | draw;
+ g_DrawLastFrame = draw;
+ return ret; // should return draw instead.
+}
+
+void updateReadback() {
+ if ((g_OldPosPage != g_PosPage) ||
+ (g_OldPosVelocity != g_PosVelocity) ||
+ (g_OldZoom != g_Zoom)) {
+
+ g_OldPosPage = g_PosPage;
+ g_OldPosVelocity = g_PosVelocity;
+ g_OldZoom = g_Zoom;
+
+ int i[3];
+ i[0] = g_PosPage * (1 << 16);
+ i[1] = g_PosVelocity * (1 << 16);
+ i[2] = g_OldZoom * (1 << 16);
+ sendToClient(&i[0], 1, 12, 1);
+ }
+}
+
+void init() {
+ g_AttractionTable[0] = 6.5f;
+ g_AttractionTable[1] = 6.5f;
+ g_AttractionTable[2] = 7.0f;
+ g_AttractionTable[3] = 6.0f;
+ g_AttractionTable[4] = -6.0f;
+ g_AttractionTable[5] = -7.0f;
+ g_AttractionTable[6] = -6.5f;
+ g_AttractionTable[7] = -6.5f;
+ g_AttractionTable[8] = -6.5f; // dup 7 to avoid a clamp later
+ g_FrictionTable[0] = 3.5f;
+ g_FrictionTable[1] = 3.6f;
+ g_FrictionTable[2] = 4.0f;
+ g_FrictionTable[3] = 5.0f;
+ g_FrictionTable[4] = 5.0f;
+ g_FrictionTable[5] = 4.0f;
+ g_FrictionTable[6] = 3.6f;
+ g_FrictionTable[7] = 3.5f;
+ g_FrictionTable[8] = 3.5f; // dup 7 to avoid a clamp later
+ g_PhysicsTableSize = 7;
+
+ g_PosVelocity = 0;
+ g_PosPage = 0;
+ g_LastTouchDown = 0;
+ g_LastPositionX = 0;
+ g_Zoom = 0;
+}
+
+void resetHWWar() {
+}
+
+void move() {
+ if (g_LastTouchDown) {
+ float dx = -(state->newPositionX - g_LastPositionX);
+ g_PosVelocity = 0;
+ g_PosPage += dx;
+
+ float pmin = -0.25f;
+ float pmax = (g_PageCount - 1) + 0.25f;
+ g_PosPage = clampf(g_PosPage, pmin, pmax);
+ }
+ g_LastTouchDown = state->newTouchDown;
+ g_LastPositionX = state->newPositionX;
+ //debugF("Move P", g_PosPage);
+}
+
+void fling() {
+ g_LastTouchDown = 0;
+ g_PosVelocity = -state->flingVelocityX;
+ float av = fabsf(g_PosVelocity);
+ float minVel = 3.5f;
+
+ minVel *= 1.f - (fabsf(fracf(g_PosPage + 0.5f) - 0.5f) * 0.45f);
+
+ if (av < minVel && av > 0.2f) {
+ if (g_PosVelocity > 0) {
+ g_PosVelocity = minVel;
+ } else {
+ g_PosVelocity = -minVel;
+ }
+ }
+
+ if (g_PosPage <= 0) {
+ g_PosVelocity = maxf(0, g_PosVelocity);
+ }
+ if (g_PosPage > (g_PageCount - 1)) {
+ g_PosVelocity = minf(0, g_PosVelocity);
+ }
+ //debugF("fling v", g_PosVelocity);
+}
+
+void touchUp() {
+ g_LastTouchDown = 0;
+}
+
+int
+count_pages(int iconCount)
+{
+ int iconsPerPage = COLUMNS_PER_PAGE * ROWS_PER_PAGE;
+ int pages = iconCount / iconsPerPage;
+ if (pages*iconsPerPage != iconCount) {
+ pages++;
+ }
+ return pages;
+}
+
+float
+modf(float x, float y)
+{
+ return x-(y*floorf(x/y));
+}
+
+void updatePos() {
+ if (g_LastTouchDown) {
+ return;
+ }
+
+ float tablePosNorm = fracf(g_PosPage + 0.5f);
+ float tablePosF = tablePosNorm * g_PhysicsTableSize;
+ int tablePosI = tablePosF;
+ float tablePosFrac = tablePosF - tablePosI;
+ float accel = lerpf(g_AttractionTable[tablePosI],
+ g_AttractionTable[tablePosI + 1],
+ tablePosFrac) * g_DT;
+ float friction = lerpf(g_FrictionTable[tablePosI],
+ g_FrictionTable[tablePosI + 1],
+ tablePosFrac) * g_DT;
+ //debugF(" accel", accel);
+ //debugF(" friction", friction);
+
+ // If our velocity is low OR acceleration is opposing it, apply it.
+ if (fabsf(g_PosVelocity) < 1.0f || (g_PosVelocity * accel) < 0) {
+ g_PosVelocity += accel;
+ }
+
+ if ((friction > fabsf(g_PosVelocity)) && (friction > fabsf(accel))) {
+ // Special get back to center and overcome friction physics.
+ float t = tablePosNorm - 0.5f;
+ if (fabsf(t) < (friction * g_DT)) {
+ // really close, just snap
+ g_PosPage = roundf(g_PosPage);
+ g_PosVelocity = 0;
+ } else {
+ if (t > 0) {
+ g_PosVelocity = -friction;
+ } else {
+ g_PosVelocity = friction;
+ }
+ }
+ } else {
+ // Normal physics
+ if (g_PosVelocity > 0) {
+ g_PosVelocity -= friction;
+ g_PosVelocity = maxf(g_PosVelocity, 0);
+ } else {
+ g_PosVelocity += friction;
+ g_PosVelocity = minf(g_PosVelocity, 0);
+ }
+ }
+ g_PosPage += g_PosVelocity * g_DT;
+
+ // Check for out of boundry conditions.
+ if (g_PosPage < 0 && g_PosVelocity < 0) {
+ float damp = 1.0 + (g_PosPage * 4);
+ damp = clampf(damp, 0.f, 0.9f);
+ g_PosVelocity *= damp;
+ }
+ if (g_PosPage > (g_PageCount-1) && g_PosVelocity > 0) {
+ float damp = 1.0 - ((g_PosPage - g_PageCount + 1) * 4);
+ damp = clampf(damp, 0.f, 0.9f);
+ g_PosVelocity *= damp;
+ }
+}
+
+int positionStrip(float row, float column)
+{
+ float mat1[16];
+
+ float y = 1.2f - row * 0.6f;
+
+ float scale = 256.f / getWidth();
+ float xscale = scale * 4.55 / 1.8f / 2;
+
+ matrixLoadTranslate(mat1, 0.f, y, 0.f);
+ matrixScale(mat1, 1.f, scale, 1.f);
+ vpLoadModelMatrix(mat1);
+
+ float soff = -21.8f - (column * 1.25f);
+ matrixLoadScale(mat1, xscale, 1.f, 1.f);
+ matrixTranslate(mat1, soff, 0, 0);
+ vpLoadTextureMatrix(mat1);
+
+ return - soff * 10.f;
+}
+
+void drawIcon(float row, float column, int iconNum)
+{
+ int offset = positionStrip(row, column);
+ bindTexture(NAMED_PFTexLinear, 0, loadI32(ALLOC_ICON_IDS, iconNum));
+
+ if (offset < 0) {
+ offset = 0;
+ }
+ if (offset >= (450 - 20)) {
+ offset = (449 - 20);
+ }
+ drawSimpleMeshRange(NAMED_SMMesh, offset * 6, 20 * 6);
+}
+
+void
+draw_home_button()
+{
+ color(1.0f, 1.0f, 1.0f, 1.0f);
+ bindTexture(NAMED_PFTexLinear, 0, state->homeButtonId);
+
+ float scale = 2.0f / SCREEN_WIDTH_PX;
+
+ float x = 0.0f;
+
+ float y = -(SCREEN_HEIGHT_PX / (float)SCREEN_WIDTH_PX);
+ y += g_Zoom * (scale * params->homeButtonTextureHeight / 2);
+
+ float z = 0.0f;
+ drawSprite(x, y, z, params->homeButtonTextureWidth, params->homeButtonTextureHeight);
+}
+
+int
+main(int launchID)
+{
+ // Compute dt in seconds.
+ int newTime = uptimeMillis();
+ g_DT = (newTime - g_LastTime) / 1000.f;
+ g_LastTime = newTime;
+
+ if (!g_DrawLastFrame) {
+ // If we stopped rendering we cannot use DT.
+ // assume 30fps in this case.
+ g_DT = 0.033f;
+ }
+ if (g_DT > 0.2f) {
+ // physics may break if DT is large.
+ g_DT = 0.2f;
+ }
+
+ debugF("zoom", g_Zoom);
+ if (g_Zoom != state->zoomTarget) {
+ float dz = (state->zoomTarget - g_Zoom) * g_DT * 5;
+ if (dz && (fabsf(dz) < 0.03f)) {
+ if (dz > 0) {
+ dz = 0.03f;
+ } else {
+ dz = -0.03f;
+ }
+ }
+ if (fabsf(g_Zoom - state->zoomTarget) < fabsf(dz)) {
+ g_Zoom = state->zoomTarget;
+ } else {
+ g_Zoom += dz;
+ }
+ updateReadback();
+ }
+
+ // Set clear value to dim the background based on the zoom position.
+ if ((g_Zoom < 0.001f) && (state->zoomTarget < 0.001f)) {
+ pfClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ // When we're zoomed out and not tracking motion events, reset the pos to 0.
+ if (!g_LastTouchDown) {
+ g_PosPage = 0;
+ }
+ return lastFrame(0);
+ } else if (g_Zoom < 0.85f) {
+ pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
+ } else {
+ pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
+ }
+
+ // icons & labels
+ int iconCount = state->iconCount;
+ g_PageCount = count_pages(iconCount);
+
+ updatePos(0.1f);
+ updateReadback();
+
+ debugF(" draw g_PosPage", g_PosPage);
+
+ // Draw the icons ========================================
+
+ // Bug makes 1.0f alpha fail.
+ //color(0.2f, 0.2f, 0.2f, 0.99f);
+ //bindProgramFragment(NAMED_PFColor);
+ //positionStrip(0, 0);
+ //drawSimpleMesh(NAMED_SMMesh);
+
+ bindProgramFragment(NAMED_PFTexLinear);
+
+
+ int lastIcon = iconCount-1;
+
+ int page = g_PosPage;
+ float currentPagePosition = g_PosPage - page;
+
+ int iconsPerPage = COLUMNS_PER_PAGE * ROWS_PER_PAGE;
+ float scale = (1 / g_Zoom);
+
+ float pageAngle = VIEW_ANGLE * 1.2f;
+
+ float zoomOffset = 40 * (1 - g_Zoom);
+ int drawPage;
+ //lastIcon = 1;
+ for (drawPage = 0; drawPage < g_PageCount; drawPage++) {
+ int r, c;
+ for (r=0; r < 4; r++) {
+ for (c=0; c < 4; c++) {
+ int iconNum = drawPage * 16 + c + r * 4;
+ if (iconNum <= lastIcon) {
+ float p = (((float)drawPage) - g_PosPage) * 5.f;
+ p += c - 1.5f;
+ p += zoomOffset;
+ if (fabsf(p) > 2) {
+ drawIcon(r, p, iconNum);
+ }
+ }
+ }
+ }
+ }
+
+ for (drawPage = 0; drawPage < g_PageCount; drawPage++) {
+ int r, c;
+ for (r=0; r < 4; r++) {
+ for (c=0; c < 4; c++) {
+ int iconNum = drawPage * 16 + c + r * 4;
+ if (iconNum <= lastIcon) {
+ float p = (((float)drawPage) - g_PosPage) * 5.f;
+ p += c - 1.5f;
+ p += zoomOffset;
+ float x = (p * 1.13f + 1.88f) * getWidth() * 0.2f;
+ float y = 570 - r * 147;
+
+ if (fabsf(p) <= 2) {
+ drawIcon(r, p, iconNum);
+ }
+ if (fabsf(p) <= 2.5) {
+ float a = (1.2f - maxf(scale, 1.0f)) * 5;
+ color(1.0f, 1.0f, 1.0f, a);
+ bindTexture(NAMED_PFTexLinear, 0, loadI32(ALLOC_LABEL_IDS, iconNum));
+ drawSpriteScreenspace(x, y, 0,
+ params->bubbleBitmapWidth, params->bubbleBitmapHeight);
+ }
+ }
+ }
+ }
+
+ }
+
+ {
+ float mat1[16];
+ matrixLoadIdentity(mat1);
+ vpLoadModelMatrix(mat1);
+ vpLoadTextureMatrix(mat1);
+ }
+
+ // Draw the home button ========================================
+ //draw_home_button();
+
+ // Bug workaround where the last frame is not always displayed
+ // So we keep rendering until the bug is fixed.
+ return 1; //(g_PosVelocity != 0) || fracf(g_PosPage) || g_Zoom != g_ZoomTarget);
+}
+
diff --git a/res/raw/rollo3.c b/res/raw/rollo3.c
new file mode 100644
index 0000000..f3250a0
--- /dev/null
+++ b/res/raw/rollo3.c
@@ -0,0 +1,525 @@
+#pragma version(1)
+#pragma stateVertex(PV)
+#pragma stateFragment(PFTexNearest)
+#pragma stateStore(PSIcons)
+
+#define PI 3.14159f
+
+int g_SpecialHWWar;
+
+// Attraction to center values from page edge to page center.
+float g_AttractionTable[9];
+float g_FrictionTable[9];
+float g_PhysicsTableSize;
+
+float g_PosPage;
+float g_PosVelocity;
+float g_LastPositionX;
+int g_LastTouchDown;
+float g_DT;
+int g_LastTime;
+int g_PosMax;
+float g_Zoom;
+float g_OldPosPage;
+float g_OldPosVelocity;
+float g_OldZoom;
+float g_MoveToTotalTime;
+float g_MoveToTime;
+float g_MoveToOldPos;
+
+
+// Drawing constants, should be parameters ======
+#define VIEW_ANGLE 1.28700222f
+
+int g_DrawLastFrame;
+int lastFrame(int draw) {
+ // We draw one extra frame to work around the last frame post bug.
+ // We also need to track if we drew the last frame to deal with large DT
+ // in the physics.
+ int ret = g_DrawLastFrame | draw;
+ g_DrawLastFrame = draw;
+ return ret; // should return draw instead.
+}
+
+void updateReadback() {
+ if ((g_OldPosPage != g_PosPage) ||
+ (g_OldPosVelocity != g_PosVelocity) ||
+ (g_OldZoom != g_Zoom)) {
+
+ g_OldPosPage = g_PosPage;
+ g_OldPosVelocity = g_PosVelocity;
+ g_OldZoom = g_Zoom;
+
+ int i[3];
+ i[0] = g_PosPage * (1 << 16);
+ i[1] = g_PosVelocity * (1 << 16);
+ i[2] = g_OldZoom * (1 << 16);
+ sendToClient(&i[0], 1, 12, 1);
+ }
+}
+
+void setColor(float r, float g, float b, float a) {
+ if (g_SpecialHWWar) {
+ color(0, 0, 0, 0.001f);
+ } else {
+ color(r, g, b, a);
+ }
+}
+
+void init() {
+ g_AttractionTable[0] = 20.0f;
+ g_AttractionTable[1] = 20.0f;
+ g_AttractionTable[2] = 20.0f;
+ g_AttractionTable[3] = 10.0f;
+ g_AttractionTable[4] = -10.0f;
+ g_AttractionTable[5] = -20.0f;
+ g_AttractionTable[6] = -20.0f;
+ g_AttractionTable[7] = -20.0f;
+ g_AttractionTable[8] = -20.0f; // dup 7 to avoid a clamp later
+ g_FrictionTable[0] = 10.0f;
+ g_FrictionTable[1] = 10.0f;
+ g_FrictionTable[2] = 11.0f;
+ g_FrictionTable[3] = 15.0f;
+ g_FrictionTable[4] = 15.0f;
+ g_FrictionTable[5] = 11.0f;
+ g_FrictionTable[6] = 10.0f;
+ g_FrictionTable[7] = 10.0f;
+ g_FrictionTable[8] = 10.0f; // dup 7 to avoid a clamp later
+ g_PhysicsTableSize = 7;
+
+ g_PosVelocity = 0;
+ g_PosPage = 0;
+ g_LastTouchDown = 0;
+ g_LastPositionX = 0;
+ g_Zoom = 0;
+ g_SpecialHWWar = 1;
+ g_MoveToTime = 0;
+ g_MoveToOldPos = 0;
+ g_MoveToTotalTime = 0.2f; // Duration of scrolling 1 line
+}
+
+void resetHWWar() {
+ g_SpecialHWWar = 1;
+}
+
+void move() {
+ if (g_LastTouchDown) {
+ float dx = -(state->newPositionX - g_LastPositionX);
+ g_PosVelocity = 0;
+ g_PosPage += dx * 5.2f;
+
+ float pmin = -0.49f;
+ float pmax = g_PosMax + 0.49f;
+ g_PosPage = clampf(g_PosPage, pmin, pmax);
+ }
+ g_LastTouchDown = state->newTouchDown;
+ g_LastPositionX = state->newPositionX;
+ g_MoveToTime = 0;
+ //debugF("Move P", g_PosPage);
+}
+
+void moveTo() {
+ g_MoveToTime = g_MoveToTotalTime;
+ g_PosVelocity = 0;
+ g_MoveToOldPos = g_PosPage;
+
+ // debugF("======= moveTo", state->targetPos);
+}
+
+void setZoom() {
+ g_Zoom = state->zoomTarget;
+ g_DrawLastFrame = 1;
+ updateReadback();
+}
+
+void fling() {
+ g_LastTouchDown = 0;
+ g_PosVelocity = -state->flingVelocity * 4;
+ float av = fabsf(g_PosVelocity);
+ float minVel = 3.5f;
+
+ minVel *= 1.f - (fabsf(fracf(g_PosPage + 0.5f) - 0.5f) * 0.45f);
+
+ if (av < minVel && av > 0.2f) {
+ if (g_PosVelocity > 0) {
+ g_PosVelocity = minVel;
+ } else {
+ g_PosVelocity = -minVel;
+ }
+ }
+
+ if (g_PosPage <= 0) {
+ g_PosVelocity = maxf(0, g_PosVelocity);
+ }
+ if (g_PosPage > g_PosMax) {
+ g_PosVelocity = minf(0, g_PosVelocity);
+ }
+}
+
+float
+modf(float x, float y)
+{
+ return x-(y*floorf(x/y));
+}
+
+
+/*
+ * Interpolates values in the range 0..1 to a curve that eases in
+ * and out.
+ */
+float
+getInterpolation(float input) {
+ return (cosf((input + 1) * PI) / 2.0f) + 0.5f;
+}
+
+
+void updatePos() {
+ if (g_LastTouchDown) {
+ return;
+ }
+
+ float tablePosNorm = fracf(g_PosPage + 0.5f);
+ float tablePosF = tablePosNorm * g_PhysicsTableSize;
+ int tablePosI = tablePosF;
+ float tablePosFrac = tablePosF - tablePosI;
+ float accel = lerpf(g_AttractionTable[tablePosI],
+ g_AttractionTable[tablePosI + 1],
+ tablePosFrac) * g_DT;
+ float friction = lerpf(g_FrictionTable[tablePosI],
+ g_FrictionTable[tablePosI + 1],
+ tablePosFrac) * g_DT;
+
+ if (g_MoveToTime) {
+ // New position is old posiition + (total distance) * (interpolated time)
+ g_PosPage = g_MoveToOldPos + (state->targetPos - g_MoveToOldPos) * getInterpolation((g_MoveToTotalTime - g_MoveToTime) / g_MoveToTotalTime);
+ g_MoveToTime -= g_DT;
+ if (g_MoveToTime <= 0) {
+ g_MoveToTime = 0;
+ g_PosPage = state->targetPos;
+ }
+ return;
+ }
+
+ // If our velocity is low OR acceleration is opposing it, apply it.
+ if (fabsf(g_PosVelocity) < 4.0f || (g_PosVelocity * accel) < 0) {
+ g_PosVelocity += accel;
+ }
+ //debugF("g_PosPage", g_PosPage);
+ //debugF(" g_PosVelocity", g_PosVelocity);
+ //debugF(" friction", friction);
+ //debugF(" accel", accel);
+
+ // Normal physics
+ if (g_PosVelocity > 0) {
+ g_PosVelocity -= friction;
+ g_PosVelocity = maxf(g_PosVelocity, 0);
+ } else {
+ g_PosVelocity += friction;
+ g_PosVelocity = minf(g_PosVelocity, 0);
+ }
+
+ if ((friction > fabsf(g_PosVelocity)) && (friction > fabsf(accel))) {
+ // Special get back to center and overcome friction physics.
+ float t = tablePosNorm - 0.5f;
+ if (fabsf(t) < (friction * g_DT)) {
+ // really close, just snap
+ g_PosPage = roundf(g_PosPage);
+ g_PosVelocity = 0;
+ } else {
+ if (t > 0) {
+ g_PosVelocity = -friction;
+ } else {
+ g_PosVelocity = friction;
+ }
+ }
+ }
+
+ // Check for out of boundry conditions.
+ if (g_PosPage < 0 && g_PosVelocity < 0) {
+ float damp = 1.0 + (g_PosPage * 4);
+ damp = clampf(damp, 0.f, 0.9f);
+ g_PosVelocity *= damp;
+ }
+ if (g_PosPage > g_PosMax && g_PosVelocity > 0) {
+ float damp = 1.0 - ((g_PosPage - g_PosMax) * 4);
+ damp = clampf(damp, 0.f, 0.9f);
+ g_PosVelocity *= damp;
+ }
+
+ g_PosPage += g_PosVelocity * g_DT;
+ g_PosPage = clampf(g_PosPage, -0.49, g_PosMax + 0.49);
+}
+
+int positionStrip(float row, float column, int isTop, float p, int isText)
+{
+ float mat1[16];
+ float x = 0.5f * (column - 1.5f);
+ float scale = 72.f * 3 / getWidth();
+
+ if (isTop) {
+ matrixLoadTranslate(mat1, x, 0.8f, 0.f);
+ matrixScale(mat1, scale, scale, 1.f);
+ } else {
+ matrixLoadTranslate(mat1, x, -0.9f, 0.f);
+ matrixScale(mat1, scale, -scale, 1.f);
+ }
+ matrixTranslate(mat1, 0, p * 2, 0.f);
+ matrixRotate(mat1, -p * 50, 1, 0, 0);
+ vpLoadModelMatrix(mat1);
+
+ float soff = -(row * 1.4);
+ if (isTop) {
+ matrixLoadScale(mat1, 1.f, -0.85f, 1.f);
+ if (isText) {
+ matrixScale(mat1, 1.f, 2.f, 1.f);
+ }
+ matrixTranslate(mat1, 0, soff - 0.95f + 0.18f, 0);
+ } else {
+ matrixLoadScale(mat1, 1.f, 0.85f, 1.f);
+ if (isText) {
+ matrixScale(mat1, 1.f, 2.f, 1.f);
+ }
+ matrixTranslate(mat1, 0, soff - 0.65f, 0);
+ }
+ vpLoadTextureMatrix(mat1);
+ return -(soff + 0.3f) * 10.f;
+}
+
+void
+draw_home_button()
+{
+ setColor(1.0f, 1.0f, 1.0f, 1.0f);
+ bindTexture(NAMED_PFTexNearest, 0, state->homeButtonId);
+ float x = (SCREEN_WIDTH_PX - params->homeButtonTextureWidth) / 2;
+ float y = (g_Zoom - 1.f) * params->homeButtonTextureHeight;
+
+ y -= 30; // move the house to the edge of the screen as it doesn't fill the texture.
+ drawSpriteScreenspace(x, y, 0, params->homeButtonTextureWidth, params->homeButtonTextureHeight);
+}
+
+void drawFrontGrid(float rowOffset, float p)
+{
+ float h = getHeight();
+ float w = getWidth();
+
+ int intRowOffset = rowOffset;
+ float rowFrac = rowOffset - intRowOffset;
+ float colWidth = getWidth() / 4;
+ float rowHeight = colWidth + 25.f;
+ float yoff = h - ((h - (rowHeight * 4.f)) / 2);
+
+ yoff -= 110;
+
+ int row, col;
+ int iconNum = intRowOffset * 4;
+ float ymax = yoff + rowHeight;
+ float ymin = yoff - (3 * rowHeight) - 70;
+ float gridTop = yoff -3;
+ float gridBottom = ymin;
+
+ gridBottom += 50;
+
+ for (row = 0; row < 5; row++) {
+ float y = yoff - ((-rowFrac + row) * rowHeight);
+
+ for (col=0; col < 4; col++) {
+ if (iconNum >= state->iconCount) {
+ return;
+ }
+
+ if (iconNum >= 0) {
+ float x = colWidth * col - ((128 - colWidth) / 2);
+
+ if ((y >= ymin) && (y <= ymax)) {
+ float iconY = y - 20;
+ setColor(1.f, 1.f, 1.f, 1.f);
+ if (state->selectedIconIndex == iconNum && !p) {
+ bindTexture(NAMED_PFTexNearest, 0, state->selectedIconTexture);
+ drawSpriteScreenspace(x, iconY, 0, 128, 128);
+ }
+
+ bindTexture(NAMED_PFTexNearest, 0, loadI32(ALLOC_ICON_IDS, iconNum));
+ if (!p) {
+ int cropT = 0;
+ if (y > gridTop) {
+ cropT = y - gridTop;
+ }
+ int cropB = 0;
+ if (y < gridBottom) {
+ cropB = gridBottom - y;
+ }
+ drawSpriteScreenspaceCropped(x, iconY+cropB, 0, 128, 128-cropT-cropB,
+ 0, 128-cropB, 128, -128+cropT+cropB);
+ } else {
+ float px = ((x + 64) - (getWidth() / 2)) / (getWidth() / 2);
+ float py = ((iconY + 64) - (getHeight() / 2)) / (getWidth() / 2);
+ float d = 64.f / (getWidth() / 2);
+ px *= p + 1;
+ py *= p + 1;
+ drawQuadTexCoords(px - d, py - d, -p, 0, 1,
+ px - d, py + d, -p, 0, 0,
+ px + d, py + d, -p, 1, 0,
+ px + d, py - d, -p, 1, 1);
+ }
+ }
+ }
+ iconNum++;
+ }
+ }
+}
+
+void drawStrip(float row, float column, int isTop, int iconNum, float p)
+{
+ if (iconNum < 0) return;
+ int offset = positionStrip(row, column, isTop, p, 0);
+ bindTexture(NAMED_PFTexMip, 0, loadI32(ALLOC_ICON_IDS, iconNum));
+ if (offset < -20) return;
+ offset = clamp(offset, 0, 199 - 20);
+
+ int len = 20;
+ if (isTop && (offset < 7)) {
+ len -= 7 - offset;
+ offset = 7;
+ }
+
+ drawSimpleMeshRange(NAMED_SMMesh, offset * 6, len * 6);
+ //drawSimpleMesh(NAMED_SMMesh);
+}
+
+void drawTop(float rowOffset, float p)
+{
+ int row, col;
+ int iconNum = 0;
+ for (row = 0; row <= (int)(rowOffset+1); row++) {
+ for (col=0; col < 4; col++) {
+ if (iconNum >= state->iconCount) {
+ return;
+ }
+ drawStrip(rowOffset - row, col, 1, iconNum, p);
+ iconNum++;
+ }
+ }
+}
+
+void drawBottom(float rowOffset, float p)
+{
+ float pos = -1.f;
+ int intRowOffset = rowOffset;
+ pos -= rowOffset - intRowOffset;
+
+ int row, col;
+ int iconNum = (intRowOffset + 3) * 4;
+ while (1) {
+ for (col=0; col < 4; col++) {
+ if (iconNum >= state->iconCount) {
+ return;
+ }
+ if (pos > -1) {
+ drawStrip(pos, col, 0, iconNum, p);
+ }
+ iconNum++;
+ }
+ pos += 1.f;
+ }
+}
+
+int
+main(int launchID)
+{
+ // Compute dt in seconds.
+ int newTime = uptimeMillis();
+ g_DT = (newTime - g_LastTime) / 1000.f;
+ g_LastTime = newTime;
+
+ if (!g_DrawLastFrame) {
+ // If we stopped rendering we cannot use DT.
+ // assume 30fps in this case.
+ g_DT = 0.033f;
+ }
+ // physics may break if DT is large.
+ g_DT = minf(g_DT, 0.2f);
+
+ if (g_Zoom != state->zoomTarget) {
+ float dz;
+ if (state->zoomTarget > 0.5f) {
+ dz = (1 - g_Zoom) * 0.2f;
+ } else {
+ dz = -g_DT - (1 - g_Zoom) * 0.2f;
+ }
+ if (dz && (fabsf(dz) < 0.02f)) {
+ if (dz > 0) {
+ dz = 0.02f;
+ } else {
+ dz = -0.02f;
+ }
+ }
+ if (fabsf(g_Zoom - state->zoomTarget) < fabsf(dz)) {
+ g_Zoom = state->zoomTarget;
+ } else {
+ g_Zoom += dz;
+ }
+ updateReadback();
+ }
+
+ // Set clear value to dim the background based on the zoom position.
+ if ((g_Zoom < 0.001f) && (state->zoomTarget < 0.001f) && !g_SpecialHWWar) {
+ pfClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ // When we're zoomed out and not tracking motion events, reset the pos to 0.
+ if (!g_LastTouchDown) {
+ g_PosPage = 0;
+ }
+ return lastFrame(0);
+ } else {
+ pfClearColor(0.0f, 0.0f, 0.0f, g_Zoom);
+ }
+
+ // icons & labels
+ int iconCount = state->iconCount;
+ g_PosMax = ((iconCount + 3) / 4) - 4;
+ if (g_PosMax < 0) g_PosMax = 0;
+
+ updatePos(0.1f);
+ updateReadback();
+
+ //debugF(" draw g_PosPage", g_PosPage);
+
+ // Draw the icons ========================================
+
+ /*
+ bindProgramFragment(NAMED_PFColor);
+ positionStrip(1, 0, 1, 0, 0);
+ drawSimpleMesh(NAMED_SMMesh);
+ */
+
+ bindProgramFragment(NAMED_PFTexMip);
+
+ drawTop(g_PosPage, 1-g_Zoom);
+ drawBottom(g_PosPage, 1-g_Zoom);
+
+ bindProgramFragment(NAMED_PFTexMip);
+ {
+ float mat1[16];
+ matrixLoadIdentity(mat1);
+ vpLoadModelMatrix(mat1);
+ vpLoadTextureMatrix(mat1);
+ }
+
+ bindProgramFragment(NAMED_PFTexNearest);
+ drawFrontGrid(g_PosPage, 1-g_Zoom);
+ draw_home_button();
+
+
+ // This is a WAR to do a rendering pass without drawing during init to
+ // force the driver to preload and compile its shaders.
+ // Without this the first animation does not appear due to the time it
+ // takes to init the driver state.
+ if (g_SpecialHWWar) {
+ g_SpecialHWWar = 0;
+ return 1;
+ }
+
+ // Bug workaround where the last frame is not always displayed
+ // So we keep rendering until the bug is fixed.
+ return lastFrame((g_PosVelocity != 0) || fracf(g_PosPage) || g_Zoom != state->zoomTarget || (g_MoveToTime != 0));
+}
+
diff --git a/res/values-cs/strings.xml b/res/values-cs/strings.xml
new file mode 100644
index 0000000..815bd10
--- /dev/null
+++ b/res/values-cs/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android Core Apps"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Složka"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Vybrat tapetu ze složky"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Nastavit tapetu"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Tapety"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Aplikace není v telefonu nainstalována."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Konfigurace..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Název složky"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Přejmenovat složku"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Zrušit"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Přidat na plochu"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Aplikace"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Zástupce"</string>
+ <string name="group_search" msgid="5905328940867162196">"Hledat"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Nová složka"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Složky"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widgety"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Tapety"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Složka"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Hodiny"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Rámeček fotografie"</string>
+ <string name="add_search" msgid="7104834713685095105">"Vyhledávání"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Na této ploše již není místo."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Zástupce <xliff:g id="NAME">%s</xliff:g> byl vytvořen."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Zástupce <xliff:g id="NAME">%s</xliff:g> byl odebrán."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Zástupce <xliff:g id="NAME">%s</xliff:g> již existuje."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Vyberte zástupce"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Vybrat složku"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Všechny aplikace"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Plocha"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Přidat"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Tapeta"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Hledat"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Oznámení"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gesta"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Nastavení"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"instalovat zástupce"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Povoluje aplikaci přidat zástupce bez zásahu uživatele."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"odinstalovat zástupce"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Povoluje aplikaci odstranit zástupce bez zásahu uživatele."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"čtení nastavení a odkazů plochy"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Povoluje aplikaci číst nastavení a odkazy plochy."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"zápis nastavení a odkazů plochy"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Povoluje aplikaci změnit nastavení a odkazy plochy."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Vyhledávání Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Problém s načtením widgetu"</string>
+</resources>
diff --git a/res/values-da/strings.xml b/res/values-da/strings.xml
new file mode 100644
index 0000000..391ec16
--- /dev/null
+++ b/res/values-da/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android-kerneprogrammer"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Mappe"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Vælg tapet fra"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Angiv tapet"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Tapeter"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Programmet er ikke installeret på din telefon."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Konfigurer ..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Mappenavn"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Omdøb mappe"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Annuller"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Føj til Startskærm"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Programmer"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Genveje"</string>
+ <string name="group_search" msgid="5905328940867162196">"Søg"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Ny mappe"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Mapper"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widgets"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Tapeter"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Mappe"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Ur"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Billedramme"</string>
+ <string name="add_search" msgid="7104834713685095105">"Søg"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Der er ikke mere plads på Startskærmen."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Genvejen \"<xliff:g id="NAME">%s</xliff:g>\" blev oprettet."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Genvejen \"<xliff:g id="NAME">%s</xliff:g>\" blev fjernet."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Genvejen \"<xliff:g id="NAME">%s</xliff:g>\" findes allerede."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Vælg genvej"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Vælg mappe"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Alle programmer"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Start"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Tilføj"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Tapet"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Søg"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Meddelelser"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gestus"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Indstillinger"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"installer genveje"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Tillader, at et program tilføjer genveje uden brugerindgriben."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"afinstaller genveje"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Tillader, at et program fjerner genveje uden brugerindgriben."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"læs indstillinger og genveje for Start"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Tillader, at et program læser indstillingerne og genvejene i Start."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"skriv indstillinger og genveje for Start"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Tillader, at et program ændrer indstillingerne og genvejene i Start."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Google-søgning"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Der er problemer med indlæsning af widget"</string>
+</resources>
diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml
new file mode 100644
index 0000000..522bd4d
--- /dev/null
+++ b/res/values-de/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android Core Apps"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Ordner"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Hintergrund auswählen"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Hintergrund festlegen"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Hintergrundbilder"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Anwendung ist nicht auf dem Telefon installiert."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Konfigurieren..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Ordnername"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Ordner umbenennen"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Abbrechen"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Zum Startbildschirm hinzufügen"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Anwendungen"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Verknüpfungen"</string>
+ <string name="group_search" msgid="5905328940867162196">"Suchen"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Neuer Ordner"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Ordner"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widgets"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Hintergrundbilder"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Ordner"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Uhr"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Bildrahmen"</string>
+ <string name="add_search" msgid="7104834713685095105">"Suchen"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Auf dem Startbildschirm ist kein Platz mehr vorhanden."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"\"<xliff:g id="NAME">%s</xliff:g>\"-Verknüpfung wurde erstellt."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"\"<xliff:g id="NAME">%s</xliff:g>\"-Verknüpfung wurde entfernt."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"\"<xliff:g id="NAME">%s</xliff:g>\"-Verknüpfung ist bereits vorhanden."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Tastenkürzel auswählen"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Ordner auswählen"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Alle Anwendungen"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Startseite"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Hinzufügen"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Hintergrund"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Suchen"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Benachrichtigungen"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Bewegungen"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Einstellungen"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"Verknüpfungen installieren"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Ermöglicht einer Anwendung das Hinzufügen von Verknüpfungen ohne Eingriff des Nutzers."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"Verknüpfungen deinstallieren"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Ermöglicht einer Anwendung das Entfernen von Verknüpfungen ohne Eingriff des Nutzers."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"Einstellungen und Shortcuts für Startseite lesen"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Ermöglicht einer Anwendung, die Einstellungen und Shortcuts auf der Startseite zu lesen."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"Einstellungen und Shortcuts für Startseite schreiben"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Ermöglicht einer Anwendung, die Einstellungen und Shortcuts auf der Startseite zu ändern."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Google-Suche"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Problem beim Laden des Widgets"</string>
+</resources>
diff --git a/res/values-el/strings.xml b/res/values-el/strings.xml
new file mode 100644
index 0000000..bb65bf3
--- /dev/null
+++ b/res/values-el/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Βασικές εφαρμογές Android"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Φάκελος"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Επιλογή ταπετσαρίας από"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Ορισμός ταπετσαρίας"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Ταπετσαρίες"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Η εφαρμογή δεν έχει εγκατασταθεί στο τηλέφωνό σας."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Διαμόρφωση..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Όνομα φακέλου"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Μετονομασία φακέλου"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Ακύρωση"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Προσθήκη στην αρχική οθόνη"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Εφαρμογές"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Συντομεύσεις"</string>
+ <string name="group_search" msgid="5905328940867162196">"Αναζήτηση"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Νέος φάκελος"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Φάκελοι"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Γραφικά στοιχεία"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Ταπετσαρίες"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Φάκελος"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Ρολόι"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Πλαίσιο εικόνας"</string>
+ <string name="add_search" msgid="7104834713685095105">"Αναζήτηση"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Δεν υπάρχει χώρος σε αυτήν την αρχική οθόνη."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Δημιουργήθηκε η συντόμευση \"<xliff:g id="NAME">%s</xliff:g>\"."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Η συντόμευση \"<xliff:g id="NAME">%s</xliff:g>\" καταργήθηκε."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Η συντόμευση \"<xliff:g id="NAME">%s</xliff:g>\" υπάρχει ήδη."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Επιλογή συντόμευσης"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Επιλογή φακέλου"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Όλες οι εφαρμογές"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Αρχική σελίδα"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Προσθήκη"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Ταπετσαρία"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Αναζήτηση"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Ειδοποιήσεις"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Χειρονομίες"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Ρυθμίσεις"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"εγκατάσταση συντομεύσεων"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Επιτρέπει σε μια εφαρμογή την προσθήκη συντομεύσεων χωρίς την παρέμβαση του χρήστη."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"κατάργηση εγκατάστασης συντομεύσεων"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Επιτρέπει σε μια εφαρμογή την κατάργηση συντομεύσεων χωρίς την παρέμβαση του χρήστη."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"ανάγνωση ρυθμίσεων και συντομεύσεων αρχικής οθόνης"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Επιτρέπει σε μια εφαρμογή την ανάγνωση των ρυθμίσεων και των συντομεύσεων στην αρχική οθόνη."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"εγγραφή ρυθμίσεων και συντομεύσεων αρχικής οθόνης"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Επιτρέπει σε μια εφαρμογή την αλλαγή των ρυθμίσεων και των συντομεύσεων στην αρχική οθόνη."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Αναζήτηση Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Παρουσιάστηκε πρόβλημα στη φόρτωση του γραφικού στοιχείου"</string>
+</resources>
diff --git a/res/values-es-rUS/strings.xml b/res/values-es-rUS/strings.xml
new file mode 100644
index 0000000..bee06e3
--- /dev/null
+++ b/res/values-es-rUS/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Aplicaciones del núcleo de Android"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Carpeta"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Seleccionar papel tapiz desde"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Definir papel tapiz"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Papeles tapiz"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"La aplicación no está instalada en tu computadora."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Configurar..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Nombre de carpeta"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Cambiar nombre de carpeta"</string>
+ <string name="rename_action" msgid="6016003384693240896">"Aceptar"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Cancelar"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Agregar a la pantalla Página principal"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Aplicaciones"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Accesos directos"</string>
+ <string name="group_search" msgid="5905328940867162196">"Buscar"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Carpeta nueva"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Carpetas"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Controles"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Papeles tapiz"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Carpeta"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Reloj"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Marco de imagen"</string>
+ <string name="add_search" msgid="7104834713685095105">"Buscar"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"No hay más espacio en esta pantalla de la página principal"</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Acceso directo \"<xliff:g id="NAME">%s</xliff:g>\" creado."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"El acceso directo \"<xliff:g id="NAME">%s</xliff:g>\" ha sido eliminado."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"El acceso directo \"<xliff:g id="NAME">%s</xliff:g>\" ya existe."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Seleccionar acceso directo"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Seleccionar carpeta"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Todas las aplicaciones"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Página principal"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Agregar"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Papel tapiz"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Buscar"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Notificaciones"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gestos"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Configuración"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"instalar accesos directos"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Permite a una aplicación agregar accesos directos sin intervención del usuario."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"desinstalar papel tapiz"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Permite a una aplicación suprimir accesos directos sin intervención del usuario."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"leer configuración y accesos directos de la página principal"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Permite a una aplicación leer la configuración y los accesos directos de la página principal."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"escribir configuración y accesos directos de la página principal"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Permite a una aplicación cambiar la configuración y los accesos directos de la página principal."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Búsqueda de Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Problema al cargar el widget"</string>
+</resources>
diff --git a/res/values-es/strings.xml b/res/values-es/strings.xml
new file mode 100644
index 0000000..7554c1b
--- /dev/null
+++ b/res/values-es/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Aplicaciones básicas de Android"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Carpeta"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Seleccionar fondo de pantalla de"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Establecer fondo de pantalla"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Fondos de pantalla"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"La aplicación no está instalada en el teléfono."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Configurar..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Nombre de carpeta"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Cambiar nombre de carpeta"</string>
+ <string name="rename_action" msgid="6016003384693240896">"Aceptar"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Cancelar"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Añadir a pantalla de página principal"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Aplicaciones"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Accesos directos"</string>
+ <string name="group_search" msgid="5905328940867162196">"Búsqueda"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Nueva carpeta"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Carpetas"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widgets"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Fondos de pantalla"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Carpeta"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Reloj"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Picture frame"</string>
+ <string name="add_search" msgid="7104834713685095105">"Búsqueda de Google"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"No queda espacio en esta pantalla de página principal."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Se ha creado el acceso directo \"<xliff:g id="NAME">%s</xliff:g>\"."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Se ha eliminado el acceso directo \"<xliff:g id="NAME">%s</xliff:g>\"."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"El acceso directo \"<xliff:g id="NAME">%s</xliff:g>\" ya existe."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Seleccionar acceso directo"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Seleccionar carpeta"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Todas las aplicaciones"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Página principal"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Añadir"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Fondo de pantalla"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Buscar con Google"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Notificaciones"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gestos"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Ajustes"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"instalar accesos directos"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Permite que una aplicación añada accesos directos sin intervención del usuario."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"desinstalar accesos directos"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Permite que una aplicación elimine accesos directos sin intervención del usuario."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"leer información de accesos directos y de configuración de la página principal"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Permite que una aplicación lea la información de configuración y accesos directos de la página principal."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"escribir información de accesos directos y de configuración de la página principal"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Permite que una aplicación modifique la configuración y los accesos directos de la página principal."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Búsqueda de Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Problema al cargar el widget"</string>
+</resources>
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
new file mode 100644
index 0000000..0d66612
--- /dev/null
+++ b/res/values-fr/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Lanceur d\'applications"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Applications de base Android"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Dossier"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Sélectionner à partir de..."</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Sélectionner"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Fonds d\'écran"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"L\'application n\'est pas installée sur votre téléphone."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Configurer..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Nom du dossier"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Renommer le dossier"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Annuler"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Ajouter à l\'écran d\'accueil"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Applications"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Raccourcis"</string>
+ <string name="group_search" msgid="5905328940867162196">"Recherche"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Nouveau dossier"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Dossiers"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widgets"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Fonds d\'écran"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Dossier"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Horloge"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Cadre d\'image"</string>
+ <string name="add_search" msgid="7104834713685095105">"Recherche"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Plus d\'espace libre sur l\'écran d\'accueil."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Le raccourci \"<xliff:g id="NAME">%s</xliff:g>\" a été créé."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Le raccourci \"<xliff:g id="NAME">%s</xliff:g>\" a été supprimé."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Le raccourci \"<xliff:g id="NAME">%s</xliff:g>\" existe déjà."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Sélectionner un raccourci"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Sélectionner le dossier"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Toutes les applications"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Domicile"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Ajouter"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Fond d\'écran"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Rechercher"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Notifications"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gestes"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Paramètres"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"installer des raccourcis"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Permet à une application d\'ajouter des raccourcis sans l\'intervention de l\'utilisateur."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"désinstaller les raccourcis"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Permet à une application de supprimer les raccourcis sans l\'intervention de l\'utilisateur."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"Lire les paramètres et les raccourcis de la page d\'accueil"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Permet à une application de lire les paramètres et raccourcis de la page d\'accueil."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"Enregistrer les paramètres de la page d\'accueil et des raccourcis"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Permet à une application de modifier les paramètres et les raccourcis de la page d\'accueil."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Recherche Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Problème lors du chargement du widget"</string>
+</resources>
diff --git a/res/values-hdpi/wallpapers.xml b/res/values-hdpi/wallpapers.xml
new file mode 100644
index 0000000..26961b3
--- /dev/null
+++ b/res/values-hdpi/wallpapers.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+<resources>
+ <string-array name="wallpapers" translatable="false">
+ <item>wallpaper_electric</item>
+ <item>wallpaper_grass</item>
+ <item>wallpaper_canyon</item>
+ <item>wallpaper_monumentvalley</item>
+ <item>wallpaper_tree</item>
+ <item>wallpaper_zanzibar</item>
+ <item>wallpaper_field</item>
+ <item>wallpaper_cloud</item>
+ <item>wallpaper_desert</item>
+ <item>wallpaper_goldengate</item>
+ <item>wallpaper_despair</item>
+ <item>wallpaper_grass_night</item>
+ <item>wallpaper_galaxy</item>
+ <item>wallpaper_x67</item>
+ <item>wallpaper_nexusrain</item>
+ <item>wallpaper_nexuspattern</item>
+ <item>wallpaper_nexuswallpaper1</item>
+ <item>wallpaper_brown</item>
+ <item>wallpaper_pcut</item>
+ <item>wallpaper_bluedotgrid</item>
+ <item>wallpaper_hazybluedots</item>
+ <item>wallpaper_ropelights</item>
+ <item>wallpaper_gray</item>
+ <item>wallpaper_greengray</item>
+ <item>wallpaper_lightgrad</item>
+ </string-array>
+</resources>
diff --git a/res/values-it/strings.xml b/res/values-it/strings.xml
new file mode 100644
index 0000000..422f998
--- /dev/null
+++ b/res/values-it/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android Core Apps"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Cartella"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Seleziona sfondo da"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Imposta sfondo"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Sfondi"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Applicazione non installata sul telefono."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Configura..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Nome cartella"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Rinomina cartella"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Annulla"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Aggiungi a schermata Home"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Applicazioni"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Collegamenti"</string>
+ <string name="group_search" msgid="5905328940867162196">"Ricerca"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Nuova cartella"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Cartelle"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widget"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Sfondi"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Cartella"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Orologio"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Cornice immagini"</string>
+ <string name="add_search" msgid="7104834713685095105">"Ricerca"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Spazio nella schermata Home esaurito."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Collegamento \"<xliff:g id="NAME">%s</xliff:g>\" creato."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Il collegamento \"<xliff:g id="NAME">%s</xliff:g>\" è stato rimosso."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Collegamento \"<xliff:g id="NAME">%s</xliff:g>\" già presente."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Seleziona collegamento"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Seleziona cartella"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Tutte le applicazioni"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Home"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Aggiungi"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Sfondo"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Cerca"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Notifiche"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gesti"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Impostazioni"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"aggiungere scorciatorie"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Consente a un\'applicazione di aggiungere scorciatoie automaticamente."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"eliminare scorciatoie"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Consente a un\'applicazione di rimuovere scorciatoie automaticamente."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"leggere impostazioni e scorciatoie in Home"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Consente a un\'applicazione di leggere le impostazioni e le scorciatoie in Home."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"creare impostazioni e scorciatoie in Home"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Consente a un\'applicazione di modificare le impostazioni e le scorciatoie in Home."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Ricerca Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Errore durante il caricamento del widget"</string>
+</resources>
diff --git a/res/values-ja/strings.xml b/res/values-ja/strings.xml
new file mode 100644
index 0000000..2d8cc6b
--- /dev/null
+++ b/res/values-ja/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"ランチャー"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android Core Apps"</string>
+ <string name="folder_name" msgid="4588446541914685904">"フォルダ"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"壁紙を選択"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"壁紙に設定"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"壁紙"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"アプリケーションがインストールされていません。"</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"設定..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"フォルダ名"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"フォルダ名を変更"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"キャンセル"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"ホーム画面に追加"</string>
+ <string name="group_applications" msgid="4118484163419674240">"アプリケーション"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"ショートカット"</string>
+ <string name="group_search" msgid="5905328940867162196">"検索"</string>
+ <string name="group_folder" msgid="5143593791798929193">"新しいフォルダ"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"フォルダ"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"ウィジェット"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"壁紙"</string>
+ <string name="add_folder" msgid="3521088587367839879">"フォルダ"</string>
+ <string name="add_clock" msgid="2337943840175865746">"時計"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"写真フレーム"</string>
+ <string name="add_search" msgid="7104834713685095105">"検索"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"ホーム画面に空きスペースがありません。"</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"ショートカット「<xliff:g id="NAME">%s</xliff:g>」を作成しました。"</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"ショートカット「<xliff:g id="NAME">%s</xliff:g>」を削除しました。"</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"ショートカット「<xliff:g id="NAME">%s</xliff:g>」は既に存在します。"</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"ショートカットを選択"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"フォルダの選択"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"すべてのアプリケーション"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"ホーム"</string>
+ <string name="menu_add" msgid="3065046628354640854">"追加"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"壁紙"</string>
+ <string name="menu_search" msgid="4826514464423239041">"検索"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"通知"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"ジェスチャー"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"設定"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"ショートカットのインストール"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"ユーザー操作なしでショートカットの追加をアプリケーションに許可します。"</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"ショートカットのアンインストール"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"ユーザー操作なしでショートカットの削除をアプリケーションに許可します。"</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"ホーム設定とショートカットの読み取り"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"ホームの設定とショートカットの読み取りをアプリケーションに許可します。"</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"ホームの設定とショートカットの書き込み"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"ホームの設定とショートカットの変更をアプリケーションに許可します。"</string>
+ <string name="search_hint" msgid="6974176141372467453">"Google検索"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"ウィジェットを表示できません"</string>
+</resources>
diff --git a/res/values-ko/strings.xml b/res/values-ko/strings.xml
new file mode 100644
index 0000000..91718b1
--- /dev/null
+++ b/res/values-ko/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android Core 애플리케이션"</string>
+ <string name="folder_name" msgid="4588446541914685904">"폴더"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"배경화면 선택"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"배경화면 설정"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"배경화면"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"휴대전화에 설치되어 있지 않은 응용프로그램입니다."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"구성..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"폴더 이름"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"폴더 이름 바꾸기"</string>
+ <string name="rename_action" msgid="6016003384693240896">"확인"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"취소"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"홈 화면에 추가"</string>
+ <string name="group_applications" msgid="4118484163419674240">"응용프로그램"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"바로가기"</string>
+ <string name="group_search" msgid="5905328940867162196">"검색"</string>
+ <string name="group_folder" msgid="5143593791798929193">"새 폴더"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"폴더"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"위젯"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"배경화면"</string>
+ <string name="add_folder" msgid="3521088587367839879">"폴더"</string>
+ <string name="add_clock" msgid="2337943840175865746">"시계"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"사진 프레임"</string>
+ <string name="add_search" msgid="7104834713685095105">"검색"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"홈 화면에 더 이상 공간이 없습니다."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"바로가기(\'<xliff:g id="NAME">%s</xliff:g>\')가 생성되었습니다."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"바로가기(\'<xliff:g id="NAME">%s</xliff:g>\')가 삭제되었습니다."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"바로가기(\'<xliff:g id="NAME">%s</xliff:g>\')가 이미 있습니다."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"바로가기 선택"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"폴더 선택"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"모든 응용프로그램"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"홈"</string>
+ <string name="menu_add" msgid="3065046628354640854">"추가"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"배경화면"</string>
+ <string name="menu_search" msgid="4826514464423239041">"검색"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"알림"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"동작"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"설정"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"바로가기 설치"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"응용프로그램이 사용자의 작업 없이 바로가기를 추가할 수 있도록 합니다."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"바로가기 제거"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"응용프로그램이 사용자의 작업 없이 바로가기를 삭제할 수 있도록 합니다."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"홈 설정 및 바로가기 읽기"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"응용프로그램이 홈에 있는 설정 및 바로가기를 읽을 수 있도록 합니다."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"홈 설정 및 바로가기 쓰기"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"응용프로그램이 홈에 있는 설정 및 바로가기를 변경할 수 있도록 합니다."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Google 검색"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"위젯을 로드하는 중 문제가 발생했습니다."</string>
+</resources>
diff --git a/res/values-land/dimens.xml b/res/values-land/dimens.xml
new file mode 100644
index 0000000..d2d31c2
--- /dev/null
+++ b/res/values-land/dimens.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <dimen name="workspace_cell_width">106dip</dimen>
+ <dimen name="workspace_cell_height">74dip</dimen>
+ <dimen name="search_widget_inset">19dip</dimen>
+ <dimen name="gesture_thumbnail_inset">8dip</dimen>
+ <dimen name="gesture_thumbnail_size">64dip</dimen>
+</resources>
diff --git a/res/values-nb/strings.xml b/res/values-nb/strings.xml
new file mode 100644
index 0000000..2208898
--- /dev/null
+++ b/res/values-nb/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Utskytingsrampe"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android-kjerneapplikasjoner"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Mappe"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Velg bakgrunnsbilde fra"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Velg bakgrunnsbilde"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Bakgrunner"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Applikasjonen er ikke installert."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Konfigurer"</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Mappenavn"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Gi nytt navn til mappe"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Avbryt"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Legg til skrivebord"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Applikasjoner"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Snarveier"</string>
+ <string name="group_search" msgid="5905328940867162196">"Søk"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Ny mappe"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Mapper"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Skrivebordselementer"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Bakgrunner"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Mappe"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Klokke"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Bilderamme"</string>
+ <string name="add_search" msgid="7104834713685095105">"Søk"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Ikke nok plass på skrivebordet."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Opprettet snarveien «<xliff:g id="NAME">%s</xliff:g>»."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Fjernet snarveien «<xliff:g id="NAME">%s</xliff:g>»."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Snarveien «<xliff:g id="NAME">%s</xliff:g>» fins allerede."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Velg snarvei"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Velg mappe"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Alle programmer"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Startsiden"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Legg til"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Bakgrunnsbilde"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Søk"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Varslinger"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Bevegelser"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Innstillinger"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"installere snarveier"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Lar applikasjonen legge til snarveier uten å involvere brukeren."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"avinstallere snarveier"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Lar applikasjonen fjerne snarveier uten å involvere brukeren."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"lese skrivebordsinnstillinger og -snarveier"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Lar applikasjonen lese innstillinger og snarveier fra skrivebordet."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"skrive skrivebordsinnstillinger og -snarveier"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Lar applikasjonen endre innstillinger og snarveier på skrivebordet."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Google-søk"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Problem under lasting av gadget"</string>
+</resources>
diff --git a/res/values-nl/strings.xml b/res/values-nl/strings.xml
new file mode 100644
index 0000000..3a69066
--- /dev/null
+++ b/res/values-nl/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android-kerntoepassingen"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Map"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Achtergrond selecteren in"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Achtergrond instellen"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Achtergronden"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Deze toepassing is niet geïnstalleerd op uw telefoon."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Configureren..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Mapnaam"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Naam van map wijzigen"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Annuleren"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Toevoegen aan startpagina"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Toepassingen"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Sneltoetsen"</string>
+ <string name="group_search" msgid="5905328940867162196">"Zoeken"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Nieuwe map"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Mappen"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widgets"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Achtergronden"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Map"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Klok"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Fotolijstje"</string>
+ <string name="add_search" msgid="7104834713685095105">"Zoeken"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Er is geen ruimte meer op dit startscherm."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Snelkoppeling \'<xliff:g id="NAME">%s</xliff:g>\' is gemaakt."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Snelkoppeling \'<xliff:g id="NAME">%s</xliff:g>\' is verwijderd."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Snelkoppeling \'<xliff:g id="NAME">%s</xliff:g>\' bestaat al."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Snelkoppeling selecteren"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Map selecteren"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Alle toepassingen"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Startpagina"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Toevoegen"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Achtergrond"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Zoeken"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Meldingen"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gebaren"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Instellingen"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"snelkoppelingen installeren"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Een toepassing toestaan om snelkoppelingen toe te voegen zonder tussenkomst van de gebruiker."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"snelkoppelingen verwijderen"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Een toepassing toestaan om snelkoppelingen te verwijderen zonder tussenkomst van de gebruiker."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"instellingen en snelkoppelingen voor de startpagina lezen"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Hiermee kan een toepassing de instellingen en snelkoppelingen op de startpagina lezen."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"instellingen en snelkoppelingen voor de startpagina schrijven"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Hiermee kan een toepassing de instellingen en snelkoppelingen op de startpagina wijzigen."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Google Zoeken"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Probleem bij het laden van widget"</string>
+</resources>
diff --git a/res/values-pl/strings.xml b/res/values-pl/strings.xml
new file mode 100644
index 0000000..cc9306b
--- /dev/null
+++ b/res/values-pl/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Program uruchamiający"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Aplikacje główne systemu Android"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Folder"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Wybierz tapetę"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Ustaw tapetę"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Tapety"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Aplikacja nie jest zainstalowana w telefonie."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Konfiguruj..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Nazwa folderu"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Zmień nazwę folderu"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Anuluj"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Dodaj do strony głównej"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Aplikacje"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Skróty"</string>
+ <string name="group_search" msgid="5905328940867162196">"Wyszukiwarka"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Nowy folder"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Foldery"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widżety"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Tapety"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Folder"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Zegar"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Ramka obrazu"</string>
+ <string name="add_search" msgid="7104834713685095105">"Wyszukiwarka"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Brak miejsca na tej stronie głównej"</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Skrót „<xliff:g id="NAME">%s</xliff:g>” został utworzony."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Skrót „<xliff:g id="NAME">%s</xliff:g>” został usunięty."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Skrót „<xliff:g id="NAME">%s</xliff:g>” już istnieje."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Wybierz skrót"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Wybierz folder"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Wszystkie aplikacje"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Ekran główny"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Dodaj"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Tapeta"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Szukaj"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Powiadomienia"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gesty"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Ustawienia"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"zainstaluj skróty"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Umożliwia aplikacji dodawanie skrótów bez interwencji użytkownika."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"odinstaluj skróty"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Umożliwia aplikacji usuwanie skrótów bez interwencji użytkownika."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"odczytywanie ustawień i skrótów strony głównej"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Umożliwia aplikacji odczytywanie ustawień i skrótów strony głównej."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"zapisywanie ustawień i skrótów strony głównej"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Umożliwia aplikacji zmianę ustawień i skrótów strony głównej."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Szukaj w Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Problem podczas ładowania widżetu"</string>
+</resources>
diff --git a/res/values-port/dimens.xml b/res/values-port/dimens.xml
new file mode 100644
index 0000000..65a3fd3
--- /dev/null
+++ b/res/values-port/dimens.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <dimen name="workspace_cell_width">80dip</dimen>
+ <dimen name="workspace_cell_height">100dip</dimen>
+</resources>
diff --git a/res/values-pt-rPT/strings.xml b/res/values-pt-rPT/strings.xml
new file mode 100644
index 0000000..895e945
--- /dev/null
+++ b/res/values-pt-rPT/strings.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Aplicações Principais do Android"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Pasta"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Seleccionar imagem de fundo a partir de"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Definir imagem de fundo"</string>
+ <!-- no translation found for pick_wallpaper (5630222540525626723) -->
+ <skip />
+ <string name="activity_not_found" msgid="3571057450431950427">"A aplicação não está instalada no telefone."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Configurar..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Nome da pasta"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Mudar o nome da pasta"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Cancelar"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Adicionar ao ecrã principal"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Aplicações"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Atalhos"</string>
+ <string name="group_search" msgid="5905328940867162196">"Pesquisar"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Nova pasta"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Pastas"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widgets"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Imagens de fundo"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Pasta"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Relógio"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Moldura de imagem"</string>
+ <string name="add_search" msgid="7104834713685095105">"Pesquisar"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Não existe espaço suficiente neste ecrã principal."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"O atalho \"<xliff:g id="NAME">%s</xliff:g>\" foi criado."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"O atalho \"<xliff:g id="NAME">%s</xliff:g>\" foi removido."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"O atalho \"<xliff:g id="NAME">%s</xliff:g>\" já existe."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Seleccione o atalho"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Seleccione a pasta"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Todas as aplicações"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Página inicial"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Adicionar"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Imagem de fundo"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Pesquisar"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Notificações"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gestos"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Definições"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"instalar atalhos"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Permite que uma aplicação adicione atalhos sem a intervenção do utilizador."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"desinstalar atalhos"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Permite que uma aplicação remova atalhos sem a intervenção do utilizador."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"ler definições e atalhos do ecrã principal"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Permite que uma aplicação leia as definições e os atalhos do ecrã principal."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"escrever definições e atalhos do ecrã principal"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Permite que uma aplicação altere as definições e os atalhos do ecrã principal."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Pesquisa do Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Erro ao carregar o widget"</string>
+</resources>
diff --git a/res/values-pt/strings.xml b/res/values-pt/strings.xml
new file mode 100644
index 0000000..003927d
--- /dev/null
+++ b/res/values-pt/strings.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Principais aplicativos do Android"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Pasta"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Selecionar papel de parede de"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Definir papel de parede"</string>
+ <!-- no translation found for pick_wallpaper (5630222540525626723) -->
+ <skip />
+ <string name="activity_not_found" msgid="3571057450431950427">"O aplicativo não está instalado no seu telefone."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Configurar..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Nome da pasta"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Renomear pasta"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Cancelar"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Adicionar à tela da Página inicial"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Aplicativos"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Atalhos"</string>
+ <string name="group_search" msgid="5905328940867162196">"Pesquisar"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Nova pasta"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Pastas"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widgets"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Papéis de parede"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Pasta"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Relógio"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Frame da imagem"</string>
+ <string name="add_search" msgid="7104834713685095105">"Pesquisar"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Não há mais espaço nesta tela da Página inicial."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Atalho \"<xliff:g id="NAME">%s</xliff:g>\" criado."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"O atalho \"<xliff:g id="NAME">%s</xliff:g>\" foi removido."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"O atalho \"<xliff:g id="NAME">%s</xliff:g>\" já existe."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Selecionar atalho"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Selecionar pasta"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Todos os aplicativos"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Página inicial"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Adicionar"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Papel de parede"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Pesquisar"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Notificações"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gestos"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Configurações"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"instalar atalhos"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Permite que um aplicativo adicione os atalhos sem a intervenção do usuário."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"desinstalar atalhos"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Permite que um aplicativo remova os atalhos sem a intervenção do usuário."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"ler configurações e atalhos da Página inicial"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Permite que um aplicativo leia as configurações e atalhos na Página inicial."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"gravar configurações e atalhos da Página inicial"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Permite que um aplicativo altere as configurações e atalhos na Página inicial."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Pesquisa do Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Problema ao carregar o widget"</string>
+</resources>
diff --git a/res/values-ru/strings.xml b/res/values-ru/strings.xml
new file mode 100644
index 0000000..7542fdb
--- /dev/null
+++ b/res/values-ru/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Основные приложения Android"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Папка"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Выбрать обои из:"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Установить обои"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Обои"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Приложение не установлено на телефоне."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Настроить..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Название папки"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Переименовать папку"</string>
+ <string name="rename_action" msgid="6016003384693240896">"ОК"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Отмена"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Добавить на главный экран"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Приложения"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Ярлыки"</string>
+ <string name="group_search" msgid="5905328940867162196">"Поиск"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Новая папка"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Папки"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Виджеты"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Обои"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Папка"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Часы"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Рамка фотографии"</string>
+ <string name="add_search" msgid="7104834713685095105">"Поиск"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"На этом главном экране нет свободного места."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Ярлык \"<xliff:g id="NAME">%s</xliff:g>\" создан"</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Ярлык \"<xliff:g id="NAME">%s</xliff:g>\" удален."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Ярлык \"<xliff:g id="NAME">%s</xliff:g>\" уже существует."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Выберите ярлык"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Выбор папки"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Все приложения"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Главная"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Добавить"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Обои"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Поиск"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Уведомления"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Жесты"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Настройки"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"устанавливать ярлыки"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Позволяет приложению добавлять ярлыки без вмешательства пользователя"</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"удалять ярлыки"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Позволяет приложению удалять ярлыки без участия пользователя"</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"считывать настройки и ярлыки главного экрана"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Позволяет приложению считывать настройки и ярлыки на главном экране."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"изменять настройки и ярлыки главного экрана"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Позволяет приложению изменять настройки и ярлыки на главном экране."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Поиск Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Не удалось загрузить виджет"</string>
+</resources>
diff --git a/res/values-sv/strings.xml b/res/values-sv/strings.xml
new file mode 100644
index 0000000..efc9227
--- /dev/null
+++ b/res/values-sv/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Startbild"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android Core Apps"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Mapp"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Välj bakgrund från"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Ange bakgrund"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Bakgrundsbilder"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Programmet är inte installerat på din telefon."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Konfigurera..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Mappnamn"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Byt namn på mapp"</string>
+ <string name="rename_action" msgid="6016003384693240896">"OK"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"Avbryt"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Lägg till på startsidan"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Program"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Genvägar"</string>
+ <string name="group_search" msgid="5905328940867162196">"Sök"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Ny mapp"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Mappar"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widgetar"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Bakgrundsbilder"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Mapp"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Klocka"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Bildram"</string>
+ <string name="add_search" msgid="7104834713685095105">"Sök"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Det finns inte plats för mer på den här startsidan."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"Genvägen \"<xliff:g id="NAME">%s</xliff:g>\" har skapats."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"Genvägen \"<xliff:g id="NAME">%s</xliff:g>\" har tagits bort."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"Genvägen \"<xliff:g id="NAME">%s</xliff:g>\" finns redan."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Välj genväg"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Välj mapp"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Alla program"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Startsida"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Lägg till"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Bakgrund"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Sök"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Aviseringar"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Gester"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Inställningar"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"installera genvägar"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Tillåter att ett program lägger till genvägar utan åtgärd från användaren."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"avinstallera genvägar"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Tillåter att ett program tar bort genvägar utan åtgärd från användaren."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"läsa inställningar och genvägar för startsidan"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Tillåter att ett program läser inställningar och genvägar på startsidan."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"skriva inställningar och genvägar för startsidan"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Tillåter att ett program ändrar inställningar och genvägar på startsidan."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Sök på Google"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Det gick inte att läsa in widgeten"</string>
+</resources>
diff --git a/res/values-tr/strings.xml b/res/values-tr/strings.xml
new file mode 100644
index 0000000..5e823ed
--- /dev/null
+++ b/res/values-tr/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"Launcher"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android Core Apps"</string>
+ <string name="folder_name" msgid="4588446541914685904">"Klasör"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"Buradan duvar kağıdını seçin:"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"Duvar kağıdını ayarla"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"Duvar Kağıtları"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"Uygulama telefonunuza yüklenmemiş."</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"Yapılandır..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"Klasör adı"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"Klasörü yeniden adlandır"</string>
+ <string name="rename_action" msgid="6016003384693240896">"Tamam"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"İptal"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"Ana ekrana ekle"</string>
+ <string name="group_applications" msgid="4118484163419674240">"Uygulamalar"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"Kısayollar"</string>
+ <string name="group_search" msgid="5905328940867162196">"Arama"</string>
+ <string name="group_folder" msgid="5143593791798929193">"Yeni klasör"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"Klasörler"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"Widget\'lar"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"Duvar Kağıtları"</string>
+ <string name="add_folder" msgid="3521088587367839879">"Klasör"</string>
+ <string name="add_clock" msgid="2337943840175865746">"Saat"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"Resim çerçevesi"</string>
+ <string name="add_search" msgid="7104834713685095105">"Arama"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"Bu Ana ekranda başka yer yok."</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"\"<xliff:g id="NAME">%s</xliff:g>\" kısayolu oluşturuldu."</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"\"<xliff:g id="NAME">%s</xliff:g>\" kısayolu kaldırıldı."</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"\"<xliff:g id="NAME">%s</xliff:g>\" kısayolu zaten var."</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"Kısayolu seçin"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"Klasörü seçin"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"Tüm uygulamalar"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"Ana Sayfa"</string>
+ <string name="menu_add" msgid="3065046628354640854">"Ekle"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"Duvar Kağıdı"</string>
+ <string name="menu_search" msgid="4826514464423239041">"Ara"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"Bildirimler"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"Hareketler"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"Ayarlar"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"kısayolları yükle"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"Bir uygulamaya, kısayolları kullanıcı müdahale etmeden ekleme izni verir."</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"kısayolları kaldır"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"Bir uygulamaya, kısayolları kullanıcı müdahale etmeden kaldırma izni verir."</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"Ana Sayfa ayarlarını ve kısayollarını oku"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"Bir uygulamaya Ana Sayfadaki ayarları ve kısayolları okuma izni verir."</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"Ana Sayfa ayarlarını ve kısayollarını yaz"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"Bir uygulamaya Ana Sayfadaki ayarları ve kısayolları değiştirme izni verir."</string>
+ <string name="search_hint" msgid="6974176141372467453">"Google Arama"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"Widget yüklenirken sorun oluştu"</string>
+</resources>
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
new file mode 100644
index 0000000..98eb170
--- /dev/null
+++ b/res/values-zh-rCN/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"启动程序"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android 核心应用程序"</string>
+ <string name="folder_name" msgid="4588446541914685904">"文件夹"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"选择壁纸来源"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"设置壁纸"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"壁纸"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"您的手机上未安装应用程序。"</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"配置..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"文件夹名称"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"重命名文件夹"</string>
+ <string name="rename_action" msgid="6016003384693240896">"确定"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"取消"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"添加到主屏幕"</string>
+ <string name="group_applications" msgid="4118484163419674240">"应用程序"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"快捷方式"</string>
+ <string name="group_search" msgid="5905328940867162196">"搜索"</string>
+ <string name="group_folder" msgid="5143593791798929193">"新建文件夹"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"文件夹"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"窗口小部件"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"壁纸"</string>
+ <string name="add_folder" msgid="3521088587367839879">"文件夹"</string>
+ <string name="add_clock" msgid="2337943840175865746">"时钟"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"相框"</string>
+ <string name="add_search" msgid="7104834713685095105">"搜索"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"此主屏幕上已没有空间。"</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"已创建“<xliff:g id="NAME">%s</xliff:g>”快捷方式。"</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"已删除“<xliff:g id="NAME">%s</xliff:g>”快捷方式。"</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"“<xliff:g id="NAME">%s</xliff:g>”快捷方式已存在。"</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"选择快捷方式"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"选择文件夹"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"所有应用程序"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"主屏幕"</string>
+ <string name="menu_add" msgid="3065046628354640854">"添加"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"壁纸"</string>
+ <string name="menu_search" msgid="4826514464423239041">"搜索"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"通知"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"手势"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"设置"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"安装快捷方式"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"允许应用程序在没有用户介入的情况下添加快捷方式。"</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"卸载快捷方式"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"允许应用程序在没有用户介入的情况下删除快捷方式。"</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"读取主屏幕的设置和快捷方式"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"允许应用程序读取主屏幕的设置和快捷方式。"</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"写入主屏幕的设置和快捷方式"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"允许应用程序更改主屏幕的设置和快捷方式。"</string>
+ <string name="search_hint" msgid="6974176141372467453">"Google 搜索"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"载入窗口小部件时出现问题"</string>
+</resources>
diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml
new file mode 100644
index 0000000..8d3d8a0
--- /dev/null
+++ b/res/values-zh-rTW/strings.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright (C) 2009 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 xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <string name="application_name" msgid="8424725141379931883">"發射器"</string>
+ <string name="uid_name" msgid="3371120195364560632">"Android 核心應用程式"</string>
+ <string name="folder_name" msgid="4588446541914685904">"資料夾"</string>
+ <string name="chooser_wallpaper" msgid="5988031014201479733">"從…選取桌布"</string>
+ <string name="wallpaper_instructions" msgid="4215640646180727542">"設定桌布"</string>
+ <string name="pick_wallpaper" msgid="5630222540525626723">"桌布"</string>
+ <string name="activity_not_found" msgid="3571057450431950427">"應用程式未安裝到手機。"</string>
+ <string name="configure_wallpaper" msgid="2820186271419674623">"設定..."</string>
+ <string name="rename_folder_label" msgid="5646236631298452787">"資料夾名稱"</string>
+ <string name="rename_folder_title" msgid="4544573104191526550">"重新命名資料夾"</string>
+ <string name="rename_action" msgid="6016003384693240896">"確定"</string>
+ <string name="cancel_action" msgid="3811860427489435048">"取消"</string>
+ <string name="menu_item_add_item" msgid="6233177331075781114">"新增至首頁畫面"</string>
+ <string name="group_applications" msgid="4118484163419674240">"應用程式"</string>
+ <string name="group_shortcuts" msgid="9133529424900391877">"捷徑"</string>
+ <string name="group_search" msgid="5905328940867162196">"搜尋"</string>
+ <string name="group_folder" msgid="5143593791798929193">"新資料夾"</string>
+ <string name="group_live_folders" msgid="2664945399140647217">"資料夾"</string>
+ <string name="group_widgets" msgid="6704978494073105844">"小工具"</string>
+ <string name="group_wallpapers" msgid="1568191644272224858">"桌布"</string>
+ <string name="add_folder" msgid="3521088587367839879">"資料夾"</string>
+ <string name="add_clock" msgid="2337943840175865746">"時鐘"</string>
+ <string name="add_photo_frame" msgid="3154058437359487954">"相框"</string>
+ <string name="add_search" msgid="7104834713685095105">"搜尋"</string>
+ <string name="out_of_space" msgid="8365249326091984698">"首頁已無空間"</string>
+ <string name="shortcut_installed" msgid="7071557296331322355">"已建立「<xliff:g id="NAME">%s</xliff:g>」捷徑。"</string>
+ <string name="shortcut_uninstalled" msgid="2129499669449749995">"已移除「<xliff:g id="NAME">%s</xliff:g>」捷徑。"</string>
+ <string name="shortcut_duplicate" msgid="4757756326465060694">"「<xliff:g id="NAME">%s</xliff:g>」捷徑已經存在。"</string>
+ <string name="title_select_shortcut" msgid="2858897527672831763">"選取捷徑"</string>
+ <string name="title_select_live_folder" msgid="3753447798805166749">"選取資料夾"</string>
+ <string name="all_apps_button_label" msgid="3953036962111614813">"所有應用程式"</string>
+ <string name="all_apps_home_button_label" msgid="1022222300329398558">"主螢幕"</string>
+ <string name="menu_add" msgid="3065046628354640854">"新增"</string>
+ <string name="menu_wallpaper" msgid="5837429080911269832">"桌布"</string>
+ <string name="menu_search" msgid="4826514464423239041">"搜尋"</string>
+ <string name="menu_notifications" msgid="6424587053194766192">"通知"</string>
+ <string name="menu_gestures" msgid="514678675575912237">"觸控動作"</string>
+ <string name="menu_settings" msgid="6233960148378443661">"設定"</string>
+ <string name="permlab_install_shortcut" msgid="1201690825493376489">"安裝捷徑"</string>
+ <string name="permdesc_install_shortcut" msgid="7429365847558984148">"允許應用程式自動新增快速鍵。"</string>
+ <string name="permlab_uninstall_shortcut" msgid="7696645932555926449">"解除安裝捷徑"</string>
+ <string name="permdesc_uninstall_shortcut" msgid="959972195916090900">"允許應用程式自動移除捷徑。"</string>
+ <string name="permlab_read_settings" msgid="3452408290738106747">"讀取首頁設定和捷徑"</string>
+ <string name="permdesc_read_settings" msgid="8377434937176025492">"允許應用程式讀取首頁中的設定和捷徑。"</string>
+ <string name="permlab_write_settings" msgid="1360567537236705628">"寫入首頁設定和捷徑"</string>
+ <string name="permdesc_write_settings" msgid="1098648778383349818">"允許應用程式變更首頁中的設定和捷徑。"</string>
+ <string name="search_hint" msgid="6974176141372467453">"Google 搜尋"</string>
+ <string name="gadget_error_text" msgid="8359351016167075858">"載入小工具時發生問題"</string>
+</resources>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
new file mode 100644
index 0000000..a0085bc
--- /dev/null
+++ b/res/values/attrs.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* Copyright 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.
+*/
+-->
+
+<resources>
+ <!-- Orientation of a widget. -->
+ <attr name="direction">
+ <!-- Vertical widget. -->
+ <enum name="vertical" value="0" />
+ <!-- Horizontal widget. -->
+ <enum name="horizontal" value="1" />
+ </attr>
+
+ <skip />
+
+ <!-- Workspace specific attributes. These attributes are used to customize
+ the workspace in XML files. -->
+ <declare-styleable name="Workspace">
+ <!-- The first screen the workspace should display. -->
+ <attr name="defaultScreen" format="integer" />
+ </declare-styleable>
+
+ <!-- CellLayout specific attributes. These attributes are used to customize
+ a CellLayout view in XML files. -->
+ <declare-styleable name="CellLayout">
+ <!-- The width of a single cell -->
+ <attr name="cellWidth" format="dimension" />
+ <!-- The height of a single cell -->
+ <attr name="cellHeight" format="dimension" />
+ <!-- Padding to apply at the start of the long axis -->
+ <attr name="longAxisStartPadding" format="dimension" />
+ <!-- Padding to apply at the end of the long axis -->
+ <attr name="longAxisEndPadding" format="dimension" />
+ <!-- Padding to apply at the start of the short axis -->
+ <attr name="shortAxisStartPadding" format="dimension" />
+ <!-- Padding to apply at the end of the short axis -->
+ <attr name="shortAxisEndPadding" format="dimension" />
+ <!-- Number of cells on the short axis of the CellLayout -->
+ <attr name="shortAxisCells" format="integer" />
+ <!-- Number of cells on the long axis of the CellLayout -->
+ <attr name="longAxisCells" format="integer" />
+ </declare-styleable>
+
+ <!-- DeleteZone specific attributes. These attributes are used to customize
+ a DeleteZone view in XML files. -->
+ <declare-styleable name="DeleteZone">
+ <!-- Orientation of the delete zone. -->
+ <attr name="direction" />
+ </declare-styleable>
+
+ <!-- HandleView specific attributes. These attributes are used to customize
+ a HandleView view in XML files. -->
+ <declare-styleable name="HandleView">
+ <!-- Orientation of the handle. -->
+ <attr name="direction" />
+ </declare-styleable>
+
+ <!-- XML attributes used by default_workspace.xml -->
+ <declare-styleable name="Favorite">
+ <attr name="className" format="string" />
+ <attr name="packageName" format="string" />
+ <attr name="screen" format="string" />
+ <attr name="x" format="string" />
+ <attr name="y" format="string" />
+ <attr name="spanX" format="string" />
+ <attr name="spanY" format="string" />
+ <attr name="icon" format="reference" />
+ <attr name="title" format="reference" />
+ <attr name="uri" format="string" />
+ </declare-styleable>
+</resources>
diff --git a/res/values/colors.xml b/res/values/colors.xml
new file mode 100644
index 0000000..9b9700f
--- /dev/null
+++ b/res/values/colors.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/* //device/apps/common/assets/res/any/colors.xml
+**
+** Copyright 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.
+*/
+-->
+<resources>
+ <color name="window_background">#FF191919</color>
+ <color name="grid_dark_background">#EB191919</color>
+ <color name="bubble_dark_background">#B2191919</color>
+ <color name="delete_color_filter">#A5FF0000</color>
+
+ <color name="appwidget_error_color">#FCCC</color>
+ <color name="snag_callout_color">#F444</color>
+
+ <color name="gesture_color">#ff0563c1</color>
+ <color name="uncertain_gesture_color">#ff848484</color>
+</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
new file mode 100644
index 0000000..e0ca384
--- /dev/null
+++ b/res/values/dimens.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<resources>
+ <dimen name="search_widget_inset">19dip</dimen>
+ <dimen name="gesture_thumbnail_inset">8dip</dimen>
+ <dimen name="gesture_thumbnail_size">64dip</dimen>
+ <dimen name="button_bar_height">56dip</dimen>
+</resources>
diff --git a/res/values/extra_wallpapers.xml b/res/values/extra_wallpapers.xml
new file mode 100644
index 0000000..9e0951c
--- /dev/null
+++ b/res/values/extra_wallpapers.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ * Copyright (C) 2009 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ -->
+
+<resources>
+ <string-array name="extra_wallpapers">
+ </string-array>
+</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
new file mode 100644
index 0000000..38f27c7
--- /dev/null
+++ b/res/values/strings.xml
@@ -0,0 +1,138 @@
+<?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.
+*/
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- General -->
+ <skip />
+ <!-- Application name -->
+ <string name="application_name">Launcher</string>
+ <!-- Name for all applications running as this uid. -->
+ <string name="uid_name">Android Core Apps</string>
+ <!-- Default folder name -->
+ <string name="folder_name">Folder</string>
+ <!-- Title of dialog that appears after user selects Wallpaper from menu -->
+ <string name="chooser_wallpaper">Select wallpaper from</string>
+ <!-- Button label on Wallpaper Gallery screen; user selects this button to set a specific wallpaper -->
+ <string name="wallpaper_instructions">Set wallpaper</string>
+ <!-- Option in "Select wallpaper from" dialog box -->
+ <string name="pick_wallpaper">Wallpapers</string>
+ <!-- Displayed when user selects a shortcut for an app that was uninstalled -->
+ <string name="activity_not_found">Application is not installed on your phone.</string>
+ <!-- List item for configuring the current wallpaper -->
+ <string name="configure_wallpaper">Configure...</string>
+
+ <!-- Folders -->
+ <skip />
+ <!-- Label of Folder name field in Rename folder dialog box -->
+ <string name="rename_folder_label">Folder name</string>
+ <!-- Title of dialog box -->
+ <string name="rename_folder_title">Rename folder</string>
+ <!-- Buttons in Rename folder dialog box -->
+ <string name="rename_action">OK</string>
+ <!-- Buttons in Rename folder dialog box -->
+ <string name="cancel_action">Cancel</string>
+
+ <!-- Shortcuts -->
+ <skip />
+ <!-- Title of dialog box -->
+ <string name="menu_item_add_item">Add to Home screen</string>
+ <!-- Options in "Add to Home" dialog box; Title of the group containing the list of all apps -->
+ <string name="group_applications">Applications</string>
+ <!-- Options in "Add to Home" dialog box; Title of the group containing the list of all shortcuts -->
+ <string name="group_shortcuts">Shortcuts</string>
+ <!-- Options in "Add to Home" dialog box; Title of the search gadget -->
+ <string name="group_search">Search</string>
+ <!-- Options in "Add to Home" dialog box; Title of the folder gadget -->
+ <string name="group_folder">New folder</string>
+ <!-- Options in "Add to Home" dialog box; Title of the group containing the list of all live folders -->
+ <string name="group_live_folders">Folders</string>
+ <!-- Options in "Add to Home" dialog box; Title of the group containing the list of all widgets/gadgets -->
+ <string name="group_widgets">Widgets</string>
+ <!-- Options in "Add to Home" dialog box; Title of the group containing the list of apps that can set the wallpaper-->
+ <string name="group_wallpapers">Wallpapers</string>
+ <!-- Options in "Add to Home" dialog box; Name of the Folder widget-->
+ <string name="add_folder">Folder</string>
+ <!-- Options in "Add to Home" dialog box; Name of the Clock widget-->
+ <string name="add_clock">Clock</string>
+ <!-- Options in "Add to Home" dialog box; Name of the Picture frame widget-->
+ <string name="add_photo_frame">Picture frame</string>
+ <!-- Options in "Add to Home" dialog box; Name of the global search widget-->
+ <string name="add_search">Search</string>
+ <!-- Error message when user has filled a home screen, possibly not used -->
+ <string name="out_of_space">No more room on this Home screen.</string>
+ <!-- Message displayed when a shortcut is created by an external application -->
+ <string name="shortcut_installed">Shortcut \"<xliff:g id="name" example="Browser">%s</xliff:g>\" created.</string>
+ <!-- Message displayed when a shortcut is uninstalled by an external application -->
+ <string name="shortcut_uninstalled">Shortcut \"<xliff:g id="name" example="Browser">%s</xliff:g>\" was removed.</string>
+ <!-- Message displayed when an external application attemps to create a shortcut that already exists -->
+ <string name="shortcut_duplicate">Shortcut \"<xliff:g id="name" example="Browser">%s</xliff:g>\" already exists.</string>
+
+ <!-- Title of dialog when user is selecting shortcut to add to homescreen -->
+ <string name="title_select_shortcut">Select shortcut</string>
+ <!-- Title of dialog when user is selecting live folder to add to homescreen -->
+ <string name="title_select_live_folder">Select folder</string>
+
+ <!-- All applications label for accessibilty (spoken when the button gets focus). -->
+ <string name="all_apps_button_label">All applications</string>
+ <!-- Label for button in all applications label to go back home (to the workspace / desktop)
+ for accessibilty (spoken when the button gets focus). -->
+ <string name="all_apps_home_button_label">Home</string>
+
+ <!-- Menus items: -->
+ <skip />
+ <!-- Verb, menu item used to add an item on the desktop -->
+ <string name="menu_add">Add</string>
+ <!-- Noun, menu item used to set the desktop's wallpaper -->
+ <string name="menu_wallpaper">Wallpaper</string>
+ <!-- Verb, menu item used to initiate global search -->
+ <string name="menu_search">Search</string>
+ <!-- Noun, menu item used to bring down the notifications shade -->
+ <string name="menu_notifications">Notifications</string>
+ <!-- Noun, menu item used to show the gestures settings -->
+ <string name="menu_gestures">Gestures</string>
+ <!-- Noun, menu item used to show the system settings -->
+ <string name="menu_settings">Settings</string>
+
+ <!-- Permissions: -->
+ <string name="permlab_install_shortcut">install shortcuts</string>
+ <string name="permdesc_install_shortcut">Allows an application to add
+ shortcuts without user intervention.</string>
+ <string name="permlab_uninstall_shortcut">uninstall shortcuts</string>
+ <string name="permdesc_uninstall_shortcut">Allows an application to remove
+ shortcuts without user intervention.</string>
+ <string name="permlab_read_settings">read Home settings and shortcuts</string>
+ <string name="permdesc_read_settings">Allows an application to read the settings and
+ shortcuts in Home.</string>
+ <string name="permlab_write_settings">write Home settings and shortcuts</string>
+ <string name="permdesc_write_settings">Allows an application to change the settings and
+ shortcuts in Home.</string>
+
+ <!-- Widgets: -->
+ <skip />
+
+ <!-- TODO: Determine if this can be removed.
+ This is the hint text shown in the search widget, before text is entered.
+ This translation SHOULD MATCH the string "search_hint" which is found in
+ GoogleSearch/res/values/strings.xml -->
+ <string name="search_hint">Google Search</string>
+
+ <!-- Text to show user in place of a gadget when we can't display it properly -->
+ <string name="gadget_error_text">Problem loading widget</string>
+
+</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
new file mode 100644
index 0000000..125a1be
--- /dev/null
+++ b/res/values/styles.xml
@@ -0,0 +1,68 @@
+<?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.
+*/
+-->
+
+<resources>
+ <style name="Theme" parent="android:Theme.Wallpaper">
+ <item name="android:windowNoTitle">true</item>
+ </style>
+
+ <style name="AnimationPreview">
+ <item name="android:windowEnterAnimation">@anim/fade_in_fast</item>
+ <item name="android:windowExitAnimation">@anim/fade_out_fast</item>
+ </style>
+
+ <style name="WorkspaceIcon">
+ <item name="android:textSize">13dip</item>
+ <item name="android:singleLine">true</item>
+ <item name="android:ellipsize">marquee</item>
+ <item name="android:shadowColor">#FF000000</item>
+ <item name="android:shadowRadius">2.0</item>
+ <item name="android:textColor">#FFF</item>
+ <item name="android:gravity">center_horizontal</item>
+ <item name="android:layout_width">fill_parent</item>
+ <item name="android:layout_height">fill_parent</item>
+ <item name="android:background">@drawable/shortcut_selector</item>
+ <item name="android:paddingLeft">5dip</item>
+ <item name="android:paddingRight">5dip</item>
+ </style>
+
+ <style name="WorkspaceIcon.Portrait">
+ <item name="android:drawablePadding">5dip</item>
+ <item name="android:paddingTop">4dip</item>
+ <item name="android:layout_marginLeft">3dip</item>
+ <item name="android:layout_marginRight">3dip</item>
+ <item name="android:layout_marginTop">13dip</item>
+ <item name="android:layout_marginBottom">8dip</item>
+ </style>
+
+ <style name="WorkspaceIcon.Landscape">
+ <item name="android:drawablePadding">3dip</item>
+ <item name="android:paddingTop">2dip</item>
+ <item name="android:layout_marginLeft">10dip</item>
+ <item name="android:layout_marginRight">10dip</item>
+ </style>
+
+ <style name="SearchButton" parent="@android:style/Widget.Button.Small">
+ <item name="android:paddingTop">7dip</item>
+ <item name="android:paddingBottom">9dip</item>
+ <item name="android:paddingLeft">10dip</item>
+ <item name="android:paddingRight">10dip</item>
+ </style>
+
+</resources>
diff --git a/res/xml/default_workspace.xml b/res/xml/default_workspace.xml
new file mode 100644
index 0000000..4213d36
--- /dev/null
+++ b/res/xml/default_workspace.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<favorites xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher2">
+
+ <!-- Left screen [1] -->
+ <favorite
+ launcher:packageName="com.android.camera"
+ launcher:className="com.android.camera.Camera"
+ launcher:screen="1"
+ launcher:x="1"
+ launcher:y="3" />
+
+ <favorite
+ launcher:packageName="com.cooliris.media"
+ launcher:className="com.cooliris.media.Gallery"
+ launcher:screen="1"
+ launcher:x="2"
+ launcher:y="3" />
+
+ <!-- Middle screen [2] -->
+ <search
+ launcher:screen="2"
+ launcher:x="0"
+ launcher:y="0" />
+
+ <favorite
+ launcher:packageName="com.android.contacts"
+ launcher:className="com.android.contacts.DialtactsActivity"
+ launcher:screen="2"
+ launcher:x="0"
+ launcher:y="3" />
+
+ <favorite
+ launcher:packageName="com.android.contacts"
+ launcher:className="com.android.contacts.DialtactsContactsEntryActivity"
+ launcher:screen="2"
+ launcher:x="1"
+ launcher:y="3" />
+
+ <favorite
+ launcher:packageName="com.android.browser"
+ launcher:className="com.android.browser.BrowserActivity"
+ launcher:screen="2"
+ launcher:x="2"
+ launcher:y="3" />
+
+ <favorite
+ launcher:packageName="com.google.android.apps.maps"
+ launcher:className="com.google.android.maps.MapsActivity"
+ launcher:screen="2"
+ launcher:x="3"
+ launcher:y="3" />
+
+ <favorite
+ launcher:packageName="com.android.mms"
+ launcher:className="com.android.mms.ui.ConversationList"
+ launcher:screen="2"
+ launcher:x="0"
+ launcher:y="2" />
+
+ <favorite
+ launcher:packageName="com.android.vending"
+ launcher:className="com.android.vending.AssetBrowserActivity"
+ launcher:screen="2"
+ launcher:x="3"
+ launcher:y="2" />
+
+ <!-- Right screen [3] -->
+
+ <appwidget
+ launcher:packageName="com.android.settings"
+ launcher:className="com.android.settings.widget.SettingsAppWidgetProvider"
+ launcher:screen="3"
+ launcher:x="0"
+ launcher:y="0"
+ launcher:spanX="4"
+ launcher:spanY="1" />
+
+ <favorite
+ launcher:packageName="com.google.android.gm"
+ launcher:className="com.google.android.gm.ConversationListActivityGmail"
+ launcher:screen="3"
+ launcher:x="1"
+ launcher:y="3" />
+
+ <favorite
+ launcher:packageName="com.google.android.talk"
+ launcher:className="com.google.android.talk.SigningInActivity"
+ launcher:screen="3"
+ launcher:x="2"
+ launcher:y="3" />
+</favorites>
diff --git a/src/com/android/launcher2/ActivityPicker.java b/src/com/android/launcher2/ActivityPicker.java
new file mode 100644
index 0000000..b6da08e
--- /dev/null
+++ b/src/com/android/launcher2/ActivityPicker.java
@@ -0,0 +1,405 @@
+/*
+ * Copyright (C) 2009 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.android.launcher2;
+
+import com.android.internal.app.AlertActivity;
+import com.android.internal.app.AlertController;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.Intent.ShortcutIconResource;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Resources;
+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.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.PaintDrawable;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Displays a list of all activities matching the incoming
+ * {@link android.content.Intent#EXTRA_INTENT} query, along with any injected items.
+ */
+public class ActivityPicker extends AlertActivity implements
+ DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
+
+ /**
+ * Adapter of items that are displayed in this dialog.
+ */
+ private PickAdapter mAdapter;
+
+ /**
+ * Base {@link android.content.Intent} used when building list.
+ */
+ private Intent mBaseIntent;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final Intent intent = getIntent();
+
+ // Read base intent from extras, otherwise assume default
+ Parcelable parcel = intent.getParcelableExtra(Intent.EXTRA_INTENT);
+ if (parcel instanceof Intent) {
+ mBaseIntent = (Intent) parcel;
+ } else {
+ mBaseIntent = new Intent(Intent.ACTION_MAIN, null);
+ mBaseIntent.addCategory(Intent.CATEGORY_DEFAULT);
+ }
+
+ // Create dialog parameters
+ AlertController.AlertParams params = mAlertParams;
+ params.mOnClickListener = this;
+ params.mOnCancelListener = this;
+
+ // Use custom title if provided, otherwise default window title
+ if (intent.hasExtra(Intent.EXTRA_TITLE)) {
+ params.mTitle = intent.getStringExtra(Intent.EXTRA_TITLE);
+ } else {
+ params.mTitle = getTitle();
+ }
+
+ // Build list adapter of pickable items
+ List<PickAdapter.Item> items = getItems();
+ mAdapter = new PickAdapter(this, items);
+ params.mAdapter = mAdapter;
+
+ setupAlert();
+ }
+
+ /**
+ * Handle clicking of dialog item by passing back
+ * {@link #getIntentForPosition(int)} in {@link #setResult(int, android.content.Intent)}.
+ */
+ public void onClick(DialogInterface dialog, int which) {
+ Intent intent = getIntentForPosition(which);
+ setResult(Activity.RESULT_OK, intent);
+ finish();
+ }
+
+ /**
+ * Handle canceled dialog by passing back {@link android.app.Activity#RESULT_CANCELED}.
+ */
+ public void onCancel(DialogInterface dialog) {
+ setResult(Activity.RESULT_CANCELED);
+ finish();
+ }
+
+ /**
+ * Build the specific {@link android.content.Intent} for a given list position. Convenience
+ * method that calls through to {@link PickAdapter.Item#getIntent(android.content.Intent)}.
+ */
+ protected Intent getIntentForPosition(int position) {
+ PickAdapter.Item item = (PickAdapter.Item) mAdapter.getItem(position);
+ return item.getIntent(mBaseIntent);
+ }
+
+ /**
+ * Build and return list of items to be shown in dialog. Default
+ * implementation mixes activities matching {@link #mBaseIntent} from
+ * {@link #putIntentItems(android.content.Intent, java.util.List)} with any injected items from
+ * {@link android.content.Intent#EXTRA_SHORTCUT_NAME}. Override this method in subclasses to
+ * change the items shown.
+ */
+ protected List<PickAdapter.Item> getItems() {
+ PackageManager packageManager = getPackageManager();
+ List<PickAdapter.Item> items = new ArrayList<PickAdapter.Item>();
+
+ // Add any injected pick items
+ final Intent intent = getIntent();
+ ArrayList<String> labels =
+ intent.getStringArrayListExtra(Intent.EXTRA_SHORTCUT_NAME);
+ ArrayList<ShortcutIconResource> icons =
+ intent.getParcelableArrayListExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
+
+ if (labels != null && icons != null && labels.size() == icons.size()) {
+ for (int i = 0; i < labels.size(); i++) {
+ String label = labels.get(i);
+ Drawable icon = null;
+
+ try {
+ // Try loading icon from requested package
+ ShortcutIconResource iconResource = icons.get(i);
+ Resources res = packageManager.getResourcesForApplication(
+ iconResource.packageName);
+ icon = res.getDrawable(res.getIdentifier(
+ iconResource.resourceName, null, null));
+ } catch (NameNotFoundException e) {
+ // Ignore
+ }
+
+ items.add(new PickAdapter.Item(this, label, icon));
+ }
+ }
+
+ // Add any intent items if base was given
+ if (mBaseIntent != null) {
+ putIntentItems(mBaseIntent, items);
+ }
+
+ return items;
+ }
+
+ /**
+ * Fill the given list with any activities matching the base {@link android.content.Intent}.
+ */
+ protected void putIntentItems(Intent baseIntent, List<PickAdapter.Item> items) {
+ PackageManager packageManager = getPackageManager();
+ List<ResolveInfo> list = packageManager.queryIntentActivities(baseIntent,
+ 0 /* no flags */);
+ Collections.sort(list, new ResolveInfo.DisplayNameComparator(packageManager));
+
+ final int listSize = list.size();
+ for (int i = 0; i < listSize; i++) {
+ ResolveInfo resolveInfo = list.get(i);
+ items.add(new PickAdapter.Item(this, packageManager, resolveInfo));
+ }
+ }
+
+ /**
+ * Adapter which shows the set of activities that can be performed for a
+ * given {@link android.content.Intent}.
+ */
+ protected static class PickAdapter extends BaseAdapter {
+
+ /**
+ * Item that appears in a {@link PickAdapter} list.
+ */
+ public static class Item {
+ protected static IconResizer sResizer;
+
+ protected IconResizer getResizer(Context context) {
+ if (sResizer == null) {
+ sResizer = new IconResizer(context);
+ }
+ return sResizer;
+ }
+
+ CharSequence label;
+ Drawable icon;
+ String packageName;
+ String className;
+ Bundle extras;
+
+ /**
+ * Create a list item from given label and icon.
+ */
+ Item(Context context, CharSequence label, Drawable icon) {
+ this.label = label;
+ this.icon = getResizer(context).createIconThumbnail(icon);
+ }
+
+ /**
+ * Create a list item and fill it with details from the given
+ * {@link android.content.pm.ResolveInfo} object.
+ */
+ Item(Context context, PackageManager pm, ResolveInfo resolveInfo) {
+ label = resolveInfo.loadLabel(pm);
+ if (label == null && resolveInfo.activityInfo != null) {
+ label = resolveInfo.activityInfo.name;
+ }
+
+ icon = getResizer(context).createIconThumbnail(resolveInfo.loadIcon(pm));
+ packageName = resolveInfo.activityInfo.applicationInfo.packageName;
+ className = resolveInfo.activityInfo.name;
+ }
+
+ Intent getIntent(Intent baseIntent) {
+ Intent intent = new Intent(baseIntent);
+ if (packageName != null && className != null) {
+ // Valid package and class, so fill details as normal intent
+ intent.setClassName(packageName, className);
+ if (extras != null) {
+ intent.putExtras(extras);
+ }
+ } else {
+ // No valid package or class, so treat as shortcut with label
+ intent.setAction(Intent.ACTION_CREATE_SHORTCUT);
+ intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
+ }
+ return intent;
+ }
+ }
+
+ private final LayoutInflater mInflater;
+
+ private List<Item> mItems;
+ private int mLayoutRes = R.layout.pick_item;
+
+ /**
+ * Create an adapter for the given items.
+ */
+ public PickAdapter(Context context, List<Item> items) {
+ mInflater = (LayoutInflater)
+ context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mItems = items;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public int getCount() {
+ return mItems.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getItem(int position) {
+ return mItems.get(position);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public long getItemId(int position) {
+ return position;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public View getView(int position, View convertView, ViewGroup parent) {
+ if (convertView == null) {
+ convertView = mInflater.inflate(mLayoutRes, parent, false);
+ }
+
+ Item item = (Item) getItem(position);
+ TextView textView = (TextView) convertView;
+ textView.setText(item.label);
+ textView.setCompoundDrawablesWithIntrinsicBounds(item.icon, null, null, null);
+
+ return convertView;
+ }
+ }
+
+ /**
+ * Utility class to resize icons to match default icon size. Code is mostly
+ * borrowed from Launcher.
+ */
+ private static class IconResizer {
+ private int mIconWidth = -1;
+ private int mIconHeight = -1;
+
+ private final Rect mOldBounds = new Rect();
+ private Canvas mCanvas = new Canvas();
+ private Resources mResources;
+
+ public IconResizer(Context context) {
+ mCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG,
+ Paint.FILTER_BITMAP_FLAG));
+
+ mResources = context.getResources();
+ mIconWidth = mIconHeight = (int) mResources.getDimension(
+ android.R.dimen.app_icon_size);
+ }
+
+ /**
+ * Returns a Drawable representing the thumbnail of the specified Drawable.
+ * The size of the thumbnail is defined by the dimension
+ * android.R.dimen.launcher_application_icon_size.
+ *
+ * This method is not thread-safe and should be invoked on the UI thread only.
+ *
+ * @param icon The icon to get a thumbnail of.
+ *
+ * @return A thumbnail for the specified icon or the icon itself if the
+ * thumbnail could not be created.
+ */
+ public Drawable createIconThumbnail(Drawable icon) {
+ int width = mIconWidth;
+ int height = mIconHeight;
+
+ if (icon == null) {
+ return null;
+ }
+
+ 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) {
+ if (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(mIconWidth, mIconHeight, c);
+ final Canvas canvas = mCanvas;
+ canvas.setBitmap(thumb);
+ // 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());
+ final int x = (mIconWidth - width) / 2;
+ final int y = (mIconHeight - height) / 2;
+ icon.setBounds(x, y, x + width, y + height);
+ icon.draw(canvas);
+ icon.setBounds(mOldBounds);
+ icon = new BitmapDrawable(mResources, thumb);
+ } else if (iconWidth < width && iconHeight < height) {
+ final Bitmap.Config c = Bitmap.Config.ARGB_8888;
+ final Bitmap thumb = Bitmap.createBitmap(mIconWidth, mIconHeight, c);
+ final Canvas canvas = mCanvas;
+ canvas.setBitmap(thumb);
+ mOldBounds.set(icon.getBounds());
+ final int x = (width - iconWidth) / 2;
+ final int y = (height - iconHeight) / 2;
+ icon.setBounds(x, y, x + iconWidth, y + iconHeight);
+ icon.draw(canvas);
+ icon.setBounds(mOldBounds);
+ icon = new BitmapDrawable(mResources, thumb);
+ }
+ }
+
+ return icon;
+ }
+ }
+}
diff --git a/src/com/android/launcher2/AddAdapter.java b/src/com/android/launcher2/AddAdapter.java
new file mode 100644
index 0000000..77f1f55
--- /dev/null
+++ b/src/com/android/launcher2/AddAdapter.java
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.BaseAdapter;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+
+/**
+ * Adapter showing the types of items that can be added to a {@link Workspace}.
+ */
+public class AddAdapter extends BaseAdapter {
+
+ private final LayoutInflater mInflater;
+
+ private final ArrayList<ListItem> mItems = new ArrayList<ListItem>();
+
+ public static final int ITEM_SHORTCUT = 0;
+ public static final int ITEM_APPWIDGET = 1;
+ public static final int ITEM_LIVE_FOLDER = 2;
+ public static final int ITEM_WALLPAPER = 3;
+
+ /**
+ * Specific item in our list.
+ */
+ public class ListItem {
+ public final CharSequence text;
+ public final Drawable image;
+ public final int actionTag;
+
+ public ListItem(Resources res, int textResourceId, int imageResourceId, int actionTag) {
+ text = res.getString(textResourceId);
+ if (imageResourceId != -1) {
+ image = res.getDrawable(imageResourceId);
+ } else {
+ image = null;
+ }
+ this.actionTag = actionTag;
+ }
+ }
+
+ public AddAdapter(Launcher launcher) {
+ super();
+
+ mInflater = (LayoutInflater) launcher.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+ // Create default actions
+ Resources res = launcher.getResources();
+
+ mItems.add(new ListItem(res, R.string.group_shortcuts,
+ R.drawable.ic_launcher_shortcut, ITEM_SHORTCUT));
+
+ mItems.add(new ListItem(res, R.string.group_widgets,
+ R.drawable.ic_launcher_appwidget, ITEM_APPWIDGET));
+
+ mItems.add(new ListItem(res, R.string.group_live_folders,
+ R.drawable.ic_launcher_folder, ITEM_LIVE_FOLDER));
+
+ mItems.add(new ListItem(res, R.string.group_wallpapers,
+ R.drawable.ic_launcher_wallpaper, ITEM_WALLPAPER));
+
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ListItem item = (ListItem) getItem(position);
+
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.add_list_item, parent, false);
+ }
+
+ TextView textView = (TextView) convertView;
+ textView.setTag(item);
+ textView.setText(item.text);
+ textView.setCompoundDrawablesWithIntrinsicBounds(item.image, null, null, null);
+
+ return convertView;
+ }
+
+ public int getCount() {
+ return mItems.size();
+ }
+
+ public Object getItem(int position) {
+ return mItems.get(position);
+ }
+
+ public long getItemId(int position) {
+ return position;
+ }
+
+}
diff --git a/src/com/android/launcher2/AllAppsList.java b/src/com/android/launcher2/AllAppsList.java
new file mode 100644
index 0000000..561b345
--- /dev/null
+++ b/src/com/android/launcher2/AllAppsList.java
@@ -0,0 +1,216 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Intent;
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+import android.util.Log;
+import android.os.Process;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+
+/**
+ * Stores the list of all applications for the all apps view.
+ */
+class AllAppsList {
+ public static final int DEFAULT_APPLICATIONS_NUMBER = 42;
+
+ /** The list off all apps. */
+ public ArrayList<ApplicationInfo> data = new ArrayList(DEFAULT_APPLICATIONS_NUMBER);
+ /** The list of apps that have been added since the last notify() call. */
+ public ArrayList<ApplicationInfo> added = new ArrayList(DEFAULT_APPLICATIONS_NUMBER);
+ /** The list of apps that have been removed since the last notify() call. */
+ public ArrayList<ApplicationInfo> removed = new ArrayList();
+ /** The list of apps that have been modified since the last notify() call. */
+ public ArrayList<ApplicationInfo> modified = new ArrayList();
+
+ /**
+ * Boring constructor.
+ */
+ public AllAppsList() {
+ }
+
+ /**
+ * Add the supplied ApplicationInfo objects to the list, and enqueue it into the
+ * list to broadcast when notify() is called.
+ */
+ public void add(ApplicationInfo info) {
+ data.add(info);
+ added.add(info);
+ }
+
+ public void clear() {
+ data.clear();
+ // TODO: do we clear these too?
+ added.clear();
+ removed.clear();
+ modified.clear();
+ }
+
+ public int size() {
+ return data.size();
+ }
+
+ public ApplicationInfo get(int index) {
+ return data.get(index);
+ }
+
+ /**
+ * Add the icons for the supplied apk called packageName.
+ */
+ public void addPackage(Context context, String packageName) {
+ final List<ResolveInfo> matches = findActivitiesForPackage(context, packageName);
+
+ if (matches.size() > 0) {
+ Utilities.BubbleText bubble = new Utilities.BubbleText(context);
+ for (ResolveInfo info : matches) {
+ ApplicationInfo item = AppInfoCache.cache(info, context, bubble);
+ data.add(item);
+ added.add(item);
+ }
+ }
+ }
+
+ /**
+ * Remove the apps for the given apk identified by packageName.
+ */
+ public void removePackage(String packageName) {
+ final List<ApplicationInfo> data = this.data;
+ for (int i=data.size()-1; i>=0; i--) {
+ ApplicationInfo info = data.get(i);
+ final ComponentName component = info.intent.getComponent();
+ if (packageName.equals(component.getPackageName())) {
+ removed.add(info);
+ data.remove(i);
+ }
+ }
+ // This is more aggressive than it needs to be.
+ AppInfoCache.flush();
+ }
+
+ /**
+ * Add and remove icons for this package which has been updated.
+ */
+ public void updatePackage(Context context, String packageName) {
+ final List<ResolveInfo> matches = findActivitiesForPackage(context, packageName);
+ if (matches.size() > 0) {
+ // Find disabled/removed activities and remove them from data and add them
+ // to the removed list.
+ for (int i=data.size()-1; i>=0; i--) {
+ final ApplicationInfo applicationInfo = data.get(i);
+ final ComponentName component = applicationInfo.intent.getComponent();
+ if (packageName.equals(component.getPackageName())) {
+ if (!findActivity(matches, component)) {
+ removed.add(applicationInfo);
+ AppInfoCache.remove(component);
+ data.remove(i);
+ }
+ }
+ }
+
+ // Find enabled activities and add them to the adapter
+ // Also updates existing activities with new labels/icons
+ Utilities.BubbleText bubble = new Utilities.BubbleText(context);
+ int count = matches.size();
+ for (int i=0; i<count; i++) {
+ final ResolveInfo info = matches.get(i);
+ ApplicationInfo applicationInfo = findApplicationInfoLocked(
+ info.activityInfo.applicationInfo.packageName,
+ info.activityInfo.name);
+ if (applicationInfo == null) {
+ applicationInfo = AppInfoCache.cache(info, context, bubble);
+ data.add(applicationInfo);
+ added.add(applicationInfo);
+ } else {
+ AppInfoCache.update(info, applicationInfo, context, bubble);
+ modified.add(applicationInfo);
+ }
+ }
+ }
+ }
+
+ /**
+ * Query the package manager for MAIN/LAUNCHER activities in the supplied package.
+ */
+ private static List<ResolveInfo> findActivitiesForPackage(Context context, String packageName) {
+ final PackageManager packageManager = context.getPackageManager();
+
+ final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
+ mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+
+ final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0);
+ final List<ResolveInfo> matches = new ArrayList<ResolveInfo>();
+
+ if (apps != null) {
+ // Find all activities that match the packageName
+ int count = apps.size();
+ for (int i = 0; i < count; i++) {
+ final ResolveInfo info = apps.get(i);
+ final ActivityInfo activityInfo = info.activityInfo;
+ if (packageName.equals(activityInfo.packageName)) {
+ matches.add(info);
+ }
+ }
+ }
+
+ return matches;
+ }
+
+ /**
+ * Returns whether <em>apps</em> contains <em>component</em>.
+ */
+ private static boolean findActivity(List<ResolveInfo> apps, ComponentName component) {
+ final String className = component.getClassName();
+ for (ResolveInfo info : apps) {
+ final ActivityInfo activityInfo = info.activityInfo;
+ if (activityInfo.name.equals(className)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Find an ApplicationInfo object for the given packageName and className.
+ */
+ private ApplicationInfo findApplicationInfoLocked(String packageName, String className) {
+ for (ApplicationInfo info: data) {
+ final ComponentName component = info.intent.getComponent();
+ if (packageName.equals(component.getPackageName())
+ && className.equals(component.getClassName())) {
+ return info;
+ }
+ }
+ return null;
+ }
+}
diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java
new file mode 100644
index 0000000..37ec15c
--- /dev/null
+++ b/src/com/android/launcher2/AllAppsView.java
@@ -0,0 +1,1421 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.PixelFormat;
+import android.graphics.Rect;
+import android.os.SystemClock;
+import android.renderscript.Allocation;
+import android.renderscript.Dimension;
+import android.renderscript.Element;
+import android.renderscript.ProgramFragment;
+import android.renderscript.ProgramStore;
+import android.renderscript.ProgramVertex;
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+import android.renderscript.Sampler;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.SimpleMesh;
+import android.renderscript.Type;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.SoundEffectConstants;
+import android.view.SurfaceHolder;
+import android.view.VelocityTracker;
+import android.view.View;
+import android.view.ViewConfiguration;
+import android.view.accessibility.AccessibilityEvent;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+
+
+public class AllAppsView extends RSSurfaceView
+ implements View.OnClickListener, View.OnLongClickListener, DragSource {
+ private static final String TAG = "Launcher.AllAppsView";
+
+ /** Bit for mLocks for when there are icons being loaded. */
+ private static final int LOCK_ICONS_PENDING = 1;
+
+ private static final int TRACKING_NONE = 0;
+ private static final int TRACKING_FLING = 1;
+ private static final int TRACKING_HOME = 2;
+
+ private static final int SELECTED_NONE = 0;
+ private static final int SELECTED_FOCUSED = 1;
+ private static final int SELECTED_PRESSED = 2;
+
+ private static final int SELECTION_NONE = 0;
+ private static final int SELECTION_ICONS = 1;
+ private static final int SELECTION_HOME = 2;
+
+ private Launcher mLauncher;
+ private DragController mDragController;
+
+ /** When this is 0, modifications are allowed, when it's not, they're not.
+ * TODO: What about scrolling? */
+ private int mLocks = LOCK_ICONS_PENDING;
+
+ private int mSlop;
+ private int mMaxFlingVelocity;
+
+ private Defines mDefines = new Defines();
+ private RenderScript mRS;
+ private RolloRS mRollo;
+ private ArrayList<ApplicationInfo> mAllAppsList;
+
+ /**
+ * True when we are using arrow keys or trackball to drive navigation
+ */
+ private boolean mArrowNavigation = false;
+ private boolean mStartedScrolling;
+
+ /**
+ * Used to keep track of the selection when AllAppsView loses window focus.
+ * One of the SELECTION_ constants.
+ */
+ private int mLastSelection;
+
+ /**
+ * Used to keep track of the selection when AllAppsView loses window focus
+ */
+ private int mLastSelectedIcon;
+
+ private VelocityTracker mVelocityTracker;
+ private int mTouchTracking;
+ private int mMotionDownRawX;
+ private int mMotionDownRawY;
+ private int mDownIconIndex = -1;
+ private int mCurrentIconIndex = -1;
+
+ private boolean mShouldGainFocus;
+
+ private boolean mZoomDirty = false;
+ private boolean mAnimateNextZoom;
+ private float mZoom;
+ private float mPosX;
+ private float mVelocity;
+ private AAMessage mMessageProc;
+
+ static class Defines {
+ public static final int ALLOC_PARAMS = 0;
+ public static final int ALLOC_STATE = 1;
+ public static final int ALLOC_ICON_IDS = 3;
+
+ public static final int COLUMNS_PER_PAGE = 4;
+ public static final int ROWS_PER_PAGE = 4;
+
+ public static final int ICON_TEXTURE_WIDTH_PX = 128;
+ public static final int ICON_TEXTURE_HEIGHT_PX = 128;
+
+ public int SCREEN_WIDTH_PX;
+ public int SCREEN_HEIGHT_PX;
+
+ public void recompute(int w, int h) {
+ SCREEN_WIDTH_PX = 480;
+ SCREEN_HEIGHT_PX = 800;
+ }
+ }
+
+ public AllAppsView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setFocusable(true);
+ setSoundEffectsEnabled(false);
+ getHolder().setFormat(PixelFormat.TRANSLUCENT);
+ final ViewConfiguration config = ViewConfiguration.get(context);
+ mSlop = config.getScaledTouchSlop();
+ mMaxFlingVelocity = config.getScaledMaximumFlingVelocity();
+
+ setOnClickListener(this);
+ setOnLongClickListener(this);
+ setZOrderOnTop(true);
+ getHolder().setFormat(PixelFormat.TRANSLUCENT);
+
+ mRS = createRenderScript(true);
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ destroyRenderScript();
+ }
+
+ /**
+ * If you have an attached click listener, View always plays the click sound!?!?
+ * Deal with sound effects by hand.
+ */
+ public void reallyPlaySoundEffect(int sound) {
+ boolean old = isSoundEffectsEnabled();
+ setSoundEffectsEnabled(true);
+ playSoundEffect(sound);
+ setSoundEffectsEnabled(old);
+ }
+
+ public AllAppsView(Context context, AttributeSet attrs, int defStyle) {
+ this(context, attrs);
+ }
+
+ public void setLauncher(Launcher launcher) {
+ mLauncher = launcher;
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ super.surfaceDestroyed(holder);
+ mRollo.mHasSurface = false;
+ // Without this, we leak mMessageCallback which leaks the context.
+ mRS.mMessageCallback = null;
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+ //long startTime = SystemClock.uptimeMillis();
+
+ super.surfaceChanged(holder, format, w, h);
+
+ if (mRollo == null) {
+ mRollo = new RolloRS();
+ mRollo.mHasSurface = true;
+ mRollo.init(getResources(), w, h);
+ if (mAllAppsList != null) {
+ mRollo.setApps(mAllAppsList);
+ }
+ if (mShouldGainFocus) {
+ gainFocus();
+ mShouldGainFocus = false;
+ }
+ } else {
+ mRollo.mHasSurface = true;
+ }
+ mRollo.dirtyCheck();
+ mRollo.resize(w, h);
+
+ mRS.mMessageCallback = mMessageProc = new AAMessage();
+
+ Resources res = getContext().getResources();
+ int barHeight = (int)res.getDimension(R.dimen.button_bar_height);
+
+ //long endTime = SystemClock.uptimeMillis();
+ //Log.d(TAG, "surfaceChanged took " + (endTime-startTime) + "ms");
+ }
+
+ @Override
+ public void onWindowFocusChanged(boolean hasWindowFocus) {
+ super.onWindowFocusChanged(hasWindowFocus);
+ if (mArrowNavigation) {
+ if (!hasWindowFocus) {
+ // Clear selection when we lose window focus
+ mLastSelectedIcon = mRollo.mState.selectedIconIndex;
+ mRollo.setHomeSelected(SELECTED_NONE);
+ mRollo.clearSelectedIcon();
+ mRollo.mState.save();
+ } else if (hasWindowFocus) {
+ if (mRollo.mState.iconCount > 0) {
+ if (mLastSelection == SELECTION_ICONS) {
+ int selection = mLastSelectedIcon;
+ final int firstIcon = Math.round(mPosX) *
+ Defines.COLUMNS_PER_PAGE;
+ if (selection < 0 || // No selection
+ selection < firstIcon || // off the top of the screen
+ selection >= mRollo.mState.iconCount || // past last icon
+ selection >= firstIcon + // past last icon on screen
+ (Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE)) {
+ selection = firstIcon;
+ }
+
+ // Select the first icon when we gain window focus
+ mRollo.selectIcon(selection, SELECTED_FOCUSED);
+ mRollo.mState.save();
+ } else if (mLastSelection == SELECTION_HOME) {
+ mRollo.setHomeSelected(SELECTED_FOCUSED);
+ mRollo.mState.save();
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
+ super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
+
+ if (!isVisible()) {
+ return;
+ }
+
+ if (gainFocus) {
+ if (mRollo != null && mRollo.mHasSurface) {
+ gainFocus();
+ } else {
+ mShouldGainFocus = true;
+ }
+ } else {
+ if (mRollo != null) {
+ if (mArrowNavigation) {
+ // Clear selection when we lose focus
+ mRollo.clearSelectedIcon();
+ mRollo.setHomeSelected(SELECTED_NONE);
+ mRollo.mState.save();
+ mArrowNavigation = false;
+ }
+ } else {
+ mShouldGainFocus = false;
+ }
+ }
+ }
+
+ private void gainFocus() {
+ if (!mArrowNavigation && mRollo.mState.iconCount > 0) {
+ // Select the first icon when we gain keyboard focus
+ mArrowNavigation = true;
+ mRollo.selectIcon(Math.round(mPosX) * Defines.COLUMNS_PER_PAGE,
+ SELECTED_FOCUSED);
+ mRollo.mState.save();
+ }
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+
+ boolean handled = false;
+
+ if (!isVisible()) {
+ return false;
+ }
+ final int iconCount = mRollo.mState.iconCount;
+
+ if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
+ if (mArrowNavigation) {
+ if (mLastSelection == SELECTION_HOME) {
+ reallyPlaySoundEffect(SoundEffectConstants.CLICK);
+ mLauncher.closeAllApps(true);
+ } else {
+ int whichApp = mRollo.mState.selectedIconIndex;
+ if (whichApp >= 0) {
+ ApplicationInfo app = mAllAppsList.get(whichApp);
+ mLauncher.startActivitySafely(app.intent);
+ handled = true;
+ }
+ }
+ }
+ }
+
+ if (iconCount > 0) {
+ mArrowNavigation = true;
+
+ int currentSelection = mRollo.mState.selectedIconIndex;
+ int currentTopRow = Math.round(mPosX);
+
+ // The column of the current selection, in the range 0..COLUMNS_PER_PAGE-1
+ final int currentPageCol = currentSelection % Defines.COLUMNS_PER_PAGE;
+
+ // The row of the current selection, in the range 0..ROWS_PER_PAGE-1
+ final int currentPageRow = (currentSelection - (currentTopRow*Defines.COLUMNS_PER_PAGE))
+ / Defines.ROWS_PER_PAGE;
+
+ int newSelection = currentSelection;
+
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_DPAD_UP:
+ if (mLastSelection == SELECTION_HOME) {
+ mRollo.setHomeSelected(SELECTED_NONE);
+ int lastRowCount = iconCount % Defines.COLUMNS_PER_PAGE;
+ if (lastRowCount == 0) {
+ lastRowCount = Defines.COLUMNS_PER_PAGE;
+ }
+ newSelection = iconCount - lastRowCount + (Defines.COLUMNS_PER_PAGE / 2);
+ if (newSelection >= iconCount) {
+ newSelection = iconCount-1;
+ }
+ int target = (newSelection / Defines.COLUMNS_PER_PAGE)
+ - (Defines.ROWS_PER_PAGE - 1);
+ if (target < 0) {
+ target = 0;
+ }
+ if (currentTopRow != target) {
+ mRollo.moveTo(target);
+ }
+ } else {
+ if (currentPageRow > 0) {
+ newSelection = currentSelection - Defines.COLUMNS_PER_PAGE;
+ } else if (currentTopRow > 0) {
+ newSelection = currentSelection - Defines.COLUMNS_PER_PAGE;
+ mRollo.moveTo(newSelection / Defines.COLUMNS_PER_PAGE);
+ } else if (currentPageRow != 0) {
+ newSelection = currentTopRow * Defines.ROWS_PER_PAGE;
+ }
+ }
+ handled = true;
+ break;
+
+ case KeyEvent.KEYCODE_DPAD_DOWN: {
+ final int rowCount = iconCount / Defines.COLUMNS_PER_PAGE
+ + (iconCount % Defines.COLUMNS_PER_PAGE == 0 ? 0 : 1);
+ final int currentRow = currentSelection / Defines.COLUMNS_PER_PAGE;
+ if (mLastSelection != SELECTION_HOME) {
+ if (currentRow < rowCount-1) {
+ mRollo.setHomeSelected(SELECTED_NONE);
+ if (currentSelection < 0) {
+ newSelection = 0;
+ } else {
+ newSelection = currentSelection + Defines.COLUMNS_PER_PAGE;
+ }
+ if (newSelection >= iconCount) {
+ // Go from D to G in this arrangement:
+ // A B C D
+ // E F G
+ newSelection = iconCount - 1;
+ }
+ if (currentPageRow >= Defines.ROWS_PER_PAGE - 1) {
+ mRollo.moveTo((newSelection / Defines.COLUMNS_PER_PAGE) -
+ Defines.ROWS_PER_PAGE + 1);
+ }
+ } else {
+ newSelection = -1;
+ mRollo.setHomeSelected(SELECTED_FOCUSED);
+ }
+ }
+ handled = true;
+ break;
+ }
+ case KeyEvent.KEYCODE_DPAD_LEFT:
+ if (currentPageCol > 0) {
+ newSelection = currentSelection - 1;
+ }
+ handled = true;
+ break;
+ case KeyEvent.KEYCODE_DPAD_RIGHT:
+ if ((currentPageCol < Defines.COLUMNS_PER_PAGE - 1) &&
+ (currentSelection < iconCount - 1)) {
+ newSelection = currentSelection + 1;
+ }
+ handled = true;
+ break;
+ }
+ if (newSelection != currentSelection) {
+ mRollo.selectIcon(newSelection, SELECTED_FOCUSED);
+ mRollo.mState.save();
+ }
+ }
+ return handled;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev)
+ {
+ mArrowNavigation = false;
+
+ if (!isVisible()) {
+ return true;
+ }
+
+ if (mLocks != 0) {
+ return true;
+ }
+
+ super.onTouchEvent(ev);
+
+ int x = (int)ev.getX();
+ int y = (int)ev.getY();
+
+ int action = ev.getAction();
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) {
+ mTouchTracking = TRACKING_HOME;
+ mRollo.setHomeSelected(SELECTED_PRESSED);
+ mRollo.mState.save();
+ mCurrentIconIndex = -1;
+ } else {
+ mTouchTracking = TRACKING_FLING;
+
+ mMotionDownRawX = (int)ev.getRawX();
+ mMotionDownRawY = (int)ev.getRawY();
+
+ mRollo.mState.newPositionX = ev.getRawY() / getHeight();
+ mRollo.mState.newTouchDown = 1;
+
+ if (!mRollo.checkClickOK()) {
+ mRollo.clearSelectedIcon();
+ } else {
+ mDownIconIndex = mCurrentIconIndex
+ = mRollo.selectIcon(x, y, mPosX, SELECTED_PRESSED);
+ if (mDownIconIndex < 0) {
+ // if nothing was selected, no long press.
+ cancelLongPress();
+ }
+ }
+ mRollo.mState.save();
+ mRollo.move();
+ mVelocityTracker = VelocityTracker.obtain();
+ mVelocityTracker.addMovement(ev);
+ mStartedScrolling = false;
+ }
+ break;
+ case MotionEvent.ACTION_MOVE:
+ case MotionEvent.ACTION_OUTSIDE:
+ if (mTouchTracking == TRACKING_HOME) {
+ mRollo.setHomeSelected(y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]
+ ? SELECTED_PRESSED : SELECTED_NONE);
+ mRollo.mState.save();
+ } else if (mTouchTracking == TRACKING_FLING) {
+ int rawX = (int)ev.getRawX();
+ int rawY = (int)ev.getRawY();
+ int slop;
+ slop = Math.abs(rawY - mMotionDownRawY);
+
+ if (!mStartedScrolling && slop < mSlop) {
+ // don't update anything so when we do start scrolling
+ // below, we get the right delta.
+ mCurrentIconIndex = mRollo.chooseTappedIcon(x, y, mPosX);
+ if (mDownIconIndex != mCurrentIconIndex) {
+ // If a different icon is selected, don't allow it to be picked up.
+ // This handles off-axis dragging.
+ cancelLongPress();
+ mCurrentIconIndex = -1;
+ }
+ } else {
+ if (!mStartedScrolling) {
+ cancelLongPress();
+ mCurrentIconIndex = -1;
+ }
+ mRollo.mState.newPositionX = ev.getRawY() / getHeight();
+ mRollo.mState.newTouchDown = 1;
+ mRollo.move();
+
+ mStartedScrolling = true;
+ mRollo.clearSelectedIcon();
+ mVelocityTracker.addMovement(ev);
+ mRollo.mState.save();
+ }
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ if (mTouchTracking == TRACKING_HOME) {
+ if (action == MotionEvent.ACTION_UP) {
+ if (y > mRollo.mTouchYBorders[mRollo.mTouchYBorders.length-1]) {
+ reallyPlaySoundEffect(SoundEffectConstants.CLICK);
+ mLauncher.closeAllApps(true);
+ }
+ mRollo.setHomeSelected(SELECTED_NONE);
+ mRollo.mState.save();
+ }
+ mCurrentIconIndex = -1;
+ } else if (mTouchTracking == TRACKING_FLING) {
+ mRollo.mState.newTouchDown = 0;
+ mRollo.mState.newPositionX = ev.getRawY() / getHeight();
+
+ mVelocityTracker.computeCurrentVelocity(1000 /* px/sec */, mMaxFlingVelocity);
+ mRollo.mState.flingVelocity = mVelocityTracker.getYVelocity() / getHeight();
+ mRollo.clearSelectedIcon();
+ mRollo.mState.save();
+ mRollo.fling();
+
+ if (mVelocityTracker != null) {
+ mVelocityTracker.recycle();
+ mVelocityTracker = null;
+ }
+ }
+ mTouchTracking = TRACKING_NONE;
+ break;
+ }
+
+ return true;
+ }
+
+ public void onClick(View v) {
+ if (mLocks != 0 || !isVisible()) {
+ return;
+ }
+ if (mRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
+ && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
+ reallyPlaySoundEffect(SoundEffectConstants.CLICK);
+ ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
+ mLauncher.startActivitySafely(app.intent);
+ }
+ }
+
+ public boolean onLongClick(View v) {
+ if (mLocks != 0 || !isVisible()) {
+ return true;
+ }
+ if (mRollo.checkClickOK() && mCurrentIconIndex == mDownIconIndex
+ && mCurrentIconIndex >= 0 && mCurrentIconIndex < mAllAppsList.size()) {
+ ApplicationInfo app = mAllAppsList.get(mCurrentIconIndex);
+
+ Bitmap bmp = Utilities.extractIconFromTexture(app.iconBitmap, getContext());
+
+ final int w = bmp.getWidth();
+ final int h = bmp.getHeight();
+
+ // We don't really have an accurate location to use. This will do.
+ int screenX = mMotionDownRawX - (w / 2);
+ int screenY = mMotionDownRawY - h;
+
+ mDragController.startDrag(bmp, screenX, screenY,
+ 0, 0, w, h, this, app, DragController.DRAG_ACTION_COPY);
+ bmp.recycle();
+
+ mLauncher.closeAllApps(true);
+ }
+ return true;
+ }
+
+ @Override
+ public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
+ if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SELECTED) {
+ if (!isVisible()) {
+ return false;
+ }
+ String text = null;
+ int index;
+ int count = mAllAppsList.size() + 1; // +1 is home
+ int pos = -1;
+ switch (mLastSelection) {
+ case SELECTION_ICONS:
+ index = mRollo.mState.selectedIconIndex;
+ if (index >= 0) {
+ ApplicationInfo info = mAllAppsList.get(index);
+ if (info.title != null) {
+ text = info.title.toString();
+ pos = index;
+ }
+ }
+ break;
+ case SELECTION_HOME:
+ text = getContext().getString(R.string.all_apps_home_button_label);
+ pos = count;
+ break;
+ }
+ if (text != null) {
+ event.setEnabled(true);
+ event.getText().add(text);
+ //event.setContentDescription(text);
+ event.setItemCount(count);
+ event.setCurrentItemIndex(pos);
+ }
+ }
+ return false;
+ }
+
+ public void setDragController(DragController dragger) {
+ mDragController = dragger;
+ }
+
+ public void onDropCompleted(View target, boolean success) {
+ }
+
+ /**
+ * Zoom to the specifed level.
+ *
+ * @param zoom [0..1] 0 is hidden, 1 is open
+ */
+ public void zoom(float zoom, boolean animate) {
+ cancelLongPress();
+ if (mRollo == null || !mRollo.mHasSurface) {
+ mZoomDirty = true;
+ mZoom = zoom;
+ mAnimateNextZoom = animate;
+ return;
+ } else {
+ mRollo.setZoom(zoom, animate);
+ }
+ }
+
+ public boolean isVisible() {
+ return mZoom > 0.001f;
+ }
+
+ public boolean isOpaque() {
+ return mZoom > 0.999f;
+ }
+
+ public void setApps(ArrayList<ApplicationInfo> list) {
+ mAllAppsList = list;
+ if (mRollo != null) {
+ mRollo.setApps(list);
+ }
+ mLocks &= ~LOCK_ICONS_PENDING;
+ }
+
+ public void addApps(ArrayList<ApplicationInfo> list) {
+ if (mAllAppsList == null) {
+ // Not done loading yet. We'll find out about it later.
+ return;
+ }
+
+ final int N = list.size();
+ if (mRollo != null) {
+ mRollo.reallocAppsList(mRollo.mState.iconCount + N);
+ }
+
+ for (int i=0; i<N; i++) {
+ final ApplicationInfo item = list.get(i);
+ int index = Collections.binarySearch(mAllAppsList, item,
+ LauncherModel.APP_NAME_COMPARATOR);
+ if (index < 0) {
+ index = -(index+1);
+ }
+ mAllAppsList.add(index, item);
+ if (mRollo != null) {
+ mRollo.addApp(index, item);
+ }
+ }
+
+ if (mRollo != null) {
+ mRollo.saveAppsList();
+ }
+ }
+
+ public void removeApps(ArrayList<ApplicationInfo> list) {
+ if (mAllAppsList == null) {
+ // Not done loading yet. We'll find out about it later.
+ return;
+ }
+
+ final int N = list.size();
+ for (int i=0; i<N; i++) {
+ final ApplicationInfo item = list.get(i);
+ int index = findAppByComponent(mAllAppsList, item);
+ if (index >= 0) {
+ int ic = mRollo != null ? mRollo.mState.iconCount : 666;
+ mAllAppsList.remove(index);
+ if (mRollo != null) {
+ mRollo.removeApp(index);
+ }
+ } else {
+ Log.w(TAG, "couldn't find a match for item \"" + item + "\"");
+ // Try to recover. This should keep us from crashing for now.
+ }
+ }
+
+ if (mRollo != null) {
+ mRollo.saveAppsList();
+ }
+ }
+
+ public void updateApps(String packageName, ArrayList<ApplicationInfo> list) {
+ // Just remove and add, because they may need to be re-sorted.
+ removeApps(list);
+ addApps(list);
+ }
+
+ private static int findAppByComponent(ArrayList<ApplicationInfo> list, ApplicationInfo item) {
+ ComponentName component = item.intent.getComponent();
+ final int N = list.size();
+ for (int i=0; i<N; i++) {
+ ApplicationInfo x = list.get(i);
+ if (x.intent.getComponent().equals(component)) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+ private static int countPages(int iconCount) {
+ int iconsPerPage = Defines.COLUMNS_PER_PAGE * Defines.ROWS_PER_PAGE;
+ int pages = iconCount / iconsPerPage;
+ if (pages*iconsPerPage != iconCount) {
+ pages++;
+ }
+ return pages;
+ }
+
+ class AAMessage extends RenderScript.RSMessage {
+ public void run() {
+ mPosX = ((float)mData[0]) / (1 << 16);
+ mVelocity = ((float)mData[1]) / (1 << 16);
+ mZoom = ((float)mData[2]) / (1 << 16);
+ mZoomDirty = false;
+ }
+ }
+
+ public class RolloRS {
+
+ // Allocations ======
+ private int mWidth;
+ private int mHeight;
+
+ private Resources mRes;
+ private Script mScript;
+ private Script.Invokable mInvokeMove;
+ private Script.Invokable mInvokeMoveTo;
+ private Script.Invokable mInvokeFling;
+ private Script.Invokable mInvokeResetWAR;
+ private Script.Invokable mInvokeSetZoom;
+
+ private ProgramStore mPSIcons;
+ private ProgramStore mPSText;
+ private ProgramFragment mPFColor;
+ private ProgramFragment mPFTexMip;
+ private ProgramFragment mPFTexNearest;
+ private ProgramVertex mPV;
+ private ProgramVertex mPVOrtho;
+ private SimpleMesh mMesh;
+ private SimpleMesh mMesh2;
+ private ProgramVertex.MatrixAllocation mPVA;
+
+ private Allocation mHomeButtonNormal;
+ private Allocation mHomeButtonFocused;
+ private Allocation mHomeButtonPressed;
+
+ private Allocation[] mIcons;
+ private int[] mIconIds;
+ private Allocation mAllocIconIds;
+ private Allocation mSelectedIcon;
+
+ private int[] mTouchYBorders;
+ private int[] mTouchXBorders;
+
+ private Bitmap mSelectionBitmap;
+ private Canvas mSelectionCanvas;
+
+ boolean mHasSurface = false;
+ private boolean mAppsDirty = true;
+
+ Params mParams;
+ State mState;
+
+ class BaseAlloc {
+ Allocation mAlloc;
+ Type mType;
+
+ void save() {
+ mAlloc.data(this);
+ }
+ }
+
+ private boolean checkClickOK() {
+ return (Math.abs(mVelocity) < 0.4f) &&
+ (Math.abs(mPosX - Math.round(mPosX)) < 0.4f);
+ }
+
+ class Params extends BaseAlloc {
+ Params() {
+ mType = Type.createFromClass(mRS, Params.class, 1, "ParamsClass");
+ mAlloc = Allocation.createTyped(mRS, mType);
+ save();
+ }
+ public int bubbleWidth;
+ public int bubbleHeight;
+ public int bubbleBitmapWidth;
+ public int bubbleBitmapHeight;
+
+ public int homeButtonWidth;
+ public int homeButtonHeight;
+ public int homeButtonTextureWidth;
+ public int homeButtonTextureHeight;
+ }
+
+ class State extends BaseAlloc {
+ public float newPositionX;
+ public int newTouchDown;
+ public float flingVelocity;
+ public int iconCount;
+ public int selectedIconIndex = -1;
+ public int selectedIconTexture;
+ public float zoomTarget;
+ public int homeButtonId;
+ public float targetPos;
+
+ State() {
+ mType = Type.createFromClass(mRS, State.class, 1, "StateClass");
+ mAlloc = Allocation.createTyped(mRS, mType);
+ save();
+ }
+ }
+
+ public RolloRS() {
+ }
+
+ public void init(Resources res, int width, int height) {
+ mRes = res;
+ mWidth = width;
+ mHeight = height;
+ mDefines.recompute(width, height);
+ initProgramVertex();
+ initProgramFragment();
+ initProgramStore();
+ initMesh();
+ initGl();
+ initData();
+ initTouchState();
+ initRs();
+ }
+
+ public void initMesh() {
+ SimpleMesh.TriangleMeshBuilder tm = new SimpleMesh.TriangleMeshBuilder(mRS, 3,
+ SimpleMesh.TriangleMeshBuilder.TEXTURE_0 | SimpleMesh.TriangleMeshBuilder.COLOR);
+
+ float y = 0;
+ float z = 0;
+ for (int ct=0; ct < 200; ct++) {
+ float angle = 0;
+ float maxAngle = 3.14f * 0.16f;
+ float l = 1.f;
+
+ l = 1 - ((ct-7) * 0.10f);
+ if (ct > 7) {
+ angle = maxAngle * (ct - 7) * 0.2f;
+ angle = Math.min(angle, maxAngle);
+ }
+ l = Math.max(0.4f, l);
+ l = Math.min(1.0f, l);
+
+ y += 0.1f * Math.cos(angle);
+ z += 0.1f * Math.sin(angle);
+
+ float t = 0.1f * ct;
+ float ds = 0.08f;
+ tm.setColor(l, l, l, 0.99f);
+ tm.setTexture(ds, t);
+ tm.addVertex(-0.5f, y, z);
+ tm.setTexture(1 - ds, t);
+ tm.addVertex(0.5f, y, z);
+ }
+ for (int ct=0; ct < (200 * 2 - 2); ct+= 2) {
+ tm.addTriangle(ct, ct+1, ct+2);
+ tm.addTriangle(ct+1, ct+3, ct+2);
+ }
+ mMesh2 = tm.create();
+ mMesh2.setName("SMMesh");
+ }
+
+ void resize(int w, int h) {
+ mPVA.setupProjectionNormalized(w, h);
+ mWidth = w;
+ mHeight = h;
+ }
+
+ private void initProgramVertex() {
+ mPVA = new ProgramVertex.MatrixAllocation(mRS);
+ resize(mWidth, mHeight);
+
+ ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
+ pvb.setTextureMatrixEnable(true);
+ mPV = pvb.create();
+ mPV.setName("PV");
+ mPV.bindAllocation(mPVA);
+
+ //pva = new ProgramVertex.MatrixAllocation(mRS);
+ //pva.setupOrthoWindow(mWidth, mHeight);
+ //pvb.setTextureMatrixEnable(true);
+ //mPVOrtho = pvb.create();
+ //mPVOrtho.setName("PVOrtho");
+ //mPVOrtho.bindAllocation(pva);
+
+ mRS.contextBindProgramVertex(mPV);
+ }
+
+ private void initProgramFragment() {
+ Sampler.Builder sb = new Sampler.Builder(mRS);
+ sb.setMin(Sampler.Value.LINEAR_MIP_LINEAR);
+ sb.setMag(Sampler.Value.LINEAR);
+ sb.setWrapS(Sampler.Value.CLAMP);
+ sb.setWrapT(Sampler.Value.CLAMP);
+ Sampler linear = sb.create();
+
+ sb.setMin(Sampler.Value.NEAREST);
+ sb.setMag(Sampler.Value.NEAREST);
+ Sampler nearest = sb.create();
+
+ ProgramFragment.Builder bf = new ProgramFragment.Builder(mRS, null, null);
+ mPFColor = bf.create();
+ mPFColor.setName("PFColor");
+
+ bf.setTexEnable(true, 0);
+ bf.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
+ mPFTexMip = bf.create();
+ mPFTexMip.setName("PFTexMip");
+ mPFTexMip.bindSampler(linear, 0);
+
+ mPFTexNearest = bf.create();
+ mPFTexNearest.setName("PFTexNearest");
+ mPFTexNearest.bindSampler(nearest, 0);
+ }
+
+ private void initProgramStore() {
+ ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
+ bs.setDepthFunc(ProgramStore.DepthFunc.ALWAYS);
+ bs.setColorMask(true,true,true,false);
+ bs.setDitherEnable(true);
+ bs.setBlendFunc(ProgramStore.BlendSrcFunc.SRC_ALPHA,
+ ProgramStore.BlendDstFunc.ONE_MINUS_SRC_ALPHA);
+ mPSIcons = bs.create();
+ mPSIcons.setName("PSIcons");
+
+ //bs.setDitherEnable(false);
+ //mPSText = bs.create();
+ //mPSText.setName("PSText");
+ }
+
+ private void initGl() {
+ mTouchXBorders = new int[Defines.COLUMNS_PER_PAGE+1];
+ mTouchYBorders = new int[Defines.ROWS_PER_PAGE+1];
+ }
+
+ private void initData() {
+ mParams = new Params();
+ mState = new State();
+
+ final Utilities.BubbleText bubble = new Utilities.BubbleText(getContext());
+
+ mParams.bubbleWidth = bubble.getBubbleWidth();
+ mParams.bubbleHeight = bubble.getMaxBubbleHeight();
+ mParams.bubbleBitmapWidth = bubble.getBitmapWidth();
+ mParams.bubbleBitmapHeight = bubble.getBitmapHeight();
+
+ mHomeButtonNormal = Allocation.createFromBitmapResource(mRS, mRes,
+ R.drawable.home_button_normal, Element.RGBA_8888(mRS), false);
+ mHomeButtonNormal.uploadToTexture(0);
+ mHomeButtonFocused = Allocation.createFromBitmapResource(mRS, mRes,
+ R.drawable.home_button_focused, Element.RGBA_8888(mRS), false);
+ mHomeButtonFocused.uploadToTexture(0);
+ mHomeButtonPressed = Allocation.createFromBitmapResource(mRS, mRes,
+ R.drawable.home_button_pressed, Element.RGBA_8888(mRS), false);
+ mHomeButtonPressed.uploadToTexture(0);
+ mParams.homeButtonWidth = 76;
+ mParams.homeButtonHeight = 68;
+ mParams.homeButtonTextureWidth = 128;
+ mParams.homeButtonTextureHeight = 128;
+
+ mState.homeButtonId = mHomeButtonNormal.getID();
+
+ mParams.save();
+ mState.save();
+
+ mSelectionBitmap = Bitmap.createBitmap(Defines.ICON_TEXTURE_WIDTH_PX,
+ Defines.ICON_TEXTURE_HEIGHT_PX, Bitmap.Config.ARGB_8888);
+ mSelectionCanvas = new Canvas(mSelectionBitmap);
+
+ setApps(null);
+ }
+
+ private void initScript(int id) {
+ }
+
+ private void initRs() {
+ ScriptC.Builder sb = new ScriptC.Builder(mRS);
+ sb.setScript(mRes, R.raw.rollo3);
+ sb.setRoot(true);
+ sb.addDefines(mDefines);
+ sb.setType(mParams.mType, "params", Defines.ALLOC_PARAMS);
+ sb.setType(mState.mType, "state", Defines.ALLOC_STATE);
+ mInvokeMove = sb.addInvokable("move");
+ mInvokeFling = sb.addInvokable("fling");
+ mInvokeMoveTo = sb.addInvokable("moveTo");
+ mInvokeResetWAR = sb.addInvokable("resetHWWar");
+ mInvokeSetZoom = sb.addInvokable("setZoom");
+ mScript = sb.create();
+ mScript.setClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ mScript.bindAllocation(mParams.mAlloc, Defines.ALLOC_PARAMS);
+ mScript.bindAllocation(mState.mAlloc, Defines.ALLOC_STATE);
+ mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
+
+ mRS.contextBindRootScript(mScript);
+ }
+
+ void dirtyCheck() {
+ if (mHasSurface) {
+ if (mAppsDirty && mAllAppsList != null) {
+ for (int i=0; i < mState.iconCount; i++) {
+ uploadAppIcon(i, mAllAppsList.get(i));
+ }
+ saveAppsList();
+ mAppsDirty = false;
+ }
+ if (mZoomDirty) {
+ setZoom(mZoom, mAnimateNextZoom);
+ }
+ }
+ }
+
+ private void setApps(ArrayList<ApplicationInfo> list) {
+ final int count = list != null ? list.size() : 0;
+ int allocCount = count;
+ if (allocCount < 1) {
+ allocCount = 1;
+ }
+
+ mIcons = new Allocation[count];
+ mIconIds = new int[allocCount];
+ mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), allocCount);
+
+ Element ie8888 = Element.RGBA_8888(mRS);
+
+ mState.iconCount = count;
+ long before = SystemClock.uptimeMillis();
+ for (int i=0; i < mState.iconCount; i++) {
+ createAppIconAllocations(i, list.get(i));
+ }
+ long after = SystemClock.uptimeMillis();
+ //Log.d(TAG, "createAppIconAllocations took " + (after-before) + "ms");
+ if (mHasSurface) {
+ for (int i=0; i < mState.iconCount; i++) {
+ uploadAppIcon(i, list.get(i));
+ }
+ } else {
+ mRollo.mAppsDirty = true;
+ }
+ saveAppsList();
+ }
+
+ private void setZoom(float zoom, boolean animate) {
+ mRollo.clearSelectedIcon();
+ mRollo.setHomeSelected(SELECTED_NONE);
+ if (zoom > 0.001f) {
+ mRollo.mState.zoomTarget = zoom;
+ } else {
+ mRollo.mState.zoomTarget = 0;
+ }
+ mRollo.mState.save();
+ if (!animate) {
+ mRollo.mInvokeSetZoom.execute();
+ }
+ }
+
+ private void frameBitmapAllocMips(Allocation alloc, int w, int h) {
+ int black[] = new int[w > h ? w : h];
+ Allocation.Adapter2D a = alloc.createAdapter2D();
+ int mip = 0;
+ while (w > 1 || h > 1) {
+ a.subData(0, 0, 1, h, black);
+ a.subData(w-1, 0, 1, h, black);
+ a.subData(0, 0, w, 1, black);
+ a.subData(0, h-1, w, 1, black);
+ mip++;
+ w = (w + 1) >> 1;
+ h = (h + 1) >> 1;
+ a.setConstraint(Dimension.LOD, mip);
+ }
+ a.subData(0, 0, 1, 1, black);
+ }
+
+ private void createAppIconAllocations(int index, ApplicationInfo item) {
+ Bitmap bitmap = item.iconBitmap;
+ mIcons[index] = Allocation.createFromBitmap(mRS, bitmap, Element.RGBA_8888(mRS), true);
+ frameBitmapAllocMips(mIcons[index], bitmap.getWidth(), bitmap.getHeight());
+
+ mIconIds[index] = mIcons[index].getID();
+ }
+
+ private void uploadAppIcon(int index, ApplicationInfo item) {
+ if (mIconIds[index] != mIcons[index].getID()) {
+ throw new IllegalStateException("uploadAppIcon index=" + index
+ + " mIcons[index].getID=" + mIcons[index].getID()
+ + " mIconsIds[index]=" + mIconIds[index]
+ + " item=" + item);
+ }
+ mIcons[index].uploadToTexture(0);
+ }
+
+ /**
+ * Puts the empty spaces at the end. Updates mState.iconCount. You must
+ * fill in the values and call saveAppsList().
+ */
+ private void reallocAppsList(int count) {
+ Allocation[] icons = new Allocation[count];
+ int[] iconIds = new int[count];
+ mAllocIconIds = Allocation.createSized(mRS, Element.USER_I32(mRS), count);
+
+ final int oldCount = mRollo.mState.iconCount;
+
+ System.arraycopy(mIcons, 0, icons, 0, oldCount);
+ System.arraycopy(mIconIds, 0, iconIds, 0, oldCount);
+
+ mIcons = icons;
+ mIconIds = iconIds;
+ }
+
+ /**
+ * Handle the allocations for the new app. Make sure you call saveAppsList when done.
+ */
+ private void addApp(int index, ApplicationInfo item) {
+ final int count = mState.iconCount - index;
+ final int dest = index + 1;
+
+ System.arraycopy(mIcons, index, mIcons, dest, count);
+ System.arraycopy(mIconIds, index, mIconIds, dest, count);
+
+ createAppIconAllocations(index, item);
+
+ if (mHasSurface) {
+ uploadAppIcon(index, item);
+ } else {
+ mAppsDirty = true;
+ }
+
+ mRollo.mState.iconCount++;
+ }
+
+ /**
+ * Handle the allocations for the removed app. Make sure you call saveAppsList when done.
+ */
+ private void removeApp(int index) {
+ final int count = mState.iconCount - index - 1;
+ final int src = index + 1;
+
+ System.arraycopy(mIcons, src, mIcons, index, count);
+ System.arraycopy(mIconIds, src, mIconIds, index, count);
+
+ mRollo.mState.iconCount--;
+ final int last = mState.iconCount;
+
+ mIcons[last] = null;
+ mIconIds[last] = 0;
+ }
+
+ /**
+ * Send the apps list structures to RS.
+ */
+ private void saveAppsList() {
+ mRS.contextBindRootScript(null);
+
+ mAllocIconIds.data(mIconIds);
+
+ if (mScript != null) { // this happens when we init it
+ mScript.bindAllocation(mAllocIconIds, Defines.ALLOC_ICON_IDS);
+ }
+
+ mState.save();
+
+ // Note: mScript may be null if we haven't initialized it yet.
+ // In that case, this is a no-op.
+ if (mInvokeResetWAR != null) {
+ mInvokeResetWAR.execute();
+ }
+ mRS.contextBindRootScript(mScript);
+ }
+
+ void initTouchState() {
+ int width = getWidth();
+ int height = getHeight();
+ int cellHeight = 145;//iconsSize / Defines.ROWS_PER_PAGE;
+ int cellWidth = width / Defines.COLUMNS_PER_PAGE;
+
+ int centerY = (height / 2);
+ mTouchYBorders[0] = centerY - (cellHeight * 2);
+ mTouchYBorders[1] = centerY - cellHeight;
+ mTouchYBorders[2] = centerY;
+ mTouchYBorders[3] = centerY + cellHeight;
+ mTouchYBorders[4] = centerY + (cellHeight * 2);
+
+ int centerX = (width / 2);
+ mTouchXBorders[0] = 0;
+ mTouchXBorders[1] = centerX - (width / 4);
+ mTouchXBorders[2] = centerX;
+ mTouchXBorders[3] = centerX + (width / 4);
+ mTouchXBorders[4] = width;
+ }
+
+ void fling() {
+ mInvokeFling.execute();
+ }
+
+ void move() {
+ mInvokeMove.execute();
+ }
+
+ void moveTo(float row) {
+ mState.targetPos = row;
+ mState.save();
+ mInvokeMoveTo.execute();
+ }
+
+ int chooseTappedIcon(int x, int y, float pos) {
+ // Adjust for scroll position if not zero.
+ y += (pos - ((int)pos)) * (mTouchYBorders[1] - mTouchYBorders[0]);
+
+ int col = -1;
+ int row = -1;
+ for (int i=0; i<Defines.COLUMNS_PER_PAGE; i++) {
+ if (x >= mTouchXBorders[i] && x < mTouchXBorders[i+1]) {
+ col = i;
+ break;
+ }
+ }
+ for (int i=0; i<Defines.ROWS_PER_PAGE; i++) {
+ if (y >= mTouchYBorders[i] && y < mTouchYBorders[i+1]) {
+ row = i;
+ break;
+ }
+ }
+
+ if (row < 0 || col < 0) {
+ return -1;
+ }
+
+ int index = (((int)pos) * Defines.COLUMNS_PER_PAGE)
+ + (row * Defines.ROWS_PER_PAGE) + col;
+
+ if (index >= mState.iconCount) {
+ return -1;
+ } else {
+ return index;
+ }
+ }
+
+ /**
+ * You need to call save() on mState on your own after calling this.
+ *
+ * @return the index of the icon that was selected.
+ */
+ int selectIcon(int x, int y, float pos, int pressed) {
+ final int index = chooseTappedIcon(x, y, pos);
+ selectIcon(index, pressed);
+ return index;
+ }
+
+ /**
+ * Select the icon at the given index.
+ *
+ * @param index The index.
+ * @param pressed one of SELECTED_PRESSED or SELECTED_FOCUSED
+ */
+ void selectIcon(int index, int pressed) {
+ if (mAllAppsList == null || index < 0 || index >= mAllAppsList.size()) {
+ mState.selectedIconIndex = -1;
+ if (mLastSelection == SELECTION_ICONS) {
+ mLastSelection = SELECTION_NONE;
+ }
+ } else {
+ if (pressed == SELECTED_FOCUSED) {
+ mLastSelection = SELECTION_ICONS;
+ }
+
+ int prev = mState.selectedIconIndex;
+ mState.selectedIconIndex = index;
+
+ ApplicationInfo info = mAllAppsList.get(index);
+ Bitmap selectionBitmap = mSelectionBitmap;
+
+ Utilities.drawSelectedAllAppsBitmap(mSelectionCanvas, selectionBitmap,
+ selectionBitmap.getWidth(), selectionBitmap.getHeight(),
+ pressed == SELECTED_PRESSED, info.iconBitmap);
+
+ mSelectedIcon = Allocation.createFromBitmap(mRS, selectionBitmap,
+ Element.RGBA_8888(mRS), false);
+ mSelectedIcon.uploadToTexture(0);
+ mState.selectedIconTexture = mSelectedIcon.getID();
+
+ if (prev != index) {
+ if (info.title != null && info.title.length() > 0) {
+ //setContentDescription(info.title);
+ sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
+ }
+ }
+ }
+ }
+
+ /**
+ * You need to call save() on mState on your own after calling this.
+ */
+ void clearSelectedIcon() {
+ mState.selectedIconIndex = -1;
+ }
+
+ void setHomeSelected(int mode) {
+ final int prev = mLastSelection;
+ switch (mode) {
+ case SELECTED_NONE:
+ mState.homeButtonId = mHomeButtonNormal.getID();
+ break;
+ case SELECTED_FOCUSED:
+ mLastSelection = SELECTION_HOME;
+ mState.homeButtonId = mHomeButtonFocused.getID();
+ if (prev != SELECTION_HOME) {
+ sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
+ }
+ break;
+ case SELECTED_PRESSED:
+ mState.homeButtonId = mHomeButtonPressed.getID();
+ break;
+ }
+ }
+
+ public void dumpState() {
+ Log.d(TAG, "mRollo.mWidth=" + mWidth);
+ Log.d(TAG, "mRollo.mHeight=" + mHeight);
+ Log.d(TAG, "mRollo.mIcons=" + mIcons);
+ if (mIcons != null) {
+ Log.d(TAG, "mRollo.mIcons.length=" + mIcons.length);
+ }
+ if (mIconIds != null) {
+ Log.d(TAG, "mRollo.mIconIds.length=" + mIconIds.length);
+ }
+ Log.d(TAG, "mRollo.mIconIds=" + Arrays.toString(mIconIds));
+ Log.d(TAG, "mRollo.mTouchXBorders=" + Arrays.toString(mTouchXBorders));
+ Log.d(TAG, "mRollo.mTouchYBorders=" + Arrays.toString(mTouchYBorders));
+ Log.d(TAG, "mRollo.mHasSurface=" + mHasSurface);
+ Log.d(TAG, "mRollo.mAppsDirty=" + mAppsDirty);
+ Log.d(TAG, "mRollo.mState.newPositionX=" + mState.newPositionX);
+ Log.d(TAG, "mRollo.mState.newTouchDown=" + mState.newTouchDown);
+ Log.d(TAG, "mRollo.mState.flingVelocity=" + mState.flingVelocity);
+ Log.d(TAG, "mRollo.mState.iconCount=" + mState.iconCount);
+ Log.d(TAG, "mRollo.mState.selectedIconIndex=" + mState.selectedIconIndex);
+ Log.d(TAG, "mRollo.mState.selectedIconTexture=" + mState.selectedIconTexture);
+ Log.d(TAG, "mRollo.mState.zoomTarget=" + mState.zoomTarget);
+ Log.d(TAG, "mRollo.mState.homeButtonId=" + mState.homeButtonId);
+ Log.d(TAG, "mRollo.mState.targetPos=" + mState.targetPos);
+ Log.d(TAG, "mRollo.mParams.bubbleWidth=" + mParams.bubbleWidth);
+ Log.d(TAG, "mRollo.mParams.bubbleHeight=" + mParams.bubbleHeight);
+ Log.d(TAG, "mRollo.mParams.bubbleBitmapWidth=" + mParams.bubbleBitmapWidth);
+ Log.d(TAG, "mRollo.mParams.bubbleBitmapHeight=" + mParams.bubbleBitmapHeight);
+ Log.d(TAG, "mRollo.mParams.homeButtonWidth=" + mParams.homeButtonWidth);
+ Log.d(TAG, "mRollo.mParams.homeButtonHeight=" + mParams.homeButtonHeight);
+ Log.d(TAG, "mRollo.mParams.homeButtonTextureWidth=" + mParams.homeButtonTextureWidth);
+ Log.d(TAG, "mRollo.mParams.homeButtonTextureHeight=" + mParams.homeButtonTextureHeight);
+ }
+ }
+
+ public void dumpState() {
+ Log.d(TAG, "mRS=" + mRS);
+ Log.d(TAG, "mRollo=" + mRollo);
+ ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList", mAllAppsList);
+ Log.d(TAG, "mArrowNavigation=" + mArrowNavigation);
+ Log.d(TAG, "mStartedScrolling=" + mStartedScrolling);
+ Log.d(TAG, "mLastSelection=" + mLastSelection);
+ Log.d(TAG, "mLastSelectedIcon=" + mLastSelectedIcon);
+ Log.d(TAG, "mVelocityTracker=" + mVelocityTracker);
+ Log.d(TAG, "mTouchTracking=" + mTouchTracking);
+ Log.d(TAG, "mShouldGainFocus=" + mShouldGainFocus);
+ Log.d(TAG, "mZoomDirty=" + mZoomDirty);
+ Log.d(TAG, "mAnimateNextZoom=" + mAnimateNextZoom);
+ Log.d(TAG, "mZoom=" + mZoom);
+ Log.d(TAG, "mPosX=" + mPosX);
+ Log.d(TAG, "mVelocity=" + mVelocity);
+ Log.d(TAG, "mMessageProc=" + mMessageProc);
+ if (mRollo != null) {
+ mRollo.dumpState();
+ }
+ if (mRS != null) {
+ mRS.contextDump(0);
+ }
+ }
+}
+
+
diff --git a/src/com/android/launcher2/AppInfoCache.java b/src/com/android/launcher2/AppInfoCache.java
new file mode 100644
index 0000000..e81168e
--- /dev/null
+++ b/src/com/android/launcher2/AppInfoCache.java
@@ -0,0 +1,180 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Intent;
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.BitmapDrawable;
+import android.net.Uri;
+import android.util.Log;
+import android.os.Process;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Cache of application icons. Icons can be made from any thread.
+ */
+public class AppInfoCache {
+ private static final String TAG = "Launcher.AppInfoCache";
+
+ private static final int INITIAL_ICON_CACHE_CAPACITY = 50;
+
+ private static final HashMap<ComponentName, ApplicationInfo> sCache =
+ new HashMap<ComponentName, ApplicationInfo>(INITIAL_ICON_CACHE_CAPACITY);
+
+ /**
+ * no public constructor.
+ */
+ private AppInfoCache() {
+ }
+
+ /**
+ * For the given ResolveInfo, return an ApplicationInfo and cache the result for later.
+ */
+ public static ApplicationInfo cache(ResolveInfo info, Context context,
+ Utilities.BubbleText bubble) {
+ synchronized (sCache) {
+ ComponentName componentName = new ComponentName(
+ info.activityInfo.applicationInfo.packageName,
+ info.activityInfo.name);
+ ApplicationInfo application = sCache.get(componentName);
+
+ if (application == null) {
+ application = new ApplicationInfo();
+ application.container = ItemInfo.NO_ID;
+
+ updateTitleAndIcon(info, application, context, bubble);
+
+ application.setActivity(componentName,
+ Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+
+ sCache.put(componentName, application);
+ }
+
+ return application;
+ }
+ }
+
+ /**
+ * Update the entry in the in the cache with its new metadata.
+ */
+ public static void update(ResolveInfo info, ApplicationInfo applicationInfo, Context context,
+ Utilities.BubbleText bubble) {
+ synchronized (sCache) {
+ updateTitleAndIcon(info, applicationInfo, context, bubble);
+
+ ComponentName componentName = new ComponentName(
+ info.activityInfo.applicationInfo.packageName, info.activityInfo.name);
+ sCache.put(componentName, applicationInfo);
+ }
+ }
+
+ /**
+ * Remove any records for the supplied ComponentName.
+ */
+ public static void remove(ComponentName componentName) {
+ synchronized (sCache) {
+ sCache.remove(componentName);
+ }
+ }
+
+ /**
+ * Empty out the cache.
+ */
+ public static void flush() {
+ synchronized (sCache) {
+ sCache.clear();
+ }
+ }
+
+ /**
+ * Get the icon for the supplied ApplicationInfo. If that activity already
+ * exists in the cache, use that.
+ */
+ public static Drawable getIconDrawable(PackageManager packageManager, ApplicationInfo info) {
+ final ResolveInfo resolveInfo = packageManager.resolveActivity(info.intent, 0);
+ if (resolveInfo == null) {
+ return null;
+ }
+
+ ComponentName componentName = new ComponentName(
+ resolveInfo.activityInfo.applicationInfo.packageName,
+ resolveInfo.activityInfo.name);
+ ApplicationInfo cached;
+ synchronized (sCache) {
+ cached = sCache.get(componentName);
+ if (cached != null) {
+ if (cached.icon == null) {
+ cached.icon = resolveInfo.activityInfo.loadIcon(packageManager);
+ }
+ return cached.icon;
+ } else {
+ return resolveInfo.activityInfo.loadIcon(packageManager);
+ }
+ }
+ }
+
+ /**
+ * Go through the cache and disconnect any of the callbacks in the drawables or we
+ * leak the previous Home screen on orientation change.
+ */
+ public static void unbindDrawables() {
+ synchronized (sCache) {
+ for (ApplicationInfo appInfo: sCache.values()) {
+ if (appInfo.icon != null) {
+ appInfo.icon.setCallback(null);
+ }
+ }
+ }
+ }
+
+ /**
+ * Update the title and icon. Don't keep a reference to the context!
+ */
+ private static void updateTitleAndIcon(ResolveInfo info, ApplicationInfo application,
+ Context context, Utilities.BubbleText bubble) {
+ final PackageManager packageManager = context.getPackageManager();
+
+ application.title = info.loadLabel(packageManager);
+ if (application.title == null) {
+ application.title = info.activityInfo.name;
+ }
+
+ // TODO: turn this on in froyo, not enough time for testing in mr3
+ //if (application.iconBitmap != null) {
+ // application.iconBitmap.recycle();
+ //}
+ application.iconBitmap = Utilities.createAllAppsBitmap(
+ info.activityInfo.loadIcon(packageManager),
+ application.title.toString(), bubble, context);
+ }
+}
+
diff --git a/src/com/android/launcher2/ApplicationInfo.java b/src/com/android/launcher2/ApplicationInfo.java
new file mode 100644
index 0000000..ae0e219
--- /dev/null
+++ b/src/com/android/launcher2/ApplicationInfo.java
@@ -0,0 +1,152 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.ComponentName;
+import android.content.ContentValues;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.drawable.Drawable;
+import android.util.Log;
+
+import java.util.ArrayList;
+
+/**
+ * Represents a launchable application. An application is made of a name (or title),
+ * an intent and an icon.
+ */
+class ApplicationInfo extends ItemInfo {
+
+ /**
+ * The application name.
+ */
+ CharSequence title;
+
+ /**
+ * The intent used to start the application.
+ */
+ Intent intent;
+
+ /**
+ * The application icon.
+ */
+ Drawable icon;
+
+ /**
+ * What we show in all apps, including the text.
+ */
+ Bitmap iconBitmap;
+
+ /**
+ * When set to true, indicates that the icon has been resized.
+ */
+ boolean filtered;
+
+ /**
+ * Indicates whether the icon comes from an application's resource (if false)
+ * or from a custom Bitmap (if true.)
+ */
+ boolean customIcon;
+
+ /**
+ * If isShortcut=true and customIcon=false, this contains a reference to the
+ * shortcut icon as an application's resource.
+ */
+ Intent.ShortcutIconResource iconResource;
+
+ ApplicationInfo() {
+ itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
+ }
+
+ public ApplicationInfo(ApplicationInfo info) {
+ super(info);
+ title = info.title.toString();
+ intent = new Intent(info.intent);
+ if (info.iconResource != null) {
+ iconResource = new Intent.ShortcutIconResource();
+ iconResource.packageName = info.iconResource.packageName;
+ iconResource.resourceName = info.iconResource.resourceName;
+ }
+ icon = info.icon;
+ filtered = info.filtered;
+ customIcon = info.customIcon;
+ }
+
+ /**
+ * Creates the application intent based on a component name and various launch flags.
+ * Sets {@link #itemType} to {@link LauncherSettings.BaseLauncherColumns#ITEM_TYPE_APPLICATION}.
+ *
+ * @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);
+ itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION;
+ }
+
+ @Override
+ void onAddToDatabase(ContentValues values) {
+ super.onAddToDatabase(values);
+
+ String titleStr = title != null ? title.toString() : null;
+ values.put(LauncherSettings.BaseLauncherColumns.TITLE, titleStr);
+
+ String uri = intent != null ? intent.toUri(0) : null;
+ values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri);
+
+ if (customIcon) {
+ values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
+ LauncherSettings.BaseLauncherColumns.ICON_TYPE_BITMAP);
+ Bitmap bitmap = ((FastBitmapDrawable) icon).getBitmap();
+ writeBitmap(values, bitmap);
+ } else {
+ values.put(LauncherSettings.BaseLauncherColumns.ICON_TYPE,
+ LauncherSettings.BaseLauncherColumns.ICON_TYPE_RESOURCE);
+ if (iconResource != null) {
+ values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE,
+ iconResource.packageName);
+ values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE,
+ iconResource.resourceName);
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return title.toString();
+ }
+
+ @Override
+ void unbind() {
+ super.unbind();
+ icon.setCallback(null);
+ }
+
+
+ public static void dumpApplicationInfoList(String tag, String label,
+ ArrayList<ApplicationInfo> list) {
+ Log.d(tag, label + " size=" + list.size());
+ for (ApplicationInfo info: list) {
+ Log.d(tag, " title=\"" + info.title + "\" icon=" + info.icon
+ + " iconBitmap=" + info.iconBitmap + " filtered=" + info.filtered
+ + " customIcon=" + info.customIcon);
+ }
+ }
+}
diff --git a/src/com/android/launcher2/ApplicationsAdapter.java b/src/com/android/launcher2/ApplicationsAdapter.java
new file mode 100644
index 0000000..129103a
--- /dev/null
+++ b/src/com/android/launcher2/ApplicationsAdapter.java
@@ -0,0 +1,64 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+
+/**
+ * GridView adapter to show the list of applications and shortcuts
+ */
+public class ApplicationsAdapter extends ArrayAdapter<ApplicationInfo> {
+ private final LayoutInflater mInflater;
+ private final PackageManager mPackageManager;
+
+ public ApplicationsAdapter(Context context, ArrayList<ApplicationInfo> apps) {
+ super(context, 0, apps);
+ mPackageManager = context.getPackageManager();
+ mInflater = LayoutInflater.from(context);
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ final ApplicationInfo info = getItem(position);
+
+ if (convertView == null) {
+ convertView = mInflater.inflate(R.layout.application_boxed, parent, false);
+ }
+
+ if (info.icon == null) {
+ info.icon = AppInfoCache.getIconDrawable(mPackageManager, info);
+ }
+ if (!info.filtered) {
+ info.icon = Utilities.createIconThumbnail(info.icon, getContext());
+ info.filtered = true;
+ }
+
+ final TextView textView = (TextView) convertView;
+ textView.setCompoundDrawablesWithIntrinsicBounds(null, info.icon, null, null);
+ textView.setText(info.title);
+
+ return convertView;
+ }
+}
diff --git a/src/com/android/launcher2/BubbleTextView.java b/src/com/android/launcher2/BubbleTextView.java
new file mode 100644
index 0000000..eaaff1c
--- /dev/null
+++ b/src/com/android/launcher2/BubbleTextView.java
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.widget.TextView;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+import android.text.Layout;
+
+/**
+ * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
+ * because we want to make the bubble taller than the text and TextView's clip is
+ * too aggressive.
+ */
+public class BubbleTextView extends TextView {
+ static final float CORNER_RADIUS = 8.0f;
+ static final float PADDING_H = 5.0f;
+ static final float PADDING_V = 1.0f;
+
+ private final RectF mRect = new RectF();
+ private Paint mPaint;
+
+ private boolean mBackgroundSizeChanged;
+ private Drawable mBackground;
+ private float mCornerRadius;
+ private float mPaddingH;
+ private float mPaddingV;
+
+ public BubbleTextView(Context context) {
+ super(context);
+ init();
+ }
+
+ public BubbleTextView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init();
+ }
+
+ public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ init();
+ }
+
+ private void init() {
+ setFocusable(true);
+ mBackground = getBackground();
+ setBackgroundDrawable(null);
+
+ mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+ mPaint.setColor(getContext().getResources().getColor(R.color.bubble_dark_background));
+
+ final float scale = getContext().getResources().getDisplayMetrics().density;
+ mCornerRadius = CORNER_RADIUS * scale;
+ mPaddingH = PADDING_H * scale;
+ //noinspection PointlessArithmeticExpression
+ mPaddingV = PADDING_V * scale;
+ }
+
+ @Override
+ protected boolean setFrame(int left, int top, int right, int bottom) {
+ if (mLeft != left || mRight != right || mTop != top || mBottom != bottom) {
+ mBackgroundSizeChanged = true;
+ }
+ return super.setFrame(left, top, right, bottom);
+ }
+
+ @Override
+ protected boolean verifyDrawable(Drawable who) {
+ return who == mBackground || super.verifyDrawable(who);
+ }
+
+ @Override
+ protected void drawableStateChanged() {
+ Drawable d = mBackground;
+ if (d != null && d.isStateful()) {
+ d.setState(getDrawableState());
+ }
+ super.drawableStateChanged();
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ final Drawable background = mBackground;
+ if (background != null) {
+ final int scrollX = mScrollX;
+ final int scrollY = mScrollY;
+
+ if (mBackgroundSizeChanged) {
+ background.setBounds(0, 0, mRight - mLeft, mBottom - mTop);
+ mBackgroundSizeChanged = false;
+ }
+
+ if ((scrollX | scrollY) == 0) {
+ background.draw(canvas);
+ } else {
+ canvas.translate(scrollX, scrollY);
+ background.draw(canvas);
+ canvas.translate(-scrollX, -scrollY);
+ }
+ }
+
+ final Layout layout = getLayout();
+ final RectF rect = mRect;
+ final int left = getCompoundPaddingLeft();
+ final int top = getExtendedPaddingTop();
+
+ rect.set(left + layout.getLineLeft(0) - mPaddingH,
+ top + layout.getLineTop(0) - mPaddingV,
+ Math.min(left + layout.getLineRight(0) + mPaddingH, mScrollX + mRight - mLeft),
+ top + layout.getLineBottom(0) + mPaddingV);
+ canvas.drawRoundRect(rect, mCornerRadius, mCornerRadius, mPaint);
+
+ super.draw(canvas);
+ }
+
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ mBackground.setCallback(this);
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+ mBackground.setCallback(null);
+ }
+}
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
new file mode 100644
index 0000000..6970875
--- /dev/null
+++ b/src/com/android/launcher2/CellLayout.java
@@ -0,0 +1,1095 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.content.res.Resources;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Canvas;
+import android.util.AttributeSet;
+import android.view.ContextMenu;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewDebug;
+import android.view.ViewGroup;
+import android.app.WallpaperManager;
+
+import java.util.ArrayList;
+
+public class CellLayout extends ViewGroup {
+ private boolean mPortrait;
+
+ private int mCellWidth;
+ private int mCellHeight;
+
+ private int mLongAxisStartPadding;
+ private int mLongAxisEndPadding;
+
+ private int mShortAxisStartPadding;
+ private int mShortAxisEndPadding;
+
+ private int mShortAxisCells;
+ private int mLongAxisCells;
+
+ private int mWidthGap;
+ private int mHeightGap;
+
+ private final Rect mRect = new Rect();
+ private final CellInfo mCellInfo = new CellInfo();
+
+ int[] mCellXY = new int[2];
+ boolean[][] mOccupied;
+
+ private RectF mDragRect = new RectF();
+
+ private boolean mDirtyTag;
+ private boolean mLastDownOnOccupiedCell = false;
+
+ private final WallpaperManager mWallpaperManager;
+
+ public CellLayout(Context context) {
+ this(context, null);
+ }
+
+ public CellLayout(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public CellLayout(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);
+
+ mCellWidth = a.getDimensionPixelSize(R.styleable.CellLayout_cellWidth, 10);
+ mCellHeight = a.getDimensionPixelSize(R.styleable.CellLayout_cellHeight, 10);
+
+ mLongAxisStartPadding =
+ a.getDimensionPixelSize(R.styleable.CellLayout_longAxisStartPadding, 10);
+ mLongAxisEndPadding =
+ a.getDimensionPixelSize(R.styleable.CellLayout_longAxisEndPadding, 10);
+ mShortAxisStartPadding =
+ a.getDimensionPixelSize(R.styleable.CellLayout_shortAxisStartPadding, 10);
+ mShortAxisEndPadding =
+ a.getDimensionPixelSize(R.styleable.CellLayout_shortAxisEndPadding, 10);
+
+ mShortAxisCells = a.getInt(R.styleable.CellLayout_shortAxisCells, 4);
+ mLongAxisCells = a.getInt(R.styleable.CellLayout_longAxisCells, 4);
+
+ a.recycle();
+
+ setAlwaysDrawnWithCacheEnabled(false);
+
+ if (mOccupied == null) {
+ if (mPortrait) {
+ mOccupied = new boolean[mShortAxisCells][mLongAxisCells];
+ } else {
+ mOccupied = new boolean[mLongAxisCells][mShortAxisCells];
+ }
+ }
+
+ mWallpaperManager = WallpaperManager.getInstance(getContext());
+ }
+
+ @Override
+ public void dispatchDraw(Canvas canvas) {
+ super.dispatchDraw(canvas);
+ }
+
+ @Override
+ public void cancelLongPress() {
+ super.cancelLongPress();
+
+ // Cancel long press for all children
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ final View child = getChildAt(i);
+ child.cancelLongPress();
+ }
+ }
+
+ int getCountX() {
+ return mPortrait ? mShortAxisCells : mLongAxisCells;
+ }
+
+ int getCountY() {
+ return mPortrait ? mLongAxisCells : mShortAxisCells;
+ }
+
+ @Override
+ public void addView(View child, int index, ViewGroup.LayoutParams params) {
+ // Generate an id for each view, this assumes we have at most 256x256 cells
+ // per workspace screen
+ final LayoutParams cellParams = (LayoutParams) params;
+ cellParams.regenerateId = true;
+
+ super.addView(child, index, params);
+ }
+
+ @Override
+ public void requestChildFocus(View child, View focused) {
+ super.requestChildFocus(child, focused);
+ if (child != null) {
+ Rect r = new Rect();
+ child.getDrawingRect(r);
+ requestRectangleOnScreen(r);
+ }
+ }
+
+ @Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ mCellInfo.screen = ((ViewGroup) getParent()).indexOfChild(this);
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ final int action = ev.getAction();
+ final CellInfo cellInfo = mCellInfo;
+
+ if (action == MotionEvent.ACTION_DOWN) {
+ final Rect frame = mRect;
+ final int x = (int) ev.getX() + mScrollX;
+ final int y = (int) ev.getY() + mScrollY;
+ final int count = getChildCount();
+
+ boolean found = false;
+ for (int i = count - 1; i >= 0; i--) {
+ final View child = getChildAt(i);
+
+ if ((child.getVisibility()) == VISIBLE || child.getAnimation() != null) {
+ child.getHitRect(frame);
+ if (frame.contains(x, y)) {
+ final LayoutParams lp = (LayoutParams) child.getLayoutParams();
+ cellInfo.cell = child;
+ cellInfo.cellX = lp.cellX;
+ cellInfo.cellY = lp.cellY;
+ cellInfo.spanX = lp.cellHSpan;
+ cellInfo.spanY = lp.cellVSpan;
+ cellInfo.valid = true;
+ found = true;
+ mDirtyTag = false;
+ break;
+ }
+ }
+ }
+
+ mLastDownOnOccupiedCell = found;
+
+ if (!found) {
+ int cellXY[] = mCellXY;
+ pointToCellExact(x, y, cellXY);
+
+ final boolean portrait = mPortrait;
+ final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
+ final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+
+ final boolean[][] occupied = mOccupied;
+ findOccupiedCells(xCount, yCount, occupied, null);
+
+ cellInfo.cell = null;
+ cellInfo.cellX = cellXY[0];
+ cellInfo.cellY = cellXY[1];
+ cellInfo.spanX = 1;
+ cellInfo.spanY = 1;
+ cellInfo.valid = cellXY[0] >= 0 && cellXY[1] >= 0 && cellXY[0] < xCount &&
+ cellXY[1] < yCount && !occupied[cellXY[0]][cellXY[1]];
+
+ // Instead of finding the interesting vacant cells here, wait until a
+ // caller invokes getTag() to retrieve the result. Finding the vacant
+ // cells is a bit expensive and can generate many new objects, it's
+ // therefore better to defer it until we know we actually need it.
+
+ mDirtyTag = true;
+ }
+ setTag(cellInfo);
+ } else if (action == MotionEvent.ACTION_UP) {
+ cellInfo.cell = null;
+ cellInfo.cellX = -1;
+ cellInfo.cellY = -1;
+ cellInfo.spanX = 0;
+ cellInfo.spanY = 0;
+ cellInfo.valid = false;
+ mDirtyTag = false;
+ setTag(cellInfo);
+ }
+
+ return false;
+ }
+
+ @Override
+ public CellInfo getTag() {
+ final CellInfo info = (CellInfo) super.getTag();
+ if (mDirtyTag && info.valid) {
+ final boolean portrait = mPortrait;
+ final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
+ final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+
+ final boolean[][] occupied = mOccupied;
+ findOccupiedCells(xCount, yCount, occupied, null);
+
+ findIntersectingVacantCells(info, info.cellX, info.cellY, xCount, yCount, occupied);
+
+ mDirtyTag = false;
+ }
+ return info;
+ }
+
+ private static void findIntersectingVacantCells(CellInfo cellInfo, int x, int y,
+ int xCount, int yCount, boolean[][] occupied) {
+
+ cellInfo.maxVacantSpanX = Integer.MIN_VALUE;
+ cellInfo.maxVacantSpanXSpanY = Integer.MIN_VALUE;
+ cellInfo.maxVacantSpanY = Integer.MIN_VALUE;
+ cellInfo.maxVacantSpanYSpanX = Integer.MIN_VALUE;
+ cellInfo.clearVacantCells();
+
+ if (occupied[x][y]) {
+ return;
+ }
+
+ cellInfo.current.set(x, y, x, y);
+
+ findVacantCell(cellInfo.current, xCount, yCount, occupied, cellInfo);
+ }
+
+ private static void findVacantCell(Rect current, int xCount, int yCount, boolean[][] occupied,
+ CellInfo cellInfo) {
+
+ addVacantCell(current, cellInfo);
+
+ if (current.left > 0) {
+ if (isColumnEmpty(current.left - 1, current.top, current.bottom, occupied)) {
+ current.left--;
+ findVacantCell(current, xCount, yCount, occupied, cellInfo);
+ current.left++;
+ }
+ }
+
+ if (current.right < xCount - 1) {
+ if (isColumnEmpty(current.right + 1, current.top, current.bottom, occupied)) {
+ current.right++;
+ findVacantCell(current, xCount, yCount, occupied, cellInfo);
+ current.right--;
+ }
+ }
+
+ if (current.top > 0) {
+ if (isRowEmpty(current.top - 1, current.left, current.right, occupied)) {
+ current.top--;
+ findVacantCell(current, xCount, yCount, occupied, cellInfo);
+ current.top++;
+ }
+ }
+
+ if (current.bottom < yCount - 1) {
+ if (isRowEmpty(current.bottom + 1, current.left, current.right, occupied)) {
+ current.bottom++;
+ findVacantCell(current, xCount, yCount, occupied, cellInfo);
+ current.bottom--;
+ }
+ }
+ }
+
+ private static void addVacantCell(Rect current, CellInfo cellInfo) {
+ CellInfo.VacantCell cell = CellInfo.VacantCell.acquire();
+ cell.cellX = current.left;
+ cell.cellY = current.top;
+ cell.spanX = current.right - current.left + 1;
+ cell.spanY = current.bottom - current.top + 1;
+ if (cell.spanX > cellInfo.maxVacantSpanX) {
+ cellInfo.maxVacantSpanX = cell.spanX;
+ cellInfo.maxVacantSpanXSpanY = cell.spanY;
+ }
+ if (cell.spanY > cellInfo.maxVacantSpanY) {
+ cellInfo.maxVacantSpanY = cell.spanY;
+ cellInfo.maxVacantSpanYSpanX = cell.spanX;
+ }
+ cellInfo.vacantCells.add(cell);
+ }
+
+ private static boolean isColumnEmpty(int x, int top, int bottom, boolean[][] occupied) {
+ for (int y = top; y <= bottom; y++) {
+ if (occupied[x][y]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean isRowEmpty(int y, int left, int right, boolean[][] occupied) {
+ for (int x = left; x <= right; x++) {
+ if (occupied[x][y]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ CellInfo findAllVacantCells(boolean[] occupiedCells, View ignoreView) {
+ final boolean portrait = mPortrait;
+ final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
+ final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+
+ boolean[][] occupied = mOccupied;
+
+ if (occupiedCells != null) {
+ for (int y = 0; y < yCount; y++) {
+ for (int x = 0; x < xCount; x++) {
+ occupied[x][y] = occupiedCells[y * xCount + x];
+ }
+ }
+ } else {
+ findOccupiedCells(xCount, yCount, occupied, ignoreView);
+ }
+
+ CellInfo cellInfo = new CellInfo();
+
+ cellInfo.cellX = -1;
+ cellInfo.cellY = -1;
+ cellInfo.spanY = 0;
+ cellInfo.spanX = 0;
+ cellInfo.maxVacantSpanX = Integer.MIN_VALUE;
+ cellInfo.maxVacantSpanXSpanY = Integer.MIN_VALUE;
+ cellInfo.maxVacantSpanY = Integer.MIN_VALUE;
+ cellInfo.maxVacantSpanYSpanX = Integer.MIN_VALUE;
+ cellInfo.screen = mCellInfo.screen;
+
+ Rect current = cellInfo.current;
+
+ for (int x = 0; x < xCount; x++) {
+ for (int y = 0; y < yCount; y++) {
+ if (!occupied[x][y]) {
+ current.set(x, y, x, y);
+ findVacantCell(current, xCount, yCount, occupied, cellInfo);
+ occupied[x][y] = true;
+ }
+ }
+ }
+
+ cellInfo.valid = cellInfo.vacantCells.size() > 0;
+
+ // Assume the caller will perform their own cell searching, otherwise we
+ // risk causing an unnecessary rebuild after findCellForSpan()
+
+ return cellInfo;
+ }
+
+ /**
+ * Given a point, return the cell that strictly encloses that point
+ * @param x X coordinate of the point
+ * @param y Y coordinate of the point
+ * @param result Array of 2 ints to hold the x and y coordinate of the cell
+ */
+ void pointToCellExact(int x, int y, int[] result) {
+ final boolean portrait = mPortrait;
+
+ final int hStartPadding = portrait ? mShortAxisStartPadding : mLongAxisStartPadding;
+ final int vStartPadding = portrait ? mLongAxisStartPadding : mShortAxisStartPadding;
+
+ result[0] = (x - hStartPadding) / (mCellWidth + mWidthGap);
+ result[1] = (y - vStartPadding) / (mCellHeight + mHeightGap);
+
+ final int xAxis = portrait ? mShortAxisCells : mLongAxisCells;
+ final int yAxis = portrait ? mLongAxisCells : mShortAxisCells;
+
+ if (result[0] < 0) result[0] = 0;
+ if (result[0] >= xAxis) result[0] = xAxis - 1;
+ if (result[1] < 0) result[1] = 0;
+ if (result[1] >= yAxis) result[1] = yAxis - 1;
+ }
+
+ /**
+ * Given a point, return the cell that most closely encloses that point
+ * @param x X coordinate of the point
+ * @param y Y coordinate of the point
+ * @param result Array of 2 ints to hold the x and y coordinate of the cell
+ */
+ void pointToCellRounded(int x, int y, int[] result) {
+ pointToCellExact(x + (mCellWidth / 2), y + (mCellHeight / 2), result);
+ }
+
+ /**
+ * Given a cell coordinate, return the point that represents the upper left corner of that cell
+ *
+ * @param cellX X coordinate of the cell
+ * @param cellY Y coordinate of the cell
+ *
+ * @param result Array of 2 ints to hold the x and y coordinate of the point
+ */
+ void cellToPoint(int cellX, int cellY, int[] result) {
+ final boolean portrait = mPortrait;
+
+ final int hStartPadding = portrait ? mShortAxisStartPadding : mLongAxisStartPadding;
+ final int vStartPadding = portrait ? mLongAxisStartPadding : mShortAxisStartPadding;
+
+
+ result[0] = hStartPadding + cellX * (mCellWidth + mWidthGap);
+ result[1] = vStartPadding + cellY * (mCellHeight + mHeightGap);
+ }
+
+ int getCellWidth() {
+ return mCellWidth;
+ }
+
+ int getCellHeight() {
+ return mCellHeight;
+ }
+
+ int getLeftPadding() {
+ return mPortrait ? mShortAxisStartPadding : mLongAxisStartPadding;
+ }
+
+ int getTopPadding() {
+ return mPortrait ? mLongAxisStartPadding : mShortAxisStartPadding;
+ }
+
+ int getRightPadding() {
+ return mPortrait ? mShortAxisEndPadding : mLongAxisEndPadding;
+ }
+
+ int getBottomPadding() {
+ return mPortrait ? mLongAxisEndPadding : mShortAxisEndPadding;
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ // TODO: currently ignoring padding
+
+ int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
+ int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
+
+ int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
+ int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
+
+ if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED) {
+ throw new RuntimeException("CellLayout cannot have UNSPECIFIED dimensions");
+ }
+
+ final int shortAxisCells = mShortAxisCells;
+ final int longAxisCells = mLongAxisCells;
+ final int longAxisStartPadding = mLongAxisStartPadding;
+ final int longAxisEndPadding = mLongAxisEndPadding;
+ final int shortAxisStartPadding = mShortAxisStartPadding;
+ final int shortAxisEndPadding = mShortAxisEndPadding;
+ final int cellWidth = mCellWidth;
+ final int cellHeight = mCellHeight;
+
+ mPortrait = heightSpecSize > widthSpecSize;
+
+ int numShortGaps = shortAxisCells - 1;
+ int numLongGaps = longAxisCells - 1;
+
+ if (mPortrait) {
+ int vSpaceLeft = heightSpecSize - longAxisStartPadding - longAxisEndPadding
+ - (cellHeight * longAxisCells);
+ mHeightGap = vSpaceLeft / numLongGaps;
+
+ int hSpaceLeft = widthSpecSize - shortAxisStartPadding - shortAxisEndPadding
+ - (cellWidth * shortAxisCells);
+ if (numShortGaps > 0) {
+ mWidthGap = hSpaceLeft / numShortGaps;
+ } else {
+ mWidthGap = 0;
+ }
+ } else {
+ int hSpaceLeft = widthSpecSize - longAxisStartPadding - longAxisEndPadding
+ - (cellWidth * longAxisCells);
+ mWidthGap = hSpaceLeft / numLongGaps;
+
+ int vSpaceLeft = heightSpecSize - shortAxisStartPadding - shortAxisEndPadding
+ - (cellHeight * shortAxisCells);
+ if (numShortGaps > 0) {
+ mHeightGap = vSpaceLeft / numShortGaps;
+ } else {
+ mHeightGap = 0;
+ }
+ }
+
+ int count = getChildCount();
+
+ for (int i = 0; i < count; i++) {
+ View child = getChildAt(i);
+ LayoutParams lp = (LayoutParams) child.getLayoutParams();
+
+ if (mPortrait) {
+ lp.setup(cellWidth, cellHeight, mWidthGap, mHeightGap, shortAxisStartPadding,
+ longAxisStartPadding);
+ } else {
+ lp.setup(cellWidth, cellHeight, mWidthGap, mHeightGap, longAxisStartPadding,
+ shortAxisStartPadding);
+ }
+
+ if (lp.regenerateId) {
+ child.setId(((getId() & 0xFF) << 16) | (lp.cellX & 0xFF) << 8 | (lp.cellY & 0xFF));
+ lp.regenerateId = false;
+ }
+
+ int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(lp.width, MeasureSpec.EXACTLY);
+ int childheightMeasureSpec =
+ MeasureSpec.makeMeasureSpec(lp.height, MeasureSpec.EXACTLY);
+ child.measure(childWidthMeasureSpec, childheightMeasureSpec);
+ }
+
+ setMeasuredDimension(widthSpecSize, heightSpecSize);
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int l, int t, int r, int b) {
+ int count = getChildCount();
+
+ for (int i = 0; i < count; i++) {
+ View child = getChildAt(i);
+ if (child.getVisibility() != GONE) {
+
+ CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
+
+ int childLeft = lp.x;
+ int childTop = lp.y;
+ child.layout(childLeft, childTop, childLeft + lp.width, childTop + lp.height);
+
+ if (lp.dropped) {
+ lp.dropped = false;
+
+ mWallpaperManager.sendWallpaperCommand(getWindowToken(), "android.home.drop",
+ childLeft + lp.width / 2, childTop + lp.height / 2, 0, null);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void setChildrenDrawingCacheEnabled(boolean enabled) {
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ final View view = getChildAt(i);
+ view.setDrawingCacheEnabled(enabled);
+ // Update the drawing caches
+ view.buildDrawingCache(true);
+ }
+ }
+
+ @Override
+ protected void setChildrenDrawnWithCacheEnabled(boolean enabled) {
+ super.setChildrenDrawnWithCacheEnabled(enabled);
+ }
+
+ /**
+ * Find a vacant area that will fit the given bounds nearest the requested
+ * cell location. Uses Euclidean distance to score multiple vacant areas.
+ *
+ * @param pixelX The X location at which you want to search for a vacant area.
+ * @param pixelY The Y location at which you want to search for a vacant area.
+ * @param spanX Horizontal span of the object.
+ * @param spanY Vertical span of the object.
+ * @param vacantCells Pre-computed set of vacant cells to search.
+ * @param recycle Previously returned value to possibly recycle.
+ * @return The X, Y cell of a vacant area that can contain this object,
+ * nearest the requested location.
+ */
+ int[] findNearestVacantArea(int pixelX, int pixelY, int spanX, int spanY,
+ CellInfo vacantCells, int[] recycle) {
+
+ // Keep track of best-scoring drop area
+ final int[] bestXY = recycle != null ? recycle : new int[2];
+ final int[] cellXY = mCellXY;
+ double bestDistance = Double.MAX_VALUE;
+
+ // Bail early if vacant cells aren't valid
+ if (!vacantCells.valid) {
+ return null;
+ }
+
+ // Look across all vacant cells for best fit
+ final int size = vacantCells.vacantCells.size();
+ for (int i = 0; i < size; i++) {
+ final CellInfo.VacantCell cell = vacantCells.vacantCells.get(i);
+
+ // Reject if vacant cell isn't our exact size
+ if (cell.spanX != spanX || cell.spanY != spanY) {
+ continue;
+ }
+
+ // Score is center distance from requested pixel
+ cellToPoint(cell.cellX, cell.cellY, cellXY);
+
+ double distance = Math.sqrt(Math.pow(cellXY[0] - pixelX, 2) +
+ Math.pow(cellXY[1] - pixelY, 2));
+ if (distance <= bestDistance) {
+ bestDistance = distance;
+ bestXY[0] = cell.cellX;
+ bestXY[1] = cell.cellY;
+ }
+ }
+
+ // Return null if no suitable location found
+ if (bestDistance < Double.MAX_VALUE) {
+ return bestXY;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Drop a child at the specified position
+ *
+ * @param child The child that is being dropped
+ * @param targetXY Destination area to move to
+ */
+ void onDropChild(View child, int[] targetXY) {
+ if (child != null) {
+ LayoutParams lp = (LayoutParams) child.getLayoutParams();
+ lp.cellX = targetXY[0];
+ lp.cellY = targetXY[1];
+ lp.isDragging = false;
+ lp.dropped = true;
+ mDragRect.setEmpty();
+ child.requestLayout();
+ invalidate();
+ }
+ }
+
+ void onDropAborted(View child) {
+ if (child != null) {
+ ((LayoutParams) child.getLayoutParams()).isDragging = false;
+ invalidate();
+ }
+ mDragRect.setEmpty();
+ }
+
+ /**
+ * Start dragging the specified child
+ *
+ * @param child The child that is being dragged
+ */
+ void onDragChild(View child) {
+ LayoutParams lp = (LayoutParams) child.getLayoutParams();
+ lp.isDragging = true;
+ mDragRect.setEmpty();
+ }
+
+ /**
+ * Drag a child over the specified position
+ *
+ * @param child The child that is being dropped
+ * @param cellX The child's new x cell location
+ * @param cellY The child's new y cell location
+ */
+ void onDragOverChild(View child, int cellX, int cellY) {
+ int[] cellXY = mCellXY;
+ pointToCellRounded(cellX, cellY, cellXY);
+ LayoutParams lp = (LayoutParams) child.getLayoutParams();
+ cellToRect(cellXY[0], cellXY[1], lp.cellHSpan, lp.cellVSpan, mDragRect);
+ invalidate();
+ }
+
+ /**
+ * Computes a bounding rectangle for a range of cells
+ *
+ * @param cellX X coordinate of upper left corner expressed as a cell position
+ * @param cellY Y coordinate of upper left corner expressed as a cell position
+ * @param cellHSpan Width in cells
+ * @param cellVSpan Height in cells
+ * @param dragRect Rectnagle into which to put the results
+ */
+ public void cellToRect(int cellX, int cellY, int cellHSpan, int cellVSpan, RectF dragRect) {
+ final boolean portrait = mPortrait;
+ final int cellWidth = mCellWidth;
+ final int cellHeight = mCellHeight;
+ final int widthGap = mWidthGap;
+ final int heightGap = mHeightGap;
+
+ final int hStartPadding = portrait ? mShortAxisStartPadding : mLongAxisStartPadding;
+ final int vStartPadding = portrait ? mLongAxisStartPadding : mShortAxisStartPadding;
+
+ int width = cellHSpan * cellWidth + ((cellHSpan - 1) * widthGap);
+ int height = cellVSpan * cellHeight + ((cellVSpan - 1) * heightGap);
+
+ int x = hStartPadding + cellX * (cellWidth + widthGap);
+ int y = vStartPadding + cellY * (cellHeight + heightGap);
+
+ dragRect.set(x, y, x + width, y + height);
+ }
+
+ /**
+ * Computes the required horizontal and vertical cell spans to always
+ * fit the given rectangle.
+ *
+ * @param width Width in pixels
+ * @param height Height in pixels
+ */
+ public int[] rectToCell(int width, int height) {
+ // Always assume we're working with the smallest span to make sure we
+ // reserve enough space in both orientations.
+ final Resources resources = getResources();
+ int actualWidth = resources.getDimensionPixelSize(R.dimen.workspace_cell_width);
+ int actualHeight = resources.getDimensionPixelSize(R.dimen.workspace_cell_height);
+ int smallerSize = Math.min(actualWidth, actualHeight);
+
+ // Always round up to next largest cell
+ int spanX = (width + smallerSize) / smallerSize;
+ int spanY = (height + smallerSize) / smallerSize;
+
+ return new int[] { spanX, spanY };
+ }
+
+ /**
+ * Find the first vacant cell, if there is one.
+ *
+ * @param vacant Holds the x and y coordinate of the vacant cell
+ * @param spanX Horizontal cell span.
+ * @param spanY Vertical cell span.
+ *
+ * @return True if a vacant cell was found
+ */
+ public boolean getVacantCell(int[] vacant, int spanX, int spanY) {
+ final boolean portrait = mPortrait;
+ final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
+ final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+ final boolean[][] occupied = mOccupied;
+
+ findOccupiedCells(xCount, yCount, occupied, null);
+
+ return findVacantCell(vacant, spanX, spanY, xCount, yCount, occupied);
+ }
+
+ static boolean findVacantCell(int[] vacant, int spanX, int spanY,
+ int xCount, int yCount, boolean[][] occupied) {
+
+ for (int x = 0; x < xCount; x++) {
+ for (int y = 0; y < yCount; y++) {
+ boolean available = !occupied[x][y];
+out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
+ for (int j = y; j < y + spanY - 1 && y < yCount; j++) {
+ available = available && !occupied[i][j];
+ if (!available) break out;
+ }
+ }
+
+ if (available) {
+ vacant[0] = x;
+ vacant[1] = y;
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ boolean[] getOccupiedCells() {
+ final boolean portrait = mPortrait;
+ final int xCount = portrait ? mShortAxisCells : mLongAxisCells;
+ final int yCount = portrait ? mLongAxisCells : mShortAxisCells;
+ final boolean[][] occupied = mOccupied;
+
+ findOccupiedCells(xCount, yCount, occupied, null);
+
+ final boolean[] flat = new boolean[xCount * yCount];
+ for (int y = 0; y < yCount; y++) {
+ for (int x = 0; x < xCount; x++) {
+ flat[y * xCount + x] = occupied[x][y];
+ }
+ }
+
+ return flat;
+ }
+
+ private void findOccupiedCells(int xCount, int yCount, boolean[][] occupied, View ignoreView) {
+ for (int x = 0; x < xCount; x++) {
+ for (int y = 0; y < yCount; y++) {
+ occupied[x][y] = false;
+ }
+ }
+
+ int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ View child = getChildAt(i);
+ if (child instanceof Folder || child.equals(ignoreView)) {
+ continue;
+ }
+ LayoutParams lp = (LayoutParams) child.getLayoutParams();
+
+ for (int x = lp.cellX; x < lp.cellX + lp.cellHSpan && x < xCount; x++) {
+ for (int y = lp.cellY; y < lp.cellY + lp.cellVSpan && y < yCount; y++) {
+ occupied[x][y] = true;
+ }
+ }
+ }
+ }
+
+ @Override
+ public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
+ return new CellLayout.LayoutParams(getContext(), attrs);
+ }
+
+ @Override
+ protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
+ return p instanceof CellLayout.LayoutParams;
+ }
+
+ @Override
+ protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
+ return new CellLayout.LayoutParams(p);
+ }
+
+ public static class LayoutParams extends ViewGroup.MarginLayoutParams {
+ /**
+ * Horizontal location of the item in the grid.
+ */
+ @ViewDebug.ExportedProperty
+ public int cellX;
+
+ /**
+ * Vertical location of the item in the grid.
+ */
+ @ViewDebug.ExportedProperty
+ public int cellY;
+
+ /**
+ * Number of cells spanned horizontally by the item.
+ */
+ @ViewDebug.ExportedProperty
+ public int cellHSpan;
+
+ /**
+ * Number of cells spanned vertically by the item.
+ */
+ @ViewDebug.ExportedProperty
+ public int cellVSpan;
+
+ /**
+ * Is this item currently being dragged
+ */
+ public boolean isDragging;
+
+ // X coordinate of the view in the layout.
+ @ViewDebug.ExportedProperty
+ int x;
+ // Y coordinate of the view in the layout.
+ @ViewDebug.ExportedProperty
+ int y;
+
+ boolean regenerateId;
+
+ boolean dropped;
+
+ public LayoutParams(Context c, AttributeSet attrs) {
+ super(c, attrs);
+ cellHSpan = 1;
+ cellVSpan = 1;
+ }
+
+ public LayoutParams(ViewGroup.LayoutParams source) {
+ super(source);
+ cellHSpan = 1;
+ cellVSpan = 1;
+ }
+
+ public LayoutParams(int cellX, int cellY, int cellHSpan, int cellVSpan) {
+ super(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
+ this.cellX = cellX;
+ this.cellY = cellY;
+ this.cellHSpan = cellHSpan;
+ this.cellVSpan = cellVSpan;
+ }
+
+ public void setup(int cellWidth, int cellHeight, int widthGap, int heightGap,
+ int hStartPadding, int vStartPadding) {
+
+ final int myCellHSpan = cellHSpan;
+ final int myCellVSpan = cellVSpan;
+ final int myCellX = cellX;
+ final int myCellY = cellY;
+
+ width = myCellHSpan * cellWidth + ((myCellHSpan - 1) * widthGap) -
+ leftMargin - rightMargin;
+ height = myCellVSpan * cellHeight + ((myCellVSpan - 1) * heightGap) -
+ topMargin - bottomMargin;
+
+ x = hStartPadding + myCellX * (cellWidth + widthGap) + leftMargin;
+ y = vStartPadding + myCellY * (cellHeight + heightGap) + topMargin;
+ }
+ }
+
+ static final class CellInfo implements ContextMenu.ContextMenuInfo {
+ /**
+ * See View.AttachInfo.InvalidateInfo for futher explanations about
+ * the recycling mechanism. In this case, we recycle the vacant cells
+ * instances because up to several hundreds can be instanciated when
+ * the user long presses an empty cell.
+ */
+ static final class VacantCell {
+ int cellX;
+ int cellY;
+ int spanX;
+ int spanY;
+
+ // We can create up to 523 vacant cells on a 4x4 grid, 100 seems
+ // like a reasonable compromise given the size of a VacantCell and
+ // the fact that the user is not likely to touch an empty 4x4 grid
+ // very often
+ private static final int POOL_LIMIT = 100;
+ private static final Object sLock = new Object();
+
+ private static int sAcquiredCount = 0;
+ private static VacantCell sRoot;
+
+ private VacantCell next;
+
+ static VacantCell acquire() {
+ synchronized (sLock) {
+ if (sRoot == null) {
+ return new VacantCell();
+ }
+
+ VacantCell info = sRoot;
+ sRoot = info.next;
+ sAcquiredCount--;
+
+ return info;
+ }
+ }
+
+ void release() {
+ synchronized (sLock) {
+ if (sAcquiredCount < POOL_LIMIT) {
+ sAcquiredCount++;
+ next = sRoot;
+ sRoot = this;
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "VacantCell[x=" + cellX + ", y=" + cellY + ", spanX=" + spanX +
+ ", spanY=" + spanY + "]";
+ }
+ }
+
+ View cell;
+ int cellX;
+ int cellY;
+ int spanX;
+ int spanY;
+ int screen;
+ boolean valid;
+
+ final ArrayList<VacantCell> vacantCells = new ArrayList<VacantCell>(VacantCell.POOL_LIMIT);
+ int maxVacantSpanX;
+ int maxVacantSpanXSpanY;
+ int maxVacantSpanY;
+ int maxVacantSpanYSpanX;
+ final Rect current = new Rect();
+
+ void clearVacantCells() {
+ final ArrayList<VacantCell> list = vacantCells;
+ final int count = list.size();
+
+ for (int i = 0; i < count; i++) list.get(i).release();
+
+ list.clear();
+ }
+
+ void findVacantCellsFromOccupied(boolean[] occupied, int xCount, int yCount) {
+ if (cellX < 0 || cellY < 0) {
+ maxVacantSpanX = maxVacantSpanXSpanY = Integer.MIN_VALUE;
+ maxVacantSpanY = maxVacantSpanYSpanX = Integer.MIN_VALUE;
+ clearVacantCells();
+ return;
+ }
+
+ final boolean[][] unflattened = new boolean[xCount][yCount];
+ for (int y = 0; y < yCount; y++) {
+ for (int x = 0; x < xCount; x++) {
+ unflattened[x][y] = occupied[y * xCount + x];
+ }
+ }
+ CellLayout.findIntersectingVacantCells(this, cellX, cellY, xCount, yCount, unflattened);
+ }
+
+ /**
+ * This method can be called only once! Calling #findVacantCellsFromOccupied will
+ * restore the ability to call this method.
+ *
+ * Finds the upper-left coordinate of the first rectangle in the grid that can
+ * hold a cell of the specified dimensions.
+ *
+ * @param cellXY The array that will contain the position of a vacant cell if such a cell
+ * can be found.
+ * @param spanX The horizontal span of the cell we want to find.
+ * @param spanY The vertical span of the cell we want to find.
+ *
+ * @return True if a vacant cell of the specified dimension was found, false otherwise.
+ */
+ boolean findCellForSpan(int[] cellXY, int spanX, int spanY) {
+ return findCellForSpan(cellXY, spanX, spanY, true);
+ }
+
+ boolean findCellForSpan(int[] cellXY, int spanX, int spanY, boolean clear) {
+ final ArrayList<VacantCell> list = vacantCells;
+ final int count = list.size();
+
+ boolean found = false;
+
+ if (this.spanX >= spanX && this.spanY >= spanY) {
+ cellXY[0] = cellX;
+ cellXY[1] = cellY;
+ found = true;
+ }
+
+ // Look for an exact match first
+ for (int i = 0; i < count; i++) {
+ VacantCell cell = list.get(i);
+ if (cell.spanX == spanX && cell.spanY == spanY) {
+ cellXY[0] = cell.cellX;
+ cellXY[1] = cell.cellY;
+ found = true;
+ break;
+ }
+ }
+
+ // Look for the first cell large enough
+ for (int i = 0; i < count; i++) {
+ VacantCell cell = list.get(i);
+ if (cell.spanX >= spanX && cell.spanY >= spanY) {
+ cellXY[0] = cell.cellX;
+ cellXY[1] = cell.cellY;
+ found = true;
+ break;
+ }
+ }
+
+ if (clear) clearVacantCells();
+
+ return found;
+ }
+
+ @Override
+ public String toString() {
+ return "Cell[view=" + (cell == null ? "null" : cell.getClass()) + ", x=" + cellX +
+ ", y=" + cellY + "]";
+ }
+ }
+
+ public boolean lastDownOnOccupiedCell() {
+ return mLastDownOnOccupiedCell;
+ }
+}
+
+
diff --git a/src/com/android/launcher2/DeferredHandler.java b/src/com/android/launcher2/DeferredHandler.java
new file mode 100644
index 0000000..ce60352
--- /dev/null
+++ b/src/com/android/launcher2/DeferredHandler.java
@@ -0,0 +1,107 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.os.MessageQueue;
+import android.util.Log;
+
+import java.util.LinkedList;
+
+/**
+ * Queue of things to run on a looper thread. Items posted with {@link #post} will not
+ * be actually enqued on the handler until after the last one has run, to keep from
+ * starving the thread.
+ *
+ * This class is fifo.
+ */
+public class DeferredHandler {
+ private LinkedList<Runnable> mQueue = new LinkedList();
+ private MessageQueue mMessageQueue = Looper.myQueue();
+ private Impl mHandler = new Impl();
+
+ private class Impl extends Handler implements MessageQueue.IdleHandler {
+ public void handleMessage(Message msg) {
+ Runnable r;
+ synchronized (mQueue) {
+ if (mQueue.size() == 0) {
+ return;
+ }
+ r = mQueue.removeFirst();
+ }
+ r.run();
+ synchronized (mQueue) {
+ scheduleNextLocked();
+ }
+ }
+
+ public boolean queueIdle() {
+ handleMessage(null);
+ return false;
+ }
+ }
+
+ private class IdleRunnable implements Runnable {
+ Runnable mRunnable;
+
+ IdleRunnable(Runnable r) {
+ mRunnable = r;
+ }
+
+ public void run() {
+ mRunnable.run();
+ }
+ }
+
+ public DeferredHandler() {
+ }
+
+ /** Schedule runnable to run after everything that's on the queue right now. */
+ public void post(Runnable runnable) {
+ synchronized (mQueue) {
+ mQueue.add(runnable);
+ if (mQueue.size() == 1) {
+ scheduleNextLocked();
+ }
+ }
+ }
+
+ /** Schedule runnable to run when the queue goes idle. */
+ public void postIdle(final Runnable runnable) {
+ post(new IdleRunnable(runnable));
+ }
+
+ public void cancel() {
+ synchronized (mQueue) {
+ mQueue.clear();
+ }
+ }
+
+ void scheduleNextLocked() {
+ if (mQueue.size() > 0) {
+ Runnable peek = mQueue.getFirst();
+ if (peek instanceof IdleRunnable) {
+ mMessageQueue.addIdleHandler(mHandler);
+ } else {
+ mHandler.sendEmptyMessage(1);
+ }
+ }
+ }
+}
+
diff --git a/src/com/android/launcher2/DeleteZone.java b/src/com/android/launcher2/DeleteZone.java
new file mode 100644
index 0000000..ec4bc53
--- /dev/null
+++ b/src/com/android/launcher2/DeleteZone.java
@@ -0,0 +1,271 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.widget.ImageView;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
+import android.graphics.Rect;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.animation.TranslateAnimation;
+import android.view.animation.Animation;
+import android.view.animation.AnimationSet;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.AlphaAnimation;
+import android.graphics.RectF;
+import android.graphics.drawable.TransitionDrawable;
+
+public class DeleteZone extends ImageView implements DropTarget, DragController.DragListener {
+ private static final int ORIENTATION_HORIZONTAL = 1;
+ private static final int TRANSITION_DURATION = 250;
+ private static final int ANIMATION_DURATION = 200;
+
+ private final int[] mLocation = new int[2];
+
+ private Launcher mLauncher;
+ private boolean mTrashMode;
+
+ private AnimationSet mInAnimation;
+ private AnimationSet mOutAnimation;
+ private Animation mHandleInAnimation;
+ private Animation mHandleOutAnimation;
+
+ private int mOrientation;
+ private DragController mDragController;
+
+ private final RectF mRegion = new RectF();
+ private TransitionDrawable mTransition;
+ private View mHandle;
+ private final Paint mTrashPaint = new Paint();
+
+ public DeleteZone(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public DeleteZone(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ final int srcColor = context.getResources().getColor(R.color.delete_color_filter);
+ mTrashPaint.setColorFilter(new PorterDuffColorFilter(srcColor, PorterDuff.Mode.SRC_ATOP));
+
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DeleteZone, defStyle, 0);
+ mOrientation = a.getInt(R.styleable.DeleteZone_direction, ORIENTATION_HORIZONTAL);
+ a.recycle();
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+ mTransition = (TransitionDrawable) getDrawable();
+ }
+
+ public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ return true;
+ }
+
+ public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo, Rect recycle) {
+ return null;
+ }
+
+ public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ final ItemInfo item = (ItemInfo) dragInfo;
+
+ if (item.container == -1) return;
+
+ if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
+ if (item instanceof LauncherAppWidgetInfo) {
+ mLauncher.removeAppWidget((LauncherAppWidgetInfo) item);
+ }
+ } else {
+ if (source instanceof UserFolder) {
+ final UserFolder userFolder = (UserFolder) source;
+ final UserFolderInfo userFolderInfo = (UserFolderInfo) userFolder.getInfo();
+ // item must be an ApplicationInfo otherwise it couldn't have been in the folder
+ // in the first place.
+ userFolderInfo.remove((ApplicationInfo)item);
+ }
+ }
+ if (item instanceof UserFolderInfo) {
+ final UserFolderInfo userFolderInfo = (UserFolderInfo)item;
+ LauncherModel.deleteUserFolderContentsFromDatabase(mLauncher, userFolderInfo);
+ mLauncher.removeFolder(userFolderInfo);
+ } else if (item instanceof LauncherAppWidgetInfo) {
+ final LauncherAppWidgetInfo launcherAppWidgetInfo = (LauncherAppWidgetInfo) item;
+ final LauncherAppWidgetHost appWidgetHost = mLauncher.getAppWidgetHost();
+ if (appWidgetHost != null) {
+ appWidgetHost.deleteAppWidgetId(launcherAppWidgetInfo.appWidgetId);
+ }
+ }
+ LauncherModel.deleteItemFromDatabase(mLauncher, item);
+ }
+
+ public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ mTransition.reverseTransition(TRANSITION_DURATION);
+ dragView.setPaint(mTrashPaint);
+ }
+
+ public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+
+ public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ mTransition.reverseTransition(TRANSITION_DURATION);
+ dragView.setPaint(null);
+ }
+
+ public void onDragStart(DragSource source, Object info, int dragAction) {
+ final ItemInfo item = (ItemInfo) info;
+ if (item != null) {
+ mTrashMode = true;
+ createAnimations();
+ final int[] location = mLocation;
+ getLocationOnScreen(location);
+ mRegion.set(location[0], location[1], location[0] + mRight - mLeft,
+ location[1] + mBottom - mTop);
+ mDragController.setDeleteRegion(mRegion);
+ mTransition.resetTransition();
+ startAnimation(mInAnimation);
+ mHandle.startAnimation(mHandleOutAnimation);
+ setVisibility(VISIBLE);
+ }
+ }
+
+ public void onDragEnd() {
+ if (mTrashMode) {
+ mTrashMode = false;
+ mDragController.setDeleteRegion(null);
+ startAnimation(mOutAnimation);
+ mHandle.startAnimation(mHandleInAnimation);
+ setVisibility(GONE);
+ }
+ }
+
+ private void createAnimations() {
+ if (mInAnimation == null) {
+ mInAnimation = new FastAnimationSet();
+ final AnimationSet animationSet = mInAnimation;
+ animationSet.setInterpolator(new AccelerateInterpolator());
+ animationSet.addAnimation(new AlphaAnimation(0.0f, 1.0f));
+ if (mOrientation == ORIENTATION_HORIZONTAL) {
+ animationSet.addAnimation(new TranslateAnimation(Animation.ABSOLUTE, 0.0f,
+ Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f,
+ Animation.RELATIVE_TO_SELF, 0.0f));
+ } else {
+ animationSet.addAnimation(new TranslateAnimation(Animation.RELATIVE_TO_SELF,
+ 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.ABSOLUTE, 0.0f,
+ Animation.ABSOLUTE, 0.0f));
+ }
+ animationSet.setDuration(ANIMATION_DURATION);
+ }
+ if (mHandleInAnimation == null) {
+ if (mOrientation == ORIENTATION_HORIZONTAL) {
+ mHandleInAnimation = new TranslateAnimation(Animation.ABSOLUTE, 0.0f,
+ Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f,
+ Animation.RELATIVE_TO_SELF, 0.0f);
+ } else {
+ mHandleInAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
+ 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.ABSOLUTE, 0.0f,
+ Animation.ABSOLUTE, 0.0f);
+ }
+ mHandleInAnimation.setDuration(ANIMATION_DURATION);
+ }
+ if (mOutAnimation == null) {
+ mOutAnimation = new FastAnimationSet();
+ final AnimationSet animationSet = mOutAnimation;
+ animationSet.setInterpolator(new AccelerateInterpolator());
+ animationSet.addAnimation(new AlphaAnimation(1.0f, 0.0f));
+ if (mOrientation == ORIENTATION_HORIZONTAL) {
+ animationSet.addAnimation(new FastTranslateAnimation(Animation.ABSOLUTE, 0.0f,
+ Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
+ Animation.RELATIVE_TO_SELF, 1.0f));
+ } else {
+ animationSet.addAnimation(new FastTranslateAnimation(Animation.RELATIVE_TO_SELF,
+ 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.ABSOLUTE, 0.0f,
+ Animation.ABSOLUTE, 0.0f));
+ }
+ animationSet.setDuration(ANIMATION_DURATION);
+ }
+ if (mHandleOutAnimation == null) {
+ if (mOrientation == ORIENTATION_HORIZONTAL) {
+ mHandleOutAnimation = new FastTranslateAnimation(Animation.ABSOLUTE, 0.0f,
+ Animation.ABSOLUTE, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
+ Animation.RELATIVE_TO_SELF, 1.0f);
+ } else {
+ mHandleOutAnimation = new FastTranslateAnimation(Animation.RELATIVE_TO_SELF,
+ 0.0f, Animation.RELATIVE_TO_SELF, 1.0f, Animation.ABSOLUTE, 0.0f,
+ Animation.ABSOLUTE, 0.0f);
+ }
+ mHandleOutAnimation.setFillAfter(true);
+ mHandleOutAnimation.setDuration(ANIMATION_DURATION);
+ }
+ }
+
+ void setLauncher(Launcher launcher) {
+ mLauncher = launcher;
+ }
+
+ void setDragController(DragController dragController) {
+ mDragController = dragController;
+ }
+
+ void setHandle(View view) {
+ mHandle = view;
+ }
+
+ private static class FastTranslateAnimation extends TranslateAnimation {
+ public FastTranslateAnimation(int fromXType, float fromXValue, int toXType, float toXValue,
+ int fromYType, float fromYValue, int toYType, float toYValue) {
+ super(fromXType, fromXValue, toXType, toXValue,
+ fromYType, fromYValue, toYType, toYValue);
+ }
+
+ @Override
+ public boolean willChangeTransformationMatrix() {
+ return true;
+ }
+
+ @Override
+ public boolean willChangeBounds() {
+ return false;
+ }
+ }
+
+ private static class FastAnimationSet extends AnimationSet {
+ FastAnimationSet() {
+ super(false);
+ }
+
+ @Override
+ public boolean willChangeTransformationMatrix() {
+ return true;
+ }
+
+ @Override
+ public boolean willChangeBounds() {
+ return false;
+ }
+ }
+}
diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java
new file mode 100644
index 0000000..590ca69
--- /dev/null
+++ b/src/com/android/launcher2/DragController.java
@@ -0,0 +1,577 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Matrix;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.os.IBinder;
+import android.os.Handler;
+import android.os.Vibrator;
+import android.os.SystemClock;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.WindowManager;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+
+import java.util.ArrayList;
+
+/**
+ * Class for initiating a drag within a view or across multiple views.
+ */
+public class DragController {
+ private static final String TAG = "Launcher.DragController";
+
+ /** Indicates the drag is a move. */
+ public static int DRAG_ACTION_MOVE = 0;
+
+ /** Indicates the drag is a copy. */
+ public static int DRAG_ACTION_COPY = 1;
+
+ private static final int SCROLL_DELAY = 600;
+ private static final int SCROLL_ZONE = 20;
+ private static final int VIBRATE_DURATION = 35;
+
+ private static final boolean PROFILE_DRAWING_DURING_DRAG = false;
+
+ private static final int SCROLL_OUTSIDE_ZONE = 0;
+ private static final int SCROLL_WAITING_IN_ZONE = 1;
+
+ private static final int SCROLL_LEFT = 0;
+ private static final int SCROLL_RIGHT = 1;
+
+ private Context mContext;
+ private Handler mHandler;
+ private final Vibrator mVibrator = new Vibrator();
+
+ // temporaries to avoid gc thrash
+ private Rect mRectTemp = new Rect();
+ private final int[] mCoordinatesTemp = new int[2];
+
+ /** Whether or not we're dragging. */
+ private boolean mDragging;
+
+ /** X coordinate of the down event. */
+ private float mMotionDownX;
+
+ /** Y coordinate of the down event. */
+ private float mMotionDownY;
+
+ /** Info about the screen for clamping. */
+ private DisplayMetrics mDisplayMetrics = new DisplayMetrics();
+
+ /** Original view that is being dragged. */
+ private View mOriginator;
+
+ /** X offset from the upper-left corner of the cell to where we touched. */
+ private float mTouchOffsetX;
+
+ /** Y offset from the upper-left corner of the cell to where we touched. */
+ private float mTouchOffsetY;
+
+ /** Where the drag originated */
+ private DragSource mDragSource;
+
+ /** The data associated with the object being dragged */
+ private Object mDragInfo;
+
+ /** The view that moves around while you drag. */
+ private DragView mDragView;
+
+ /** Who can receive drop events */
+ private ArrayList<DropTarget> mDropTargets = new ArrayList<DropTarget>();
+
+ private DragListener mListener;
+
+ /** The window token used as the parent for the DragView. */
+ private IBinder mWindowToken;
+
+ /** The view that will be scrolled when dragging to the left and right edges of the screen. */
+ private View mScrollView;
+
+ private DragScroller mDragScroller;
+ private int mScrollState = SCROLL_OUTSIDE_ZONE;
+ private ScrollRunnable mScrollRunnable = new ScrollRunnable();
+
+ private RectF mDeleteRegion;
+ private DropTarget mLastDropTarget;
+
+ private InputMethodManager mInputMethodManager;
+
+ /**
+ * Interface to receive notifications when a drag starts or stops
+ */
+ interface DragListener {
+
+ /**
+ * A drag has begun
+ *
+ * @param source An object representing where the drag originated
+ * @param info The data associated with the object that is being dragged
+ * @param dragAction The drag action: either {@link DragController#DRAG_ACTION_MOVE}
+ * or {@link DragController#DRAG_ACTION_COPY}
+ */
+ void onDragStart(DragSource source, Object info, int dragAction);
+
+ /**
+ * The drag has eneded
+ */
+ void onDragEnd();
+ }
+
+ /**
+ * Used to create a new DragLayer from XML.
+ *
+ * @param context The application's context.
+ * @param attrs The attribtues set containing the Workspace's customization values.
+ */
+ public DragController(Context context) {
+ mContext = context;
+ mHandler = new Handler();
+ }
+
+ /**
+ * Starts a drag.
+ *
+ * @param v The view that is being dragged
+ * @param source An object representing where the drag originated
+ * @param info The data associated with the object that is being dragged
+ * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
+ * {@link #DRAG_ACTION_COPY}
+ */
+ public void startDrag(View v, DragSource source, Object dragInfo, int dragAction) {
+ mOriginator = v;
+
+ Bitmap b = getViewBitmap(v);
+
+ int[] loc = mCoordinatesTemp;
+ v.getLocationOnScreen(loc);
+ int screenX = loc[0];
+ int screenY = loc[1];
+
+ startDrag(b, screenX, screenY, 0, 0, b.getWidth(), b.getHeight(),
+ source, dragInfo, dragAction);
+
+ b.recycle();
+
+ if (dragAction == DRAG_ACTION_MOVE) {
+ v.setVisibility(View.GONE);
+ }
+ }
+
+ /**
+ * Starts a drag.
+ *
+ * @param b The bitmap to display as the drag image. It will be re-scaled to the
+ * enlarged size.
+ * @param screenX The x position on screen of the left-top of the bitmap.
+ * @param screenY The y position on screen of the left-top of the bitmap.
+ * @param textureLeft The left edge of the region inside b to use.
+ * @param textureTop The top edge of the region inside b to use.
+ * @param textureWidth The width of the region inside b to use.
+ * @param textureHeight The height of the region inside b to use.
+ * @param source An object representing where the drag originated
+ * @param info The data associated with the object that is being dragged
+ * @param dragAction The drag action: either {@link #DRAG_ACTION_MOVE} or
+ * {@link #DRAG_ACTION_COPY}
+ */
+ public void startDrag(Bitmap b, int screenX, int screenY,
+ int textureLeft, int textureTop, int textureWidth, int textureHeight,
+ DragSource source, Object dragInfo, int dragAction) {
+ if (PROFILE_DRAWING_DURING_DRAG) {
+ android.os.Debug.startMethodTracing("Launcher");
+ }
+
+ // Hide soft keyboard, if visible
+ if (mInputMethodManager == null) {
+ mInputMethodManager = (InputMethodManager)
+ mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
+ }
+ mInputMethodManager.hideSoftInputFromWindow(mWindowToken, 0);
+
+ if (mListener != null) {
+ mListener.onDragStart(source, dragInfo, dragAction);
+ }
+
+ int registrationX = ((int)mMotionDownX) - screenX;
+ int registrationY = ((int)mMotionDownY) - screenY;
+
+ mTouchOffsetX = mMotionDownX - screenX;
+ mTouchOffsetY = mMotionDownY - screenY;
+
+ mDragging = true;
+ mDragSource = source;
+ mDragInfo = dragInfo;
+
+ mVibrator.vibrate(VIBRATE_DURATION);
+
+ DragView dragView = mDragView = new DragView(mContext, b, registrationX, registrationY,
+ textureLeft, textureTop, textureWidth, textureHeight);
+ dragView.show(mWindowToken, (int)mMotionDownX, (int)mMotionDownY);
+ }
+
+ /**
+ * Draw the view into a bitmap.
+ */
+ private Bitmap getViewBitmap(View v) {
+ v.clearFocus();
+ v.setPressed(false);
+
+ boolean willNotCache = v.willNotCacheDrawing();
+ v.setWillNotCacheDrawing(false);
+
+ // Reset the drawing cache background color to fully transparent
+ // for the duration of this operation
+ int color = v.getDrawingCacheBackgroundColor();
+ v.setDrawingCacheBackgroundColor(0);
+
+ if (color != 0) {
+ v.destroyDrawingCache();
+ }
+ v.buildDrawingCache();
+ Bitmap cacheBitmap = v.getDrawingCache();
+
+ Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
+
+ // Restore the view
+ v.destroyDrawingCache();
+ v.setWillNotCacheDrawing(willNotCache);
+ v.setDrawingCacheBackgroundColor(color);
+
+ return bitmap;
+ }
+
+ /**
+ * Call this from a drag source view like this:
+ *
+ * <pre>
+ * @Override
+ * public boolean dispatchKeyEvent(KeyEvent event) {
+ * return mDragController.dispatchKeyEvent(this, event)
+ * || super.dispatchKeyEvent(event);
+ * </pre>
+ */
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ return mDragging;
+ }
+
+ /**
+ * Stop dragging without dropping.
+ */
+ public void cancelDrag() {
+ endDrag();
+ }
+
+ private void endDrag() {
+ if (mDragging) {
+ mDragging = false;
+ if (mOriginator != null) {
+ mOriginator.setVisibility(View.VISIBLE);
+ }
+ if (mListener != null) {
+ mListener.onDragEnd();
+ }
+ if (mDragView != null) {
+ mDragView.remove();
+ mDragView = null;
+ }
+ }
+ }
+
+ /**
+ * Call this from a drag source view.
+ */
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ if (false) {
+ Log.d(Launcher.TAG, "DragController.onInterceptTouchEvent " + ev + " mDragging="
+ + mDragging);
+ }
+ final int action = ev.getAction();
+
+ if (action == MotionEvent.ACTION_DOWN) {
+ recordScreenSize();
+ }
+
+ final int screenX = clamp((int)ev.getRawX(), 0, mDisplayMetrics.widthPixels);
+ final int screenY = clamp((int)ev.getRawY(), 0, mDisplayMetrics.heightPixels);
+
+ switch (action) {
+ case MotionEvent.ACTION_MOVE:
+ break;
+
+ case MotionEvent.ACTION_DOWN:
+ // Remember location of down touch
+ mMotionDownX = screenX;
+ mMotionDownY = screenY;
+ mLastDropTarget = null;
+ break;
+
+ case MotionEvent.ACTION_CANCEL:
+ case MotionEvent.ACTION_UP:
+ if (mDragging) {
+ drop(screenX, screenY);
+ }
+ endDrag();
+ break;
+ }
+
+ return mDragging;
+ }
+
+ /**
+ * Call this from a drag source view.
+ */
+ public boolean onTouchEvent(MotionEvent ev) {
+ View scrollView = mScrollView;
+
+ if (!mDragging) {
+ return false;
+ }
+
+ final int action = ev.getAction();
+ final int screenX = clamp((int)ev.getRawX(), 0, mDisplayMetrics.widthPixels);
+ final int screenY = clamp((int)ev.getRawY(), 0, mDisplayMetrics.heightPixels);
+
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ // Remember where the motion event started
+ mMotionDownX = screenX;
+ mMotionDownY = screenY;
+
+ if ((screenX < SCROLL_ZONE) || (screenX > scrollView.getWidth() - SCROLL_ZONE)) {
+ mScrollState = SCROLL_WAITING_IN_ZONE;
+ mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
+ } else {
+ mScrollState = SCROLL_OUTSIDE_ZONE;
+ }
+
+ break;
+ case MotionEvent.ACTION_MOVE:
+ // Update the drag view. Don't use the clamped pos here so the dragging looks
+ // like it goes off screen a little, intead of bumping up against the edge.
+ mDragView.move((int)ev.getRawX(), (int)ev.getRawY());
+
+ // Drop on someone?
+ final int[] coordinates = mCoordinatesTemp;
+ DropTarget dropTarget = findDropTarget((int) screenX, (int) screenY, coordinates);
+ if (dropTarget != null) {
+ if (mLastDropTarget == dropTarget) {
+ dropTarget.onDragOver(mDragSource, coordinates[0], coordinates[1],
+ (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
+ } else {
+ if (mLastDropTarget != null) {
+ mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1],
+ (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
+ }
+ dropTarget.onDragEnter(mDragSource, coordinates[0], coordinates[1],
+ (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
+ }
+ } else {
+ if (mLastDropTarget != null) {
+ mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1],
+ (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
+ }
+ }
+ mLastDropTarget = dropTarget;
+
+ // Scroll, maybe, but not if we're in the delete region.
+ boolean inDeleteRegion = false;
+ if (mDeleteRegion != null) {
+ inDeleteRegion = mDeleteRegion.contains(screenX, screenY);
+ }
+ if (!inDeleteRegion && screenX < SCROLL_ZONE) {
+ if (mScrollState == SCROLL_OUTSIDE_ZONE) {
+ mScrollState = SCROLL_WAITING_IN_ZONE;
+ mScrollRunnable.setDirection(SCROLL_LEFT);
+ mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
+ }
+ } else if (!inDeleteRegion && screenX > scrollView.getWidth() - SCROLL_ZONE) {
+ if (mScrollState == SCROLL_OUTSIDE_ZONE) {
+ mScrollState = SCROLL_WAITING_IN_ZONE;
+ mScrollRunnable.setDirection(SCROLL_RIGHT);
+ mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY);
+ }
+ } else {
+ if (mScrollState == SCROLL_WAITING_IN_ZONE) {
+ mScrollState = SCROLL_OUTSIDE_ZONE;
+ mScrollRunnable.setDirection(SCROLL_RIGHT);
+ mHandler.removeCallbacks(mScrollRunnable);
+ }
+ }
+
+ break;
+ case MotionEvent.ACTION_UP:
+ mHandler.removeCallbacks(mScrollRunnable);
+ if (mDragging) {
+ drop(screenX, screenY);
+ }
+ endDrag();
+
+ break;
+ case MotionEvent.ACTION_CANCEL:
+ cancelDrag();
+ }
+
+ return true;
+ }
+
+ private boolean drop(float x, float y) {
+ final int[] coordinates = mCoordinatesTemp;
+ DropTarget dropTarget = findDropTarget((int) x, (int) y, coordinates);
+
+ if (dropTarget != null) {
+ dropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1],
+ (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
+ if (dropTarget.acceptDrop(mDragSource, coordinates[0], coordinates[1],
+ (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo)) {
+ dropTarget.onDrop(mDragSource, coordinates[0], coordinates[1],
+ (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo);
+ mDragSource.onDropCompleted((View) dropTarget, true);
+ return true;
+ } else {
+ mDragSource.onDropCompleted((View) dropTarget, false);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
+ final Rect r = mRectTemp;
+
+ final ArrayList<DropTarget> dropTargets = mDropTargets;
+ final int count = dropTargets.size();
+ for (int i=count-1; i>=0; i--) {
+ final DropTarget target = dropTargets.get(i);
+ target.getHitRect(r);
+ target.getLocationOnScreen(dropCoordinates);
+ r.offset(dropCoordinates[0] - target.getLeft(), dropCoordinates[1] - target.getTop());
+ if (r.contains(x, y)) {
+ dropCoordinates[0] = x - dropCoordinates[0];
+ dropCoordinates[1] = y - dropCoordinates[1];
+ return target;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the screen size so we can clamp events to the screen size so even if
+ * you drag off the edge of the screen, we find something.
+ */
+ private void recordScreenSize() {
+ ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE))
+ .getDefaultDisplay().getMetrics(mDisplayMetrics);
+ }
+
+ /**
+ * Clamp val to be >= min and < max.
+ */
+ private static int clamp(int val, int min, int max) {
+ if (val < min) {
+ return min;
+ } else if (val >= max) {
+ return max - 1;
+ } else {
+ return val;
+ }
+ }
+
+ public void setDragScoller(DragScroller scroller) {
+ mDragScroller = scroller;
+ }
+
+ public void setWindowToken(IBinder token) {
+ mWindowToken = token;
+ }
+
+ /**
+ * Sets the drag listner which will be notified when a drag starts or ends.
+ */
+ public void setDragListener(DragListener l) {
+ mListener = l;
+ }
+
+ /**
+ * Remove a previously installed drag listener.
+ */
+ public void removeDragListener(DragListener l) {
+ mListener = null;
+ }
+
+ /**
+ * Add a DropTarget to the list of potential places to receive drop events.
+ */
+ public void addDropTarget(DropTarget target) {
+ mDropTargets.add(target);
+ }
+
+ /**
+ * Don't send drop events to <em>target</em> any more.
+ */
+ public void removeDropTarget(DropTarget target) {
+ mDropTargets.remove(target);
+ }
+
+ /**
+ * Set which view scrolls for touch events near the edge of the screen.
+ */
+ public void setScrollView(View v) {
+ mScrollView = v;
+ }
+
+ /**
+ * Specifies the delete region. We won't scroll on touch events over the delete region.
+ *
+ * @param region The rectangle in screen coordinates of the delete region.
+ */
+ void setDeleteRegion(RectF region) {
+ mDeleteRegion = region;
+ }
+
+ private class ScrollRunnable implements Runnable {
+ private int mDirection;
+
+ ScrollRunnable() {
+ }
+
+ public void run() {
+ if (mDragScroller != null) {
+ if (mDirection == SCROLL_LEFT) {
+ mDragScroller.scrollLeft();
+ } else {
+ mDragScroller.scrollRight();
+ }
+ mScrollState = SCROLL_OUTSIDE_ZONE;
+ }
+ }
+
+ void setDirection(int direction) {
+ mDirection = direction;
+ }
+ }
+}
diff --git a/src/com/android/launcher2/DragLayer.java b/src/com/android/launcher2/DragLayer.java
new file mode 100644
index 0000000..7ae9891
--- /dev/null
+++ b/src/com/android/launcher2/DragLayer.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.KeyEvent;
+import android.widget.FrameLayout;
+
+/**
+ * A ViewGroup that coordinated dragging across its dscendants
+ */
+public class DragLayer extends FrameLayout {
+ DragController mDragController;
+
+ /**
+ * Used to create a new DragLayer from XML.
+ *
+ * @param context The application's context.
+ * @param attrs The attribtues set containing the Workspace's customization values.
+ */
+ public DragLayer(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public void setDragController(DragController controller) {
+ mDragController = controller;
+ }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ return mDragController.dispatchKeyEvent(event) || super.dispatchKeyEvent(event);
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ return mDragController.onInterceptTouchEvent(ev);
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ return mDragController.onTouchEvent(ev);
+ }
+}
diff --git a/src/com/android/launcher2/DragScroller.java b/src/com/android/launcher2/DragScroller.java
new file mode 100644
index 0000000..c3c251c
--- /dev/null
+++ b/src/com/android/launcher2/DragScroller.java
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+/**
+ * Handles scrolling while dragging
+ *
+ */
+public interface DragScroller {
+ void scrollLeft();
+ void scrollRight();
+}
diff --git a/src/com/android/launcher2/DragSource.java b/src/com/android/launcher2/DragSource.java
new file mode 100644
index 0000000..7c6ca58
--- /dev/null
+++ b/src/com/android/launcher2/DragSource.java
@@ -0,0 +1,28 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.view.View;
+
+/**
+ * Interface defining an object that can originate a drag.
+ *
+ */
+public interface DragSource {
+ void setDragController(DragController dragger);
+ void onDropCompleted(View target, boolean success);
+}
diff --git a/src/com/android/launcher2/DragView.java b/src/com/android/launcher2/DragView.java
new file mode 100644
index 0000000..7a86273
--- /dev/null
+++ b/src/com/android/launcher2/DragView.java
@@ -0,0 +1,182 @@
+/*
+ * 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.
+ */
+
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.PixelFormat;
+import android.graphics.Point;
+import android.os.IBinder;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.KeyEvent;
+import android.view.WindowManager;
+import android.view.WindowManagerImpl;
+
+public class DragView extends View implements TweenCallback {
+ // Number of pixels to add to the dragged item for scaling. Should be even for pixel alignment.
+ private static final int DRAG_SCALE = 24;
+
+ private Bitmap mBitmap;
+ private Paint mPaint;
+ private int mRegistrationX;
+ private int mRegistrationY;
+
+ SymmetricalLinearTween mTween;
+ private float mScale;
+ private float mAnimationScale = 1.0f;
+
+ private WindowManager.LayoutParams mLayoutParams;
+ private WindowManager mWindowManager;
+
+ /**
+ * Construct the drag view.
+ * <p>
+ * The registration point is the point inside our view that the touch events should
+ * be centered upon.
+ *
+ * @param context A context
+ * @param bitmap The view that we're dragging around. We scale it up when we draw it.
+ * @param registrationX The x coordinate of the registration point.
+ * @param registrationY The y coordinate of the registration point.
+ */
+ public DragView(Context context, Bitmap bitmap, int registrationX, int registrationY,
+ int left, int top, int width, int height) {
+ super(context);
+
+ mWindowManager = WindowManagerImpl.getDefault();
+
+ mTween = new SymmetricalLinearTween(false, 110 /*ms duration*/, this);
+
+ Matrix scale = new Matrix();
+ float scaleFactor = width;
+ scaleFactor = mScale = (scaleFactor + DRAG_SCALE) / scaleFactor;
+ scale.setScale(scaleFactor, scaleFactor);
+
+ mBitmap = Bitmap.createBitmap(bitmap, left, top, width, height, scale, true);
+
+ // The point in our scaled bitmap that the touch events are located
+ mRegistrationX = registrationX + (DRAG_SCALE / 2);
+ mRegistrationY = registrationY + (DRAG_SCALE / 2);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ setMeasuredDimension(mBitmap.getWidth(), mBitmap.getHeight());
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ if (false) {
+ // for debugging
+ Paint p = new Paint();
+ p.setStyle(Paint.Style.FILL);
+ p.setColor(0xaaffffff);
+ canvas.drawRect(0, 0, getWidth(), getHeight(), p);
+ }
+ float scale = mAnimationScale;
+ if (scale < 0.999f) { // allow for some float error
+ float width = mBitmap.getWidth();
+ float offset = (width-(width*scale))/2;
+ canvas.translate(offset, offset);
+ canvas.scale(scale, scale);
+ }
+ canvas.drawBitmap(mBitmap, 0.0f, 0.0f, mPaint);
+ }
+
+ @Override
+ protected void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+ mBitmap.recycle();
+ }
+
+ public void onTweenValueChanged(float value, float oldValue) {
+ mAnimationScale = (1.0f+((mScale-1.0f)*value))/mScale;
+ invalidate();
+ }
+
+ public void onTweenStarted() {
+ }
+
+ public void onTweenFinished() {
+ }
+
+ public void setPaint(Paint paint) {
+ mPaint = paint;
+ invalidate();
+ }
+
+ /**
+ * Create a window containing this view and show it.
+ *
+ * @param windowToken obtained from v.getWindowToken() from one of your views
+ * @param touchX the x coordinate the user touched in screen coordinates
+ * @param touchY the y coordinate the user touched in screen coordinates
+ */
+ public void show(IBinder windowToken, int touchX, int touchY) {
+ WindowManager.LayoutParams lp;
+ int pixelFormat;
+
+ pixelFormat = PixelFormat.TRANSLUCENT;
+
+ lp = new WindowManager.LayoutParams(
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT,
+ touchX-mRegistrationX, touchY-mRegistrationY,
+ WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL,
+ WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
+ | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
+ /*| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM*/,
+ pixelFormat);
+// lp.token = mStatusBarView.getWindowToken();
+ lp.gravity = Gravity.LEFT | Gravity.TOP;
+ lp.token = windowToken;
+ lp.setTitle("DragView");
+ mLayoutParams = lp;
+
+ mWindowManager.addView(this, lp);
+
+ mAnimationScale = 1.0f/mScale;
+ mTween.start(true);
+ }
+
+ /**
+ * Move the window containing this view.
+ *
+ * @param touchX the x coordinate the user touched in screen coordinates
+ * @param touchY the y coordinate the user touched in screen coordinates
+ */
+ void move(int touchX, int touchY) {
+ WindowManager.LayoutParams lp = mLayoutParams;
+ lp.x = touchX - mRegistrationX;
+ lp.y = touchY - mRegistrationY;
+ mWindowManager.updateViewLayout(this, lp);
+ }
+
+ void remove() {
+ mWindowManager.removeView(this);
+ }
+}
+
diff --git a/src/com/android/launcher2/DropTarget.java b/src/com/android/launcher2/DropTarget.java
new file mode 100644
index 0000000..72eb330
--- /dev/null
+++ b/src/com/android/launcher2/DropTarget.java
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.graphics.Rect;
+
+/**
+ * Interface defining an object that can receive a drag.
+ *
+ */
+public interface DropTarget {
+
+ /**
+ * Handle an object being dropped on the DropTarget
+ *
+ * @param source DragSource where the drag started
+ * @param x X coordinate of the drop location
+ * @param y Y coordinate of the drop location
+ * @param xOffset Horizontal offset with the object being dragged where the original
+ * touch happened
+ * @param yOffset Vertical offset with the object being dragged where the original
+ * touch happened
+ * @param dragView The DragView that's being dragged around on screen.
+ * @param dragInfo Data associated with the object being dragged
+ *
+ */
+ void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo);
+
+ void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo);
+
+ void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo);
+
+ void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo);
+
+ /**
+ * Check if a drop action can occur at, or near, the requested location.
+ * This may be called repeatedly during a drag, so any calls should return
+ * quickly.
+ *
+ * @param source DragSource where the drag started
+ * @param x X coordinate of the drop location
+ * @param y Y coordinate of the drop location
+ * @param xOffset Horizontal offset with the object being dragged where the
+ * original touch happened
+ * @param yOffset Vertical offset with the object being dragged where the
+ * original touch happened
+ * @param dragView The DragView that's being dragged around on screen.
+ * @param dragInfo Data associated with the object being dragged
+ * @return True if the drop will be accepted, false otherwise.
+ */
+ boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo);
+
+ /**
+ * Estimate the surface area where this object would land if dropped at the
+ * given location.
+ *
+ * @param source DragSource where the drag started
+ * @param x X coordinate of the drop location
+ * @param y Y coordinate of the drop location
+ * @param xOffset Horizontal offset with the object being dragged where the
+ * original touch happened
+ * @param yOffset Vertical offset with the object being dragged where the
+ * original touch happened
+ * @param dragView The DragView that's being dragged around on screen.
+ * @param dragInfo Data associated with the object being dragged
+ * @param recycle {@link Rect} object to be possibly recycled.
+ * @return Estimated area that would be occupied if object was dropped at
+ * the given location. Should return null if no estimate is found,
+ * or if this target doesn't provide estimations.
+ */
+ Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo, Rect recycle);
+
+ // These methods are implemented in Views
+ void getHitRect(Rect outRect);
+ void getLocationOnScreen(int[] loc);
+ int getLeft();
+ int getTop();
+}
diff --git a/src/com/android/launcher2/FastBitmapDrawable.java b/src/com/android/launcher2/FastBitmapDrawable.java
new file mode 100644
index 0000000..db2c01c
--- /dev/null
+++ b/src/com/android/launcher2/FastBitmapDrawable.java
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.graphics.drawable.Drawable;
+import android.graphics.PixelFormat;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+
+class FastBitmapDrawable extends Drawable {
+ private Bitmap mBitmap;
+
+ FastBitmapDrawable(Bitmap b) {
+ mBitmap = b;
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null);
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.TRANSLUCENT;
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter cf) {
+ }
+
+ @Override
+ public int getIntrinsicWidth() {
+ return mBitmap.getWidth();
+ }
+
+ @Override
+ public int getIntrinsicHeight() {
+ return mBitmap.getHeight();
+ }
+
+ @Override
+ public int getMinimumWidth() {
+ return mBitmap.getWidth();
+ }
+
+ @Override
+ public int getMinimumHeight() {
+ return mBitmap.getHeight();
+ }
+
+ public Bitmap getBitmap() {
+ return mBitmap;
+ }
+}
diff --git a/src/com/android/launcher2/Folder.java b/src/com/android/launcher2/Folder.java
new file mode 100644
index 0000000..4f66ad0
--- /dev/null
+++ b/src/com/android/launcher2/Folder.java
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.AbsListView;
+import android.widget.BaseAdapter;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
+
+/**
+ * Represents a set of icons chosen by the user or generated by the system.
+ */
+public class Folder extends LinearLayout implements DragSource, OnItemLongClickListener,
+ OnItemClickListener, OnClickListener, View.OnLongClickListener {
+
+ protected AbsListView mContent;
+ protected DragController mDragController;
+
+ protected Launcher mLauncher;
+
+ protected Button mCloseButton;
+
+ protected FolderInfo mInfo;
+
+ /**
+ * Which item is being dragged
+ */
+ protected ApplicationInfo mDragItem;
+ private boolean mCloneInfo;
+
+ /**
+ * Used to inflate the Workspace from XML.
+ *
+ * @param context The application's context.
+ * @param attrs The attribtues set containing the Workspace's customization values.
+ */
+ public Folder(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setAlwaysDrawnWithCacheEnabled(false);
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+
+ mContent = (AbsListView) findViewById(R.id.folder_content);
+ mContent.setOnItemClickListener(this);
+ mContent.setOnItemLongClickListener(this);
+
+ mCloseButton = (Button) findViewById(R.id.folder_close);
+ mCloseButton.setOnClickListener(this);
+ mCloseButton.setOnLongClickListener(this);
+ }
+
+ public void onItemClick(AdapterView parent, View v, int position, long id) {
+ ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
+ mLauncher.startActivitySafely(app.intent);
+ }
+
+ public void onClick(View v) {
+ mLauncher.closeFolder(this);
+ }
+
+ public boolean onLongClick(View v) {
+ mLauncher.closeFolder(this);
+ mLauncher.showRenameDialog(mInfo);
+ return true;
+ }
+
+ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
+ if (!view.isInTouchMode()) {
+ return false;
+ }
+
+ ApplicationInfo app = (ApplicationInfo) parent.getItemAtPosition(position);
+ if (mCloneInfo) {
+ app = new ApplicationInfo(app);
+ }
+
+ mDragController.startDrag(view, this, app, DragController.DRAG_ACTION_COPY);
+ mLauncher.closeFolder(this);
+ mDragItem = app;
+
+ return true;
+ }
+
+ void setCloneInfo(boolean cloneInfo) {
+ mCloneInfo = cloneInfo;
+ }
+
+ public void setDragController(DragController dragController) {
+ mDragController = dragController;
+ }
+
+ public void onDropCompleted(View target, boolean success) {
+ }
+
+ /**
+ * Sets the adapter used to populate the content area. The adapter must only
+ * contains ApplicationInfo items.
+ *
+ * @param adapter The list of applications to display in the folder.
+ */
+ void setContentAdapter(BaseAdapter adapter) {
+ mContent.setAdapter(adapter);
+ }
+
+ void notifyDataSetChanged() {
+ ((BaseAdapter) mContent.getAdapter()).notifyDataSetChanged();
+ }
+
+ void setLauncher(Launcher launcher) {
+ mLauncher = launcher;
+ }
+
+ /**
+ * @return the FolderInfo object associated with this folder
+ */
+ FolderInfo getInfo() {
+ return mInfo;
+ }
+
+ // When the folder opens, we need to refresh the GridView's selection by
+ // forcing a layout
+ void onOpen() {
+ mContent.requestLayout();
+ }
+
+ void onClose() {
+ final Workspace workspace = mLauncher.getWorkspace();
+ workspace.getChildAt(workspace.getCurrentScreen()).requestFocus();
+ }
+
+ void bind(FolderInfo info) {
+ mInfo = info;
+ mCloseButton.setText(info.title);
+ }
+}
diff --git a/src/com/android/launcher2/FolderIcon.java b/src/com/android/launcher2/FolderIcon.java
new file mode 100644
index 0000000..85fc3a7
--- /dev/null
+++ b/src/com/android/launcher2/FolderIcon.java
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.ViewGroup;
+
+/**
+ * An icon that can appear on in the workspace representing an {@link UserFolder}.
+ */
+public class FolderIcon extends BubbleTextView implements DropTarget {
+ private UserFolderInfo mInfo;
+ private Launcher mLauncher;
+ private Drawable mCloseIcon;
+ private Drawable mOpenIcon;
+
+ public FolderIcon(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public FolderIcon(Context context) {
+ super(context);
+ }
+
+ static FolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
+ UserFolderInfo folderInfo) {
+
+ FolderIcon icon = (FolderIcon) LayoutInflater.from(launcher).inflate(resId, group, false);
+
+ final Resources resources = launcher.getResources();
+ Drawable d = resources.getDrawable(R.drawable.ic_launcher_folder);
+ d = Utilities.createIconThumbnail(d, launcher);
+ icon.mCloseIcon = d;
+ icon.mOpenIcon = resources.getDrawable(R.drawable.ic_launcher_folder_open);
+ icon.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
+ icon.setText(folderInfo.title);
+ icon.setTag(folderInfo);
+ icon.setOnClickListener(launcher);
+ icon.mInfo = folderInfo;
+ icon.mLauncher = launcher;
+
+ return icon;
+ }
+
+ public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ final ItemInfo item = (ItemInfo) dragInfo;
+ final int itemType = item.itemType;
+ return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
+ itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
+ && item.container != mInfo.id;
+ }
+
+ public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo, Rect recycle) {
+ return null;
+ }
+
+ public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ final ApplicationInfo item = (ApplicationInfo) dragInfo;
+ // TODO: update open folder that is looking at this data
+ mInfo.add(item);
+ LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
+ }
+
+ public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ setCompoundDrawablesWithIntrinsicBounds(null, mOpenIcon, null, null);
+ }
+
+ public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+
+ public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ setCompoundDrawablesWithIntrinsicBounds(null, mCloseIcon, null, null);
+ }
+}
diff --git a/src/com/android/launcher2/FolderInfo.java b/src/com/android/launcher2/FolderInfo.java
new file mode 100644
index 0000000..8732690
--- /dev/null
+++ b/src/com/android/launcher2/FolderInfo.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+
+/**
+ * Represents a folder containing shortcuts or apps.
+ */
+class FolderInfo extends ItemInfo {
+
+ /**
+ * Whether this folder has been opened
+ */
+ boolean opened;
+
+ /**
+ * The folder name.
+ */
+ CharSequence title;
+}
diff --git a/src/com/android/launcher2/HandleView.java b/src/com/android/launcher2/HandleView.java
new file mode 100644
index 0000000..e07334e
--- /dev/null
+++ b/src/com/android/launcher2/HandleView.java
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+
+package com.android.launcher2;
+
+import android.widget.ImageView;
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.KeyEvent;
+import android.view.View;
+
+public class HandleView extends ImageView {
+ private static final int ORIENTATION_HORIZONTAL = 1;
+
+ private Launcher mLauncher;
+ private int mOrientation = ORIENTATION_HORIZONTAL;
+
+ public HandleView(Context context) {
+ super(context);
+ }
+
+ public HandleView(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public HandleView(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HandleView, defStyle, 0);
+ mOrientation = a.getInt(R.styleable.HandleView_direction, ORIENTATION_HORIZONTAL);
+ a.recycle();
+
+ setContentDescription(context.getString(R.string.all_apps_button_label));
+ }
+
+ @Override
+ public View focusSearch(int direction) {
+ View newFocus = super.focusSearch(direction);
+ if (newFocus == null && !mLauncher.isAllAppsVisible()) {
+ final Workspace workspace = mLauncher.getWorkspace();
+ workspace.dispatchUnhandledMove(null, direction);
+ return (mOrientation == ORIENTATION_HORIZONTAL && direction == FOCUS_DOWN) ?
+ this : workspace;
+ }
+ return newFocus;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ if (ev.getAction() == MotionEvent.ACTION_DOWN && mLauncher.isAllAppsVisible()) {
+ return false;
+ }
+ return super.onTouchEvent(ev);
+ }
+
+ private static boolean isDirectionKey(int keyCode) {
+ return keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_LEFT ||
+ keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_UP;
+ }
+
+ void setLauncher(Launcher launcher) {
+ mLauncher = launcher;
+ }
+}
diff --git a/src/com/android/launcher2/InstallShortcutReceiver.java b/src/com/android/launcher2/InstallShortcutReceiver.java
new file mode 100644
index 0000000..45ff24e
--- /dev/null
+++ b/src/com/android/launcher2/InstallShortcutReceiver.java
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ContentResolver;
+import android.database.Cursor;
+import android.widget.Toast;
+
+public class InstallShortcutReceiver extends BroadcastReceiver {
+ private static final String ACTION_INSTALL_SHORTCUT =
+ "com.android.launcher.action.INSTALL_SHORTCUT";
+
+ private final int[] mCoordinates = new int[2];
+
+ public void onReceive(Context context, Intent data) {
+ if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
+ return;
+ }
+
+ int screen = Launcher.getScreen();
+
+ if (!installShortcut(context, data, screen)) {
+ // The target screen is full, let's try the other screens
+ for (int i = 0; i < Launcher.SCREEN_COUNT; i++) {
+ if (i != screen && installShortcut(context, data, i)) break;
+ }
+ }
+ }
+
+ private boolean installShortcut(Context context, Intent data, int screen) {
+ String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
+
+ if (findEmptyCell(context, mCoordinates, screen)) {
+ CellLayout.CellInfo cell = new CellLayout.CellInfo();
+ cell.cellX = mCoordinates[0];
+ cell.cellY = mCoordinates[1];
+ cell.screen = screen;
+
+ Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
+
+ if (intent.getAction() == null) {
+ intent.setAction(Intent.ACTION_VIEW);
+ }
+
+ // By default, we allow for duplicate entries (located in
+ // different places)
+ boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
+ if (duplicate || !LauncherModel.shortcutExists(context, name, intent)) {
+ Launcher.addShortcut(context, data, cell, true);
+ Toast.makeText(context, context.getString(R.string.shortcut_installed, name),
+ Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(context, context.getString(R.string.shortcut_duplicate, name),
+ Toast.LENGTH_SHORT).show();
+ }
+
+ return true;
+ } else {
+ Toast.makeText(context, context.getString(R.string.out_of_space),
+ Toast.LENGTH_SHORT).show();
+ }
+
+ return false;
+ }
+
+ private static boolean findEmptyCell(Context context, int[] xy, int screen) {
+ final int xCount = Launcher.NUMBER_CELLS_X;
+ final int yCount = Launcher.NUMBER_CELLS_Y;
+
+ boolean[][] occupied = new boolean[xCount][yCount];
+
+ final ContentResolver cr = context.getContentResolver();
+ Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
+ new String[] { LauncherSettings.Favorites.CELLX, LauncherSettings.Favorites.CELLY,
+ LauncherSettings.Favorites.SPANX, LauncherSettings.Favorites.SPANY },
+ LauncherSettings.Favorites.SCREEN + "=?",
+ new String[] { String.valueOf(screen) }, null);
+
+ final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
+ final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
+ final int spanXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANX);
+ final int spanYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SPANY);
+
+ try {
+ while (c.moveToNext()) {
+ int cellX = c.getInt(cellXIndex);
+ int cellY = c.getInt(cellYIndex);
+ int spanX = c.getInt(spanXIndex);
+ int spanY = c.getInt(spanYIndex);
+
+ for (int x = cellX; x < cellX + spanX && x < xCount; x++) {
+ for (int y = cellY; y < cellY + spanY && y < yCount; y++) {
+ occupied[x][y] = true;
+ }
+ }
+ }
+ } catch (Exception e) {
+ return false;
+ } finally {
+ c.close();
+ }
+
+ return CellLayout.findVacantCell(xy, 1, 1, xCount, yCount, occupied);
+ }
+}
diff --git a/src/com/android/launcher2/ItemInfo.java b/src/com/android/launcher2/ItemInfo.java
new file mode 100644
index 0000000..f04880d
--- /dev/null
+++ b/src/com/android/launcher2/ItemInfo.java
@@ -0,0 +1,135 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import android.content.ContentValues;
+import android.graphics.Bitmap;
+import android.util.Log;
+
+/**
+ * Represents an item in the launcher.
+ */
+class ItemInfo {
+
+ static final int NO_ID = -1;
+
+ /**
+ * The id in the settings database for this item
+ */
+ long id = NO_ID;
+
+ /**
+ * One of {@link LauncherSettings.Favorites#ITEM_TYPE_APPLICATION},
+ * {@link LauncherSettings.Favorites#ITEM_TYPE_SHORTCUT},
+ * {@link LauncherSettings.Favorites#ITEM_TYPE_USER_FOLDER}, or
+ * {@link LauncherSettings.Favorites#ITEM_TYPE_APPWIDGET}.
+ */
+ int itemType;
+
+ /**
+ * The id of the container that holds this item. For the desktop, this will be
+ * {@link LauncherSettings.Favorites#CONTAINER_DESKTOP}. For the all applications folder it
+ * will be {@link #NO_ID} (since it is not stored in the settings DB). For user folders
+ * it will be the id of the folder.
+ */
+ long container = NO_ID;
+
+ /**
+ * Iindicates the screen in which the shortcut appears.
+ */
+ int screen = -1;
+
+ /**
+ * Indicates the X position of the associated cell.
+ */
+ int cellX = -1;
+
+ /**
+ * Indicates the Y position of the associated cell.
+ */
+ int cellY = -1;
+
+ /**
+ * Indicates the X cell span.
+ */
+ int spanX = 1;
+
+ /**
+ * Indicates the Y cell span.
+ */
+ int spanY = 1;
+
+ /**
+ * Indicates whether the item is a gesture.
+ */
+ boolean isGesture = false;
+
+ ItemInfo() {
+ }
+
+ ItemInfo(ItemInfo info) {
+ id = info.id;
+ cellX = info.cellX;
+ cellY = info.cellY;
+ spanX = info.spanX;
+ spanY = info.spanY;
+ screen = info.screen;
+ itemType = info.itemType;
+ container = info.container;
+ }
+
+ /**
+ * Write the fields of this item to the DB
+ *
+ * @param values
+ */
+ void onAddToDatabase(ContentValues values) {
+ values.put(LauncherSettings.BaseLauncherColumns.ITEM_TYPE, itemType);
+ if (!isGesture) {
+ values.put(LauncherSettings.Favorites.CONTAINER, container);
+ values.put(LauncherSettings.Favorites.SCREEN, screen);
+ values.put(LauncherSettings.Favorites.CELLX, cellX);
+ values.put(LauncherSettings.Favorites.CELLY, cellY);
+ values.put(LauncherSettings.Favorites.SPANX, spanX);
+ values.put(LauncherSettings.Favorites.SPANY, spanY);
+ }
+ }
+
+ static void writeBitmap(ContentValues values, Bitmap bitmap) {
+ if (bitmap != null) {
+ // Try go guesstimate how much space the icon will take when serialized
+ // to avoid unnecessary allocations/copies during the write.
+ int size = bitmap.getWidth() * bitmap.getHeight() * 4;
+ ByteArrayOutputStream out = new ByteArrayOutputStream(size);
+ try {
+ bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
+ out.flush();
+ out.close();
+
+ values.put(LauncherSettings.Favorites.ICON, out.toByteArray());
+ } catch (IOException e) {
+ Log.w("Favorite", "Could not write icon");
+ }
+ }
+ }
+
+ void unbind() {
+ }
+}
diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java
new file mode 100644
index 0000000..45545db
--- /dev/null
+++ b/src/com/android/launcher2/Launcher.java
@@ -0,0 +1,2272 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.ISearchManager;
+import android.app.SearchManager;
+import android.app.StatusBarManager;
+import android.app.WallpaperManager;
+import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.Intent.ShortcutIconResource;
+import android.content.IntentFilter;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.PackageManager.NameNotFoundException;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.database.ContentObserver;
+import android.graphics.Bitmap;
+import android.graphics.Rect;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.ColorDrawable;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Parcelable;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.SystemProperties;
+import android.provider.LiveFolders;
+import android.text.Selection;
+import android.text.SpannableStringBuilder;
+import android.text.TextUtils;
+import android.text.method.TextKeyListener;
+import android.util.Log;
+import android.view.Display;
+import android.view.HapticFeedbackConstants;
+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.View.OnLongClickListener;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
+import android.widget.ImageView;
+import android.widget.PopupWindow;
+import android.widget.LinearLayout;
+import android.appwidget.AppWidgetManager;
+import android.appwidget.AppWidgetProviderInfo;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.io.DataOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.DataInputStream;
+
+/**
+ * Default launcher application.
+ */
+public final class Launcher extends Activity
+ implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks {
+ static final String TAG = "Launcher";
+ static final boolean LOGD = false;
+
+ static final boolean PROFILE_STARTUP = false;
+ static final boolean PROFILE_ROTATE = false;
+ static final boolean DEBUG_USER_INTERFACE = false;
+
+ private static final int WALLPAPER_SCREENS_SPAN = 2;
+
+ private static final int MENU_GROUP_ADD = 1;
+ private static final int MENU_ADD = Menu.FIRST + 1;
+ private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1;
+ private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1;
+ private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1;
+ private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1;
+
+ private static final int REQUEST_CREATE_SHORTCUT = 1;
+ private static final int REQUEST_CREATE_LIVE_FOLDER = 4;
+ private static final int REQUEST_CREATE_APPWIDGET = 5;
+ private static final int REQUEST_PICK_APPLICATION = 6;
+ private static final int REQUEST_PICK_SHORTCUT = 7;
+ private static final int REQUEST_PICK_LIVE_FOLDER = 8;
+ private static final int REQUEST_PICK_APPWIDGET = 9;
+ private static final int REQUEST_PICK_WALLPAPER = 10;
+
+ static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate";
+
+ static final String EXTRA_CUSTOM_WIDGET = "custom_widget";
+ static final String SEARCH_WIDGET = "search_widget";
+
+ static final int SCREEN_COUNT = 5;
+ static final int DEFAULT_SCREEN = 2;
+ static final int NUMBER_CELLS_X = 4;
+ static final int NUMBER_CELLS_Y = 4;
+
+ static final int DIALOG_CREATE_SHORTCUT = 1;
+ static final int DIALOG_RENAME_FOLDER = 2;
+
+ private static final String PREFERENCES = "launcher.preferences";
+
+ // Type: int
+ private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen";
+ // Type: boolean
+ private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder";
+ // Type: long
+ private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder";
+ // Type: int
+ private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen";
+ // Type: int
+ private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX";
+ // Type: int
+ private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY";
+ // Type: int
+ private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX";
+ // Type: int
+ private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY";
+ // Type: int
+ private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX";
+ // Type: int
+ private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY";
+ // Type: int[]
+ private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells";
+ // Type: boolean
+ private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder";
+ // Type: long
+ private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id";
+
+ static final int APPWIDGET_HOST_ID = 1024;
+
+ private static final Object sLock = new Object();
+ private static int sScreen = DEFAULT_SCREEN;
+
+ private final BroadcastReceiver mCloseSystemDialogsReceiver
+ = new CloseSystemDialogsIntentReceiver();
+ private final ContentObserver mWidgetObserver = new AppWidgetResetObserver();
+
+ private LayoutInflater mInflater;
+
+ private DragController mDragController;
+ private Workspace mWorkspace;
+
+ private AppWidgetManager mAppWidgetManager;
+ private LauncherAppWidgetHost mAppWidgetHost;
+
+ private CellLayout.CellInfo mAddItemCellInfo;
+ private CellLayout.CellInfo mMenuAddInfo;
+ private final int[] mCellCoordinates = new int[2];
+ private FolderInfo mFolderInfo;
+
+ private DeleteZone mDeleteZone;
+ private HandleView mHandleView;
+ private AllAppsView mAllAppsGrid;
+
+ private Bundle mSavedState;
+
+ private SpannableStringBuilder mDefaultKeySsb = null;
+
+ private boolean mIsNewIntent;
+
+ private boolean mWorkspaceLoading = true;
+
+ private boolean mPaused = true;
+ private boolean mRestoring;
+ private boolean mWaitingForResult;
+
+ private Bundle mSavedInstanceState;
+
+ private LauncherModel mModel;
+
+ private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>();
+ private static HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
+
+ private ImageView mPreviousView;
+ private ImageView mNextView;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mModel = ((LauncherApplication)getApplication()).setLauncher(this);
+ mDragController = new DragController(this);
+ mInflater = getLayoutInflater();
+
+ mAppWidgetManager = AppWidgetManager.getInstance(this);
+ mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
+ mAppWidgetHost.startListening();
+
+ if (PROFILE_STARTUP) {
+ android.os.Debug.startMethodTracing("/sdcard/launcher");
+ }
+
+ checkForLocaleChange();
+ setWallpaperDimension();
+
+ setContentView(R.layout.launcher);
+ setupViews();
+
+ registerContentObservers();
+
+ lockAllApps();
+
+ mSavedState = savedInstanceState;
+ restoreState(mSavedState);
+
+ if (PROFILE_STARTUP) {
+ android.os.Debug.stopMethodTracing();
+ }
+
+ // We have a new AllAppsView, we need to re-bind everything, and it could have
+ // changed in our absence.
+ mModel.setAllAppsDirty();
+ mModel.setWorkspaceDirty();
+
+ if (!mRestoring) {
+ mModel.startLoader(this, true);
+ }
+
+ // For handling default keys
+ mDefaultKeySsb = new SpannableStringBuilder();
+ Selection.setSelection(mDefaultKeySsb, 0);
+
+ IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
+ registerReceiver(mCloseSystemDialogsReceiver, filter);
+ }
+
+ private void checkForLocaleChange() {
+ final LocaleConfiguration localeConfiguration = new LocaleConfiguration();
+ readConfiguration(this, localeConfiguration);
+
+ final Configuration configuration = getResources().getConfiguration();
+
+ final String previousLocale = localeConfiguration.locale;
+ final String locale = configuration.locale.toString();
+
+ final int previousMcc = localeConfiguration.mcc;
+ final int mcc = configuration.mcc;
+
+ final int previousMnc = localeConfiguration.mnc;
+ final int mnc = configuration.mnc;
+
+ boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc;
+
+ if (localeChanged) {
+ localeConfiguration.locale = locale;
+ localeConfiguration.mcc = mcc;
+ localeConfiguration.mnc = mnc;
+
+ writeConfiguration(this, localeConfiguration);
+ AppInfoCache.flush();
+ }
+ }
+
+ private static class LocaleConfiguration {
+ public String locale;
+ public int mcc = -1;
+ public int mnc = -1;
+ }
+
+ private static void readConfiguration(Context context, LocaleConfiguration configuration) {
+ DataInputStream in = null;
+ try {
+ in = new DataInputStream(context.openFileInput(PREFERENCES));
+ configuration.locale = in.readUTF();
+ configuration.mcc = in.readInt();
+ configuration.mnc = in.readInt();
+ } catch (FileNotFoundException e) {
+ // Ignore
+ } catch (IOException e) {
+ // Ignore
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ private static void writeConfiguration(Context context, LocaleConfiguration configuration) {
+ DataOutputStream out = null;
+ try {
+ out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE));
+ out.writeUTF(configuration.locale);
+ out.writeInt(configuration.mcc);
+ out.writeInt(configuration.mnc);
+ out.flush();
+ } catch (FileNotFoundException e) {
+ // Ignore
+ } catch (IOException e) {
+ //noinspection ResultOfMethodCallIgnored
+ context.getFileStreamPath(PREFERENCES).delete();
+ } finally {
+ if (out != null) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ static int getScreen() {
+ synchronized (sLock) {
+ return sScreen;
+ }
+ }
+
+ static void setScreen(int screen) {
+ synchronized (sLock) {
+ sScreen = screen;
+ }
+ }
+
+ private void setWallpaperDimension() {
+ WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
+
+ Display display = getWindowManager().getDefaultDisplay();
+ boolean isPortrait = display.getWidth() < display.getHeight();
+
+ final int width = isPortrait ? display.getWidth() : display.getHeight();
+ final int height = isPortrait ? display.getHeight() : display.getWidth();
+ wpm.suggestDesiredDimensions(width * WALLPAPER_SCREENS_SPAN, height);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ mWaitingForResult = false;
+
+ // The pattern used here is that a user PICKs a specific application,
+ // which, depending on the target, might need to CREATE the actual target.
+
+ // For example, the user would PICK_SHORTCUT for "Music playlist", and we
+ // launch over to the Music app to actually CREATE_SHORTCUT.
+
+ if (resultCode == RESULT_OK && mAddItemCellInfo != null) {
+ switch (requestCode) {
+ case REQUEST_PICK_APPLICATION:
+ completeAddApplication(this, data, mAddItemCellInfo);
+ break;
+ case REQUEST_PICK_SHORTCUT:
+ processShortcut(data, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT);
+ break;
+ case REQUEST_CREATE_SHORTCUT:
+ completeAddShortcut(data, mAddItemCellInfo);
+ break;
+ case REQUEST_PICK_LIVE_FOLDER:
+ addLiveFolder(data);
+ break;
+ case REQUEST_CREATE_LIVE_FOLDER:
+ completeAddLiveFolder(data, mAddItemCellInfo);
+ break;
+ case REQUEST_PICK_APPWIDGET:
+ addAppWidget(data);
+ break;
+ case REQUEST_CREATE_APPWIDGET:
+ completeAddAppWidget(data, mAddItemCellInfo);
+ break;
+ case REQUEST_PICK_WALLPAPER:
+ // We just wanted the activity result here so we can clear mWaitingForResult
+ break;
+ }
+ } else if ((requestCode == REQUEST_PICK_APPWIDGET ||
+ requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED &&
+ data != null) {
+ // Clean up the appWidgetId if we canceled
+ int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
+ if (appWidgetId != -1) {
+ mAppWidgetHost.deleteAppWidgetId(appWidgetId);
+ }
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ mPaused = false;
+
+ if (mRestoring) {
+ mWorkspaceLoading = true;
+ mModel.startLoader(this, true);
+ mRestoring = false;
+ }
+
+ // If this was a new intent (i.e., the mIsNewIntent flag got set to true by
+ // onNewIntent), then close the search dialog if needed, because it probably
+ // came from the user pressing 'home' (rather than, for example, pressing 'back').
+ if (mIsNewIntent) {
+ // Post to a handler so that this happens after the search dialog tries to open
+ // itself again.
+ mWorkspace.post(new Runnable() {
+ public void run() {
+ stopSearch();
+ }
+ });
+ }
+
+ mIsNewIntent = false;
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ dismissPreview(mPreviousView);
+ dismissPreview(mNextView);
+ mDragController.cancelDrag();
+ }
+
+ @Override
+ public Object onRetainNonConfigurationInstance() {
+ // Flag the loader to stop early before switching
+ mModel.stopLoader();
+
+ if (PROFILE_ROTATE) {
+ android.os.Debug.startMethodTracing("/sdcard/launcher-rotate");
+ }
+ return null;
+ }
+
+ private boolean acceptFilter() {
+ final InputMethodManager inputManager = (InputMethodManager)
+ getSystemService(Context.INPUT_METHOD_SERVICE);
+ return !inputManager.isFullscreenMode();
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ boolean handled = super.onKeyDown(keyCode, event);
+ if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
+ boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
+ keyCode, event);
+ if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
+ // something usable has been typed - start a search
+ // the typed text will be retrieved and cleared by
+ // showSearchDialog()
+ // If there are multiple keystrokes before the search dialog takes focus,
+ // onSearchRequested() will be called for every keystroke,
+ // but it is idempotent, so it's fine.
+ return onSearchRequested();
+ }
+ }
+
+ return handled;
+ }
+
+ private String getTypedText() {
+ return mDefaultKeySsb.toString();
+ }
+
+ private void clearTypedText() {
+ mDefaultKeySsb.clear();
+ mDefaultKeySsb.clearSpans();
+ Selection.setSelection(mDefaultKeySsb, 0);
+ }
+
+ /**
+ * Restores the previous state, if it exists.
+ *
+ * @param savedState The previous state.
+ */
+ private void restoreState(Bundle savedState) {
+ if (savedState == null) {
+ return;
+ }
+
+ final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false);
+ if (allApps) {
+ showAllApps(false);
+ }
+
+ final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1);
+ if (currentScreen > -1) {
+ mWorkspace.setCurrentScreen(currentScreen);
+ }
+
+ final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1);
+ if (addScreen > -1) {
+ mAddItemCellInfo = new CellLayout.CellInfo();
+ final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
+ addItemCellInfo.valid = true;
+ addItemCellInfo.screen = addScreen;
+ addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X);
+ addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y);
+ addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X);
+ addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y);
+ addItemCellInfo.findVacantCellsFromOccupied(
+ savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS),
+ savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X),
+ savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y));
+ mRestoring = true;
+ }
+
+ boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false);
+ if (renameFolder) {
+ long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID);
+ mFolderInfo = mModel.getFolderById(this, mFolders, id);
+ mRestoring = true;
+ }
+ }
+
+ /**
+ * Finds all the views we need and configure them properly.
+ */
+ private void setupViews() {
+ DragController dragController = mDragController;
+
+ DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer);
+ dragLayer.setDragController(dragController);
+
+ mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view);
+ mAllAppsGrid.setLauncher(this);
+ mAllAppsGrid.setDragController(dragController);
+ mAllAppsGrid.setWillNotDraw(false); // We don't want a hole punched in our window.
+ // Manage focusability manually since this thing is always visible
+ mAllAppsGrid.setFocusable(false);
+
+ mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace);
+ final Workspace workspace = mWorkspace;
+
+ DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone);
+ mDeleteZone = deleteZone;
+
+ mHandleView = (HandleView) findViewById(R.id.all_apps_button);
+ mHandleView.setLauncher(this);
+ mHandleView.setOnClickListener(this);
+
+ mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen);
+ mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen);
+
+ Drawable previous = mPreviousView.getDrawable();
+ Drawable next = mNextView.getDrawable();
+ mWorkspace.setIndicators(previous, next);
+
+ mPreviousView.setHapticFeedbackEnabled(false);
+ mPreviousView.setOnLongClickListener(this);
+ mNextView.setHapticFeedbackEnabled(false);
+ mNextView.setOnLongClickListener(this);
+
+ workspace.setOnLongClickListener(this);
+ workspace.setDragController(dragController);
+ workspace.setLauncher(this);
+
+ deleteZone.setLauncher(this);
+ deleteZone.setDragController(dragController);
+ deleteZone.setHandle(mHandleView);
+
+ dragController.setDragScoller(workspace);
+ dragController.setDragListener(deleteZone);
+ dragController.setScrollView(dragLayer);
+
+ // The order here is bottom to top.
+ dragController.addDropTarget(workspace);
+ dragController.addDropTarget(deleteZone);
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void previousScreen(View v) {
+ if (!isAllAppsVisible()) {
+ mWorkspace.scrollLeft();
+ }
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void nextScreen(View v) {
+ if (!isAllAppsVisible()) {
+ mWorkspace.scrollRight();
+ }
+ }
+
+ /**
+ * Creates a view representing a shortcut.
+ *
+ * @param info The data structure describing the shortcut.
+ *
+ * @return A View inflated from R.layout.application.
+ */
+ View createShortcut(ApplicationInfo info) {
+ return createShortcut(R.layout.application,
+ (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
+ }
+
+ /**
+ * Creates a view representing a shortcut inflated from the specified resource.
+ *
+ * @param layoutResId The id of the XML layout used to create the shortcut.
+ * @param parent The group the shortcut belongs to.
+ * @param info The data structure describing the shortcut.
+ *
+ * @return A View inflated from layoutResId.
+ */
+ View createShortcut(int layoutResId, ViewGroup parent, ApplicationInfo info) {
+ TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false);
+
+ if (info.icon == null) {
+ info.icon = AppInfoCache.getIconDrawable(getPackageManager(), info);
+ }
+ if (!info.filtered) {
+ info.icon = Utilities.createIconThumbnail(info.icon, this);
+ info.filtered = true;
+ }
+
+ favorite.setCompoundDrawablesWithIntrinsicBounds(null, info.icon, null, null);
+ favorite.setText(info.title);
+ favorite.setTag(info);
+ favorite.setOnClickListener(this);
+
+ return favorite;
+ }
+
+ /**
+ * Add an application shortcut to the workspace.
+ *
+ * @param data The intent describing the application.
+ * @param cellInfo The position on screen where to create the shortcut.
+ */
+ void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) {
+ cellInfo.screen = mWorkspace.getCurrentScreen();
+ if (!findSingleSlot(cellInfo)) return;
+
+ final ApplicationInfo info = infoFromApplicationIntent(context, data);
+ if (info != null) {
+ mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked());
+ }
+ }
+
+ private static ApplicationInfo infoFromApplicationIntent(Context context, Intent data) {
+ ComponentName component = data.getComponent();
+ PackageManager packageManager = context.getPackageManager();
+ ActivityInfo activityInfo = null;
+ try {
+ activityInfo = packageManager.getActivityInfo(component, 0 /* no flags */);
+ } catch (NameNotFoundException e) {
+ Log.e(TAG, "Couldn't find ActivityInfo for selected application", e);
+ }
+
+ if (activityInfo != null) {
+ ApplicationInfo itemInfo = new ApplicationInfo();
+
+ itemInfo.title = activityInfo.loadLabel(packageManager);
+ if (itemInfo.title == null) {
+ itemInfo.title = activityInfo.name;
+ }
+
+ itemInfo.setActivity(component, Intent.FLAG_ACTIVITY_NEW_TASK |
+ Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+ itemInfo.icon = activityInfo.loadIcon(packageManager);
+ itemInfo.container = ItemInfo.NO_ID;
+
+ return itemInfo;
+ }
+
+ return null;
+ }
+
+ /**
+ * Add a shortcut to the workspace.
+ *
+ * @param data The intent describing the shortcut.
+ * @param cellInfo The position on screen where to create the shortcut.
+ */
+ private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) {
+ cellInfo.screen = mWorkspace.getCurrentScreen();
+ if (!findSingleSlot(cellInfo)) return;
+
+ final ApplicationInfo info = addShortcut(this, data, cellInfo, false);
+
+ if (!mRestoring) {
+ final View view = createShortcut(info);
+ mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
+ isWorkspaceLocked());
+ }
+ }
+
+
+ /**
+ * Add a widget to the workspace.
+ *
+ * @param data The intent describing the appWidgetId.
+ * @param cellInfo The position on screen where to create the widget.
+ */
+ private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo) {
+ Bundle extras = data.getExtras();
+ int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
+
+ if (LOGD) Log.d(TAG, "dumping extras content=" + extras.toString());
+
+ AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
+
+ // Calculate the grid spans needed to fit this widget
+ CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
+ int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);
+
+ // Try finding open space on Launcher screen
+ final int[] xy = mCellCoordinates;
+ if (!findSlot(cellInfo, xy, spans[0], spans[1])) {
+ if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId);
+ return;
+ }
+
+ // Build Launcher-specific widget info and save to database
+ LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
+ launcherInfo.spanX = spans[0];
+ launcherInfo.spanY = spans[1];
+
+ LauncherModel.addItemToDatabase(this, launcherInfo,
+ LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
+
+ if (!mRestoring) {
+ mDesktopItems.add(launcherInfo);
+
+ // Perform actual inflation because we're live
+ launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
+
+ launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
+ launcherInfo.hostView.setTag(launcherInfo);
+
+ mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1],
+ launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
+ }
+ }
+
+ public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) {
+ mDesktopItems.remove(launcherInfo);
+ launcherInfo.hostView = null;
+ }
+
+ public LauncherAppWidgetHost getAppWidgetHost() {
+ return mAppWidgetHost;
+ }
+
+ static ApplicationInfo addShortcut(Context context, Intent data,
+ CellLayout.CellInfo cellInfo, boolean notify) {
+
+ final ApplicationInfo info = infoFromShortcutIntent(context, data);
+ LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
+
+ return info;
+ }
+
+ private static ApplicationInfo infoFromShortcutIntent(Context context, Intent data) {
+ Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
+ String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
+ Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
+
+ Drawable icon = null;
+ boolean filtered = false;
+ boolean customIcon = false;
+ ShortcutIconResource iconResource = null;
+
+ if (bitmap != null) {
+ icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, context));
+ filtered = true;
+ customIcon = true;
+ } else {
+ Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
+ if (extra != null && extra instanceof ShortcutIconResource) {
+ try {
+ iconResource = (ShortcutIconResource) extra;
+ final PackageManager packageManager = context.getPackageManager();
+ Resources resources = packageManager.getResourcesForApplication(
+ iconResource.packageName);
+ final int id = resources.getIdentifier(iconResource.resourceName, null, null);
+ icon = resources.getDrawable(id);
+ } catch (Exception e) {
+ Log.w(TAG, "Could not load shortcut icon: " + extra);
+ }
+ }
+ }
+
+ if (icon == null) {
+ icon = context.getPackageManager().getDefaultActivityIcon();
+ }
+
+ final ApplicationInfo info = new ApplicationInfo();
+ info.icon = icon;
+ info.filtered = filtered;
+ info.title = name;
+ info.intent = intent;
+ info.customIcon = customIcon;
+ info.iconResource = iconResource;
+
+ return info;
+ }
+
+ void closeSystemDialogs() {
+ getWindow().closeAllPanels();
+
+ try {
+ dismissDialog(DIALOG_CREATE_SHORTCUT);
+ // Unlock the workspace if the dialog was showing
+ } catch (Exception e) {
+ // An exception is thrown if the dialog is not visible, which is fine
+ }
+
+ try {
+ dismissDialog(DIALOG_RENAME_FOLDER);
+ // Unlock the workspace if the dialog was showing
+ } catch (Exception e) {
+ // An exception is thrown if the dialog is not visible, which is fine
+ }
+
+ // Whatever we were doing is hereby canceled.
+ mWaitingForResult = false;
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+
+ // Close the menu
+ if (Intent.ACTION_MAIN.equals(intent.getAction())) {
+ // also will cancel mWaitingForResult.
+ closeSystemDialogs();
+
+ // Set this flag so that onResume knows to close the search dialog if it's open,
+ // because this was a new intent (thus a press of 'home' or some such) rather than
+ // for example onResume being called when the user pressed the 'back' button.
+ mIsNewIntent = true;
+
+ boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
+ != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
+ boolean allAppsVisible = isAllAppsVisible();
+ if (!mWorkspace.isDefaultScreenShowing()) {
+ mWorkspace.moveToDefaultScreen(alreadyOnHome && !allAppsVisible);
+ }
+ closeAllApps(alreadyOnHome && allAppsVisible);
+
+ final View v = getWindow().peekDecorView();
+ if (v != null && v.getWindowToken() != null) {
+ InputMethodManager imm = (InputMethodManager)getSystemService(
+ INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
+ }
+ }
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Bundle savedInstanceState) {
+ // Do not call super here
+ mSavedInstanceState = savedInstanceState;
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle outState) {
+ outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentScreen());
+
+ final ArrayList<Folder> folders = mWorkspace.getOpenFolders();
+ if (folders.size() > 0) {
+ final int count = folders.size();
+ long[] ids = new long[count];
+ for (int i = 0; i < count; i++) {
+ final FolderInfo info = folders.get(i).getInfo();
+ ids[i] = info.id;
+ }
+ outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids);
+ } else {
+ super.onSaveInstanceState(outState);
+ }
+
+ // TODO should not do this if the drawer is currently closing.
+ if (isAllAppsVisible()) {
+ outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true);
+ }
+
+ if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) {
+ final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo;
+ final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen);
+
+ outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen);
+ outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX);
+ outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY);
+ outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX);
+ outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY);
+ outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX());
+ outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY());
+ outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS,
+ layout.getOccupiedCells());
+ }
+
+ if (mFolderInfo != null && mWaitingForResult) {
+ outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true);
+ outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ try {
+ mAppWidgetHost.stopListening();
+ } catch (NullPointerException ex) {
+ Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex);
+ }
+
+ TextKeyListener.getInstance().release();
+
+ mModel.stopLoader();
+
+ unbindDesktopItems();
+ AppInfoCache.unbindDrawables();
+
+ getContentResolver().unregisterContentObserver(mWidgetObserver);
+
+ dismissPreview(mPreviousView);
+ dismissPreview(mNextView);
+
+ unregisterReceiver(mCloseSystemDialogsReceiver);
+ }
+
+ @Override
+ public void startActivityForResult(Intent intent, int requestCode) {
+ if (requestCode >= 0) mWaitingForResult = true;
+ super.startActivityForResult(intent, requestCode);
+ }
+
+ @Override
+ public void startSearch(String initialQuery, boolean selectInitialQuery,
+ Bundle appSearchData, boolean globalSearch) {
+
+ closeAllApps(true);
+
+ // Slide the search widget to the top, if it's on the current screen,
+ // otherwise show the search dialog immediately.
+ Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
+ if (searchWidget == null) {
+ showSearchDialog(initialQuery, selectInitialQuery, appSearchData, globalSearch);
+ } else {
+ searchWidget.startSearch(initialQuery, selectInitialQuery, appSearchData, globalSearch);
+ // show the currently typed text in the search widget while sliding
+ searchWidget.setQuery(getTypedText());
+ }
+ }
+
+ /**
+ * Show the search dialog immediately, without changing the search widget.
+ *
+ * @see Activity#startSearch(String, boolean, android.os.Bundle, boolean)
+ */
+ void showSearchDialog(String initialQuery, boolean selectInitialQuery,
+ Bundle appSearchData, boolean globalSearch) {
+
+ if (initialQuery == null) {
+ // Use any text typed in the launcher as the initial query
+ initialQuery = getTypedText();
+ clearTypedText();
+ }
+ if (appSearchData == null) {
+ appSearchData = new Bundle();
+ appSearchData.putString(SearchManager.SOURCE, "launcher-search");
+ }
+
+ final SearchManager searchManager =
+ (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+
+ final Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
+ if (searchWidget != null) {
+ // This gets called when the user leaves the search dialog to go back to
+ // the Launcher.
+ searchManager.setOnCancelListener(new SearchManager.OnCancelListener() {
+ public void onCancel() {
+ searchManager.setOnCancelListener(null);
+ stopSearch();
+ }
+ });
+ }
+
+ searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(),
+ appSearchData, globalSearch);
+ }
+
+ /**
+ * Cancel search dialog if it is open.
+ */
+ void stopSearch() {
+ // Close search dialog
+ SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+ searchManager.stopSearch();
+ // Restore search widget to its normal position
+ Search searchWidget = mWorkspace.findSearchWidgetOnCurrentScreen();
+ if (searchWidget != null) {
+ searchWidget.stopSearch(false);
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ if (isWorkspaceLocked()) {
+ return false;
+ }
+
+ super.onCreateOptionsMenu(menu);
+ menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add)
+ .setIcon(android.R.drawable.ic_menu_add)
+ .setAlphabeticShortcut('A');
+ 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_NOTIFICATIONS, 0, R.string.menu_notifications)
+ .setIcon(com.android.internal.R.drawable.ic_menu_notifications)
+ .setAlphabeticShortcut('N');
+
+ final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS);
+ settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
+ Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+
+ menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings)
+ .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P')
+ .setIntent(settings);
+
+ return true;
+ }
+
+ @Override
+ public boolean onPrepareOptionsMenu(Menu menu) {
+ super.onPrepareOptionsMenu(menu);
+
+ mMenuAddInfo = mWorkspace.findAllVacantCells(null);
+ menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid);
+
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case MENU_ADD:
+ addItems();
+ return true;
+ case MENU_WALLPAPER_SETTINGS:
+ startWallpaper();
+ return true;
+ case MENU_SEARCH:
+ onSearchRequested();
+ return true;
+ case MENU_NOTIFICATIONS:
+ showNotifications();
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ /**
+ * Indicates that we want global search for this activity by setting the globalSearch
+ * argument for {@link #startSearch} to true.
+ */
+
+ @Override
+ public boolean onSearchRequested() {
+ startSearch(null, false, null, true);
+ return true;
+ }
+
+ public boolean isWorkspaceLocked() {
+ return mWorkspaceLoading || mWaitingForResult;
+ }
+
+ private void addItems() {
+ closeAllApps(true);
+ showAddDialog(mMenuAddInfo);
+ }
+
+ void addAppWidget(Intent data) {
+ // TODO: catch bad widget exception when sent
+ int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
+
+ String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET);
+ if (SEARCH_WIDGET.equals(customWidget)) {
+ // We don't need this any more, since this isn't a real app widget.
+ mAppWidgetHost.deleteAppWidgetId(appWidgetId);
+ // add the search widget
+ addSearch();
+ } else {
+ AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
+
+ if (appWidget.configure != null) {
+ // Launch over to configure widget, if needed
+ Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
+ intent.setComponent(appWidget.configure);
+ intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
+
+ startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
+ } else {
+ // Otherwise just add it
+ onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
+ }
+ }
+ }
+
+ void addSearch() {
+ final Widget info = Widget.makeSearch();
+ final CellLayout.CellInfo cellInfo = mAddItemCellInfo;
+
+ final int[] xy = mCellCoordinates;
+ final int spanX = info.spanX;
+ final int spanY = info.spanY;
+
+ if (!findSlot(cellInfo, xy, spanX, spanY)) return;
+
+ LauncherModel.addItemToDatabase(this, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
+
+ final View view = mInflater.inflate(info.layoutResource, null);
+ view.setTag(info);
+ Search search = (Search) view.findViewById(R.id.widget_search);
+ search.setLauncher(this);
+
+ mWorkspace.addInCurrentScreen(view, xy[0], xy[1], info.spanX, spanY);
+ }
+
+ void processShortcut(Intent intent, int requestCodeApplication, int requestCodeShortcut) {
+ // Handle case where user selected "Applications"
+ String applicationName = getResources().getString(R.string.group_applications);
+ String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
+
+ if (applicationName != null && applicationName.equals(shortcutName)) {
+ Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
+ mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+
+ Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
+ pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent);
+ startActivityForResult(pickIntent, requestCodeApplication);
+ } else {
+ startActivityForResult(intent, requestCodeShortcut);
+ }
+ }
+
+ void addLiveFolder(Intent intent) {
+ // Handle case where user selected "Folder"
+ String folderName = getResources().getString(R.string.group_folder);
+ String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
+
+ if (folderName != null && folderName.equals(shortcutName)) {
+ addFolder();
+ } else {
+ startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER);
+ }
+ }
+
+ void addFolder() {
+ UserFolderInfo folderInfo = new UserFolderInfo();
+ folderInfo.title = getText(R.string.folder_name);
+
+ CellLayout.CellInfo cellInfo = mAddItemCellInfo;
+ cellInfo.screen = mWorkspace.getCurrentScreen();
+ if (!findSingleSlot(cellInfo)) return;
+
+ // Update the model
+ LauncherModel.addItemToDatabase(this, folderInfo,
+ LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ mWorkspace.getCurrentScreen(), cellInfo.cellX, cellInfo.cellY, false);
+ mFolders.put(folderInfo.id, folderInfo);
+
+ // Create the view
+ FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
+ (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), folderInfo);
+ mWorkspace.addInCurrentScreen(newFolder,
+ cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked());
+ }
+
+ void removeFolder(FolderInfo folder) {
+ mFolders.remove(folder.id);
+ }
+
+ private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) {
+ cellInfo.screen = mWorkspace.getCurrentScreen();
+ if (!findSingleSlot(cellInfo)) return;
+
+ final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false);
+
+ if (!mRestoring) {
+ final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this,
+ (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentScreen()), info);
+ mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1,
+ isWorkspaceLocked());
+ }
+ }
+
+ static LiveFolderInfo addLiveFolder(Context context, Intent data,
+ CellLayout.CellInfo cellInfo, boolean notify) {
+
+ Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT);
+ String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME);
+
+ Drawable icon = null;
+ boolean filtered = false;
+ Intent.ShortcutIconResource iconResource = null;
+
+ Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON);
+ if (extra != null && extra instanceof Intent.ShortcutIconResource) {
+ try {
+ iconResource = (Intent.ShortcutIconResource) extra;
+ final PackageManager packageManager = context.getPackageManager();
+ Resources resources = packageManager.getResourcesForApplication(
+ iconResource.packageName);
+ final int id = resources.getIdentifier(iconResource.resourceName, null, null);
+ icon = resources.getDrawable(id);
+ } catch (Exception e) {
+ Log.w(TAG, "Could not load live folder icon: " + extra);
+ }
+ }
+
+ if (icon == null) {
+ icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder);
+ }
+
+ final LiveFolderInfo info = new LiveFolderInfo();
+ info.icon = icon;
+ info.filtered = filtered;
+ info.title = name;
+ info.iconResource = iconResource;
+ info.uri = data.getData();
+ info.baseIntent = baseIntent;
+ info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE,
+ LiveFolders.DISPLAY_MODE_GRID);
+
+ LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP,
+ cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify);
+ mFolders.put(info.id, info);
+
+ return info;
+ }
+
+ private boolean findSingleSlot(CellLayout.CellInfo cellInfo) {
+ final int[] xy = new int[2];
+ if (findSlot(cellInfo, xy, 1, 1)) {
+ cellInfo.cellX = xy[0];
+ cellInfo.cellY = xy[1];
+ return true;
+ }
+ return false;
+ }
+
+ private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) {
+ if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
+ boolean[] occupied = mSavedState != null ?
+ mSavedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS) : null;
+ cellInfo = mWorkspace.findAllVacantCells(occupied);
+ if (!cellInfo.findCellForSpan(xy, spanX, spanY)) {
+ Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show();
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void showNotifications() {
+ final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE);
+ if (statusBar != null) {
+ statusBar.expand();
+ }
+ }
+
+ private void startWallpaper() {
+ closeAllApps(true);
+ final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
+ Intent chooser = Intent.createChooser(pickWallpaper,
+ getText(R.string.chooser_wallpaper));
+ // NOTE: Adds a configure option to the chooser if the wallpaper supports it
+ // Removed in Eclair MR1
+// WallpaperManager wm = (WallpaperManager)
+// getSystemService(Context.WALLPAPER_SERVICE);
+// WallpaperInfo wi = wm.getWallpaperInfo();
+// if (wi != null && wi.getSettingsActivity() != null) {
+// LabeledIntent li = new LabeledIntent(getPackageName(),
+// R.string.configure_wallpaper, 0);
+// li.setClassName(wi.getPackageName(), wi.getSettingsActivity());
+// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li });
+// }
+ startActivityForResult(chooser, REQUEST_PICK_WALLPAPER);
+ }
+
+ /**
+ * Registers various content observers. The current implementation registers
+ * only a favorites observer to keep track of the favorites applications.
+ */
+ private void registerContentObservers() {
+ ContentResolver resolver = getContentResolver();
+ resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI,
+ true, mWidgetObserver);
+ }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ switch (event.getKeyCode()) {
+ case KeyEvent.KEYCODE_HOME:
+ return true;
+ case KeyEvent.KEYCODE_VOLUME_DOWN:
+ if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) {
+ dumpState();
+ return true;
+ }
+ break;
+ }
+ } else if (event.getAction() == KeyEvent.ACTION_UP) {
+ switch (event.getKeyCode()) {
+ case KeyEvent.KEYCODE_HOME:
+ return true;
+ }
+ }
+
+ return super.dispatchKeyEvent(event);
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (isAllAppsVisible()) {
+ closeAllApps(true);
+ } else {
+ closeFolder();
+ }
+ dismissPreview(mPreviousView);
+ dismissPreview(mNextView);
+ }
+
+ private void closeFolder() {
+ Folder folder = mWorkspace.getOpenFolder();
+ if (folder != null) {
+ closeFolder(folder);
+ }
+ }
+
+ void closeFolder(Folder folder) {
+ folder.getInfo().opened = false;
+ ViewGroup parent = (ViewGroup) folder.getParent();
+ if (parent != null) {
+ parent.removeView(folder);
+ if (folder instanceof DropTarget) {
+ // Live folders aren't DropTargets.
+ mDragController.removeDropTarget((DropTarget)folder);
+ }
+ }
+ folder.onClose();
+ }
+
+ /**
+ * Re-listen when widgets are reset.
+ */
+ private void onAppWidgetReset() {
+ mAppWidgetHost.startListening();
+ }
+
+ /**
+ * Go through the and disconnect any of the callbacks in the drawables and the views or we
+ * leak the previous Home screen on orientation change.
+ */
+ private void unbindDesktopItems() {
+ for (ItemInfo item: mDesktopItems) {
+ item.unbind();
+ }
+ }
+
+ /**
+ * Launches the intent referred by the clicked shortcut.
+ *
+ * @param v The view representing the clicked shortcut.
+ */
+ public void onClick(View v) {
+ Object tag = v.getTag();
+ if (tag instanceof ApplicationInfo) {
+ // Open shortcut
+ final Intent intent = ((ApplicationInfo) tag).intent;
+ int[] pos = new int[2];
+ v.getLocationOnScreen(pos);
+ intent.setSourceBounds(
+ new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight()));
+ startActivitySafely(intent);
+ } else if (tag instanceof FolderInfo) {
+ handleFolderClick((FolderInfo) tag);
+ } else if (v == mHandleView) {
+ if (isAllAppsVisible()) {
+ closeAllApps(true);
+ } else {
+ showAllApps(true);
+ }
+ }
+ }
+
+ void startActivitySafely(Intent intent) {
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ startActivity(intent);
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
+ } catch (SecurityException e) {
+ Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
+ Log.e(TAG, "Launcher does not have the permission to launch " + intent +
+ ". Make sure to create a MAIN intent-filter for the corresponding activity " +
+ "or use the exported attribute for this activity.", e);
+ }
+ }
+
+ private void handleFolderClick(FolderInfo folderInfo) {
+ if (!folderInfo.opened) {
+ // Close any open folder
+ closeFolder();
+ // Open the requested folder
+ openFolder(folderInfo);
+ } else {
+ // Find the open folder...
+ Folder openFolder = mWorkspace.getFolderForTag(folderInfo);
+ int folderScreen;
+ if (openFolder != null) {
+ folderScreen = mWorkspace.getScreenForView(openFolder);
+ // .. and close it
+ closeFolder(openFolder);
+ if (folderScreen != mWorkspace.getCurrentScreen()) {
+ // Close any folder open on the current screen
+ closeFolder();
+ // Pull the folder onto this screen
+ openFolder(folderInfo);
+ }
+ }
+ }
+ }
+
+ /**
+ * Opens the user fodler described by the specified tag. The opening of the folder
+ * is animated relative to the specified View. If the View is null, no animation
+ * is played.
+ *
+ * @param folderInfo The FolderInfo describing the folder to open.
+ */
+ private void openFolder(FolderInfo folderInfo) {
+ Folder openFolder;
+
+ if (folderInfo instanceof UserFolderInfo) {
+ openFolder = UserFolder.fromXml(this);
+ } else if (folderInfo instanceof LiveFolderInfo) {
+ openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo);
+ } else {
+ return;
+ }
+
+ openFolder.setDragController(mDragController);
+ openFolder.setLauncher(this);
+
+ openFolder.bind(folderInfo);
+ folderInfo.opened = true;
+
+ mWorkspace.addInScreen(openFolder, folderInfo.screen, 0, 0, 4, 4);
+ openFolder.onOpen();
+ }
+
+ public boolean onLongClick(View v) {
+ switch (v.getId()) {
+ case R.id.previous_screen:
+ if (!isAllAppsVisible()) {
+ mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
+ HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
+ showPreviousPreview(v);
+ }
+ return true;
+ case R.id.next_screen:
+ if (!isAllAppsVisible()) {
+ mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
+ HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
+ showNextPreview(v);
+ }
+ return true;
+ }
+
+ if (isWorkspaceLocked()) {
+ return false;
+ }
+
+ if (!(v instanceof CellLayout)) {
+ v = (View) v.getParent();
+ }
+
+ CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag();
+
+ // This happens when long clicking an item with the dpad/trackball
+ if (cellInfo == null) {
+ return true;
+ }
+
+ if (mWorkspace.allowLongPress()) {
+ if (cellInfo.cell == null) {
+ if (cellInfo.valid) {
+ // User long pressed on empty space
+ mWorkspace.setAllowLongPress(false);
+ showAddDialog(cellInfo);
+ }
+ } else {
+ if (!(cellInfo.cell instanceof Folder)) {
+ // User long pressed on an item
+ mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
+ HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
+ mWorkspace.startDrag(cellInfo);
+ }
+ }
+ }
+ return true;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ private void dismissPreview(final View v) {
+ final PopupWindow window = (PopupWindow) v.getTag();
+ if (window != null) {
+ window.setOnDismissListener(new PopupWindow.OnDismissListener() {
+ public void onDismiss() {
+ ViewGroup group = (ViewGroup) v.getTag(R.id.workspace);
+ int count = group.getChildCount();
+ for (int i = 0; i < count; i++) {
+ ((ImageView) group.getChildAt(i)).setImageDrawable(null);
+ }
+ ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon);
+ for (Bitmap bitmap : bitmaps) bitmap.recycle();
+
+ v.setTag(R.id.workspace, null);
+ v.setTag(R.id.icon, null);
+ window.setOnDismissListener(null);
+ }
+ });
+ window.dismiss();
+ }
+ v.setTag(null);
+ }
+
+ private void showPreviousPreview(View anchor) {
+ int current = mWorkspace.getCurrentScreen();
+ if (current <= 0) return;
+
+ showPreviews(anchor, 0, mWorkspace.getChildCount());
+ }
+
+ private void showNextPreview(View anchor) {
+ int current = mWorkspace.getCurrentScreen();
+ if (current >= mWorkspace.getChildCount() - 1) return;
+
+ showPreviews(anchor, 0, mWorkspace.getChildCount());
+ }
+
+ private void showPreviews(final View anchor, int start, int end) {
+ Resources resources = getResources();
+
+ Workspace workspace = mWorkspace;
+ CellLayout cell = ((CellLayout) workspace.getChildAt(start));
+
+ float max = workspace.getChildCount();
+
+ Rect r = new Rect();
+ resources.getDrawable(R.drawable.preview_background).getPadding(r);
+ int extraW = (int) ((r.left + r.right) * max);
+ int extraH = r.top + r.bottom;
+
+ int aW = cell.getWidth() - extraW;
+ float w = aW / max;
+
+ int width = cell.getWidth();
+ int height = cell.getHeight();
+ int x = cell.getLeftPadding();
+ int y = cell.getTopPadding();
+ width -= (x + cell.getRightPadding());
+ height -= (y + cell.getBottomPadding());
+
+ float scale = w / width;
+
+ int count = end - start;
+
+ final float sWidth = width * scale;
+ float sHeight = height * scale;
+
+ LinearLayout preview = new LinearLayout(this);
+
+ PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
+ ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);
+
+ for (int i = start; i < end; i++) {
+ ImageView image = new ImageView(this);
+ cell = (CellLayout) workspace.getChildAt(i);
+
+ Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight,
+ Bitmap.Config.ARGB_8888);
+
+ Canvas c = new Canvas(bitmap);
+ c.scale(scale, scale);
+ c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
+ cell.dispatchDraw(c);
+
+ image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background));
+ image.setImageBitmap(bitmap);
+ image.setTag(i);
+ image.setOnClickListener(handler);
+ image.setOnFocusChangeListener(handler);
+ image.setFocusable(true);
+ if (i == mWorkspace.getCurrentScreen()) image.requestFocus();
+
+ preview.addView(image,
+ LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
+
+ bitmaps.add(bitmap);
+ }
+
+ PopupWindow p = new PopupWindow(this);
+ p.setContentView(preview);
+ p.setWidth((int) (sWidth * count + extraW));
+ p.setHeight((int) (sHeight + extraH));
+ p.setAnimationStyle(R.style.AnimationPreview);
+ p.setOutsideTouchable(true);
+ p.setFocusable(true);
+ p.setBackgroundDrawable(new ColorDrawable(0));
+ p.showAsDropDown(anchor, 0, 0);
+
+ p.setOnDismissListener(new PopupWindow.OnDismissListener() {
+ public void onDismiss() {
+ dismissPreview(anchor);
+ }
+ });
+
+ anchor.setTag(p);
+ anchor.setTag(R.id.workspace, preview);
+ anchor.setTag(R.id.icon, bitmaps);
+ }
+
+ class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener {
+ private final View mAnchor;
+
+ public PreviewTouchHandler(View anchor) {
+ mAnchor = anchor;
+ }
+
+ public void onClick(View v) {
+ mWorkspace.snapToScreen((Integer) v.getTag());
+ v.post(this);
+ }
+
+ public void run() {
+ dismissPreview(mAnchor);
+ }
+
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (hasFocus) {
+ mWorkspace.snapToScreen((Integer) v.getTag());
+ }
+ }
+ }
+
+ View getDrawerHandle() {
+ return mHandleView;
+ }
+
+ Workspace getWorkspace() {
+ return mWorkspace;
+ }
+
+ @Override
+ protected Dialog onCreateDialog(int id) {
+ switch (id) {
+ case DIALOG_CREATE_SHORTCUT:
+ return new CreateShortcut().createDialog();
+ case DIALOG_RENAME_FOLDER:
+ return new RenameFolder().createDialog();
+ }
+
+ return super.onCreateDialog(id);
+ }
+
+ @Override
+ protected void onPrepareDialog(int id, Dialog dialog) {
+ switch (id) {
+ case DIALOG_CREATE_SHORTCUT:
+ break;
+ case DIALOG_RENAME_FOLDER:
+ if (mFolderInfo != null) {
+ EditText input = (EditText) dialog.findViewById(R.id.folder_name);
+ final CharSequence text = mFolderInfo.title;
+ input.setText(text);
+ input.setSelection(0, text.length());
+ }
+ break;
+ }
+ }
+
+ void showRenameDialog(FolderInfo info) {
+ mFolderInfo = info;
+ mWaitingForResult = true;
+ showDialog(DIALOG_RENAME_FOLDER);
+ }
+
+ private void showAddDialog(CellLayout.CellInfo cellInfo) {
+ mAddItemCellInfo = cellInfo;
+ mWaitingForResult = true;
+ showDialog(DIALOG_CREATE_SHORTCUT);
+ }
+
+ private void pickShortcut(int requestCode, int title) {
+ Bundle bundle = new Bundle();
+
+ ArrayList<String> shortcutNames = new ArrayList<String>();
+ shortcutNames.add(getString(R.string.group_applications));
+ bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
+
+ ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
+ shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
+ R.drawable.ic_launcher_application));
+ bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
+
+ Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
+ pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
+ pickIntent.putExtra(Intent.EXTRA_TITLE, getText(title));
+ pickIntent.putExtras(bundle);
+
+ startActivityForResult(pickIntent, requestCode);
+ }
+
+ private class RenameFolder {
+ private EditText mInput;
+
+ Dialog createDialog() {
+ mWaitingForResult = true;
+ final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null);
+ mInput = (EditText) layout.findViewById(R.id.folder_name);
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
+ builder.setIcon(0);
+ builder.setTitle(getString(R.string.rename_folder_title));
+ builder.setCancelable(true);
+ builder.setOnCancelListener(new Dialog.OnCancelListener() {
+ public void onCancel(DialogInterface dialog) {
+ cleanup();
+ }
+ });
+ builder.setNegativeButton(getString(R.string.cancel_action),
+ new Dialog.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ cleanup();
+ }
+ }
+ );
+ builder.setPositiveButton(getString(R.string.rename_action),
+ new Dialog.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ changeFolderName();
+ }
+ }
+ );
+ builder.setView(layout);
+
+ final AlertDialog dialog = builder.create();
+ dialog.setOnShowListener(new DialogInterface.OnShowListener() {
+ public void onShow(DialogInterface dialog) {
+ mInput.requestFocus();
+ InputMethodManager inputManager = (InputMethodManager)
+ getSystemService(Context.INPUT_METHOD_SERVICE);
+ inputManager.showSoftInput(mInput, 0);
+ }
+ });
+
+ return dialog;
+ }
+
+ private void changeFolderName() {
+ final String name = mInput.getText().toString();
+ if (!TextUtils.isEmpty(name)) {
+ // Make sure we have the right folder info
+ mFolderInfo = mFolders.get(mFolderInfo.id);
+ mFolderInfo.title = name;
+ LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo);
+
+ if (mWorkspaceLoading) {
+ lockAllApps();
+ mModel.setWorkspaceDirty();
+ mModel.startLoader(Launcher.this, false);
+ } else {
+ final FolderIcon folderIcon = (FolderIcon)
+ mWorkspace.getViewForTag(mFolderInfo);
+ if (folderIcon != null) {
+ folderIcon.setText(name);
+ getWorkspace().requestLayout();
+ } else {
+ lockAllApps();
+ mModel.setWorkspaceDirty();
+ mWorkspaceLoading = true;
+ mModel.startLoader(Launcher.this, false);
+ }
+ }
+ }
+ cleanup();
+ }
+
+ private void cleanup() {
+ dismissDialog(DIALOG_RENAME_FOLDER);
+ mWaitingForResult = false;
+ mFolderInfo = null;
+ }
+ }
+
+ boolean isAllAppsVisible() {
+ return mAllAppsGrid.isVisible();
+ }
+
+ boolean isAllAppsOpaque() {
+ return mAllAppsGrid.isOpaque();
+ }
+
+ void showAllApps(boolean animated) {
+ mAllAppsGrid.zoom(1.0f, animated);
+ //mWorkspace.hide();
+
+ mWorkspace.startFading(false);
+
+ mAllAppsGrid.setFocusable(true);
+ mAllAppsGrid.requestFocus();
+
+ // TODO: fade these two too
+ mDeleteZone.setVisibility(View.GONE);
+ //mHandleView.setVisibility(View.GONE);
+ }
+
+ /**
+ * Things to test when changing this code.
+ * - Home from workspace
+ * - from center screen
+ * - from other screens
+ * - Home from all apps
+ * - from center screen
+ * - from other screens
+ * - Back from all apps
+ * - from center screen
+ * - from other screens
+ * - Launch app from workspace and quit
+ * - with back
+ * - with home
+ * - Launch app from all apps and quit
+ * - with back
+ * - with home
+ * - Go to a screen that's not the default, then all
+ * apps, and launch and app, and go back
+ * - with back
+ * -with home
+ * - On workspace, long press power and go back
+ * - with back
+ * - with home
+ * - On all apps, long press power and go back
+ * - with back
+ * - with home
+ * - On workspace, power off
+ * - On all apps, power off
+ * - Launch an app and turn off the screen while in that app
+ * - Go back with home key
+ * - Go back with back key TODO: make this not go to workspace
+ * - From all apps
+ * - From workspace
+ */
+ void closeAllApps(boolean animated) {
+ if (mAllAppsGrid.isVisible()) {
+ mAllAppsGrid.zoom(0.0f, animated);
+ mAllAppsGrid.setFocusable(false);
+ mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
+ mWorkspace.startFading(true);
+
+ // TODO: fade these two too
+ /*
+ mDeleteZone.setVisibility(View.VISIBLE);
+ mHandleView.setVisibility(View.VISIBLE);
+ */
+ }
+ }
+
+ void lockAllApps() {
+ // TODO
+ }
+
+ void unlockAllApps() {
+ // TODO
+ }
+
+ /**
+ * Displays the shortcut creation dialog and launches, if necessary, the
+ * appropriate activity.
+ */
+ private class CreateShortcut implements DialogInterface.OnClickListener,
+ DialogInterface.OnCancelListener, DialogInterface.OnDismissListener,
+ DialogInterface.OnShowListener {
+
+ private AddAdapter mAdapter;
+
+ Dialog createDialog() {
+ mWaitingForResult = true;
+
+ mAdapter = new AddAdapter(Launcher.this);
+
+ final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this);
+ builder.setTitle(getString(R.string.menu_item_add_item));
+ builder.setAdapter(mAdapter, this);
+
+ builder.setInverseBackgroundForced(true);
+
+ AlertDialog dialog = builder.create();
+ dialog.setOnCancelListener(this);
+ dialog.setOnDismissListener(this);
+ dialog.setOnShowListener(this);
+
+ return dialog;
+ }
+
+ public void onCancel(DialogInterface dialog) {
+ mWaitingForResult = false;
+ cleanup();
+ }
+
+ public void onDismiss(DialogInterface dialog) {
+ }
+
+ private void cleanup() {
+ try {
+ dismissDialog(DIALOG_CREATE_SHORTCUT);
+ } catch (Exception e) {
+ // An exception is thrown if the dialog is not visible, which is fine
+ }
+ }
+
+ /**
+ * Handle the action clicked in the "Add to home" dialog.
+ */
+ public void onClick(DialogInterface dialog, int which) {
+ Resources res = getResources();
+ cleanup();
+
+ switch (which) {
+ case AddAdapter.ITEM_SHORTCUT: {
+ // Insert extra item to handle picking application
+ pickShortcut(REQUEST_PICK_SHORTCUT, R.string.title_select_shortcut);
+ break;
+ }
+
+ case AddAdapter.ITEM_APPWIDGET: {
+ int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId();
+
+ Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
+ pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
+ // add the search widget
+ ArrayList<AppWidgetProviderInfo> customInfo =
+ new ArrayList<AppWidgetProviderInfo>();
+ AppWidgetProviderInfo info = new AppWidgetProviderInfo();
+ info.provider = new ComponentName(getPackageName(), "XXX.YYY");
+ info.label = getString(R.string.group_search);
+ info.icon = R.drawable.ic_search_widget;
+ customInfo.add(info);
+ pickIntent.putParcelableArrayListExtra(
+ AppWidgetManager.EXTRA_CUSTOM_INFO, customInfo);
+ ArrayList<Bundle> customExtras = new ArrayList<Bundle>();
+ Bundle b = new Bundle();
+ b.putString(EXTRA_CUSTOM_WIDGET, SEARCH_WIDGET);
+ customExtras.add(b);
+ pickIntent.putParcelableArrayListExtra(
+ AppWidgetManager.EXTRA_CUSTOM_EXTRAS, customExtras);
+ // start the pick activity
+ startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
+ break;
+ }
+
+ case AddAdapter.ITEM_LIVE_FOLDER: {
+ // Insert extra item to handle inserting folder
+ Bundle bundle = new Bundle();
+
+ ArrayList<String> shortcutNames = new ArrayList<String>();
+ shortcutNames.add(res.getString(R.string.group_folder));
+ bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
+
+ ArrayList<ShortcutIconResource> shortcutIcons =
+ new ArrayList<ShortcutIconResource>();
+ shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this,
+ R.drawable.ic_launcher_folder));
+ bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons);
+
+ Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
+ pickIntent.putExtra(Intent.EXTRA_INTENT,
+ new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER));
+ pickIntent.putExtra(Intent.EXTRA_TITLE,
+ getText(R.string.title_select_live_folder));
+ pickIntent.putExtras(bundle);
+
+ startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER);
+ break;
+ }
+
+ case AddAdapter.ITEM_WALLPAPER: {
+ startWallpaper();
+ break;
+ }
+ }
+ }
+
+ public void onShow(DialogInterface dialog) {
+ }
+ }
+
+ /**
+ * Receives notifications when applications are added/removed.
+ */
+ private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ closeSystemDialogs();
+ String reason = intent.getStringExtra("reason");
+ if (!"homekey".equals(reason)) {
+ boolean animate = true;
+ if (mPaused || "lock".equals(reason)) {
+ animate = false;
+ }
+ closeAllApps(animate);
+ }
+ }
+ }
+
+ /**
+ * Receives notifications whenever the appwidgets are reset.
+ */
+ private class AppWidgetResetObserver extends ContentObserver {
+ public AppWidgetResetObserver() {
+ super(new Handler());
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ onAppWidgetReset();
+ }
+ }
+
+ /**
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public int getCurrentWorkspaceScreen() {
+ return mWorkspace.getCurrentScreen();
+ }
+
+ /**
+ * Refreshes the shortcuts shown on the workspace.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void startBinding() {
+ final Workspace workspace = mWorkspace;
+ int count = workspace.getChildCount();
+ for (int i = 0; i < count; i++) {
+ // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate().
+ ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout();
+ }
+
+ if (DEBUG_USER_INTERFACE) {
+ android.widget.Button finishButton = new android.widget.Button(this);
+ finishButton.setText("Finish");
+ workspace.addInScreen(finishButton, 1, 0, 0, 1, 1);
+
+ finishButton.setOnClickListener(new android.widget.Button.OnClickListener() {
+ public void onClick(View v) {
+ finish();
+ }
+ });
+ }
+ }
+
+ /**
+ * Bind the items start-end from the list.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) {
+
+ final Workspace workspace = mWorkspace;
+
+ for (int i=start; i<end; i++) {
+ final ItemInfo item = shortcuts.get(i);
+ mDesktopItems.add(item);
+ switch (item.itemType) {
+ case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
+ case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
+ final View shortcut = createShortcut((ApplicationInfo) item);
+ workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1,
+ false);
+ break;
+ case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
+ final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this,
+ (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
+ (UserFolderInfo) item);
+ workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1,
+ false);
+ break;
+ case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
+ final FolderIcon newLiveFolder = LiveFolderIcon.fromXml(
+ R.layout.live_folder_icon, this,
+ (ViewGroup) workspace.getChildAt(workspace.getCurrentScreen()),
+ (LiveFolderInfo) item);
+ workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1,
+ false);
+ break;
+ case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH:
+ final int screen = workspace.getCurrentScreen();
+ final View view = mInflater.inflate(R.layout.widget_search,
+ (ViewGroup) workspace.getChildAt(screen), false);
+
+ Search search = (Search) view.findViewById(R.id.widget_search);
+ search.setLauncher(this);
+
+ final Widget widget = (Widget) item;
+ view.setTag(widget);
+
+ workspace.addWidget(view, widget, false);
+ break;
+ }
+ }
+
+ workspace.requestLayout();
+ }
+
+ /**
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindFolders(HashMap<Long, FolderInfo> folders) {
+ mFolders.clear();
+ mFolders.putAll(folders);
+ }
+
+ /**
+ * Add the views for a widget to the workspace.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindAppWidget(LauncherAppWidgetInfo item) {
+ final Workspace workspace = mWorkspace;
+
+ final int appWidgetId = item.appWidgetId;
+ final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
+ item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
+
+ item.hostView.setAppWidget(appWidgetId, appWidgetInfo);
+ item.hostView.setTag(item);
+
+ workspace.addInScreen(item.hostView, item.screen, item.cellX,
+ item.cellY, item.spanX, item.spanY, false);
+
+ workspace.requestLayout();
+
+ mDesktopItems.add(item);
+ }
+
+ /**
+ * Callback saying that there aren't any more items to bind.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void finishBindingItems() {
+ if (mSavedState != null) {
+ if (!mWorkspace.hasFocus()) {
+ mWorkspace.getChildAt(mWorkspace.getCurrentScreen()).requestFocus();
+ }
+
+ final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS);
+ if (userFolders != null) {
+ for (long folderId : userFolders) {
+ final FolderInfo info = mFolders.get(folderId);
+ if (info != null) {
+ openFolder(info);
+ }
+ }
+ final Folder openFolder = mWorkspace.getOpenFolder();
+ if (openFolder != null) {
+ openFolder.requestFocus();
+ }
+ }
+
+ mSavedState = null;
+ }
+
+ if (mSavedInstanceState != null) {
+ super.onRestoreInstanceState(mSavedInstanceState);
+ mSavedInstanceState = null;
+ }
+
+ mWorkspaceLoading = false;
+ }
+
+ /**
+ * Add the icons for all apps.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindAllApplications(ArrayList<ApplicationInfo> apps) {
+ mAllAppsGrid.setApps(apps);
+ }
+
+ /**
+ * A package was installed.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindPackageAdded(ArrayList<ApplicationInfo> apps) {
+ removeDialog(DIALOG_CREATE_SHORTCUT);
+ mAllAppsGrid.addApps(apps);
+ }
+
+ /**
+ * A package was updated.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindPackageUpdated(String packageName, ArrayList<ApplicationInfo> apps) {
+ removeDialog(DIALOG_CREATE_SHORTCUT);
+ mWorkspace.updateShortcutsForPackage(packageName);
+ mAllAppsGrid.updateApps(packageName, apps);
+ }
+
+ /**
+ * A package was uninstalled.
+ *
+ * Implementation of the method from LauncherModel.Callbacks.
+ */
+ public void bindPackageRemoved(String packageName, ArrayList<ApplicationInfo> apps) {
+ removeDialog(DIALOG_CREATE_SHORTCUT);
+ mWorkspace.removeShortcutsForPackage(packageName);
+ mAllAppsGrid.removeApps(apps);
+ }
+
+ /**
+ * Prints out out state for debugging.
+ */
+ public void dumpState() {
+ Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this);
+ Log.d(TAG, "mSavedState=" + mSavedState);
+ Log.d(TAG, "mIsNewIntent=" + mIsNewIntent);
+ Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading);
+ Log.d(TAG, "mRestoring=" + mRestoring);
+ Log.d(TAG, "mWaitingForResult=" + mWaitingForResult);
+ Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState);
+ Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size());
+ Log.d(TAG, "mFolders.size=" + mFolders.size());
+ mModel.dumpState();
+ mAllAppsGrid.dumpState();
+ Log.d(TAG, "END launcher2 dump state");
+ }
+}
diff --git a/src/com/android/launcher2/LauncherAppWidgetHost.java b/src/com/android/launcher2/LauncherAppWidgetHost.java
new file mode 100644
index 0000000..a5761ec
--- /dev/null
+++ b/src/com/android/launcher2/LauncherAppWidgetHost.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2009 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.android.launcher2;
+
+import android.appwidget.AppWidgetHost;
+import android.appwidget.AppWidgetHostView;
+import android.appwidget.AppWidgetProviderInfo;
+import android.content.Context;
+
+/**
+ * Specific {@link AppWidgetHost} that creates our {@link LauncherAppWidgetHostView}
+ * which correctly captures all long-press events. This ensures that users can
+ * always pick up and move widgets.
+ */
+public class LauncherAppWidgetHost extends AppWidgetHost {
+ public LauncherAppWidgetHost(Context context, int hostId) {
+ super(context, hostId);
+ }
+
+ @Override
+ protected AppWidgetHostView onCreateView(Context context, int appWidgetId,
+ AppWidgetProviderInfo appWidget) {
+ return new LauncherAppWidgetHostView(context);
+ }
+}
diff --git a/src/com/android/launcher2/LauncherAppWidgetHostView.java b/src/com/android/launcher2/LauncherAppWidgetHostView.java
new file mode 100644
index 0000000..d8fe499
--- /dev/null
+++ b/src/com/android/launcher2/LauncherAppWidgetHostView.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2009 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.android.launcher2;
+
+import android.appwidget.AppWidgetHostView;
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewConfiguration;
+
+/**
+ * {@inheritDoc}
+ */
+public class LauncherAppWidgetHostView extends AppWidgetHostView {
+ private boolean mHasPerformedLongPress;
+
+ private CheckForLongPress mPendingCheckForLongPress;
+
+ private LayoutInflater mInflater;
+
+ public LauncherAppWidgetHostView(Context context) {
+ super(context);
+ mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ }
+
+ @Override
+ protected View getErrorView() {
+ return mInflater.inflate(R.layout.appwidget_error, this, false);
+ }
+
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ // Consume any touch events for ourselves after longpress is triggered
+ if (mHasPerformedLongPress) {
+ mHasPerformedLongPress = false;
+ return true;
+ }
+
+ // Watch for longpress events at this level to make sure
+ // users can always pick up this widget
+ switch (ev.getAction()) {
+ case MotionEvent.ACTION_DOWN: {
+ postCheckForLongClick();
+ break;
+ }
+
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ mHasPerformedLongPress = false;
+ if (mPendingCheckForLongPress != null) {
+ removeCallbacks(mPendingCheckForLongPress);
+ }
+ break;
+ }
+
+ // Otherwise continue letting touch events fall through to children
+ return false;
+ }
+
+ class CheckForLongPress implements Runnable {
+ private int mOriginalWindowAttachCount;
+
+ public void run() {
+ if ((mParent != null) && hasWindowFocus()
+ && mOriginalWindowAttachCount == getWindowAttachCount()
+ && !mHasPerformedLongPress) {
+ if (performLongClick()) {
+ mHasPerformedLongPress = true;
+ }
+ }
+ }
+
+ public void rememberWindowAttachCount() {
+ mOriginalWindowAttachCount = getWindowAttachCount();
+ }
+ }
+
+ private void postCheckForLongClick() {
+ mHasPerformedLongPress = false;
+
+ if (mPendingCheckForLongPress == null) {
+ mPendingCheckForLongPress = new CheckForLongPress();
+ }
+ mPendingCheckForLongPress.rememberWindowAttachCount();
+ postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout());
+ }
+
+ @Override
+ public void cancelLongPress() {
+ super.cancelLongPress();
+
+ mHasPerformedLongPress = false;
+ if (mPendingCheckForLongPress != null) {
+ removeCallbacks(mPendingCheckForLongPress);
+ }
+ }
+}
diff --git a/src/com/android/launcher2/LauncherAppWidgetInfo.java b/src/com/android/launcher2/LauncherAppWidgetInfo.java
new file mode 100644
index 0000000..25db72b
--- /dev/null
+++ b/src/com/android/launcher2/LauncherAppWidgetInfo.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009 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.android.launcher2;
+
+import android.appwidget.AppWidgetHostView;
+import android.content.ContentValues;
+
+/**
+ * Represents a widget, which just contains an identifier.
+ */
+class LauncherAppWidgetInfo extends ItemInfo {
+
+ /**
+ * Identifier for this widget when talking with {@link AppWidgetManager} for updates.
+ */
+ int appWidgetId;
+
+ /**
+ * View that holds this widget after it's been created. This view isn't created
+ * until Launcher knows it's needed.
+ */
+ AppWidgetHostView hostView = null;
+
+ LauncherAppWidgetInfo(int appWidgetId) {
+ itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
+ this.appWidgetId = appWidgetId;
+ }
+
+ @Override
+ void onAddToDatabase(ContentValues values) {
+ super.onAddToDatabase(values);
+ values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
+ }
+
+ @Override
+ public String toString() {
+ return Integer.toString(appWidgetId);
+ }
+
+
+ @Override
+ void unbind() {
+ super.unbind();
+ hostView = null;
+ }
+}
diff --git a/src/com/android/launcher2/LauncherApplication.java b/src/com/android/launcher2/LauncherApplication.java
new file mode 100644
index 0000000..9b63524
--- /dev/null
+++ b/src/com/android/launcher2/LauncherApplication.java
@@ -0,0 +1,83 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.app.Application;
+import android.content.ContentResolver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.database.ContentObserver;
+import android.os.Handler;
+import dalvik.system.VMRuntime;
+
+public class LauncherApplication extends Application {
+ public final LauncherModel mModel;
+
+ public LauncherApplication() {
+ mModel = new LauncherModel(this);
+ }
+
+ @Override
+ public void onCreate() {
+ VMRuntime.getRuntime().setMinimumHeapSize(4 * 1024 * 1024);
+
+ super.onCreate();
+
+ // Register intent receivers
+ IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
+ filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
+ filter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+ filter.addDataScheme("package");
+ registerReceiver(mModel, filter);
+
+ // Register for changes to the favorites
+ ContentResolver resolver = getContentResolver();
+ resolver.registerContentObserver(LauncherSettings.Favorites.CONTENT_URI, true,
+ mFavoritesObserver);
+ }
+
+ /**
+ * There's no guarantee that this function is ever called.
+ */
+ @Override
+ public void onTerminate() {
+ super.onTerminate();
+
+ unregisterReceiver(mModel);
+
+ ContentResolver resolver = getContentResolver();
+ resolver.unregisterContentObserver(mFavoritesObserver);
+ }
+
+ /**
+ * Receives notifications whenever the user favorites have changed.
+ */
+ private final ContentObserver mFavoritesObserver = new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ // TODO: lockAllApps();
+ mModel.setWorkspaceDirty();
+ mModel.startLoader(LauncherApplication.this, false);
+ }
+ };
+
+ LauncherModel setLauncher(Launcher launcher) {
+ mModel.initialize(launcher);
+ return mModel;
+ }
+}
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java
new file mode 100644
index 0000000..97fa554
--- /dev/null
+++ b/src/com/android/launcher2/LauncherModel.java
@@ -0,0 +1,1239 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.Intent;
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.net.Uri;
+import android.util.Log;
+import android.os.Process;
+import android.os.SystemClock;
+
+import java.lang.ref.WeakReference;
+import java.net.URISyntaxException;
+import java.text.Collator;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * Maintains in-memory state of the Launcher. It is expected that there should be only one
+ * LauncherModel object held in a static. Also provide APIs for updating the database state
+ * for the Launcher.
+ */
+public class LauncherModel extends BroadcastReceiver {
+ static final boolean DEBUG_LOADERS = false;
+ static final String TAG = "Launcher.Model";
+
+ private final LauncherApplication mApp;
+ private final Object mLock = new Object();
+ private DeferredHandler mHandler = new DeferredHandler();
+ private Loader mLoader = new Loader();
+
+ private boolean mBeforeFirstLoad = true;
+ private WeakReference<Callbacks> mCallbacks;
+
+ private AllAppsList mAllAppsList = new AllAppsList();
+
+ public interface Callbacks {
+ public int getCurrentWorkspaceScreen();
+ public void startBinding();
+ public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end);
+ public void bindFolders(HashMap<Long,FolderInfo> folders);
+ public void finishBindingItems();
+ public void bindAppWidget(LauncherAppWidgetInfo info);
+ public void bindAllApplications(ArrayList<ApplicationInfo> apps);
+ public void bindPackageAdded(ArrayList<ApplicationInfo> apps);
+ public void bindPackageUpdated(String packageName, ArrayList<ApplicationInfo> apps);
+ public void bindPackageRemoved(String packageName, ArrayList<ApplicationInfo> apps);
+ }
+
+ LauncherModel(LauncherApplication app) {
+ mApp = app;
+ }
+
+ /**
+ * Adds an item to the DB if it was not created previously, or move it to a new
+ * <container, screen, cellX, cellY>
+ */
+ static void addOrMoveItemInDatabase(Context context, ItemInfo item, long container,
+ int screen, int cellX, int cellY) {
+ if (item.container == ItemInfo.NO_ID) {
+ // From all apps
+ addItemToDatabase(context, item, container, screen, cellX, cellY, false);
+ } else {
+ // From somewhere else
+ moveItemInDatabase(context, item, container, screen, cellX, cellY);
+ }
+ }
+
+ /**
+ * Move an item in the DB to a new <container, screen, cellX, cellY>
+ */
+ static void moveItemInDatabase(Context context, ItemInfo item, long container, int screen,
+ int cellX, int cellY) {
+ item.container = container;
+ item.screen = screen;
+ item.cellX = cellX;
+ item.cellY = cellY;
+
+ final ContentValues values = new ContentValues();
+ final ContentResolver cr = context.getContentResolver();
+
+ values.put(LauncherSettings.Favorites.CONTAINER, item.container);
+ values.put(LauncherSettings.Favorites.CELLX, item.cellX);
+ values.put(LauncherSettings.Favorites.CELLY, item.cellY);
+ values.put(LauncherSettings.Favorites.SCREEN, item.screen);
+
+ cr.update(LauncherSettings.Favorites.getContentUri(item.id, false), values, null, null);
+ }
+
+ /**
+ * Returns true if the shortcuts already exists in the database.
+ * we identify a shortcut by its title and intent.
+ */
+ static boolean shortcutExists(Context context, String title, Intent intent) {
+ final ContentResolver cr = context.getContentResolver();
+ Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
+ new String[] { "title", "intent" }, "title=? and intent=?",
+ new String[] { title, intent.toUri(0) }, null);
+ boolean result = false;
+ try {
+ result = c.moveToFirst();
+ } finally {
+ c.close();
+ }
+ return result;
+ }
+
+ /**
+ * Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList.
+ */
+ FolderInfo getFolderById(Context context, HashMap<Long,FolderInfo> folderList, long id) {
+ final ContentResolver cr = context.getContentResolver();
+ Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null,
+ "_id=? and (itemType=? or itemType=?)",
+ new String[] { String.valueOf(id),
+ String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER),
+ String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER) }, null);
+
+ try {
+ if (c.moveToFirst()) {
+ final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
+ final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
+ final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
+ final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
+ final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
+ final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
+
+ FolderInfo folderInfo = null;
+ switch (c.getInt(itemTypeIndex)) {
+ case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
+ folderInfo = findOrMakeUserFolder(folderList, id);
+ break;
+ case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
+ folderInfo = findOrMakeLiveFolder(folderList, id);
+ break;
+ }
+
+ folderInfo.title = c.getString(titleIndex);
+ folderInfo.id = id;
+ folderInfo.container = c.getInt(containerIndex);
+ folderInfo.screen = c.getInt(screenIndex);
+ folderInfo.cellX = c.getInt(cellXIndex);
+ folderInfo.cellY = c.getInt(cellYIndex);
+
+ return folderInfo;
+ }
+ } finally {
+ c.close();
+ }
+
+ return null;
+ }
+
+ /**
+ * Add an item to the database in a specified container. Sets the container, screen, cellX and
+ * cellY fields of the item. Also assigns an ID to the item.
+ */
+ static void addItemToDatabase(Context context, ItemInfo item, long container,
+ int screen, int cellX, int cellY, boolean notify) {
+ item.container = container;
+ item.screen = screen;
+ item.cellX = cellX;
+ item.cellY = cellY;
+
+ final ContentValues values = new ContentValues();
+ final ContentResolver cr = context.getContentResolver();
+
+ item.onAddToDatabase(values);
+
+ Uri result = cr.insert(notify ? LauncherSettings.Favorites.CONTENT_URI :
+ LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION, values);
+
+ if (result != null) {
+ item.id = Integer.parseInt(result.getPathSegments().get(1));
+ }
+ }
+
+ /**
+ * Update an item to the database in a specified container.
+ */
+ static void updateItemInDatabase(Context context, ItemInfo item) {
+ final ContentValues values = new ContentValues();
+ final ContentResolver cr = context.getContentResolver();
+
+ item.onAddToDatabase(values);
+
+ cr.update(LauncherSettings.Favorites.getContentUri(item.id, false), values, null, null);
+ }
+
+ /**
+ * Removes the specified item from the database
+ * @param context
+ * @param item
+ */
+ static void deleteItemFromDatabase(Context context, ItemInfo item) {
+ final ContentResolver cr = context.getContentResolver();
+
+ cr.delete(LauncherSettings.Favorites.getContentUri(item.id, false), null, null);
+ }
+
+ /**
+ * Remove the contents of the specified folder from the database
+ */
+ static void deleteUserFolderContentsFromDatabase(Context context, UserFolderInfo info) {
+ final ContentResolver cr = context.getContentResolver();
+
+ cr.delete(LauncherSettings.Favorites.getContentUri(info.id, false), null, null);
+ cr.delete(LauncherSettings.Favorites.CONTENT_URI,
+ LauncherSettings.Favorites.CONTAINER + "=" + info.id, null);
+ }
+
+ /**
+ * Set this as the current Launcher activity object for the loader.
+ */
+ public void initialize(Callbacks callbacks) {
+ synchronized (mLock) {
+ mCallbacks = new WeakReference<Callbacks>(callbacks);
+ }
+ }
+
+ public void startLoader(Context context, boolean isLaunching) {
+ mLoader.startLoader(context, isLaunching);
+ }
+
+ public void stopLoader() {
+ mLoader.stopLoader();
+ }
+
+ /**
+ * We pick up most of the changes to all apps.
+ */
+ public void setAllAppsDirty() {
+ mLoader.setAllAppsDirty();
+ }
+
+ public void setWorkspaceDirty() {
+ mLoader.setWorkspaceDirty();
+ }
+
+ /**
+ * Call from the handler for ACTION_PACKAGE_ADDED, ACTION_PACKAGE_REMOVED and
+ * ACTION_PACKAGE_CHANGED.
+ */
+ public void onReceive(Context context, Intent intent) {
+ // Use the app as the context.
+ context = mApp;
+
+ final String packageName = intent.getData().getSchemeSpecificPart();
+
+ ArrayList<ApplicationInfo> added = null;
+ ArrayList<ApplicationInfo> removed = null;
+ ArrayList<ApplicationInfo> modified = null;
+
+ synchronized (mLock) {
+ if (mBeforeFirstLoad) {
+ // If we haven't even loaded yet, don't bother, since we'll just pick
+ // up the changes.
+ return;
+ }
+
+ final String action = intent.getAction();
+ final boolean replacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
+
+ if (packageName == null || packageName.length() == 0) {
+ // they sent us a bad intent
+ return;
+ }
+
+ if (Intent.ACTION_PACKAGE_CHANGED.equals(action)) {
+ mAllAppsList.updatePackage(context, packageName);
+ } else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {
+ if (!replacing) {
+ mAllAppsList.removePackage(packageName);
+ }
+ // else, we are replacing the package, so a PACKAGE_ADDED will be sent
+ // later, we will update the package at this time
+ } else {
+ if (!replacing) {
+ mAllAppsList.addPackage(context, packageName);
+ } else {
+ mAllAppsList.updatePackage(context, packageName);
+ }
+ }
+
+ if (mAllAppsList.added.size() > 0) {
+ added = mAllAppsList.added;
+ mAllAppsList.added = new ArrayList<ApplicationInfo>();
+ }
+ if (mAllAppsList.removed.size() > 0) {
+ removed = mAllAppsList.removed;
+ mAllAppsList.removed = new ArrayList<ApplicationInfo>();
+ for (ApplicationInfo info: removed) {
+ AppInfoCache.remove(info.intent.getComponent());
+ }
+ }
+ if (mAllAppsList.modified.size() > 0) {
+ modified = mAllAppsList.modified;
+ mAllAppsList.modified = new ArrayList<ApplicationInfo>();
+ }
+
+ final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null;
+ if (callbacks == null) {
+ Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading.");
+ return;
+ }
+
+ if (added != null) {
+ final ArrayList<ApplicationInfo> addedFinal = added;
+ mHandler.post(new Runnable() {
+ public void run() {
+ callbacks.bindPackageAdded(addedFinal);
+ }
+ });
+ }
+ if (modified != null) {
+ final ArrayList<ApplicationInfo> modifiedFinal = modified;
+ mHandler.post(new Runnable() {
+ public void run() {
+ callbacks.bindPackageUpdated(packageName, modifiedFinal);
+ }
+ });
+ }
+ if (removed != null) {
+ final ArrayList<ApplicationInfo> removedFinal = removed;
+ mHandler.post(new Runnable() {
+ public void run() {
+ callbacks.bindPackageRemoved(packageName, removedFinal);
+ }
+ });
+ }
+ }
+ }
+
+ public class Loader {
+ private static final int ITEMS_CHUNK = 6;
+
+ private LoaderThread mLoaderThread;
+
+ private int mLastWorkspaceSeq = 0;
+ private int mWorkspaceSeq = 1;
+
+ private int mLastAllAppsSeq = 0;
+ private int mAllAppsSeq = 1;
+
+ final ArrayList<ItemInfo> mItems = new ArrayList<ItemInfo>();
+ final ArrayList<LauncherAppWidgetInfo> mAppWidgets = new ArrayList<LauncherAppWidgetInfo>();
+ final HashMap<Long, FolderInfo> mFolders = new HashMap<Long, FolderInfo>();
+
+ /**
+ * Call this from the ui thread so the handler is initialized on the correct thread.
+ */
+ public Loader() {
+ }
+
+ public void startLoader(Context context, boolean isLaunching) {
+ synchronized (mLock) {
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "startLoader isLaunching=" + isLaunching);
+ }
+ // Don't bother to start the thread if we know it's not going to do anything
+ if (mCallbacks.get() != null) {
+ LoaderThread oldThread = mLoaderThread;
+ if (oldThread != null) {
+ if (oldThread.isLaunching()) {
+ // don't downgrade isLaunching if we're already running
+ isLaunching = true;
+ }
+ oldThread.stopLocked();
+ }
+ mLoaderThread = new LoaderThread(context, oldThread, isLaunching);
+ mLoaderThread.start();
+ }
+ }
+ }
+
+ public void stopLoader() {
+ synchronized (mLock) {
+ if (mLoaderThread != null) {
+ mLoaderThread.stopLocked();
+ }
+ }
+ }
+
+ public void setWorkspaceDirty() {
+ synchronized (mLock) {
+ mWorkspaceSeq++;
+ }
+ }
+
+ public void setAllAppsDirty() {
+ synchronized (mLock) {
+ mAllAppsSeq++;
+ }
+ }
+
+ /**
+ * Runnable for the thread that loads the contents of the launcher:
+ * - workspace icons
+ * - widgets
+ * - all apps icons
+ */
+ private class LoaderThread extends Thread {
+ private Context mContext;
+ private Thread mWaitThread;
+ private boolean mIsLaunching;
+ private boolean mStopped;
+ private boolean mWorkspaceDoneBinding;
+
+ LoaderThread(Context context, Thread waitThread, boolean isLaunching) {
+ mContext = context;
+ mWaitThread = waitThread;
+ mIsLaunching = isLaunching;
+ }
+
+ boolean isLaunching() {
+ return mIsLaunching;
+ }
+
+ /**
+ * If another LoaderThread was supplied, we need to wait for that to finish before
+ * we start our processing. This keeps the ordering of the setting and clearing
+ * of the dirty flags correct by making sure we don't start processing stuff until
+ * they've had a chance to re-set them. We do this waiting the worker thread, not
+ * the ui thread to avoid ANRs.
+ */
+ private void waitForOtherThread() {
+ if (mWaitThread != null) {
+ boolean done = false;
+ while (!done) {
+ try {
+ mWaitThread.join();
+ done = true;
+ } catch (InterruptedException ex) {
+ // Ignore
+ }
+ }
+ mWaitThread = null;
+ }
+ }
+
+ public void run() {
+ waitForOtherThread();
+
+ // Elevate priority when Home launches for the first time to avoid
+ // starving at boot time. Staring at a blank home is not cool.
+ synchronized (mLock) {
+ android.os.Process.setThreadPriority(mIsLaunching
+ ? Process.THREAD_PRIORITY_DEFAULT : Process.THREAD_PRIORITY_BACKGROUND);
+ }
+
+ // Load the workspace only if it's dirty.
+ int workspaceSeq;
+ boolean workspaceDirty;
+ synchronized (mLock) {
+ workspaceSeq = mWorkspaceSeq;
+ workspaceDirty = mWorkspaceSeq != mLastWorkspaceSeq;
+ }
+ if (workspaceDirty) {
+ loadWorkspace();
+ }
+ synchronized (mLock) {
+ // If we're not stopped, and nobody has incremented mWorkspaceSeq.
+ if (mStopped) {
+ return;
+ }
+ if (workspaceSeq == mWorkspaceSeq) {
+ mLastWorkspaceSeq = mWorkspaceSeq;
+ }
+ }
+
+ // Bind the workspace
+ bindWorkspace();
+
+ // Wait until the either we're stopped or the other threads are done.
+ // This way we don't start loading all apps until the workspace has settled
+ // down.
+ synchronized (LoaderThread.this) {
+ mHandler.postIdle(new Runnable() {
+ public void run() {
+ synchronized (LoaderThread.this) {
+ mWorkspaceDoneBinding = true;
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "done with workspace");
+ }
+ LoaderThread.this.notify();
+ }
+ }
+ });
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "waiting to be done with workspace");
+ }
+ while (!mStopped && !mWorkspaceDoneBinding) {
+ try {
+ this.wait();
+ } catch (InterruptedException ex) {
+ // Ignore
+ }
+ }
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "done waiting to be done with workspace");
+ }
+ }
+
+ // Load all apps if they're dirty
+ int allAppsSeq;
+ boolean allAppsDirty;
+ synchronized (mLock) {
+ allAppsSeq = mAllAppsSeq;
+ allAppsDirty = mAllAppsSeq != mLastAllAppsSeq;
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "mAllAppsSeq=" + mAllAppsSeq
+ + " mLastAllAppsSeq=" + mLastAllAppsSeq + " allAppsDirty");
+ }
+ }
+ if (allAppsDirty) {
+ loadAllApps();
+ }
+ synchronized (mLock) {
+ // If we're not stopped, and nobody has incremented mAllAppsSeq.
+ if (mStopped) {
+ return;
+ }
+ if (allAppsSeq == mAllAppsSeq) {
+ mLastAllAppsSeq = mAllAppsSeq;
+ }
+ }
+
+ // Bind all apps
+ if (allAppsDirty) {
+ bindAllApps();
+ }
+
+ // Clear out this reference, otherwise we end up holding it until all of the
+ // callback runnables are done.
+ mContext = null;
+
+ synchronized (mLock) {
+ // Setting the reference is atomic, but we can't do it inside the other critical
+ // sections.
+ mLoaderThread = null;
+ }
+ }
+
+ public void stopLocked() {
+ synchronized (LoaderThread.this) {
+ mStopped = true;
+ this.notify();
+ }
+ }
+
+ /**
+ * Gets the callbacks object. If we've been stopped, or if the launcher object
+ * has somehow been garbage collected, return null instead.
+ */
+ Callbacks tryGetCallbacks() {
+ synchronized (mLock) {
+ if (mStopped) {
+ return null;
+ }
+
+ final Callbacks callbacks = mCallbacks.get();
+ if (callbacks == null) {
+ Log.w(TAG, "no mCallbacks");
+ return null;
+ }
+
+ return callbacks;
+ }
+ }
+
+ private void loadWorkspace() {
+ long t = SystemClock.uptimeMillis();
+
+ final Context context = mContext;
+ final ContentResolver contentResolver = context.getContentResolver();
+ final PackageManager manager = context.getPackageManager();
+
+ /* TODO
+ if (mLocaleChanged) {
+ updateShortcutLabels(contentResolver, manager);
+ }
+ */
+
+ mItems.clear();
+ mAppWidgets.clear();
+ mFolders.clear();
+
+ final Cursor c = contentResolver.query(
+ LauncherSettings.Favorites.CONTENT_URI, null, null, null, null);
+
+ try {
+ final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
+ final int intentIndex = c.getColumnIndexOrThrow
+ (LauncherSettings.Favorites.INTENT);
+ final int titleIndex = c.getColumnIndexOrThrow
+ (LauncherSettings.Favorites.TITLE);
+ final int iconTypeIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.ICON_TYPE);
+ final int iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
+ final int iconPackageIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.ICON_PACKAGE);
+ final int iconResourceIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.ICON_RESOURCE);
+ final int containerIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.CONTAINER);
+ final int itemTypeIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.ITEM_TYPE);
+ final int appWidgetIdIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.APPWIDGET_ID);
+ final int screenIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.SCREEN);
+ final int cellXIndex = c.getColumnIndexOrThrow
+ (LauncherSettings.Favorites.CELLX);
+ final int cellYIndex = c.getColumnIndexOrThrow
+ (LauncherSettings.Favorites.CELLY);
+ final int spanXIndex = c.getColumnIndexOrThrow
+ (LauncherSettings.Favorites.SPANX);
+ final int spanYIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.SPANY);
+ final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI);
+ final int displayModeIndex = c.getColumnIndexOrThrow(
+ LauncherSettings.Favorites.DISPLAY_MODE);
+
+ ApplicationInfo info;
+ String intentDescription;
+ Widget widgetInfo;
+ LauncherAppWidgetInfo appWidgetInfo;
+ int container;
+ long id;
+ Intent intent;
+
+ while (!mStopped && c.moveToNext()) {
+ try {
+ int itemType = c.getInt(itemTypeIndex);
+
+ switch (itemType) {
+ case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
+ case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
+ intentDescription = c.getString(intentIndex);
+ try {
+ intent = Intent.parseUri(intentDescription, 0);
+ } catch (URISyntaxException e) {
+ continue;
+ }
+
+ if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
+ info = getApplicationInfo(manager, intent, context);
+ } else {
+ info = getApplicationInfoShortcut(c, context, iconTypeIndex,
+ iconPackageIndex, iconResourceIndex, iconIndex);
+ }
+
+ if (info == null) {
+ info = new ApplicationInfo();
+ info.icon = manager.getDefaultActivityIcon();
+ }
+
+ if (info != null) {
+ if (itemType
+ != LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
+ info.title = c.getString(titleIndex);
+ }
+ info.intent = intent;
+
+ info.id = c.getLong(idIndex);
+ container = c.getInt(containerIndex);
+ info.container = container;
+ info.screen = c.getInt(screenIndex);
+ info.cellX = c.getInt(cellXIndex);
+ info.cellY = c.getInt(cellYIndex);
+
+ switch (container) {
+ case LauncherSettings.Favorites.CONTAINER_DESKTOP:
+ mItems.add(info);
+ break;
+ default:
+ // Item is in a user folder
+ UserFolderInfo folderInfo =
+ findOrMakeUserFolder(mFolders, container);
+ folderInfo.add(info);
+ break;
+ }
+ }
+ break;
+
+ case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
+ id = c.getLong(idIndex);
+ UserFolderInfo folderInfo = findOrMakeUserFolder(mFolders, id);
+
+ folderInfo.title = c.getString(titleIndex);
+
+ folderInfo.id = id;
+ container = c.getInt(containerIndex);
+ folderInfo.container = container;
+ folderInfo.screen = c.getInt(screenIndex);
+ folderInfo.cellX = c.getInt(cellXIndex);
+ folderInfo.cellY = c.getInt(cellYIndex);
+
+ switch (container) {
+ case LauncherSettings.Favorites.CONTAINER_DESKTOP:
+ mItems.add(folderInfo);
+ break;
+ }
+
+ mFolders.put(folderInfo.id, folderInfo);
+ break;
+
+ case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER:
+
+ id = c.getLong(idIndex);
+ LiveFolderInfo liveFolderInfo = findOrMakeLiveFolder(mFolders, id);
+
+ intentDescription = c.getString(intentIndex);
+ intent = null;
+ if (intentDescription != null) {
+ try {
+ intent = Intent.parseUri(intentDescription, 0);
+ } catch (URISyntaxException e) {
+ // Ignore, a live folder might not have a base intent
+ }
+ }
+
+ liveFolderInfo.title = c.getString(titleIndex);
+ liveFolderInfo.id = id;
+ container = c.getInt(containerIndex);
+ liveFolderInfo.container = container;
+ liveFolderInfo.screen = c.getInt(screenIndex);
+ liveFolderInfo.cellX = c.getInt(cellXIndex);
+ liveFolderInfo.cellY = c.getInt(cellYIndex);
+ liveFolderInfo.uri = Uri.parse(c.getString(uriIndex));
+ liveFolderInfo.baseIntent = intent;
+ liveFolderInfo.displayMode = c.getInt(displayModeIndex);
+
+ loadLiveFolderIcon(context, c, iconTypeIndex, iconPackageIndex,
+ iconResourceIndex, liveFolderInfo);
+
+ switch (container) {
+ case LauncherSettings.Favorites.CONTAINER_DESKTOP:
+ mItems.add(liveFolderInfo);
+ break;
+ }
+ mFolders.put(liveFolderInfo.id, liveFolderInfo);
+ break;
+
+ case LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH:
+ widgetInfo = Widget.makeSearch();
+
+ container = c.getInt(containerIndex);
+ if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
+ Log.e(TAG, "Widget found where container "
+ + "!= CONTAINER_DESKTOP ignoring!");
+ continue;
+ }
+
+ widgetInfo.id = c.getLong(idIndex);
+ widgetInfo.screen = c.getInt(screenIndex);
+ widgetInfo.container = container;
+ widgetInfo.cellX = c.getInt(cellXIndex);
+ widgetInfo.cellY = c.getInt(cellYIndex);
+
+ mItems.add(widgetInfo);
+ break;
+
+ case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET:
+ // Read all Launcher-specific widget details
+ int appWidgetId = c.getInt(appWidgetIdIndex);
+ appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId);
+ appWidgetInfo.id = c.getLong(idIndex);
+ appWidgetInfo.screen = c.getInt(screenIndex);
+ appWidgetInfo.cellX = c.getInt(cellXIndex);
+ appWidgetInfo.cellY = c.getInt(cellYIndex);
+ appWidgetInfo.spanX = c.getInt(spanXIndex);
+ appWidgetInfo.spanY = c.getInt(spanYIndex);
+
+ container = c.getInt(containerIndex);
+ if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
+ Log.e(TAG, "Widget found where container "
+ + "!= CONTAINER_DESKTOP -- ignoring!");
+ continue;
+ }
+ appWidgetInfo.container = c.getInt(containerIndex);
+
+ mAppWidgets.add(appWidgetInfo);
+ break;
+ }
+ } catch (Exception e) {
+ Log.w(TAG, "Desktop items loading interrupted:", e);
+ }
+ }
+ } finally {
+ c.close();
+ }
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms");
+ }
+ }
+
+ /**
+ * Read everything out of our database.
+ */
+ private void bindWorkspace() {
+ final long t = SystemClock.uptimeMillis();
+
+ // Don't use these two variables in any of the callback runnables.
+ // Otherwise we hold a reference to them.
+ Callbacks callbacks = mCallbacks.get();
+ if (callbacks == null) {
+ // This launcher has exited and nobody bothered to tell us. Just bail.
+ Log.w(TAG, "LoaderThread running with no launcher");
+ return;
+ }
+
+ int N;
+ // Tell the workspace that we're about to start firing items at it
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks callbacks = tryGetCallbacks();
+ if (callbacks != null) {
+ callbacks.startBinding();
+ }
+ }
+ });
+ // Add the items to the workspace.
+ N = mItems.size();
+ for (int i=0; i<N; i+=ITEMS_CHUNK) {
+ final int start = i;
+ final int chunkSize = (i+ITEMS_CHUNK <= N) ? ITEMS_CHUNK : (N-i);
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks callbacks = tryGetCallbacks();
+ if (callbacks != null) {
+ callbacks.bindItems(mItems, start, start+chunkSize);
+ }
+ }
+ });
+ }
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks callbacks = tryGetCallbacks();
+ if (callbacks != null) {
+ callbacks.bindFolders(mFolders);
+ }
+ }
+ });
+ // Wait until the queue goes empty.
+ mHandler.postIdle(new Runnable() {
+ public void run() {
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "Going to start binding widgets soon.");
+ }
+ }
+ });
+ // Bind the widgets, one at a time.
+ // WARNING: this is calling into the workspace from the background thread,
+ // but since getCurrentScreen() just returns the int, we should be okay. This
+ // is just a hint for the order, and if it's wrong, we'll be okay.
+ // TODO: instead, we should have that push the current screen into here.
+ final int currentScreen = callbacks.getCurrentWorkspaceScreen();
+ N = mAppWidgets.size();
+ // once for the current screen
+ for (int i=0; i<N; i++) {
+ final LauncherAppWidgetInfo widget = mAppWidgets.get(i);
+ if (widget.screen == currentScreen) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks callbacks = tryGetCallbacks();
+ if (callbacks != null) {
+ callbacks.bindAppWidget(widget);
+ }
+ }
+ });
+ }
+ }
+ // once for the other screens
+ for (int i=0; i<N; i++) {
+ final LauncherAppWidgetInfo widget = mAppWidgets.get(i);
+ if (widget.screen != currentScreen) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks callbacks = tryGetCallbacks();
+ if (callbacks != null) {
+ callbacks.bindAppWidget(widget);
+ }
+ }
+ });
+ }
+ }
+ // Tell the workspace that we're done.
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks callbacks = tryGetCallbacks();
+ if (callbacks != null) {
+ callbacks.finishBindingItems();
+ }
+ }
+ });
+ // If we're profiling, this is the last thing in the queue.
+ mHandler.post(new Runnable() {
+ public void run() {
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "bound workspace in "
+ + (SystemClock.uptimeMillis()-t) + "ms");
+ }
+ if (Launcher.PROFILE_ROTATE) {
+ android.os.Debug.stopMethodTracing();
+ }
+ }
+ });
+ }
+
+ private void loadAllApps() {
+ final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
+ mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
+
+ final Callbacks callbacks = tryGetCallbacks();
+ if (callbacks == null) {
+ return;
+ }
+
+ final Context context = mContext;
+ final PackageManager packageManager = context.getPackageManager();
+
+ final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0);
+
+ synchronized (mLock) {
+ mBeforeFirstLoad = false;
+
+ mAllAppsList.clear();
+ if (apps != null) {
+ long t = SystemClock.uptimeMillis();
+
+ int N = apps.size();
+ Utilities.BubbleText bubble = new Utilities.BubbleText(context);
+ for (int i=0; i<N && !mStopped; i++) {
+ // This builds the icon bitmaps.
+ mAllAppsList.add(AppInfoCache.cache(apps.get(i), context, bubble));
+ }
+ Collections.sort(mAllAppsList.data, APP_NAME_COMPARATOR);
+ Collections.sort(mAllAppsList.added, APP_NAME_COMPARATOR);
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "cached app icons in "
+ + (SystemClock.uptimeMillis()-t) + "ms");
+ }
+ }
+ }
+ }
+
+ private void bindAllApps() {
+ synchronized (mLock) {
+ final ArrayList<ApplicationInfo> results
+ = (ArrayList<ApplicationInfo>)mAllAppsList.data.clone();
+ // We're adding this now, so clear out this so we don't re-send them.
+ mAllAppsList.added = new ArrayList<ApplicationInfo>();
+ mHandler.post(new Runnable() {
+ public void run() {
+ final long t = SystemClock.uptimeMillis();
+ final int count = results.size();
+
+ Callbacks callbacks = tryGetCallbacks();
+ if (callbacks != null) {
+ callbacks.bindAllApplications(results);
+ }
+
+ if (DEBUG_LOADERS) {
+ Log.d(TAG, "bound app " + count + " icons in "
+ + (SystemClock.uptimeMillis()-t) + "ms");
+ }
+ }
+ });
+ }
+ }
+
+ public void dumpState() {
+ Log.d(TAG, "mLoader.mLoaderThread.mContext=" + mContext);
+ Log.d(TAG, "mLoader.mLoaderThread.mWaitThread=" + mWaitThread);
+ Log.d(TAG, "mLoader.mLoaderThread.mIsLaunching=" + mIsLaunching);
+ Log.d(TAG, "mLoader.mLoaderThread.mStopped=" + mStopped);
+ Log.d(TAG, "mLoader.mLoaderThread.mWorkspaceDoneBinding=" + mWorkspaceDoneBinding);
+ }
+ }
+
+ public void dumpState() {
+ Log.d(TAG, "mLoader.mLastWorkspaceSeq=" + mLoader.mLastWorkspaceSeq);
+ Log.d(TAG, "mLoader.mWorkspaceSeq=" + mLoader.mWorkspaceSeq);
+ Log.d(TAG, "mLoader.mLastAllAppsSeq=" + mLoader.mLastAllAppsSeq);
+ Log.d(TAG, "mLoader.mAllAppsSeq=" + mLoader.mAllAppsSeq);
+ Log.d(TAG, "mLoader.mItems size=" + mLoader.mItems.size());
+ if (mLoaderThread != null) {
+ mLoaderThread.dumpState();
+ } else {
+ Log.d(TAG, "mLoader.mLoaderThread=null");
+ }
+ }
+ }
+
+ /**
+ * Make an ApplicationInfo object for an application.
+ */
+ private static ApplicationInfo getApplicationInfo(PackageManager manager, Intent intent,
+ Context context) {
+ final ResolveInfo resolveInfo = manager.resolveActivity(intent, 0);
+
+ if (resolveInfo == null) {
+ return null;
+ }
+
+ final ApplicationInfo info = new ApplicationInfo();
+ final ActivityInfo activityInfo = resolveInfo.activityInfo;
+ info.icon = Utilities.createIconThumbnail(activityInfo.loadIcon(manager), context);
+ if (info.title == null || info.title.length() == 0) {
+ info.title = activityInfo.loadLabel(manager);
+ }
+ if (info.title == null) {
+ info.title = "";
+ }
+ info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
+ return info;
+ }
+
+ /**
+ * Make an ApplicationInfo object for a sortcut
+ */
+ private static ApplicationInfo getApplicationInfoShortcut(Cursor c, Context context,
+ int iconTypeIndex, int iconPackageIndex, int iconResourceIndex, int iconIndex) {
+
+ final ApplicationInfo info = new ApplicationInfo();
+ info.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
+
+ int iconType = c.getInt(iconTypeIndex);
+ switch (iconType) {
+ case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
+ String packageName = c.getString(iconPackageIndex);
+ String resourceName = c.getString(iconResourceIndex);
+ PackageManager packageManager = context.getPackageManager();
+ try {
+ Resources resources = packageManager.getResourcesForApplication(packageName);
+ final int id = resources.getIdentifier(resourceName, null, null);
+ info.icon = Utilities.createIconThumbnail(resources.getDrawable(id), context);
+ } catch (Exception e) {
+ info.icon = packageManager.getDefaultActivityIcon();
+ }
+ info.iconResource = new Intent.ShortcutIconResource();
+ info.iconResource.packageName = packageName;
+ info.iconResource.resourceName = resourceName;
+ info.customIcon = false;
+ break;
+ case LauncherSettings.Favorites.ICON_TYPE_BITMAP:
+ byte[] data = c.getBlob(iconIndex);
+ try {
+ Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
+ info.icon = new FastBitmapDrawable(
+ Utilities.createBitmapThumbnail(bitmap, context));
+ } catch (Exception e) {
+ packageManager = context.getPackageManager();
+ info.icon = packageManager.getDefaultActivityIcon();
+ }
+ info.filtered = true;
+ info.customIcon = true;
+ break;
+ default:
+ info.icon = context.getPackageManager().getDefaultActivityIcon();
+ info.customIcon = false;
+ break;
+ }
+ return info;
+ }
+
+ private static void loadLiveFolderIcon(Context context, Cursor c, int iconTypeIndex,
+ int iconPackageIndex, int iconResourceIndex, LiveFolderInfo liveFolderInfo) {
+
+ int iconType = c.getInt(iconTypeIndex);
+ switch (iconType) {
+ case LauncherSettings.Favorites.ICON_TYPE_RESOURCE:
+ String packageName = c.getString(iconPackageIndex);
+ String resourceName = c.getString(iconResourceIndex);
+ PackageManager packageManager = context.getPackageManager();
+ try {
+ Resources resources = packageManager.getResourcesForApplication(packageName);
+ final int id = resources.getIdentifier(resourceName, null, null);
+ liveFolderInfo.icon = resources.getDrawable(id);
+ } catch (Exception e) {
+ liveFolderInfo.icon =
+ context.getResources().getDrawable(R.drawable.ic_launcher_folder);
+ }
+ liveFolderInfo.iconResource = new Intent.ShortcutIconResource();
+ liveFolderInfo.iconResource.packageName = packageName;
+ liveFolderInfo.iconResource.resourceName = resourceName;
+ break;
+ default:
+ liveFolderInfo.icon =
+ context.getResources().getDrawable(R.drawable.ic_launcher_folder);
+ }
+ }
+
+ /**
+ * Return an existing UserFolderInfo object if we have encountered this ID previously,
+ * or make a new one.
+ */
+ private static UserFolderInfo findOrMakeUserFolder(HashMap<Long, FolderInfo> folders, long id) {
+ // See if a placeholder was created for us already
+ FolderInfo folderInfo = folders.get(id);
+ if (folderInfo == null || !(folderInfo instanceof UserFolderInfo)) {
+ // No placeholder -- create a new instance
+ folderInfo = new UserFolderInfo();
+ folders.put(id, folderInfo);
+ }
+ return (UserFolderInfo) folderInfo;
+ }
+
+ /**
+ * Return an existing UserFolderInfo object if we have encountered this ID previously, or make a
+ * new one.
+ */
+ private static LiveFolderInfo findOrMakeLiveFolder(HashMap<Long, FolderInfo> folders, long id) {
+ // See if a placeholder was created for us already
+ FolderInfo folderInfo = folders.get(id);
+ if (folderInfo == null || !(folderInfo instanceof LiveFolderInfo)) {
+ // No placeholder -- create a new instance
+ folderInfo = new LiveFolderInfo();
+ folders.put(id, folderInfo);
+ }
+ return (LiveFolderInfo) folderInfo;
+ }
+
+ private static void updateShortcutLabels(ContentResolver resolver, PackageManager manager) {
+ final Cursor c = resolver.query(LauncherSettings.Favorites.CONTENT_URI,
+ new String[] { LauncherSettings.Favorites._ID, LauncherSettings.Favorites.TITLE,
+ LauncherSettings.Favorites.INTENT, LauncherSettings.Favorites.ITEM_TYPE },
+ null, null, null);
+
+ final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
+ final int intentIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
+ final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
+ final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
+
+ // boolean changed = false;
+
+ try {
+ while (c.moveToNext()) {
+ try {
+ if (c.getInt(itemTypeIndex) !=
+ LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
+ continue;
+ }
+
+ final String intentUri = c.getString(intentIndex);
+ if (intentUri != null) {
+ final Intent shortcut = Intent.parseUri(intentUri, 0);
+ if (Intent.ACTION_MAIN.equals(shortcut.getAction())) {
+ final ComponentName name = shortcut.getComponent();
+ if (name != null) {
+ final ActivityInfo activityInfo = manager.getActivityInfo(name, 0);
+ final String title = c.getString(titleIndex);
+ String label = getLabel(manager, activityInfo);
+
+ if (title == null || !title.equals(label)) {
+ final ContentValues values = new ContentValues();
+ values.put(LauncherSettings.Favorites.TITLE, label);
+
+ resolver.update(
+ LauncherSettings.Favorites.CONTENT_URI_NO_NOTIFICATION,
+ values, "_id=?",
+ new String[] { String.valueOf(c.getLong(idIndex)) });
+
+ // changed = true;
+ }
+ }
+ }
+ }
+ } catch (URISyntaxException e) {
+ // Ignore
+ } catch (PackageManager.NameNotFoundException e) {
+ // Ignore
+ }
+ }
+ } finally {
+ c.close();
+ }
+
+ // if (changed) resolver.notifyChange(Settings.Favorites.CONTENT_URI, null);
+ }
+
+ private static String getLabel(PackageManager manager, ActivityInfo activityInfo) {
+ String label = activityInfo.loadLabel(manager).toString();
+ if (label == null) {
+ label = manager.getApplicationLabel(activityInfo.applicationInfo).toString();
+ if (label == null) {
+ label = activityInfo.name;
+ }
+ }
+ return label;
+ }
+
+ private static final Collator sCollator = Collator.getInstance();
+ public static final Comparator<ApplicationInfo> APP_NAME_COMPARATOR
+ = new Comparator<ApplicationInfo>() {
+ public final int compare(ApplicationInfo a, ApplicationInfo b) {
+ return sCollator.compare(a.title.toString(), b.title.toString());
+ }
+ };
+
+ public void dumpState() {
+ Log.d(TAG, "mBeforeFirstLoad=" + mBeforeFirstLoad);
+ Log.d(TAG, "mCallbacks=" + mCallbacks);
+ ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.data", mAllAppsList.data);
+ ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.added", mAllAppsList.added);
+ ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.removed", mAllAppsList.removed);
+ ApplicationInfo.dumpApplicationInfoList(TAG, "mAllAppsList.modified", mAllAppsList.modified);
+ mLoader.dumpState();
+ }
+}
diff --git a/src/com/android/launcher2/LauncherProvider.java b/src/com/android/launcher2/LauncherProvider.java
new file mode 100644
index 0000000..c3ceefd
--- /dev/null
+++ b/src/com/android/launcher2/LauncherProvider.java
@@ -0,0 +1,808 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.appwidget.AppWidgetHost;
+import android.appwidget.AppWidgetManager;
+import android.content.ContentProvider;
+import android.content.Context;
+import android.content.ContentValues;
+import android.content.Intent;
+import android.content.ComponentName;
+import android.content.ContentUris;
+import android.content.ContentResolver;
+import android.content.res.Resources;
+import android.content.res.XmlResourceParser;
+import android.content.res.TypedArray;
+import android.content.pm.PackageManager;
+import android.content.pm.ActivityInfo;
+import android.database.sqlite.SQLiteOpenHelper;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteQueryBuilder;
+import android.database.Cursor;
+import android.database.SQLException;
+import android.util.Log;
+import android.util.Xml;
+import android.util.AttributeSet;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.os.*;
+import android.provider.Settings;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlPullParser;
+import com.android.internal.util.XmlUtils;
+import com.android.launcher2.LauncherSettings.Favorites;
+
+public class LauncherProvider extends ContentProvider {
+ private static final String TAG = "Launcher.LauncherProvider";
+ private static final boolean LOGD = false;
+
+ private static final String DATABASE_NAME = "launcher.db";
+
+ private static final int DATABASE_VERSION = 6;
+
+ static final String AUTHORITY = "com.android.launcher2.settings";
+
+ static final String EXTRA_BIND_SOURCES = "com.android.launcher2.settings.bindsources";
+ static final String EXTRA_BIND_TARGETS = "com.android.launcher2.settings.bindtargets";
+
+ static final String TABLE_FAVORITES = "favorites";
+ static final String PARAMETER_NOTIFY = "notify";
+
+ /**
+ * {@link Uri} triggered at any registered {@link android.database.ContentObserver} when
+ * {@link AppWidgetHost#deleteHost()} is called during database creation.
+ * Use this to recall {@link AppWidgetHost#startListening()} if needed.
+ */
+ static final Uri CONTENT_APPWIDGET_RESET_URI =
+ Uri.parse("content://" + AUTHORITY + "/appWidgetReset");
+
+ private SQLiteOpenHelper mOpenHelper;
+
+ @Override
+ public boolean onCreate() {
+ mOpenHelper = new DatabaseHelper(getContext());
+ return true;
+ }
+
+ @Override
+ public String getType(Uri uri) {
+ SqlArguments args = new SqlArguments(uri, null, null);
+ if (TextUtils.isEmpty(args.where)) {
+ return "vnd.android.cursor.dir/" + args.table;
+ } else {
+ return "vnd.android.cursor.item/" + args.table;
+ }
+ }
+
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection,
+ String[] selectionArgs, String sortOrder) {
+
+ SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
+ SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
+ qb.setTables(args.table);
+
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ Cursor result = qb.query(db, projection, args.where, args.args, null, null, sortOrder);
+ result.setNotificationUri(getContext().getContentResolver(), uri);
+
+ return result;
+ }
+
+ @Override
+ public Uri insert(Uri uri, ContentValues initialValues) {
+ SqlArguments args = new SqlArguments(uri);
+
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ final long rowId = db.insert(args.table, null, initialValues);
+ if (rowId <= 0) return null;
+
+ uri = ContentUris.withAppendedId(uri, rowId);
+ sendNotify(uri);
+
+ return uri;
+ }
+
+ @Override
+ public int bulkInsert(Uri uri, ContentValues[] values) {
+ SqlArguments args = new SqlArguments(uri);
+
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ db.beginTransaction();
+ try {
+ int numValues = values.length;
+ for (int i = 0; i < numValues; i++) {
+ if (db.insert(args.table, null, values[i]) < 0) return 0;
+ }
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+
+ sendNotify(uri);
+ return values.length;
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
+
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ int count = db.delete(args.table, args.where, args.args);
+ if (count > 0) sendNotify(uri);
+
+ return count;
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ SqlArguments args = new SqlArguments(uri, selection, selectionArgs);
+
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ int count = db.update(args.table, values, args.where, args.args);
+ if (count > 0) sendNotify(uri);
+
+ return count;
+ }
+
+ private void sendNotify(Uri uri) {
+ String notify = uri.getQueryParameter(PARAMETER_NOTIFY);
+ if (notify == null || "true".equals(notify)) {
+ getContext().getContentResolver().notifyChange(uri, null);
+ }
+ }
+
+ private static class DatabaseHelper extends SQLiteOpenHelper {
+ private static final String TAG_FAVORITES = "favorites";
+ private static final String TAG_FAVORITE = "favorite";
+ private static final String TAG_CLOCK = "clock";
+ private static final String TAG_SEARCH = "search";
+ private static final String TAG_APPWIDGET = "appwidget";
+ private static final String TAG_SHORTCUT = "shortcut";
+
+ private final Context mContext;
+ private final AppWidgetHost mAppWidgetHost;
+
+ DatabaseHelper(Context context) {
+ super(context, DATABASE_NAME, null, DATABASE_VERSION);
+ mContext = context;
+ mAppWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
+ }
+
+ /**
+ * Send notification that we've deleted the {@link AppWidgetHost},
+ * probably as part of the initial database creation. The receiver may
+ * want to re-call {@link AppWidgetHost#startListening()} to ensure
+ * callbacks are correctly set.
+ */
+ private void sendAppWidgetResetNotify() {
+ final ContentResolver resolver = mContext.getContentResolver();
+ resolver.notifyChange(CONTENT_APPWIDGET_RESET_URI, null);
+ }
+
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ if (LOGD) Log.d(TAG, "creating new launcher database");
+
+ db.execSQL("CREATE TABLE favorites (" +
+ "_id INTEGER PRIMARY KEY," +
+ "title TEXT," +
+ "intent TEXT," +
+ "container INTEGER," +
+ "screen INTEGER," +
+ "cellX INTEGER," +
+ "cellY INTEGER," +
+ "spanX INTEGER," +
+ "spanY INTEGER," +
+ "itemType INTEGER," +
+ "appWidgetId INTEGER NOT NULL DEFAULT -1," +
+ "isShortcut INTEGER," +
+ "iconType INTEGER," +
+ "iconPackage TEXT," +
+ "iconResource TEXT," +
+ "icon BLOB," +
+ "uri TEXT," +
+ "displayMode INTEGER" +
+ ");");
+
+ // Database was just created, so wipe any previous widgets
+ if (mAppWidgetHost != null) {
+ mAppWidgetHost.deleteHost();
+ sendAppWidgetResetNotify();
+ }
+
+ if (!convertDatabase(db)) {
+ // Populate favorites table with initial favorites
+ loadFavorites(db);
+ }
+ }
+
+ private boolean convertDatabase(SQLiteDatabase db) {
+ if (LOGD) Log.d(TAG, "converting database from an older format, but not onUpgrade");
+ boolean converted = false;
+
+ final Uri uri = Uri.parse("content://" + Settings.AUTHORITY +
+ "/old_favorites?notify=true");
+ final ContentResolver resolver = mContext.getContentResolver();
+ Cursor cursor = null;
+
+ try {
+ cursor = resolver.query(uri, null, null, null, null);
+ } catch (Exception e) {
+ // Ignore
+ }
+
+ // We already have a favorites database in the old provider
+ if (cursor != null && cursor.getCount() > 0) {
+ try {
+ converted = copyFromCursor(db, cursor) > 0;
+ } finally {
+ cursor.close();
+ }
+
+ if (converted) {
+ resolver.delete(uri, null, null);
+ }
+ }
+
+ if (converted) {
+ // Convert widgets from this import into widgets
+ if (LOGD) Log.d(TAG, "converted and now triggering widget upgrade");
+ convertWidgets(db);
+ }
+
+ return converted;
+ }
+
+ private int copyFromCursor(SQLiteDatabase db, Cursor c) {
+ final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
+ final int intentIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
+ final int titleIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.TITLE);
+ final int iconTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_TYPE);
+ final int iconIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON);
+ final int iconPackageIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_PACKAGE);
+ final int iconResourceIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ICON_RESOURCE);
+ final int containerIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CONTAINER);
+ final int itemTypeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.ITEM_TYPE);
+ final int screenIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.SCREEN);
+ final int cellXIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLX);
+ final int cellYIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.CELLY);
+ final int uriIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.URI);
+ final int displayModeIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.DISPLAY_MODE);
+
+ ContentValues[] rows = new ContentValues[c.getCount()];
+ int i = 0;
+ while (c.moveToNext()) {
+ ContentValues values = new ContentValues(c.getColumnCount());
+ values.put(LauncherSettings.Favorites._ID, c.getLong(idIndex));
+ values.put(LauncherSettings.Favorites.INTENT, c.getString(intentIndex));
+ values.put(LauncherSettings.Favorites.TITLE, c.getString(titleIndex));
+ values.put(LauncherSettings.Favorites.ICON_TYPE, c.getInt(iconTypeIndex));
+ values.put(LauncherSettings.Favorites.ICON, c.getBlob(iconIndex));
+ values.put(LauncherSettings.Favorites.ICON_PACKAGE, c.getString(iconPackageIndex));
+ values.put(LauncherSettings.Favorites.ICON_RESOURCE, c.getString(iconResourceIndex));
+ values.put(LauncherSettings.Favorites.CONTAINER, c.getInt(containerIndex));
+ values.put(LauncherSettings.Favorites.ITEM_TYPE, c.getInt(itemTypeIndex));
+ values.put(LauncherSettings.Favorites.APPWIDGET_ID, -1);
+ values.put(LauncherSettings.Favorites.SCREEN, c.getInt(screenIndex));
+ values.put(LauncherSettings.Favorites.CELLX, c.getInt(cellXIndex));
+ values.put(LauncherSettings.Favorites.CELLY, c.getInt(cellYIndex));
+ values.put(LauncherSettings.Favorites.URI, c.getString(uriIndex));
+ values.put(LauncherSettings.Favorites.DISPLAY_MODE, c.getInt(displayModeIndex));
+ rows[i++] = values;
+ }
+
+ db.beginTransaction();
+ int total = 0;
+ try {
+ int numValues = rows.length;
+ for (i = 0; i < numValues; i++) {
+ if (db.insert(TABLE_FAVORITES, null, rows[i]) < 0) {
+ return 0;
+ } else {
+ total++;
+ }
+ }
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+
+ return total;
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ if (LOGD) Log.d(TAG, "onUpgrade triggered");
+
+ int version = oldVersion;
+ if (version < 3) {
+ // upgrade 1,2 -> 3 added appWidgetId column
+ db.beginTransaction();
+ try {
+ // Insert new column for holding appWidgetIds
+ db.execSQL("ALTER TABLE favorites " +
+ "ADD COLUMN appWidgetId INTEGER NOT NULL DEFAULT -1;");
+ db.setTransactionSuccessful();
+ version = 3;
+ } catch (SQLException ex) {
+ // Old version remains, which means we wipe old data
+ Log.e(TAG, ex.getMessage(), ex);
+ } finally {
+ db.endTransaction();
+ }
+
+ // Convert existing widgets only if table upgrade was successful
+ if (version == 3) {
+ convertWidgets(db);
+ }
+ }
+
+ if (version < 4) {
+ version = 4;
+ }
+
+ if (version < 5) {
+ // We went from 3 to 5 screens. Move everything 1 to the right
+ db.beginTransaction();
+ try {
+ db.execSQL("UPDATE favorites SET screen=(screen + 1);");
+ db.setTransactionSuccessful();
+ version = 5;
+ } catch (SQLException ex) {
+ // Old version remains, which means we wipe old data
+ Log.e(TAG, ex.getMessage(), ex);
+ } finally {
+ db.endTransaction();
+ }
+ }
+
+ if (version < 6) {
+ if (updateContactsShortcuts(db)) {
+ version = 6;
+ }
+ }
+
+ if (version != DATABASE_VERSION) {
+ Log.w(TAG, "Destroying all old data.");
+ db.execSQL("DROP TABLE IF EXISTS " + TABLE_FAVORITES);
+ onCreate(db);
+ }
+ }
+
+ private boolean updateContactsShortcuts(SQLiteDatabase db) {
+ Cursor c = null;
+ final String selectWhere = buildOrWhereString(Favorites.ITEM_TYPE,
+ new int[] { Favorites.ITEM_TYPE_SHORTCUT });
+
+ db.beginTransaction();
+ try {
+ // Select and iterate through each matching widget
+ c = db.query(TABLE_FAVORITES, new String[] { Favorites._ID, Favorites.INTENT },
+ selectWhere, null, null, null, null);
+
+ if (LOGD) Log.d(TAG, "found upgrade cursor count=" + c.getCount());
+
+ final ContentValues values = new ContentValues();
+ final int idIndex = c.getColumnIndex(Favorites._ID);
+ final int intentIndex = c.getColumnIndex(Favorites.INTENT);
+
+ while (c != null && c.moveToNext()) {
+ long favoriteId = c.getLong(idIndex);
+ final String intentUri = c.getString(intentIndex);
+ if (intentUri != null) {
+ try {
+ Intent intent = Intent.parseUri(intentUri, 0);
+ android.util.Log.d("Home", intent.toString());
+ final Uri uri = intent.getData();
+ final String data = uri.toString();
+ if (Intent.ACTION_VIEW.equals(intent.getAction()) &&
+ (data.startsWith("content://contacts/people/") ||
+ data.startsWith("content://com.android.contacts/contacts/lookup/"))) {
+
+ intent = new Intent("com.android.contacts.action.QUICK_CONTACT");
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
+ Intent.FLAG_ACTIVITY_CLEAR_TOP |
+ Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+
+ intent.setData(uri);
+ intent.putExtra("mode", 3);
+ intent.putExtra("exclude_mimes", (String[]) null);
+
+ values.clear();
+ values.put(LauncherSettings.Favorites.INTENT, intent.toUri(0));
+
+ String updateWhere = Favorites._ID + "=" + favoriteId;
+ db.update(TABLE_FAVORITES, values, updateWhere, null);
+ }
+ } catch (RuntimeException ex) {
+ Log.e(TAG, "Problem upgrading shortcut", ex);
+ } catch (URISyntaxException e) {
+ Log.e(TAG, "Problem upgrading shortcut", e);
+ }
+ }
+ }
+
+ db.setTransactionSuccessful();
+ } catch (SQLException ex) {
+ Log.w(TAG, "Problem while upgrading contacts", ex);
+ return false;
+ } finally {
+ db.endTransaction();
+ if (c != null) {
+ c.close();
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Upgrade existing clock and photo frame widgets into their new widget
+ * equivalents. This method allocates appWidgetIds, and then hands off to
+ * LauncherAppWidgetBinder to finish the actual binding.
+ */
+ private void convertWidgets(SQLiteDatabase db) {
+ final int[] bindSources = new int[] {
+ Favorites.ITEM_TYPE_WIDGET_CLOCK,
+ Favorites.ITEM_TYPE_WIDGET_PHOTO_FRAME,
+ };
+
+ final ArrayList<ComponentName> bindTargets = new ArrayList<ComponentName>();
+ bindTargets.add(new ComponentName("com.android.alarmclock",
+ "com.android.alarmclock.AnalogAppWidgetProvider"));
+ bindTargets.add(new ComponentName("com.android.camera",
+ "com.android.camera.PhotoAppWidgetProvider"));
+
+ final String selectWhere = buildOrWhereString(Favorites.ITEM_TYPE, bindSources);
+
+ Cursor c = null;
+ boolean allocatedAppWidgets = false;
+
+ db.beginTransaction();
+ try {
+ // Select and iterate through each matching widget
+ c = db.query(TABLE_FAVORITES, new String[] { Favorites._ID },
+ selectWhere, null, null, null, null);
+
+ if (LOGD) Log.d(TAG, "found upgrade cursor count=" + c.getCount());
+
+ final ContentValues values = new ContentValues();
+ while (c != null && c.moveToNext()) {
+ long favoriteId = c.getLong(0);
+
+ // Allocate and update database with new appWidgetId
+ try {
+ int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
+
+ if (LOGD) {
+ Log.d(TAG, "allocated appWidgetId=" + appWidgetId
+ + " for favoriteId=" + favoriteId);
+ }
+
+ values.clear();
+ values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
+
+ // Original widgets might not have valid spans when upgrading
+ values.put(LauncherSettings.Favorites.SPANX, 2);
+ values.put(LauncherSettings.Favorites.SPANY, 2);
+
+ String updateWhere = Favorites._ID + "=" + favoriteId;
+ db.update(TABLE_FAVORITES, values, updateWhere, null);
+
+ allocatedAppWidgets = true;
+ } catch (RuntimeException ex) {
+ Log.e(TAG, "Problem allocating appWidgetId", ex);
+ }
+ }
+
+ db.setTransactionSuccessful();
+ } catch (SQLException ex) {
+ Log.w(TAG, "Problem while allocating appWidgetIds for existing widgets", ex);
+ } finally {
+ db.endTransaction();
+ if (c != null) {
+ c.close();
+ }
+ }
+
+ // If any appWidgetIds allocated, then launch over to binder
+ if (allocatedAppWidgets) {
+ launchAppWidgetBinder(bindSources, bindTargets);
+ }
+ }
+
+ /**
+ * Launch the widget binder that walks through the Launcher database,
+ * binding any matching widgets to the corresponding targets. We can't
+ * bind ourselves because our parent process can't obtain the
+ * BIND_APPWIDGET permission.
+ */
+ private void launchAppWidgetBinder(int[] bindSources, ArrayList<ComponentName> bindTargets) {
+ final Intent intent = new Intent();
+ intent.setComponent(new ComponentName("com.android.settings",
+ "com.android.settings.LauncherAppWidgetBinder"));
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ final Bundle extras = new Bundle();
+ extras.putIntArray(EXTRA_BIND_SOURCES, bindSources);
+ extras.putParcelableArrayList(EXTRA_BIND_TARGETS, bindTargets);
+ intent.putExtras(extras);
+
+ mContext.startActivity(intent);
+ }
+
+ /**
+ * Loads the default set of favorite packages from an xml file.
+ *
+ * @param db The database to write the values into
+ */
+ private int loadFavorites(SQLiteDatabase db) {
+ Intent intent = new Intent(Intent.ACTION_MAIN, null);
+ intent.addCategory(Intent.CATEGORY_LAUNCHER);
+ ContentValues values = new ContentValues();
+
+ PackageManager packageManager = mContext.getPackageManager();
+ int i = 0;
+ try {
+ XmlResourceParser parser = mContext.getResources().getXml(R.xml.default_workspace);
+ AttributeSet attrs = Xml.asAttributeSet(parser);
+ XmlUtils.beginDocument(parser, TAG_FAVORITES);
+
+ final int depth = parser.getDepth();
+
+ int type;
+ while (((type = parser.next()) != XmlPullParser.END_TAG ||
+ parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
+
+ if (type != XmlPullParser.START_TAG) {
+ continue;
+ }
+
+ boolean added = false;
+ final String name = parser.getName();
+
+ TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.Favorite);
+
+ values.clear();
+ values.put(LauncherSettings.Favorites.CONTAINER,
+ LauncherSettings.Favorites.CONTAINER_DESKTOP);
+ values.put(LauncherSettings.Favorites.SCREEN,
+ a.getString(R.styleable.Favorite_screen));
+ values.put(LauncherSettings.Favorites.CELLX,
+ a.getString(R.styleable.Favorite_x));
+ values.put(LauncherSettings.Favorites.CELLY,
+ a.getString(R.styleable.Favorite_y));
+
+ if (TAG_FAVORITE.equals(name)) {
+ added = addAppShortcut(db, values, a, packageManager, intent);
+ } else if (TAG_SEARCH.equals(name)) {
+ added = addSearchWidget(db, values);
+ } else if (TAG_CLOCK.equals(name)) {
+ added = addClockWidget(db, values);
+ } else if (TAG_APPWIDGET.equals(name)) {
+ added = addAppWidget(db, values, a);
+ } else if (TAG_SHORTCUT.equals(name)) {
+ added = addUriShortcut(db, values, a);
+ }
+
+ if (added) i++;
+
+ a.recycle();
+ }
+ } catch (XmlPullParserException e) {
+ Log.w(TAG, "Got exception parsing favorites.", e);
+ } catch (IOException e) {
+ Log.w(TAG, "Got exception parsing favorites.", e);
+ }
+
+ return i;
+ }
+
+ private boolean addAppShortcut(SQLiteDatabase db, ContentValues values, TypedArray a,
+ PackageManager packageManager, Intent intent) {
+
+ ActivityInfo info;
+ String packageName = a.getString(R.styleable.Favorite_packageName);
+ String className = a.getString(R.styleable.Favorite_className);
+ try {
+ ComponentName cn = new ComponentName(packageName, className);
+ info = packageManager.getActivityInfo(cn, 0);
+ intent.setComponent(cn);
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
+ | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
+ values.put(Favorites.INTENT, intent.toUri(0));
+ values.put(Favorites.TITLE, info.loadLabel(packageManager).toString());
+ values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPLICATION);
+ values.put(Favorites.SPANX, 1);
+ values.put(Favorites.SPANY, 1);
+ db.insert(TABLE_FAVORITES, null, values);
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.w(TAG, "Unable to add favorite: " + packageName +
+ "/" + className, e);
+ return false;
+ }
+ return true;
+ }
+
+ private boolean addSearchWidget(SQLiteDatabase db, ContentValues values) {
+ // Add a search box
+ values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_WIDGET_SEARCH);
+ values.put(Favorites.SPANX, 4);
+ values.put(Favorites.SPANY, 1);
+ db.insert(TABLE_FAVORITES, null, values);
+
+ return true;
+ }
+
+ private boolean addClockWidget(SQLiteDatabase db, ContentValues values) {
+ final int[] bindSources = new int[] {
+ Favorites.ITEM_TYPE_WIDGET_CLOCK,
+ };
+
+ final ArrayList<ComponentName> bindTargets = new ArrayList<ComponentName>();
+ bindTargets.add(new ComponentName("com.android.alarmclock",
+ "com.android.alarmclock.AnalogAppWidgetProvider"));
+
+ boolean allocatedAppWidgets = false;
+
+ // Try binding to an analog clock widget
+ try {
+ int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
+
+ values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_WIDGET_CLOCK);
+ values.put(Favorites.SPANX, 2);
+ values.put(Favorites.SPANY, 2);
+ values.put(Favorites.APPWIDGET_ID, appWidgetId);
+ db.insert(TABLE_FAVORITES, null, values);
+
+ allocatedAppWidgets = true;
+ } catch (RuntimeException ex) {
+ Log.e(TAG, "Problem allocating appWidgetId", ex);
+ }
+
+ // If any appWidgetIds allocated, then launch over to binder
+ if (allocatedAppWidgets) {
+ launchAppWidgetBinder(bindSources, bindTargets);
+ }
+
+ return allocatedAppWidgets;
+ }
+
+ private boolean addAppWidget(SQLiteDatabase db, ContentValues values, TypedArray a) {
+ String packageName = a.getString(R.styleable.Favorite_packageName);
+ String className = a.getString(R.styleable.Favorite_className);
+
+ if (packageName == null || className == null) {
+ return false;
+ }
+
+ ComponentName cn = new ComponentName(packageName, className);
+
+ boolean allocatedAppWidgets = false;
+ final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
+
+ try {
+ int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
+
+ values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET);
+ values.put(Favorites.SPANX, a.getString(R.styleable.Favorite_spanX));
+ values.put(Favorites.SPANY, a.getString(R.styleable.Favorite_spanY));
+ values.put(Favorites.APPWIDGET_ID, appWidgetId);
+ db.insert(TABLE_FAVORITES, null, values);
+
+ allocatedAppWidgets = true;
+
+ appWidgetManager.bindAppWidgetId(appWidgetId, cn);
+ } catch (RuntimeException ex) {
+ Log.e(TAG, "Problem allocating appWidgetId", ex);
+ }
+
+ return allocatedAppWidgets;
+ }
+
+ private boolean addUriShortcut(SQLiteDatabase db, ContentValues values,
+ TypedArray a) {
+ Resources r = mContext.getResources();
+
+ final int iconResId = a.getResourceId(R.styleable.Favorite_icon, 0);
+ final int titleResId = a.getResourceId(R.styleable.Favorite_title, 0);
+
+ Intent intent;
+ String uri = null;
+ try {
+ uri = a.getString(R.styleable.Favorite_uri);
+ intent = Intent.parseUri(uri, 0);
+ } catch (URISyntaxException e) {
+ Log.w(TAG, "Shortcut has malformed uri: " + uri);
+ return false; // Oh well
+ }
+
+ if (iconResId == 0 || titleResId == 0) {
+ Log.w(TAG, "Shortcut is missing title or icon resource ID");
+ return false;
+ }
+
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ values.put(Favorites.INTENT, intent.toUri(0));
+ values.put(Favorites.TITLE, r.getString(titleResId));
+ values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_SHORTCUT);
+ values.put(Favorites.SPANX, 1);
+ values.put(Favorites.SPANY, 1);
+ values.put(Favorites.ICON_TYPE, Favorites.ICON_TYPE_RESOURCE);
+ values.put(Favorites.ICON_PACKAGE, mContext.getPackageName());
+ values.put(Favorites.ICON_RESOURCE, r.getResourceName(iconResId));
+
+ db.insert(TABLE_FAVORITES, null, values);
+
+ return true;
+ }
+ }
+
+ /**
+ * Build a query string that will match any row where the column matches
+ * anything in the values list.
+ */
+ static String buildOrWhereString(String column, int[] values) {
+ StringBuilder selectWhere = new StringBuilder();
+ for (int i = values.length - 1; i >= 0; i--) {
+ selectWhere.append(column).append("=").append(values[i]);
+ if (i > 0) {
+ selectWhere.append(" OR ");
+ }
+ }
+ return selectWhere.toString();
+ }
+
+ static class SqlArguments {
+ public final String table;
+ public final String where;
+ public final String[] args;
+
+ SqlArguments(Uri url, String where, String[] args) {
+ if (url.getPathSegments().size() == 1) {
+ this.table = url.getPathSegments().get(0);
+ this.where = where;
+ this.args = args;
+ } else if (url.getPathSegments().size() != 2) {
+ throw new IllegalArgumentException("Invalid URI: " + url);
+ } else if (!TextUtils.isEmpty(where)) {
+ throw new UnsupportedOperationException("WHERE clause not supported: " + url);
+ } else {
+ this.table = url.getPathSegments().get(0);
+ this.where = "_id=" + ContentUris.parseId(url);
+ this.args = null;
+ }
+ }
+
+ SqlArguments(Uri url) {
+ if (url.getPathSegments().size() == 1) {
+ table = url.getPathSegments().get(0);
+ where = null;
+ args = null;
+ } else {
+ throw new IllegalArgumentException("Invalid URI: " + url);
+ }
+ }
+ }
+}
diff --git a/src/com/android/launcher2/LauncherSettings.java b/src/com/android/launcher2/LauncherSettings.java
new file mode 100644
index 0000000..a438d47
--- /dev/null
+++ b/src/com/android/launcher2/LauncherSettings.java
@@ -0,0 +1,232 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.provider.BaseColumns;
+import android.net.Uri;
+
+/**
+ * Settings related utilities.
+ */
+class LauncherSettings {
+ static interface BaseLauncherColumns extends BaseColumns {
+ /**
+ * Descriptive name of the gesture that can be displayed to the user.
+ * <P>Type: TEXT</P>
+ */
+ static final String TITLE = "title";
+
+ /**
+ * The Intent URL of the gesture, describing what it points to. This
+ * value is given to {@link android.content.Intent#parseUri(String, int)} to create
+ * an Intent that can be launched.
+ * <P>Type: TEXT</P>
+ */
+ static final String INTENT = "intent";
+
+ /**
+ * The type of the gesture
+ *
+ * <P>Type: INTEGER</P>
+ */
+ static final String ITEM_TYPE = "itemType";
+
+ /**
+ * The gesture is an application
+ */
+ static final int ITEM_TYPE_APPLICATION = 0;
+
+ /**
+ * The gesture is an application created shortcut
+ */
+ static final int ITEM_TYPE_SHORTCUT = 1;
+
+ /**
+ * The icon type.
+ * <P>Type: INTEGER</P>
+ */
+ static final String ICON_TYPE = "iconType";
+
+ /**
+ * The icon is a resource identified by a package name and an integer id.
+ */
+ static final int ICON_TYPE_RESOURCE = 0;
+
+ /**
+ * The icon is a bitmap.
+ */
+ static final int ICON_TYPE_BITMAP = 1;
+
+ /**
+ * The icon package name, if icon type is ICON_TYPE_RESOURCE.
+ * <P>Type: TEXT</P>
+ */
+ static final String ICON_PACKAGE = "iconPackage";
+
+ /**
+ * The icon resource id, if icon type is ICON_TYPE_RESOURCE.
+ * <P>Type: TEXT</P>
+ */
+ static final String ICON_RESOURCE = "iconResource";
+
+ /**
+ * The custom icon bitmap, if icon type is ICON_TYPE_BITMAP.
+ * <P>Type: BLOB</P>
+ */
+ static final String ICON = "icon";
+ }
+
+ /**
+ * Favorites. When changing these values, be sure to update
+ * {@link com.android.settings.LauncherAppWidgetBinder} as needed.
+ */
+ static final class Favorites implements BaseLauncherColumns {
+ /**
+ * The content:// style URL for this table
+ */
+ static final Uri CONTENT_URI = Uri.parse("content://" +
+ LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES +
+ "?" + LauncherProvider.PARAMETER_NOTIFY + "=true");
+
+ /**
+ * The content:// style URL for this table. When this Uri is used, no notification is
+ * sent if the content changes.
+ */
+ static final Uri CONTENT_URI_NO_NOTIFICATION = Uri.parse("content://" +
+ LauncherProvider.AUTHORITY + "/" + LauncherProvider.TABLE_FAVORITES +
+ "?" + LauncherProvider.PARAMETER_NOTIFY + "=false");
+
+ /**
+ * The content:// style URL for a given row, identified by its id.
+ *
+ * @param id The row id.
+ * @param notify True to send a notification is the content changes.
+ *
+ * @return The unique content URL for the specified row.
+ */
+ static Uri getContentUri(long id, boolean notify) {
+ return Uri.parse("content://" + LauncherProvider.AUTHORITY +
+ "/" + LauncherProvider.TABLE_FAVORITES + "/" + id + "?" +
+ LauncherProvider.PARAMETER_NOTIFY + "=" + notify);
+ }
+
+ /**
+ * The container holding the favorite
+ * <P>Type: INTEGER</P>
+ */
+ static final String CONTAINER = "container";
+
+ /**
+ * The icon is a resource identified by a package name and an integer id.
+ */
+ static final int CONTAINER_DESKTOP = -100;
+
+ /**
+ * The screen holding the favorite (if container is CONTAINER_DESKTOP)
+ * <P>Type: INTEGER</P>
+ */
+ static final String SCREEN = "screen";
+
+ /**
+ * The X coordinate of the cell holding the favorite
+ * (if container is CONTAINER_DESKTOP or CONTAINER_DOCK)
+ * <P>Type: INTEGER</P>
+ */
+ static final String CELLX = "cellX";
+
+ /**
+ * The Y coordinate of the cell holding the favorite
+ * (if container is CONTAINER_DESKTOP)
+ * <P>Type: INTEGER</P>
+ */
+ static final String CELLY = "cellY";
+
+ /**
+ * The X span of the cell holding the favorite
+ * <P>Type: INTEGER</P>
+ */
+ static final String SPANX = "spanX";
+
+ /**
+ * The Y span of the cell holding the favorite
+ * <P>Type: INTEGER</P>
+ */
+ static final String SPANY = "spanY";
+
+ /**
+ * The favorite is a user created folder
+ */
+ static final int ITEM_TYPE_USER_FOLDER = 2;
+
+ /**
+ * The favorite is a live folder
+ */
+ static final int ITEM_TYPE_LIVE_FOLDER = 3;
+
+ /**
+ * The favorite is a widget
+ */
+ static final int ITEM_TYPE_APPWIDGET = 4;
+
+ /**
+ * The favorite is a clock
+ */
+ static final int ITEM_TYPE_WIDGET_CLOCK = 1000;
+
+ /**
+ * The favorite is a search widget
+ */
+ static final int ITEM_TYPE_WIDGET_SEARCH = 1001;
+
+ /**
+ * The favorite is a photo frame
+ */
+ static final int ITEM_TYPE_WIDGET_PHOTO_FRAME = 1002;
+
+ /**
+ * The appWidgetId of the widget
+ *
+ * <P>Type: INTEGER</P>
+ */
+ static final String APPWIDGET_ID = "appWidgetId";
+
+ /**
+ * Indicates whether this favorite is an application-created shortcut or not.
+ * If the value is 0, the favorite is not an application-created shortcut, if the
+ * value is 1, it is an application-created shortcut.
+ * <P>Type: INTEGER</P>
+ */
+ @Deprecated
+ static final String IS_SHORTCUT = "isShortcut";
+
+ /**
+ * The URI associated with the favorite. It is used, for instance, by
+ * live folders to find the content provider.
+ * <P>Type: TEXT</P>
+ */
+ static final String URI = "uri";
+
+ /**
+ * The display mode if the item is a live folder.
+ * <P>Type: INTEGER</P>
+ *
+ * @see android.provider.LiveFolders#DISPLAY_MODE_GRID
+ * @see android.provider.LiveFolders#DISPLAY_MODE_LIST
+ */
+ static final String DISPLAY_MODE = "displayMode";
+ }
+}
diff --git a/src/com/android/launcher2/LiveFolder.java b/src/com/android/launcher2/LiveFolder.java
new file mode 100644
index 0000000..ecd9bdf
--- /dev/null
+++ b/src/com/android/launcher2/LiveFolder.java
@@ -0,0 +1,134 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.content.Intent;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.AdapterView;
+import android.net.Uri;
+import android.provider.LiveFolders;
+import android.os.AsyncTask;
+import android.database.Cursor;
+
+import java.lang.ref.WeakReference;
+
+public class LiveFolder extends Folder {
+ private AsyncTask<LiveFolderInfo,Void,Cursor> mLoadingTask;
+
+ public LiveFolder(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ static LiveFolder fromXml(Context context, FolderInfo folderInfo) {
+ final int layout = isDisplayModeList(folderInfo) ?
+ R.layout.live_folder_list : R.layout.live_folder_grid;
+ return (LiveFolder) LayoutInflater.from(context).inflate(layout, null);
+ }
+
+ private static boolean isDisplayModeList(FolderInfo folderInfo) {
+ return ((LiveFolderInfo) folderInfo).displayMode ==
+ LiveFolders.DISPLAY_MODE_LIST;
+ }
+
+ @Override
+ public void onItemClick(AdapterView parent, View v, int position, long id) {
+ LiveFolderAdapter.ViewHolder holder = (LiveFolderAdapter.ViewHolder) v.getTag();
+
+ if (holder.useBaseIntent) {
+ final Intent baseIntent = ((LiveFolderInfo) mInfo).baseIntent;
+ if (baseIntent != null) {
+ final Intent intent = new Intent(baseIntent);
+ Uri uri = baseIntent.getData();
+ uri = uri.buildUpon().appendPath(Long.toString(holder.id)).build();
+ intent.setData(uri);
+ mLauncher.startActivitySafely(intent);
+ }
+ } else if (holder.intent != null) {
+ mLauncher.startActivitySafely(holder.intent);
+ }
+ }
+
+ @Override
+ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
+ return false;
+ }
+
+ void bind(FolderInfo info) {
+ super.bind(info);
+ if (mLoadingTask != null && mLoadingTask.getStatus() == AsyncTask.Status.RUNNING) {
+ mLoadingTask.cancel(true);
+ }
+ mLoadingTask = new FolderLoadingTask(this).execute((LiveFolderInfo) info);
+ }
+
+ @Override
+ void onOpen() {
+ super.onOpen();
+ requestFocus();
+ }
+
+ @Override
+ void onClose() {
+ super.onClose();
+ if (mLoadingTask != null && mLoadingTask.getStatus() == AsyncTask.Status.RUNNING) {
+ mLoadingTask.cancel(true);
+ }
+
+ // The adapter can be null if onClose() is called before FolderLoadingTask
+ // is done querying the provider
+ final LiveFolderAdapter adapter = (LiveFolderAdapter) mContent.getAdapter();
+ if (adapter != null) {
+ adapter.cleanup();
+ }
+ }
+
+ static class FolderLoadingTask extends AsyncTask<LiveFolderInfo, Void, Cursor> {
+ private final WeakReference<LiveFolder> mFolder;
+ private LiveFolderInfo mInfo;
+
+ FolderLoadingTask(LiveFolder folder) {
+ mFolder = new WeakReference<LiveFolder>(folder);
+ }
+
+ protected Cursor doInBackground(LiveFolderInfo... params) {
+ final LiveFolder folder = mFolder.get();
+ if (folder != null) {
+ mInfo = params[0];
+ return LiveFolderAdapter.query(folder.mLauncher, mInfo);
+ }
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Cursor cursor) {
+ if (!isCancelled()) {
+ if (cursor != null) {
+ final LiveFolder folder = mFolder.get();
+ if (folder != null) {
+ final Launcher launcher = folder.mLauncher;
+ folder.setContentAdapter(new LiveFolderAdapter(launcher, mInfo, cursor));
+ }
+ }
+ } else if (cursor != null) {
+ cursor.close();
+ }
+ }
+ }
+}
diff --git a/src/com/android/launcher2/LiveFolderAdapter.java b/src/com/android/launcher2/LiveFolderAdapter.java
new file mode 100644
index 0000000..b0e9eff
--- /dev/null
+++ b/src/com/android/launcher2/LiveFolderAdapter.java
@@ -0,0 +1,209 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.widget.CursorAdapter;
+import android.widget.TextView;
+import android.widget.ImageView;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.content.pm.PackageManager;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.LayoutInflater;
+import android.database.Cursor;
+import android.provider.LiveFolders;
+import android.graphics.drawable.Drawable;
+import android.graphics.BitmapFactory;
+import android.graphics.Bitmap;
+
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.lang.ref.SoftReference;
+
+class LiveFolderAdapter extends CursorAdapter {
+ private boolean mIsList;
+ private LayoutInflater mInflater;
+
+ private final HashMap<String, Drawable> mIcons = new HashMap<String, Drawable>();
+ private final HashMap<Long, SoftReference<Drawable>> mCustomIcons =
+ new HashMap<Long, SoftReference<Drawable>>();
+ private final Launcher mLauncher;
+
+ LiveFolderAdapter(Launcher launcher, LiveFolderInfo info, Cursor cursor) {
+ super(launcher, cursor, true);
+ mIsList = info.displayMode == LiveFolders.DISPLAY_MODE_LIST;
+ mInflater = LayoutInflater.from(launcher);
+ mLauncher = launcher;
+
+ mLauncher.startManagingCursor(getCursor());
+ }
+
+ static Cursor query(Context context, LiveFolderInfo info) {
+ return context.getContentResolver().query(info.uri, null, null,
+ null, LiveFolders.NAME + " ASC");
+ }
+
+ public View newView(Context context, Cursor cursor, ViewGroup parent) {
+ View view;
+ final ViewHolder holder = new ViewHolder();
+
+ if (!mIsList) {
+ view = mInflater.inflate(R.layout.application_boxed, parent, false);
+ } else {
+ view = mInflater.inflate(R.layout.application_list, parent, false);
+ holder.description = (TextView) view.findViewById(R.id.description);
+ holder.icon = (ImageView) view.findViewById(R.id.icon);
+ }
+
+ holder.name = (TextView) view.findViewById(R.id.name);
+
+ holder.idIndex = cursor.getColumnIndexOrThrow(LiveFolders._ID);
+ holder.nameIndex = cursor.getColumnIndexOrThrow(LiveFolders.NAME);
+ holder.descriptionIndex = cursor.getColumnIndex(LiveFolders.DESCRIPTION);
+ holder.intentIndex = cursor.getColumnIndex(LiveFolders.INTENT);
+ holder.iconBitmapIndex = cursor.getColumnIndex(LiveFolders.ICON_BITMAP);
+ holder.iconResourceIndex = cursor.getColumnIndex(LiveFolders.ICON_RESOURCE);
+ holder.iconPackageIndex = cursor.getColumnIndex(LiveFolders.ICON_PACKAGE);
+
+ view.setTag(holder);
+
+ return view;
+ }
+
+ public void bindView(View view, Context context, Cursor cursor) {
+ final ViewHolder holder = (ViewHolder) view.getTag();
+
+ holder.id = cursor.getLong(holder.idIndex);
+ final Drawable icon = loadIcon(context, cursor, holder);
+
+ holder.name.setText(cursor.getString(holder.nameIndex));
+
+ if (!mIsList) {
+ holder.name.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
+ } else {
+ final boolean hasIcon = icon != null;
+ holder.icon.setVisibility(hasIcon ? View.VISIBLE : View.GONE);
+ if (hasIcon) holder.icon.setImageDrawable(icon);
+
+ if (holder.descriptionIndex != -1) {
+ final String description = cursor.getString(holder.descriptionIndex);
+ if (description != null) {
+ holder.description.setText(description);
+ holder.description.setVisibility(View.VISIBLE);
+ } else {
+ holder.description.setVisibility(View.GONE);
+ }
+ } else {
+ holder.description.setVisibility(View.GONE);
+ }
+ }
+
+ if (holder.intentIndex != -1) {
+ try {
+ holder.intent = Intent.parseUri(cursor.getString(holder.intentIndex), 0);
+ } catch (URISyntaxException e) {
+ // Ignore
+ }
+ } else {
+ holder.useBaseIntent = true;
+ }
+ }
+
+ private Drawable loadIcon(Context context, Cursor cursor, ViewHolder holder) {
+ Drawable icon = null;
+ byte[] data = null;
+
+ if (holder.iconBitmapIndex != -1) {
+ data = cursor.getBlob(holder.iconBitmapIndex);
+ }
+
+ if (data != null) {
+ final SoftReference<Drawable> reference = mCustomIcons.get(holder.id);
+ if (reference != null) {
+ icon = reference.get();
+ }
+
+ if (icon == null) {
+ final Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
+ icon = new FastBitmapDrawable(Utilities.createBitmapThumbnail(bitmap, mContext));
+ mCustomIcons.put(holder.id, new SoftReference<Drawable>(icon));
+ }
+ } else if (holder.iconResourceIndex != -1 && holder.iconPackageIndex != -1) {
+ final String resource = cursor.getString(holder.iconResourceIndex);
+ icon = mIcons.get(resource);
+ if (icon == null) {
+ try {
+ final PackageManager packageManager = context.getPackageManager();
+ Resources resources = packageManager.getResourcesForApplication(
+ cursor.getString(holder.iconPackageIndex));
+ final int id = resources.getIdentifier(resource,
+ null, null);
+ icon = Utilities.createIconThumbnail(resources.getDrawable(id), mContext);
+ mIcons.put(resource, icon);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
+
+ return icon;
+ }
+
+ void cleanup() {
+ for (Drawable icon : mIcons.values()) {
+ icon.setCallback(null);
+ }
+ mIcons.clear();
+
+ for (SoftReference<Drawable> icon : mCustomIcons.values()) {
+ final Drawable drawable = icon.get();
+ if (drawable != null) {
+ drawable.setCallback(null);
+ }
+ }
+ mCustomIcons.clear();
+
+ final Cursor cursor = getCursor();
+ if (cursor != null) {
+ try {
+ cursor.close();
+ } finally {
+ mLauncher.stopManagingCursor(cursor);
+ }
+ }
+ }
+
+ static class ViewHolder {
+ TextView name;
+ TextView description;
+ ImageView icon;
+
+ Intent intent;
+ long id;
+ boolean useBaseIntent;
+
+ int idIndex;
+ int nameIndex;
+ int descriptionIndex = -1;
+ int intentIndex = -1;
+ int iconBitmapIndex = -1;
+ int iconResourceIndex = -1;
+ int iconPackageIndex = -1;
+ }
+}
diff --git a/src/com/android/launcher2/LiveFolderIcon.java b/src/com/android/launcher2/LiveFolderIcon.java
new file mode 100644
index 0000000..55f100c
--- /dev/null
+++ b/src/com/android/launcher2/LiveFolderIcon.java
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.util.AttributeSet;
+import android.view.ViewGroup;
+import android.view.LayoutInflater;
+import android.graphics.drawable.Drawable;
+
+public class LiveFolderIcon extends FolderIcon {
+ public LiveFolderIcon(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public LiveFolderIcon(Context context) {
+ super(context);
+ }
+
+ static LiveFolderIcon fromXml(int resId, Launcher launcher, ViewGroup group,
+ LiveFolderInfo folderInfo) {
+
+ LiveFolderIcon icon = (LiveFolderIcon)
+ LayoutInflater.from(launcher).inflate(resId, group, false);
+
+ final Resources resources = launcher.getResources();
+ Drawable d = folderInfo.icon;
+ if (d == null) {
+ d = Utilities.createIconThumbnail(resources.getDrawable(R.drawable.ic_launcher_folder),
+ launcher);
+ folderInfo.filtered = true;
+ }
+ icon.setCompoundDrawablesWithIntrinsicBounds(null, d, null, null);
+ icon.setText(folderInfo.title);
+ icon.setTag(folderInfo);
+ icon.setOnClickListener(launcher);
+
+ return icon;
+ }
+
+ @Override
+ public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ return false;
+ }
+
+ @Override
+ public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+
+ @Override
+ public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+
+ @Override
+ public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+
+ @Override
+ public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+}
diff --git a/src/com/android/launcher2/LiveFolderInfo.java b/src/com/android/launcher2/LiveFolderInfo.java
new file mode 100644
index 0000000..5b1217c
--- /dev/null
+++ b/src/com/android/launcher2/LiveFolderInfo.java
@@ -0,0 +1,75 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.ContentValues;
+import android.content.Intent;
+import android.graphics.drawable.Drawable;
+import android.net.Uri;
+
+class LiveFolderInfo extends FolderInfo {
+
+ /**
+ * The base intent, if it exists.
+ */
+ Intent baseIntent;
+
+ /**
+ * The live folder's content uri.
+ */
+ Uri uri;
+
+ /**
+ * The live folder's display type.
+ */
+ int displayMode;
+
+ /**
+ * The live folder icon.
+ */
+ Drawable icon;
+
+ /**
+ * When set to true, indicates that the icon has been resized.
+ */
+ boolean filtered;
+
+ /**
+ * Reference to the live folder icon as an application's resource.
+ */
+ Intent.ShortcutIconResource iconResource;
+
+ LiveFolderInfo() {
+ itemType = LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER;
+ }
+
+ @Override
+ void onAddToDatabase(ContentValues values) {
+ super.onAddToDatabase(values);
+ values.put(LauncherSettings.Favorites.TITLE, title.toString());
+ values.put(LauncherSettings.Favorites.URI, uri.toString());
+ if (baseIntent != null) {
+ values.put(LauncherSettings.Favorites.INTENT, baseIntent.toUri(0));
+ }
+ values.put(LauncherSettings.Favorites.ICON_TYPE, LauncherSettings.Favorites.ICON_TYPE_RESOURCE);
+ values.put(LauncherSettings.Favorites.DISPLAY_MODE, displayMode);
+ if (iconResource != null) {
+ values.put(LauncherSettings.Favorites.ICON_PACKAGE, iconResource.packageName);
+ values.put(LauncherSettings.Favorites.ICON_RESOURCE, iconResource.resourceName);
+ }
+ }
+}
diff --git a/src/com/android/launcher2/Search.java b/src/com/android/launcher2/Search.java
new file mode 100644
index 0000000..283042d
--- /dev/null
+++ b/src/com/android/launcher2/Search.java
@@ -0,0 +1,380 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.app.Activity;
+import android.content.ActivityNotFoundException;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.content.res.Configuration;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.View.OnKeyListener;
+import android.view.View.OnLongClickListener;
+import android.view.animation.AccelerateDecelerateInterpolator;
+import android.view.animation.Animation;
+import android.view.animation.Interpolator;
+import android.view.animation.Transformation;
+import android.view.inputmethod.InputMethodManager;
+import android.widget.ImageButton;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class Search extends LinearLayout
+ implements OnClickListener, OnKeyListener, OnLongClickListener {
+
+ // Speed at which the widget slides up/down, in pixels/ms.
+ private static final float ANIMATION_VELOCITY = 1.0f;
+
+ /** The distance in dips between the optical top of the widget and the top if its bounds */
+ private static final float WIDGET_TOP_OFFSET = 9;
+
+
+ private final String TAG = "Launcher.SearchWidget";
+
+ private Launcher mLauncher;
+
+ private TextView mSearchText;
+ private ImageButton mVoiceButton;
+
+ /** The animation that morphs the search widget to the search dialog. */
+ private Animation mMorphAnimation;
+
+ /** The animation that morphs the search widget back to its normal position. */
+ private Animation mUnmorphAnimation;
+
+ // These four are passed to Launcher.startSearch() when the search widget
+ // has finished morphing. They are instance variables to make it possible to update
+ // them while the widget is morphing.
+ private String mInitialQuery;
+ private boolean mSelectInitialQuery;
+ private Bundle mAppSearchData;
+ private boolean mGlobalSearch;
+
+ // For voice searching
+ private Intent mVoiceSearchIntent;
+
+ private int mWidgetTopOffset;
+
+ /**
+ * Used to inflate the Workspace from XML.
+ *
+ * @param context The application's context.
+ * @param attrs The attributes set containing the Workspace's customization values.
+ */
+ public Search(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ final float scale = context.getResources().getDisplayMetrics().density;
+ mWidgetTopOffset = Math.round(WIDGET_TOP_OFFSET * scale);
+
+ Interpolator interpolator = new AccelerateDecelerateInterpolator();
+
+ mMorphAnimation = new ToParentOriginAnimation();
+ // no need to apply transformation before the animation starts,
+ // since the gadget is already in its normal place.
+ mMorphAnimation.setFillBefore(false);
+ // stay in the top position after the animation finishes
+ mMorphAnimation.setFillAfter(true);
+ mMorphAnimation.setInterpolator(interpolator);
+ mMorphAnimation.setAnimationListener(new Animation.AnimationListener() {
+ // The amount of time before the animation ends to show the search dialog.
+ private static final long TIME_BEFORE_ANIMATION_END = 80;
+
+ // The runnable which we'll pass to our handler to show the search dialog.
+ private final Runnable mShowSearchDialogRunnable = new Runnable() {
+ public void run() {
+ showSearchDialog();
+ }
+ };
+
+ public void onAnimationEnd(Animation animation) { }
+ public void onAnimationRepeat(Animation animation) { }
+ public void onAnimationStart(Animation animation) {
+ // Make the search dialog show up ideally *just* as the animation reaches
+ // the top, to aid the illusion that the widget becomes the search dialog.
+ // Otherwise, there is a short delay when the widget reaches the top before
+ // the search dialog shows. We do this roughly 80ms before the animation ends.
+ getHandler().postDelayed(
+ mShowSearchDialogRunnable,
+ Math.max(mMorphAnimation.getDuration() - TIME_BEFORE_ANIMATION_END, 0));
+ }
+ });
+
+ mUnmorphAnimation = new FromParentOriginAnimation();
+ // stay in the top position until the animation starts
+ mUnmorphAnimation.setFillBefore(true);
+ // no need to apply transformation after the animation finishes,
+ // since the gadget is now back in its normal place.
+ mUnmorphAnimation.setFillAfter(false);
+ mUnmorphAnimation.setInterpolator(interpolator);
+ mUnmorphAnimation.setAnimationListener(new Animation.AnimationListener(){
+ public void onAnimationEnd(Animation animation) {
+ clearAnimation();
+ }
+ public void onAnimationRepeat(Animation animation) { }
+ public void onAnimationStart(Animation animation) { }
+ });
+
+ mVoiceSearchIntent = new Intent(android.speech.RecognizerIntent.ACTION_WEB_SEARCH);
+ mVoiceSearchIntent.putExtra(android.speech.RecognizerIntent.EXTRA_LANGUAGE_MODEL,
+ android.speech.RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
+ }
+
+ /**
+ * Implements OnClickListener.
+ */
+ public void onClick(View v) {
+ if (v == mVoiceButton) {
+ startVoiceSearch();
+ } else {
+ mLauncher.onSearchRequested();
+ }
+ }
+
+ private void startVoiceSearch() {
+ try {
+ getContext().startActivity(mVoiceSearchIntent);
+ } catch (ActivityNotFoundException ex) {
+ // Should not happen, since we check the availability of
+ // voice search before showing the button. But just in case...
+ Log.w(TAG, "Could not find voice search activity");
+ }
+ }
+
+ /**
+ * Sets the query text. The query field is not editable, instead we forward
+ * the key events to the launcher, which keeps track of the text,
+ * calls setQuery() to show it, and gives it to the search dialog.
+ */
+ public void setQuery(String query) {
+ mSearchText.setText(query, TextView.BufferType.NORMAL);
+ }
+
+ /**
+ * Morph the search gadget to the search dialog.
+ * See {@link Activity#startSearch()} for the arguments.
+ */
+ public void startSearch(String initialQuery, boolean selectInitialQuery,
+ Bundle appSearchData, boolean globalSearch) {
+ mInitialQuery = initialQuery;
+ mSelectInitialQuery = selectInitialQuery;
+ mAppSearchData = appSearchData;
+ mGlobalSearch = globalSearch;
+
+ if (isAtTop()) {
+ showSearchDialog();
+ } else {
+ // Call up the keyboard before we actually call the search dialog so that it
+ // (hopefully) animates in at about the same time as the widget animation, and
+ // so that it becomes available as soon as possible. Only do this if a hard
+ // keyboard is not currently available.
+ if (getContext().getResources().getConfiguration().hardKeyboardHidden ==
+ Configuration.HARDKEYBOARDHIDDEN_YES) {
+ InputMethodManager inputManager = (InputMethodManager)
+ getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
+ inputManager.showSoftInputUnchecked(0, null);
+ }
+
+ // Start the animation, unless it has already started.
+ if (getAnimation() != mMorphAnimation) {
+ mMorphAnimation.setDuration(getAnimationDuration());
+ startAnimation(mMorphAnimation);
+ }
+ }
+ }
+
+ /**
+ * Shows the system search dialog immediately, without any animation.
+ */
+ private void showSearchDialog() {
+ mLauncher.showSearchDialog(
+ mInitialQuery, mSelectInitialQuery, mAppSearchData, mGlobalSearch);
+ }
+
+ /**
+ * Restore the search gadget to its normal position.
+ *
+ * @param animate Whether to animate the movement of the gadget.
+ */
+ public void stopSearch(boolean animate) {
+ setQuery("");
+
+ // Only restore if we are not already restored.
+ if (getAnimation() == mMorphAnimation) {
+ if (animate && !isAtTop()) {
+ mUnmorphAnimation.setDuration(getAnimationDuration());
+ startAnimation(mUnmorphAnimation);
+ } else {
+ clearAnimation();
+ }
+ }
+ }
+
+ private boolean isAtTop() {
+ return getWidgetTop() == 0;
+ }
+
+ private int getAnimationDuration() {
+ return (int) (getWidgetTop() / ANIMATION_VELOCITY);
+ }
+
+ /**
+ * Modify clearAnimation() to invalidate the parent. This works around
+ * an issue where the region where the end of the animation placed the view
+ * was not redrawn after clearing the animation.
+ */
+ @Override
+ public void clearAnimation() {
+ Animation animation = getAnimation();
+ if (animation != null) {
+ super.clearAnimation();
+ if (animation.hasEnded()
+ && animation.getFillAfter()
+ && animation.willChangeBounds()) {
+ View parent = (View) getParent();
+ if (parent != null) parent.invalidate();
+ } else {
+ invalidate();
+ }
+ }
+ }
+
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ if (!event.isSystem() &&
+ (keyCode != KeyEvent.KEYCODE_DPAD_UP) &&
+ (keyCode != KeyEvent.KEYCODE_DPAD_DOWN) &&
+ (keyCode != KeyEvent.KEYCODE_DPAD_LEFT) &&
+ (keyCode != KeyEvent.KEYCODE_DPAD_RIGHT) &&
+ (keyCode != KeyEvent.KEYCODE_DPAD_CENTER)) {
+ // Forward key events to Launcher, which will forward text
+ // to search dialog
+ switch (event.getAction()) {
+ case KeyEvent.ACTION_DOWN:
+ return mLauncher.onKeyDown(keyCode, event);
+ case KeyEvent.ACTION_MULTIPLE:
+ return mLauncher.onKeyMultiple(keyCode, event.getRepeatCount(), event);
+ case KeyEvent.ACTION_UP:
+ return mLauncher.onKeyUp(keyCode, event);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Implements OnLongClickListener to pass long clicks on child views
+ * to the widget. This makes it possible to pick up the widget by long
+ * clicking on the text field or a button.
+ */
+ public boolean onLongClick(View v) {
+ return performLongClick();
+ }
+
+ @Override
+ protected void onFinishInflate() {
+ super.onFinishInflate();
+
+ mSearchText = (TextView) findViewById(R.id.search_src_text);
+ mVoiceButton = (ImageButton) findViewById(R.id.search_voice_btn);
+
+ mSearchText.setOnKeyListener(this);
+
+ mSearchText.setOnClickListener(this);
+ mVoiceButton.setOnClickListener(this);
+ setOnClickListener(this);
+
+ mSearchText.setOnLongClickListener(this);
+ mVoiceButton.setOnLongClickListener(this);
+
+ // Set the placeholder text to be the Google logo within the search widget.
+ Drawable googlePlaceholder =
+ getContext().getResources().getDrawable(R.drawable.placeholder_google);
+ mSearchText.setCompoundDrawablesWithIntrinsicBounds(googlePlaceholder, null, null, null);
+
+ configureVoiceSearchButton();
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+ }
+
+ /**
+ * If appropriate & available, configure voice search
+ *
+ * Note: Because the home screen search widget is always web search, we only check for
+ * getVoiceSearchLaunchWebSearch() modes. We don't support the alternate form of app-specific
+ * voice search.
+ */
+ private void configureVoiceSearchButton() {
+ // Enable the voice search button if there is an activity that can handle it
+ PackageManager pm = getContext().getPackageManager();
+ ResolveInfo ri = pm.resolveActivity(mVoiceSearchIntent,
+ PackageManager.MATCH_DEFAULT_ONLY);
+ boolean voiceSearchVisible = ri != null;
+
+ // finally, set visible state of voice search button, as appropriate
+ mVoiceButton.setVisibility(voiceSearchVisible ? View.VISIBLE : View.GONE);
+ }
+
+ /**
+ * Sets the {@link Launcher} that this gadget will call on to display the search dialog.
+ */
+ public void setLauncher(Launcher launcher) {
+ mLauncher = launcher;
+ }
+
+ /**
+ * Moves the view to the top left corner of its parent.
+ */
+ private class ToParentOriginAnimation extends Animation {
+ @Override
+ protected void applyTransformation(float interpolatedTime, Transformation t) {
+ float dx = -getLeft() * interpolatedTime;
+ float dy = -getWidgetTop() * interpolatedTime;
+ t.getMatrix().setTranslate(dx, dy);
+ }
+ }
+
+ /**
+ * Moves the view from the top left corner of its parent.
+ */
+ private class FromParentOriginAnimation extends Animation {
+ @Override
+ protected void applyTransformation(float interpolatedTime, Transformation t) {
+ float dx = -getLeft() * (1.0f - interpolatedTime);
+ float dy = -getWidgetTop() * (1.0f - interpolatedTime);
+ t.getMatrix().setTranslate(dx, dy);
+ }
+ }
+
+ /**
+ * The widget is centered vertically within it's 4x1 slot. This is accomplished by nesting
+ * the actual widget inside another view. For animation purposes, we care about the top of the
+ * actual widget rather than it's container. This method return the top of the actual widget.
+ */
+ private int getWidgetTop() {
+ return getTop() + getChildAt(0).getTop() + mWidgetTopOffset;
+ }
+}
diff --git a/src/com/android/launcher2/SymmetricalLinearTween.java b/src/com/android/launcher2/SymmetricalLinearTween.java
new file mode 100644
index 0000000..2e0ed8f
--- /dev/null
+++ b/src/com/android/launcher2/SymmetricalLinearTween.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2009 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.android.launcher2;
+
+import android.os.Handler;
+import android.os.Message;
+import android.os.SystemClock;
+import android.util.Log;
+
+/**
+ * Provides an animation between 0.0f and 1.0f over a given duration.
+ */
+class SymmetricalLinearTween {
+
+ private static final int FPS = 30;
+ private static final int FRAME_TIME = 1000 / FPS;
+
+ Handler mHandler;
+ int mDuration;
+ TweenCallback mCallback;
+
+ boolean mRunning;
+ long mBase;
+ boolean mDirection;
+ float mValue;
+
+ /**
+ * @param duration milliseconds duration
+ * @param callback callbacks
+ */
+ public SymmetricalLinearTween(boolean initial, int duration, TweenCallback callback) {
+ mValue = initial ? 1.0f : 0.0f;
+ mDirection = initial;
+ mDuration = duration;
+ mCallback = callback;
+ mHandler = new Handler();
+ }
+
+ /**
+ * Starts the tweening.
+ *
+ * @param direction If direction is true, the value goes towards 1.0f. If direction
+ * is false, the value goes towards 0.0f.
+ */
+ public void start(boolean direction) {
+ start(direction, SystemClock.uptimeMillis());
+ }
+
+ /**
+ * Starts the tweening.
+ *
+ * @param direction If direction is true, the value goes towards 1.0f. If direction
+ * is false, the value goes towards 0.0f.
+ * @param baseTime The time to use as zero for this animation, in the
+ * {@link SystemClock.uptimeMillis} time base. This allows you to
+ * synchronize multiple animations.
+ */
+ public void start(boolean direction, long baseTime) {
+ if (direction != mDirection) {
+ if (!mRunning) {
+ mBase = baseTime;
+ mRunning = true;
+ mCallback.onTweenStarted();
+ long next = SystemClock.uptimeMillis() + FRAME_TIME;
+ mHandler.postAtTime(mTick, next);
+ } else {
+ // reverse direction
+ long now = SystemClock.uptimeMillis();
+ long diff = now - mBase;
+ mBase = now + diff - mDuration;
+ }
+ mDirection = direction;
+ }
+ }
+
+ Runnable mTick = new Runnable() {
+ public void run() {
+ long base = mBase;
+ long now = SystemClock.uptimeMillis();
+ long diff = now-base;
+ int duration = mDuration;
+ float val = diff/(float)duration;
+ if (!mDirection) {
+ val = 1.0f - val;
+ }
+ if (val > 1.0f) {
+ val = 1.0f;
+ } else if (val < 0.0f) {
+ val = 0.0f;
+ }
+ float old = mValue;
+ mValue = val;
+ mCallback.onTweenValueChanged(val, old);
+ int frame = (int)(diff / FRAME_TIME);
+ long next = base + ((frame+1)*FRAME_TIME);
+ if (diff < duration) {
+ mHandler.postAtTime(this, next);
+ }
+ if (diff >= duration) {
+ mCallback.onTweenFinished();
+ mRunning = false;
+ }
+ }
+ };
+}
+
diff --git a/src/com/android/launcher2/TweenCallback.java b/src/com/android/launcher2/TweenCallback.java
new file mode 100644
index 0000000..380a217
--- /dev/null
+++ b/src/com/android/launcher2/TweenCallback.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2009 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.android.launcher2;
+
+interface TweenCallback {
+ void onTweenValueChanged(float value, float oldValue);
+ void onTweenStarted();
+ void onTweenFinished();
+}
+
diff --git a/src/com/android/launcher2/UninstallShortcutReceiver.java b/src/com/android/launcher2/UninstallShortcutReceiver.java
new file mode 100644
index 0000000..e65c6a0
--- /dev/null
+++ b/src/com/android/launcher2/UninstallShortcutReceiver.java
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ContentResolver;
+import android.database.Cursor;
+import android.net.Uri;
+import android.widget.Toast;
+
+import java.net.URISyntaxException;
+
+public class UninstallShortcutReceiver extends BroadcastReceiver {
+ private static final String ACTION_UNINSTALL_SHORTCUT =
+ "com.android.launcher.action.UNINSTALL_SHORTCUT";
+
+ public void onReceive(Context context, Intent data) {
+ if (!ACTION_UNINSTALL_SHORTCUT.equals(data.getAction())) {
+ return;
+ }
+
+ Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
+ String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
+ boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
+
+ if (intent != null && name != null) {
+ final ContentResolver cr = context.getContentResolver();
+ Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
+ new String[] { LauncherSettings.Favorites._ID, LauncherSettings.Favorites.INTENT },
+ LauncherSettings.Favorites.TITLE + "=?", new String[] { name }, null);
+
+ final int intentIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
+ final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);
+
+ boolean changed = false;
+
+ try {
+ while (c.moveToNext()) {
+ try {
+ if (intent.filterEquals(Intent.parseUri(c.getString(intentIndex), 0))) {
+ final long id = c.getLong(idIndex);
+ final Uri uri = LauncherSettings.Favorites.getContentUri(id, false);
+ cr.delete(uri, null, null);
+ changed = true;
+ if (!duplicate) {
+ break;
+ }
+ }
+ } catch (URISyntaxException e) {
+ // Ignore
+ }
+ }
+ } finally {
+ c.close();
+ }
+
+ if (changed) {
+ cr.notifyChange(LauncherSettings.Favorites.CONTENT_URI, null);
+ Toast.makeText(context, context.getString(R.string.shortcut_uninstalled, name),
+ Toast.LENGTH_SHORT).show();
+ }
+ }
+ }
+}
diff --git a/src/com/android/launcher2/UserFolder.java b/src/com/android/launcher2/UserFolder.java
new file mode 100644
index 0000000..16fe616
--- /dev/null
+++ b/src/com/android/launcher2/UserFolder.java
@@ -0,0 +1,93 @@
+package com.android.launcher2;
+
+import android.content.Context;
+import android.graphics.Rect;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.ArrayAdapter;
+
+/**
+ * Folder which contains applications or shortcuts chosen by the user.
+ *
+ */
+public class UserFolder extends Folder implements DropTarget {
+ private static final String TAG = "Launcher.UserFolder";
+
+ public UserFolder(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ /**
+ * Creates a new UserFolder, inflated from R.layout.user_folder.
+ *
+ * @param context The application's context.
+ *
+ * @return A new UserFolder.
+ */
+ static UserFolder fromXml(Context context) {
+ return (UserFolder) LayoutInflater.from(context).inflate(R.layout.user_folder, null);
+ }
+
+ public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ final ItemInfo item = (ItemInfo) dragInfo;
+ final int itemType = item.itemType;
+ return (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
+ itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
+ && item.container != mInfo.id;
+ }
+
+ public Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo, Rect recycle) {
+ return null;
+ }
+
+ public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ ApplicationInfo item = (ApplicationInfo) dragInfo;
+ if (item.container == NO_ID) {
+ // Came from all apps -- make a copy
+ item = new ApplicationInfo((ApplicationInfo)item);
+ }
+ //noinspection unchecked
+ ((ArrayAdapter<ApplicationInfo>) mContent.getAdapter()).add((ApplicationInfo) dragInfo);
+ LauncherModel.addOrMoveItemInDatabase(mLauncher, item, mInfo.id, 0, 0, 0);
+ }
+
+ public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+
+ public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+
+ public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+
+ @Override
+ public void onDropCompleted(View target, boolean success) {
+ if (success) {
+ //noinspection unchecked
+ ArrayAdapter<ApplicationInfo> adapter =
+ (ArrayAdapter<ApplicationInfo>) mContent.getAdapter();
+ adapter.remove(mDragItem);
+ }
+ }
+
+ void bind(FolderInfo info) {
+ super.bind(info);
+ setContentAdapter(new ApplicationsAdapter(mContext, ((UserFolderInfo) info).contents));
+ }
+
+ // When the folder opens, we need to refresh the GridView's selection by
+ // forcing a layout
+ @Override
+ void onOpen() {
+ super.onOpen();
+ requestFocus();
+ }
+}
diff --git a/src/com/android/launcher2/UserFolderInfo.java b/src/com/android/launcher2/UserFolderInfo.java
new file mode 100644
index 0000000..75b19ee
--- /dev/null
+++ b/src/com/android/launcher2/UserFolderInfo.java
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.ContentValues;
+
+import java.util.ArrayList;
+
+/**
+ * Represents a folder containing shortcuts or apps.
+ */
+class UserFolderInfo extends FolderInfo {
+ /**
+ * The apps and shortcuts
+ */
+ ArrayList<ApplicationInfo> contents = new ArrayList<ApplicationInfo>();
+
+ UserFolderInfo() {
+ itemType = LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER;
+ }
+
+ /**
+ * Add an app or shortcut
+ *
+ * @param item
+ */
+ public void add(ApplicationInfo item) {
+ contents.add(item);
+ }
+
+ /**
+ * Remove an app or shortcut. Does not change the DB.
+ *
+ * @param item
+ */
+ public void remove(ApplicationInfo item) {
+ contents.remove(item);
+ }
+
+ @Override
+ void onAddToDatabase(ContentValues values) {
+ super.onAddToDatabase(values);
+ values.put(LauncherSettings.Favorites.TITLE, title.toString());
+ }
+}
diff --git a/src/com/android/launcher2/Utilities.java b/src/com/android/launcher2/Utilities.java
new file mode 100644
index 0000000..2dfba43
--- /dev/null
+++ b/src/com/android/launcher2/Utilities.java
@@ -0,0 +1,522 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.PaintDrawable;
+import android.graphics.Bitmap;
+import android.graphics.BlurMaskFilter;
+import android.graphics.Canvas;
+import android.graphics.MaskFilter;
+import android.graphics.Paint;
+import android.graphics.PaintFlagsDrawFilter;
+import android.graphics.PixelFormat;
+import android.graphics.PorterDuff;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.TableMaskFilter;
+import android.graphics.Typeface;
+import android.text.Layout.Alignment;
+import android.text.StaticLayout;
+import android.text.TextPaint;
+import android.util.DisplayMetrics;
+import android.util.Log;
+import android.content.res.Resources;
+import android.content.Context;
+
+/**
+ * Various utilities shared amongst the Launcher's classes.
+ */
+final class Utilities {
+ private static final String TAG = "Launcher.Utilities";
+
+ private static final boolean TEXT_BURN = false;
+
+ private static int sIconWidth = -1;
+ private static int sIconHeight = -1;
+ private static int sIconTextureWidth = -1;
+ private static int sIconTextureHeight = -1;
+
+ private static int sTitleMargin = -1;
+ private static float sBlurRadius = -1;
+ private static Rect sIconTextureRect;
+
+ private static final Paint sPaint = new Paint();
+ private static final Paint sBlurPaint = new Paint();
+ private static final Paint sGlowColorPressedPaint = new Paint();
+ private static final Paint sGlowColorFocusedPaint = new Paint();
+ private static final Paint sEmptyPaint = new Paint();
+ private static final Rect sBounds = new Rect();
+ private static final Rect sOldBounds = new Rect();
+ private static final Canvas sCanvas = new Canvas();
+
+ static {
+ sCanvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG,
+ Paint.FILTER_BITMAP_FLAG));
+ }
+
+ static Bitmap centerToFit(Bitmap bitmap, int width, int height, Context context) {
+ final int bitmapWidth = bitmap.getWidth();
+ final int bitmapHeight = bitmap.getHeight();
+
+ if (bitmapWidth < width || bitmapHeight < height) {
+ int color = context.getResources().getColor(R.color.window_background);
+
+ Bitmap centered = Bitmap.createBitmap(bitmapWidth < width ? width : bitmapWidth,
+ bitmapHeight < height ? height : bitmapHeight, Bitmap.Config.RGB_565);
+ centered.setDensity(bitmap.getDensity());
+ Canvas canvas = new Canvas(centered);
+ canvas.drawColor(color);
+ canvas.drawBitmap(bitmap, (width - bitmapWidth) / 2.0f, (height - bitmapHeight) / 2.0f,
+ null);
+
+ bitmap = centered;
+ }
+
+ return bitmap;
+ }
+
+ /**
+ * Returns a Drawable representing the thumbnail of the specified Drawable.
+ * The size of the thumbnail is defined by the dimension
+ * android.R.dimen.launcher_application_icon_size.
+ *
+ * @param icon The icon to get a thumbnail of.
+ * @param context The application's context.
+ *
+ * @return A thumbnail for the specified icon or the icon itself if the
+ * thumbnail could not be created.
+ */
+ static Drawable createIconThumbnail(Drawable icon, Context context) {
+ synchronized (sCanvas) { // we share the statics :-(
+ if (sIconWidth == -1) {
+ initStatics(context);
+ }
+
+ int width = sIconWidth;
+ int height = sIconHeight;
+
+ if (icon instanceof PaintDrawable) {
+ PaintDrawable painter = (PaintDrawable) icon;
+ painter.setIntrinsicWidth(width);
+ painter.setIntrinsicHeight(height);
+ } else if (icon instanceof BitmapDrawable) {
+ // Ensure the bitmap has a density.
+ BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
+ Bitmap bitmap = bitmapDrawable.getBitmap();
+ if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
+ bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
+ }
+ }
+ int iconWidth = icon.getIntrinsicWidth();
+ int iconHeight = icon.getIntrinsicHeight();
+
+ if (iconWidth > 0 && iconHeight > 0) {
+ if (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(sIconWidth, sIconHeight, c);
+ final Canvas canvas = sCanvas;
+ canvas.setBitmap(thumb);
+ // 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
+ sOldBounds.set(icon.getBounds());
+ final int x = (sIconWidth - width) / 2;
+ final int y = (sIconHeight - height) / 2;
+ icon.setBounds(x, y, x + width, y + height);
+ icon.draw(canvas);
+ icon.setBounds(sOldBounds);
+ icon = new FastBitmapDrawable(thumb);
+ } else if (iconWidth < width && iconHeight < height) {
+ final Bitmap.Config c = Bitmap.Config.ARGB_8888;
+ final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
+ final Canvas canvas = sCanvas;
+ canvas.setBitmap(thumb);
+ sOldBounds.set(icon.getBounds());
+ final int x = (width - iconWidth) / 2;
+ final int y = (height - iconHeight) / 2;
+ icon.setBounds(x, y, x + iconWidth, y + iconHeight);
+ icon.draw(canvas);
+ icon.setBounds(sOldBounds);
+ icon = new FastBitmapDrawable(thumb);
+ }
+ }
+
+ return icon;
+ }
+ }
+
+ static int sColors[] = { 0xffff0000, 0xff00ff00, 0xff0000ff };
+ static int sColorIndex = 0;
+
+ /**
+ * Returns a bitmap suitable for the all apps view. The bitmap will be a power
+ * of two sized ARGB_8888 bitmap that can be used as a gl texture.
+ */
+ static Bitmap createAllAppsBitmap(Drawable icon, String title, BubbleText bubble,
+ Context context) {
+ synchronized (sCanvas) { // we share the statics :-(
+ if (sIconWidth == -1) {
+ initStatics(context);
+ }
+
+ int width = sIconWidth;
+ int height = sIconHeight;
+
+ if (icon instanceof PaintDrawable) {
+ PaintDrawable painter = (PaintDrawable) icon;
+ painter.setIntrinsicWidth(width);
+ painter.setIntrinsicHeight(height);
+ } else if (icon instanceof BitmapDrawable) {
+ // Ensure the bitmap has a density.
+ BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
+ Bitmap bitmap = bitmapDrawable.getBitmap();
+ if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
+ bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
+ }
+ }
+ int sourceWidth = icon.getIntrinsicWidth();
+ int sourceHeight = icon.getIntrinsicHeight();
+
+ if (sourceWidth > 0 && sourceWidth > 0) {
+ // There are intrinsic sizes.
+ if (width < sourceWidth || height < sourceHeight) {
+ // It's too big, scale it down.
+ final float ratio = (float) sourceWidth / sourceHeight;
+ if (sourceWidth > sourceHeight) {
+ height = (int) (width / ratio);
+ } else if (sourceHeight > sourceWidth) {
+ width = (int) (height * ratio);
+ }
+ } else if (sourceWidth < width && sourceHeight < height) {
+ // It's small, use the size they gave us.
+ width = sourceWidth;
+ height = sourceHeight;
+ }
+ }
+
+ // no intrinsic size --> use default size
+ final int textureWidth = sIconTextureWidth;
+ final int textureHeight = sIconTextureHeight;
+
+ final Bitmap bitmap = Bitmap.createBitmap(textureWidth, textureHeight,
+ Bitmap.Config.ARGB_8888);
+ final Canvas canvas = sCanvas;
+ canvas.setBitmap(bitmap);
+
+ final int left = (textureWidth-width) / 2;
+ final int top = sIconTextureRect.top;
+
+ if (false) {
+ // draw a big box for the icon for debugging
+ canvas.drawColor(sColors[sColorIndex]);
+ if (++sColorIndex >= sColors.length) sColorIndex = 0;
+ Paint debugPaint = new Paint();
+ debugPaint.setColor(0xffcccc00);
+ canvas.drawRect(left, top, left+width, top+height, debugPaint);
+ }
+
+ sOldBounds.set(icon.getBounds());
+ icon.setBounds(left, top, left+width, top+height);
+ icon.draw(canvas);
+ icon.setBounds(sOldBounds);
+
+ if (title != null) {
+ bubble.drawText(canvas, title);
+ }
+
+ return bitmap;
+ }
+ }
+
+ static Bitmap extractIconFromTexture(Bitmap src, Context context) {
+ synchronized (sCanvas) { // we share the statics :-(
+ if (sIconWidth == -1) {
+ initStatics(context);
+ }
+ final Bitmap bitmap = Bitmap.createBitmap(sIconWidth, sIconHeight,
+ Bitmap.Config.ARGB_8888);
+ final Canvas canvas = sCanvas;
+ canvas.setBitmap(bitmap);
+
+ Rect r = new Rect(0, 0, sIconWidth, sIconHeight);
+ canvas.drawColor(0, PorterDuff.Mode.CLEAR);
+ canvas.drawBitmap(src, sIconTextureRect, r, sEmptyPaint);
+
+ return bitmap;
+ }
+ }
+
+ static void drawSelectedAllAppsBitmap(Canvas dest, Bitmap destBitmap,
+ int destWidth, int destHeight, boolean pressed, Bitmap src) {
+ synchronized (sCanvas) { // we share the statics :-(
+ if (sIconWidth == -1) {
+ // We can't have gotten to here without src being initialized, which
+ // comes from this file already. So just assert.
+ //initStatics(context);
+ throw new RuntimeException("Assertion failed: Utilities not initialized");
+ }
+
+ dest.drawColor(0, PorterDuff.Mode.CLEAR);
+ dest.drawBitmap(src, sIconTextureRect, sIconTextureRect, sEmptyPaint);
+
+ int[] xy = new int[2];
+ Bitmap mask = destBitmap.extractAlpha(sBlurPaint, xy);
+
+ float px = (destWidth - src.getWidth()) / 2;
+ float py = (destHeight - src.getHeight()) / 2;
+ dest.drawColor(0, PorterDuff.Mode.CLEAR);
+ dest.drawBitmap(mask, px + xy[0], py + xy[1],
+ pressed ? sGlowColorPressedPaint : sGlowColorFocusedPaint);
+
+ mask.recycle();
+ }
+ }
+
+ /**
+ * Returns a Bitmap representing the thumbnail of the specified Bitmap.
+ * The size of the thumbnail is defined by the dimension
+ * android.R.dimen.launcher_application_icon_size.
+ *
+ * @param bitmap The bitmap to get a thumbnail of.
+ * @param context The application's context.
+ *
+ * @return A thumbnail for the specified bitmap or the bitmap itself if the
+ * thumbnail could not be created.
+ */
+ static Bitmap createBitmapThumbnail(Bitmap bitmap, Context context) {
+ synchronized (sCanvas) { // we share the statics :-(
+ if (sIconWidth == -1) {
+ initStatics(context);
+ }
+
+ int width = sIconWidth;
+ int height = sIconHeight;
+
+ final int bitmapWidth = bitmap.getWidth();
+ final int bitmapHeight = bitmap.getHeight();
+
+ if (width > 0 && height > 0) {
+ if (width < bitmapWidth || height < bitmapHeight) {
+ final float ratio = (float) bitmapWidth / bitmapHeight;
+
+ if (bitmapWidth > bitmapHeight) {
+ height = (int) (width / ratio);
+ } else if (bitmapHeight > bitmapWidth) {
+ width = (int) (height * ratio);
+ }
+
+ final Bitmap.Config c = (width == sIconWidth && height == sIconHeight) ?
+ bitmap.getConfig() : Bitmap.Config.ARGB_8888;
+ final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
+ final Canvas canvas = sCanvas;
+ final Paint paint = sPaint;
+ canvas.setBitmap(thumb);
+ paint.setDither(false);
+ paint.setFilterBitmap(true);
+ sBounds.set((sIconWidth - width) / 2, (sIconHeight - height) / 2, width, height);
+ sOldBounds.set(0, 0, bitmapWidth, bitmapHeight);
+ canvas.drawBitmap(bitmap, sOldBounds, sBounds, paint);
+ return thumb;
+ } else if (bitmapWidth < width || bitmapHeight < height) {
+ final Bitmap.Config c = Bitmap.Config.ARGB_8888;
+ final Bitmap thumb = Bitmap.createBitmap(sIconWidth, sIconHeight, c);
+ final Canvas canvas = sCanvas;
+ final Paint paint = sPaint;
+ canvas.setBitmap(thumb);
+ paint.setDither(false);
+ paint.setFilterBitmap(true);
+ canvas.drawBitmap(bitmap, (sIconWidth - bitmapWidth) / 2,
+ (sIconHeight - bitmapHeight) / 2, paint);
+ return thumb;
+ }
+ }
+
+ return bitmap;
+ }
+ }
+
+ private static void initStatics(Context context) {
+ final Resources resources = context.getResources();
+ final DisplayMetrics metrics = resources.getDisplayMetrics();
+ final float density = metrics.density;
+
+ sIconWidth = sIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size);
+ sIconTextureWidth = sIconTextureHeight = roundToPow2(sIconWidth);
+
+ sTitleMargin = (int)(1 * density);
+ sBlurRadius = 5 * density;
+ final int left = (sIconTextureWidth-sIconWidth)/2;
+ final int top = (int)(sBlurRadius) + 1;
+ sIconTextureRect = new Rect(left, top, left+sIconWidth, top+sIconHeight);
+
+ sBlurPaint.setMaskFilter(new BlurMaskFilter(5 * density, BlurMaskFilter.Blur.NORMAL));
+ sGlowColorPressedPaint.setColor(0xffffc300);
+ sGlowColorPressedPaint.setMaskFilter(TableMaskFilter.CreateClipTable(0, 30));
+ sGlowColorFocusedPaint.setColor(0xffff8e00);
+ sGlowColorFocusedPaint.setMaskFilter(TableMaskFilter.CreateClipTable(0, 30));
+ }
+
+ static class BubbleText {
+ private static final int MAX_LINES = 2;
+ private TextPaint mTextPaint;
+
+ private float mBubblePadding;
+ private RectF mBubbleRect = new RectF();
+
+ private float mTextWidth;
+ private int mLeading;
+ private int mFirstLineY;
+ private int mLineHeight;
+
+ private int mBitmapWidth;
+ private int mBitmapHeight;
+
+ BubbleText(Context context) {
+ synchronized (sCanvas) { // we share the statics :-(
+ if (sIconWidth == -1) {
+ initStatics(context);
+ }
+ final Resources resources = context.getResources();
+
+ final float scale = resources.getDisplayMetrics().density;
+
+ final float paddingLeft = 5.0f * scale;
+ final float paddingRight = 5.0f * scale;
+ final float cellWidth = resources.getDimension(R.dimen.workspace_cell_width);
+ final float bubbleWidth = cellWidth - paddingLeft - paddingRight;
+ mBubblePadding = 3.0f * scale;
+
+ RectF bubbleRect = mBubbleRect;
+ bubbleRect.left = 0;
+ bubbleRect.top = 0;
+ bubbleRect.right = (int)(bubbleWidth+0.5f);
+
+ mTextWidth = bubbleWidth - mBubblePadding - mBubblePadding;
+
+ Paint rectPaint = new Paint();
+ rectPaint.setColor(0xff000000);
+ rectPaint.setAntiAlias(true);
+
+ TextPaint textPaint = mTextPaint = new TextPaint();
+ textPaint.setTypeface(Typeface.DEFAULT);
+ textPaint.setTextSize(13*scale);
+ //textPaint.setColor(0xff00ff00);
+ textPaint.setColor(0xffffffff);
+ textPaint.setAntiAlias(true);
+ if (TEXT_BURN) {
+ textPaint.setShadowLayer(8, 0, 0, 0xff000000);
+ }
+
+ final int iconTop = (int)(sBlurRadius) + 1;
+ final int iconBottom = iconTop + sIconHeight;
+
+ float ascent = -textPaint.ascent();
+ float descent = textPaint.descent();
+ float leading = -1.0f;//(ascent+descent) * 0.1f;
+ mLeading = (int)(leading + 0.5f);
+ mFirstLineY = (int)(iconBottom + sTitleMargin + ascent + 0.5f);
+ mLineHeight = (int)(leading + ascent + descent + 0.5f);
+
+ mBitmapWidth = roundToPow2((int)(mBubbleRect.width() + 0.5f));
+ mBitmapHeight = roundToPow2((int)((MAX_LINES * mLineHeight) + leading + 0.5f));
+
+ mBubbleRect.offsetTo((mBitmapWidth-mBubbleRect.width())/2, 0);
+
+ if (false) {
+ Log.d(TAG, "mBitmapWidth=" + mBitmapWidth + " mBitmapHeight="
+ + mBitmapHeight + " w=" + ((int)(mBubbleRect.width() + 0.5f))
+ + " h=" + ((int)((MAX_LINES * mLineHeight) + leading + 0.5f)));
+ }
+ }
+ }
+
+ void drawText(Canvas c, String text) {
+ StaticLayout layout = new StaticLayout(text, mTextPaint, (int)mTextWidth,
+ Alignment.ALIGN_CENTER, 1, 0, true);
+ int lineCount = layout.getLineCount();
+ if (lineCount > MAX_LINES) {
+ lineCount = MAX_LINES;
+ }
+ //if (!TEXT_BURN && lineCount > 0) {
+ //RectF bubbleRect = mBubbleRect;
+ //bubbleRect.bottom = height(lineCount);
+ //c.drawRoundRect(bubbleRect, mCornerRadius, mCornerRadius, mRectPaint);
+ //}
+ for (int i=0; i<lineCount; i++) {
+ //int x = (int)((mBubbleRect.width() - layout.getLineMax(i)) / 2.0f);
+ //int y = mFirstLineY + (i * mLineHeight);
+ int x = (int)(mBubbleRect.left
+ + ((mBubbleRect.width() - layout.getLineMax(i)) / 2.0f));
+ int y = mFirstLineY + (i * mLineHeight);
+ c.drawText(text.substring(layout.getLineStart(i), layout.getLineEnd(i)),
+ x, y, mTextPaint);
+ }
+ }
+
+ private int height(int lineCount) {
+ return (int)((lineCount * mLineHeight) + mLeading + mLeading + 0.0f);
+ }
+
+ int getBubbleWidth() {
+ return (int)(mBubbleRect.width() + 0.5f);
+ }
+
+ int getMaxBubbleHeight() {
+ return height(MAX_LINES);
+ }
+
+ int getBitmapWidth() {
+ return mBitmapWidth;
+ }
+
+ int getBitmapHeight() {
+ return mBitmapHeight;
+ }
+ }
+
+ /** Only works for positive numbers. */
+ static int roundToPow2(int n) {
+ int orig = n;
+ n >>= 1;
+ int mask = 0x8000000;
+ while (mask != 0 && (n & mask) == 0) {
+ mask >>= 1;
+ }
+ while (mask != 0) {
+ n |= mask;
+ mask >>= 1;
+ }
+ n += 1;
+ if (n != orig) {
+ n <<= 1;
+ }
+ return n;
+ }
+}
diff --git a/src/com/android/launcher2/WallpaperChooser.java b/src/com/android/launcher2/WallpaperChooser.java
new file mode 100644
index 0000000..8045059
--- /dev/null
+++ b/src/com/android/launcher2/WallpaperChooser.java
@@ -0,0 +1,244 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.app.Activity;
+import android.app.WallpaperManager;
+import android.content.res.Resources;
+import android.graphics.BitmapFactory;
+import android.graphics.Bitmap;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.os.AsyncTask;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.BaseAdapter;
+import android.widget.Gallery;
+import android.widget.ImageView;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public class WallpaperChooser extends Activity implements AdapterView.OnItemSelectedListener,
+ OnClickListener {
+ private static final String TAG = "Launcher.WallpaperChooser";
+
+ private Gallery mGallery;
+ private ImageView mImageView;
+ private boolean mIsWallpaperSet;
+
+ private Bitmap mBitmap;
+
+ private ArrayList<Integer> mThumbs;
+ private ArrayList<Integer> mImages;
+ private WallpaperLoader mLoader;
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+
+ findWallpapers();
+
+ setContentView(R.layout.wallpaper_chooser);
+
+ mGallery = (Gallery) findViewById(R.id.gallery);
+ mGallery.setAdapter(new ImageAdapter(this));
+ mGallery.setOnItemSelectedListener(this);
+ mGallery.setCallbackDuringFling(false);
+
+ findViewById(R.id.set).setOnClickListener(this);
+
+ mImageView = (ImageView) findViewById(R.id.wallpaper);
+ }
+
+ private void findWallpapers() {
+ mThumbs = new ArrayList<Integer>(24);
+ mImages = new ArrayList<Integer>(24);
+
+ final Resources resources = getResources();
+ final String packageName = getApplication().getPackageName();
+
+ addWallpapers(resources, packageName, R.array.wallpapers);
+ addWallpapers(resources, packageName, R.array.extra_wallpapers);
+ }
+
+ private void addWallpapers(Resources resources, String packageName, int list) {
+ final String[] extras = resources.getStringArray(list);
+ for (String extra : extras) {
+ int res = resources.getIdentifier(extra, "drawable", packageName);
+ if (res != 0) {
+ final int thumbRes = resources.getIdentifier(extra + "_small",
+ "drawable", packageName);
+
+ if (thumbRes != 0) {
+ mThumbs.add(thumbRes);
+ mImages.add(res);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ mIsWallpaperSet = false;
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ if (mLoader != null && mLoader.getStatus() != WallpaperLoader.Status.FINISHED) {
+ mLoader.cancel(true);
+ mLoader = null;
+ }
+ }
+
+ public void onItemSelected(AdapterView parent, View v, int position, long id) {
+ if (mLoader != null && mLoader.getStatus() != WallpaperLoader.Status.FINISHED) {
+ mLoader.cancel();
+ }
+ mLoader = (WallpaperLoader) new WallpaperLoader().execute(position);
+ }
+
+ /*
+ * When using touch if you tap an image it triggers both the onItemClick and
+ * the onTouchEvent causing the wallpaper to be set twice. Ensure we only
+ * set the wallpaper once.
+ */
+ private void selectWallpaper(int position) {
+ if (mIsWallpaperSet) {
+ return;
+ }
+
+ mIsWallpaperSet = true;
+ try {
+ WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
+ wpm.setResource(mImages.get(position));
+ setResult(RESULT_OK);
+ finish();
+ } catch (IOException e) {
+ Log.e(TAG, "Failed to set wallpaper: " + e);
+ }
+ }
+
+ public void onNothingSelected(AdapterView parent) {
+ }
+
+ private class ImageAdapter extends BaseAdapter {
+ private LayoutInflater mLayoutInflater;
+
+ ImageAdapter(WallpaperChooser context) {
+ mLayoutInflater = context.getLayoutInflater();
+ }
+
+ public int getCount() {
+ return mThumbs.size();
+ }
+
+ public Object getItem(int position) {
+ return position;
+ }
+
+ public long getItemId(int position) {
+ return position;
+ }
+
+ public View getView(int position, View convertView, ViewGroup parent) {
+ ImageView image;
+
+ if (convertView == null) {
+ image = (ImageView) mLayoutInflater.inflate(R.layout.wallpaper_item, parent, false);
+ } else {
+ image = (ImageView) convertView;
+ }
+
+ int thumbRes = mThumbs.get(position);
+ image.setImageResource(thumbRes);
+ Drawable thumbDrawable = image.getDrawable();
+ if (thumbDrawable != null) {
+ thumbDrawable.setDither(true);
+ } else {
+ Log.e(TAG, "Error decoding thumbnail resId=" + thumbRes + " for wallpaper #"
+ + position);
+ }
+ return image;
+ }
+ }
+
+ public void onClick(View v) {
+ selectWallpaper(mGallery.getSelectedItemPosition());
+ }
+
+ class WallpaperLoader extends AsyncTask<Integer, Void, Bitmap> {
+ BitmapFactory.Options mOptions;
+
+ WallpaperLoader() {
+ mOptions = new BitmapFactory.Options();
+ mOptions.inDither = false;
+ mOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ }
+
+ protected Bitmap doInBackground(Integer... params) {
+ if (isCancelled()) return null;
+ try {
+ return BitmapFactory.decodeResource(getResources(),
+ mImages.get(params[0]), mOptions);
+ } catch (OutOfMemoryError e) {
+ return null;
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Bitmap b) {
+ if (b == null) return;
+
+ if (!isCancelled() && !mOptions.mCancel) {
+ // Help the GC
+ if (mBitmap != null) {
+ mBitmap.recycle();
+ }
+
+ final ImageView view = mImageView;
+ view.setImageBitmap(b);
+
+ mBitmap = b;
+
+ final Drawable drawable = view.getDrawable();
+ drawable.setFilterBitmap(true);
+ drawable.setDither(true);
+
+ view.postInvalidate();
+
+ mLoader = null;
+ } else {
+ b.recycle();
+ }
+ }
+
+ void cancel() {
+ mOptions.requestCancelDecode();
+ super.cancel(true);
+ }
+ }
+}
diff --git a/src/com/android/launcher2/Widget.java b/src/com/android/launcher2/Widget.java
new file mode 100644
index 0000000..348acee
--- /dev/null
+++ b/src/com/android/launcher2/Widget.java
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.content.ContentValues;
+import android.graphics.Bitmap;
+
+/**
+ * Represents one instance of a Launcher widget, such as search.
+ */
+class Widget extends ItemInfo {
+ int layoutResource;
+
+ static Widget makeSearch() {
+ Widget w = new Widget();
+ w.itemType = LauncherSettings.Favorites.ITEM_TYPE_WIDGET_SEARCH;
+ w.spanX = 4;
+ w.spanY = 1;
+ w.layoutResource = R.layout.widget_search;
+ return w;
+ }
+}
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
new file mode 100644
index 0000000..9e32dd5
--- /dev/null
+++ b/src/com/android/launcher2/Workspace.java
@@ -0,0 +1,1475 @@
+/*
+ * 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.
+ */
+
+package com.android.launcher2;
+
+import android.app.WallpaperManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.ComponentName;
+import android.content.res.TypedArray;
+import android.content.pm.PackageManager;
+import android.graphics.Canvas;
+import android.graphics.RectF;
+import android.graphics.Rect;
+import android.graphics.drawable.Drawable;
+import android.os.Parcelable;
+import android.os.Parcel;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.VelocityTracker;
+import android.view.View;
+import android.view.ViewConfiguration;
+import android.view.ViewGroup;
+import android.view.ViewParent;
+import android.widget.Scroller;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+
+/**
+ * The workspace is a wide area with a wallpaper and a finite number of screens. Each
+ * screen contains a number of icons, folders or widgets the user can interact with.
+ * A workspace is meant to be used with a fixed width only.
+ */
+public class Workspace extends ViewGroup implements DropTarget, DragSource, DragScroller {
+ @SuppressWarnings({"UnusedDeclaration"})
+ private static final String TAG = "Launcher.Workspace";
+ private static final int INVALID_SCREEN = -1;
+
+ /**
+ * The velocity at which a fling gesture will cause us to snap to the next screen
+ */
+ private static final int SNAP_VELOCITY = 1000;
+
+ private final WallpaperManager mWallpaperManager;
+
+ private int mDefaultScreen;
+
+ private boolean mFirstLayout = true;
+
+ private int mCurrentScreen;
+ private int mNextScreen = INVALID_SCREEN;
+ private Scroller mScroller;
+ private VelocityTracker mVelocityTracker;
+
+ /**
+ * CellInfo for the cell that is currently being dragged
+ */
+ private CellLayout.CellInfo mDragInfo;
+
+ /**
+ * Target drop area calculated during last acceptDrop call.
+ */
+ private int[] mTargetCell = null;
+
+ private float mLastMotionX;
+ private float mLastMotionY;
+
+ private final static int TOUCH_STATE_REST = 0;
+ private final static int TOUCH_STATE_SCROLLING = 1;
+
+ private int mTouchState = TOUCH_STATE_REST;
+
+ private OnLongClickListener mLongClickListener;
+
+ private Launcher mLauncher;
+ private DragController mDragController;
+
+ /**
+ * Cache of vacant cells, used during drag events and invalidated as needed.
+ */
+ private CellLayout.CellInfo mVacantCache = null;
+
+ private int[] mTempCell = new int[2];
+ private int[] mTempEstimate = new int[2];
+
+ private boolean mAllowLongPress = true;
+
+ private int mTouchSlop;
+ private int mMaximumVelocity;
+
+ final Rect mDrawerBounds = new Rect();
+ final Rect mClipBounds = new Rect();
+ int mDrawerContentHeight;
+ int mDrawerContentWidth;
+
+ private Drawable mPreviousIndicator;
+ private Drawable mNextIndicator;
+
+ private boolean mFading = true;
+
+ /**
+ * Used to inflate the Workspace from XML.
+ *
+ * @param context The application's context.
+ * @param attrs The attribtues set containing the Workspace's customization values.
+ */
+ public Workspace(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ /**
+ * Used to inflate the Workspace from XML.
+ *
+ * @param context The application's context.
+ * @param attrs The attribtues set containing the Workspace's customization values.
+ * @param defStyle Unused.
+ */
+ public Workspace(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+
+ mWallpaperManager = WallpaperManager.getInstance(context);
+
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0);
+ mDefaultScreen = a.getInt(R.styleable.Workspace_defaultScreen, 1);
+ a.recycle();
+
+ setHapticFeedbackEnabled(false);
+ initWorkspace();
+ }
+
+ /**
+ * Initializes various states for this workspace.
+ */
+ private void initWorkspace() {
+ mScroller = new Scroller(getContext());
+ mCurrentScreen = mDefaultScreen;
+ Launcher.setScreen(mCurrentScreen);
+
+ final ViewConfiguration configuration = ViewConfiguration.get(getContext());
+ mTouchSlop = configuration.getScaledTouchSlop();
+ mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
+ }
+
+ @Override
+ public void addView(View child, int index, LayoutParams params) {
+ if (!(child instanceof CellLayout)) {
+ throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
+ }
+ super.addView(child, index, params);
+ }
+
+ @Override
+ public void addView(View child) {
+ if (!(child instanceof CellLayout)) {
+ throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
+ }
+ super.addView(child);
+ }
+
+ @Override
+ public void addView(View child, int index) {
+ if (!(child instanceof CellLayout)) {
+ throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
+ }
+ super.addView(child, index);
+ }
+
+ @Override
+ public void addView(View child, int width, int height) {
+ if (!(child instanceof CellLayout)) {
+ throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
+ }
+ super.addView(child, width, height);
+ }
+
+ @Override
+ public void addView(View child, LayoutParams params) {
+ if (!(child instanceof CellLayout)) {
+ throw new IllegalArgumentException("A Workspace can only have CellLayout children.");
+ }
+ super.addView(child, params);
+ }
+
+ /**
+ * @return The open folder on the current screen, or null if there is none
+ */
+ Folder getOpenFolder() {
+ CellLayout currentScreen = (CellLayout) getChildAt(mCurrentScreen);
+ int count = currentScreen.getChildCount();
+ for (int i = 0; i < count; i++) {
+ View child = currentScreen.getChildAt(i);
+ CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
+ if (lp.cellHSpan == 4 && lp.cellVSpan == 4 && child instanceof Folder) {
+ return (Folder) child;
+ }
+ }
+ return null;
+ }
+
+ ArrayList<Folder> getOpenFolders() {
+ final int screens = getChildCount();
+ ArrayList<Folder> folders = new ArrayList<Folder>(screens);
+
+ for (int screen = 0; screen < screens; screen++) {
+ CellLayout currentScreen = (CellLayout) getChildAt(screen);
+ int count = currentScreen.getChildCount();
+ for (int i = 0; i < count; i++) {
+ View child = currentScreen.getChildAt(i);
+ CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
+ if (lp.cellHSpan == 4 && lp.cellVSpan == 4 && child instanceof Folder) {
+ folders.add((Folder) child);
+ break;
+ }
+ }
+ }
+
+ return folders;
+ }
+
+ boolean isDefaultScreenShowing() {
+ return mCurrentScreen == mDefaultScreen;
+ }
+
+ /**
+ * Returns the index of the currently displayed screen.
+ *
+ * @return The index of the currently displayed screen.
+ */
+ int getCurrentScreen() {
+ return mCurrentScreen;
+ }
+
+ /**
+ * Returns how many screens there are.
+ */
+ int getScreenCount() {
+ return getChildCount();
+ }
+
+ /**
+ * Computes a bounding rectangle for a range of cells
+ *
+ * @param cellX X coordinate of upper left corner expressed as a cell position
+ * @param cellY Y coordinate of upper left corner expressed as a cell position
+ * @param cellHSpan Width in cells
+ * @param cellVSpan Height in cells
+ * @param rect Rectnagle into which to put the results
+ */
+ public void cellToRect(int cellX, int cellY, int cellHSpan, int cellVSpan, RectF rect) {
+ ((CellLayout)getChildAt(mCurrentScreen)).cellToRect(cellX, cellY,
+ cellHSpan, cellVSpan, rect);
+ }
+
+ /**
+ * Sets the current screen.
+ *
+ * @param currentScreen
+ */
+ void setCurrentScreen(int currentScreen) {
+ if (!mScroller.isFinished()) mScroller.abortAnimation();
+ clearVacantCache();
+ mCurrentScreen = Math.max(0, Math.min(currentScreen, getChildCount() - 1));
+ scrollTo(mCurrentScreen * getWidth(), 0);
+ invalidate();
+ }
+
+ /**
+ * Adds the specified child in the current screen. The position and dimension of
+ * the child are defined by x, y, spanX and spanY.
+ *
+ * @param child The child to add in one of the workspace's screens.
+ * @param x The X position of the child in the screen's grid.
+ * @param y The Y position of the child in the screen's grid.
+ * @param spanX The number of cells spanned horizontally by the child.
+ * @param spanY The number of cells spanned vertically by the child.
+ */
+ void addInCurrentScreen(View child, int x, int y, int spanX, int spanY) {
+ addInScreen(child, mCurrentScreen, x, y, spanX, spanY, false);
+ }
+
+ /**
+ * Adds the specified child in the current screen. The position and dimension of
+ * the child are defined by x, y, spanX and spanY.
+ *
+ * @param child The child to add in one of the workspace's screens.
+ * @param x The X position of the child in the screen's grid.
+ * @param y The Y position of the child in the screen's grid.
+ * @param spanX The number of cells spanned horizontally by the child.
+ * @param spanY The number of cells spanned vertically by the child.
+ * @param insert When true, the child is inserted at the beginning of the children list.
+ */
+ void addInCurrentScreen(View child, int x, int y, int spanX, int spanY, boolean insert) {
+ addInScreen(child, mCurrentScreen, x, y, spanX, spanY, insert);
+ }
+
+ /**
+ * Adds the specified child in the specified screen. The position and dimension of
+ * the child are defined by x, y, spanX and spanY.
+ *
+ * @param child The child to add in one of the workspace's screens.
+ * @param screen The screen in which to add the child.
+ * @param x The X position of the child in the screen's grid.
+ * @param y The Y position of the child in the screen's grid.
+ * @param spanX The number of cells spanned horizontally by the child.
+ * @param spanY The number of cells spanned vertically by the child.
+ */
+ void addInScreen(View child, int screen, int x, int y, int spanX, int spanY) {
+ addInScreen(child, screen, x, y, spanX, spanY, false);
+ }
+
+ /**
+ * Adds the specified child in the specified screen. The position and dimension of
+ * the child are defined by x, y, spanX and spanY.
+ *
+ * @param child The child to add in one of the workspace's screens.
+ * @param screen The screen in which to add the child.
+ * @param x The X position of the child in the screen's grid.
+ * @param y The Y position of the child in the screen's grid.
+ * @param spanX The number of cells spanned horizontally by the child.
+ * @param spanY The number of cells spanned vertically by the child.
+ * @param insert When true, the child is inserted at the beginning of the children list.
+ */
+ void addInScreen(View child, int screen, int x, int y, int spanX, int spanY, boolean insert) {
+ if (screen < 0 || screen >= getChildCount()) {
+ throw new IllegalStateException("The screen must be >= 0 and < " + getChildCount());
+ }
+
+ clearVacantCache();
+
+ final CellLayout group = (CellLayout) getChildAt(screen);
+ CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
+ if (lp == null) {
+ lp = new CellLayout.LayoutParams(x, y, spanX, spanY);
+ } else {
+ lp.cellX = x;
+ lp.cellY = y;
+ lp.cellHSpan = spanX;
+ lp.cellVSpan = spanY;
+ }
+ group.addView(child, insert ? 0 : -1, lp);
+ if (!(child instanceof Folder)) {
+ child.setHapticFeedbackEnabled(false);
+ child.setOnLongClickListener(mLongClickListener);
+ }
+ if (child instanceof DropTarget) {
+ mDragController.addDropTarget((DropTarget)child);
+ }
+ }
+
+ void addWidget(View view, Widget widget) {
+ addInScreen(view, widget.screen, widget.cellX, widget.cellY, widget.spanX,
+ widget.spanY, false);
+ }
+
+ void addWidget(View view, Widget widget, boolean insert) {
+ addInScreen(view, widget.screen, widget.cellX, widget.cellY, widget.spanX,
+ widget.spanY, insert);
+ }
+
+ CellLayout.CellInfo findAllVacantCells(boolean[] occupied) {
+ CellLayout group = (CellLayout) getChildAt(mCurrentScreen);
+ if (group != null) {
+ return group.findAllVacantCells(occupied, null);
+ }
+ return null;
+ }
+
+ private void clearVacantCache() {
+ if (mVacantCache != null) {
+ mVacantCache.clearVacantCells();
+ mVacantCache = null;
+ }
+ }
+
+ /**
+ * Returns the coordinate of a vacant cell for the current screen.
+ */
+ boolean getVacantCell(int[] vacant, int spanX, int spanY) {
+ CellLayout group = (CellLayout) getChildAt(mCurrentScreen);
+ if (group != null) {
+ return group.getVacantCell(vacant, spanX, spanY);
+ }
+ return false;
+ }
+
+ /**
+ * Adds the specified child in the current screen. The position and dimension of
+ * the child are defined by x, y, spanX and spanY.
+ *
+ * @param child The child to add in one of the workspace's screens.
+ * @param spanX The number of cells spanned horizontally by the child.
+ * @param spanY The number of cells spanned vertically by the child.
+ */
+ void fitInCurrentScreen(View child, int spanX, int spanY) {
+ fitInScreen(child, mCurrentScreen, spanX, spanY);
+ }
+
+ /**
+ * Adds the specified child in the specified screen. The position and dimension of
+ * the child are defined by x, y, spanX and spanY.
+ *
+ * @param child The child to add in one of the workspace's screens.
+ * @param screen The screen in which to add the child.
+ * @param spanX The number of cells spanned horizontally by the child.
+ * @param spanY The number of cells spanned vertically by the child.
+ */
+ void fitInScreen(View child, int screen, int spanX, int spanY) {
+ if (screen < 0 || screen >= getChildCount()) {
+ throw new IllegalStateException("The screen must be >= 0 and < " + getChildCount());
+ }
+
+ final CellLayout group = (CellLayout) getChildAt(screen);
+ boolean vacant = group.getVacantCell(mTempCell, spanX, spanY);
+ if (vacant) {
+ group.addView(child,
+ new CellLayout.LayoutParams(mTempCell[0], mTempCell[1], spanX, spanY));
+ child.setHapticFeedbackEnabled(false);
+ child.setOnLongClickListener(mLongClickListener);
+ if (child instanceof DropTarget) {
+ mDragController.addDropTarget((DropTarget)child);
+ }
+ }
+ }
+
+ /**
+ * Registers the specified listener on each screen contained in this workspace.
+ *
+ * @param l The listener used to respond to long clicks.
+ */
+ @Override
+ public void setOnLongClickListener(OnLongClickListener l) {
+ mLongClickListener = l;
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ getChildAt(i).setOnLongClickListener(l);
+ }
+ }
+
+ private void updateWallpaperOffset() {
+ updateWallpaperOffset(getChildAt(getChildCount() - 1).getRight() - (mRight - mLeft));
+ }
+
+ private void updateWallpaperOffset(int scrollRange) {
+ mWallpaperManager.setWallpaperOffsetSteps(1.0f / (getChildCount() - 1), 0 );
+ mWallpaperManager.setWallpaperOffsets(getWindowToken(), mScrollX / (float) scrollRange, 0);
+ }
+
+ @Override
+ public void computeScroll() {
+ if (mScroller.computeScrollOffset()) {
+ mScrollX = mScroller.getCurrX();
+ mScrollY = mScroller.getCurrY();
+ updateWallpaperOffset();
+ postInvalidate();
+ } else if (mNextScreen != INVALID_SCREEN) {
+ mCurrentScreen = Math.max(0, Math.min(mNextScreen, getChildCount() - 1));
+ mPreviousIndicator.setLevel(mCurrentScreen);
+ mNextIndicator.setLevel(mCurrentScreen);
+ Launcher.setScreen(mCurrentScreen);
+ mNextScreen = INVALID_SCREEN;
+ clearChildrenCache();
+ }
+ }
+
+ public void startFading(boolean dest) {
+ mFading = dest;
+ invalidate();
+ }
+
+ @Override
+ protected void dispatchDraw(Canvas canvas) {
+ /*
+ final boolean allAppsOpaque = mLauncher.isAllAppsOpaque();
+ if (mFading == allAppsOpaque) {
+ invalidate();
+ } else {
+ mFading = !allAppsOpaque;
+ }
+ if (allAppsOpaque) {
+ // If the launcher is up, draw black.
+ canvas.drawARGB(0xff, 0, 0, 0);
+ return;
+ }
+ */
+
+ boolean restore = false;
+ int restoreCount = 0;
+
+ // For the fade. If view gets setAlpha(), use that instead.
+ float scale = mScale;
+ if (scale < 0.999f) {
+ int sx = mScrollX;
+
+ int alpha = (scale < 0.5f) ? (int)(255 * 2 * scale) : 255;
+
+ restoreCount = canvas.saveLayerAlpha(sx, 0, sx+getWidth(), getHeight(), alpha,
+ Canvas.HAS_ALPHA_LAYER_SAVE_FLAG | Canvas.CLIP_TO_LAYER_SAVE_FLAG);
+ restore = true;
+
+ if (scale < 0.999f) {
+ int w = getWidth();
+ w += 2 * mCurrentScreen * w;
+ int dx = w/2;
+ int h = getHeight();
+ int dy = (h/2) - (h/4);
+ canvas.translate(dx, dy);
+ canvas.scale(scale, scale);
+ canvas.translate(-dx, -dy);
+ }
+ }
+
+ // ViewGroup.dispatchDraw() supports many features we don't need:
+ // clip to padding, layout animation, animation listener, disappearing
+ // children, etc. The following implementation attempts to fast-track
+ // the drawing dispatch by drawing only what we know needs to be drawn.
+
+ boolean fastDraw = mTouchState != TOUCH_STATE_SCROLLING && mNextScreen == INVALID_SCREEN
+ && scale > 0.999f;
+ // If we are not scrolling or flinging, draw only the current screen
+ if (fastDraw) {
+ drawChild(canvas, getChildAt(mCurrentScreen), getDrawingTime());
+ } else {
+ final long drawingTime = getDrawingTime();
+ // If we are flinging, draw only the current screen and the target screen
+ if (mNextScreen >= 0 && mNextScreen < getChildCount() &&
+ Math.abs(mCurrentScreen - mNextScreen) == 1) {
+ drawChild(canvas, getChildAt(mCurrentScreen), drawingTime);
+ drawChild(canvas, getChildAt(mNextScreen), drawingTime);
+ } else {
+ // If we are scrolling, draw all of our children
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ drawChild(canvas, getChildAt(i), drawingTime);
+ }
+ }
+ }
+
+ if (restore) {
+ canvas.restoreToCount(restoreCount);
+ }
+ }
+
+ private float mScale = 1.0f;
+ public void setScale(float scale) {
+ mScale = scale;
+ invalidate();
+ }
+
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ mDragController.setWindowToken(getWindowToken());
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+
+ final int width = MeasureSpec.getSize(widthMeasureSpec);
+ final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
+ if (widthMode != MeasureSpec.EXACTLY) {
+ throw new IllegalStateException("Workspace can only be used in EXACTLY mode.");
+ }
+
+ final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
+ if (heightMode != MeasureSpec.EXACTLY) {
+ throw new IllegalStateException("Workspace can only be used in EXACTLY mode.");
+ }
+
+ // The children are given the same width and height as the workspace
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
+ }
+
+
+ if (mFirstLayout) {
+ setHorizontalScrollBarEnabled(false);
+ scrollTo(mCurrentScreen * width, 0);
+ setHorizontalScrollBarEnabled(true);
+ updateWallpaperOffset(width * (getChildCount() - 1));
+ mFirstLayout = false;
+ }
+ }
+
+ @Override
+ protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+ int childLeft = 0;
+
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ final View child = getChildAt(i);
+ if (child.getVisibility() != View.GONE) {
+ final int childWidth = child.getMeasuredWidth();
+ child.layout(childLeft, 0, childLeft + childWidth, child.getMeasuredHeight());
+ childLeft += childWidth;
+ }
+ }
+ }
+
+ @Override
+ public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
+ int screen = indexOfChild(child);
+ if (screen != mCurrentScreen || !mScroller.isFinished()) {
+ if (!mLauncher.isWorkspaceLocked()) {
+ snapToScreen(screen);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
+ if (!mLauncher.isAllAppsVisible()) {
+ final Folder openFolder = getOpenFolder();
+ if (openFolder != null) {
+ return openFolder.requestFocus(direction, previouslyFocusedRect);
+ } else {
+ int focusableScreen;
+ if (mNextScreen != INVALID_SCREEN) {
+ focusableScreen = mNextScreen;
+ } else {
+ focusableScreen = mCurrentScreen;
+ }
+ getChildAt(focusableScreen).requestFocus(direction, previouslyFocusedRect);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean dispatchUnhandledMove(View focused, int direction) {
+ if (direction == View.FOCUS_LEFT) {
+ if (getCurrentScreen() > 0) {
+ snapToScreen(getCurrentScreen() - 1);
+ return true;
+ }
+ } else if (direction == View.FOCUS_RIGHT) {
+ if (getCurrentScreen() < getChildCount() - 1) {
+ snapToScreen(getCurrentScreen() + 1);
+ return true;
+ }
+ }
+ return super.dispatchUnhandledMove(focused, direction);
+ }
+
+ @Override
+ public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
+ if (!mLauncher.isAllAppsVisible()) {
+ final Folder openFolder = getOpenFolder();
+ if (openFolder == null) {
+ getChildAt(mCurrentScreen).addFocusables(views, direction);
+ if (direction == View.FOCUS_LEFT) {
+ if (mCurrentScreen > 0) {
+ getChildAt(mCurrentScreen - 1).addFocusables(views, direction);
+ }
+ } else if (direction == View.FOCUS_RIGHT){
+ if (mCurrentScreen < getChildCount() - 1) {
+ getChildAt(mCurrentScreen + 1).addFocusables(views, direction);
+ }
+ }
+ } else {
+ openFolder.addFocusables(views, direction);
+ }
+ }
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent ev) {
+ if (ev.getAction() == MotionEvent.ACTION_DOWN) {
+ if (mLauncher.isWorkspaceLocked() || mLauncher.isAllAppsVisible()) {
+ return false;
+ }
+ }
+ return super.dispatchTouchEvent(ev);
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ final boolean workspaceLocked = mLauncher.isWorkspaceLocked();
+ final boolean allAppsVisible = mLauncher.isAllAppsVisible();
+ if (workspaceLocked || allAppsVisible) {
+ return false; // We don't want the events. Let them fall through to the all apps view.
+ }
+
+ /*
+ * This method JUST determines whether we want to intercept the motion.
+ * If we return true, onTouchEvent will be called and we do the actual
+ * scrolling there.
+ */
+
+ /*
+ * Shortcut the most recurring case: the user is in the dragging
+ * state and he is moving his finger. We want to intercept this
+ * motion.
+ */
+ final int action = ev.getAction();
+ if ((action == MotionEvent.ACTION_MOVE) && (mTouchState != TOUCH_STATE_REST)) {
+ return true;
+ }
+
+ final float x = ev.getX();
+ final float y = ev.getY();
+
+ switch (action) {
+ case MotionEvent.ACTION_MOVE:
+ /*
+ * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
+ * whether the user has moved far enough from his original down touch.
+ */
+
+ /*
+ * Locally do absolute value. mLastMotionX is set to the y value
+ * of the down event.
+ */
+ final int xDiff = (int) Math.abs(x - mLastMotionX);
+ final int yDiff = (int) Math.abs(y - mLastMotionY);
+
+ final int touchSlop = mTouchSlop;
+ boolean xMoved = xDiff > touchSlop;
+ boolean yMoved = yDiff > touchSlop;
+
+ if (xMoved || yMoved) {
+
+ if (xMoved) {
+ // Scroll if the user moved far enough along the X axis
+ mTouchState = TOUCH_STATE_SCROLLING;
+ enableChildrenCache(mCurrentScreen - 1, mCurrentScreen + 1);
+ }
+ // Either way, cancel any pending longpress
+ if (mAllowLongPress) {
+ mAllowLongPress = false;
+ // Try canceling the long press. It could also have been scheduled
+ // by a distant descendant, so use the mAllowLongPress flag to block
+ // everything
+ final View currentScreen = getChildAt(mCurrentScreen);
+ currentScreen.cancelLongPress();
+ }
+ }
+ break;
+
+ case MotionEvent.ACTION_DOWN:
+ // Remember location of down touch
+ mLastMotionX = x;
+ mLastMotionY = y;
+ mAllowLongPress = true;
+
+ /*
+ * If being flinged and user touches the screen, initiate drag;
+ * otherwise don't. mScroller.isFinished should be false when
+ * being flinged.
+ */
+ mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
+ break;
+
+ case MotionEvent.ACTION_CANCEL:
+ case MotionEvent.ACTION_UP:
+
+ if (mTouchState != TOUCH_STATE_SCROLLING) {
+
+ final CellLayout currentScreen = (CellLayout)getChildAt(mCurrentScreen);
+ if (!currentScreen.lastDownOnOccupiedCell()) {
+ // Send a tap to the wallpaper if the last down was on empty space
+ mWallpaperManager.sendWallpaperCommand(getWindowToken(),
+ "android.wallpaper.tap", (int) ev.getX(), (int) ev.getY(), 0, null);
+ }
+ }
+
+ // Release the drag
+ clearChildrenCache();
+ mTouchState = TOUCH_STATE_REST;
+ mAllowLongPress = false;
+
+ break;
+ }
+
+ /*
+ * The only time we want to intercept motion events is if we are in the
+ * drag mode.
+ */
+ return mTouchState != TOUCH_STATE_REST;
+ }
+
+ /**
+ * If one of our descendant views decides that it could be focused now, only
+ * pass that along if it's on the current screen.
+ *
+ * This happens when live folders requery, and if they're off screen, they
+ * end up calling requestFocus, which pulls it on screen.
+ */
+ @Override
+ public void focusableViewAvailable(View focused) {
+ View current = getChildAt(mCurrentScreen);
+ View v = focused;
+ while (true) {
+ if (v == current) {
+ super.focusableViewAvailable(focused);
+ return;
+ }
+ if (v == this) {
+ return;
+ }
+ ViewParent parent = v.getParent();
+ if (parent instanceof View) {
+ v = (View)v.getParent();
+ } else {
+ return;
+ }
+ }
+ }
+
+ void enableChildrenCache(int fromScreen, int toScreen) {
+ if (fromScreen > toScreen) {
+ fromScreen = toScreen;
+ toScreen = fromScreen;
+ }
+
+ final int count = getChildCount();
+
+ fromScreen = Math.max(fromScreen, 0);
+ toScreen = Math.min(toScreen, count - 1);
+
+ for (int i = fromScreen; i <= toScreen; i++) {
+ final CellLayout layout = (CellLayout) getChildAt(i);
+ layout.setChildrenDrawnWithCacheEnabled(true);
+ layout.setChildrenDrawingCacheEnabled(true);
+ }
+ }
+
+ void clearChildrenCache() {
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ final CellLayout layout = (CellLayout) getChildAt(i);
+ layout.setChildrenDrawnWithCacheEnabled(false);
+ }
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+
+ if (mLauncher.isWorkspaceLocked()) {
+ return false; // We don't want the events. Let them fall through to the all apps view.
+ }
+ if (mLauncher.isAllAppsVisible()) {
+ // Cancel any scrolling that is in progress.
+ if (!mScroller.isFinished()) {
+ mScroller.abortAnimation();
+ }
+ snapToScreen(mCurrentScreen);
+ return false; // We don't want the events. Let them fall through to the all apps view.
+ }
+
+ if (mVelocityTracker == null) {
+ mVelocityTracker = VelocityTracker.obtain();
+ }
+ mVelocityTracker.addMovement(ev);
+
+ final int action = ev.getAction();
+ final float x = ev.getX();
+
+ switch (action) {
+ case MotionEvent.ACTION_DOWN:
+ /*
+ * If being flinged and user touches, stop the fling. isFinished
+ * will be false if being flinged.
+ */
+ if (!mScroller.isFinished()) {
+ mScroller.abortAnimation();
+ }
+
+ // Remember where the motion event started
+ mLastMotionX = x;
+ break;
+ case MotionEvent.ACTION_MOVE:
+ if (mTouchState == TOUCH_STATE_SCROLLING) {
+ // Scroll to follow the motion event
+ final int deltaX = (int) (mLastMotionX - x);
+ mLastMotionX = x;
+
+ if (deltaX < 0) {
+ if (mScrollX > 0) {
+ scrollBy(Math.max(-mScrollX, deltaX), 0);
+ updateWallpaperOffset();
+ }
+ } else if (deltaX > 0) {
+ final int availableToScroll = getChildAt(getChildCount() - 1).getRight() -
+ mScrollX - getWidth();
+ if (availableToScroll > 0) {
+ scrollBy(Math.min(availableToScroll, deltaX), 0);
+ updateWallpaperOffset();
+ }
+ } else {
+ awakenScrollBars();
+ }
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ if (mTouchState == TOUCH_STATE_SCROLLING) {
+ final VelocityTracker velocityTracker = mVelocityTracker;
+ velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
+ int velocityX = (int) velocityTracker.getXVelocity();
+
+ if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
+ // Fling hard enough to move left
+ snapToScreen(mCurrentScreen - 1);
+ } else if (velocityX < -SNAP_VELOCITY && mCurrentScreen < getChildCount() - 1) {
+ // Fling hard enough to move right
+ snapToScreen(mCurrentScreen + 1);
+ } else {
+ snapToDestination();
+ }
+
+ if (mVelocityTracker != null) {
+ mVelocityTracker.recycle();
+ mVelocityTracker = null;
+ }
+ }
+ mTouchState = TOUCH_STATE_REST;
+ break;
+ case MotionEvent.ACTION_CANCEL:
+ mTouchState = TOUCH_STATE_REST;
+ }
+
+ return true;
+ }
+
+ private void snapToDestination() {
+ final int screenWidth = getWidth();
+ final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth;
+
+ snapToScreen(whichScreen);
+ }
+
+ void snapToScreen(int whichScreen) {
+ //if (!mScroller.isFinished()) return;
+
+ whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));
+
+ clearVacantCache();
+ enableChildrenCache(mCurrentScreen, whichScreen);
+
+ final int screenDelta = Math.abs(whichScreen - mCurrentScreen);
+
+ mNextScreen = whichScreen;
+
+ mPreviousIndicator.setLevel(mNextScreen);
+ mNextIndicator.setLevel(mNextScreen);
+
+ View focusedChild = getFocusedChild();
+ if (focusedChild != null && screenDelta != 0 && focusedChild == getChildAt(mCurrentScreen)) {
+ focusedChild.clearFocus();
+ }
+
+ final int newX = whichScreen * getWidth();
+ final int delta = newX - mScrollX;
+ final int duration = screenDelta * 300;
+ awakenScrollBars(duration);
+ mScroller.startScroll(mScrollX, 0, delta, 0, duration);
+ invalidate();
+ }
+
+ void startDrag(CellLayout.CellInfo cellInfo) {
+ View child = cellInfo.cell;
+
+ // Make sure the drag was started by a long press as opposed to a long click.
+ // Note that Search takes focus when clicked rather than entering touch mode
+ if (!child.isInTouchMode() && !(child instanceof Search)) {
+ return;
+ }
+
+ mDragInfo = cellInfo;
+ mDragInfo.screen = mCurrentScreen;
+
+ CellLayout current = ((CellLayout) getChildAt(mCurrentScreen));
+
+ current.onDragChild(child);
+ mDragController.startDrag(child, this, child.getTag(), DragController.DRAG_ACTION_MOVE);
+ invalidate();
+ }
+
+ @Override
+ protected Parcelable onSaveInstanceState() {
+ final SavedState state = new SavedState(super.onSaveInstanceState());
+ state.currentScreen = mCurrentScreen;
+ return state;
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Parcelable state) {
+ SavedState savedState = (SavedState) state;
+ super.onRestoreInstanceState(savedState.getSuperState());
+ if (savedState.currentScreen != -1) {
+ mCurrentScreen = savedState.currentScreen;
+ Launcher.setScreen(mCurrentScreen);
+ }
+ }
+
+ void addApplicationShortcut(ApplicationInfo info, CellLayout.CellInfo cellInfo) {
+ addApplicationShortcut(info, cellInfo, false);
+ }
+
+ void addApplicationShortcut(ApplicationInfo info, CellLayout.CellInfo cellInfo,
+ boolean insertAtFirst) {
+ final CellLayout layout = (CellLayout) getChildAt(cellInfo.screen);
+ final int[] result = new int[2];
+
+ layout.cellToPoint(cellInfo.cellX, cellInfo.cellY, result);
+ onDropExternal(result[0], result[1], info, layout, insertAtFirst);
+ }
+
+ public void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ final CellLayout cellLayout = getCurrentDropLayout();
+ if (source != this) {
+ onDropExternal(x - xOffset, y - yOffset, dragInfo, cellLayout);
+ } else {
+ // Move internally
+ if (mDragInfo != null) {
+ final View cell = mDragInfo.cell;
+ int index = mScroller.isFinished() ? mCurrentScreen : mNextScreen;
+ if (index != mDragInfo.screen) {
+ final CellLayout originalCellLayout = (CellLayout) getChildAt(mDragInfo.screen);
+ originalCellLayout.removeView(cell);
+ cellLayout.addView(cell);
+ }
+ mTargetCell = estimateDropCell(x - xOffset, y - yOffset,
+ mDragInfo.spanX, mDragInfo.spanY, cell, cellLayout, mTargetCell);
+ cellLayout.onDropChild(cell, mTargetCell);
+
+ final ItemInfo info = (ItemInfo) cell.getTag();
+ CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
+ LauncherModel.moveItemInDatabase(mLauncher, info,
+ LauncherSettings.Favorites.CONTAINER_DESKTOP, index, lp.cellX, lp.cellY);
+ }
+ }
+ }
+
+ public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ clearVacantCache();
+ }
+
+ public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ }
+
+ public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
+ DragView dragView, Object dragInfo) {
+ clearVacantCache();
+ }
+
+ private void onDropExternal(int x, int y, Object dragInfo, CellLayout cellLayout) {
+ onDropExternal(x, y, dragInfo, cellLayout, false);
+ }
+
+ private void onDropExternal(int x, int y, Object dragInfo, CellLayout cellLayout,
+ boolean insertAtFirst) {
+ // Drag from somewhere else
+ ItemInfo info = (ItemInfo) dragInfo;
+
+ View view;
+
+ switch (info.itemType) {
+ case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
+ case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
+ if (info.container == NO_ID) {
+ // Came from all apps -- make a copy
+ info = new ApplicationInfo((ApplicationInfo) info);
+ }
+ view = mLauncher.createShortcut(R.layout.application, cellLayout,
+ (ApplicationInfo) info);
+ break;
+ case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER:
+ view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher,
+ (ViewGroup) getChildAt(mCurrentScreen), ((UserFolderInfo) info));
+ break;
+ default:
+ throw new IllegalStateException("Unknown item type: " + info.itemType);
+ }
+
+ cellLayout.addView(view, insertAtFirst ? 0 : -1);
+ view.setHapticFeedbackEnabled(false);
+ view.setOnLongClickListener(mLongClickListener);
+ if (view instanceof DropTarget) {
+ mDragController.addDropTarget((DropTarget) view);
+ }
+
+ mTargetCell = estimateDropCell(x, y, 1, 1, view, cellLayout, mTargetCell);
+ cellLayout.onDropChild(view, mTargetCell);
+ CellLayout.LayoutParams lp = (CellLayout.LayoutParams) view.getLayoutParams();
+
+ LauncherModel.addOrMoveItemInDatabase(mLauncher, info,
+ LauncherSettings.Favorites.CONTAINER_DESKTOP, mCurrentScreen, lp.cellX, lp.cellY);
+ }
+
+ /**
+ * Return the current {@link CellLayout}, correctly picking the destination
+ * screen while a scroll is in progress.
+ */
+ private CellLayout getCurrentDropLayout() {
+ int index = mScroller.isFinished() ? mCurrentScreen : mNextScreen;
+ return (CellLayout) getChildAt(index);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean acceptDrop(DragSource source, int x, int y,
+ int xOffset, int yOffset, DragView dragView, Object dragInfo) {
+ final CellLayout layout = getCurrentDropLayout();
+ final CellLayout.CellInfo cellInfo = mDragInfo;
+ final int spanX = cellInfo == null ? 1 : cellInfo.spanX;
+ final int spanY = cellInfo == null ? 1 : cellInfo.spanY;
+
+ if (mVacantCache == null) {
+ final View ignoreView = cellInfo == null ? null : cellInfo.cell;
+ mVacantCache = layout.findAllVacantCells(null, ignoreView);
+ }
+
+ return mVacantCache.findCellForSpan(mTempEstimate, spanX, spanY, false);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Rect estimateDropLocation(DragSource source, int x, int y,
+ int xOffset, int yOffset, DragView dragView, Object dragInfo, Rect recycle) {
+ final CellLayout layout = getCurrentDropLayout();
+
+ final CellLayout.CellInfo cellInfo = mDragInfo;
+ final int spanX = cellInfo == null ? 1 : cellInfo.spanX;
+ final int spanY = cellInfo == null ? 1 : cellInfo.spanY;
+ final View ignoreView = cellInfo == null ? null : cellInfo.cell;
+
+ final Rect location = recycle != null ? recycle : new Rect();
+
+ // Find drop cell and convert into rectangle
+ int[] dropCell = estimateDropCell(x - xOffset, y - yOffset,
+ spanX, spanY, ignoreView, layout, mTempCell);
+
+ if (dropCell == null) {
+ return null;
+ }
+
+ layout.cellToPoint(dropCell[0], dropCell[1], mTempEstimate);
+ location.left = mTempEstimate[0];
+ location.top = mTempEstimate[1];
+
+ layout.cellToPoint(dropCell[0] + spanX, dropCell[1] + spanY, mTempEstimate);
+ location.right = mTempEstimate[0];
+ location.bottom = mTempEstimate[1];
+
+ return location;
+ }
+
+ /**
+ * Calculate the nearest cell where the given object would be dropped.
+ */
+ private int[] estimateDropCell(int pixelX, int pixelY,
+ int spanX, int spanY, View ignoreView, CellLayout layout, int[] recycle) {
+ // Create vacant cell cache if none exists
+ if (mVacantCache == null) {
+ mVacantCache = layout.findAllVacantCells(null, ignoreView);
+ }
+
+ // Find the best target drop location
+ return layout.findNearestVacantArea(pixelX, pixelY,
+ spanX, spanY, mVacantCache, recycle);
+ }
+
+ void setLauncher(Launcher launcher) {
+ mLauncher = launcher;
+ }
+
+ public void setDragController(DragController dragController) {
+ mDragController = dragController;
+ }
+
+ public void onDropCompleted(View target, boolean success) {
+ clearVacantCache();
+
+ if (success){
+ if (target != this && mDragInfo != null) {
+ final CellLayout cellLayout = (CellLayout) getChildAt(mDragInfo.screen);
+ cellLayout.removeView(mDragInfo.cell);
+ if (mDragInfo.cell instanceof DropTarget) {
+ mDragController.removeDropTarget((DropTarget)mDragInfo.cell);
+ }
+ //final Object tag = mDragInfo.cell.getTag();
+ }
+ } else {
+ if (mDragInfo != null) {
+ final CellLayout cellLayout = (CellLayout) getChildAt(mDragInfo.screen);
+ cellLayout.onDropAborted(mDragInfo.cell);
+ }
+ }
+
+ mDragInfo = null;
+ }
+
+ public void scrollLeft() {
+ clearVacantCache();
+ if (mNextScreen == INVALID_SCREEN && mCurrentScreen > 0 && mScroller.isFinished()) {
+ snapToScreen(mCurrentScreen - 1);
+ }
+ }
+
+ public void scrollRight() {
+ clearVacantCache();
+ if (mNextScreen == INVALID_SCREEN && mCurrentScreen < getChildCount() -1 &&
+ mScroller.isFinished()) {
+ snapToScreen(mCurrentScreen + 1);
+ }
+ }
+
+ public int getScreenForView(View v) {
+ int result = -1;
+ if (v != null) {
+ ViewParent vp = v.getParent();
+ int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ if (vp == getChildAt(i)) {
+ return i;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Find a search widget on the given screen
+ */
+ private Search findSearchWidget(CellLayout screen) {
+ final int count = screen.getChildCount();
+ for (int i = 0; i < count; i++) {
+ View v = screen.getChildAt(i);
+ if (v instanceof Search) {
+ return (Search) v;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Gets the first search widget on the current screen, if there is one.
+ * Returns <code>null</code> otherwise.
+ */
+ public Search findSearchWidgetOnCurrentScreen() {
+ CellLayout currentScreen = (CellLayout)getChildAt(mCurrentScreen);
+ return findSearchWidget(currentScreen);
+ }
+
+ public Folder getFolderForTag(Object tag) {
+ int screenCount = getChildCount();
+ for (int screen = 0; screen < screenCount; screen++) {
+ CellLayout currentScreen = ((CellLayout) getChildAt(screen));
+ int count = currentScreen.getChildCount();
+ for (int i = 0; i < count; i++) {
+ View child = currentScreen.getChildAt(i);
+ CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
+ if (lp.cellHSpan == 4 && lp.cellVSpan == 4 && child instanceof Folder) {
+ Folder f = (Folder) child;
+ if (f.getInfo() == tag) {
+ return f;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public View getViewForTag(Object tag) {
+ int screenCount = getChildCount();
+ for (int screen = 0; screen < screenCount; screen++) {
+ CellLayout currentScreen = ((CellLayout) getChildAt(screen));
+ int count = currentScreen.getChildCount();
+ for (int i = 0; i < count; i++) {
+ View child = currentScreen.getChildAt(i);
+ if (child.getTag() == tag) {
+ return child;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return True is long presses are still allowed for the current touch
+ */
+ public boolean allowLongPress() {
+ return mAllowLongPress;
+ }
+
+ /**
+ * Set true to allow long-press events to be triggered, usually checked by
+ * {@link Launcher} to accept or block dpad-initiated long-presses.
+ */
+ public void setAllowLongPress(boolean allowLongPress) {
+ mAllowLongPress = allowLongPress;
+ }
+
+ void removeShortcutsForPackage(String packageName) {
+ final ArrayList<View> childrenToRemove = new ArrayList<View>();
+ final int count = getChildCount();
+
+ for (int i = 0; i < count; i++) {
+ final CellLayout layout = (CellLayout) getChildAt(i);
+ int childCount = layout.getChildCount();
+
+ childrenToRemove.clear();
+
+ for (int j = 0; j < childCount; j++) {
+ final View view = layout.getChildAt(j);
+ Object tag = view.getTag();
+
+ if (tag instanceof ApplicationInfo) {
+ final ApplicationInfo info = (ApplicationInfo) tag;
+ // We need to check for ACTION_MAIN otherwise getComponent() might
+ // return null for some shortcuts (for instance, for shortcuts to
+ // web pages.)
+ final Intent intent = info.intent;
+ final ComponentName name = intent.getComponent();
+
+ if (Intent.ACTION_MAIN.equals(intent.getAction()) &&
+ name != null && packageName.equals(name.getPackageName())) {
+ LauncherModel.deleteItemFromDatabase(mLauncher, info);
+ childrenToRemove.add(view);
+ }
+ } else if (tag instanceof UserFolderInfo) {
+ final UserFolderInfo info = (UserFolderInfo) tag;
+ final ArrayList<ApplicationInfo> contents = info.contents;
+ final ArrayList<ApplicationInfo> toRemove = new ArrayList<ApplicationInfo>(1);
+ final int contentsCount = contents.size();
+ boolean removedFromFolder = false;
+
+ for (int k = 0; k < contentsCount; k++) {
+ final ApplicationInfo appInfo = contents.get(k);
+ final Intent intent = appInfo.intent;
+ final ComponentName name = intent.getComponent();
+
+ if (Intent.ACTION_MAIN.equals(intent.getAction()) &&
+ name != null && packageName.equals(name.getPackageName())) {
+ toRemove.add(appInfo);
+ LauncherModel.deleteItemFromDatabase(mLauncher, appInfo);
+ removedFromFolder = true;
+ }
+ }
+
+ contents.removeAll(toRemove);
+ if (removedFromFolder) {
+ final Folder folder = getOpenFolder();
+ if (folder != null) folder.notifyDataSetChanged();
+ }
+ }
+ }
+
+ childCount = childrenToRemove.size();
+ for (int j = 0; j < childCount; j++) {
+ View child = childrenToRemove.get(j);
+ layout.removeViewInLayout(child);
+ if (child instanceof DropTarget) {
+ mDragController.removeDropTarget((DropTarget)child);
+ }
+ }
+
+ if (childCount > 0) {
+ layout.requestLayout();
+ layout.invalidate();
+ }
+ }
+ }
+
+ void updateShortcutsForPackage(String packageName) {
+ final PackageManager pm = mLauncher.getPackageManager();
+
+ final int count = getChildCount();
+ for (int i = 0; i < count; i++) {
+ final CellLayout layout = (CellLayout) getChildAt(i);
+ int childCount = layout.getChildCount();
+ for (int j = 0; j < childCount; j++) {
+ final View view = layout.getChildAt(j);
+ Object tag = view.getTag();
+ if (tag instanceof ApplicationInfo) {
+ ApplicationInfo info = (ApplicationInfo) tag;
+ // We need to check for ACTION_MAIN otherwise getComponent() might
+ // return null for some shortcuts (for instance, for shortcuts to
+ // web pages.)
+ final Intent intent = info.intent;
+ final ComponentName name = intent.getComponent();
+ if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION &&
+ Intent.ACTION_MAIN.equals(intent.getAction()) && name != null &&
+ packageName.equals(name.getPackageName())) {
+
+ final Drawable icon = AppInfoCache.getIconDrawable(pm, info);
+ if (icon != null && icon != info.icon) {
+ info.icon.setCallback(null);
+ info.icon = Utilities.createIconThumbnail(icon, mContext);
+ info.filtered = true;
+ ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(null,
+ info.icon, null, null);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ void moveToDefaultScreen(boolean animate) {
+ if (animate) {
+ snapToScreen(mDefaultScreen);
+ } else {
+ setCurrentScreen(mDefaultScreen);
+ }
+ getChildAt(mDefaultScreen).requestFocus();
+ }
+
+ void setIndicators(Drawable previous, Drawable next) {
+ mPreviousIndicator = previous;
+ mNextIndicator = next;
+ previous.setLevel(mCurrentScreen);
+ next.setLevel(mCurrentScreen);
+ }
+
+ public static class SavedState extends BaseSavedState {
+ int currentScreen = -1;
+
+ SavedState(Parcelable superState) {
+ super(superState);
+ }
+
+ private SavedState(Parcel in) {
+ super(in);
+ currentScreen = in.readInt();
+ }
+
+ @Override
+ public void writeToParcel(Parcel out, int flags) {
+ super.writeToParcel(out, flags);
+ out.writeInt(currentScreen);
+ }
+
+ public static final Parcelable.Creator<SavedState> CREATOR =
+ new Parcelable.Creator<SavedState>() {
+ public SavedState createFromParcel(Parcel in) {
+ return new SavedState(in);
+ }
+
+ public SavedState[] newArray(int size) {
+ return new SavedState[size];
+ }
+ };
+ }
+
+ void show() {
+ setVisibility(VISIBLE);
+ }
+
+ void hide() {
+ }
+}