This will allow the NotificationMenuRow plugin to do something else
rather than showing a menu when the view is long pressed.
- Allow menu to intercept touch events
- If the menu item provided to long press is null, don’t show it
- Also passes the status bar notification when the menu is created
or updated
Bug:
62534409
Test: manual, have no plugin and long press -> see notification info
have a plugin that returns null for long press -> nothing happens
Change-Id: I384c5217d5343e990f4c3506eb2477b015705e5c
package com.android.systemui.plugins.statusbar;
import android.content.Context;
+import android.service.notification.StatusBarNotification;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
public interface NotificationMenuRowPlugin extends Plugin {
public static final String ACTION = "com.android.systemui.action.PLUGIN_NOTIFICATION_MENU_ROW";
- public static final int VERSION = 2;
+ public static final int VERSION = 3;
@ProvidesInterface(version = OnMenuEventListener.VERSION)
public interface OnMenuEventListener {
public void setAppName(String appName);
- public void createMenu(ViewGroup parent);
+ public void createMenu(ViewGroup parent, StatusBarNotification sbn);
public View getMenuView();
public void onHeightUpdate();
- public void onNotificationUpdated();
+ public void onNotificationUpdated(StatusBarNotification sbn);
public boolean onTouchEvent(View view, MotionEvent ev, float velocity);
+ public default boolean onInterceptTouchEvent(View view, MotionEvent ev) {
+ return false;
+ }
+
public default boolean useDefaultMenuItems() {
return false;
}
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
import com.android.systemui.classifier.FalsingManager;
+import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem;
import com.android.systemui.statusbar.ExpandableNotificationRow;
import com.android.systemui.statusbar.FlingAnimationUtils;
private float mDensityScale;
private float mTranslation = 0;
+ private boolean mMenuRowIntercepting;
private boolean mLongPressSent;
private LongPressListener mLongPressListener;
private Runnable mWatchLongPress;
@Override
public boolean onInterceptTouchEvent(final MotionEvent ev) {
+ if (mCurrView instanceof ExpandableNotificationRow) {
+ NotificationMenuRowPlugin nmr = ((ExpandableNotificationRow) mCurrView).getProvider();
+ mMenuRowIntercepting = nmr.onInterceptTouchEvent(mCurrView, ev);
+ }
final int action = ev.getAction();
switch (action) {
menuItem = ((ExpandableNotificationRow) mCurrView)
.getProvider().getLongpressMenuItem(mContext);
}
- mLongPressListener.onLongPress(mCurrView, x, y, menuItem);
+ if (menuItem != null) {
+ mLongPressListener.onLongPress(mCurrView, x, y,
+ menuItem);
+ }
}
}
};
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
- final boolean captured = (mDragging || mLongPressSent);
+ final boolean captured = (mDragging || mLongPressSent || mMenuRowIntercepting);
mDragging = false;
mCurrView = null;
mLongPressSent = false;
+ mMenuRowIntercepting = false;
removeLongPressCallback();
if (captured) return true;
break;
}
- return mDragging || mLongPressSent;
+ return mDragging || mLongPressSent || mMenuRowIntercepting;
}
/**
@Override
public boolean onTouchEvent(MotionEvent ev) {
- if (mLongPressSent) {
+ if (mLongPressSent && !mMenuRowIntercepting) {
return true;
}
- if (!mDragging) {
+ if (!mDragging && !mMenuRowIntercepting) {
if (mCallback.getChildAtPosition(ev) != null) {
// We are dragging directly over a card, make sure that we also catch the gesture
mShowingPublicInitialized = false;
updateNotificationColor();
if (mMenuRow != null) {
- mMenuRow.onNotificationUpdated();
+ mMenuRow.onNotificationUpdated(mStatusBarNotification);
}
if (mIsSummaryWithChildren) {
mChildrenContainer.recreateNotificationHeader(mExpandClickListener);
public NotificationMenuRowPlugin createMenu() {
if (mMenuRow.getMenuView() == null) {
- mMenuRow.createMenu(this);
+ mMenuRow.createMenu(this, mStatusBarNotification);
mMenuRow.setAppName(mAppName);
FrameLayout.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
if (oldMenu != null) {
int menuIndex = indexOfChild(oldMenu);
removeView(oldMenu);
- mMenuRow.createMenu(ExpandableNotificationRow.this);
+ mMenuRow.createMenu(ExpandableNotificationRow.this, mStatusBarNotification);
mMenuRow.setAppName(mAppName);
addView(mMenuRow.getMenuView(), menuIndex);
}
}
@Override
- public void createMenu(ViewGroup parent) {
+ public void createMenu(ViewGroup parent, StatusBarNotification sbn) {
mParent = (ExpandableNotificationRow) parent;
createMenuViews(true /* resetState */);
}
}
@Override
- public void onNotificationUpdated() {
+ public void onNotificationUpdated(StatusBarNotification sbn) {
if (mMenuContainer == null) {
// Menu hasn't been created yet, no need to do anything.
return;
@Test
public void testAttachDetach() {
NotificationMenuRowPlugin row = new NotificationMenuRow(mContext);
- row.createMenu(null);
+ row.createMenu(null, null);
ViewUtils.attachView(row.getMenuView());
TestableLooper.get(this).processAllMessages();
ViewUtils.detachView(row.getMenuView());
@Test
public void testRecreateMenu() {
NotificationMenuRowPlugin row = new NotificationMenuRow(mContext);
- row.createMenu(null);
+ row.createMenu(null, null);
assertTrue(row.getMenuView() != null);
- row.createMenu(null);
+ row.createMenu(null, null);
assertTrue(row.getMenuView() != null);
}
}