OSDN Git Service

Fixes issue where the notification menu was not visible after RTL changes
authorMady Mellor <madym@google.com>
Wed, 5 Apr 2017 01:45:30 +0000 (18:45 -0700)
committerMady Mellor <madym@google.com>
Tue, 2 May 2017 21:25:56 +0000 (14:25 -0700)
- 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
Change-Id: I3a3b688f2b301f5ac0446a55b668db79c323a95c

packages/SystemUI/plugin/src/com/android/systemui/plugins/statusbar/NotificationMenuRowPlugin.java
packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
packages/SystemUI/src/com/android/systemui/statusbar/NotificationMenuRow.java

index 4a7d0fd..28f78e5 100644 (file)
@@ -96,4 +96,7 @@ public interface NotificationMenuRowPlugin extends Plugin {
     public default boolean useDefaultMenuItems() {
         return false;
     }
+
+    public default void onConfigurationChanged() {
+    }
 }
index 4612735..072373b 100644 (file)
@@ -25,6 +25,7 @@ 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;
@@ -836,6 +837,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) {
index 4305bde..8d3bff2 100644 (file)
@@ -165,6 +165,17 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
         createMenuViews();
     }
 
+    @Override
+    public void onConfigurationChanged() {
+        mParent.post(new Runnable() {
+            @Override
+            public void run() {
+                mIconsPlaced = false; // Force icons to be re-placed
+                setMenuLocation();
+            }
+        });
+    }
+
     private void createMenuViews() {
         // Filter the menu items based on the notification
         if (mParent != null && mParent.getStatusBarNotification() != null) {
@@ -459,22 +470,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;