blob: 35634374d5dd253ac1ad097adcd7021a6e42e092 [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;
18
Jason Monkb4302182017-08-04 13:39:17 -040019import android.app.Dialog;
20import android.app.KeyguardManager;
Jason Monkb4302182017-08-04 13:39:17 -040021import android.app.WallpaperManager;
22import android.content.Context;
Jason Monkb4302182017-08-04 13:39:17 -040023import android.graphics.Point;
24import 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;
32import com.android.internal.colorextraction.drawable.GradientDrawable;
33import 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;
Charles He9851a8d2017-10-10 17:31:30 +010038import com.android.systemui.statusbar.CommandQueue;
Jason Monk361915c2017-03-21 20:33:59 -040039import com.android.systemui.statusbar.policy.DeviceProvisionedController;
40import com.android.systemui.statusbar.policy.KeyguardMonitor;
41
Charles He9851a8d2017-10-10 17:31:30 +010042public class GlobalActionsImpl implements GlobalActions, CommandQueue.Callbacks {
Jason Monk361915c2017-03-21 20:33:59 -040043
Jason Monkb4302182017-08-04 13:39:17 -040044 private static final float SHUTDOWN_SCRIM_ALPHA = 0.95f;
45
Jason Monk361915c2017-03-21 20:33:59 -040046 private final Context mContext;
47 private final KeyguardMonitor mKeyguardMonitor;
48 private final DeviceProvisionedController mDeviceProvisionedController;
49 private GlobalActionsDialog mGlobalActions;
Charles He9851a8d2017-10-10 17:31:30 +010050 private boolean mDisabled;
Jason Monk361915c2017-03-21 20:33:59 -040051
52 public GlobalActionsImpl(Context context) {
53 mContext = context;
54 mKeyguardMonitor = Dependency.get(KeyguardMonitor.class);
55 mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class);
Charles He9851a8d2017-10-10 17:31:30 +010056 SysUiServiceProvider.getComponent(context, CommandQueue.class).addCallbacks(this);
57 }
58
59 @Override
60 public void destroy() {
61 SysUiServiceProvider.getComponent(mContext, CommandQueue.class).removeCallbacks(this);
Jason Monk361915c2017-03-21 20:33:59 -040062 }
63
64 @Override
65 public void showGlobalActions(GlobalActionsManager manager) {
Charles He9851a8d2017-10-10 17:31:30 +010066 if (mDisabled) return;
Jason Monk361915c2017-03-21 20:33:59 -040067 if (mGlobalActions == null) {
Lucas Dupin448786c2017-07-24 17:44:25 -070068 mGlobalActions = new GlobalActionsDialog(mContext, manager);
Jason Monk361915c2017-03-21 20:33:59 -040069 }
70 mGlobalActions.showDialog(mKeyguardMonitor.isShowing(),
71 mDeviceProvisionedController.isDeviceProvisioned());
72 }
Jason Monkb4302182017-08-04 13:39:17 -040073
74 @Override
75 public void showShutdownUi(boolean isReboot, String reason) {
76 GradientDrawable background = new GradientDrawable(mContext);
77 background.setAlpha((int) (SHUTDOWN_SCRIM_ALPHA * 255));
78
79 Dialog d = new Dialog(mContext,
80 com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
81 // Window initialization
82 Window window = d.getWindow();
83 window.getAttributes().width = ViewGroup.LayoutParams.MATCH_PARENT;
84 window.getAttributes().height = ViewGroup.LayoutParams.MATCH_PARENT;
85 window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
86 window.requestFeature(Window.FEATURE_NO_TITLE);
87 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND
88 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
89 window.addFlags(
90 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
91 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
92 | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
93 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
94 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
95 window.setBackgroundDrawable(background);
96 window.setWindowAnimations(R.style.Animation_Toast);
97
98 d.setContentView(R.layout.shutdown_dialog);
99 d.setCancelable(false);
100
101 int color = Utils.getColorAttr(mContext, com.android.systemui.R.attr.wallpaperTextColor);
102 boolean onKeyguard = mContext.getSystemService(
103 KeyguardManager.class).isKeyguardLocked();
104
105 ProgressBar bar = d.findViewById(R.id.progress);
106 bar.getIndeterminateDrawable().setTint(color);
107 TextView message = d.findViewById(R.id.text1);
108 message.setTextColor(color);
109 if (isReboot) message.setText(R.string.reboot_to_reset_message);
110
111 Point displaySize = new Point();
112 mContext.getDisplay().getRealSize(displaySize);
113 GradientColors colors = Dependency.get(SysuiColorExtractor.class).getColors(
114 onKeyguard ? WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM);
115 background.setColors(colors, false);
116 background.setScreenSize(displaySize.x, displaySize.y);
117
118 d.show();
119 }
Charles He9851a8d2017-10-10 17:31:30 +0100120
121 @Override
122 public void disable(int state1, int state2, boolean animate) {
123 final boolean disabled = (state2 & DISABLE2_GLOBAL_ACTIONS) != 0;
124 if (disabled == mDisabled) return;
125 mDisabled = disabled;
126 if (disabled && mGlobalActions != null) {
127 mGlobalActions.dismissDialog();
128 }
129 }
Jason Monk361915c2017-03-21 20:33:59 -0400130}