Merge change Ia20b55c7 into eclair
* changes:
Add hardware support to AVD creation dialog.
diff --git a/samples/ApiDemos/default.properties b/samples/ApiDemos/default.properties
deleted file mode 100644
index 4e561dc..0000000
--- a/samples/ApiDemos/default.properties
+++ /dev/null
@@ -1,11 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
-# project structure.
-
-# Project target.
-target=android-Eclair
diff --git a/samples/CubeLiveWallpaper/Android.mk b/samples/CubeLiveWallpaper/Android.mk
new file mode 100644
index 0000000..7227394
--- /dev/null
+++ b/samples/CubeLiveWallpaper/Android.mk
@@ -0,0 +1,27 @@
+#
+# 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+# LOCAL_MODULE_TAGS := user
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := CubeLiveWallpapers
+LOCAL_CERTIFICATE := shared
+
+include $(BUILD_PACKAGE)
diff --git a/samples/CubeLiveWallpaper/AndroidManifest.xml b/samples/CubeLiveWallpaper/AndroidManifest.xml
new file mode 100644
index 0000000..8d24c4a
--- /dev/null
+++ b/samples/CubeLiveWallpaper/AndroidManifest.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 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.
+*/
+-->
+<manifest
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.livecubes">
+
+ <application
+ android:label="@string/wallpapers"
+ android:icon="@drawable/ic_launcher_wallpaper">
+
+ <service
+ android:label="@string/wallpaper_cube1"
+ android:name=".cube1.CubeWallpaper1"
+ android:permission="android.permission.BIND_WALLPAPER">
+ <intent-filter>
+ <action android:name="android.service.wallpaper.WallpaperService" />
+ </intent-filter>
+ <meta-data android:name="android.service.wallpaper" android:resource="@xml/cube1" />
+ </service>
+
+ <service
+ android:label="@string/wallpaper_cube2"
+ android:name=".cube2.CubeWallpaper2"
+ android:permission="android.permission.BIND_WALLPAPER">
+ <intent-filter>
+ <action android:name="android.service.wallpaper.WallpaperService" />
+ </intent-filter>
+ <meta-data android:name="android.service.wallpaper" android:resource="@xml/cube2" />
+ </service>
+ <activity
+ android:label="@string/cube2_settings"
+ android:name="com.android.livecubes.cube2.CubeWallpaper2Settings"
+ android:theme="@android:style/Theme.Light.WallpaperSettings"
+ android:exported="true">
+ </activity>
+
+ <service
+ android:label="@string/wallpaper_cube3"
+ android:name=".cube3.CubeWallpaper3"
+ android:permission="android.permission.BIND_WALLPAPER">
+ <intent-filter>
+ <action android:name="android.service.wallpaper.WallpaperService" />
+ </intent-filter>
+ <meta-data android:name="android.service.wallpaper" android:resource="@xml/cube3" />
+ </service>
+
+ </application>
+
+</manifest>
diff --git a/samples/CubeLiveWallpaper/MODULE_LICENSE_APACHE2 b/samples/CubeLiveWallpaper/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/samples/CubeLiveWallpaper/MODULE_LICENSE_APACHE2
diff --git a/samples/CubeLiveWallpaper/NOTICE b/samples/CubeLiveWallpaper/NOTICE
new file mode 100644
index 0000000..c5b1efa
--- /dev/null
+++ b/samples/CubeLiveWallpaper/NOTICE
@@ -0,0 +1,190 @@
+
+ Copyright (c) 2005-2008, The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
diff --git a/samples/CubeLiveWallpaper/res/drawable/ic_launcher_wallpaper.png b/samples/CubeLiveWallpaper/res/drawable/ic_launcher_wallpaper.png
new file mode 100644
index 0000000..965fb71
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/drawable/ic_launcher_wallpaper.png
Binary files differ
diff --git a/samples/CubeLiveWallpaper/res/raw/cube.rs b/samples/CubeLiveWallpaper/res/raw/cube.rs
new file mode 100644
index 0000000..407d63b
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/raw/cube.rs
@@ -0,0 +1,50 @@
+// 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.
+
+#pragma version(1)
+#pragma stateVertex(PVBackground)
+
+#define RSID_POINTS 0
+
+void dumpState() {
+
+// debugF("@@@@@ yrot: ", State->yRotation);
+
+}
+
+int main(int launchID) {
+
+ int i;
+
+ // Change the model matrix to account for the large model
+ // and to do the necessary rotations.
+ float mat1[16];
+ float rads = ((float)startTimeMillis()) / 1000;
+ float xrot = degf(-rads);
+ float yrot = State->yRotation;
+ float scale = 1.0/900.0;
+ matrixLoadScale(mat1, scale, scale, scale);
+ matrixRotate(mat1, yrot, 0.f, 1.f, 0.f);
+ matrixRotate(mat1, xrot, 1.f, 0.f, 0.f);
+ vpLoadModelMatrix(mat1);
+
+ // Draw the cube. The default color will be used,
+ // but we can also set the color here with the color()
+ // function, or specify the color(s) as part of
+ // the vertex data.
+ uploadToBufferObject(NAMED_PointBuffer);
+ drawSimpleMesh(NAMED_CubeMesh);
+
+ return 1;
+}
diff --git a/samples/CubeLiveWallpaper/res/values/shapes.xml b/samples/CubeLiveWallpaper/res/values/shapes.xml
new file mode 100644
index 0000000..49bdaf9
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/values/shapes.xml
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+* Copyright (C) 4008 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">
+
+ <string-array name="cube2_shapenames">
+ <item>"Cube"</item>
+ <item>"Dodecahedron"</item>
+ </string-array>
+
+ <string-array name="cube2_shapeprefix">
+ <item>"cube"</item>
+ <item>"dodecahedron"</item>
+ </string-array>
+
+ <!-- x,y,z tuples for the points defining the object -->
+ <!-- stored as strings for easier human readability -->
+ <string-array name="cubepoints">
+ <item>"-400 -400 -400"</item>
+ <item>"400 -400 -400"</item>
+ <item>"400 400 -400"</item>
+ <item>"-400 400 -400"</item>
+ <item>"-400 -400 400"</item>
+ <item>"400 -400 400"</item>
+ <item>"400 400 400"</item>
+ <item>"-400 400 400"</item>
+ </string-array>
+
+ <!-- start,end point index tuples of the lines defining the object -->
+ <string-array name="cubelines">
+ <!-- lines forming one face -->
+ <item>"0 1"</item>
+ <item>"1 2"</item>
+ <item>"2 3"</item>
+ <item>"3 0"</item>
+
+ <!-- lines forming the opposite face -->
+ <item>"4 5"</item>
+ <item>"5 6"</item>
+ <item>"6 7"</item>
+ <item>"7 4"</item>
+
+ <!-- lines connecting the two faces -->
+ <item>"0 4"</item>
+ <item>"1 5"</item>
+ <item>"2 6"</item>
+ <item>"3 7"</item>
+ </string-array>
+
+ <string-array name="dodecahedronpoints">
+ <item>"333.850000 0.000000 437.250000"</item>
+ <item>"103.400000 317.350000 437.250000"</item>
+ <item>"-270.050000 196.350000 437.250000"</item>
+ <item>"-270.050000 -196.350000 437.250000"</item>
+ <item>"103.400000 -317.350000 437.250000"</item>
+ <item>"540.100000 0.000000 103.400000"</item>
+ <item>"167.200000 513.700000 103.400000"</item>
+ <item>"-437.250000 317.350000 103.400000"</item>
+ <item>"-437.250000 -317.350000 103.400000"</item>
+ <item>"167.200000 -513.700000 103.400000"</item>
+ <item>"437.250000 317.350000 -103.400000"</item>
+ <item>"-167.200000 513.700000 -103.400000"</item>
+ <item>"-540.100000 0.000000 -103.400000"</item>
+ <item>"-167.200000 -513.700000 -103.400000"</item>
+ <item>"437.250000 -317.350000 -103.400000"</item>
+ <item>"270.050000 196.350000 -437.250000"</item>
+ <item>"-103.400000 317.350000 -437.250000"</item>
+ <item>"-333.850000 0.000000 -437.250000"</item>
+ <item>"-103.400000 -317.350000 -437.250000"</item>
+ <item>"270.050000 -196.350000 -437.250000"</item>
+ </string-array>
+
+ <string-array name="dodecahedronlines">
+ <item>"0 1"</item>
+ <item>"0 4"</item>
+ <item>"0 5"</item>
+ <item>"1 2"</item>
+ <item>"1 6"</item>
+ <item>"2 3"</item>
+ <item>"2 7"</item>
+ <item>"3 4"</item>
+ <item>"3 8"</item>
+ <item>"4 9"</item>
+ <item>"5 10"</item>
+ <item>"5 14"</item>
+ <item>"6 10"</item>
+ <item>"6 11"</item>
+ <item>"7 11"</item>
+ <item>"7 12"</item>
+ <item>"8 12"</item>
+ <item>"8 13"</item>
+ <item>"9 13"</item>
+ <item>"9 14"</item>
+ <item>"10 15"</item>
+ <item>"11 16"</item>
+ <item>"12 17"</item>
+ <item>"13 18"</item>
+ <item>"14 19"</item>
+ <item>"15 16"</item>
+ <item>"15 19"</item>
+ <item>"16 17"</item>
+ <item>"17 18"</item>
+ <item>"18 19"</item>
+ </string-array>
+</resources>
diff --git a/samples/CubeLiveWallpaper/res/values/strings.xml b/samples/CubeLiveWallpaper/res/values/strings.xml
new file mode 100644
index 0000000..3302058
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/values/strings.xml
@@ -0,0 +1,38 @@
+<?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:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- General -->
+ <skip />
+ <!-- Application name -->
+ <string name="wallpapers">Example Wallpapers</string>
+
+ <!-- Wallpaper showing a cube -->
+ <string name="wallpaper_cube1">Cube</string>
+
+ <!-- Wallpaper showing a cube or dodecahedron, data read from resource -->
+ <string name="wallpaper_cube2">Cube - resource</string>
+
+ <!-- Wallpaper showing a cube, renderscript version -->
+ <string name="wallpaper_cube3">Cube - RenderScript</string>
+
+ <string name="cube2_settings">Settings</string>
+ <string name="cube2_settings_title">Select shape</string>
+ <string name="cube2_settings_summary">Choose whether to display a cube or a dodecahedron</string>
+</resources>
diff --git a/samples/CubeLiveWallpaper/res/xml/cube1.xml b/samples/CubeLiveWallpaper/res/xml/cube1.xml
new file mode 100644
index 0000000..5c7fca5
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/xml/cube1.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.
+ */
+-->
+
+<!-- The attributes in this XML file provide configuration information -->
+
+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
+/>
diff --git a/samples/CubeLiveWallpaper/res/xml/cube2.xml b/samples/CubeLiveWallpaper/res/xml/cube2.xml
new file mode 100644
index 0000000..bf9054c
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/xml/cube2.xml
@@ -0,0 +1,24 @@
+<?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.
+ */
+-->
+
+<!-- The attributes in this XML file provide configuration information -->
+
+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
+ android:settingsActivity="com.android.livecubes.cube2.CubeWallpaper2Settings"
+/>
diff --git a/samples/CubeLiveWallpaper/res/xml/cube2_settings.xml b/samples/CubeLiveWallpaper/res/xml/cube2_settings.xml
new file mode 100644
index 0000000..50a28ae
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/xml/cube2_settings.xml
@@ -0,0 +1,28 @@
+<?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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/cube2_settings"
+ android:key="cube2wallpaper_settings">
+
+ <ListPreference
+ android:key="cube2_shape"
+ android:title="@string/cube2_settings_title"
+ android:summary="@string/cube2_settings_summary"
+ android:entries="@array/cube2_shapenames"
+ android:entryValues="@array/cube2_shapeprefix" />
+
+</PreferenceScreen>
diff --git a/samples/CubeLiveWallpaper/res/xml/cube3.xml b/samples/CubeLiveWallpaper/res/xml/cube3.xml
new file mode 100644
index 0000000..5c7fca5
--- /dev/null
+++ b/samples/CubeLiveWallpaper/res/xml/cube3.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.
+ */
+-->
+
+<!-- The attributes in this XML file provide configuration information -->
+
+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
+/>
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube1/CubeWallpaper1.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube1/CubeWallpaper1.java
new file mode 100644
index 0000000..9279065
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube1/CubeWallpaper1.java
@@ -0,0 +1,240 @@
+/*
+ * 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.livecubes.cube1;
+
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.os.SystemClock;
+import android.service.wallpaper.WallpaperService;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.SurfaceHolder;
+
+/*
+ * This animated wallpaper draws a rotating wireframe cube.
+ */
+public class CubeWallpaper1 extends WallpaperService {
+
+ private final Handler mHandler = new Handler();
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public Engine onCreateEngine() {
+ return new CubeEngine();
+ }
+
+ class CubeEngine extends Engine {
+
+ private final Paint mPaint = new Paint();
+ private float mOffset;
+ private float mTouchX = -1;
+ private float mTouchY = -1;
+ private long mStartTime;
+ private float mCenterX;
+ private float mCenterY;
+
+ private final Runnable mDrawCube = new Runnable() {
+ public void run() {
+ drawFrame();
+ }
+ };
+ private boolean mVisible;
+
+ CubeEngine() {
+ // Create a Paint to draw the lines for our cube
+ final Paint paint = mPaint;
+ paint.setColor(0xffffffff);
+ paint.setAntiAlias(true);
+ paint.setStrokeWidth(2);
+ paint.setStrokeCap(Paint.Cap.ROUND);
+ paint.setStyle(Paint.Style.STROKE);
+
+ mStartTime = SystemClock.elapsedRealtime();
+ }
+
+ @Override
+ public void onCreate(SurfaceHolder surfaceHolder) {
+ super.onCreate(surfaceHolder);
+
+ // By default we don't get touch events, so enable them.
+ setTouchEventsEnabled(true);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ mHandler.removeCallbacks(mDrawCube);
+ }
+
+ @Override
+ public void onVisibilityChanged(boolean visible) {
+ mVisible = visible;
+ if (visible) {
+ drawFrame();
+ } else {
+ mHandler.removeCallbacks(mDrawCube);
+ }
+ }
+
+ @Override
+ public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ super.onSurfaceChanged(holder, format, width, height);
+ // store the center of the surface, so we can draw the cube in the right spot
+ mCenterX = width/2.0f;
+ mCenterY = height/2.0f;
+ drawFrame();
+ }
+
+ @Override
+ public void onSurfaceCreated(SurfaceHolder holder) {
+ super.onSurfaceCreated(holder);
+ }
+
+ @Override
+ public void onSurfaceDestroyed(SurfaceHolder holder) {
+ super.onSurfaceDestroyed(holder);
+ mVisible = false;
+ mHandler.removeCallbacks(mDrawCube);
+ }
+
+ @Override
+ public void onOffsetsChanged(float xOffset, float yOffset, int xPixels, int yPixels) {
+ mOffset = xOffset;
+ drawFrame();
+ }
+
+ /*
+ * Store the position of the touch event so we can use it for drawing later
+ */
+ @Override
+ public void onTouchEvent(MotionEvent event) {
+ if (event.getAction() == MotionEvent.ACTION_MOVE) {
+ mTouchX = event.getX();
+ mTouchY = event.getY();
+ } else {
+ mTouchX = -1;
+ mTouchY = -1;
+ }
+ super.onTouchEvent(event);
+ }
+
+ /*
+ * Draw one frame of the animation. This method gets called repeatedly
+ * by posting a delayed Runnable. You can do any drawing you want in
+ * here. This example draws a wireframe cube.
+ */
+ void drawFrame() {
+ final SurfaceHolder holder = getSurfaceHolder();
+
+ Canvas c = null;
+ try {
+ c = holder.lockCanvas();
+ if (c != null) {
+ // draw something
+ drawCube(c);
+ drawTouchPoint(c);
+ }
+ } finally {
+ if (c != null) holder.unlockCanvasAndPost(c);
+ }
+
+ // Reschedule the next redraw
+ mHandler.removeCallbacks(mDrawCube);
+ if (mVisible) {
+ mHandler.postDelayed(mDrawCube, 1000 / 25);
+ }
+ }
+
+ /*
+ * Draw a wireframe cube by drawing 12 3 dimensional lines between
+ * adjacent corners of the cube
+ */
+ void drawCube(Canvas c) {
+ c.save();
+ c.translate(mCenterX, mCenterY);
+ c.drawColor(0xff000000);
+ drawLine(c, -400, -400, -400, 400, -400, -400);
+ drawLine(c, 400, -400, -400, 400, 400, -400);
+ drawLine(c, 400, 400, -400, -400, 400, -400);
+ drawLine(c, -400, 400, -400, -400, -400, -400);
+
+ drawLine(c, -400, -400, 400, 400, -400, 400);
+ drawLine(c, 400, -400, 400, 400, 400, 400);
+ drawLine(c, 400, 400, 400, -400, 400, 400);
+ drawLine(c, -400, 400, 400, -400, -400, 400);
+
+ drawLine(c, -400, -400, 400, -400, -400, -400);
+ drawLine(c, 400, -400, 400, 400, -400, -400);
+ drawLine(c, 400, 400, 400, 400, 400, -400);
+ drawLine(c, -400, 400, 400, -400, 400, -400);
+ c.restore();
+ }
+
+ /*
+ * Draw a 3 dimensional line on to the screen
+ */
+ void drawLine(Canvas c, int x1, int y1, int z1, int x2, int y2, int z2) {
+ long now = SystemClock.elapsedRealtime();
+ float xrot = ((float)(now - mStartTime)) / 1000;
+ float yrot = (0.5f - mOffset) * 2.0f;
+ float zrot = 0;
+
+ // 3D transformations
+
+ // rotation around X-axis
+ float newy1 = (float)(Math.sin(xrot) * z1 + Math.cos(xrot) * y1);
+ float newy2 = (float)(Math.sin(xrot) * z2 + Math.cos(xrot) * y2);
+ float newz1 = (float)(Math.cos(xrot) * z1 - Math.sin(xrot) * y1);
+ float newz2 = (float)(Math.cos(xrot) * z2 - Math.sin(xrot) * y2);
+
+ // rotation around Y-axis
+ float newx1 = (float)(Math.sin(yrot) * newz1 + Math.cos(yrot) * x1);
+ float newx2 = (float)(Math.sin(yrot) * newz2 + Math.cos(yrot) * x2);
+ newz1 = (float)(Math.cos(yrot) * newz1 - Math.sin(yrot) * x1);
+ newz2 = (float)(Math.cos(yrot) * newz2 - Math.sin(yrot) * x2);
+
+ // 3D-to-2D projection
+ float startX = newx1 / (4 - newz1 / 400);
+ float startY = newy1 / (4 - newz1 / 400);
+ float stopX = newx2 / (4 - newz2 / 400);
+ float stopY = newy2 / (4 - newz2 / 400);
+
+ c.drawLine(startX, startY, stopX, stopY, mPaint);
+ }
+
+ /*
+ * Draw a circle around the current touch point, if any.
+ */
+ void drawTouchPoint(Canvas c) {
+ if (mTouchX >=0 && mTouchY >= 0) {
+ c.drawCircle(mTouchX, mTouchY, 80, mPaint);
+ }
+ }
+
+ }
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2.java
new file mode 100644
index 0000000..43f1326
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2.java
@@ -0,0 +1,296 @@
+/*
+ * 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.livecubes.cube2;
+
+import com.android.livecubes.R;
+
+import android.content.SharedPreferences;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.os.Handler;
+import android.os.SystemClock;
+import android.service.wallpaper.WallpaperService;
+import android.util.Log;
+import android.view.MotionEvent;
+import android.view.SurfaceHolder;
+
+/*
+ * This animated wallpaper draws a rotating wireframe shape. It is similar to
+ * example #1, but has a choice of 2 shapes, which are user selectable and
+ * defined in resources instead of in code.
+ */
+
+public class CubeWallpaper2 extends WallpaperService {
+
+ public static final String SHARED_PREFS_NAME="cube2settings";
+
+ static class ThreeDPoint {
+ float x;
+ float y;
+ float z;
+ }
+
+ static class ThreeDLine {
+ int startPoint;
+ int endPoint;
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ public Engine onCreateEngine() {
+ return new CubeEngine();
+ }
+
+ class CubeEngine extends Engine
+ implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+ private final Handler mHandler = new Handler();
+
+ ThreeDPoint [] mOriginalPoints;
+ ThreeDPoint [] mRotatedPoints;
+ ThreeDLine [] mLines;
+ private final Paint mPaint = new Paint();
+ private float mOffset;
+ private float mTouchX = -1;
+ private float mTouchY = -1;
+ private long mStartTime;
+ private float mCenterX;
+ private float mCenterY;
+
+ private final Runnable mDrawCube = new Runnable() {
+ public void run() {
+ drawFrame();
+ }
+ };
+ private boolean mVisible;
+ private SharedPreferences mPrefs;
+
+ CubeEngine() {
+ // Create a Paint to draw the lines for our cube
+ final Paint paint = mPaint;
+ paint.setColor(0xffffffff);
+ paint.setAntiAlias(true);
+ paint.setStrokeWidth(2);
+ paint.setStrokeCap(Paint.Cap.ROUND);
+ paint.setStyle(Paint.Style.STROKE);
+
+ mStartTime = SystemClock.elapsedRealtime();
+
+ mPrefs = CubeWallpaper2.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
+ mPrefs.registerOnSharedPreferenceChangeListener(this);
+ onSharedPreferenceChanged(mPrefs, null);
+ }
+
+ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
+
+ String shape = prefs.getString("cube2_shape", "cube");
+
+ // read the 3D model from the resource
+ readModel(shape);
+ }
+
+ private void readModel(String prefix) {
+ // Read the model definition in from a resource.
+
+ // get the resource identifiers for the arrays for the selected shape
+ int pid = getResources().getIdentifier(prefix + "points", "array", getPackageName());
+ int lid = getResources().getIdentifier(prefix + "lines", "array", getPackageName());
+
+ String [] p = getResources().getStringArray(pid);
+ int numpoints = p.length;
+ mOriginalPoints = new ThreeDPoint[numpoints];
+ mRotatedPoints = new ThreeDPoint[numpoints];
+
+ for (int i = 0; i < numpoints; i++) {
+ mOriginalPoints[i] = new ThreeDPoint();
+ mRotatedPoints[i] = new ThreeDPoint();
+ String [] coord = p[i].split(" ");
+ mOriginalPoints[i].x = Float.valueOf(coord[0]);
+ mOriginalPoints[i].y = Float.valueOf(coord[1]);
+ mOriginalPoints[i].z = Float.valueOf(coord[2]);
+ }
+
+ String [] l = getResources().getStringArray(lid);
+ int numlines = l.length;
+ mLines = new ThreeDLine[numlines];
+
+ for (int i = 0; i < numlines; i++) {
+ mLines[i] = new ThreeDLine();
+ String [] idx = l[i].split(" ");
+ mLines[i].startPoint = Integer.valueOf(idx[0]);
+ mLines[i].endPoint = Integer.valueOf(idx[1]);
+ }
+ }
+
+ @Override
+ public void onCreate(SurfaceHolder surfaceHolder) {
+ super.onCreate(surfaceHolder);
+ setTouchEventsEnabled(true);
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ mHandler.removeCallbacks(mDrawCube);
+ }
+
+ @Override
+ public void onVisibilityChanged(boolean visible) {
+ mVisible = visible;
+ if (visible) {
+ drawFrame();
+ } else {
+ mHandler.removeCallbacks(mDrawCube);
+ }
+ }
+
+ @Override
+ public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ super.onSurfaceChanged(holder, format, width, height);
+ // store the center of the surface, so we can draw the cube in the right spot
+ mCenterX = width/2.0f;
+ mCenterY = height/2.0f;
+ drawFrame();
+ }
+
+ @Override
+ public void onSurfaceCreated(SurfaceHolder holder) {
+ super.onSurfaceCreated(holder);
+ }
+
+ @Override
+ public void onSurfaceDestroyed(SurfaceHolder holder) {
+ super.onSurfaceDestroyed(holder);
+ mVisible = false;
+ mHandler.removeCallbacks(mDrawCube);
+ }
+
+ @Override
+ public void onOffsetsChanged(float xOffset, float yOffset, int xPixels, int yPixels) {
+ mOffset = xOffset;
+ drawFrame();
+ }
+
+ /*
+ * Store the position of the touch event so we can use it for drawing later
+ */
+ @Override
+ public void onTouchEvent(MotionEvent event) {
+ if (event.getAction() == MotionEvent.ACTION_MOVE) {
+ mTouchX = event.getX();
+ mTouchY = event.getY();
+ } else {
+ mTouchX = -1;
+ mTouchY = -1;
+ }
+ super.onTouchEvent(event);
+ }
+
+ /*
+ * Draw one frame of the animation. This method gets called repeatedly
+ * by posting a delayed Runnable. You can do any drawing you want in
+ * here. This example draws a wireframe cube.
+ */
+ void drawFrame() {
+ final SurfaceHolder holder = getSurfaceHolder();
+ final Rect frame = holder.getSurfaceFrame();
+ final int width = frame.width();
+ final int height = frame.height();
+
+ Canvas c = null;
+ try {
+ c = holder.lockCanvas();
+ if (c != null) {
+ // draw something
+ drawCube(c);
+ drawTouchPoint(c);
+ }
+ } finally {
+ if (c != null) holder.unlockCanvasAndPost(c);
+ }
+
+ mHandler.removeCallbacks(mDrawCube);
+ if (mVisible) {
+ mHandler.postDelayed(mDrawCube, 1000 / 25);
+ }
+ }
+
+ void drawCube(Canvas c) {
+ c.save();
+ c.translate(mCenterX, mCenterY);
+ c.drawColor(0xff000000);
+
+ long now = SystemClock.elapsedRealtime();
+ float xrot = ((float)(now - mStartTime)) / 1000;
+ float yrot = (0.5f - mOffset) * 2.0f;
+ rotateAndProjectPoints(xrot, yrot);
+ drawLines(c);
+ c.restore();
+ }
+
+ void rotateAndProjectPoints(float xrot, float yrot) {
+ int n = mOriginalPoints.length;
+ for (int i = 0; i < n; i++) {
+ // rotation around X-axis
+ ThreeDPoint p = mOriginalPoints[i];
+ float x = p.x;
+ float y = p.y;
+ float z = p.z;
+ float newy = (float)(Math.sin(xrot) * z + Math.cos(xrot) * y);
+ float newz = (float)(Math.cos(xrot) * z - Math.sin(xrot) * y);
+
+ // rotation around Y-axis
+ float newx = (float)(Math.sin(yrot) * newz + Math.cos(yrot) * x);
+ newz = (float)(Math.cos(yrot) * newz - Math.sin(yrot) * x);
+
+ // 3D-to-2D projection
+ float screenX = newx / (4 - newz / 400);
+ float screenY = newy / (4 - newz / 400);
+
+ mRotatedPoints[i].x = screenX;
+ mRotatedPoints[i].y = screenY;
+ mRotatedPoints[i].z = 0;
+ }
+ }
+
+ void drawLines(Canvas c) {
+ int n = mLines.length;
+ for (int i = 0; i < n; i++) {
+ ThreeDLine l = mLines[i];
+ ThreeDPoint start = mRotatedPoints[l.startPoint];
+ ThreeDPoint end = mRotatedPoints[l.endPoint];
+ c.drawLine(start.x, start.y, end.x, end.y, mPaint);
+ }
+ }
+
+ void drawTouchPoint(Canvas c) {
+ if (mTouchX >=0 && mTouchY >= 0) {
+ c.drawCircle(mTouchX, mTouchY, 80, mPaint);
+ }
+ }
+ }
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2Settings.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2Settings.java
new file mode 100644
index 0000000..feeb0bd
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube2/CubeWallpaper2Settings.java
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+package com.android.livecubes.cube2;
+
+import com.android.livecubes.R;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.service.wallpaper.WallpaperSettingsActivity;
+
+public class CubeWallpaper2Settings extends WallpaperSettingsActivity
+ implements SharedPreferences.OnSharedPreferenceChangeListener {
+
+ @Override
+ protected void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ getPreferenceManager().setSharedPreferencesName(
+ CubeWallpaper2.SHARED_PREFS_NAME);
+ addPreferencesFromResource(R.xml.cube2_settings);
+ getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(
+ this);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ protected void onDestroy() {
+ getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
+ this);
+ super.onDestroy();
+ }
+
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
+ String key) {
+ //(new BackupManager(this)).dataChanged();
+ }
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/Cube3RS.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/Cube3RS.java
new file mode 100644
index 0000000..5cfad14
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/Cube3RS.java
@@ -0,0 +1,242 @@
+/*
+ * 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.livecubes.cube3;
+
+import com.android.livecubes.R;
+import com.android.livecubes.RenderScriptScene;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Primitive;
+import android.renderscript.ProgramRaster;
+import android.renderscript.ProgramVertex;
+import android.renderscript.ScriptC;
+import android.renderscript.SimpleMesh;
+import android.renderscript.Type;
+import android.renderscript.Element.Builder;
+
+import java.util.TimeZone;
+
+/*
+ * This example draws a shape whose definition is read from resources (though
+ * it's not user selectable like in example #2), but does the drawing using
+ * RenderScript.
+ */
+class Cube3RS extends RenderScriptScene {
+
+ static class ThreeDPoint {
+ public float x;
+ public float y;
+ public float z;
+ }
+
+ static class ThreeDLine {
+ int startPoint;
+ int endPoint;
+ }
+
+ static class WorldState {
+ public float yRotation;
+ public float mCenterX;
+ public float mCenterY;
+ }
+ ThreeDPoint [] mOriginalPoints;
+ ThreeDLine [] mLines;
+
+ WorldState mWorldState = new WorldState();
+ private Type mStateType;
+ private Allocation mState;
+
+ private SimpleMesh mCubeMesh;
+
+ private Allocation mPointAlloc;
+ private float [] mPointData;
+
+ private Allocation mLineIdxAlloc;
+ private short [] mIndexData;
+
+ private ProgramVertex mPVBackground;
+ private ProgramVertex.MatrixAllocation mPVAlloc;
+
+ private int mWidth;
+ private int mHeight;
+
+ private static final int RSID_STATE = 0;
+ private static final int RSID_POINTS = 1;
+ private static final int RSID_LINES = 2;
+ private static final int RSID_PROGRAMVERTEX = 3;
+
+
+ Cube3RS(int width, int height) {
+ super(width, height);
+ mWidth = width;
+ mHeight = height;
+ }
+
+ @Override
+ public void resize(int width, int height) {
+ super.resize(width, height);
+ mWidth = width;
+ mHeight = height;
+ }
+
+ @Override
+ protected ScriptC createScript() {
+
+ // Read the model in to our point/line objects
+ readModel();
+
+ // Create a renderscript type from a java class. The specified name doesn't
+ // really matter; the name by which we refer to the object in RenderScript
+ // will be specified later.
+ mStateType = Type.createFromClass(mRS, WorldState.class, 1, "WorldState");
+ // Create an allocation from the type we just created.
+ mState = Allocation.createTyped(mRS, mStateType);
+ // set our java object as the data for the renderscript allocation
+ mWorldState.yRotation = (-0.5f) * 2 * 180 / (float) Math.PI;
+ mState.data(mWorldState);
+
+ /*
+ * Now put our model in to a form that renderscript can work with:
+ * - create a buffer of floats that are the coordinates for the points that define the cube
+ * - create a buffer of integers that are the indices of the points that form lines
+ * - combine the two in to a mesh
+ */
+
+ // First set up the coordinate system and such
+ ProgramVertex.Builder pvb = new ProgramVertex.Builder(mRS, null, null);
+ mPVBackground = pvb.create();
+ mPVBackground.setName("PVBackground");
+ mPVAlloc = new ProgramVertex.MatrixAllocation(mRS);
+ mPVBackground.bindAllocation(mPVAlloc);
+ mPVAlloc.setupProjectionNormalized(mWidth, mHeight);
+
+ // Start creating the mesh
+ final SimpleMesh.Builder meshBuilder = new SimpleMesh.Builder(mRS);
+
+ // Create the Element for the points
+ Builder elementBuilder = new Builder(mRS);
+ // By specifying a prefix, even an empty one, the members will be accessible
+ // in the renderscript. If we just called addFloatXYZ(), the members would be
+ // unnamed in the renderscript struct definition.
+ elementBuilder.addFloatXYZ("");
+ final Element vertexElement = elementBuilder.create();
+ final int vertexSlot = meshBuilder.addVertexType(vertexElement, mOriginalPoints.length);
+ // Specify the type and number of indices we need. We'll allocate them later.
+ meshBuilder.setIndexType(Element.INDEX_16(mRS), mLines.length * 2);
+ // This will be a line mesh
+ meshBuilder.setPrimitive(Primitive.LINE);
+
+ // Create the Allocation for the vertices
+ mCubeMesh = meshBuilder.create();
+ mCubeMesh.setName("CubeMesh");
+ mPointAlloc = mCubeMesh.createVertexAllocation(vertexSlot);
+ mPointAlloc.setName("PointBuffer");
+
+ // Create the Allocation for the indices
+ mLineIdxAlloc = mCubeMesh.createIndexAllocation();
+
+ // Bind the allocations to the mesh
+ mCubeMesh.bindVertexAllocation(mPointAlloc, 0);
+ mCubeMesh.bindIndexAllocation(mLineIdxAlloc);
+
+ /*
+ * put the vertex and index data in their respective buffers
+ */
+ // one float each for x, y and z, and the 4th float will hold rgba
+ mPointData = new float[mOriginalPoints.length * 3];
+ for(int i = 0; i < mOriginalPoints.length; i ++) {
+ mPointData[i*3] = mOriginalPoints[i].x;
+ mPointData[i*3+1] = mOriginalPoints[i].y;
+ mPointData[i*3+2] = mOriginalPoints[i].z;
+ }
+ mIndexData = new short[mLines.length * 2];
+ for(int i = 0; i < mLines.length; i++) {
+ mIndexData[i * 2] = (short)(mLines[i].startPoint);
+ mIndexData[i * 2 + 1] = (short)(mLines[i].endPoint);
+ }
+
+ /*
+ * upload the vertex and index data
+ */
+ mPointAlloc.data(mPointData);
+ mPointAlloc.uploadToBufferObject();
+ mLineIdxAlloc.data(mIndexData);
+ mLineIdxAlloc.uploadToBufferObject();
+
+ // Time to create the script
+ ScriptC.Builder sb = new ScriptC.Builder(mRS);
+ // Specify the name by which to refer to the WorldState object in the
+ // renderscript.
+ sb.setType(mStateType, "State", RSID_STATE);
+ sb.setType(mCubeMesh.getVertexType(0), "Points", RSID_POINTS);
+ // this crashes when uncommented
+ //sb.setType(mCubeMesh.getIndexType(), "Lines", RSID_LINES);
+
+ // Set the render script that will make use of the objects we defined above
+ sb.setScript(mResources, R.raw.cube);
+ sb.setRoot(true);
+
+ ScriptC script = sb.create();
+ script.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+ script.setTimeZone(TimeZone.getDefault().getID());
+
+ script.bindAllocation(mState, RSID_STATE);
+ script.bindAllocation(mPointAlloc, RSID_POINTS);
+ script.bindAllocation(mLineIdxAlloc, RSID_LINES);
+ script.bindAllocation(mPVAlloc.mAlloc, RSID_PROGRAMVERTEX);
+
+ return script;
+ }
+
+ @Override
+ public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
+ // update our state, then push it to the renderscript
+ mWorldState.yRotation = (xOffset - 0.5f) * 2 * 180 / (float) Math.PI;
+ mState.data(mWorldState);
+ }
+
+ /*
+ * Read the model definition from the resource.
+ */
+ private void readModel() {
+
+ String [] p = mResources.getStringArray(R.array.cubepoints);
+ int numpoints = p.length;
+ mOriginalPoints = new ThreeDPoint[numpoints];
+
+ for (int i = 0; i < numpoints; i++) {
+ mOriginalPoints[i] = new ThreeDPoint();
+ String [] coord = p[i].split(" ");
+ mOriginalPoints[i].x = Float.valueOf(coord[0]);
+ mOriginalPoints[i].y = Float.valueOf(coord[1]);
+ mOriginalPoints[i].z = Float.valueOf(coord[2]);
+ }
+
+ String [] l = mResources.getStringArray(R.array.cubelines);
+ int numlines = l.length;
+ mLines = new ThreeDLine[numlines];
+
+ for (int i = 0; i < numlines; i++) {
+ mLines[i] = new ThreeDLine();
+ String [] idx = l[i].split(" ");
+ mLines[i].startPoint = Integer.valueOf(idx[0]);
+ mLines[i].endPoint = Integer.valueOf(idx[1]);
+ }
+ }
+
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/CubeWallpaper3.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/CubeWallpaper3.java
new file mode 100644
index 0000000..8f09388
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/CubeWallpaper3.java
@@ -0,0 +1,28 @@
+/*
+ * 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.livecubes.cube3;
+
+import com.android.livecubes.RenderScriptWallpaper;
+
+public class CubeWallpaper3 extends RenderScriptWallpaper<Cube3RS> {
+
+ @Override
+ protected Cube3RS createScene(int width, int height) {
+ return new Cube3RS(width, height);
+ }
+}
+
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptScene.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptScene.java
new file mode 100644
index 0000000..429e93d
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptScene.java
@@ -0,0 +1,86 @@
+/*
+ * 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.livecubes;
+
+import android.content.res.Resources;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptC;
+
+public abstract class RenderScriptScene {
+ protected int mWidth;
+ protected int mHeight;
+ protected boolean mPreview;
+ protected Resources mResources;
+ protected RenderScript mRS;
+ protected ScriptC mScript;
+
+ public RenderScriptScene(int width, int height) {
+ mWidth = width;
+ mHeight = height;
+ }
+
+ public void init(RenderScript rs, Resources res, boolean isPreview) {
+ mRS = rs;
+ mResources = res;
+ mPreview = isPreview;
+ mScript = createScript();
+ }
+
+ public boolean isPreview() {
+ return mPreview;
+ }
+
+ public int getWidth() {
+ return mWidth;
+ }
+
+ public int getHeight() {
+ return mHeight;
+ }
+
+ public Resources getResources() {
+ return mResources;
+ }
+
+ public RenderScript getRS() {
+ return mRS;
+ }
+
+ public ScriptC getScript() {
+ return mScript;
+ }
+
+ protected abstract ScriptC createScript();
+
+ public void stop() {
+ mRS.contextBindRootScript(null);
+ }
+
+ public void start() {
+ mRS.contextBindRootScript(mScript);
+ }
+
+ public void resize(int width, int height) {
+ mWidth = width;
+ mHeight = height;
+ }
+
+ @SuppressWarnings({"UnusedDeclaration"})
+ public void setOffset(float xOffset, float yOffset, int xPixels, int yPixels) {
+ }
+}
diff --git a/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptWallpaper.java b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptWallpaper.java
new file mode 100644
index 0000000..c30a619
--- /dev/null
+++ b/samples/CubeLiveWallpaper/src/com/android/livecubes/cube3/RenderScriptWallpaper.java
@@ -0,0 +1,106 @@
+/*
+ * 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.livecubes;
+
+import android.service.wallpaper.WallpaperService;
+import android.renderscript.RenderScript;
+import android.view.SurfaceHolder;
+import android.view.Surface;
+
+public abstract class RenderScriptWallpaper<T extends RenderScriptScene> extends WallpaperService {
+ public Engine onCreateEngine() {
+ return new RenderScriptEngine();
+ }
+
+ protected abstract T createScene(int width, int height);
+
+ private class RenderScriptEngine extends Engine {
+ private RenderScript mRs;
+ private T mRenderer;
+
+ @Override
+ public void onCreate(SurfaceHolder surfaceHolder) {
+ super.onCreate(surfaceHolder);
+ setTouchEventsEnabled(false);
+ surfaceHolder.setSizeFromLayout();
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ destroyRenderer();
+ }
+
+ private void destroyRenderer() {
+ if (mRenderer != null) {
+ mRenderer.stop();
+ mRenderer = null;
+ }
+ if (mRs != null) {
+ mRs.destroy();
+ mRs = null;
+ }
+ }
+
+ @Override
+ public void onVisibilityChanged(boolean visible) {
+ super.onVisibilityChanged(visible);
+ if (mRenderer != null) {
+ if (visible) {
+ mRenderer.start();
+ } else {
+ mRenderer.stop();
+ }
+ }
+ }
+
+ @Override
+ public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+ super.onSurfaceChanged(holder, format, width, height);
+ if (mRenderer == null) {
+ mRenderer = createScene(width, height);
+ mRenderer.init(mRs, getResources(), isPreview());
+ mRenderer.start();
+ } else {
+ mRenderer.resize(width, height);
+ }
+ }
+
+ @Override
+ public void onOffsetsChanged(float xOffset, float yOffset, int xPixels, int yPixels) {
+ mRenderer.setOffset(xOffset, yOffset, xPixels, yPixels);
+ }
+
+ @Override
+ public void onSurfaceCreated(SurfaceHolder holder) {
+ super.onSurfaceCreated(holder);
+
+ Surface surface = null;
+ while (surface == null) {
+ surface = holder.getSurface();
+ }
+ mRs = new RenderScript(surface, false, false);
+ }
+
+ @Override
+ public void onSurfaceDestroyed(SurfaceHolder holder) {
+ super.onSurfaceDestroyed(holder);
+ destroyRenderer();
+ }
+ }
+}
diff --git a/testrunner/test_defs.xml b/testrunner/test_defs.xml
index 04fcf99..adb854e 100644
--- a/testrunner/test_defs.xml
+++ b/testrunner/test_defs.xml
@@ -317,6 +317,13 @@
coverage_target="framework"
cts="true" />
+<test name="cts-webkit"
+ build_path="cts/tests/tests/webkit"
+ package="com.android.cts.webkit"
+ runner="android.test.InstrumentationCtsTestRunner"
+ coverage_target="framework"
+ cts="true" />
+
<test name="cts-widget"
build_path="cts/tests/tests/widget"
package="com.android.cts.widget"
diff --git a/tools/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java b/tools/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java
index e2d8c35..a70086d 100644
--- a/tools/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java
+++ b/tools/layoutopt/libs/uix/src/com/android/layoutopt/uix/groovy/LayoutAnalysisCategory.java
@@ -35,6 +35,11 @@
* to {@link com.android.layoutopt.uix.LayoutAnalysis} and {@link org.w3c.dom.Node}.
*/
public class LayoutAnalysisCategory {
+ private static final String ANDROID_PADDING = "android:padding";
+ private static final String ANDROID_PADDING_LEFT = "android:paddingLeft";
+ private static final String ANDROID_PADDING_TOP = "android:paddingTop";
+ private static final String ANDROID_PADDING_RIGHT = "android:paddingRight";
+ private static final String ANDROID_PADDING_BOTTOM = "android:paddingBottom";
private static final String ANDROID_LAYOUT_WIDTH = "android:layout_width";
private static final String ANDROID_LAYOUT_HEIGHT = "android:layout_height";
private static final String VALUE_FILL_PARENT = "fill_parent";
@@ -98,8 +103,20 @@
node.getUserData(XmlDocumentBuilder.NODE_END_LINE);
return data == null ? -1 : (Integer) data;
}
-
-
+
+ /**
+ * xmlNode.hasPadding()
+ *
+ * @return True if the node has one ore more padding attributes.
+ */
+ public static boolean hasPadding(Element element) {
+ return element.getAttribute(ANDROID_PADDING).length() > 0 ||
+ element.getAttribute(ANDROID_PADDING_LEFT).length() > 0 ||
+ element.getAttribute(ANDROID_PADDING_TOP).length() > 0 ||
+ element.getAttribute(ANDROID_PADDING_BOTTOM).length() > 0 ||
+ element.getAttribute(ANDROID_PADDING_RIGHT).length() > 0;
+ }
+
/**
* Returns whether this node's width is fill_parent.
*/
diff --git a/tools/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule b/tools/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule
index 2221036..d3fc3d9 100644
--- a/tools/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule
+++ b/tools/layoutopt/libs/uix/src/resources/rules/MergeRootFrameLayout.rule
@@ -8,9 +8,11 @@
// - The node is a FrameLayout
// - The node is fill_parent in both orientation *or* it has no layout_gravity
// - The node does not have a background nor a foreground
+// - The node does not have padding
if (node.isRoot() && node.is("FrameLayout") && !node.'@android:background' &&
!node.'@android:foreground' && ((node.isWidthFillParent() &&
- node.isHeightFillParent()) || !node.'@android:layout_gravity')) {
+ node.isHeightFillParent()) || !node.'@android:layout_gravity') &&
+ !node.hasPadding()) {
analysis << "The root-level <FrameLayout/> can be replaced with <merge/>"
}
diff --git a/tools/monkeyrunner/src/Android.mk b/tools/monkeyrunner/src/Android.mk
index 576025a..fb6b9c1 100644
--- a/tools/monkeyrunner/src/Android.mk
+++ b/tools/monkeyrunner/src/Android.mk
@@ -21,9 +21,31 @@
LOCAL_JAR_MANIFEST := ../etc/manifest.txt
LOCAL_JAVA_LIBRARIES := \
ddmlib \
- jython
+ jython \
+ xmlwriter
LOCAL_MODULE := monkeyrunner
include $(BUILD_HOST_JAVA_LIBRARY)
+
+# Build ext.jar
+# ============================================================
+
+ext_dirs := ../../../../external/xmlwriter/src
+
+ext_src_files := $(call all-java-files-under,$(ext_dirs))
+
+# ==== the library =========================================
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(ext_src_files)
+
+LOCAL_NO_STANDARD_LIBRARIES := true
+#LOCAL_JAVA_LIBRARIES := core
+#LOCAL_STATIC_JAVA_LIBRARIES := libgoogleclient
+
+LOCAL_MODULE := xmlwriter
+
+include $(BUILD_HOST_JAVA_LIBRARY)
+
diff --git a/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRecorder.java b/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRecorder.java
new file mode 100644
index 0000000..efc002b
--- /dev/null
+++ b/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRecorder.java
@@ -0,0 +1,312 @@
+/*
+ * 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.monkeyrunner;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.jheer.XMLWriter;
+
+/**
+ * MonkeyRecorder is a host side class that records the output of scripts that are run.
+ * It creates a unique directory, puts in an xml file that records each cmd and result.
+ * It stores every screenshot in this directory.
+ * When finished, it zips this all up.
+ *
+ * Calling Sequence:
+ * mr = new MonkeyRecorder(scriptName);
+ * mr.startCommand();
+ * [mr.addAttribute(name, value);]
+ * ...
+ * [mr.addInput(cmd);]
+ * [mr.addResults(result, filename);] // filename = "" if no screenshot
+ * mr.endCommand();
+ * mr.addComment(comment);
+ * mr.startCommand();
+ * ...
+ * mr.endCommand();
+ * ...
+ * mr.close();
+ *
+ * With MonkeyRunner this should output an xml file, <script_name>-yyyyMMdd-HH:mm:ss.xml, into the
+ * directory out/<script_name>-yyyyMMdd-HH:mm:ss with the contents:
+ *
+ * <?xml version="1.0" encoding='UTF-8'?>
+ * <script_run>
+ * script_name="filename"
+ * monkeyRunnerVersion="0.2"
+ * <!-- Device specific variables -->
+ * <device_var var_name="name" var_value="value" />
+ * <device_var name="build.display" value="opal-userdebug 1.6 DRC79 14207 test-keys"/>
+ * ...
+ * <!-- Script commands -->
+ * <command>
+ * dateTime="20090921-17:08:43"
+ * <input cmd="Pressing: menu"/>
+ * <response result="OK" dateTime="20090921-17:08:43"/>
+ * </command>
+ * ...
+ * <command>
+ * dateTime="20090921-17:09:44"
+ * <input cmd="grabscreen"/>
+ * <response result="OK" dateTime="20090921-17:09:45" screenshot="home_screen-20090921-17:09:45.png"/>
+ * </command>
+ * ...
+ * </script_run>
+ *
+ * And then zip it up with all the screenshots in the file: <script_name>-yyyyMMdd-HH:mm:ss.zip.
+ */
+
+public class MonkeyRecorder {
+
+ // xml file to store output results in
+ private static String mXmlFilename;
+ private static FileWriter mXmlFile;
+ private static XMLWriter mXmlWriter;
+
+ // unique subdirectory to put results in (screenshots and xml file)
+ private static String mDirname;
+ private static List<String> mScreenShotNames = new ArrayList<String>();
+
+ // where we store all the results for all the script runs
+ private static final String ROOT_DIR = "out";
+
+ // for getting the date and time in now()
+ private static final SimpleDateFormat SIMPLE_DATE_TIME_FORMAT = new SimpleDateFormat("yyyyMMdd-HH:mm:ss");
+
+ /**
+ * Create a new MonkeyRecorder that records commands and zips up screenshots for submittal
+ *
+ * @param scriptName filepath of the monkey script we are running
+ */
+ public MonkeyRecorder(String scriptName) throws IOException {
+ // Create directory structure to store xml file, images and zips
+ File scriptFile = new File(scriptName);
+ scriptName = scriptFile.getName(); // Get rid of path
+ mDirname = ROOT_DIR + "/" + stripType(scriptName) + "-" + now();
+ new File(mDirname).mkdirs();
+
+ // Initialize xml file
+ mXmlFilename = stampFilename(stripType(scriptName) + ".xml");
+ initXmlFile(scriptName);
+ }
+
+ // Get the current date and time in a simple string format (used for timestamping filenames)
+ private static String now() {
+ return SIMPLE_DATE_TIME_FORMAT.format(Calendar.getInstance().getTime());
+ }
+
+ /**
+ * Initialize the xml file writer
+ *
+ * @param scriptName filename (not path) of the monkey script, stored as attribute in the xml file
+ */
+ private static void initXmlFile(String scriptName) throws IOException {
+ mXmlFile = new FileWriter(mDirname + "/" + mXmlFilename);
+ mXmlWriter = new XMLWriter(mXmlFile);
+ mXmlWriter.begin();
+ mXmlWriter.comment("Monkey Script Results");
+ mXmlWriter.start("script_run");
+ mXmlWriter.addAttribute("script_name", scriptName);
+ }
+
+ /**
+ * Add a comment to the xml file.
+ *
+ * @param comment comment to add to the xml file
+ */
+ public static void addComment(String comment) throws IOException {
+ mXmlWriter.comment(comment);
+ }
+
+ /**
+ * Begin writing a command xml element
+ */
+ public static void startCommand() throws IOException {
+ mXmlWriter.start("command");
+ mXmlWriter.addAttribute("dateTime", now());
+ }
+
+ /**
+ * Write a command name attribute in a command xml element.
+ * It's add as a sinlge script command could be multiple monkey commands.
+ *
+ * @param cmd command sent to the monkey
+ */
+ public static void addInput(String cmd) throws IOException {
+ String name = "cmd";
+ String value = cmd;
+ mXmlWriter.tag("input", name, value);
+ }
+
+ /**
+ * Write a response xml element in a command.
+ * Attributes include the monkey result, datetime, and possibly screenshot filename
+ *
+ * @param result response of the monkey to the command
+ * @param filename filename of the screen shot (or other file to be included)
+ */
+ public static void addResult(String result, String filename) throws IOException {
+ int num_args = 2;
+ String[] names = new String[3];
+ String[] values = new String[3];
+ names[0] = "result";
+ values[0] = result;
+ names[1] = "dateTime";
+ values[1] = now();
+ if (filename.length() != 0) {
+ names[2] = "screenshot";
+ values[2] = stampFilename(filename);
+ addScreenShot(filename);
+ num_args = 3;
+ }
+ mXmlWriter.tag("response", names, values, num_args);
+ }
+
+ /**
+ * Add an attribut to an xml element. name="escaped_value"
+ *
+ * @param name name of the attribute
+ * @param value value of the attribute
+ */
+ public static void addAttribute(String name, String value) throws IOException {
+ mXmlWriter.addAttribute(name, value);
+ }
+
+ /**
+ * Add an xml device variable element. name="escaped_value"
+ *
+ * @param name name of the variable
+ * @param value value of the variable
+ */
+ public static void addDeviceVar(String name, String value) throws IOException {
+ String[] names = {"name", "value"};
+ String[] values = {name, value};
+ mXmlWriter.tag("device_var", names, values, names.length);
+ }
+
+ /**
+ * Move the screenshot to storage and remember you did it so it can be zipped up later.
+ *
+ * @param filename file name of the screenshot to be stored (Not path name)
+ */
+ private static void addScreenShot(String filename) {
+ File file = new File(filename);
+ String screenShotName = stampFilename(filename);
+ file.renameTo(new File(mDirname, screenShotName));
+ mScreenShotNames.add(screenShotName);
+ }
+
+ /**
+ * Finish writing a command xml element
+ */
+ public static void endCommand() throws IOException {
+ mXmlWriter.end();
+ }
+
+ /**
+ * Add datetime in front of filetype (the stuff after and including the last infamous '.')
+ *
+ * @param filename path of file to be stamped
+ */
+ private static String stampFilename(String filename) {
+ //
+ int typeIndex = filename.lastIndexOf('.');
+ if (typeIndex == -1) {
+ return filename + "-" + now();
+ }
+ return filename.substring(0, typeIndex) + "-" + now() + filename.substring(typeIndex);
+ }
+
+ /**
+ * Strip out the file type (the stuff after and including the last infamous '.')
+ *
+ * @param filename path of file to be stripped of type information
+ */
+ private static String stripType(String filename) {
+ //
+ int typeIndex = filename.lastIndexOf('.');
+ if (typeIndex == -1)
+ return filename;
+ return filename.substring(0, typeIndex);
+ }
+
+ /**
+ * Add a signature element
+ *
+ * @param filename path of file to be signatured
+ */
+ private static void addMD5Signature(String filename) throws IOException {
+ String signature = "";
+ // find signature... MD5 sig = new MD5(filename); signature = sig.toString();
+ String[] names = new String[] { "type", "filename", "signature" };
+ String[] values = new String[] { "md5", filename, signature };
+ mXmlWriter.tag("Signature", names, values, values.length);
+ }
+
+
+ /**
+ * Close the monkeyRecorder by closing the xml file and zipping it up with the screenshots.
+ *
+ * @param filename path of file to be stripped of type information
+ */
+ public static void close() throws IOException {
+ // zip up xml file and screenshots into ROOT_DIR.
+ byte[] buf = new byte[1024];
+ String zipFileName = mXmlFilename + ".zip";
+ endCommand();
+ mXmlFile.close();
+ FileOutputStream zipFile = new FileOutputStream(ROOT_DIR + "/" + zipFileName);
+ ZipOutputStream out = new ZipOutputStream(zipFile);
+
+ // add the xml file
+ addFileToZip(out, mDirname + "/" + mXmlFilename, buf);
+
+ // Add the screenshots
+ for (String filename : mScreenShotNames) {
+ addFileToZip(out, mDirname + "/" + filename, buf);
+ }
+ out.close();
+ }
+
+ /**
+ * Helper function to zip up a file into an open zip archive.
+ *
+ * @param zip the stream of the zip archive
+ * @param filepath the filepath of the file to be added to the zip archive
+ * @param buf storage place to stage reads of file before zipping
+ */
+ private static void addFileToZip(ZipOutputStream zip, String filepath, byte[] buf) throws IOException {
+ FileInputStream in = new FileInputStream(filepath);
+ zip.putNextEntry(new ZipEntry(filepath));
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ zip.write(buf, 0, len);
+ }
+ zip.closeEntry();
+ in.close();
+ }
+}
diff --git a/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java b/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java
index cbc881c..07a4739 100644
--- a/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java
+++ b/tools/monkeyrunner/src/com/android/monkeyrunner/MonkeyRunner.java
@@ -30,18 +30,21 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.imageio.ImageIO;
/**
* MonkeyRunner is a host side application to control a monkey instance on a
- * device. MonkeyRunner provides some useful helper functions to control the
- * device as well as various other methods to help script tests.
+ * device. MonkeyRunner provides some useful helper functions to control the
+ * device as well as various other methods to help script tests.
*/
public class MonkeyRunner {
@@ -50,27 +53,46 @@
static Socket monkeySocket = null;
static IDevice monkeyDevice;
-
+
static BufferedReader monkeyReader;
static BufferedWriter monkeyWriter;
+ static String monkeyResponse;
+
+ static MonkeyRecorder monkeyRecorder;
static String scriptName = null;
+
+ // Obtain a suitable logger.
+ private static Logger logger = Logger.getLogger("com.android.monkeyrunner");
// delay between key events
final static int KEY_INPUT_DELAY = 1000;
+
+ // version of monkey runner
+ final static String monkeyRunnerVersion = "0.31";
- public static void main(String[] args) {
+ // TODO: interface cmd; class xml tags; fix logger; test class/script
+ public static void main(String[] args) throws IOException {
+
+ // haven't figure out how to get below INFO...bad parent. Pass -v INFO to turn on logging
+ logger.setLevel(Level.parse("WARNING"));
processOptions(args);
+ logger.info("initAdb");
initAdbConnection();
+ logger.info("openMonkeyConnection");
openMonkeyConnection();
+ logger.info("start_script");
start_script();
+ logger.info("ScriptRunner.run");
ScriptRunner.run(scriptName);
+ logger.info("end_script");
end_script();
+ logger.info("closeMonkeyConnection");
closeMonkeyConnection();
}
@@ -166,13 +188,15 @@
try {
InetAddress addr = InetAddress.getByName(monkeyServer);
monkeySocket = new Socket(addr, monkeyPort);
+ monkeyWriter = new BufferedWriter(new OutputStreamWriter(monkeySocket.getOutputStream()));
+ monkeyReader = new BufferedReader(new InputStreamReader(monkeySocket.getInputStream()));
} catch (UnknownHostException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
}
}
-
+
/**
* Close tcp session with the monkey on the device
*
@@ -189,47 +213,59 @@
}
/**
- * This is a house cleaning type routine to run before starting a script. Puts
- * the device in a known state.
+ * This is a house cleaning routine to run before starting a script. Puts
+ * the device in a known state and starts recording interesting info.
*/
- public static void start_script() {
- press("menu");
- press("menu");
- press("home");
+ public static void start_script() throws IOException {
+ press("menu", false);
+ press("menu", false);
+ press("home", false);
+
+ // Start recording the script output, might want md5 signature of file for completeness
+ monkeyRecorder = new MonkeyRecorder(scriptName);
+
+ // Record what device and version of software we are running on
+ monkeyRecorder.addAttribute("monkeyRunnerVersion", monkeyRunnerVersion);
+ addDeviceVars();
+ monkeyRecorder.addComment("Script commands");
}
- public static void end_script() {
- String command = "END";
- sendMonkeyEvent(command);
+ /**
+ * This is a house cleaning routine to run after finishing a script.
+ * Puts the monkey server in a known state and closes the recording.
+ */
+ public static void end_script() throws IOException {
+ String command = "done";
+ sendMonkeyEvent(command, false, false);
+
+ // Stop the recording and zip up the results
+ monkeyRecorder.close();
}
/** This is a method for scripts to launch an activity on the device
*
* @param name The name of the activity to launch
*/
- public static void launch_activity(String name) {
- try {
- System.out.println("Launching: " + name);
- monkeyDevice.executeShellCommand("am start -a android.intent.action.MAIN -n "
- + name, new NullOutputReceiver());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ public static void launch_activity(String name) throws IOException {
+ System.out.println("Launching: " + name);
+ recordCommand("Launching: " + name);
+ monkeyDevice.executeShellCommand("am start -a android.intent.action.MAIN -n "
+ + name, new NullOutputReceiver());
+ // void return, so no response given, just close the command element in the xml file.
+ monkeyRecorder.endCommand();
+ }
/**
* Grabs the current state of the screen stores it as a png
*
* @param tag filename or tag descriptor of the screenshot
*/
- public static void grabscreen(String tag) {
+ public static void grabscreen(String tag) throws IOException {
tag += ".png";
try {
Thread.sleep(1000);
getDeviceImage(monkeyDevice, tag, false);
- } catch (IOException e) {
- e.printStackTrace();
} catch (InterruptedException e) {
}
}
@@ -239,9 +275,11 @@
*
* @param msec msecs to sleep for
*/
- public static void sleep(int msec) {
+ public static void sleep(int msec) throws IOException {
try {
+ recordCommand("sleep: " + msec);
Thread.sleep(msec);
+ recordResponse("OK");
} catch (InterruptedException e) {
e.printStackTrace();
}
@@ -253,12 +291,10 @@
* @param x x-coordinate
* @param y y-coordinate
*/
- public static boolean tap(int x, int y) {
- String command = "touch down " + x + " " + y + "\r\n" +
- "touch up " + x + " " + y + "\r\n";
-
- System.out.println("Tapping: " + x + ", " + y);
- return sendMonkeyEvent(command);
+ public static boolean tap(int x, int y) throws IOException {
+ String command = "tap " + x + " " + y;
+ boolean result = sendMonkeyEvent(command);
+ return result;
}
/**
@@ -266,25 +302,33 @@
*
* @param key key to press
*/
- public static boolean press(String key) {
- String command = "key down " + key + "\r\n" +
- "key up " + key + "\r\n";
+ public static boolean press(String key) throws IOException {
+ return press(key, true);
+ }
- System.out.println("Pressing: " + key);
- return sendMonkeyEvent(command);
+ /**
+ * Press function for scripts to call on a particular button or key
+ *
+ * @param key key to press
+ * @param print whether to send output to user
+ */
+ private static boolean press(String key, boolean print) throws IOException {
+ String command = "press " + key;
+ boolean result = sendMonkeyEvent(command, print, true);
+ return result;
}
/**
* dpad down function
*/
- public static boolean down() {
+ public static boolean down() throws IOException {
return press("dpad_down");
}
/**
* dpad up function
*/
- public static boolean up() {
+ public static boolean up() throws IOException {
return press("dpad_up");
}
@@ -293,69 +337,173 @@
*
* @param text text to type
*/
- public static boolean type(String text) {
- System.out.println("Typing: " + text);
- for (int i=0; i<text.length(); i++) {
- String command = "key down ";
- char c = text.charAt(i);
- if(Character.isDigit(c)) {
- command += "KEYCODE_" + c + "\n" + "key up KEYCODE_" + c + "\n";
- } else {
- command = "key down " + c + "\n" + "key up " + c + "\n";
- }
-
- if(!sendMonkeyEvent(command)) {
- System.out.println("\nERROR: Key not set \n");
- }
-
- // lets delay a bit after each input to ensure accuracy
- try {
- Thread.sleep(KEY_INPUT_DELAY);
- } catch (InterruptedException e) {
- }
+ public static boolean type(String text) throws IOException {
+ boolean result = false;
+ // text might have line ends, which signal new monkey command, so we have to eat and reissue
+ String[] lines = text.split("[\\r\\n]+");
+ for (String line: lines) {
+ result = sendMonkeyEvent("type " + line + "\n");
}
+ // return last result. Should never fail..?
+ return result;
+ }
+
+ /**
+ * Function to get a static variable from the device
+ *
+ * @param name name of static variable to get
+ */
+ public static boolean getvar(String name) throws IOException {
+ return sendMonkeyEvent("getvar " + name + "\n");
+ }
- return true;
+ /**
+ * Function to get the list of static variables from the device
+ */
+ public static boolean listvar() throws IOException {
+ return sendMonkeyEvent("listvar \n");
}
/**
* This function is the communication bridge between the host and the device.
* It sends monkey events and waits for responses over the adb tcp socket.
+ * This version if for all scripted events so that they get recorded and reported to user.
*
* @param command the monkey command to send to the device
*/
- private static boolean sendMonkeyEvent(String command) {
- try {
- monkeyWriter = new BufferedWriter(
- new OutputStreamWriter(monkeySocket.getOutputStream()));
- monkeyWriter.write(command);
- monkeyWriter.flush();
+ private static boolean sendMonkeyEvent(String command) throws IOException {
+ return sendMonkeyEvent(command, true, true);
+ }
- monkeyReader = new BufferedReader(
- new InputStreamReader(monkeySocket.getInputStream()));
- String response = monkeyReader.readLine();
+ /**
+ * This function allows the communication bridge between the host and the device
+ * to be invisible to the script for internal needs.
+ * It splits a command into monkey events and waits for responses for each over an adb tcp socket.
+ * Returns on an error, else continues and sets up last response.
+ *
+ * @param command the monkey command to send to the device
+ * @param print whether to print out the responses to the user
+ * @param record whether to put the command in the xml file that stores test outputs
+ */
+ private static boolean sendMonkeyEvent(String command, Boolean print, Boolean record) throws IOException {
+ command = command.trim();
+ if (print)
+ System.out.println("MonkeyCommand: " + command);
+ if (record)
+ recordCommand(command);
+ logger.info("Monkey Command: " + command + ".");
+
+ // send a single command and get the response
+ monkeyWriter.write(command + "\n");
+ monkeyWriter.flush();
+ monkeyResponse = monkeyReader.readLine();
- sleep(1000);
- System.out.println("MonkeyServer: " + response);
- if(response.equals("OK"))
- return true;
- if(response.equals("ERROR"))
+ if(monkeyResponse != null) {
+ // if a command returns with a response
+ if (print)
+ System.out.println("MonkeyServer: " + monkeyResponse);
+ if (record)
+ recordResponse(monkeyResponse);
+ logger.info("Monkey Response: " + monkeyResponse + ".");
+
+ // return on error
+ if (monkeyResponse.startsWith("ERROR"))
return false;
- } catch (IOException e) {
- e.printStackTrace();
- }
+ // return on ok
+ if(monkeyResponse.startsWith("OK"))
+ return true;
+ // return on something else?
+ return false;
+ }
+ // didn't get a response...
+ if (print)
+ System.out.println("MonkeyServer: ??no response");
+ if (record)
+ recordResponse("??no response");
+ logger.info("Monkey Response: ??no response.");
+
+ //return on no response
return false;
}
-
+ /**
+ * Record the command in the xml file
+ *
+ * @param command the command sent to the monkey server
+ */
+ private static void recordCommand(String command) throws IOException {
+ if (monkeyRecorder != null) { // don't record setup junk
+ monkeyRecorder.startCommand();
+ monkeyRecorder.addInput(command);
+ }
+ }
+
+ /**
+ * Record the response in the xml file
+ *
+ * @param response the response sent by the monkey server
+ */
+ private static void recordResponse(String response) throws IOException {
+ recordResponse(response, "");
+ }
+
+ /**
+ * Record the response and the filename in the xml file, store the file (to be zipped up later)
+ *
+ * @param response the response sent by the monkey server
+ * @param filename the filename of a file to be time stamped, recorded in the xml file and stored
+ */
+ private static void recordResponse(String response, String filename) throws IOException {
+ if (monkeyRecorder != null) { // don't record setup junk
+ monkeyRecorder.addResult(response, filename); // ignores file if filename empty
+ monkeyRecorder.endCommand();
+ }
+ }
+
+ /**
+ * Add the device variables to the xml file in monkeyRecorder.
+ * The results get added as device_var tags in the script_run tag
+ */
+ private static void addDeviceVars() throws IOException {
+ monkeyRecorder.addComment("Device specific variables");
+ sendMonkeyEvent("listvar \n", false, false);
+ if (monkeyResponse.startsWith("OK:")) {
+ // peel off "OK:" string and get the individual var names
+ String[] varNames = monkeyResponse.substring(3).split("\\s+");
+ // grab all the individual var values
+ for (String name: varNames) {
+ sendMonkeyEvent("getvar " + name, false, false);
+ if(monkeyResponse != null) {
+ if (monkeyResponse.startsWith("OK") ) {
+ if (monkeyResponse.length() > 2) {
+ monkeyRecorder.addDeviceVar(name, monkeyResponse.substring(3));
+ } else {
+ // only got OK - good variable but no value
+ monkeyRecorder.addDeviceVar(name, "null");
+ }
+ } else {
+ // error returned - couldn't get var value for name... include error return
+ monkeyRecorder.addDeviceVar(name, monkeyResponse);
+ }
+ } else {
+ // no monkeyResponse - bad variable with no value
+ monkeyRecorder.addDeviceVar(name, "null");
+ }
+ }
+ } else {
+ // it's an error, can't find variable names...
+ monkeyRecorder.addAttribute("listvar", monkeyResponse);
+ }
+ }
+
/**
* Process the command-line options
*
* @return Returns true if options were parsed with no apparent errors.
*/
- public static void processOptions(String[] args) {
+ private static void processOptions(String[] args) {
// parse command line parameters.
int index = 0;
@@ -364,7 +512,7 @@
if ("-s".equals(argument)) {
if(index == args.length) {
- printAndExit("Missing Server after -s", false);
+ printUsageAndQuit("Missing Server after -s");
}
monkeyServer = args[index++];
@@ -372,18 +520,32 @@
} else if ("-p".equals(argument)) {
// quick check on the next argument.
if (index == args.length) {
- printAndExit("Missing Server IP after -p", false /* terminate */);
+ printUsageAndQuit("Missing Server port after -p");
}
monkeyPort = Integer.parseInt(args[index++]);
- } else {
- // get the filepath of the script to run.
- scriptName = argument;
- // should not be any other device.
- //if (index < args.length) {
- // printAndExit("Too many arguments!", false /* terminate */);
- //}
+ } else if ("-v".equals(argument)) {
+ // quick check on the next argument.
+ if (index == args.length) {
+ printUsageAndQuit("Missing Log Level after -v");
+ }
+
+ Level level = Level.parse(args[index++]);
+ logger.setLevel(level);
+ level = logger.getLevel();
+ System.out.println("Log level set to: " + level + "(" + level.intValue() + ").");
+ System.out.println("Warning: Log levels below INFO(800) not working currently... parent issues");
+
+ } else if (argument.startsWith("-")) {
+ // we have an unrecognized argument.
+ printUsageAndQuit("Unrecognized argument: " + argument + ".");
+
+ monkeyPort = Integer.parseInt(args[index++]);
+
+ } else {
+ // get the filepath of the script to run. This will be the last undashed argument.
+ scriptName = argument;
}
} while (index < args.length);
}
@@ -394,22 +556,29 @@
private static void getDeviceImage(IDevice device, String filepath, boolean landscape)
throws IOException {
RawImage rawImage;
+ recordCommand("grabscreen");
+ System.out.println("Grabbing Screeshot: " + filepath + ".");
try {
rawImage = device.getScreenshot();
}
catch (IOException ioe) {
+ recordResponse("No frame buffer", "");
printAndExit("Unable to get frame buffer: " + ioe.getMessage(), true /* terminate */);
return;
}
// device/adb not available?
- if (rawImage == null)
+ if (rawImage == null) {
+ recordResponse("No image", "");
return;
-
+ }
+
assert rawImage.bpp == 16;
BufferedImage image;
+
+ logger.info("Raw Image - height: " + rawImage.height + ", width: " + rawImage.width);
if (landscape) {
// convert raw data to an Image
@@ -458,16 +627,20 @@
}
if (!ImageIO.write(image, "png", new File(filepath))) {
+ recordResponse("No png writer", "");
throw new IOException("Failed to find png writer");
}
+ recordResponse("OK", filepath);
}
- private static void printUsageAndQuit() {
+ private static void printUsageAndQuit(String message) {
// 80 cols marker: 01234567890123456789012345678901234567890123456789012345678901234567890123456789
+ System.out.println(message);
System.out.println("Usage: monkeyrunner [options] SCRIPT_FILE");
System.out.println("");
System.out.println(" -s MonkeyServer IP Address.");
System.out.println(" -p MonkeyServer TCP Port.");
+ System.out.println(" -v MonkeyServer Logging level (ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE, OFF)");
System.out.println("");
System.out.println("");