Skip to content

Commit f988bdf

Browse files
author
Adam Cohen
committed
Fixing up glowpad scaling issues (issue 7494378)
Change-Id: I55c0f7a3774d42d4f5893b12bc0c08690268e351
1 parent 4eb36cf commit f988bdf

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public interface OnTriggerListener {
114114
private int mMaxTargetHeight;
115115
private int mMaxTargetWidth;
116116
private float mRingScaleFactor = 1f;
117+
private boolean mAllowScaling;
117118

118119
private float mOuterRadius = 0.0f;
119120
private float mSnapMargin = 0.0f;
@@ -222,6 +223,7 @@ public GlowPadView(Context context, AttributeSet attrs) {
222223
mVibrationDuration);
223224
mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount,
224225
mFeedbackCount);
226+
mAllowScaling = a.getBoolean(R.styleable.GlowPadView_allowScaling, false);
225227
TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable);
226228
mHandleDrawable = new TargetDrawable(res, handle != null ? handle.resourceId : 0);
227229
mHandleDrawable.setState(TargetDrawable.STATE_INACTIVE);
@@ -793,8 +795,12 @@ public boolean onTouchEvent(MotionEvent event) {
793795
}
794796

795797
private void updateGlowPosition(float x, float y) {
796-
mPointCloud.glowManager.setX(x);
797-
mPointCloud.glowManager.setY(y);
798+
float dx = x - mOuterRing.getX();
799+
float dy = y - mOuterRing.getY();
800+
dx *= 1f / mRingScaleFactor;
801+
dy *= 1f / mRingScaleFactor;
802+
mPointCloud.glowManager.setX(mOuterRing.getX() + dx);
803+
mPointCloud.glowManager.setY(mOuterRing.getY() + dy);
798804
}
799805

800806
private void handleDown(MotionEvent event) {
@@ -863,7 +869,7 @@ private void handleMove(MotionEvent event) {
863869

864870
if (mDragging) {
865871
// For multiple targets, snap to the one that matches
866-
final float snapRadius = mOuterRadius - mSnapMargin;
872+
final float snapRadius = mRingScaleFactor * mOuterRadius - mSnapMargin;
867873
final float snapDistance2 = snapRadius * snapRadius;
868874
// Find first target in range
869875
for (int i = 0; i < ntargets; i++) {
@@ -1034,6 +1040,10 @@ private void computeInsets(int dx, int dy) {
10341040
*/
10351041
private float computeScaleFactor(int desiredWidth, int desiredHeight,
10361042
int actualWidth, int actualHeight) {
1043+
1044+
// Return unity if scaling is not allowed.
1045+
if (!mAllowScaling) return 1f;
1046+
10371047
final int layoutDirection = getLayoutDirection();
10381048
final int absoluteGravity = Gravity.getAbsoluteGravity(mGravity, layoutDirection);
10391049

core/res/res/layout/keyguard_glow_pad_view.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@
4242
prvandroid:feedbackCount="1"
4343
prvandroid:vibrationDuration="20"
4444
prvandroid:glowRadius="@*android:dimen/glowpadview_glow_radius"
45-
prvandroid:pointDrawable="@*android:drawable/ic_lockscreen_glowdot" />
45+
prvandroid:pointDrawable="@*android:drawable/ic_lockscreen_glowdot"
46+
prvandroid:allowScaling="true" />

core/res/res/values/attrs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5484,6 +5484,11 @@
54845484
<attr name="magneticTargets" format="boolean" />
54855485

54865486
<attr name="gravity" />
5487+
5488+
<!-- Determine whether the glow pad is allowed to scale to fit the bounds indicated
5489+
by its parent. If this is set to false, no scaling will occur. If this is set to true
5490+
scaling will occur to fit for any axis in which gravity is set to center. -->
5491+
<attr name="allowScaling" format="boolean" />
54875492
</declare-styleable>
54885493

54895494
<!-- =============================== -->

0 commit comments

Comments
 (0)