From 6fcf2afbfceaff1f2d8211783f5049c2ec0cf440 Mon Sep 17 00:00:00 2001 From: yueg Date: Thu, 27 Jul 2017 12:21:46 -0700 Subject: Fix bubble text overflow. When we calculate transition end values, primaryText might be invisible and causing primaryButton size smaller than expected. Fix it by always using larger size (primaryText size). Conference call ended twice, before: https://drive.google.com/a/google.com/file/d/0Bz1rQbdSCWSKamYzVTVrbVpBWWM After: https://drive.google.com/a/google.com/file/d/0Bz1rQbdSCWSKck9WUm5IUlI2QVU Test: ChangeOnScreenBoundsTest, BubbleIntegrationTest PiperOrigin-RevId: 163375425 Change-Id: I251d0e96546742247ee3ce463f0aade65fe302bb --- java/com/android/dialershared/bubble/Bubble.java | 14 +++++++++++--- .../dialershared/bubble/ChangeOnScreenBounds.java | 22 ++++++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/java/com/android/dialershared/bubble/Bubble.java b/java/com/android/dialershared/bubble/Bubble.java index f2ba117d8..cbc64dd4e 100644 --- a/java/com/android/dialershared/bubble/Bubble.java +++ b/java/com/android/dialershared/bubble/Bubble.java @@ -102,7 +102,7 @@ public class Bubble { private final Handler handler = new Handler(); - private ViewHolder viewHolder; + @VisibleForTesting ViewHolder viewHolder; private ViewPropertyAnimator collapseAnimation; private Integer overrideGravity; private ViewPropertyAnimator exitAnimator; @@ -350,8 +350,15 @@ public class Bubble { public boolean onPreDraw() { primaryButton.getViewTreeObserver().removeOnPreDrawListener(this); - // Prepare and capture end values + // Prepare and capture end values, always use the size of primaryText since + // its invisibility makes primaryButton smaller than expected TransitionValues endValues = new TransitionValues(); + endValues.values.put( + ChangeOnScreenBounds.PROPNAME_WIDTH, + viewHolder.getPrimaryText().getWidth()); + endValues.values.put( + ChangeOnScreenBounds.PROPNAME_HEIGHT, + viewHolder.getPrimaryText().getHeight()); endValues.view = primaryButton; transition.addTarget(endValues.view); transition.captureEndValues(endValues); @@ -681,7 +688,8 @@ public class Bubble { windowManager.updateViewLayout(getRootView(), windowParams); } - private class ViewHolder { + @VisibleForTesting + class ViewHolder { public static final int CHILD_INDEX_ICON = 0; public static final int CHILD_INDEX_TEXT = 1; diff --git a/java/com/android/dialershared/bubble/ChangeOnScreenBounds.java b/java/com/android/dialershared/bubble/ChangeOnScreenBounds.java index 37c820447..8cd61afce 100644 --- a/java/com/android/dialershared/bubble/ChangeOnScreenBounds.java +++ b/java/com/android/dialershared/bubble/ChangeOnScreenBounds.java @@ -41,6 +41,9 @@ public class ChangeOnScreenBounds extends Transition { @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) static final String PROPNAME_SCREEN_Y = "bubble:changeScreenBounds:screenY"; + static final String PROPNAME_WIDTH = "bubble:changeScreenBounds:width"; + static final String PROPNAME_HEIGHT = "bubble:changeScreenBounds:height"; + private static final Property TOP_LEFT_PROPERTY = new Property(PointF.class, "topLeft") { @Override @@ -70,21 +73,32 @@ public class ChangeOnScreenBounds extends Transition { @Override public void captureStartValues(TransitionValues transitionValues) { - captureValues(transitionValues); + captureValuesWithSize(transitionValues); } @Override public void captureEndValues(TransitionValues transitionValues) { - captureValues(transitionValues); + captureValuesWithSize(transitionValues); } - private void captureValues(TransitionValues values) { + /** + * Capture location (left and top) from {@code values.view} and size (width and height) from + * {@code values.values}. If size is not set, use the size of {@code values.view}. + */ + private void captureValuesWithSize(TransitionValues values) { View view = values.view; if (view.isLaidOut() || view.getWidth() != 0 || view.getHeight() != 0) { + Integer width = (Integer) values.values.get(PROPNAME_WIDTH); + Integer height = (Integer) values.values.get(PROPNAME_HEIGHT); + values.values.put( PROPNAME_BOUNDS, - new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())); + new Rect( + view.getLeft(), + view.getTop(), + width == null ? view.getRight() : view.getLeft() + width, + height == null ? view.getBottom() : view.getTop() + height)); values.view.getLocationOnScreen(tempLocation); values.values.put(PROPNAME_SCREEN_X, tempLocation[0]); values.values.put(PROPNAME_SCREEN_Y, tempLocation[1]); -- cgit v1.2.3