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 android.app.Dialog;
     18 import android.app.KeyguardManager;
     19 import android.app.WallpaperColors;
     20 import android.app.WallpaperManager;
     21 import android.content.Context;
     22 import android.graphics.Color;
     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;
     34 import com.android.systemui.Dependency;
     35 import com.android.systemui.colorextraction.SysuiColorExtractor;
     36 import com.android.systemui.plugins.GlobalActions;
     37 import com.android.systemui.statusbar.policy.DeviceProvisionedController;
     38 import com.android.systemui.statusbar.policy.KeyguardMonitor;
     39 
     40 public class GlobalActionsImpl implements GlobalActions {
     41 
     42     private static final float SHUTDOWN_SCRIM_ALPHA = 0.95f;
     43 
     44     private final Context mContext;
     45     private final KeyguardMonitor mKeyguardMonitor;
     46     private final DeviceProvisionedController mDeviceProvisionedController;
     47     private GlobalActionsDialog mGlobalActions;
     48 
     49     public GlobalActionsImpl(Context context) {
     50         mContext = context;
     51         mKeyguardMonitor = Dependency.get(KeyguardMonitor.class);
     52         mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class);
     53     }
     54 
     55     @Override
     56     public void showGlobalActions(GlobalActionsManager manager) {
     57         if (mGlobalActions == null) {
     58             mGlobalActions = new GlobalActionsDialog(mContext, manager);
     59         }
     60         mGlobalActions.showDialog(mKeyguardMonitor.isShowing(),
     61                 mDeviceProvisionedController.isDeviceProvisioned());
     62     }
     63 
     64     @Override
     65     public void showShutdownUi(boolean isReboot, String reason) {
     66         GradientDrawable background = new GradientDrawable(mContext);
     67         background.setAlpha((int) (SHUTDOWN_SCRIM_ALPHA * 255));
     68 
     69         Dialog d = new Dialog(mContext,
     70                 com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
     71         // Window initialization
     72         Window window = d.getWindow();
     73         window.getAttributes().width = ViewGroup.LayoutParams.MATCH_PARENT;
     74         window.getAttributes().height = ViewGroup.LayoutParams.MATCH_PARENT;
     75         window.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY);
     76         window.requestFeature(Window.FEATURE_NO_TITLE);
     77         window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND
     78                 | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
     79         window.addFlags(
     80                 WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
     81                         | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
     82                         | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
     83                         | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
     84                         | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
     85         window.setBackgroundDrawable(background);
     86         window.setWindowAnimations(R.style.Animation_Toast);
     87 
     88         d.setContentView(R.layout.shutdown_dialog);
     89         d.setCancelable(false);
     90 
     91         int color = Utils.getColorAttr(mContext, com.android.systemui.R.attr.wallpaperTextColor);
     92         boolean onKeyguard = mContext.getSystemService(
     93                 KeyguardManager.class).isKeyguardLocked();
     94 
     95         ProgressBar bar = d.findViewById(R.id.progress);
     96         bar.getIndeterminateDrawable().setTint(color);
     97         TextView message = d.findViewById(R.id.text1);
     98         message.setTextColor(color);
     99         if (isReboot) message.setText(R.string.reboot_to_reset_message);
    100 
    101         Point displaySize = new Point();
    102         mContext.getDisplay().getRealSize(displaySize);
    103         GradientColors colors = Dependency.get(SysuiColorExtractor.class).getColors(
    104                 onKeyguard ? WallpaperManager.FLAG_LOCK : WallpaperManager.FLAG_SYSTEM);
    105         background.setColors(colors, false);
    106         background.setScreenSize(displaySize.x, displaySize.y);
    107 
    108         d.show();
    109     }
    110 }
    111