diff options
| author | 2018-05-03 08:34:38 -0700 | |
|---|---|---|
| committer | 2018-05-03 08:34:38 -0700 | |
| commit | c6bc98577915946f88a0e9d76d096953cb699d4c (patch) | |
| tree | 3082f99b9786a3728f555ead5ddad2dfe4fba6dc | |
| parent | d48aca89b0e2a2aeb949dc65c69b52481003e10b (diff) | |
| parent | 31919fb2327b368947c42c0c31882560b338a363 (diff) | |
Merge "Dismiss systemui QS dialogs on screen off." into pi-dev
am: 31919fb232
Change-Id: I65b9b897d09955d0d96f19e6fb5bde9c617a5fd5
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java | 58 | 
1 files changed, 38 insertions, 20 deletions
| diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java index 6a8d3a50eddd..48a9fb67c17b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java @@ -20,6 +20,7 @@ import android.app.AlertDialog;  import android.app.Dialog;  import android.content.BroadcastReceiver;  import android.content.Context; +import android.content.DialogInterface;  import android.content.Intent;  import android.content.IntentFilter;  import android.os.UserHandle; @@ -30,6 +31,7 @@ import com.android.systemui.Dependency;  import com.android.systemui.R;  import com.android.systemui.statusbar.policy.KeyguardMonitor; +  /**   * Base class for dialogs that should appear over panels and keyguard.   */ @@ -99,24 +101,40 @@ public class SystemUIDialog extends AlertDialog {      }      public static void registerDismissListener(Dialog dialog) { -        boolean[] registered = new boolean[1]; -        Context context = dialog.getContext(); -        final BroadcastReceiver mReceiver = new BroadcastReceiver() { -            @Override -            public void onReceive(Context context, Intent intent) { -                if (dialog != null) { -                    dialog.dismiss(); -                } -            } -        }; -        context.registerReceiverAsUser(mReceiver, UserHandle.CURRENT, -                new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS), null, null); -        registered[0] = true; -        dialog.setOnDismissListener(d -> { -            if (registered[0]) { -                context.unregisterReceiver(mReceiver); -                registered[0] = false; -            } -        }); +        DismissReceiver dismissReceiver = new DismissReceiver(dialog); +        dismissReceiver.register();      } -} + +    private static class DismissReceiver extends BroadcastReceiver implements OnDismissListener { +        private static final IntentFilter INTENT_FILTER = new IntentFilter(); +        static { +            INTENT_FILTER.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); +            INTENT_FILTER.addAction(Intent.ACTION_SCREEN_OFF); +        } + +        private final Dialog mDialog; +        private boolean mRegistered; + +        DismissReceiver(Dialog dialog) { +            mDialog = dialog; +        } + +        void register() { +            mDialog.getContext() +                    .registerReceiverAsUser(this, UserHandle.CURRENT, INTENT_FILTER, null, null); +            mRegistered = true; +        } + +        @Override +        public void onReceive(Context context, Intent intent) { +            mDialog.dismiss(); +        } + +        @Override +        public void onDismiss(DialogInterface dialog) { +            if (mRegistered) { +                mDialog.getContext().unregisterReceiver(this); +                mRegistered = false; +            } +        } +    }} |