From 6cb5cc19d467251d2e1e28791bf070f4ea6a2eed Mon Sep 17 00:00:00 2001 From: Abodunrinwa Toki Date: Wed, 3 Jun 2015 11:28:12 +0100 Subject: Fix FloatingToolbar positioning for RTL. -The position of the toolbar was forced to the left side in an attempt to fix an RTL bug. This led to wrong positioning in LTR. This is now fixed by using a dynamic "show" animation that takes into consideration already set positions. -The correct position of the toolbar wasn't recalculated on updates for RTL. This is now fixed. Bug:21455067 Change-Id: I0b31a8fd3c95549f5f10133a47a4d3ef27689010 --- .../android/internal/widget/FloatingToolbar.java | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'core') diff --git a/core/java/com/android/internal/widget/FloatingToolbar.java b/core/java/com/android/internal/widget/FloatingToolbar.java index 1fc0ac3..e02d706 100644 --- a/core/java/com/android/internal/widget/FloatingToolbar.java +++ b/core/java/com/android/internal/widget/FloatingToolbar.java @@ -289,7 +289,6 @@ public final class FloatingToolbar { public void onAnimationRepeat(Animation animation) { } }; - private final AnimatorSet mShowAnimation; private final AnimatorSet mDismissAnimation; private final AnimatorSet mHideAnimation; private final AnimationSet mOpenOverflowAnimation = new AnimationSet(true) { @@ -353,14 +352,9 @@ public final class FloatingToolbar { * from. */ public FloatingToolbarPopup(View parent) { - mMarginHorizontal = parent.getResources() - .getDimensionPixelSize(R.dimen.floating_toolbar_horizontal_margin); - mMarginVertical = parent.getResources() - .getDimensionPixelSize(R.dimen.floating_toolbar_vertical_margin); mParent = Preconditions.checkNotNull(parent); mContentContainer = createContentContainer(parent.getContext()); mPopupWindow = createPopupWindow(mContentContainer); - mShowAnimation = createGrowFadeInFromBottom(mContentContainer, mMarginHorizontal); mDismissAnimation = createShrinkFadeOutFromBottomAnimation( mContentContainer, 150, // startDelay @@ -380,6 +374,10 @@ public final class FloatingToolbar { mPopupWindow.dismiss(); } }); + mMarginHorizontal = parent.getResources() + .getDimensionPixelSize(R.dimen.floating_toolbar_horizontal_margin); + mMarginVertical = parent.getResources() + .getDimensionPixelSize(R.dimen.floating_toolbar_vertical_margin); } /** @@ -549,7 +547,7 @@ public final class FloatingToolbar { * Performs the "show" animation on the floating popup. */ private void runShowAnimation() { - mShowAnimation.start(); + createGrowFadeInFromBottom(mContentContainer).start(); } /** @@ -597,7 +595,6 @@ public final class FloatingToolbar { final float startY = mContentContainer.getY(); final float left = mContentContainer.getX(); final float right = left + mContentContainer.getWidth(); - final boolean rtl = mContentContainer.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; Animation widthAnimation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { @@ -605,7 +602,7 @@ public final class FloatingToolbar { int deltaWidth = (int) (interpolatedTime * (targetWidth - startWidth)); params.width = startWidth + deltaWidth; mContentContainer.setLayoutParams(params); - if (rtl) { + if (isRTL()) { mContentContainer.setX(left); } else { mContentContainer.setX(right - mContentContainer.getWidth()); @@ -656,7 +653,6 @@ public final class FloatingToolbar { final boolean morphedUpwards = (mOverflowDirection == OVERFLOW_DIRECTION_UP); final float left = mContentContainer.getX(); final float right = left + mContentContainer.getWidth(); - final boolean rtl = mContentContainer.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; Animation widthAnimation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { @@ -664,7 +660,7 @@ public final class FloatingToolbar { int deltaWidth = (int) (interpolatedTime * (targetWidth - startWidth)); params.width = startWidth + deltaWidth; mContentContainer.setLayoutParams(params); - if (rtl) { + if (isRTL()) { mContentContainer.setX(left); } else { mContentContainer.setX(right - mContentContainer.getWidth()); @@ -777,8 +773,13 @@ public final class FloatingToolbar { */ private void positionOverflowPanel() { Preconditions.checkNotNull(mOverflowPanel); - float x = mPopupWindow.getWidth() + float x; + if (isRTL()) { + x = mMarginHorizontal; + } else { + x = mPopupWindow.getWidth() - (mOverflowPanel.getView().getMeasuredWidth() + mMarginHorizontal); + } mContentContainer.setX(x); mContentContainer.setY(mMarginVertical); setContentAreaAsTouchableSurface(); @@ -856,6 +857,10 @@ public final class FloatingToolbar { viewTreeObserver.removeOnComputeInternalInsetsListener(mInsetsComputer); viewTreeObserver.addOnComputeInternalInsetsListener(mInsetsComputer); } + + private boolean isRTL() { + return mContentContainer.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + } } /** @@ -1332,14 +1337,14 @@ public final class FloatingToolbar { * * @param view The view to animate */ - private static AnimatorSet createGrowFadeInFromBottom(View view, int x) { + private static AnimatorSet createGrowFadeInFromBottom(View view) { AnimatorSet growFadeInFromBottomAnimation = new AnimatorSet(); growFadeInFromBottomAnimation.playTogether( ObjectAnimator.ofFloat(view, View.SCALE_X, 0.5f, 1).setDuration(125), ObjectAnimator.ofFloat(view, View.SCALE_Y, 0.5f, 1).setDuration(125), ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1).setDuration(75), // Make sure that view.x is always fixed throughout the duration of this animation. - ObjectAnimator.ofFloat(view, View.X, x, x)); + ObjectAnimator.ofFloat(view, View.X, view.getX(), view.getX())); growFadeInFromBottomAnimation.setStartDelay(50); return growFadeInFromBottomAnimation; } -- cgit v1.1