From d9c2232c9952d204a774041305b1ad5ce3d13715 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Tue, 4 Apr 2017 18:45:30 -0700 Subject: [PATCH] Fixes issue where the notification menu was not visible after RTL changes - Altered how the menu location is set so that it doesn't depend on RTL state - Also fixes an issue where if you change from landscape to portrait or vice versa then the menu wouldn't be visible because the placement is based on the width of the notification which changes based on orientation Test: (1) have notifications and show the menu, toggle the RTL state, show the menu, note that it is visible (2) have notifications and show the menu, rotate the device, note that the menu is still visible Fixes: 36874498 Merged-In: I33b8f87e53a3393a2802842ad2196c9d089ec7fc Merged-In: I3a3b688f2b301f5ac0446a55b668db79c323a95c Change-Id: I3a3b688f2b301f5ac0446a55b668db79c323a95c --- .../statusbar/NotificationMenuRowPlugin.java | 3 ++ .../statusbar/ExpandableNotificationRow.java | 25 ++++++++++++++++ .../statusbar/NotificationMenuRow.java | 30 ++++++++++++------- 3 files changed, 47 insertions(+), 11 deletions(-) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/NotificationMenuRowPlugin.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/NotificationMenuRowPlugin.java index 4a7d0fd8d1ff3..28f78e58c05a7 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/NotificationMenuRowPlugin.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/NotificationMenuRowPlugin.java @@ -96,4 +96,7 @@ public interface NotificationMenuRowPlugin extends Plugin { public default boolean useDefaultMenuItems() { return false; } + + public default void onConfigurationChanged() { + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java index 8c1b334fe5703..21aa10f40d1dd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java @@ -24,6 +24,8 @@ import android.animation.ObjectAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.annotation.Nullable; import android.content.Context; +import android.content.res.Resources; +import android.content.res.Configuration; import android.graphics.drawable.AnimatedVectorDrawable; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.ColorDrawable; @@ -84,6 +86,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView private static final int COLORED_DIVIDER_ALPHA = 0x7B; private static final int MENU_VIEW_INDEX = 0; + public interface LayoutListener { + public void onLayout(); + } + + private LayoutListener mLayoutListener; private final NotificationInflater mNotificationInflater; private int mIconTransformContentShift; private int mIconTransformContentShiftNoIcon; @@ -833,6 +840,13 @@ public class ExpandableNotificationRow extends ActivatableNotificationView onNotificationUpdated(); } + @Override + public void onConfigurationChanged(Configuration newConfig) { + if (mMenuRow.getMenuView() != null) { + mMenuRow.onConfigurationChanged(); + } + } + public void setContentBackground(int customBackgroundColor, boolean animate, NotificationContentView notificationContentView) { if (getShowingLayout() == notificationContentView) { @@ -1578,6 +1592,14 @@ public class ExpandableNotificationRow extends ActivatableNotificationView mIsSystemChildExpanded = expanded; } + public void setLayoutListener(LayoutListener listener) { + mLayoutListener = listener; + } + + public void removeListener() { + mLayoutListener = null; + } + @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); @@ -1586,6 +1608,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView mMenuRow.onHeightUpdate(); } updateContentShiftHeight(); + if (mLayoutListener != null) { + mLayoutListener.onLayout(); + } } /** diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMenuRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMenuRow.java index 4305bdef6fef1..cf910a724cfdc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMenuRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMenuRow.java @@ -44,7 +44,8 @@ import android.view.ViewGroup; import android.widget.FrameLayout; import android.widget.FrameLayout.LayoutParams; -public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnClickListener { +public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnClickListener, + ExpandableNotificationRow.LayoutListener { private static final boolean DEBUG = false; private static final String TAG = "swipe"; @@ -165,6 +166,18 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl createMenuViews(); } + @Override + public void onConfigurationChanged() { + mParent.setLayoutListener(this); + } + + @Override + public void onLayout() { + mIconsPlaced = false; // Force icons to be re-placed + setMenuLocation(); + mParent.removeListener(); + } + private void createMenuViews() { // Filter the menu items based on the notification if (mParent != null && mParent.getStatusBarNotification() != null) { @@ -459,22 +472,17 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl private void setMenuLocation() { boolean showOnLeft = mTranslation > 0; - if ((mIconsPlaced && showOnLeft == mOnLeft) || mSnapping || mParent == null) { + if ((mIconsPlaced && showOnLeft == mOnLeft) || mSnapping + || !mMenuContainer.isAttachedToWindow()) { // Do nothing return; } - final boolean isRtl = mParent.isLayoutRtl(); final int count = mMenuContainer.getChildCount(); - final int width = mParent.getWidth(); for (int i = 0; i < count; i++) { final View v = mMenuContainer.getChildAt(i); - final float left = isRtl - ? -(width - mHorizSpaceForIcon * (i + 1)) - : i * mHorizSpaceForIcon; - final float right = isRtl - ? -i * mHorizSpaceForIcon - : width - (mHorizSpaceForIcon * (i + 1)); - v.setTranslationX(showOnLeft ? left : right); + final float left = i * mHorizSpaceForIcon; + final float right = mParent.getWidth() - (mHorizSpaceForIcon * (i + 1)); + v.setX(showOnLeft ? left : right); } mOnLeft = showOnLeft; mIconsPlaced = true;