diff options
Diffstat (limited to 'java/com/android/dialershared/bubble/MoveHandler.java')
-rw-r--r-- | java/com/android/dialershared/bubble/MoveHandler.java | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/java/com/android/dialershared/bubble/MoveHandler.java b/java/com/android/dialershared/bubble/MoveHandler.java index bc6db64bc..9c754dab7 100644 --- a/java/com/android/dialershared/bubble/MoveHandler.java +++ b/java/com/android/dialershared/bubble/MoveHandler.java @@ -149,6 +149,13 @@ class MoveHandler implements OnTouchListener { xProperty.setValue(windowParams, xProperty.getValue(windowParams)); } + public void snapToBounds() { + ensureSprings(); + + moveXAnimation.animateToFinalPosition(relativeToRight(bubble.getWindowParams()) ? maxX : minX); + moveYAnimation.animateToFinalPosition(yProperty.getValue(bubble.getWindowParams())); + } + @Override public boolean onTouch(View v, MotionEvent event) { float eventX = event.getRawX(); @@ -166,16 +173,7 @@ class MoveHandler implements OnTouchListener { bubble.onMoveStart(); } - if (moveXAnimation == null) { - moveXAnimation = new SpringAnimation(bubble.getWindowParams(), xProperty); - moveXAnimation.setSpring(new SpringForce()); - moveXAnimation.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY); - } - if (moveYAnimation == null) { - moveYAnimation = new SpringAnimation(bubble.getWindowParams(), yProperty); - moveYAnimation.setSpring(new SpringForce()); - moveYAnimation.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY); - } + ensureSprings(); moveXAnimation.animateToFinalPosition(MathUtils.clamp(eventX, minX, maxX)); moveYAnimation.animateToFinalPosition(MathUtils.clamp(eventY, minY, maxY)); @@ -216,6 +214,20 @@ class MoveHandler implements OnTouchListener { return true; } + private void ensureSprings() { + if (moveXAnimation == null) { + moveXAnimation = new SpringAnimation(bubble.getWindowParams(), xProperty); + moveXAnimation.setSpring(new SpringForce()); + moveXAnimation.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY); + } + + if (moveYAnimation == null) { + moveYAnimation = new SpringAnimation(bubble.getWindowParams(), yProperty); + moveYAnimation.setSpring(new SpringForce()); + moveYAnimation.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY); + } + } + private Point findTarget(float xVelocity, float yVelocity, int startX, int startY) { if (scroller == null) { scroller = new Scroller(context); |