packages/wallpapers/Basic
修订版 | b8ca9a4b5b8f70306b14d0cd05cbc8e4d1d7e0e5 (tree) |
---|---|
时间 | 2009-08-21 11:39:42 |
作者 | Dianne Hackborn <hackbod@goog...> |
Commiter | Dianne Hackborn |
Fix polar clock to work when showing a preview.
@@ -35,16 +35,8 @@ import java.util.TimeZone; | ||
35 | 35 | |
36 | 36 | public class PolarClockWallpaper extends WallpaperService { |
37 | 37 | private final Handler mHandler = new Handler(); |
38 | - private final Runnable mDrawClock = new Runnable() { | |
39 | - public void run() { | |
40 | - mEngine.drawFrame(true); | |
41 | - } | |
42 | - }; | |
43 | 38 | |
44 | - private boolean mWatcherRegistered; | |
45 | - private TimeWatcher mWatcher; | |
46 | 39 | private IntentFilter mFilter; |
47 | - private ClockEngine mEngine; | |
48 | 40 | |
49 | 41 | @Override |
50 | 42 | public void onCreate() { |
@@ -52,31 +44,15 @@ public class PolarClockWallpaper extends WallpaperService { | ||
52 | 44 | |
53 | 45 | mFilter = new IntentFilter(); |
54 | 46 | mFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED); |
55 | - | |
56 | - mWatcher = new TimeWatcher(); | |
57 | 47 | } |
58 | 48 | |
59 | 49 | @Override |
60 | 50 | public void onDestroy() { |
61 | 51 | super.onDestroy(); |
62 | - if (mWatcherRegistered) { | |
63 | - mWatcherRegistered = false; | |
64 | - unregisterReceiver(mWatcher); | |
65 | - } | |
66 | - mHandler.removeCallbacks(mDrawClock); | |
67 | 52 | } |
68 | 53 | |
69 | 54 | public Engine onCreateEngine() { |
70 | - mEngine = new ClockEngine(); | |
71 | - return mEngine; | |
72 | - } | |
73 | - | |
74 | - class TimeWatcher extends BroadcastReceiver { | |
75 | - public void onReceive(Context context, Intent intent) { | |
76 | - final String timeZone = intent.getStringExtra("time-zone"); | |
77 | - mEngine.mCalendar = new Time(TimeZone.getTimeZone(timeZone).getID()); | |
78 | - mEngine.drawFrame(true); | |
79 | - } | |
55 | + return new ClockEngine(); | |
80 | 56 | } |
81 | 57 | |
82 | 58 | class ClockEngine extends Engine { |
@@ -89,6 +65,7 @@ public class PolarClockWallpaper extends WallpaperService { | ||
89 | 65 | |
90 | 66 | private static final int COLORS_CACHE_COUNT = 720; |
91 | 67 | |
68 | + private boolean mWatcherRegistered; | |
92 | 69 | private float mStartTime; |
93 | 70 | private Time mCalendar; |
94 | 71 |
@@ -96,6 +73,20 @@ public class PolarClockWallpaper extends WallpaperService { | ||
96 | 73 | private final RectF mRect = new RectF(); |
97 | 74 | private final int[] mColors; |
98 | 75 | |
76 | + private final BroadcastReceiver mWatcher = new BroadcastReceiver() { | |
77 | + public void onReceive(Context context, Intent intent) { | |
78 | + final String timeZone = intent.getStringExtra("time-zone"); | |
79 | + mCalendar = new Time(TimeZone.getTimeZone(timeZone).getID()); | |
80 | + drawFrame(true); | |
81 | + } | |
82 | + }; | |
83 | + | |
84 | + private final Runnable mDrawClock = new Runnable() { | |
85 | + public void run() { | |
86 | + drawFrame(true); | |
87 | + } | |
88 | + }; | |
89 | + | |
99 | 90 | ClockEngine() { |
100 | 91 | mColors = new int[COLORS_CACHE_COUNT]; |
101 | 92 |
@@ -123,6 +114,16 @@ public class PolarClockWallpaper extends WallpaperService { | ||
123 | 114 | } |
124 | 115 | |
125 | 116 | @Override |
117 | + public void onDestroy() { | |
118 | + super.onDestroy(); | |
119 | + if (mWatcherRegistered) { | |
120 | + mWatcherRegistered = false; | |
121 | + unregisterReceiver(mWatcher); | |
122 | + } | |
123 | + mHandler.removeCallbacks(mDrawClock); | |
124 | + } | |
125 | + | |
126 | + @Override | |
126 | 127 | public void onVisibilityChanged(boolean visible) { |
127 | 128 | if (visible) { |
128 | 129 | if (!mWatcherRegistered) { |