packages/wallpapers/Basic
修订版 | b2487598a8abb56463fbb3e58d59d56256dabdd8 (tree) |
---|---|
时间 | 2009-08-30 16:39:01 |
作者 | Dianne Hackborn <hackbod@goog...> |
Commiter | Dianne Hackborn |
A few little fixes to the polar clock.
I was trying to figure out how to get it to fill the screen correctly when in
preview mode, but have no idea. :)
Change-Id: Ia4bb3ea4f4922475a27da0864d6a9d5e284ac37b
@@ -30,6 +30,7 @@ import android.content.Context; | ||
30 | 30 | import android.os.Handler; |
31 | 31 | import android.os.SystemClock; |
32 | 32 | import android.text.format.Time; |
33 | +import android.util.Log; | |
33 | 34 | import android.util.MathUtils; |
34 | 35 | |
35 | 36 | import java.util.TimeZone; |
@@ -80,13 +81,13 @@ public class PolarClockWallpaper extends WallpaperService { | ||
80 | 81 | public void onReceive(Context context, Intent intent) { |
81 | 82 | final String timeZone = intent.getStringExtra("time-zone"); |
82 | 83 | mCalendar = new Time(TimeZone.getTimeZone(timeZone).getID()); |
83 | - drawFrame(true); | |
84 | + drawFrame(); | |
84 | 85 | } |
85 | 86 | }; |
86 | 87 | |
87 | 88 | private final Runnable mDrawClock = new Runnable() { |
88 | 89 | public void run() { |
89 | - drawFrame(true); | |
90 | + drawFrame(); | |
90 | 91 | } |
91 | 92 | }; |
92 | 93 | private boolean mVisible; |
@@ -145,13 +146,13 @@ public class PolarClockWallpaper extends WallpaperService { | ||
145 | 146 | } |
146 | 147 | mHandler.removeCallbacks(mDrawClock); |
147 | 148 | } |
148 | - drawFrame(visible); | |
149 | + drawFrame(); | |
149 | 150 | } |
150 | 151 | |
151 | 152 | @Override |
152 | 153 | public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
153 | 154 | super.onSurfaceChanged(holder, format, width, height); |
154 | - drawFrame(true); | |
155 | + drawFrame(); | |
155 | 156 | } |
156 | 157 | |
157 | 158 | @Override |
@@ -162,16 +163,17 @@ public class PolarClockWallpaper extends WallpaperService { | ||
162 | 163 | @Override |
163 | 164 | public void onSurfaceDestroyed(SurfaceHolder holder) { |
164 | 165 | super.onSurfaceDestroyed(holder); |
165 | - drawFrame(false); | |
166 | + mVisible = false; | |
167 | + mHandler.removeCallbacks(mDrawClock); | |
166 | 168 | } |
167 | 169 | |
168 | 170 | @Override |
169 | 171 | public void onOffsetsChanged(float xOffset, float yOffset, int xPixels, int yPixels) { |
170 | 172 | mOffsetX = xOffset; |
171 | - drawFrame(mVisible); | |
173 | + drawFrame(); | |
172 | 174 | } |
173 | 175 | |
174 | - void drawFrame(boolean redraw) { | |
176 | + void drawFrame() { | |
175 | 177 | final SurfaceHolder holder = getSurfaceHolder(); |
176 | 178 | final Rect frame = holder.getSurfaceFrame(); |
177 | 179 | final int width = frame.width(); |
@@ -204,6 +206,7 @@ public class PolarClockWallpaper extends WallpaperService { | ||
204 | 206 | rect.set(-size, -size, size, size); |
205 | 207 | |
206 | 208 | float angle = ((mStartTime + SystemClock.elapsedRealtime()) % 60000) / 60000.0f; |
209 | + if (angle < 0) angle = -angle; | |
207 | 210 | paint.setColor(colors[((int) (angle * COLORS_CACHE_COUNT))]); |
208 | 211 | c.drawArc(rect, 0.0f, angle * 360.0f, false, paint); |
209 | 212 |
@@ -245,7 +248,7 @@ public class PolarClockWallpaper extends WallpaperService { | ||
245 | 248 | } |
246 | 249 | |
247 | 250 | mHandler.removeCallbacks(mDrawClock); |
248 | - if (redraw) { | |
251 | + if (mVisible) { | |
249 | 252 | mHandler.postDelayed(mDrawClock, 1000 / 25); |
250 | 253 | } |
251 | 254 | } |