Skip to content

Commit 955a016

Browse files
author
Jim Miller
committed
Fix 6613962: Update keyguard to use new GlowPadView UX design.
Change-Id: I4f1ef3107e5550f7df9dcb412943a84b66432b7d
1 parent 1c95810 commit 955a016

File tree

28 files changed

+1655
-157
lines changed

28 files changed

+1655
-157
lines changed

core/java/com/android/internal/widget/multiwaveview/GlowPadView.java

Lines changed: 1226 additions & 0 deletions
Large diffs are not rendered by default.

core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ public interface OnTriggerListener {
117117
private float mWaveCenterY;
118118
private int mMaxTargetHeight;
119119
private int mMaxTargetWidth;
120-
private float mHorizontalOffset;
121-
private float mVerticalOffset;
122120

123121
private float mOuterRadius = 0.0f;
124122
private float mHitRadius = 0.0f;
@@ -215,9 +213,6 @@ public MultiWaveView(Context context, AttributeSet attrs) {
215213

216214
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiWaveView);
217215
mOuterRadius = a.getDimension(R.styleable.MultiWaveView_outerRadius, mOuterRadius);
218-
// mHorizontalOffset = a.getDimension(R.styleable.MultiWaveView_horizontalOffset,
219-
// mHorizontalOffset);
220-
// mVerticalOffset = a.getDimension(R.styleable.MultiWaveView_verticalOffset, mVerticalOffset);
221216
mHitRadius = a.getDimension(R.styleable.MultiWaveView_hitRadius, mHitRadius);
222217
mSnapMargin = a.getDimension(R.styleable.MultiWaveView_snapMargin, mSnapMargin);
223218
mVibrationDuration = a.getInt(R.styleable.MultiWaveView_vibrationDuration,
@@ -230,7 +225,6 @@ public MultiWaveView(Context context, AttributeSet attrs) {
230225
mOuterRing = new TargetDrawable(res,
231226
a.peekValue(R.styleable.MultiWaveView_waveDrawable).resourceId);
232227
mAlwaysTrackFinger = a.getBoolean(R.styleable.MultiWaveView_alwaysTrackFinger, false);
233-
mGravity = a.getInt(R.styleable.MultiWaveView_gravity, Gravity.TOP);
234228

235229
// Read array of chevron drawables
236230
TypedValue outValue = new TypedValue();
@@ -244,24 +238,6 @@ public MultiWaveView(Context context, AttributeSet attrs) {
244238
}
245239
}
246240

247-
// Support old-style chevron specification if new specification not found
248-
if (mChevronDrawables.size() == 0) {
249-
final int chevronResIds[] = {
250-
R.styleable.MultiWaveView_rightChevronDrawable,
251-
R.styleable.MultiWaveView_topChevronDrawable,
252-
R.styleable.MultiWaveView_leftChevronDrawable,
253-
R.styleable.MultiWaveView_bottomChevronDrawable
254-
};
255-
256-
for (int i = 0; i < chevronResIds.length; i++) {
257-
TypedValue typedValue = a.peekValue(chevronResIds[i]);
258-
for (int k = 0; k < mFeedbackCount; k++) {
259-
mChevronDrawables.add(
260-
typedValue != null ? new TargetDrawable(res, typedValue.resourceId) : null);
261-
}
262-
}
263-
}
264-
265241
// Read array of target drawables
266242
if (a.getValue(R.styleable.MultiWaveView_targetDrawables, outValue)) {
267243
internalSetTargetResources(outValue.resourceId);
@@ -289,6 +265,12 @@ public MultiWaveView(Context context, AttributeSet attrs) {
289265
}
290266

291267
a.recycle();
268+
269+
// Use gravity attribute from LinearLayout
270+
a = context.obtainStyledAttributes(attrs, android.R.styleable.LinearLayout);
271+
mGravity = a.getInt(android.R.styleable.LinearLayout_gravity, Gravity.TOP);
272+
a.recycle();
273+
292274
setVibrateEnabled(mVibrationDuration > 0);
293275
assignDefaultsIfNeeded();
294276
}
@@ -302,8 +284,6 @@ private void dump() {
302284
Log.v(TAG, "TapRadius = " + mTapRadius);
303285
Log.v(TAG, "WaveCenterX = " + mWaveCenterX);
304286
Log.v(TAG, "WaveCenterY = " + mWaveCenterY);
305-
Log.v(TAG, "HorizontalOffset = " + mHorizontalOffset);
306-
Log.v(TAG, "VerticalOffset = " + mVerticalOffset);
307287
}
308288

309289
public void suspendAnimations() {
@@ -1042,9 +1022,9 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
10421022
// width or the specified outer radius.
10431023
final float placementWidth = Math.max(mOuterRing.getWidth(), 2 * mOuterRadius);
10441024
final float placementHeight = Math.max(mOuterRing.getHeight(), 2 * mOuterRadius);
1045-
float newWaveCenterX = mHorizontalOffset + mHorizontalInset
1025+
float newWaveCenterX = mHorizontalInset
10461026
+ Math.max(width, mMaxTargetWidth + placementWidth) / 2;
1047-
float newWaveCenterY = mVerticalOffset + mVerticalInset
1027+
float newWaveCenterY = mVerticalInset
10481028
+ Math.max(height, + mMaxTargetHeight + placementHeight) / 2;
10491029

10501030
if (mInitialLayout) {
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
/*
2+
* Copyright (C) 2012 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+
package com.android.internal.widget.multiwaveview;
18+
19+
import java.util.ArrayList;
20+
21+
import android.graphics.Canvas;
22+
import android.graphics.Color;
23+
import android.graphics.Paint;
24+
import android.graphics.drawable.Drawable;
25+
import android.util.FloatMath;
26+
import android.util.Log;
27+
28+
public class PointCloud {
29+
private static final float MIN_POINT_SIZE = 2.0f;
30+
private static final float MAX_POINT_SIZE = 4.0f;
31+
private static final int INNER_POINTS = 8;
32+
private static final String TAG = "PointCloud";
33+
private ArrayList<Point> mPointCloud = new ArrayList<Point>();
34+
private Drawable mDrawable;
35+
private float mCenterX;
36+
private float mCenterY;
37+
private Paint mPaint;
38+
private float mScale = 1.0f;
39+
private static final float PI = (float) Math.PI;
40+
41+
// These allow us to have multiple concurrent animations.
42+
WaveManager waveManager = new WaveManager();
43+
GlowManager glowManager = new GlowManager();
44+
private float mOuterRadius;
45+
46+
public class WaveManager {
47+
private float radius = 50;
48+
private float width = 200.0f; // TODO: Make configurable
49+
private float alpha = 0.0f;
50+
public void setRadius(float r) {
51+
radius = r;
52+
}
53+
54+
public float getRadius() {
55+
return radius;
56+
}
57+
58+
public void setAlpha(float a) {
59+
alpha = a;
60+
}
61+
62+
public float getAlpha() {
63+
return alpha;
64+
}
65+
};
66+
67+
public class GlowManager {
68+
private float x;
69+
private float y;
70+
private float radius = 0.0f;
71+
private float alpha = 0.0f;
72+
73+
public void setX(float x1) {
74+
x = x1;
75+
}
76+
77+
public float getX() {
78+
return x;
79+
}
80+
81+
public void setY(float y1) {
82+
y = y1;
83+
}
84+
85+
public float getY() {
86+
return y;
87+
}
88+
89+
public void setAlpha(float a) {
90+
alpha = a;
91+
}
92+
93+
public float getAlpha() {
94+
return alpha;
95+
}
96+
97+
public void setRadius(float r) {
98+
radius = r;
99+
}
100+
101+
public float getRadius() {
102+
return radius;
103+
}
104+
}
105+
106+
class Point {
107+
float x;
108+
float y;
109+
float radius;
110+
111+
public Point(float x2, float y2, float r) {
112+
x = (float) x2;
113+
y = (float) y2;
114+
radius = r;
115+
}
116+
}
117+
118+
public PointCloud(Drawable drawable) {
119+
mPaint = new Paint();
120+
mPaint.setFilterBitmap(true);
121+
mPaint.setColor(Color.rgb(255, 255, 255)); // TODO: make configurable
122+
mPaint.setAntiAlias(true);
123+
mPaint.setDither(true);
124+
125+
mDrawable = drawable;
126+
if (mDrawable != null) {
127+
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
128+
}
129+
}
130+
131+
public void setCenter(float x, float y) {
132+
mCenterX = x;
133+
mCenterY = y;
134+
}
135+
136+
public void makePointCloud(float innerRadius, float outerRadius) {
137+
if (innerRadius == 0) {
138+
Log.w(TAG, "Must specify an inner radius");
139+
return;
140+
}
141+
mOuterRadius = outerRadius;
142+
mPointCloud.clear();
143+
final float pointAreaRadius = (outerRadius - innerRadius);
144+
final float ds = (2.0f * PI * innerRadius / INNER_POINTS);
145+
final int bands = (int) Math.round(pointAreaRadius / ds);
146+
final float dr = pointAreaRadius / bands;
147+
float r = innerRadius;
148+
for (int b = 0; b <= bands; b++, r += dr) {
149+
float circumference = 2.0f * PI * r;
150+
final int pointsInBand = (int) (circumference / ds);
151+
float eta = PI/2.0f;
152+
float dEta = 2.0f * PI / pointsInBand;
153+
for (int i = 0; i < pointsInBand; i++) {
154+
float x = r * FloatMath.cos(eta);
155+
float y = r * FloatMath.sin(eta);
156+
eta += dEta;
157+
mPointCloud.add(new Point(x, y, r));
158+
}
159+
}
160+
}
161+
162+
public void setScale(float scale) {
163+
mScale = scale;
164+
}
165+
166+
public float getScale() {
167+
return mScale;
168+
}
169+
170+
private static float hypot(float x, float y) {
171+
return FloatMath.sqrt(x*x + y*y);
172+
}
173+
174+
private static float max(float a, float b) {
175+
return a > b ? a : b;
176+
}
177+
178+
public int getAlphaForPoint(Point point) {
179+
// Contribution from positional glow
180+
float glowDistance = hypot(glowManager.x - point.x, glowManager.y - point.y);
181+
float glowAlpha = 0.0f;
182+
if (glowDistance < glowManager.radius) {
183+
float cosf = FloatMath.cos(PI * 0.5f * glowDistance / glowManager.radius);
184+
glowAlpha = glowManager.alpha * max(0.0f, (float) Math.pow(cosf, 0.5f));
185+
}
186+
187+
// Compute contribution from Wave
188+
float radius = hypot(point.x, point.y);
189+
float distanceToWaveRing = Math.abs(radius - waveManager.radius);
190+
float waveAlpha = 0.0f;
191+
if (distanceToWaveRing < waveManager.width * 0.5f) {
192+
float cosf = FloatMath.cos(PI * 0.5f * distanceToWaveRing / waveManager.width);
193+
waveAlpha = waveManager.alpha * max(0.0f, (float) Math.pow(cosf, 15.0f));
194+
}
195+
196+
return (int) (max(glowAlpha, waveAlpha) * 255);
197+
}
198+
199+
private float interp(float min, float max, float f) {
200+
return min + (max - min) * f;
201+
}
202+
203+
public void draw(Canvas canvas) {
204+
ArrayList<Point> points = mPointCloud;
205+
final float cx = mDrawable != null ? (-mDrawable.getIntrinsicWidth() / 2) : 0;
206+
final float cy = mDrawable != null ? (-mDrawable.getIntrinsicHeight() / 2) : 0;
207+
canvas.save(Canvas.MATRIX_SAVE_FLAG);
208+
canvas.scale(mScale, mScale, mCenterX, mCenterY);
209+
for (int i = 0; i < points.size(); i++) {
210+
Point point = points.get(i);
211+
final float pointSize = interp(MAX_POINT_SIZE, MIN_POINT_SIZE,
212+
point.radius / mOuterRadius);
213+
final float px = point.x + cx + mCenterX;
214+
final float py = point.y + cy + mCenterY;
215+
int alpha = getAlphaForPoint(point);
216+
217+
if (alpha == 0) continue;
218+
219+
if (mDrawable != null) {
220+
canvas.save(Canvas.MATRIX_SAVE_FLAG);
221+
float s = pointSize / MAX_POINT_SIZE;
222+
canvas.scale(s, s, px, py);
223+
canvas.translate(px, py);
224+
mDrawable.setAlpha(alpha);
225+
mDrawable.draw(canvas);
226+
canvas.restore();
227+
} else {
228+
mPaint.setAlpha(alpha);
229+
canvas.drawCircle(px, py, pointSize, mPaint);
230+
}
231+
}
232+
canvas.restore();
233+
}
234+
235+
}
738 Bytes
Loading
538 Bytes
Loading
964 Bytes
Loading

core/res/res/layout-sw600dp/keyguard_screen_tab_unlock.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
android:drawablePadding="4dip"
8383
/>
8484

85-
<com.android.internal.widget.multiwaveview.MultiWaveView
85+
<com.android.internal.widget.multiwaveview.GlowPadView
8686
android:id="@+id/unlock_widget"
8787
android:orientation="horizontal"
8888
android:layout_width="wrap_content"
@@ -94,13 +94,15 @@
9494
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
9595
android:directionDescriptions="@array/lockscreen_direction_descriptions"
9696
android:handleDrawable="@drawable/ic_lockscreen_handle"
97-
android:waveDrawable="@drawable/ic_lockscreen_outerring"
98-
android:outerRadius="@dimen/multiwaveview_target_placement_radius"
99-
android:snapMargin="@dimen/multiwaveview_snap_margin"
100-
android:hitRadius="@dimen/multiwaveview_hit_radius"
101-
android:chevronDrawables="@array/lockscreen_chevron_drawables"
102-
android:feedbackCount="3"
97+
android:outerRingDrawable="@drawable/ic_lockscreen_outerring"
98+
android:outerRadius="@dimen/glowpadview_target_placement_radius"
99+
android:innerRadius="@dimen/glowpadview_inner_radius"
100+
android:snapMargin="@dimen/glowpadview_snap_margin"
101+
android:hitRadius="@dimen/glowpadview_hit_radius"
102+
android:feedbackCount="1"
103103
android:vibrationDuration="20"
104+
android:glowRadius="@dimen/glowpadview_glow_radius"
105+
android:pointDrawable="@drawable/ic_lockscreen_glowdot"
104106
/>
105107

106108
<!-- emergency call button shown when sim is PUKd and tab_selector is hidden -->

core/res/res/layout-sw600dp/keyguard_screen_tab_unlock_land.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
android:layout_alignParentTop="true"
8383
android:drawablePadding="4dip"/>
8484

85-
<com.android.internal.widget.multiwaveview.MultiWaveView
85+
<com.android.internal.widget.multiwaveview.GlowPadView
8686
android:id="@+id/unlock_widget"
8787
android:layout_width="wrap_content"
8888
android:layout_height="wrap_content"
@@ -94,13 +94,15 @@
9494
android:targetDescriptions="@array/lockscreen_target_descriptions_with_camera"
9595
android:directionDescriptions="@array/lockscreen_direction_descriptions"
9696
android:handleDrawable="@drawable/ic_lockscreen_handle"
97-
android:waveDrawable="@drawable/ic_lockscreen_outerring"
98-
android:outerRadius="@dimen/multiwaveview_target_placement_radius"
99-
android:snapMargin="@dimen/multiwaveview_snap_margin"
100-
android:hitRadius="@dimen/multiwaveview_hit_radius"
101-
android:chevronDrawables="@array/lockscreen_chevron_drawables"
102-
android:feedbackCount="3"
97+
android:outerRingDrawable="@drawable/ic_lockscreen_outerring"
98+
android:outerRadius="@dimen/glowpadview_target_placement_radius"
99+
android:innerRadius="@dimen/glowpadview_inner_radius"
100+
android:snapMargin="@dimen/glowpadview_snap_margin"
101+
android:hitRadius="@dimen/glowpadview_hit_radius"
102+
android:feedbackCount="1"
103103
android:vibrationDuration="20"
104+
android:glowRadius="@dimen/glowpadview_glow_radius"
105+
android:pointDrawable="@drawable/ic_lockscreen_glowdot"
104106
/>
105107

106108
<!-- emergency call button shown when sim is PUKd and tab_selector is hidden -->

0 commit comments

Comments
 (0)