• 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

Revision913771d67c494d1e311a58febbf8e7b9017e0a3b (tree)
Time2009-08-22 03:24:10
AuthorRomain Guy <romainguy@andr...>
CommiterRomain Guy

Log Message

Implement scrolling in PolarClock

Change Summary

Incremental Difference

--- a/src/com/android/wallpaper/polarclock/PolarClockWallpaper.java
+++ b/src/com/android/wallpaper/polarclock/PolarClockWallpaper.java
@@ -30,6 +30,7 @@ import android.content.Context;
3030 import android.os.Handler;
3131 import android.os.SystemClock;
3232 import android.text.format.Time;
33+import android.util.MathUtils;
3334
3435 import java.util.TimeZone;
3536
@@ -71,7 +72,9 @@ public class PolarClockWallpaper extends WallpaperService {
7172
7273 private final Paint mPaint = new Paint();
7374 private final RectF mRect = new RectF();
74- private final int[] mColors;
75+ private final int[] mColors = new int[COLORS_CACHE_COUNT];
76+
77+ private float mOffsetX;
7578
7679 private final BroadcastReceiver mWatcher = new BroadcastReceiver() {
7780 public void onReceive(Context context, Intent intent) {
@@ -86,21 +89,22 @@ public class PolarClockWallpaper extends WallpaperService {
8689 drawFrame(true);
8790 }
8891 };
89-
90- ClockEngine() {
91- mColors = new int[COLORS_CACHE_COUNT];
92+ private boolean mVisible;
9293
94+ ClockEngine() {
9395 final int[] colors = mColors;
9496 final int count = colors.length;
9597
98+ float invCount = 1.0f / (float) COLORS_CACHE_COUNT;
9699 for (int i = 0; i < count; i++) {
97- colors[i] = Color.HSBtoColor(i / (float) COLORS_CACHE_COUNT, SATURATION, BRIGHTNESS);
100+ colors[i] = Color.HSBtoColor(i * invCount, SATURATION, BRIGHTNESS);
98101 }
99102 }
100103
101104 @Override
102105 public void onCreate(SurfaceHolder surfaceHolder) {
103106 super.onCreate(surfaceHolder);
107+ surfaceHolder.setSizeFromLayout();
104108
105109 mCalendar = new Time();
106110 mCalendar.setToNow();
@@ -125,6 +129,7 @@ public class PolarClockWallpaper extends WallpaperService {
125129
126130 @Override
127131 public void onVisibilityChanged(boolean visible) {
132+ mVisible = visible;
128133 if (visible) {
129134 if (!mWatcherRegistered) {
130135 mWatcherRegistered = true;
@@ -159,6 +164,12 @@ public class PolarClockWallpaper extends WallpaperService {
159164 super.onSurfaceDestroyed(holder);
160165 drawFrame(false);
161166 }
167+
168+ @Override
169+ public void onOffsetsChanged(float xOffset, float yOffset, int xPixels, int yPixels) {
170+ mOffsetX = xOffset;
171+ drawFrame(mVisible);
172+ }
162173
163174 void drawFrame(boolean redraw) {
164175 final SurfaceHolder holder = getSurfaceHolder();
@@ -177,12 +188,18 @@ public class PolarClockWallpaper extends WallpaperService {
177188 calendar.setToNow();
178189 calendar.normalize(false);
179190
191+ int s = width / 2;
192+ int t = height / 2;
193+
180194 c.drawColor(0xffffffff);
181- c.translate(width / 2.0f, height/ 2.0f);
195+ c.translate(s + MathUtils.lerp(s, -s, mOffsetX), t);
182196 c.rotate(-90.0f);
197+ if (height < width) {
198+ c.scale(0.9f, 0.9f);
199+ }
183200
184201 // Draw seconds
185- float size = width / 2.0f / 2.0f - RING_THICKNESS;
202+ float size = Math.min(width, height) * 0.5f - RING_THICKNESS;
186203 final RectF rect = mRect;
187204 rect.set(-size, -size, size, size);
188205