Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | |
| 15 | package com.android.systemui.globalactions; |
| 16 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 17 | import static android.app.StatusBarManager.DISABLE2_GLOBAL_ACTIONS; |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 18 | import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 19 | |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 20 | import android.app.Dialog; |
| 21 | import android.app.KeyguardManager; |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 22 | import android.content.Context; |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 23 | import android.view.View; |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 24 | import android.view.ViewGroup; |
| 25 | import android.view.Window; |
| 26 | import android.view.WindowManager; |
| 27 | import android.widget.ProgressBar; |
| 28 | import android.widget.TextView; |
| 29 | |
| 30 | import com.android.internal.R; |
| 31 | import com.android.internal.colorextraction.ColorExtractor.GradientColors; |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 32 | import com.android.internal.colorextraction.drawable.ScrimDrawable; |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 33 | import com.android.settingslib.Utils; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 34 | import com.android.systemui.Dependency; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 35 | import com.android.systemui.SysUiServiceProvider; |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 36 | import com.android.systemui.colorextraction.SysuiColorExtractor; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 37 | import com.android.systemui.plugins.GlobalActions; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 38 | import com.android.systemui.plugins.GlobalActionsPanelPlugin; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 39 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 40 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 41 | import com.android.systemui.statusbar.policy.ExtensionController; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 42 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
| 43 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 44 | public class GlobalActionsImpl implements GlobalActions, CommandQueue.Callbacks { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 45 | |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 46 | private static final float SHUTDOWN_SCRIM_ALPHA = 0.95f; |
| 47 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 48 | private final Context mContext; |
| 49 | private final KeyguardMonitor mKeyguardMonitor; |
| 50 | private final DeviceProvisionedController mDeviceProvisionedController; |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 51 | private final ExtensionController.Extension<GlobalActionsPanelPlugin> mPanelExtension; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 52 | private GlobalActionsDialog mGlobalActions; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 53 | private boolean mDisabled; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 54 | |
| 55 | public GlobalActionsImpl(Context context) { |
| 56 | mContext = context; |
| 57 | mKeyguardMonitor = Dependency.get(KeyguardMonitor.class); |
| 58 | mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); |
Jason Monk | d7c9855 | 2018-12-04 11:14:50 -0500 | [diff] [blame] | 59 | SysUiServiceProvider.getComponent(context, CommandQueue.class).addCallback(this); |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 60 | mPanelExtension = Dependency.get(ExtensionController.class) |
| 61 | .newExtension(GlobalActionsPanelPlugin.class) |
| 62 | .withPlugin(GlobalActionsPanelPlugin.class) |
| 63 | .build(); |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void destroy() { |
Jason Monk | d7c9855 | 2018-12-04 11:14:50 -0500 | [diff] [blame] | 68 | SysUiServiceProvider.getComponent(mContext, CommandQueue.class).removeCallback(this); |
Lucas Dupin | e5b7dc7 | 2018-10-02 15:18:05 -0700 | [diff] [blame] | 69 | if (mGlobalActions != null) { |
| 70 | mGlobalActions.destroy(); |
| 71 | mGlobalActions = null; |
| 72 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void showGlobalActions(GlobalActionsManager manager) { |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 77 | if (mDisabled) return; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 78 | if (mGlobalActions == null) { |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 79 | mGlobalActions = new GlobalActionsDialog(mContext, manager); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 80 | } |
| 81 | mGlobalActions.showDialog(mKeyguardMonitor.isShowing(), |
Steve Elliott | a3f520792 | 2019-03-18 13:37:22 -0400 | [diff] [blame] | 82 | mDeviceProvisionedController.isDeviceProvisioned(), |
| 83 | mPanelExtension.get()); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 84 | } |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 85 | |
| 86 | @Override |
| 87 | public void showShutdownUi(boolean isReboot, String reason) { |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 88 | ScrimDrawable background = new ScrimDrawable(); |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 89 | background.setAlpha((int) (SHUTDOWN_SCRIM_ALPHA * 255)); |
| 90 | |
| 91 | Dialog d = new Dialog(mContext, |
| 92 | com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions); |
| 93 | // Window initialization |
| 94 | Window window = d.getWindow(); |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 95 | window.requestFeature(Window.FEATURE_NO_TITLE); |
| 96 | window.getAttributes().systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
| 97 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
| 98 | | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION; |
| 99 | // Inflate the decor view, so the attributes below are not overwritten by the theme. |
| 100 | window.getDecorView(); |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 101 | window.getAttributes().width = ViewGroup.LayoutParams.MATCH_PARENT; |
| 102 | window.getAttributes().height = ViewGroup.LayoutParams.MATCH_PARENT; |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 103 | window.getAttributes().layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 104 | window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY); |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 105 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 106 | window.addFlags( |
| 107 | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
| 108 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 109 | | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 110 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 111 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 112 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
| 113 | window.setBackgroundDrawable(background); |
| 114 | window.setWindowAnimations(R.style.Animation_Toast); |
| 115 | |
| 116 | d.setContentView(R.layout.shutdown_dialog); |
| 117 | d.setCancelable(false); |
| 118 | |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 119 | int color = Utils.getColorAttrDefaultColor(mContext, |
| 120 | com.android.systemui.R.attr.wallpaperTextColor); |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 121 | boolean onKeyguard = mContext.getSystemService( |
| 122 | KeyguardManager.class).isKeyguardLocked(); |
| 123 | |
| 124 | ProgressBar bar = d.findViewById(R.id.progress); |
| 125 | bar.getIndeterminateDrawable().setTint(color); |
| 126 | TextView message = d.findViewById(R.id.text1); |
| 127 | message.setTextColor(color); |
| 128 | if (isReboot) message.setText(R.string.reboot_to_reset_message); |
| 129 | |
Lucas Dupin | 2bd3af6 | 2019-03-25 17:44:28 -0700 | [diff] [blame] | 130 | GradientColors colors = Dependency.get(SysuiColorExtractor.class).getNeutralColors(); |
| 131 | background.setColor(colors.getMainColor(), false); |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 132 | |
| 133 | d.show(); |
| 134 | } |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 135 | |
| 136 | @Override |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 137 | public void disable(int displayId, int state1, int state2, boolean animate) { |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 138 | final boolean disabled = (state2 & DISABLE2_GLOBAL_ACTIONS) != 0; |
Charles Chen | f3d295c | 2018-11-30 18:15:21 +0800 | [diff] [blame] | 139 | if (displayId != mContext.getDisplayId() || disabled == mDisabled) return; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 140 | mDisabled = disabled; |
| 141 | if (disabled && mGlobalActions != null) { |
| 142 | mGlobalActions.dismissDialog(); |
| 143 | } |
| 144 | } |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 145 | } |