From 8bf2351797f2adfb444fc3356b6eb2c60c459bb7 Mon Sep 17 00:00:00 2001 From: Danny Baumann Date: Mon, 15 Jul 2013 13:31:32 +0200 Subject: Make notification-shade-collapse-after-dismiss behaviour configurable. Change-Id: I1be0be2753b479e6d2e4fc8e17d971d03ce01bb7 --- .../android/systemui/statusbar/BaseStatusBar.java | 65 ++++++++++++++++++---- .../systemui/statusbar/phone/PhoneStatusBar.java | 2 +- 2 files changed, 56 insertions(+), 11 deletions(-) (limited to 'packages') diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index b2d4e85..b56aa12 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -183,6 +183,7 @@ public abstract class BaseStatusBar extends SystemUI implements protected Display mDisplay; private boolean mDeviceProvisioned = false; + private int mAutoCollapseBehaviour; public IStatusBarService getStatusBarService() { return mBarService; @@ -192,7 +193,7 @@ public abstract class BaseStatusBar extends SystemUI implements return mDeviceProvisioned; } - private ContentObserver mProvisioningObserver = new ContentObserver(new Handler()) { + private ContentObserver mProvisioningObserver = new ContentObserver(mHandler) { @Override public void onChange(boolean selfChange) { final boolean provisioned = 0 != Settings.Global.getInt( @@ -204,6 +205,33 @@ public abstract class BaseStatusBar extends SystemUI implements } }; + private class SettingsObserver extends ContentObserver { + public SettingsObserver(Handler handler) { + super(handler); + } + + public void observe() { + ContentResolver resolver = mContext.getContentResolver(); + resolver.registerContentObserver(Settings.System.getUriFor( + Settings.System.STATUS_BAR_COLLAPSE_ON_DISMISS), false, this); + update(); + } + + @Override + public void onChange(boolean selfChange) { + update(); + } + + private void update() { + ContentResolver resolver = mContext.getContentResolver(); + mAutoCollapseBehaviour = Settings.System.getIntForUser(resolver, + Settings.System.STATUS_BAR_COLLAPSE_ON_DISMISS, + Settings.System.STATUS_BAR_COLLAPSE_IF_NO_CLEARABLE, UserHandle.USER_CURRENT); + } + }; + + private SettingsObserver mSettingsObserver = new SettingsObserver(mHandler); + private RemoteViews.OnClickHandler mOnClickHandler = new RemoteViews.OnClickHandler() { @Override public boolean onClickHandler(View view, PendingIntent pendingIntent, Intent fillInIntent) { @@ -246,6 +274,8 @@ public abstract class BaseStatusBar extends SystemUI implements Settings.Global.getUriFor(Settings.Global.DEVICE_PROVISIONED), true, mProvisioningObserver); + mSettingsObserver.observe(); + mBarService = IStatusBarService.Stub.asInterface( ServiceManager.getService(Context.STATUS_BAR_SERVICE)); @@ -950,18 +980,33 @@ public abstract class BaseStatusBar extends SystemUI implements if (rowParent != null) rowParent.removeView(entry.row); updateExpansionStates(); updateNotificationIcons(); + maybeCollapseAfterNotificationRemoval(entry.userDismissed()); - if (CLOSE_PANEL_WHEN_EMPTIED && isNotificationPanelFullyVisible()) { - if (entry.userDismissed() && !mNotificationData.hasClearableItems()) { - mHandler.removeCallbacks(mPanelCollapseRunnable); - mHandler.postDelayed(mPanelCollapseRunnable, COLLAPSE_AFTER_DISMISS_DELAY); - } else if (mNotificationData.size() == 0) { - mHandler.removeCallbacks(mPanelCollapseRunnable); - mHandler.postDelayed(mPanelCollapseRunnable, COLLAPSE_AFTER_REMOVE_DELAY); - } + return entry.notification; + } + + protected void maybeCollapseAfterNotificationRemoval(boolean userDismissed) { + if (mAutoCollapseBehaviour == Settings.System.STATUS_BAR_COLLAPSE_NEVER) { + return; + } + if (!isNotificationPanelFullyVisible()) { + return; } - return entry.notification; + boolean collapseDueToEmpty = + mAutoCollapseBehaviour == Settings.System.STATUS_BAR_COLLAPSE_IF_EMPTIED + && mNotificationData.size() == 0; + boolean collapseDueToNoClearable = + mAutoCollapseBehaviour == Settings.System.STATUS_BAR_COLLAPSE_IF_NO_CLEARABLE + && !mNotificationData.hasClearableItems(); + + if (userDismissed && (collapseDueToEmpty || collapseDueToNoClearable)) { + mHandler.removeCallbacks(mPanelCollapseRunnable); + mHandler.postDelayed(mPanelCollapseRunnable, COLLAPSE_AFTER_DISMISS_DELAY); + } else if (mNotificationData.size() == 0) { + mHandler.removeCallbacks(mPanelCollapseRunnable); + mHandler.postDelayed(mPanelCollapseRunnable, COLLAPSE_AFTER_REMOVE_DELAY); + } } protected StatusBarIconView addNotificationViews(IBinder key, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index 7d98350..ad588af 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -2549,7 +2549,7 @@ public class PhoneStatusBar extends BaseStatusBar { } if (snapshot.isEmpty()) { - animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_NONE); + maybeCollapseAfterNotificationRemoval(true); return; } -- cgit v1.1