Skip to content

Commit 71fc205

Browse files
mikejurkaAndroid (Google) Code Review
authored andcommitted
Merge "Change snap behavior for lock screen" into jb-dev
2 parents 9e19714 + 53f109b commit 71fc205

File tree

13 files changed

+38
-84
lines changed

13 files changed

+38
-84
lines changed

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

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public interface OnTriggerListener {
115115
private int mMaxTargetWidth;
116116

117117
private float mOuterRadius = 0.0f;
118-
private float mHitRadius = 0.0f;
119118
private float mSnapMargin = 0.0f;
120119
private boolean mDragging;
121120
private int mNewTargetResources;
@@ -211,7 +210,6 @@ public GlowPadView(Context context, AttributeSet attrs) {
211210
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlowPadView);
212211
mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius);
213212
mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius);
214-
mHitRadius = a.getDimension(R.styleable.GlowPadView_hitRadius, mHitRadius);
215213
mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin);
216214
mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration,
217215
mVibrationDuration);
@@ -280,7 +278,6 @@ private int getResourceId(TypedArray a, int id) {
280278

281279
private void dump() {
282280
Log.v(TAG, "Outer Radius = " + mOuterRadius);
283-
Log.v(TAG, "HitRadius = " + mHitRadius);
284281
Log.v(TAG, "SnapMargin = " + mSnapMargin);
285282
Log.v(TAG, "FeedbackCount = " + mFeedbackCount);
286283
Log.v(TAG, "VibrationDuration = " + mVibrationDuration);
@@ -799,7 +796,6 @@ private void handleMove(MotionEvent event) {
799796
final int historySize = event.getHistorySize();
800797
ArrayList<TargetDrawable> targets = mTargetDrawables;
801798
int ntargets = targets.size();
802-
final boolean singleTarget = ntargets == 1;
803799
float x = 0.0f;
804800
float y = 0.0f;
805801
for (int k = 0; k < historySize + 1; k++) {
@@ -812,31 +808,29 @@ private void handleMove(MotionEvent event) {
812808
final float scale = touchRadius > mOuterRadius ? mOuterRadius / touchRadius : 1.0f;
813809
float limitX = tx * scale;
814810
float limitY = ty * scale;
811+
double angleRad = Math.atan2(-ty, tx);
815812

816813
if (!mDragging) {
817814
trySwitchToFirstTouchState(eventX, eventY);
818815
}
819816

820817
if (mDragging) {
821-
if (singleTarget) {
822-
// Snap to outer ring if there's only one target
823-
float snapRadius = mOuterRadius - mSnapMargin;
824-
if (touchRadius > snapRadius) {
825-
activeTarget = 0;
826-
}
827-
} else {
828-
// For more than one target, snap to the closest one less than hitRadius away.
829-
float best = Float.MAX_VALUE;
830-
final float hitRadius2 = mHitRadius * mHitRadius;
831-
// Find first target in range
832-
for (int i = 0; i < ntargets; i++) {
833-
TargetDrawable target = targets.get(i);
834-
float dx = limitX - target.getX();
835-
float dy = limitY - target.getY();
836-
float dist2 = dx*dx + dy*dy;
837-
if (target.isEnabled() && dist2 < hitRadius2 && dist2 < best) {
818+
// For multiple targets, snap to the one that matches
819+
final float snapRadius = mOuterRadius - mSnapMargin;
820+
final float snapDistance2 = snapRadius * snapRadius;
821+
// Find first target in range
822+
for (int i = 0; i < ntargets; i++) {
823+
TargetDrawable target = targets.get(i);
824+
825+
double targetMinRad = (i - 0.5) * 2 * Math.PI / ntargets;
826+
double targetMaxRad = (i + 0.5) * 2 * Math.PI / ntargets;
827+
if (target.isEnabled()) {
828+
boolean angleMatches =
829+
(angleRad > targetMinRad && angleRad <= targetMaxRad) ||
830+
(angleRad + 2 * Math.PI > targetMinRad &&
831+
angleRad + 2 * Math.PI <= targetMaxRad);
832+
if (angleMatches && (dist2(tx, ty) > snapDistance2)) {
838833
activeTarget = i;
839-
best = dist2;
840834
}
841835
}
842836
}
@@ -851,10 +845,7 @@ private void handleMove(MotionEvent event) {
851845

852846
if (activeTarget != -1) {
853847
switchToState(STATE_SNAP, x,y);
854-
TargetDrawable target = targets.get(activeTarget);
855-
final float newX = singleTarget ? x : target.getX();
856-
final float newY = singleTarget ? y : target.getY();
857-
updateGlowPosition(newX, newY);
848+
updateGlowPosition(x, y);
858849
} else {
859850
switchToState(STATE_TRACKING, x, y);
860851
updateGlowPosition(x, y);
@@ -942,10 +933,6 @@ private void assignDefaultsIfNeeded() {
942933
if (mOuterRadius == 0.0f) {
943934
mOuterRadius = Math.max(mOuterRing.getWidth(), mOuterRing.getHeight())/2.0f;
944935
}
945-
if (mHitRadius == 0.0f) {
946-
// Use the radius of inscribed circle of the first target.
947-
mHitRadius = mTargetDrawables.get(0).getWidth() / 2.0f;
948-
}
949936
if (mSnapMargin == 0.0f) {
950937
mSnapMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
951938
SNAP_MARGIN_DEFAULT, getContext().getResources().getDisplayMetrics());

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

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ public interface OnTriggerListener {
119119
private int mMaxTargetWidth;
120120

121121
private float mOuterRadius = 0.0f;
122-
private float mHitRadius = 0.0f;
123122
private float mSnapMargin = 0.0f;
124123
private boolean mDragging;
125124
private int mNewTargetResources;
@@ -213,7 +212,6 @@ public MultiWaveView(Context context, AttributeSet attrs) {
213212

214213
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MultiWaveView);
215214
mOuterRadius = a.getDimension(R.styleable.MultiWaveView_outerRadius, mOuterRadius);
216-
mHitRadius = a.getDimension(R.styleable.MultiWaveView_hitRadius, mHitRadius);
217215
mSnapMargin = a.getDimension(R.styleable.MultiWaveView_snapMargin, mSnapMargin);
218216
mVibrationDuration = a.getInt(R.styleable.MultiWaveView_vibrationDuration,
219217
mVibrationDuration);
@@ -277,7 +275,6 @@ public MultiWaveView(Context context, AttributeSet attrs) {
277275

278276
private void dump() {
279277
Log.v(TAG, "Outer Radius = " + mOuterRadius);
280-
Log.v(TAG, "HitRadius = " + mHitRadius);
281278
Log.v(TAG, "SnapMargin = " + mSnapMargin);
282279
Log.v(TAG, "FeedbackCount = " + mFeedbackCount);
283280
Log.v(TAG, "VibrationDuration = " + mVibrationDuration);
@@ -823,7 +820,6 @@ private void handleMove(MotionEvent event) {
823820
final int historySize = event.getHistorySize();
824821
ArrayList<TargetDrawable> targets = mTargetDrawables;
825822
int ntargets = targets.size();
826-
final boolean singleTarget = ntargets == 1;
827823
float x = 0.0f;
828824
float y = 0.0f;
829825
for (int k = 0; k < historySize + 1; k++) {
@@ -836,31 +832,29 @@ private void handleMove(MotionEvent event) {
836832
final float scale = touchRadius > mOuterRadius ? mOuterRadius / touchRadius : 1.0f;
837833
float limitX = tx * scale;
838834
float limitY = ty * scale;
835+
double angleRad = Math.atan2(-ty, tx);
839836

840837
if (!mDragging) {
841838
trySwitchToFirstTouchState(eventX, eventY);
842839
}
843840

844841
if (mDragging) {
845-
if (singleTarget) {
846-
// Snap to outer ring if there's only one target
847-
float snapRadius = mOuterRadius - mSnapMargin;
848-
if (touchRadius > snapRadius) {
849-
activeTarget = 0;
850-
}
851-
} else {
852-
// For more than one target, snap to the closest one less than hitRadius away.
853-
float best = Float.MAX_VALUE;
854-
final float hitRadius2 = mHitRadius * mHitRadius;
855-
// Find first target in range
856-
for (int i = 0; i < ntargets; i++) {
857-
TargetDrawable target = targets.get(i);
858-
float dx = limitX - target.getX();
859-
float dy = limitY - target.getY();
860-
float dist2 = dx*dx + dy*dy;
861-
if (target.isEnabled() && dist2 < hitRadius2 && dist2 < best) {
842+
// For multiple targets, snap to the one that matches
843+
final float snapRadius = mOuterRadius - mSnapMargin;
844+
final float snapDistance2 = snapRadius * snapRadius;
845+
// Find first target in range
846+
for (int i = 0; i < ntargets; i++) {
847+
TargetDrawable target = targets.get(i);
848+
849+
double targetMinRad = (i - 0.5) * 2 * Math.PI / ntargets;
850+
double targetMaxRad = (i + 0.5) * 2 * Math.PI / ntargets;
851+
if (target.isEnabled()) {
852+
boolean angleMatches =
853+
(angleRad > targetMinRad && angleRad <= targetMaxRad) ||
854+
(angleRad + 2 * Math.PI > targetMinRad &&
855+
angleRad + 2 * Math.PI <= targetMaxRad);
856+
if (angleMatches && (dist2(tx, ty) > snapDistance2)) {
862857
activeTarget = i;
863-
best = dist2;
864858
}
865859
}
866860
}
@@ -875,10 +869,7 @@ private void handleMove(MotionEvent event) {
875869

876870
if (activeTarget != -1) {
877871
switchToState(STATE_SNAP, x,y);
878-
TargetDrawable target = targets.get(activeTarget);
879-
final float newX = singleTarget ? x : target.getX();
880-
final float newY = singleTarget ? y : target.getY();
881-
moveHandleTo(newX, newY, false);
872+
moveHandleTo(x, y, false);
882873
} else {
883874
switchToState(STATE_TRACKING, x, y);
884875
moveHandleTo(x, y, false);
@@ -972,10 +963,6 @@ private void assignDefaultsIfNeeded() {
972963
if (mOuterRadius == 0.0f) {
973964
mOuterRadius = Math.max(mOuterRing.getWidth(), mOuterRing.getHeight())/2.0f;
974965
}
975-
if (mHitRadius == 0.0f) {
976-
// Use the radius of inscribed circle of the first target.
977-
mHitRadius = mTargetDrawables.get(0).getWidth() / 2.0f;
978-
}
979966
if (mSnapMargin == 0.0f) {
980967
mSnapMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
981968
SNAP_MARGIN_DEFAULT, getContext().getResources().getDisplayMetrics());

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
android:outerRadius="@dimen/glowpadview_target_placement_radius"
9999
android:innerRadius="@dimen/glowpadview_inner_radius"
100100
android:snapMargin="@dimen/glowpadview_snap_margin"
101-
android:hitRadius="@dimen/glowpadview_hit_radius"
102101
android:feedbackCount="1"
103102
android:vibrationDuration="20"
104103
android:glowRadius="@dimen/glowpadview_glow_radius"

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
android:outerRadius="@dimen/glowpadview_target_placement_radius"
9999
android:innerRadius="@dimen/glowpadview_inner_radius"
100100
android:snapMargin="@dimen/glowpadview_snap_margin"
101-
android:hitRadius="@dimen/glowpadview_hit_radius"
102101
android:feedbackCount="1"
103102
android:vibrationDuration="20"
104103
android:glowRadius="@dimen/glowpadview_glow_radius"

core/res/res/layout/keyguard_screen_tab_unlock.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
android:outerRadius="@dimen/glowpadview_target_placement_radius"
140140
android:innerRadius="@dimen/glowpadview_inner_radius"
141141
android:snapMargin="@dimen/glowpadview_snap_margin"
142-
android:hitRadius="@dimen/glowpadview_hit_radius"
143142
android:feedbackCount="1"
144143
android:vibrationDuration="20"
145144
android:glowRadius="@dimen/glowpadview_glow_radius"

core/res/res/layout/keyguard_screen_tab_unlock_land.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
android:outerRadius="@dimen/glowpadview_target_placement_radius"
145145
android:innerRadius="@dimen/glowpadview_inner_radius"
146146
android:snapMargin="@dimen/glowpadview_snap_margin"
147-
android:hitRadius="@dimen/glowpadview_hit_radius"
148147
android:feedbackCount="1"
149148
android:vibrationDuration="20"
150149
android:glowRadius="@dimen/glowpadview_glow_radius"

core/res/res/values/attrs.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5405,9 +5405,6 @@
54055405
<!-- Outer radius of glow area. Target icons will be drawn on this circle. -->
54065406
<attr name="outerRadius"/>
54075407

5408-
<!-- Size of target radius. Points within this distance of target center is a "hit". -->
5409-
<attr name="hitRadius"/>
5410-
54115408
<!-- Radius of glow under finger. -->
54125409
<attr name="glowRadius" format="dimension" />
54135410

@@ -5450,9 +5447,6 @@
54505447
<!-- Outer radius of target circle. Icons will be drawn on this circle. -->
54515448
<attr name="outerRadius" format="dimension" />
54525449

5453-
<!-- Size of target radius. Points within this distance of target center is a "hit". -->
5454-
<attr name="hitRadius" format="dimension" />
5455-
54565450
<!-- Tactile feedback duration for actions. Set to '0' for no vibration. -->
54575451
<attr name="vibrationDuration" format="integer"/>
54585452

core/res/res/values/dimens.xml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,8 @@
7979
<!-- Default glow radius for GlowPadView -->
8080
<dimen name="glowpadview_glow_radius">75dip</dimen>
8181

82-
<!-- Default distance beyond which GlowPadView snaps to the target radius -->
83-
<dimen name="glowpadview_snap_margin">20dip</dimen>
84-
85-
<!-- Default distance from each snap target that GlowPadView considers a "hit" -->
86-
<dimen name="glowpadview_hit_radius">60dip</dimen>
82+
<!-- Default distance beyond which GlowPadView snaps to the matching target -->
83+
<dimen name="glowpadview_snap_margin">40dip</dimen>
8784

8885
<!-- Default distance from each snap target that GlowPadView considers a "hit" -->
8986
<dimen name="glowpadview_inner_radius">15dip</dimen>

packages/SystemUI/res/layout-land/status_bar_search_panel.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
prvandroid:outerRadius="@dimen/navbar_search_outerring_radius"
5555
prvandroid:innerRadius="@*android:dimen/glowpadview_inner_radius"
5656
prvandroid:snapMargin="@dimen/navbar_search_snap_margin"
57-
prvandroid:hitRadius="@dimen/navbar_search_hit_radius"
5857
prvandroid:feedbackCount="0"
5958
prvandroid:vibrationDuration="@integer/config_vibration_duration"
6059
prvandroid:alwaysTrackFinger="true"

packages/SystemUI/res/layout-port/status_bar_search_panel.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
prvandroid:outerRadius="@dimen/navbar_search_outerring_radius"
5555
prvandroid:innerRadius="@*android:dimen/glowpadview_inner_radius"
5656
prvandroid:snapMargin="@dimen/navbar_search_snap_margin"
57-
prvandroid:hitRadius="@dimen/navbar_search_hit_radius"
5857
prvandroid:feedbackCount="0"
5958
prvandroid:vibrationDuration="@integer/config_vibration_duration"
6059
prvandroid:alwaysTrackFinger="true"

0 commit comments

Comments
 (0)