blob: 4065d5b5dd8d972ae17dac11c932cae4c4159f54 [file] [log] [blame]
Jason Monk361915c2017-03-21 20:33:59 -04001/*
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
15package com.android.systemui.globalactions;
16
Charles He9851a8d2017-10-10 17:31:30 +010017import static android.app.StatusBarManager.DISABLE2_GLOBAL_ACTIONS;
Adrian Roosedfab3b2018-03-08 18:39:20 +010018import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Charles He9851a8d2017-10-10 17:31:30 +010019
Jason Monkb4302182017-08-04 13:39:17 -040020import android.app.Dialog;
21import android.app.KeyguardManager;
Jason Monkb4302182017-08-04 13:39:17 -040022import android.content.Context;
Adrian Roosedfab3b2018-03-08 18:39:20 +010023import android.view.View;
Jason Monkb4302182017-08-04 13:39:17 -040024import android.view.ViewGroup;
25import android.view.Window;
26import android.view.WindowManager;
27import android.widget.ProgressBar;
28import android.widget.TextView;
29
30import com.android.internal.R;
31import com.android.internal.colorextraction.ColorExtractor.GradientColors;
Lucas Dupin2bd3af62019-03-25 17:44:28 -070032import com.android.internal.colorextraction.drawable.ScrimDrawable;
Jason Monkb4302182017-08-04 13:39:17 -040033import com.android.settingslib.Utils;
Jason Monk361915c2017-03-21 20:33:59 -040034import com.android.systemui.Dependency;
Charles He9851a8d2017-10-10 17:31:30 +010035import com.android.systemui.SysUiServiceProvider;
Jason Monkb4302182017-08-04 13:39:17 -040036import com.android.systemui.colorextraction.SysuiColorExtractor;
Jason Monk361915c2017-03-21 20:33:59 -040037import com.android.systemui.plugins.GlobalActions;
Steve Elliotta3f5207922019-03-18 13:37:22 -040038import com.android.systemui.plugins.GlobalActionsPanelPlugin;
Charles He9851a8d2017-10-10 17:31:30 +010039import com.android.systemui.statusbar.CommandQueue;
Jason Monk361915c2017-03-21 20:33:59 -040040import com.android.systemui.statusbar.policy.DeviceProvisionedController;
Steve Elliotta3f5207922019-03-18 13:37:22 -040041import com.android.systemui.statusbar.policy.ExtensionController;
Jason Monk361915c2017-03-21 20:33:59 -040042import com.android.systemui.statusbar.policy.KeyguardMonitor;
43
Charles He9851a8d2017-10-10 17:31:30 +010044public class GlobalActionsImpl implements GlobalActions, CommandQueue.Callbacks {
Jason Monk361915c2017-03-21 20:33:59 -040045
Jason Monkb4302182017-08-04 13:39:17 -040046 private static final float SHUTDOWN_SCRIM_ALPHA = 0.95f;
47
Jason Monk361915c2017-03-21 20:33:59 -040048 private final Context mContext;
49 private final KeyguardMonitor mKeyguardMonitor;
50 private final DeviceProvisionedController mDeviceProvisionedController;
Steve Elliotta3f5207922019-03-18 13:37:22 -040051 private final ExtensionController.Extension<GlobalActionsPanelPlugin> mPanelExtension;
Jason Monk361915c2017-03-21 20:33:59 -040052 private GlobalActionsDialog mGlobalActions;
Charles He9851a8d2017-10-10 17:31:30 +010053 private boolean mDisabled;
Jason Monk361915c2017-03-21 20:33:59 -040054
55 public GlobalActionsImpl(Context context) {
56 mContext = context;
57 mKeyguardMonitor = Dependency.get(KeyguardMonitor.class);
58 mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class);
Jason Monkd7c98552018-12-04 11:14:50 -050059 SysUiServiceProvider.getComponent(context, CommandQueue.class).addCallback(this);
Steve Elliotta3f5207922019-03-18 13:37:22 -040060 mPanelExtension = Dependency.get(ExtensionController.class)
61 .newExtension(GlobalActionsPanelPlugin.class)
62 .withPlugin(GlobalActionsPanelPlugin.class)
63 .build();
Charles He9851a8d2017-10-10 17:31:30 +010064 }
65
66 @Override
67 public void destroy() {
Jason Monkd7c98552018-12-04 11:14:50 -050068 SysUiServiceProvider.getComponent(mContext, CommandQueue.class).removeCallback(this);
Lucas Dupine5b7dc72018-10-02 15:18:05 -070069 if (mGlobalActions != null) {
70 mGlobalActions.destroy();
71 mGlobalActions = null;
72 }
Jason Monk361915c2017-03-21 20:33:59 -040073 }
74
75 @Override
76 public void showGlobalActions(GlobalActionsManager manager) {
Charles He9851a8d2017-10-10 17:31:30 +010077 if (mDisabled) return;
Jason Monk361915c2017-03-21 20:33:59 -040078 if (mGlobalActions == null) {
Lucas Dupin448786c2017-07-24 17:44:25 -070079 mGlobalActions = new GlobalActionsDialog(mContext, manager);
Jason Monk361915c2017-03-21 20:33:59 -040080 }
81 mGlobalActions.showDialog(mKeyguardMonitor.isShowing(),
Steve Elliotta3f5207922019-03-18 13:37:22 -040082 mDeviceProvisionedController.isDeviceProvisioned(),
83 mPanelExtension.get());
Jason Monk361915c2017-03-21 20:33:59 -040084 }
Jason Monkb4302182017-08-04 13:39:17 -040085
86 @Override
87 public void showShutdownUi(boolean isReboot, String reason) {
Lucas Dupin2bd3af62019-03-25 17:44:28 -070088 ScrimDrawable background = new ScrimDrawable();
Jason Monkb4302182017-08-04 13:39:17 -040089 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 Roosedfab3b2018-03-08 18:39:20 +010095 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 Monkb4302182017-08-04 13:39:17 -0400101 window.getAttributes().width = ViewGroup.LayoutParams.MATCH_PARENT;
102 window.getAttributes().height = ViewGroup.LayoutParams.MATCH_PARENT;
Adrian Roosedfab3b2018-03-08 18:39:20 +0100103 window.getAttributes().layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
Jason Monkb4302182017-08-04 13:39:17 -0400104 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
Adrian Roosedfab3b2018-03-08 18:39:20 +0100105 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
Jason Monkb4302182017-08-04 13:39:17 -0400106 window.addFlags(
107 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
108 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
Adrian Roosedfab3b2018-03-08 18:39:20 +0100109 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
Jason Monkb4302182017-08-04 13:39:17 -0400110 | 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 Changb4e879d2018-04-11 11:17:58 +0800119 int color = Utils.getColorAttrDefaultColor(mContext,
120 com.android.systemui.R.attr.wallpaperTextColor);
Jason Monkb4302182017-08-04 13:39:17 -0400121 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 Dupin2bd3af62019-03-25 17:44:28 -0700130 GradientColors colors = Dependency.get(SysuiColorExtractor.class).getNeutralColors();
131 background.setColor(colors.getMainColor(), false);
Jason Monkb4302182017-08-04 13:39:17 -0400132
133 d.show();
134 }
Charles He9851a8d2017-10-10 17:31:30 +0100135
136 @Override
Charles Chenf3d295c2018-11-30 18:15:21 +0800137 public void disable(int displayId, int state1, int state2, boolean animate) {
Charles He9851a8d2017-10-10 17:31:30 +0100138 final boolean disabled = (state2 & DISABLE2_GLOBAL_ACTIONS) != 0;
Charles Chenf3d295c2018-11-30 18:15:21 +0800139 if (displayId != mContext.getDisplayId() || disabled == mDisabled) return;
Charles He9851a8d2017-10-10 17:31:30 +0100140 mDisabled = disabled;
141 if (disabled && mGlobalActions != null) {
142 mGlobalActions.dismissDialog();
143 }
144 }
Jason Monk361915c2017-03-21 20:33:59 -0400145}