Merge "Don't offer snooze for foreground service notifications" into oc-dev

This commit is contained in:
Mady Mellor
2017-04-12 18:27:23 +00:00
committed by Android (Google) Code Review
4 changed files with 68 additions and 24 deletions

View File

@@ -37,7 +37,7 @@ import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem
public interface NotificationMenuRowPlugin extends Plugin {
public static final String ACTION = "com.android.systemui.action.PLUGIN_NOTIFICATION_MENU_ROW";
public static final int VERSION = 1;
public static final int VERSION = 2;
@ProvidesInterface(version = OnMenuEventListener.VERSION)
public interface OnMenuEventListener {
@@ -89,6 +89,8 @@ public interface NotificationMenuRowPlugin extends Plugin {
public void onHeightUpdate();
public void onNotificationUpdated();
public boolean onTouchEvent(View view, MotionEvent ev, float velocity);
public default boolean useDefaultMenuItems() {

View File

@@ -328,6 +328,9 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
mIsColorized = mStatusBarNotification.getNotification().isColorized();
mShowingPublicInitialized = false;
updateNotificationColor();
if (mMenuRow != null) {
mMenuRow.onNotificationUpdated();
}
if (mIsSummaryWithChildren) {
mChildrenContainer.recreateNotificationHeader(mExpandClickListener);
mChildrenContainer.onNotificationUpdated();
@@ -760,7 +763,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
}
mMenuRow = plugin;
if (mMenuRow.useDefaultMenuItems()) {
mMenuRow.setMenuItems(NotificationMenuRow.getDefaultMenuItems(mContext));
ArrayList<MenuItem> items = new ArrayList<>();
items.add(NotificationMenuRow.createInfoItem(mContext));
items.add(NotificationMenuRow.createSnoozeItem(mContext));
mMenuRow.setMenuItems(items);
}
if (existed) {
createMenu();
@@ -787,7 +793,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
return mMenuRow;
}
public NotificationMenuRowPlugin getProvider() {
return mMenuRow;
}

View File

@@ -30,11 +30,13 @@ import com.android.systemui.statusbar.stack.NotificationStackScrollLayout;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.app.Notification;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.Log;
import android.service.notification.StatusBarNotification;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -48,12 +50,12 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
private static final long SHOW_MENU_DELAY = 60;
private static final long SWIPE_MENU_TIMING = 200;
private static final int NOTIFICATION_INFO_INDEX = 1;
private ExpandableNotificationRow mParent;
private Context mContext;
private FrameLayout mMenuContainer;
private MenuItem mSnoozeItem;
private MenuItem mInfoItem;
private ArrayList<MenuItem> mMenuItems;
private OnMenuEventListener mMenuListener;
@@ -94,7 +96,11 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
mVertSpaceForIcons = res.getDimensionPixelSize(R.dimen.notification_min_height);
mIconPadding = res.getDimensionPixelSize(R.dimen.notification_menu_icon_padding);
mHandler = new Handler();
mMenuItems = getDefaultMenuItems(context);
mMenuItems = new ArrayList<>();
mSnoozeItem = createSnoozeItem(context);
mInfoItem = createInfoItem(context);
mMenuItems.add(mSnoozeItem);
mMenuItems.add(mInfoItem);
}
@Override
@@ -104,7 +110,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
@Override
public MenuItem getLongpressMenuItem(Context context) {
return mMenuItems.get(NOTIFICATION_INFO_INDEX);
return mInfoItem;
}
@Override
@@ -120,14 +126,7 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
@Override
public void createMenu(ViewGroup parent) {
mParent = (ExpandableNotificationRow) parent;
if (mMenuContainer != null) {
mMenuContainer.removeAllViews();
}
mMenuContainer = new FrameLayout(mContext);
for (int i = 0; i < mMenuItems.size(); i++) {
addMenuView(mMenuItems.get(i), mMenuContainer);
}
resetState(false);
createMenuViews();
}
@Override
@@ -145,6 +144,40 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
resetState(true);
}
@Override
public void onNotificationUpdated() {
if (mMenuContainer == null) {
// Menu hasn't been created yet, no need to do anything.
return;
}
createMenuViews();
}
private void createMenuViews() {
// Filter the menu items based on the notification
if (mParent != null && mParent.getStatusBarNotification() != null) {
int flags = mParent.getStatusBarNotification().getNotification().flags;
boolean isForeground = (flags & Notification.FLAG_FOREGROUND_SERVICE) != 0;
if (isForeground) {
// Don't show snooze for foreground services
mMenuItems.remove(mSnoozeItem);
} else if (!mMenuItems.contains(mSnoozeItem)) {
// Was a foreground service but is no longer, add snooze back
mMenuItems.add(mSnoozeItem);
}
}
// Recreate the menu
if (mMenuContainer != null) {
mMenuContainer.removeAllViews();
} else {
mMenuContainer = new FrameLayout(mContext);
}
for (int i = 0; i < mMenuItems.size(); i++) {
addMenuView(mMenuItems.get(i), mMenuContainer);
}
resetState(false /* notify */);
}
private void resetState(boolean notify) {
setMenuAlpha(0f);
mIconsPlaced = false;
@@ -495,24 +528,24 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl
// TODO -- handle / allow custom menu items!
}
public static ArrayList<MenuItem> getDefaultMenuItems(Context context) {
ArrayList<MenuItem> items = new ArrayList<MenuItem>();
public static MenuItem createSnoozeItem(Context context) {
Resources res = context.getResources();
NotificationSnooze content = (NotificationSnooze) LayoutInflater.from(context)
.inflate(R.layout.notification_snooze, null, false);
String snoozeDescription = res.getString(R.string.notification_menu_snooze_description);
MenuItem snooze = new NotificationMenuItem(context, snoozeDescription, content,
R.drawable.ic_snooze);
items.add(snooze);
return snooze;
}
String settingsDescription = res.getString(R.string.notification_menu_gear_description);
NotificationInfo settingsContent = (NotificationInfo) LayoutInflater.from(context).inflate(
public static MenuItem createInfoItem(Context context) {
Resources res = context.getResources();
String infoDescription = res.getString(R.string.notification_menu_gear_description);
NotificationInfo infoContent = (NotificationInfo) LayoutInflater.from(context).inflate(
R.layout.notification_info, null, false);
MenuItem settings = new NotificationMenuItem(context, settingsDescription, settingsContent,
MenuItem info = new NotificationMenuItem(context, infoDescription, infoContent,
R.drawable.ic_settings);
items.add(settings);
return items;
return info;
}
private void addMenuView(MenuItem item, ViewGroup parent) {

View File

@@ -14,6 +14,8 @@
package com.android.systemui.statusbar;
import static junit.framework.Assert.assertTrue;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
@@ -49,6 +51,8 @@ public class NotificationMenuRowTest extends LeakCheckedTest {
public void testRecreateMenu() {
NotificationMenuRowPlugin row = new NotificationMenuRow(mContext);
row.createMenu(null);
assertTrue(row.getMenuView() != null);
row.createMenu(null);
assertTrue(row.getMenuView() != null);
}
}