diff options
7 files changed, 80 insertions, 8 deletions
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 55d12fc2802f..0961bc37afca 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -8249,6 +8249,16 @@ public final class Settings { private static final Validator NOTIFICATION_BADGING_VALIDATOR = BOOLEAN_VALIDATOR; /** + * Whether notifications are dismissed by a right-to-left swipe (instead of a left-to-right + * swipe). + * + * @hide + */ + public static final String NOTIFICATION_DISMISS_RTL = "notification_dismiss_rtl"; + + private static final Validator NOTIFICATION_DISMISS_RTL_VALIDATOR = BOOLEAN_VALIDATOR; + + /** * Comma separated list of QS tiles that have been auto-added already. * @hide */ @@ -8550,6 +8560,7 @@ public final class Settings { ASSIST_GESTURE_WAKE_ENABLED, VR_DISPLAY_MODE, NOTIFICATION_BADGING, + NOTIFICATION_DISMISS_RTL, QS_AUTO_ADDED_TILES, SCREENSAVER_ENABLED, SCREENSAVER_COMPONENTS, @@ -8712,6 +8723,7 @@ public final class Settings { VALIDATORS.put(ASSIST_GESTURE_WAKE_ENABLED, ASSIST_GESTURE_WAKE_ENABLED_VALIDATOR); VALIDATORS.put(VR_DISPLAY_MODE, VR_DISPLAY_MODE_VALIDATOR); VALIDATORS.put(NOTIFICATION_BADGING, NOTIFICATION_BADGING_VALIDATOR); + VALIDATORS.put(NOTIFICATION_DISMISS_RTL, NOTIFICATION_DISMISS_RTL_VALIDATOR); VALIDATORS.put(QS_AUTO_ADDED_TILES, QS_AUTO_ADDED_TILES_VALIDATOR); VALIDATORS.put(SCREENSAVER_ENABLED, SCREENSAVER_ENABLED_VALIDATOR); VALIDATORS.put(SCREENSAVER_COMPONENTS, SCREENSAVER_COMPONENTS_VALIDATOR); 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 0b1dab1c3bca..fc84332151ec 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 @@ -20,14 +20,14 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import java.util.ArrayList; - import com.android.systemui.plugins.Plugin; import com.android.systemui.plugins.annotations.DependsOn; import com.android.systemui.plugins.annotations.ProvidesInterface; +import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem; import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.OnMenuEventListener; import com.android.systemui.plugins.statusbar.NotificationSwipeActionHelper.SnoozeOption; -import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem; + +import java.util.ArrayList; @ProvidesInterface(action = NotificationMenuRowPlugin.ACTION, version = NotificationMenuRowPlugin.VERSION) @@ -149,6 +149,12 @@ public interface NotificationMenuRowPlugin extends Plugin { public boolean canBeDismissed(); /** + * Informs the menu whether dismiss gestures are left-to-right or right-to-left. + */ + default void setDismissRtl(boolean dismissRtl) { + } + + /** * Determines whether the menu should remain open given its current state, or snap closed. * @return true if the menu should remain open, false otherwise. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java index f46ded4d61d8..c25b7cfd804c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManager.java @@ -39,6 +39,9 @@ public interface NotificationLockscreenUserManager { boolean isCurrentProfile(int userId); + /** Adds a listener to be notified when the current user changes. */ + void addUserChangedListener(UserChangedListener listener); + void destroy(); SparseArray<UserInfo> getCurrentProfiles(); @@ -58,4 +61,9 @@ public interface NotificationLockscreenUserManager { boolean needsRedaction(NotificationEntry entry); boolean userAllowsPrivateNotificationsInPublic(int currentUserId); + + /** Notified when the current user changes. */ + interface UserChangedListener { + void onUserChanged(int userId); + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java index d2ce31d75648..4f9d4282dae8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java @@ -55,6 +55,8 @@ import com.android.systemui.statusbar.policy.KeyguardMonitor; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; /** * Handles keeping track of the current user, profiles, and various things related to hiding @@ -78,6 +80,7 @@ public class NotificationLockscreenUserManagerImpl implements private final SparseBooleanArray mUsersAllowingNotifications = new SparseBooleanArray(); private final UserManager mUserManager; private final IStatusBarService mBarService; + private final List<UserChangedListener> mListeners = new ArrayList<>(); private boolean mShowLockscreenNotifications; private boolean mAllowLockscreenRemoteInput; @@ -112,6 +115,10 @@ public class NotificationLockscreenUserManagerImpl implements updatePublicMode(); mPresenter.onUserSwitched(mCurrentUserId); getEntryManager().getNotificationData().filterAndSort(); + + for (UserChangedListener listener : mListeners) { + listener.onUserChanged(mCurrentUserId); + } } else if (Intent.ACTION_USER_ADDED.equals(action)) { updateCurrentProfilesCache(); } else if (Intent.ACTION_USER_UNLOCKED.equals(action)) { @@ -502,6 +509,10 @@ public class NotificationLockscreenUserManagerImpl implements } } + @Override + public void addUserChangedListener(UserChangedListener listener) { + mListeners.add(listener); + } // public void updatePublicMode() { // //TODO: I think there may be a race condition where mKeyguardViewManager.isShowing() returns @@ -541,6 +552,7 @@ public class NotificationLockscreenUserManagerImpl implements public void destroy() { mContext.unregisterReceiver(mBaseBroadcastReceiver); mContext.unregisterReceiver(mAllUsersReceiver); + mListeners.clear(); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java index 296c061459bc..bed2426021a1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java @@ -3092,6 +3092,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView } } + /** Sets whether dismiss gestures are right-to-left (instead of left-to-right). */ + public void setDismissRtl(boolean dismissRtl) { + mMenuRow.setDismissRtl(dismissRtl); + } + private static class NotificationViewState extends ExpandableViewState { @Override diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java index d97162c2ef1e..eafaba8370e4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationMenuRow.java @@ -78,6 +78,8 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl private ArrayList<MenuItem> mRightMenuItems; private final Map<View, MenuItem> mMenuItemsByView = new ArrayMap<>(); private OnMenuEventListener mMenuListener; + private boolean mDismissRtl; + private boolean mIsForeground; private ValueAnimator mFadeAnimator; private boolean mAnimating; @@ -238,6 +240,8 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl } private void createMenuViews(boolean resetState, final boolean isForeground) { + mIsForeground = isForeground; + final Resources res = mContext.getResources(); mHorizSpaceForIcon = res.getDimensionPixelSize(R.dimen.notification_menu_icon_size); mVertSpaceForIcons = res.getDimensionPixelSize(R.dimen.notification_min_height); @@ -268,10 +272,11 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl mRightMenuItems.add(mAppOpsItem); mLeftMenuItems.addAll(mRightMenuItems); } else { - mRightMenuItems.add(mInfoItem); - mRightMenuItems.add(mAppOpsItem); + ArrayList<MenuItem> menuItems = mDismissRtl ? mLeftMenuItems : mRightMenuItems; + menuItems.add(mInfoItem); + menuItems.add(mAppOpsItem); if (!isForeground) { - mRightMenuItems.add(mSnoozeItem); + menuItems.add(mSnoozeItem); } } @@ -729,6 +734,14 @@ public class NotificationMenuRow implements NotificationMenuRowPlugin, View.OnCl return getParent().canViewBeDismissed(); } + @Override + public void setDismissRtl(boolean dismissRtl) { + mDismissRtl = dismissRtl; + if (mMenuContainer != null) { + createMenuViews(true, mIsForeground); + } + } + public static class NotificationMenuItem implements MenuItem { View mMenuView; GutsContent mGutsContent; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java index 2129b81b1448..8d57ea5d8ed6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java @@ -174,6 +174,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd private final boolean mShouldDrawNotificationBackground; private boolean mLowPriorityBeforeSpeedBump; private final boolean mAllowLongPress; + private boolean mDismissRtl; private float mExpandedHeight; private int mOwnScrollY; @@ -533,8 +534,10 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd tunerService.addTunable((key, newValue) -> { if (key.equals(LOW_PRIORITY)) { mLowPriorityBeforeSpeedBump = "1".equals(newValue); + } else if (key.equals(Settings.Secure.NOTIFICATION_DISMISS_RTL)) { + updateDismissRtlSetting("1".equals(newValue)); } - }, LOW_PRIORITY); + }, LOW_PRIORITY, Settings.Secure.NOTIFICATION_DISMISS_RTL); mEntryManager.addNotificationEntryListener(new NotificationEntryListener() { @Override @@ -548,6 +551,16 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd }); } + private void updateDismissRtlSetting(boolean dismissRtl) { + mDismissRtl = dismissRtl; + for (int i = 0; i < getChildCount(); i++) { + View child = getChildAt(i); + if (child instanceof ExpandableNotificationRow) { + ((ExpandableNotificationRow) child).setDismissRtl(dismissRtl); + } + } + } + @Override @ShadeViewRefactor(RefactorComponent.SHADE_VIEW) protected void onFinishInflate() { @@ -3255,6 +3268,9 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd generateAddAnimation(child, false /* fromMoreCard */); updateAnimationState(child); updateChronometerForChild(child); + if (child instanceof ExpandableNotificationRow) { + ((ExpandableNotificationRow) child).setDismissRtl(mDismissRtl); + } if (ANCHOR_SCROLLING) { // TODO: once we're recycling this will need to check the adapter position of the child if (child == getFirstChildNotGone() && (isScrolledToTop() || !mIsExpanded)) { @@ -6315,7 +6331,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd public boolean canChildBeDismissedInDirection(View v, boolean isRightOrDown) { boolean isValidDirection; if (NotificationUtils.useNewInterruptionModel(mContext)) { - isValidDirection = isLayoutRtl() ? !isRightOrDown : isRightOrDown; + isValidDirection = mDismissRtl ? !isRightOrDown : isRightOrDown; } else { isValidDirection = true; } |