• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/wallpapers/Basic


Commit MetaInfo

Revision0e1eb1a99bf6b95cebdcf9a1d855f4d4bc2a733d (tree)
Time2009-09-08 15:28:32
AuthorDianne Hackborn <hackbod@goog...>
CommiterDianne Hackborn

Log Message

Update wallpapers for configuration API.

Now all wallpapers have a wallpaper XML file describing them. All of these
are currently empty, except for the polar clock which grows a configuration
UI which currently allows you to select whether or not to display seconds.

Change-Id: I1ef2466c23e290f5157cc241867d83c17feba245

Change Summary

Incremental Difference

--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -56,6 +56,7 @@
5656 <intent-filter>
5757 <action android:name="android.service.wallpaper.WallpaperService" />
5858 </intent-filter>
59+ <meta-data android:name="android.service.wallpaper" android:resource="@xml/grass" />
5960 </service>
6061
6162 <service
@@ -65,8 +66,16 @@
6566 <intent-filter>
6667 <action android:name="android.service.wallpaper.WallpaperService" />
6768 </intent-filter>
69+ <meta-data android:name="android.service.wallpaper" android:resource="@xml/galaxy" />
6870 </service>
6971
72+ <activity
73+ android:label="@string/clock_settings"
74+ android:name="com.android.wallpaper.polarclock.PolarClockSettings"
75+ android:theme="@android:style/Theme.Wallpaper"
76+ android:exported="true">
77+ </activity>
78+
7079 <service
7180 android:label="@string/wallpaper_clock"
7281 android:name="com.android.wallpaper.polarclock.PolarClockWallpaper"
@@ -74,6 +83,7 @@
7483 <intent-filter>
7584 <action android:name="android.service.wallpaper.WallpaperService" />
7685 </intent-filter>
86+ <meta-data android:name="android.service.wallpaper" android:resource="@xml/polar_clock" />
7787 </service>
7888
7989 </application>
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -28,8 +28,14 @@
2828
2929 <!-- Wallpaper showing grass and the sky -->
3030 <string name="wallpaper_grass">Grass</string>
31+
3132 <!-- Wallpaper showing a galaxy -->
3233 <string name="wallpaper_galaxy">Galaxy</string>
34+
3335 <!-- Wallpaper showing a clock -->
3436 <string name="wallpaper_clock">Polar clock</string>
37+ <!-- Polar clock: title of settings activity -->
38+ <string name="clock_settings">Polar clock settings</string>
39+ <!-- Polar clock: label for "show seconds" pref -->
40+ <string name="show_seconds">Show seconds</string>
3541 </resources>
--- /dev/null
+++ b/res/xml/galaxy.xml
@@ -0,0 +1,24 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!--
3+/**
4+ * Copyright (c) 2008, The Android Open Source Project
5+ *
6+ * Licensed under the Apache License, Version 2.0 (the "License");
7+ * you may not use this file except in compliance with the License.
8+ * You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing, software
13+ * distributed under the License is distributed on an "AS IS" BASIS,
14+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ * See the License for the specific language governing permissions and
16+ * limitations under the License.
17+ */
18+-->
19+
20+<!-- The attributes in this XML file provide configuration information -->
21+<!-- about the galaxy wallpaper. -->
22+
23+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
24+/>
--- /dev/null
+++ b/res/xml/grass.xml
@@ -0,0 +1,24 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!--
3+/**
4+ * Copyright (c) 2008, The Android Open Source Project
5+ *
6+ * Licensed under the Apache License, Version 2.0 (the "License");
7+ * you may not use this file except in compliance with the License.
8+ * You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing, software
13+ * distributed under the License is distributed on an "AS IS" BASIS,
14+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ * See the License for the specific language governing permissions and
16+ * limitations under the License.
17+ */
18+-->
19+
20+<!-- The attributes in this XML file provide configuration information -->
21+<!-- about the grass wallpaper. -->
22+
23+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
24+/>
--- /dev/null
+++ b/res/xml/polar_clock.xml
@@ -0,0 +1,25 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!--
3+/**
4+ * Copyright (c) 2008, The Android Open Source Project
5+ *
6+ * Licensed under the Apache License, Version 2.0 (the "License");
7+ * you may not use this file except in compliance with the License.
8+ * You may obtain a copy of the License at
9+ *
10+ * http://www.apache.org/licenses/LICENSE-2.0
11+ *
12+ * Unless required by applicable law or agreed to in writing, software
13+ * distributed under the License is distributed on an "AS IS" BASIS,
14+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ * See the License for the specific language governing permissions and
16+ * limitations under the License.
17+ */
18+-->
19+
20+<!-- The attributes in this XML file provide configuration information -->
21+<!-- about the polar clock. -->
22+
23+<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
24+ android:settingsActivity="com.android.wallpaper.polarclock.PolarClockSettings"
25+/>
--- /dev/null
+++ b/res/xml/polar_clock_prefs.xml
@@ -0,0 +1,27 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<!-- Copyright (C) 2008 The Android Open Source Project
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ http://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+-->
16+
17+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
18+ android:title="@string/clock_settings"
19+ android:key="polar_clock_settings">
20+
21+ <CheckBoxPreference
22+ android:key="show_seconds"
23+ android:title="@string/show_seconds"
24+ android:defaultValue="true"
25+ android:persistent="true"
26+ />
27+</PreferenceScreen>
--- /dev/null
+++ b/src/com/android/wallpaper/polarclock/PolarClockSettings.java
@@ -0,0 +1,61 @@
1+/*
2+ * Copyright (C) 2009 Google Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+ * use this file except in compliance with the License. You may obtain a copy of
6+ * the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+ * License for the specific language governing permissions and limitations under
14+ * the License.
15+ */
16+
17+package com.android.wallpaper.polarclock;
18+
19+import com.android.wallpaper.R;
20+
21+import android.content.SharedPreferences;
22+import android.os.Bundle;
23+import android.preference.CheckBoxPreference;
24+import android.preference.PreferenceActivity;
25+
26+public class PolarClockSettings extends PreferenceActivity
27+ implements SharedPreferences.OnSharedPreferenceChangeListener {
28+
29+ private CheckBoxPreference mShowSeconds;
30+
31+ @Override
32+ protected void onCreate(Bundle icicle) {
33+ super.onCreate(icicle);
34+ getPreferenceManager().setSharedPreferencesName(
35+ PolarClockWallpaper.SHARED_PREFS_NAME);
36+ addPreferencesFromResource(R.xml.polar_clock_prefs);
37+ mShowSeconds = (CheckBoxPreference) findPreference(
38+ PolarClockWallpaper.PREF_SHOW_SECONDS);
39+ getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(
40+ this);
41+ getWindow().setBackgroundDrawableResource(
42+ android.R.drawable.screen_background_dark_transparent);
43+ }
44+
45+ @Override
46+ protected void onResume() {
47+ super.onResume();
48+ }
49+
50+ @Override
51+ protected void onDestroy() {
52+ getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
53+ this);
54+ super.onDestroy();
55+ }
56+
57+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
58+ String key) {
59+ //(new BackupManager(this)).dataChanged();
60+ }
61+}
--- a/src/com/android/wallpaper/polarclock/PolarClockWallpaper.java
+++ b/src/com/android/wallpaper/polarclock/PolarClockWallpaper.java
@@ -27,15 +27,18 @@ import android.content.IntentFilter;
2727 import android.content.Intent;
2828 import android.content.BroadcastReceiver;
2929 import android.content.Context;
30+import android.content.SharedPreferences;
3031 import android.os.Handler;
3132 import android.os.SystemClock;
3233 import android.text.format.Time;
33-import android.util.Log;
3434 import android.util.MathUtils;
3535
3636 import java.util.TimeZone;
3737
3838 public class PolarClockWallpaper extends WallpaperService {
39+ public static final String SHARED_PREFS_NAME = "polar_clock_settings";
40+ public static final String PREF_SHOW_SECONDS = "show_seconds";
41+
3942 private final Handler mHandler = new Handler();
4043
4144 private IntentFilter mFilter;
@@ -57,7 +60,8 @@ public class PolarClockWallpaper extends WallpaperService {
5760 return new ClockEngine();
5861 }
5962
60- class ClockEngine extends Engine {
63+ class ClockEngine extends Engine
64+ implements SharedPreferences.OnSharedPreferenceChangeListener {
6165 private static final float SATURATION = 0.8f;
6266 private static final float BRIGHTNESS = 0.9f;
6367
@@ -67,6 +71,9 @@ public class PolarClockWallpaper extends WallpaperService {
6771
6872 private static final int COLORS_CACHE_COUNT = 720;
6973
74+ private SharedPreferences mPrefs;
75+ private boolean mShowSeconds;
76+
7077 private boolean mWatcherRegistered;
7178 private float mStartTime;
7279 private Time mCalendar;
@@ -105,7 +112,10 @@ public class PolarClockWallpaper extends WallpaperService {
105112 @Override
106113 public void onCreate(SurfaceHolder surfaceHolder) {
107114 super.onCreate(surfaceHolder);
108- surfaceHolder.setSizeFromLayout();
115+
116+ mPrefs = PolarClockWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, 0);
117+ mPrefs.registerOnSharedPreferenceChangeListener(this);
118+ onSharedPreferenceChanged(mPrefs, null);
109119
110120 mCalendar = new Time();
111121 mCalendar.setToNow();
@@ -128,6 +138,16 @@ public class PolarClockWallpaper extends WallpaperService {
128138 mHandler.removeCallbacks(mDrawClock);
129139 }
130140
141+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
142+ String key) {
143+ if (key == null || PREF_SHOW_SECONDS.equals(key)) {
144+ mShowSeconds = sharedPreferences.getBoolean(PREF_SHOW_SECONDS, true);
145+ if (mVisible) {
146+ drawFrame();
147+ }
148+ }
149+ }
150+
131151 @Override
132152 public void onVisibilityChanged(boolean visible) {
133153 mVisible = visible;
@@ -200,15 +220,18 @@ public class PolarClockWallpaper extends WallpaperService {
200220 c.scale(0.9f, 0.9f);
201221 }
202222
203- // Draw seconds
204223 float size = Math.min(width, height) * 0.5f - RING_THICKNESS;
205224 final RectF rect = mRect;
206225 rect.set(-size, -size, size, size);
207-
208- float angle = ((mStartTime + SystemClock.elapsedRealtime()) % 60000) / 60000.0f;
209- if (angle < 0) angle = -angle;
210- paint.setColor(colors[((int) (angle * COLORS_CACHE_COUNT))]);
211- c.drawArc(rect, 0.0f, angle * 360.0f, false, paint);
226+ float angle;
227+
228+ if (mShowSeconds) {
229+ // Draw seconds
230+ angle = ((mStartTime + SystemClock.elapsedRealtime()) % 60000) / 60000.0f;
231+ if (angle < 0) angle = -angle;
232+ paint.setColor(colors[((int) (angle * COLORS_CACHE_COUNT))]);
233+ c.drawArc(rect, 0.0f, angle * 360.0f, false, paint);
234+ }
212235
213236 // Draw minutes
214237 size -= (SMALL_GAP + RING_THICKNESS);
@@ -249,7 +272,13 @@ public class PolarClockWallpaper extends WallpaperService {
249272
250273 mHandler.removeCallbacks(mDrawClock);
251274 if (mVisible) {
252- mHandler.postDelayed(mDrawClock, 1000 / 25);
275+ if (mShowSeconds) {
276+ mHandler.postDelayed(mDrawClock, 1000 / 25);
277+ } else {
278+ // If we aren't showing seconds, we don't need to update
279+ // nearly as often.
280+ mHandler.postDelayed(mDrawClock, 2000);
281+ }
253282 }
254283 }
255284 }