packages/wallpapers/Basic
Revision | 0e1eb1a99bf6b95cebdcf9a1d855f4d4bc2a733d (tree) |
---|---|
Time | 2009-09-08 15:28:32 |
Author | Dianne Hackborn <hackbod@goog...> |
Commiter | Dianne Hackborn |
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
@@ -56,6 +56,7 @@ | ||
56 | 56 | <intent-filter> |
57 | 57 | <action android:name="android.service.wallpaper.WallpaperService" /> |
58 | 58 | </intent-filter> |
59 | + <meta-data android:name="android.service.wallpaper" android:resource="@xml/grass" /> | |
59 | 60 | </service> |
60 | 61 | |
61 | 62 | <service |
@@ -65,8 +66,16 @@ | ||
65 | 66 | <intent-filter> |
66 | 67 | <action android:name="android.service.wallpaper.WallpaperService" /> |
67 | 68 | </intent-filter> |
69 | + <meta-data android:name="android.service.wallpaper" android:resource="@xml/galaxy" /> | |
68 | 70 | </service> |
69 | 71 | |
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 | + | |
70 | 79 | <service |
71 | 80 | android:label="@string/wallpaper_clock" |
72 | 81 | android:name="com.android.wallpaper.polarclock.PolarClockWallpaper" |
@@ -74,6 +83,7 @@ | ||
74 | 83 | <intent-filter> |
75 | 84 | <action android:name="android.service.wallpaper.WallpaperService" /> |
76 | 85 | </intent-filter> |
86 | + <meta-data android:name="android.service.wallpaper" android:resource="@xml/polar_clock" /> | |
77 | 87 | </service> |
78 | 88 | |
79 | 89 | </application> |
@@ -28,8 +28,14 @@ | ||
28 | 28 | |
29 | 29 | <!-- Wallpaper showing grass and the sky --> |
30 | 30 | <string name="wallpaper_grass">Grass</string> |
31 | + | |
31 | 32 | <!-- Wallpaper showing a galaxy --> |
32 | 33 | <string name="wallpaper_galaxy">Galaxy</string> |
34 | + | |
33 | 35 | <!-- Wallpaper showing a clock --> |
34 | 36 | <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> | |
35 | 41 | </resources> |
@@ -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 | +/> |
@@ -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 | +/> |
@@ -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 | +/> |
@@ -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> |
@@ -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 | +} |
@@ -27,15 +27,18 @@ import android.content.IntentFilter; | ||
27 | 27 | import android.content.Intent; |
28 | 28 | import android.content.BroadcastReceiver; |
29 | 29 | import android.content.Context; |
30 | +import android.content.SharedPreferences; | |
30 | 31 | import android.os.Handler; |
31 | 32 | import android.os.SystemClock; |
32 | 33 | import android.text.format.Time; |
33 | -import android.util.Log; | |
34 | 34 | import android.util.MathUtils; |
35 | 35 | |
36 | 36 | import java.util.TimeZone; |
37 | 37 | |
38 | 38 | 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 | + | |
39 | 42 | private final Handler mHandler = new Handler(); |
40 | 43 | |
41 | 44 | private IntentFilter mFilter; |
@@ -57,7 +60,8 @@ public class PolarClockWallpaper extends WallpaperService { | ||
57 | 60 | return new ClockEngine(); |
58 | 61 | } |
59 | 62 | |
60 | - class ClockEngine extends Engine { | |
63 | + class ClockEngine extends Engine | |
64 | + implements SharedPreferences.OnSharedPreferenceChangeListener { | |
61 | 65 | private static final float SATURATION = 0.8f; |
62 | 66 | private static final float BRIGHTNESS = 0.9f; |
63 | 67 |
@@ -67,6 +71,9 @@ public class PolarClockWallpaper extends WallpaperService { | ||
67 | 71 | |
68 | 72 | private static final int COLORS_CACHE_COUNT = 720; |
69 | 73 | |
74 | + private SharedPreferences mPrefs; | |
75 | + private boolean mShowSeconds; | |
76 | + | |
70 | 77 | private boolean mWatcherRegistered; |
71 | 78 | private float mStartTime; |
72 | 79 | private Time mCalendar; |
@@ -105,7 +112,10 @@ public class PolarClockWallpaper extends WallpaperService { | ||
105 | 112 | @Override |
106 | 113 | public void onCreate(SurfaceHolder surfaceHolder) { |
107 | 114 | super.onCreate(surfaceHolder); |
108 | - surfaceHolder.setSizeFromLayout(); | |
115 | + | |
116 | + mPrefs = PolarClockWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, 0); | |
117 | + mPrefs.registerOnSharedPreferenceChangeListener(this); | |
118 | + onSharedPreferenceChanged(mPrefs, null); | |
109 | 119 | |
110 | 120 | mCalendar = new Time(); |
111 | 121 | mCalendar.setToNow(); |
@@ -128,6 +138,16 @@ public class PolarClockWallpaper extends WallpaperService { | ||
128 | 138 | mHandler.removeCallbacks(mDrawClock); |
129 | 139 | } |
130 | 140 | |
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 | + | |
131 | 151 | @Override |
132 | 152 | public void onVisibilityChanged(boolean visible) { |
133 | 153 | mVisible = visible; |
@@ -200,15 +220,18 @@ public class PolarClockWallpaper extends WallpaperService { | ||
200 | 220 | c.scale(0.9f, 0.9f); |
201 | 221 | } |
202 | 222 | |
203 | - // Draw seconds | |
204 | 223 | float size = Math.min(width, height) * 0.5f - RING_THICKNESS; |
205 | 224 | final RectF rect = mRect; |
206 | 225 | 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 | + } | |
212 | 235 | |
213 | 236 | // Draw minutes |
214 | 237 | size -= (SMALL_GAP + RING_THICKNESS); |
@@ -249,7 +272,13 @@ public class PolarClockWallpaper extends WallpaperService { | ||
249 | 272 | |
250 | 273 | mHandler.removeCallbacks(mDrawClock); |
251 | 274 | 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 | + } | |
253 | 282 | } |
254 | 283 | } |
255 | 284 | } |