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
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 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 @@
* 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 @@
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 @@
* Performs the "show" animation on the floating popup.
*/
private void runShowAnimation() {
- mShowAnimation.start();
+ createGrowFadeInFromBottom(mContentContainer).start();
}
/**
@@ -597,7 +595,6 @@
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 @@
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 @@
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 @@
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 @@
*/
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 @@
viewTreeObserver.removeOnComputeInternalInsetsListener(mInsetsComputer);
viewTreeObserver.addOnComputeInternalInsetsListener(mInsetsComputer);
}
+
+ private boolean isRTL() {
+ return mContentContainer.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
+ }
}
/**
@@ -1332,14 +1337,14 @@
*
* @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;
}