Home | History | Annotate | Download | only in globalactions
      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 
     17 import static android.app.StatusBarManager.DISABLE2_GLOBAL_ACTIONS;
     18 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
     19 
     20 import android.app.Dialog;
     21 import android.app.KeyguardManager;
     22 import android.content.Context;
     23 import android.view.View;
     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.ScrimDrawable;
     33 import com.android.settingslib.Utils;
     34 import com.android.systemui.Dependency;
     35 import com.android.systemui.SysUiServiceProvider;
     36 import com.android.systemui.colorextraction.SysuiColorExtractor;
     37 import com.android.systemui.plugins.GlobalActions;
     38 import com.android.systemui.plugins.GlobalActionsPanelPlugin;
     39 import com.android.systemui.statusbar.CommandQueue;
     40 import com.android.systemui.statusbar.policy.DeviceProvisionedController;
     41 import com.android.systemui.statusbar.policy.ExtensionController;
     42 import com.android.systemui.statusbar.policy.KeyguardMonitor;
     43 
     44 public class GlobalActionsImpl implements GlobalActions, CommandQueue.Callbacks {
     45 
     46     private static final float SHUTDOWN_SCRIM_ALPHA = 0.95f;
     47 
     48     private final Context mContext;
     49     private final KeyguardMonitor mKeyguardMonitor;
     50     private final DeviceProvisionedController mDeviceProvisionedController;
     51     private final ExtensionController.Extension<GlobalActionsPanelPlugin> mPanelExtension;
     52     private GlobalActionsDialog mGlobalActions;
     53     private boolean mDisabled;
     54 
     55     public GlobalActionsImpl(Context context) {
     56         mContext = context;
     57         mKeyguardMonitor = Dependency.get(KeyguardMonitor.class);
     58         mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class);
     59         SysUiServiceProvider.getComponent(context, CommandQueue.class).addCallback(this);
     60         mPanelExtension = Dependency.get(ExtensionController.class)
     61                 .newExtension(GlobalActionsPanelPlugin.class)
     62                 .withPlugin(GlobalActionsPanelPlugin.class)
     63                 .build();
     64     }
     65 
     66     @Override
     67     public void destroy() {
     68         SysUiServiceProvider.getComponent(mContext, CommandQueue.class).removeCallback(this);
     69         if (mGlobalActions != null) {
     70             mGlobalActions.destroy();
     71             mGlobalActions = null;
     72         }
     73     }
     74 
     75     @Override
     76     public void showGlobalActions(GlobalActionsManager manager) {
     77         if (mDisabled) return;
     78         if (mGlobalActions == null) {
     79             mGlobalActions = new GlobalActionsDialog(mContext, manager);
     80         }
     81         mGlobalActions.showDialog(mKeyguardMonitor.isShowing(),
     82                 mDeviceProvisionedController.isDeviceProvisioned(),
     83                 mPanelExtension.get());
     84     }
     85 
     86     @Override
     87     public void showShutdownUi(boolean isReboot, String reason) {
     88         ScrimDrawable background = new ScrimDrawable();
     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();
     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();
    101         window.getAttributes().width = ViewGroup.LayoutParams.MATCH_PARENT;
    102         window.getAttributes().height = ViewGroup.LayoutParams.MATCH_PARENT;
    103         window.getAttributes().layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
    104         window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
    105         window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    106         window.addFlags(
    107                 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
    108                         | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
    109                         | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
    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 
    119         int color = Utils.getColorAttrDefaultColor(mContext,
    120                 com.android.systemui.R.attr.wallpaperTextColor);
    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 
    130         GradientColors colors = Dependency.get(SysuiColorExtractor.class).getNeutralColors();
    131         background.setColor(colors.getMainColor(), false);
    132 
    133         d.show();
    134     }
    135 
    136     @Override
    137     public void disable(int displayId, int state1, int state2, boolean animate) {
    138         final boolean disabled = (state2 & DISABLE2_GLOBAL_ACTIONS) != 0;
    139         if (displayId != mContext.getDisplayId() || disabled == mDisabled) return;
    140         mDisabled = disabled;
    141         if (disabled && mGlobalActions != null) {
    142             mGlobalActions.dismissDialog();
    143         }
    144     }
    145 }
    146