summaryrefslogtreecommitdiff
path: root/java/com/android/newbubble/NewMoveHandler.java
diff options
context:
space:
mode:
authoryueg <yueg@google.com>2017-12-05 10:29:03 -0800
committerCopybara-Service <copybara-piper@google.com>2017-12-07 11:02:15 -0800
commit81a77ffc4d36c6054a75acfe7b048e7c0d7a8744 (patch)
tree650eabb797c3a2176bf4260dfadddfd9e4d9908e /java/com/android/newbubble/NewMoveHandler.java
parent5b77c7dfd420cb77cdb195fd441a8d57676a837f (diff)
Bubble v2 animation changes.
Including: - expanded view expands/collapses from top of itself - small icon on avatar shows on left side when bubble is on right side - when expand on bottom, bubble move up a bit so that expanded view doesn't go off screen. It also go back to previous position when collapse. - remove animation for collapse when move expanded bubble This change should not enable bubble v2 for anyone. Bug: 67605985 Test: manual PiperOrigin-RevId: 177974562 Change-Id: Id83f3f744b717d51fbe58e58769ac2cd2810d2b5
Diffstat (limited to 'java/com/android/newbubble/NewMoveHandler.java')
-rw-r--r--java/com/android/newbubble/NewMoveHandler.java40
1 files changed, 37 insertions, 3 deletions
diff --git a/java/com/android/newbubble/NewMoveHandler.java b/java/com/android/newbubble/NewMoveHandler.java
index 189ad8472..9cb1f1eca 100644
--- a/java/com/android/newbubble/NewMoveHandler.java
+++ b/java/com/android/newbubble/NewMoveHandler.java
@@ -48,6 +48,8 @@ class NewMoveHandler implements OnTouchListener {
private final int maxX;
private final int maxY;
private final int bubbleSize;
+ private final int bubbleShadowPaddingHorizontal;
+ private final int bubbleExpandedViewWidth;
private final float touchSlopSquared;
private boolean clickable = true;
@@ -70,8 +72,14 @@ class NewMoveHandler implements OnTouchListener {
@Override
public float getValue(LayoutParams windowParams) {
int realX = windowParams.x;
- realX = realX + bubbleSize / 2;
+ // Get bubble center position from real position
+ if (bubble.getDrawerVisibility() == View.INVISIBLE) {
+ realX += bubbleExpandedViewWidth / 2 + bubbleShadowPaddingHorizontal * 2;
+ } else {
+ realX += bubbleSize / 2 + bubbleShadowPaddingHorizontal;
+ }
if (relativeToRight(windowParams)) {
+ // If gravity is right, get distant from bubble center position to screen right edge
int displayWidth = context.getResources().getDisplayMetrics().widthPixels;
realX = displayWidth - realX;
}
@@ -88,12 +96,19 @@ class NewMoveHandler implements OnTouchListener {
} else {
onRight = (gravityOverride & Gravity.RIGHT) == Gravity.RIGHT;
}
- int centeringOffset = bubbleSize / 2;
+ // Get real position from bubble center position
+ int centeringOffset;
+ if (bubble.getDrawerVisibility() == View.INVISIBLE) {
+ centeringOffset = bubbleExpandedViewWidth / 2 + bubbleShadowPaddingHorizontal * 2;
+ } else {
+ centeringOffset = bubbleSize / 2 + bubbleShadowPaddingHorizontal;
+ }
windowParams.x =
(int) (onRight ? (displayWidth - value - centeringOffset) : value - centeringOffset);
windowParams.gravity = Gravity.TOP | (onRight ? Gravity.RIGHT : Gravity.LEFT);
if (bubble.isVisible()) {
windowManager.updateViewLayout(bubble.getRootView(), windowParams);
+ bubble.onLeftRightSwitch(onRight);
}
}
};
@@ -120,8 +135,13 @@ class NewMoveHandler implements OnTouchListener {
windowManager = context.getSystemService(WindowManager.class);
bubbleSize = context.getResources().getDimensionPixelSize(R.dimen.bubble_size);
+ bubbleShadowPaddingHorizontal =
+ context.getResources().getDimensionPixelSize(R.dimen.bubble_shadow_padding_size_horizontal);
+ bubbleExpandedViewWidth =
+ context.getResources().getDimensionPixelSize(R.dimen.bubble_expanded_width);
+ // The following value is based on bubble center
minX =
- context.getResources().getDimensionPixelOffset(R.dimen.bubble_safe_margin_horizontal)
+ context.getResources().getDimensionPixelOffset(R.dimen.bubble_off_screen_size_horizontal)
+ bubbleSize / 2;
minY =
context.getResources().getDimensionPixelOffset(R.dimen.bubble_safe_margin_vertical)
@@ -156,6 +176,12 @@ class NewMoveHandler implements OnTouchListener {
moveYAnimation.animateToFinalPosition(yProperty.getValue(bubble.getWindowParams()));
}
+ public int getMoveUpDistance(int deltaAllowed) {
+ int currentY = (int) yProperty.getValue(bubble.getWindowParams());
+ int currentDelta = maxY - currentY;
+ return currentDelta >= deltaAllowed ? 0 : deltaAllowed - currentDelta;
+ }
+
@Override
public boolean onTouch(View v, MotionEvent event) {
float eventX = event.getRawX();
@@ -222,6 +248,14 @@ class NewMoveHandler implements OnTouchListener {
moveXAnimation = new SpringAnimation(bubble.getWindowParams(), xProperty);
moveXAnimation.setSpring(new SpringForce());
moveXAnimation.getSpring().setDampingRatio(SpringForce.DAMPING_RATIO_NO_BOUNCY);
+ // Moving when expanded makes expanded view INVISIBLE, and the whole view is not at the
+ // boundary. It's time to create a viewHolder.
+ moveXAnimation.addEndListener(
+ (animation, canceled, value, velocity) -> {
+ if (!isMoving && bubble.getDrawerVisibility() == View.INVISIBLE) {
+ bubble.replaceViewHolder();
+ }
+ });
}
if (moveYAnimation == null) {