* commit 'd9b7424923662e465fe2cf155cb7a9e6eef434c0': Fix FloatingToolbar look and animation for RTL.
This commit is contained in:
@@ -353,10 +353,14 @@ public final class FloatingToolbar {
|
|||||||
* from.
|
* from.
|
||||||
*/
|
*/
|
||||||
public FloatingToolbarPopup(View parent) {
|
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);
|
mParent = Preconditions.checkNotNull(parent);
|
||||||
mContentContainer = createContentContainer(parent.getContext());
|
mContentContainer = createContentContainer(parent.getContext());
|
||||||
mPopupWindow = createPopupWindow(mContentContainer);
|
mPopupWindow = createPopupWindow(mContentContainer);
|
||||||
mShowAnimation = createGrowFadeInFromBottom(mContentContainer);
|
mShowAnimation = createGrowFadeInFromBottom(mContentContainer, mMarginHorizontal);
|
||||||
mDismissAnimation = createShrinkFadeOutFromBottomAnimation(
|
mDismissAnimation = createShrinkFadeOutFromBottomAnimation(
|
||||||
mContentContainer,
|
mContentContainer,
|
||||||
150, // startDelay
|
150, // startDelay
|
||||||
@@ -376,17 +380,15 @@ public final class FloatingToolbar {
|
|||||||
mPopupWindow.dismiss();
|
mPopupWindow.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mMarginHorizontal = parent.getResources()
|
|
||||||
.getDimensionPixelSize(R.dimen.floating_toolbar_horizontal_margin);
|
|
||||||
mMarginVertical = parent.getResources()
|
|
||||||
.getDimensionPixelSize(R.dimen.floating_toolbar_vertical_margin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lays out buttons for the specified menu items.
|
* Lays out buttons for the specified menu items.
|
||||||
*/
|
*/
|
||||||
public void layoutMenuItems(List<MenuItem> menuItems,
|
public void layoutMenuItems(
|
||||||
MenuItem.OnMenuItemClickListener menuItemClickListener, int suggestedWidth) {
|
List<MenuItem> menuItems,
|
||||||
|
MenuItem.OnMenuItemClickListener menuItemClickListener,
|
||||||
|
int suggestedWidth) {
|
||||||
Preconditions.checkNotNull(menuItems);
|
Preconditions.checkNotNull(menuItems);
|
||||||
|
|
||||||
mContentContainer.removeAllViews();
|
mContentContainer.removeAllViews();
|
||||||
@@ -593,7 +595,9 @@ public final class FloatingToolbar {
|
|||||||
final int startWidth = mContentContainer.getWidth();
|
final int startWidth = mContentContainer.getWidth();
|
||||||
final int startHeight = mContentContainer.getHeight();
|
final int startHeight = mContentContainer.getHeight();
|
||||||
final float startY = mContentContainer.getY();
|
final float startY = mContentContainer.getY();
|
||||||
final float right = mContentContainer.getX() + mContentContainer.getWidth();
|
final float left = mContentContainer.getX();
|
||||||
|
final float right = left + mContentContainer.getWidth();
|
||||||
|
final boolean rtl = mContentContainer.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
|
||||||
Animation widthAnimation = new Animation() {
|
Animation widthAnimation = new Animation() {
|
||||||
@Override
|
@Override
|
||||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||||
@@ -601,7 +605,11 @@ public final class FloatingToolbar {
|
|||||||
int deltaWidth = (int) (interpolatedTime * (targetWidth - startWidth));
|
int deltaWidth = (int) (interpolatedTime * (targetWidth - startWidth));
|
||||||
params.width = startWidth + deltaWidth;
|
params.width = startWidth + deltaWidth;
|
||||||
mContentContainer.setLayoutParams(params);
|
mContentContainer.setLayoutParams(params);
|
||||||
mContentContainer.setX(right - mContentContainer.getWidth());
|
if (rtl) {
|
||||||
|
mContentContainer.setX(left);
|
||||||
|
} else {
|
||||||
|
mContentContainer.setX(right - mContentContainer.getWidth());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Animation heightAnimation = new Animation() {
|
Animation heightAnimation = new Animation() {
|
||||||
@@ -644,9 +652,11 @@ public final class FloatingToolbar {
|
|||||||
final int targetHeight = mainPanelSize.getHeight();
|
final int targetHeight = mainPanelSize.getHeight();
|
||||||
final int startWidth = mContentContainer.getWidth();
|
final int startWidth = mContentContainer.getWidth();
|
||||||
final int startHeight = mContentContainer.getHeight();
|
final int startHeight = mContentContainer.getHeight();
|
||||||
final float right = mContentContainer.getX() + mContentContainer.getWidth();
|
|
||||||
final float bottom = mContentContainer.getY() + mContentContainer.getHeight();
|
final float bottom = mContentContainer.getY() + mContentContainer.getHeight();
|
||||||
final boolean morphedUpwards = (mOverflowDirection == OVERFLOW_DIRECTION_UP);
|
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() {
|
Animation widthAnimation = new Animation() {
|
||||||
@Override
|
@Override
|
||||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||||
@@ -654,7 +664,11 @@ public final class FloatingToolbar {
|
|||||||
int deltaWidth = (int) (interpolatedTime * (targetWidth - startWidth));
|
int deltaWidth = (int) (interpolatedTime * (targetWidth - startWidth));
|
||||||
params.width = startWidth + deltaWidth;
|
params.width = startWidth + deltaWidth;
|
||||||
mContentContainer.setLayoutParams(params);
|
mContentContainer.setLayoutParams(params);
|
||||||
mContentContainer.setX(right - mContentContainer.getWidth());
|
if (rtl) {
|
||||||
|
mContentContainer.setX(left);
|
||||||
|
} else {
|
||||||
|
mContentContainer.setX(right - mContentContainer.getWidth());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Animation heightAnimation = new Animation() {
|
Animation heightAnimation = new Animation() {
|
||||||
@@ -747,9 +761,7 @@ public final class FloatingToolbar {
|
|||||||
*/
|
*/
|
||||||
private void positionMainPanel() {
|
private void positionMainPanel() {
|
||||||
Preconditions.checkNotNull(mMainPanel);
|
Preconditions.checkNotNull(mMainPanel);
|
||||||
float x = mPopupWindow.getWidth()
|
mContentContainer.setX(mMarginHorizontal);
|
||||||
- (mMainPanel.getView().getMeasuredWidth() + mMarginHorizontal);
|
|
||||||
mContentContainer.setX(x);
|
|
||||||
|
|
||||||
float y = mMarginVertical;
|
float y = mMarginVertical;
|
||||||
if (mOverflowDirection == OVERFLOW_DIRECTION_UP) {
|
if (mOverflowDirection == OVERFLOW_DIRECTION_UP) {
|
||||||
@@ -1320,12 +1332,14 @@ public final class FloatingToolbar {
|
|||||||
*
|
*
|
||||||
* @param view The view to animate
|
* @param view The view to animate
|
||||||
*/
|
*/
|
||||||
private static AnimatorSet createGrowFadeInFromBottom(View view) {
|
private static AnimatorSet createGrowFadeInFromBottom(View view, int x) {
|
||||||
AnimatorSet growFadeInFromBottomAnimation = new AnimatorSet();
|
AnimatorSet growFadeInFromBottomAnimation = new AnimatorSet();
|
||||||
growFadeInFromBottomAnimation.playTogether(
|
growFadeInFromBottomAnimation.playTogether(
|
||||||
ObjectAnimator.ofFloat(view, View.SCALE_X, 0.5f, 1).setDuration(125),
|
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.SCALE_Y, 0.5f, 1).setDuration(125),
|
||||||
ObjectAnimator.ofFloat(view, View.ALPHA, 0, 1).setDuration(75));
|
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));
|
||||||
growFadeInFromBottomAnimation.setStartDelay(50);
|
growFadeInFromBottomAnimation.setStartDelay(50);
|
||||||
return growFadeInFromBottomAnimation;
|
return growFadeInFromBottomAnimation;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user