packages/wallpapers/Basic
Revision | 913771d67c494d1e311a58febbf8e7b9017e0a3b (tree) |
---|---|
Time | 2009-08-22 03:24:10 |
Author | Romain Guy <romainguy@andr...> |
Commiter | Romain Guy |
Implement scrolling in PolarClock
@@ -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.MathUtils; | |
33 | 34 | |
34 | 35 | import java.util.TimeZone; |
35 | 36 |
@@ -71,7 +72,9 @@ public class PolarClockWallpaper extends WallpaperService { | ||
71 | 72 | |
72 | 73 | private final Paint mPaint = new Paint(); |
73 | 74 | 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; | |
75 | 78 | |
76 | 79 | private final BroadcastReceiver mWatcher = new BroadcastReceiver() { |
77 | 80 | public void onReceive(Context context, Intent intent) { |
@@ -86,21 +89,22 @@ public class PolarClockWallpaper extends WallpaperService { | ||
86 | 89 | drawFrame(true); |
87 | 90 | } |
88 | 91 | }; |
89 | - | |
90 | - ClockEngine() { | |
91 | - mColors = new int[COLORS_CACHE_COUNT]; | |
92 | + private boolean mVisible; | |
92 | 93 | |
94 | + ClockEngine() { | |
93 | 95 | final int[] colors = mColors; |
94 | 96 | final int count = colors.length; |
95 | 97 | |
98 | + float invCount = 1.0f / (float) COLORS_CACHE_COUNT; | |
96 | 99 | 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); | |
98 | 101 | } |
99 | 102 | } |
100 | 103 | |
101 | 104 | @Override |
102 | 105 | public void onCreate(SurfaceHolder surfaceHolder) { |
103 | 106 | super.onCreate(surfaceHolder); |
107 | + surfaceHolder.setSizeFromLayout(); | |
104 | 108 | |
105 | 109 | mCalendar = new Time(); |
106 | 110 | mCalendar.setToNow(); |
@@ -125,6 +129,7 @@ public class PolarClockWallpaper extends WallpaperService { | ||
125 | 129 | |
126 | 130 | @Override |
127 | 131 | public void onVisibilityChanged(boolean visible) { |
132 | + mVisible = visible; | |
128 | 133 | if (visible) { |
129 | 134 | if (!mWatcherRegistered) { |
130 | 135 | mWatcherRegistered = true; |
@@ -159,6 +164,12 @@ public class PolarClockWallpaper extends WallpaperService { | ||
159 | 164 | super.onSurfaceDestroyed(holder); |
160 | 165 | drawFrame(false); |
161 | 166 | } |
167 | + | |
168 | + @Override | |
169 | + public void onOffsetsChanged(float xOffset, float yOffset, int xPixels, int yPixels) { | |
170 | + mOffsetX = xOffset; | |
171 | + drawFrame(mVisible); | |
172 | + } | |
162 | 173 | |
163 | 174 | void drawFrame(boolean redraw) { |
164 | 175 | final SurfaceHolder holder = getSurfaceHolder(); |
@@ -177,12 +188,18 @@ public class PolarClockWallpaper extends WallpaperService { | ||
177 | 188 | calendar.setToNow(); |
178 | 189 | calendar.normalize(false); |
179 | 190 | |
191 | + int s = width / 2; | |
192 | + int t = height / 2; | |
193 | + | |
180 | 194 | c.drawColor(0xffffffff); |
181 | - c.translate(width / 2.0f, height/ 2.0f); | |
195 | + c.translate(s + MathUtils.lerp(s, -s, mOffsetX), t); | |
182 | 196 | c.rotate(-90.0f); |
197 | + if (height < width) { | |
198 | + c.scale(0.9f, 0.9f); | |
199 | + } | |
183 | 200 | |
184 | 201 | // Draw seconds |
185 | - float size = width / 2.0f / 2.0f - RING_THICKNESS; | |
202 | + float size = Math.min(width, height) * 0.5f - RING_THICKNESS; | |
186 | 203 | final RectF rect = mRect; |
187 | 204 | rect.set(-size, -size, size, size); |
188 | 205 |