Merge "Volume: delay dismissing panel when starting settings."
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 5c7dc90..f8b04ae 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -157,5 +157,8 @@
 
     <!-- Doze: should the significant motion sensor be used as a tease signal? -->
     <bool name="doze_tease_on_significant_motion">true</bool>
+
+    <!-- Volume: time to delay dismissing the volume panel after a click is performed -->
+    <integer name="volume_panel_dismiss_delay">200</integer>
 </resources>
 
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java b/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java
index 08216c4..3570257 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumePanel.java
@@ -263,7 +263,7 @@
             synchronized (sConfirmSafeVolumeLock) {
                 sConfirmSafeVolumeDialog = null;
             }
-            mVolumePanel.forceTimeout();
+            mVolumePanel.forceTimeout(0);
             mVolumePanel.updateStates();
         }
     }
@@ -293,7 +293,7 @@
                 public boolean onTouchEvent(MotionEvent event) {
                     if (isShowing() && event.getAction() == MotionEvent.ACTION_OUTSIDE &&
                             sConfirmSafeVolumeDialog == null) {
-                        forceTimeout();
+                        forceTimeout(0);
                         return true;
                     }
                     return false;
@@ -718,8 +718,8 @@
         obtainMessage(MSG_DISPLAY_SAFE_VOLUME_WARNING, flags, 0).sendToTarget();
     }
 
-    public void postDismiss() {
-        forceTimeout();
+    public void postDismiss(long delay) {
+        forceTimeout(delay);
     }
 
     public void postLayoutDirection(int layoutDirection) {
@@ -1205,9 +1205,9 @@
         sendEmptyMessage(MSG_USER_ACTIVITY);
     }
 
-    private void forceTimeout() {
+    private void forceTimeout(long delay) {
         removeMessages(MSG_TIMEOUT);
-        sendEmptyMessage(MSG_TIMEOUT);
+        sendEmptyMessageDelayed(MSG_TIMEOUT, delay);
     }
 
     public ZenModeController getZenController() {
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
index 51be833..e4f5870 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeUI.java
@@ -11,12 +11,14 @@
 import android.media.session.MediaController;
 import android.media.session.MediaSessionManager;
 import android.net.Uri;
+import android.os.AsyncTask;
 import android.os.Handler;
 import android.os.RemoteException;
 import android.os.UserHandle;
 import android.provider.Settings;
 import android.util.Log;
 
+import com.android.systemui.R;
 import com.android.systemui.SystemUI;
 import com.android.systemui.keyguard.KeyguardViewMediator;
 import com.android.systemui.statusbar.policy.ZenModeController;
@@ -45,6 +47,7 @@
     private static final int DEFAULT = 1;  // enabled by default
 
     private final Handler mHandler = new Handler();
+
     private AudioManager mAudioManager;
     private MediaSessionManager mMediaSessionManager;
     private VolumeController mVolumeController;
@@ -52,6 +55,7 @@
 
     private VolumePanel mDialogPanel;
     private VolumePanel mPanel;
+    private int mDismissDelay;
 
     @Override
     public void start() {
@@ -79,6 +83,7 @@
     }
 
     private void initPanel() {
+        mDismissDelay = mContext.getResources().getInteger(R.integer.volume_panel_dismiss_delay);
         mPanel = new VolumePanel(mContext, null, new ZenModeControllerImpl(mContext, mHandler));
         mPanel.setCallback(new VolumePanel.Callback() {
             @Override
@@ -109,15 +114,20 @@
     private final Runnable mStartZenSettings = new Runnable() {
         @Override
         public void run() {
-            mDialogPanel.postDismiss();
-            try {
-                // Dismiss the lock screen when Settings starts.
-                ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
-            } catch (RemoteException e) {
-            }
-            final Intent intent = ZenModePanel.ZEN_SETTINGS;
-            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
-            mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
+            AsyncTask.execute(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        // Dismiss the lock screen when Settings starts.
+                        ActivityManagerNative.getDefault().dismissKeyguardOnNextActivity();
+                    } catch (RemoteException e) {
+                    }
+                    final Intent intent = ZenModePanel.ZEN_SETTINGS;
+                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+                    mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
+                }
+            });
+            mDialogPanel.postDismiss(mDismissDelay);
         }
     };
 
@@ -153,7 +163,7 @@
 
         @Override
         public void dismiss() throws RemoteException {
-            mPanel.postDismiss();
+            mPanel.postDismiss(0);
         }
 
         @Override