diff options
author | Chris Wren <cwren@android.com> | 2012-10-26 21:50:32 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-10-26 21:50:34 -0700 |
commit | 1d269e8e8fc508f59e4010777f4da6a2feafb0a4 (patch) | |
tree | d4332853f536a02743f087a717b92ace43222fef /core/java/com | |
parent | fdbbbba4cd4807bed1200f714609d4000501d4ee (diff) | |
parent | f0ee5b813597e97123d518b227c555c0ea0c0f29 (diff) | |
download | frameworks_base-1d269e8e8fc508f59e4010777f4da6a2feafb0a4.zip frameworks_base-1d269e8e8fc508f59e4010777f4da6a2feafb0a4.tar.gz frameworks_base-1d269e8e8fc508f59e4010777f4da6a2feafb0a4.tar.bz2 |
Merge "single unlock target with honycomb semantics" into jb-mr1-lockscreen-dev
Diffstat (limited to 'core/java/com')
-rw-r--r-- | core/java/com/android/internal/widget/multiwaveview/GlowPadView.java | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java index b7f64ec..209bd3c 100644 --- a/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java +++ b/core/java/com/android/internal/widget/multiwaveview/GlowPadView.java @@ -116,6 +116,8 @@ public class GlowPadView extends View { private float mOuterRadius = 0.0f; private float mSnapMargin = 0.0f; + private float mFirstItemOffset = 0.0f; + private boolean mMagneticTargets = false; private boolean mDragging; private int mNewTargetResources; @@ -212,6 +214,9 @@ public class GlowPadView extends View { mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius); mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius); mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin); + mFirstItemOffset = (float) Math.toRadians( + a.getFloat(R.styleable.GlowPadView_firstItemOffset, + (float) Math.toDegrees(mFirstItemOffset))); mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration, mVibrationDuration); mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount, @@ -223,6 +228,7 @@ public class GlowPadView extends View { getResourceId(a, R.styleable.GlowPadView_outerRingDrawable)); mAlwaysTrackFinger = a.getBoolean(R.styleable.GlowPadView_alwaysTrackFinger, false); + mMagneticTargets = a.getBoolean(R.styleable.GlowPadView_magneticTargets, mMagneticTargets); int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable); Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null; @@ -820,6 +826,7 @@ public class GlowPadView extends View { int ntargets = targets.size(); float x = 0.0f; float y = 0.0f; + float activeAngle = 0.0f; int actionIndex = event.findPointerIndex(mPointerId); if (actionIndex == -1) { @@ -852,15 +859,18 @@ public class GlowPadView extends View { for (int i = 0; i < ntargets; i++) { TargetDrawable target = targets.get(i); - double targetMinRad = (i - 0.5) * 2 * Math.PI / ntargets; - double targetMaxRad = (i + 0.5) * 2 * Math.PI / ntargets; + double targetMinRad = mFirstItemOffset + (i - 0.5) * 2 * Math.PI / ntargets; + double targetMaxRad = mFirstItemOffset + (i + 0.5) * 2 * Math.PI / ntargets; if (target.isEnabled()) { boolean angleMatches = (angleRad > targetMinRad && angleRad <= targetMaxRad) || (angleRad + 2 * Math.PI > targetMinRad && - angleRad + 2 * Math.PI <= targetMaxRad); + angleRad + 2 * Math.PI <= targetMaxRad) || + (angleRad - 2 * Math.PI > targetMinRad && + angleRad - 2 * Math.PI <= targetMaxRad); if (angleMatches && (dist2(tx, ty) > snapDistance2)) { activeTarget = i; + activeAngle = (float) -angleRad; } } } @@ -888,6 +898,9 @@ public class GlowPadView extends View { if (target.hasState(TargetDrawable.STATE_FOCUSED)) { target.setState(TargetDrawable.STATE_INACTIVE); } + if (mMagneticTargets) { + updateTargetPosition(mActiveTarget, mWaveCenterX, mWaveCenterY); + } } // Focus the new target if (activeTarget != -1) { @@ -895,6 +908,9 @@ public class GlowPadView extends View { if (target.hasState(TargetDrawable.STATE_FOCUSED)) { target.setState(TargetDrawable.STATE_FOCUSED); } + if (mMagneticTargets) { + updateTargetPosition(activeTarget, mWaveCenterX, mWaveCenterY, activeAngle); + } if (AccessibilityManager.getInstance(mContext).isEnabled()) { String targetContentDescription = getTargetDescription(activeTarget); announceForAccessibility(targetContentDescription); @@ -1039,14 +1055,15 @@ public class GlowPadView extends View { if (DEBUG) dump(); } - private void updateTargetPositions(float centerX, float centerY) { - // Reposition the target drawables if the view changed. - ArrayList<TargetDrawable> targets = mTargetDrawables; - final int size = targets.size(); - final float alpha = (float) (-2.0f * Math.PI / size); - for (int i = 0; i < size; i++) { + private void updateTargetPosition(int i, float centerX, float centerY) { + final float angle = getAngle(getSliceAngle(), i); + updateTargetPosition(i, centerX, centerY, angle); + } + + private void updateTargetPosition(int i, float centerX, float centerY, float angle) { + if (i >= 0) { + ArrayList<TargetDrawable> targets = mTargetDrawables; final TargetDrawable targetIcon = targets.get(i); - final float angle = alpha * i; targetIcon.setPositionX(centerX); targetIcon.setPositionY(centerY); targetIcon.setX(mOuterRadius * (float) Math.cos(angle)); @@ -1054,6 +1071,29 @@ public class GlowPadView extends View { } } + private void updateTargetPositions(float centerX, float centerY) { + updateTargetPositions(centerX, centerY, false); + } + + private void updateTargetPositions(float centerX, float centerY, boolean skipActive) { + final int size = mTargetDrawables.size(); + final float alpha = getSliceAngle(); + // Reposition the target drawables if the view changed. + for (int i = 0; i < size; i++) { + if (!skipActive || i != mActiveTarget) { + updateTargetPosition(i, centerX, centerY, getAngle(alpha, i)); + } + } + } + + private float getAngle(float alpha, int i) { + return mFirstItemOffset + alpha * i; + } + + private float getSliceAngle() { + return (float) (-2.0f * Math.PI / mTargetDrawables.size()); + } + private void updatePointCloudPosition(float centerX, float centerY) { mPointCloud.setCenter(centerX, centerY); } |