summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2009-11-10 08:22:06 -0800
committerMarco Nelissen <marcone@google.com>2009-11-10 10:19:51 -0800
commit423d39f6a9fd7b6399b92a272eadc49676375f48 (patch)
tree3994c10ff1692951a5de252db6f5baa93d91382c
parent425c152170cade85a8e53f554c2f835eab78c30b (diff)
downloadandroid_packages_wallpapers_MagicSmoke-423d39f6a9fd7b6399b92a272eadc49676375f48.tar.gz
android_packages_wallpapers_MagicSmoke-423d39f6a9fd7b6399b92a272eadc49676375f48.tar.bz2
android_packages_wallpapers_MagicSmoke-423d39f6a9fd7b6399b92a272eadc49676375f48.zip
Don't let the magic smoke out!
-rw-r--r--Android.mk27
-rw-r--r--AndroidManifest.xml49
-rw-r--r--MODULE_LICENSE_APACHE20
-rw-r--r--NOTICE190
-rw-r--r--res/drawable-hdpi/noise1.pngbin0 -> 20835 bytes
-rw-r--r--res/drawable-hdpi/noise2.pngbin0 -> 31765 bytes
-rw-r--r--res/drawable-hdpi/noise3.pngbin0 -> 39258 bytes
-rw-r--r--res/drawable-hdpi/noise4.pngbin0 -> 48490 bytes
-rw-r--r--res/drawable-hdpi/noise5.pngbin0 -> 46264 bytes
-rw-r--r--res/drawable/ic_launcher_wallpaper.pngbin0 -> 3040 bytes
-rw-r--r--res/drawable/magicsmoke_thumb.pngbin0 -> 26811 bytes
-rw-r--r--res/layout/selector.xml43
-rw-r--r--res/raw/clouds.rs236
-rw-r--r--res/values/strings.xml37
-rw-r--r--res/values/styles.xml36
-rw-r--r--res/xml/magicsmoke.xml28
-rw-r--r--src/com/android/magicsmoke/MagicSmoke.java26
-rw-r--r--src/com/android/magicsmoke/MagicSmokeRS.java363
-rw-r--r--src/com/android/magicsmoke/MagicSmokeSelector.java234
-rw-r--r--src/com/android/magicsmoke/RenderScriptScene.java91
-rw-r--r--src/com/android/magicsmoke/RenderScriptWallpaper.java114
21 files changed, 1474 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..49b8719
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,27 @@
+#
+# 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 := MagicSmokeWallpapers
+LOCAL_CERTIFICATE := shared
+
+include $(BUILD_PACKAGE)
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
new file mode 100644
index 0000000..5e79225
--- /dev/null
+++ b/AndroidManifest.xml
@@ -0,0 +1,49 @@
+<?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.magicsmoke">
+
+ <uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />
+ <uses-permission android:name="android.permission.BIND_WALLPAPER" />
+
+ <application
+ android:label="@string/wallpapers"
+ android:icon="@drawable/ic_launcher_wallpaper">
+
+ <service
+ android:label="@string/wallpaper_magicsmoke"
+ android:name="MagicSmoke"
+ 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/magicsmoke" />
+ </service>
+
+ <activity
+ android:name="com.android.magicsmoke.MagicSmokeSelector"
+ android:theme="@style/Preview"
+ android:exported="true">
+ </activity>
+
+ </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/drawable-hdpi/noise1.png b/res/drawable-hdpi/noise1.png
new file mode 100644
index 0000000..fee1cf9
--- /dev/null
+++ b/res/drawable-hdpi/noise1.png
Binary files differ
diff --git a/res/drawable-hdpi/noise2.png b/res/drawable-hdpi/noise2.png
new file mode 100644
index 0000000..0d13662
--- /dev/null
+++ b/res/drawable-hdpi/noise2.png
Binary files differ
diff --git a/res/drawable-hdpi/noise3.png b/res/drawable-hdpi/noise3.png
new file mode 100644
index 0000000..c9c610b
--- /dev/null
+++ b/res/drawable-hdpi/noise3.png
Binary files differ
diff --git a/res/drawable-hdpi/noise4.png b/res/drawable-hdpi/noise4.png
new file mode 100644
index 0000000..02261c9
--- /dev/null
+++ b/res/drawable-hdpi/noise4.png
Binary files differ
diff --git a/res/drawable-hdpi/noise5.png b/res/drawable-hdpi/noise5.png
new file mode 100644
index 0000000..2f9a713
--- /dev/null
+++ b/res/drawable-hdpi/noise5.png
Binary files differ
diff --git a/res/drawable/ic_launcher_wallpaper.png b/res/drawable/ic_launcher_wallpaper.png
new file mode 100644
index 0000000..965fb71
--- /dev/null
+++ b/res/drawable/ic_launcher_wallpaper.png
Binary files differ
diff --git a/res/drawable/magicsmoke_thumb.png b/res/drawable/magicsmoke_thumb.png
new file mode 100644
index 0000000..8c937b8
--- /dev/null
+++ b/res/drawable/magicsmoke_thumb.png
Binary files differ
diff --git a/res/layout/selector.xml b/res/layout/selector.xml
new file mode 100644
index 0000000..e202733
--- /dev/null
+++ b/res/layout/selector.xml
@@ -0,0 +1,43 @@
+<?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.
+-->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/backgroundview"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingBottom="4dip">
+
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/taptochange"
+ android:textSize="24dip"
+ android:gravity="center_horizontal"
+ android:layout_alignParentTop="true"
+ android:padding="12dip"
+ android:background="#40000000"
+ />
+
+ <Button
+ android:layout_width="160dip"
+ android:layout_height="wrap_content"
+ android:text="@string/ok"
+ android:onClick="setLiveWallpaper"
+ android:layout_alignParentBottom="true"
+ android:layout_centerHorizontal="true"
+ />
+
+</RelativeLayout>
diff --git a/res/raw/clouds.rs b/res/raw/clouds.rs
new file mode 100644
index 0000000..515a281
--- /dev/null
+++ b/res/raw/clouds.rs
@@ -0,0 +1,236 @@
+// 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)
+#pragma stateRaster(parent)
+#pragma stateFragment(PFBackground)
+
+#define RSID_NOISESRC1 1
+#define RSID_NOISESRC2 2
+#define RSID_NOISESRC3 3
+#define RSID_NOISESRC4 4
+#define RSID_NOISESRC5 5
+#define RSID_NOISEDST1 6
+#define RSID_NOISEDST2 7
+#define RSID_NOISEDST3 8
+#define RSID_NOISEDST4 9
+#define RSID_NOISEDST5 10
+
+float xshift[5];
+float rotation[5];
+float scale[5];
+float alphafactor;
+int currentpreset;
+
+
+void drawCloud(float *ident, int id, int idx) {
+ float mat1[16];
+ float z = -8.f * idx;
+ matrixLoadMat(mat1,ident);
+ matrixTranslate(mat1, -State->mXOffset * 8.f * idx, -State->mTilt * idx / 3.f, 0.f);
+ matrixRotate(mat1, rotation[idx], 0.f, 0.f, 1.f);
+ vpLoadModelMatrix(mat1);
+
+ bindTexture(NAMED_PFBackground, 0, id);
+ drawQuadTexCoords(
+ -600.0f, -600.0f, z, // space
+ 0.f + xshift[idx], 0.f, // texture
+ 600, -600.0f, z, // space
+ scale[idx] + xshift[idx], 0.f, // texture
+ 600, 600.0f, z, // space
+ scale[idx] + xshift[idx], scale[idx], // texture
+ -600.0f, 600.0f, z, // space
+ 0.f + xshift[idx], scale[idx]); // texture
+}
+
+void drawClouds(float* ident) {
+
+ int i;
+
+ float mat1[16];
+
+ matrixLoadMat(mat1,ident);
+
+
+ int mask = State->mTextureMask;
+ if (mask & 1) {
+ if (State->mTextureSwap != 0) {
+ drawCloud(mat1, NAMED_Tnoise5, 0);
+ } else {
+ drawCloud(mat1, NAMED_Tnoise1, 0);
+ }
+ xshift[0] += 0.0010f;
+ }
+
+ if (mask & 2) {
+ drawCloud(mat1, NAMED_Tnoise2, 1);
+ xshift[1] += 0.00106;
+ }
+
+ if (mask & 4) {
+ drawCloud(mat1, NAMED_Tnoise3, 2);
+ xshift[2] += 0.00114f;
+ }
+
+ if (mask & 8) {
+ drawCloud(mat1, NAMED_Tnoise4, 3);
+ xshift[3] += 0.00118f;
+ }
+
+ if (mask & 16) {
+ drawCloud(mat1, NAMED_Tnoise5, 4);
+ xshift[4] += 0.00127f;
+ }
+
+ if (State->mRotate != 0) {
+ rotation[0] += 0.10;
+ rotation[1] += 0.102f;
+ rotation[2] += 0.106f;
+ rotation[3] += 0.114f;
+ rotation[4] += 0.123f;
+ }
+}
+
+int premul(int rgb, int a) {
+ int r = (rgb >> 16) * a + 1;
+ r = (r + (r >> 8)) >> 8;
+ int g = ((rgb >> 8) & 0xff) * a + 1;
+ g = (g + (g >> 8)) >> 8;
+ int b = (rgb & 0xff) * a + 1;
+ b = (b + (b >> 8)) >> 8;
+ return r << 16 | g << 8 | b;
+}
+
+void makeTexture(int *src, int *dst, int rsid) {
+
+ int x;
+ int y;
+ int pm = State->mPreMul;
+
+ if (State->mProcessTexture) {
+ int lowcol = State->mLowCol;
+ int highcol = State->mHighCol;
+
+ for (y=0;y<256;y++) {
+ for (x=0;x<256;x++) {
+ int pix = src[y*256+x];
+ int lum = pix & 0x00ff;
+ int newpix;
+ if (lum < 128) {
+ newpix = lowcol;
+ int newalpha = 255 - (lum * 2);
+ newalpha /= alphafactor;
+ if (pm) newpix = premul(newpix, newalpha);
+ newpix = newpix | (newalpha << 24);
+ } else {
+ newpix = highcol;
+ int newalpha = (lum - 128) * 2;
+ newalpha /= alphafactor;
+ if (pm) newpix = premul(newpix, newalpha);
+ newpix = newpix | (newalpha << 24);
+ }
+ // have ARGB, need ABGR
+ newpix = (newpix & 0xff00ff00) | ((newpix & 0xff) << 16) | ((newpix >> 16) & 0xff);
+ dst[y*256+x] = newpix;
+ }
+ }
+ alphafactor *= State->mAlphaMul;
+ } else {
+ for (y=0;y<256;y++) {
+ for (x=0;x<256;x++) {
+ int rgb = *src++;
+ int a = (rgb >> 24) & 0xff;
+ rgb &= 0x00ffffff;
+ rgb = premul(rgb, a);
+ int newpix = (a << 24) | rgb;
+ newpix = (newpix & 0xff00ff00) | ((newpix & 0xff) << 16) | ((newpix >> 16) & 0xff);
+ *dst++ = newpix;
+ }
+ }
+ }
+ uploadToTexture(rsid, 0);
+}
+
+void makeTextures() {
+ debugI32("makeTextures", State->mPreset);
+ alphafactor = 1.f;
+ makeTexture((int*)noisesrc1, (int*)noisedst1, NAMED_Tnoise1);
+ makeTexture((int*)noisesrc2, (int*)noisedst2, NAMED_Tnoise2);
+ makeTexture((int*)noisesrc3, (int*)noisedst3, NAMED_Tnoise3);
+ makeTexture((int*)noisesrc4, (int*)noisedst4, NAMED_Tnoise4);
+ makeTexture((int*)noisesrc5, (int*)noisedst5, NAMED_Tnoise5);
+}
+
+
+
+struct color {
+ float r;
+ float g;
+ float b;
+};
+
+void init() {
+ int i;
+ for (i=0;i<4;i++) {
+ xshift[i] = 0.f;
+ rotation[i] = 360.f * i / 5.f;
+ }
+ scale[0] = 2.f; // changed below based on preset
+ scale[1] = 1.5f;
+ scale[2] = 1.7f;
+ scale[3] = 1.9f;
+ scale[4] = 2.1f;
+
+ currentpreset = -1;
+}
+
+
+int main(int launchID) {
+
+ int i;
+ float ident[16];
+ float masterscale = 0.0041f;// / (State->mXOffset * 4.f + 1.f);
+ matrixLoadIdentity(ident);
+ matrixTranslate(ident, -State->mXOffset, 0.f, 0.f);
+ matrixScale(ident, masterscale, masterscale, masterscale);
+ //matrixRotate(ident, 0.f, 0.f, 0.f, 1.f);
+ matrixRotate(ident, -State->mTilt, 1.f, 0.f, 0.f);
+
+ if (State->mBlendFunc) {
+ bindProgramStore(NAMED_PFSBackgroundOne);
+ } else {
+ bindProgramStore(NAMED_PFSBackgroundSrc);
+ }
+ i = State->mPreset;
+ if (i != currentpreset) {
+ currentpreset = i;
+ int rgb = State->mBackCol;
+ pfClearColor(
+ ((float)((rgb >> 16) & 0xff)) / 255.0f,
+ ((float)((rgb >> 8) & 0xff)) / 255.0f,
+ ((float)(rgb & 0xff)) / 255.0f,
+ 1.0f);
+ makeTextures();
+ }
+
+ if (State->mTextureSwap != 0) {
+ scale[0] = .125f;
+ } else {
+ scale[0] = 2.f;
+ }
+ drawClouds(ident);
+
+ return 1;
+}
diff --git a/res/values/strings.xml b/res/values/strings.xml
new file mode 100644
index 0000000..c92b122
--- /dev/null
+++ b/res/values/strings.xml
@@ -0,0 +1,37 @@
+<?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="wallpapers">Magic Smoke Wallpapers</string>
+
+ <!-- Wallpapers showing smoke, clouds, water, plasmas -->
+ <string name="wallpaper_magicsmoke">Magic Smoke</string>
+
+ <string name="author">Google</string>
+ <string name="magicsmoke_desc">Draws smoke, clouds, water and plasmas.</string>
+
+ <!-- button label -->
+ <string name="ok">OK</string>
+
+ <!-- overlay text -->
+ <string name="taptochange">Tap to change</string>
+</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
new file mode 100644
index 0000000..a55fbdb
--- /dev/null
+++ b/res/values/styles.xml
@@ -0,0 +1,36 @@
+<?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="WallpaperTitle">
+ <item name="android:textSize">20dip</item>
+ <item name="android:shadowColor">#FF000000</item>
+ <item name="android:shadowRadius">2.5</item>
+ <item name="android:shadowDx">0</item>
+ <item name="android:shadowDy">0</item>
+ <item name="android:textColor">#FFFFFFFF</item>
+ <item name="android:gravity">left</item>
+ </style>
+
+ <style name="Preview" parent="@android:style/Theme.NoTitleBar">
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:colorBackgroundCacheHint">@null</item>
+ <item name="android:windowAnimationStyle">@android:style/Animation.Activity</item>
+ </style>
+</resources>
diff --git a/res/xml/magicsmoke.xml b/res/xml/magicsmoke.xml
new file mode 100644
index 0000000..fed502a
--- /dev/null
+++ b/res/xml/magicsmoke.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.
+ */
+-->
+
+<!-- The attributes in this XML file provide configuration information -->
+<!-- for the cube. -->
+
+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
+ android:wallpaperAuthor="@string/author"
+ android:wallpaperDescription="@string/magicsmoke_desc"
+ android:thumbnail="@drawable/magicsmoke_thumb"
+ android:settingsActivity="com.android.magicsmoke.MagicSmokeSelector"
+/>
diff --git a/src/com/android/magicsmoke/MagicSmoke.java b/src/com/android/magicsmoke/MagicSmoke.java
new file mode 100644
index 0000000..e0ff258
--- /dev/null
+++ b/src/com/android/magicsmoke/MagicSmoke.java
@@ -0,0 +1,26 @@
+/*
+ * 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.magicsmoke;
+
+public class MagicSmoke extends RenderScriptWallpaper<MagicSmokeRS> {
+
+ @Override
+ protected MagicSmokeRS createScene(int width, int height) {
+ return new MagicSmokeRS(this, width, height);
+ }
+}
+
diff --git a/src/com/android/magicsmoke/MagicSmokeRS.java b/src/com/android/magicsmoke/MagicSmokeRS.java
new file mode 100644
index 0000000..726d128
--- /dev/null
+++ b/src/com/android/magicsmoke/MagicSmokeRS.java
@@ -0,0 +1,363 @@
+/*
+ * 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.magicsmoke;
+
+import static android.renderscript.ProgramFragment.EnvMode.REPLACE;
+import static android.renderscript.Sampler.Value.LINEAR;
+import static android.renderscript.Sampler.Value.WRAP;
+
+import com.android.magicsmoke.R;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.media.MediaPlayer;
+import android.os.Handler;
+import android.renderscript.Allocation;
+import android.renderscript.Dimension;
+import android.renderscript.Element;
+import android.renderscript.Primitive;
+import android.renderscript.ProgramFragment;
+import android.renderscript.ProgramStore;
+import android.renderscript.ProgramVertex;
+import android.renderscript.Sampler;
+import android.renderscript.ScriptC;
+import android.renderscript.SimpleMesh;
+import android.renderscript.Type;
+import android.renderscript.Element.Builder;
+import android.renderscript.ProgramStore.BlendDstFunc;
+import android.renderscript.ProgramStore.BlendSrcFunc;
+import android.util.Log;
+import android.view.MotionEvent;
+
+import java.util.TimeZone;
+
+class MagicSmokeRS extends RenderScriptScene implements OnSharedPreferenceChangeListener {
+
+ static class WorldState {
+ public float mXOffset;
+ public float mTilt;
+ public int mPreset;
+ public int mTextureMask;
+ public int mRotate;
+ public int mTextureSwap;
+ public int mProcessTexture;
+ public int mBackCol;
+ public int mLowCol;
+ public int mHighCol;
+ public float mAlphaMul;
+ public int mPreMul;
+ public int mBlendFunc;
+ }
+ WorldState mWorldState = new WorldState();
+ private Type mStateType;
+ private Allocation mState;
+
+ private ProgramStore mPfsBackgroundOne;
+ private ProgramStore mPfsBackgroundSrc;
+ private ProgramFragment mPfBackground;
+ private Sampler mSampler;
+ private Allocation[] mSourceTextures;
+ private Allocation[] mRealTextures;
+
+ private ProgramVertex mPVBackground;
+ private ProgramVertex.MatrixAllocation mPVAlloc;
+
+ private static final int RSID_STATE = 0;
+ //private static final int RSID_PROGRAMVERTEX = 3;
+ private static final int RSID_NOISESRC1 = 1;
+ private static final int RSID_NOISESRC2 = 2;
+ private static final int RSID_NOISESRC3 = 3;
+ private static final int RSID_NOISESRC4 = 4;
+ private static final int RSID_NOISESRC5 = 5;
+ private static final int RSID_NOISEDST1 = 6;
+ private static final int RSID_NOISEDST2 = 7;
+ private static final int RSID_NOISEDST3 = 8;
+ private static final int RSID_NOISEDST4 = 9;
+ private static final int RSID_NOISEDST5 = 10;
+
+ private Context mContext;
+ private SharedPreferences mSharedPref;
+
+ static class Preset {
+ Preset(boolean process, int backcol, int locol, int hicol, float mul, int mask,
+ boolean rot, int blend, boolean texswap, boolean premul) {
+ mProcessTexture = process;
+ mBackColor = backcol;
+ mLowColor = locol;
+ mHighColor = hicol;
+ mAlphaMul = mul;
+ mTextureMask = mask;
+ mRotate = rot;
+ mBlendFunc = blend;
+ mTextureSwap = texswap;
+ mPreMul = premul;
+ }
+ public boolean mProcessTexture;
+ public int mBackColor;
+ public int mLowColor;
+ public int mHighColor;
+ public float mAlphaMul;
+ public int mTextureMask;
+ public boolean mRotate;
+ public int mBlendFunc;
+ public boolean mTextureSwap;
+ public boolean mPreMul;
+ }
+
+ public static final int DEFAULT_PRESET = 4;
+ public static final Preset [] mPreset = new Preset[] {
+ // proc back low high alph mask rot blend swap premul
+ new Preset(true, 0x000000, 0x000000, 0xffffff, 2.0f, 0x0f, true, 0, false, false),
+ new Preset(true, 0x0000ff, 0x000000, 0xffffff, 2.0f, 0x0f, true, 0, false, false),
+ new Preset(true, 0x00ff00, 0x000000, 0xffffff, 2.0f, 0x0f, true, 0, false, false),
+ new Preset(true, 0x00ff00, 0x000000, 0xffffff, 2.0f, 0x0f, true, 0, false, true),
+ new Preset(true, 0x00ff00, 0x00ff00, 0xffffff, 2.5f, 0x1f, true, 0, true, true),
+ new Preset(true, 0x800000, 0xff0000, 0xffffff, 2.5f, 0x1f, true, 0, true, false),
+ new Preset(false, 0x000000, 0x000000, 0xffffff, 0.0f, 0x1f, true, 0, false, false),
+ new Preset(true, 0x0000ff, 0x00ff00, 0xffff00, 2.0f, 0x1f, true, 0, true, false),
+ new Preset(true, 0x008000, 0x00ff00, 0xffffff, 2.5f, 0x1f, true, 0, true, false),
+ new Preset(true, 0x800000, 0xff0000, 0xffffff, 2.5f, 0x1f, true, 0, true, true),
+ new Preset(true, 0x808080, 0x000000, 0xffffff, 2.0f, 0x0f, true, 0, false, true),
+ new Preset(true, 0x0000ff, 0x000000, 0xffffff, 2.0f, 0x0f, true, 0, false, true),
+ new Preset(true, 0x0000ff, 0x00ff00, 0xffff00, 1.5f, 0x1f, false, 0, false, true),
+ new Preset(true, 0x0000ff, 0x00ff00, 0xffff00, 2.0f, 0x1f, true, 0, true, true),
+ new Preset(true, 0x0000ff, 0x00ff00, 0xffff00, 1.5f, 0x1f, true, 0, true, true),
+ new Preset(true, 0x808080, 0x000000, 0xffffff, 2.0f, 0x0f, true, 0, false, false),
+ new Preset(true, 0x000000, 0x000000, 0xffffff, 2.0f, 0x0f, true, 0, true, false),
+ };
+
+ private float mTouchY;
+
+ MagicSmokeRS(Context context, int width, int height) {
+ super(width, height);
+ mWidth = width;
+ mHeight = height;
+ mWorldState.mTilt = 0;
+ mContext = context;
+ mSharedPref = mContext.getSharedPreferences("magicsmoke", Context.MODE_PRIVATE);
+ makeNewState();
+ }
+
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+
+ makeNewState();
+ mState.data(mWorldState);
+ }
+
+ void makeNewState() {
+ int p = mSharedPref.getInt("preset", DEFAULT_PRESET);
+ if (p >= mPreset.length) {
+ p = 0;
+ }
+ mWorldState.mPreset = p;
+ mWorldState.mTextureMask = mPreset[p].mTextureMask;
+ mWorldState.mRotate = mPreset[p].mRotate ? 1 : 0;
+ mWorldState.mTextureSwap = mPreset[p].mTextureSwap ? 1 : 0;
+ mWorldState.mProcessTexture = mPreset[p].mProcessTexture ? 1 : 0;
+ mWorldState.mBackCol = mPreset[p].mBackColor;
+ mWorldState.mLowCol = mPreset[p].mLowColor;
+ mWorldState.mHighCol = mPreset[p].mHighColor;
+ mWorldState.mAlphaMul = mPreset[p].mAlphaMul;
+ mWorldState.mPreMul = mPreset[p].mPreMul ? 1 : 0;
+ mWorldState.mBlendFunc = mPreset[p].mBlendFunc;
+ }
+
+ @Override
+ public void resize(int width, int height) {
+ super.resize(width, height);
+ if (mPVAlloc != null) {
+ mPVAlloc.setupProjectionNormalized(width, height);
+ }
+ }
+
+ @Override
+ public void onTouchEvent(MotionEvent event) {
+ switch(event.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ mTouchY = event.getY();
+ break;
+ case MotionEvent.ACTION_MOVE:
+ float dy = event.getY() - mTouchY;
+ mTouchY += dy;
+ dy /= 20;
+ dy += mWorldState.mTilt;
+ if (dy > 4) {
+ dy = 4;
+ } else if (dy < -4) {
+ dy = -4;
+ }
+ mWorldState.mTilt = dy;
+ mState.data(mWorldState);
+ }
+ }
+
+ @Override
+ public void setOffset(float xOffset, float yOffset, float xStep, float yStep,
+ int xPixels, int yPixels) {
+ // update our state, then push it to the renderscript
+ mWorldState.mXOffset = xOffset;
+ mState.data(mWorldState);
+ }
+
+ @Override
+ public void stop() {
+ mSharedPref.unregisterOnSharedPreferenceChangeListener(this);
+ super.stop();
+ }
+
+ @Override
+ public void start() {
+ super.start();
+ mSharedPref.registerOnSharedPreferenceChangeListener(this);
+ makeNewState();
+ mState.data(mWorldState);
+ }
+
+ float alphafactor;
+ Type mTextureType;
+
+ void loadBitmap(int id, int index, String name, float alphamul, int lowcol, int highcol) {
+ BitmapFactory.Options opts = new BitmapFactory.Options();
+ opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ Bitmap in = BitmapFactory.decodeResource(mResources, id, opts);
+
+ int pixels[] = new int[65536];
+ in.getPixels(pixels, 0, 256, 0, 0, 256, 256);
+ mRealTextures[index] = Allocation.createTyped(mRS, mTextureType);
+ mSourceTextures[index] = Allocation.createTyped(mRS, mTextureType);
+ mSourceTextures[index].setName(name+"_src");
+ mSourceTextures[index].data(pixels);
+ mRealTextures[index].setName(name);
+ in.recycle();
+ }
+
+ void loadBitmaps() {
+ alphafactor = 1f;
+ float alphamul = mPreset[mWorldState.mPreset].mAlphaMul;
+ int lowcol = mPreset[mWorldState.mPreset].mLowColor;
+ int highcol = mPreset[mWorldState.mPreset].mHighColor;
+ //Log.i("@@@@", "preset " + mWorldState.mPreset + ", mul: " + alphamul +
+ // ", colors: " + Integer.toHexString(lowcol) + "/" + Integer.toHexString(highcol));
+
+ // TODO: using different high and low colors for each layer offers some cool effects too
+ loadBitmap(R.drawable.noise1, 0, "Tnoise1", alphamul, lowcol, highcol);
+ loadBitmap(R.drawable.noise2, 1, "Tnoise2", alphamul, lowcol, highcol);
+ loadBitmap(R.drawable.noise3, 2, "Tnoise3", alphamul, lowcol, highcol);
+ loadBitmap(R.drawable.noise4, 3, "Tnoise4", alphamul, lowcol, highcol);
+ loadBitmap(R.drawable.noise5, 4, "Tnoise5", alphamul, lowcol, highcol);
+ }
+
+ @Override
+ protected ScriptC createScript() {
+
+ // 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);
+ mState.data(mWorldState);
+
+ // 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);
+
+ mSourceTextures = new Allocation[5];
+ mRealTextures = new Allocation[5];
+
+ Type.Builder tb = new Type.Builder(mRS, Element.RGBA_8888(mRS));
+ tb.add(Dimension.X, 256);
+ tb.add(Dimension.Y, 256);
+ mTextureType = tb.create();
+ loadBitmaps();
+
+ Sampler.Builder samplerBuilder = new Sampler.Builder(mRS);
+ samplerBuilder.setMin(LINEAR);
+ samplerBuilder.setMag(LINEAR);
+ samplerBuilder.setWrapS(WRAP);
+ samplerBuilder.setWrapT(WRAP);
+ mSampler = samplerBuilder.create();
+
+ {
+ ProgramFragment.Builder builder = new ProgramFragment.Builder(mRS, null, null);
+ builder.setTexEnable(true, 0);
+ builder.setTexEnvMode(ProgramFragment.EnvMode.MODULATE, 0);
+ mPfBackground = builder.create();
+ mPfBackground.setName("PFBackground");
+ mPfBackground.bindSampler(mSampler, 0);
+ }
+
+ {
+ ProgramStore.Builder builder = new ProgramStore.Builder(mRS, null, null);
+ builder.setDepthFunc(ProgramStore.DepthFunc.EQUAL);
+ builder.setBlendFunc(BlendSrcFunc.ONE, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
+ builder.setDitherEnable(true); // without dithering there is severe banding
+ builder.setDepthMask(false);
+ mPfsBackgroundOne = builder.create();
+ mPfsBackgroundOne.setName("PFSBackgroundOne");
+ builder.setBlendFunc(BlendSrcFunc.SRC_ALPHA, BlendDstFunc.ONE_MINUS_SRC_ALPHA);
+ mPfsBackgroundSrc = builder.create();
+ mPfsBackgroundSrc.setName("PFSBackgroundSrc");
+ }
+
+ // 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(mTextureType, "noisesrc1", RSID_NOISESRC1);
+ sb.setType(mTextureType, "noisedst1", RSID_NOISEDST1);
+ sb.setType(mTextureType, "noisesrc2", RSID_NOISESRC2);
+ sb.setType(mTextureType, "noisedst2", RSID_NOISEDST2);
+ sb.setType(mTextureType, "noisesrc3", RSID_NOISESRC3);
+ sb.setType(mTextureType, "noisedst3", RSID_NOISEDST3);
+ sb.setType(mTextureType, "noisesrc4", RSID_NOISESRC4);
+ sb.setType(mTextureType, "noisedst4", RSID_NOISEDST4);
+ sb.setType(mTextureType, "noisesrc5", RSID_NOISESRC5);
+ sb.setType(mTextureType, "noisedst5", RSID_NOISEDST5);
+ sb.setScript(mResources, R.raw.clouds);
+ sb.setRoot(true);
+
+ ScriptC script = sb.create();
+ script.setClearColor(1.0f, 0.0f, 0.0f, 1.0f);
+ script.setTimeZone(TimeZone.getDefault().getID());
+
+ script.bindAllocation(mState, RSID_STATE);
+ script.bindAllocation(mSourceTextures[0], RSID_NOISESRC1);
+ script.bindAllocation(mRealTextures[0], RSID_NOISEDST1);
+ script.bindAllocation(mSourceTextures[1], RSID_NOISESRC2);
+ script.bindAllocation(mRealTextures[1], RSID_NOISEDST2);
+ script.bindAllocation(mSourceTextures[2], RSID_NOISESRC3);
+ script.bindAllocation(mRealTextures[2], RSID_NOISEDST3);
+ script.bindAllocation(mSourceTextures[3], RSID_NOISESRC4);
+ script.bindAllocation(mRealTextures[3], RSID_NOISEDST4);
+ script.bindAllocation(mSourceTextures[4], RSID_NOISESRC5);
+ script.bindAllocation(mRealTextures[4], RSID_NOISEDST5);
+ //script.bindAllocation(mPVAlloc.mAlloc, RSID_PROGRAMVERTEX);
+
+
+ return script;
+ }
+}
diff --git a/src/com/android/magicsmoke/MagicSmokeSelector.java b/src/com/android/magicsmoke/MagicSmokeSelector.java
new file mode 100644
index 0000000..fbe335d
--- /dev/null
+++ b/src/com/android/magicsmoke/MagicSmokeSelector.java
@@ -0,0 +1,234 @@
+/*
+ * 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.magicsmoke;
+
+import android.app.Activity;
+import android.app.WallpaperManager;
+import android.app.WallpaperInfo;
+import android.app.Dialog;
+import android.service.wallpaper.IWallpaperConnection;
+import android.service.wallpaper.IWallpaperService;
+import android.service.wallpaper.IWallpaperEngine;
+import android.service.wallpaper.WallpaperSettingsActivity;
+import android.content.ServiceConnection;
+import android.content.Intent;
+import android.content.Context;
+import android.content.ComponentName;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+import android.os.RemoteException;
+import android.os.IBinder;
+import android.os.ParcelFileDescriptor;
+import android.os.Bundle;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.WindowManager;
+import android.view.ViewGroup;
+import android.view.Window;
+import android.view.LayoutInflater;
+import android.util.Log;
+import android.widget.TextView;
+
+public class MagicSmokeSelector extends Activity {
+
+ private static final String LOG_TAG = "MagicSmokeSelector";
+
+ private WallpaperManager mWallpaperManager;
+ private WallpaperConnection mWallpaperConnection;
+
+ private Intent mWallpaperIntent;
+ private SharedPreferences mSharedPref;
+ private int mCurrentPreset;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.selector);
+
+ mWallpaperIntent = new Intent(this, MagicSmoke.class);
+
+ mWallpaperManager = WallpaperManager.getInstance(this);
+ mWallpaperConnection = new WallpaperConnection(mWallpaperIntent);
+
+ mSharedPref = getSharedPreferences("magicsmoke", Context.MODE_PRIVATE);
+ mCurrentPreset = mSharedPref.getInt("preset", MagicSmokeRS.DEFAULT_PRESET);
+ if (mCurrentPreset >= MagicSmokeRS.mPreset.length) {
+ mCurrentPreset = 0;
+ updatePrefs();
+ }
+ }
+
+ // button hook
+ public void setLiveWallpaper(View v) {
+ finish();
+ }
+
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) {
+ try {
+ mWallpaperConnection.mEngine.setVisibility(true);
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ }
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+ if (mWallpaperConnection != null && mWallpaperConnection.mEngine != null) {
+ try {
+ mWallpaperConnection.mEngine.setVisibility(false);
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ }
+ }
+
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+
+ if (!mWallpaperConnection.connect()) {
+ mWallpaperConnection = null;
+ }
+ }
+
+ @Override
+ public void onDetachedFromWindow() {
+ super.onDetachedFromWindow();
+
+ if (mWallpaperConnection != null) {
+ mWallpaperConnection.disconnect();
+ }
+ mWallpaperConnection = null;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ // TODO: make this conditional on preview mode. Right now we
+ // don't get touch events in preview mode.
+ switch(event.getAction()) {
+ case MotionEvent.ACTION_DOWN:
+ if (mCurrentPreset == 0) {
+ mCurrentPreset = MagicSmokeRS.mPreset.length - 1;
+ } else {
+ mCurrentPreset--;
+ }
+ updatePrefs();
+ return true;
+ }
+
+ return super.onTouchEvent(event);
+ }
+
+ private void updatePrefs() {
+
+ Editor edit = mSharedPref.edit();
+ edit.putInt("preset", mCurrentPreset);
+ edit.commit();
+
+ }
+
+ class WallpaperConnection extends IWallpaperConnection.Stub implements ServiceConnection {
+ final Intent mIntent;
+ IWallpaperService mService;
+ IWallpaperEngine mEngine;
+ boolean mConnected;
+
+ WallpaperConnection(Intent intent) {
+ mIntent = intent;
+ }
+
+ public boolean connect() {
+ synchronized (this) {
+ if (!bindService(mIntent, this, Context.BIND_AUTO_CREATE)) {
+ return false;
+ }
+
+ mConnected = true;
+ return true;
+ }
+ }
+
+ public void disconnect() {
+ synchronized (this) {
+ mConnected = false;
+ if (mEngine != null) {
+ try {
+ mEngine.destroy();
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ mEngine = null;
+ }
+ unbindService(this);
+ mService = null;
+ }
+ }
+
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ if (mWallpaperConnection == this) {
+ mService = IWallpaperService.Stub.asInterface(service);
+ try {
+ final View view = findViewById(R.id.backgroundview);
+ final View root = view.getRootView();
+ mService.attach(this, view.getWindowToken(),
+ WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY,
+ true, root.getWidth(), root.getHeight());
+ } catch (RemoteException e) {
+ Log.w(LOG_TAG, "Failed attaching wallpaper; clearing", e);
+ }
+ }
+ }
+
+ public void onServiceDisconnected(ComponentName name) {
+ mService = null;
+ mEngine = null;
+ if (mWallpaperConnection == this) {
+ Log.w(LOG_TAG, "Wallpaper service gone: " + name);
+ }
+ }
+
+ public void attachEngine(IWallpaperEngine engine) {
+ synchronized (this) {
+ if (mConnected) {
+ mEngine = engine;
+ try {
+ engine.setVisibility(true);
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ } else {
+ try {
+ engine.destroy();
+ } catch (RemoteException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ public ParcelFileDescriptor setWallpaper(String name) {
+ return null;
+ }
+ }
+}
diff --git a/src/com/android/magicsmoke/RenderScriptScene.java b/src/com/android/magicsmoke/RenderScriptScene.java
new file mode 100644
index 0000000..446e01f
--- /dev/null
+++ b/src/com/android/magicsmoke/RenderScriptScene.java
@@ -0,0 +1,91 @@
+/*
+ * 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.magicsmoke;
+
+import android.content.res.Resources;
+import android.renderscript.RenderScript;
+import android.renderscript.ScriptC;
+import android.view.MotionEvent;
+
+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,
+ float xStep, float yStep, int xPixels, int yPixels) {
+ }
+ public void onTouchEvent(MotionEvent event) {
+ }
+
+}
diff --git a/src/com/android/magicsmoke/RenderScriptWallpaper.java b/src/com/android/magicsmoke/RenderScriptWallpaper.java
new file mode 100644
index 0000000..984496d
--- /dev/null
+++ b/src/com/android/magicsmoke/RenderScriptWallpaper.java
@@ -0,0 +1,114 @@
+/*
+ * 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.magicsmoke;
+
+import android.service.wallpaper.WallpaperService;
+import android.renderscript.RenderScript;
+import android.util.Log;
+import android.view.MotionEvent;
+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(true);
+ 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 onTouchEvent(MotionEvent event) {
+ mRenderer.onTouchEvent(event);
+ }
+
+ @Override
+ public void onOffsetsChanged(float xOffset, float yOffset,
+ float xStep, float yStep, int xPixels, int yPixels) {
+ mRenderer.setOffset(xOffset, yOffset, xStep, yStep, 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();
+ }
+ }
+}