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; |
| 18 | |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 19 | import android.app.Dialog; |
| 20 | import android.app.KeyguardManager; |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 21 | import android.app.WallpaperManager; |
| 22 | import android.content.Context; |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 23 | import android.graphics.Point; |
| 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; |
| 32 | import com.android.internal.colorextraction.drawable.GradientDrawable; |
| 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; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 38 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 39 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 40 | import com.android.systemui.statusbar.policy.KeyguardMonitor; |
| 41 | |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 42 | public class GlobalActionsImpl implements GlobalActions, CommandQueue.Callbacks { |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 43 | |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 44 | private static final float SHUTDOWN_SCRIM_ALPHA = 0.95f; |
| 45 | |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 46 | private final Context mContext; |
| 47 | private final KeyguardMonitor mKeyguardMonitor; |
| 48 | private final DeviceProvisionedController mDeviceProvisionedController; |
| 49 | private GlobalActionsDialog mGlobalActions; |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 50 | private boolean mDisabled; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 51 | |
| 52 | public GlobalActionsImpl(Context context) { |
| 53 | mContext = context; |
| 54 | mKeyguardMonitor = Dependency.get(KeyguardMonitor.class); |
| 55 | mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 56 | SysUiServiceProvider.getComponent(context, CommandQueue.class).addCallbacks(this); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public void destroy() { |
| 61 | SysUiServiceProvider.getComponent(mContext, CommandQueue.class).removeCallbacks(this); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void showGlobalActions(GlobalActionsManager manager) { |
Charles He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 66 | if (mDisabled) return; |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 67 | if (mGlobalActions == null) { |
Lucas Dupin | 448786c | 2017-07-24 17:44:25 -0700 | [diff] [blame] | 68 | mGlobalActions = new GlobalActionsDialog(mContext, manager); |
Jason Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 69 | } |
| 70 | mGlobalActions.showDialog(mKeyguardMonitor.isShowing(), |
| 71 | mDeviceProvisionedController.isDeviceProvisioned()); |
| 72 | } |
Jason Monk | b430218 | 2017-08-04 13:39:17 -0400 | [diff] [blame] | 73 | |
| 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 He | 9851a8d | 2017-10-10 17:31:30 +0100 | [diff] [blame] | 120 | |
| 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 Monk | 361915c | 2017-03-21 20:33:59 -0400 | [diff] [blame] | 130 | } |