Merge "Ensure the menu items are properly recreated after a density change" into oc-dev

This commit is contained in:
TreeHugger Robot
2017-06-08 17:39:37 +00:00
committed by Android (Google) Code Review

View File

@@ -67,7 +67,6 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
private Context mContext; private Context mContext;
private FrameLayout mMenuContainer; private FrameLayout mMenuContainer;
private MenuItem mSnoozeItem;
private MenuItem mInfoItem; private MenuItem mInfoItem;
private ArrayList<MenuItem> mMenuItems; private ArrayList<MenuItem> mMenuItems;
private OnMenuEventListener mMenuListener; private OnMenuEventListener mMenuListener;
@@ -86,9 +85,9 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
private int[] mIconLocation = new int[2]; private int[] mIconLocation = new int[2];
private int[] mParentLocation = new int[2]; private int[] mParentLocation = new int[2];
private float mHorizSpaceForIcon; private float mHorizSpaceForIcon = -1;
private int mVertSpaceForIcons; private int mVertSpaceForIcons = -1;
private int mIconPadding; private int mIconPadding = -1;
private float mAlpha = 0f; private float mAlpha = 0f;
private float mPrevX; private float mPrevX;
@@ -104,17 +103,9 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
public NotificationMenuRow(Context context) { public NotificationMenuRow(Context context) {
mContext = context; mContext = context;
final Resources res = context.getResources(); mShouldShowMenu = context.getResources().getBoolean(R.bool.config_showNotificationGear);
mShouldShowMenu = res.getBoolean(R.bool.config_showNotificationGear);
mHorizSpaceForIcon = res.getDimensionPixelSize(R.dimen.notification_menu_icon_size);
mVertSpaceForIcons = res.getDimensionPixelSize(R.dimen.notification_min_height);
mIconPadding = res.getDimensionPixelSize(R.dimen.notification_menu_icon_padding);
mHandler = new Handler(Looper.getMainLooper()); mHandler = new Handler(Looper.getMainLooper());
mMenuItems = new ArrayList<>(); mMenuItems = new ArrayList<>();
mSnoozeItem = createSnoozeItem(context);
mInfoItem = createInfoItem(context);
mMenuItems.add(mSnoozeItem);
mMenuItems.add(mInfoItem);
} }
@Override @Override
@@ -180,19 +171,24 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
} }
private void createMenuViews(boolean resetState) { private void createMenuViews(boolean resetState) {
// Filter the menu items based on the notification final Resources res = mContext.getResources();
mHorizSpaceForIcon = res.getDimensionPixelSize(R.dimen.notification_menu_icon_size);
mVertSpaceForIcons = res.getDimensionPixelSize(R.dimen.notification_min_height);
mIconPadding = res.getDimensionPixelSize(R.dimen.notification_menu_icon_padding);
mMenuItems.clear();
// Construct the menu items based on the notification
if (mParent != null && mParent.getStatusBarNotification() != null) { if (mParent != null && mParent.getStatusBarNotification() != null) {
int flags = mParent.getStatusBarNotification().getNotification().flags; int flags = mParent.getStatusBarNotification().getNotification().flags;
boolean isForeground = (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0; boolean isForeground = (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0;
if (isForeground) { if (!isForeground) {
// Don't show snooze for foreground services // Only show snooze for non-foreground notifications
mMenuItems.remove(mSnoozeItem); mMenuItems.add(createSnoozeItem(mContext));
} else if (!mMenuItems.contains(mSnoozeItem)) {
// Was a foreground service but is no longer, add snooze back
mMenuItems.add(mSnoozeItem);
} }
} }
// Recreate the menu mInfoItem = createInfoItem(mContext);
mMenuItems.add(mInfoItem);
// Construct the menu views
if (mMenuContainer != null) { if (mMenuContainer != null) {
mMenuContainer.removeAllViews(); mMenuContainer.removeAllViews();
} else { } else {