1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.keyguard; 18 19 import android.content.res.ColorStateList; 20 import android.content.res.Configuration; 21 22 import com.android.systemui.statusbar.policy.ConfigurationController; 23 import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; 24 import com.android.systemui.util.ViewController; 25 26 import javax.inject.Inject; 27 28 /** Controller for a {@link KeyguardMessageAreaController}. */ 29 public class KeyguardMessageAreaController extends ViewController<KeyguardMessageArea> { 30 private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; 31 private final ConfigurationController mConfigurationController; 32 private boolean mAltBouncerShowing; 33 34 private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() { 35 public void onFinishedGoingToSleep(int why) { 36 mView.setSelected(false); 37 } 38 39 public void onStartedWakingUp() { 40 mView.setSelected(true); 41 } 42 43 @Override 44 public void onKeyguardBouncerChanged(boolean bouncer) { 45 mView.setBouncerVisible(bouncer); 46 mView.update(); 47 } 48 }; 49 50 private ConfigurationListener mConfigurationListener = new ConfigurationListener() { 51 @Override 52 public void onConfigChanged(Configuration newConfig) { 53 mView.onConfigChanged(newConfig); 54 } 55 56 @Override 57 public void onThemeChanged() { 58 mView.onThemeChanged(); 59 } 60 61 @Override 62 public void onDensityOrFontScaleChanged() { 63 mView.onDensityOrFontScaleChanged(); 64 } 65 }; 66 KeyguardMessageAreaController(KeyguardMessageArea view, KeyguardUpdateMonitor keyguardUpdateMonitor, ConfigurationController configurationController)67 private KeyguardMessageAreaController(KeyguardMessageArea view, 68 KeyguardUpdateMonitor keyguardUpdateMonitor, 69 ConfigurationController configurationController) { 70 super(view); 71 72 mKeyguardUpdateMonitor = keyguardUpdateMonitor; 73 mConfigurationController = configurationController; 74 } 75 76 @Override onViewAttached()77 protected void onViewAttached() { 78 mConfigurationController.addCallback(mConfigurationListener); 79 mKeyguardUpdateMonitor.registerCallback(mInfoCallback); 80 mView.setSelected(mKeyguardUpdateMonitor.isDeviceInteractive()); 81 mView.onThemeChanged(); 82 } 83 84 @Override onViewDetached()85 protected void onViewDetached() { 86 mConfigurationController.removeCallback(mConfigurationListener); 87 mKeyguardUpdateMonitor.removeCallback(mInfoCallback); 88 } 89 90 /** 91 * Set whether alt bouncer is showing 92 */ setAltBouncerShowing(boolean showing)93 public void setAltBouncerShowing(boolean showing) { 94 mView.setAltBouncerShowing(showing); 95 } 96 setMessage(CharSequence s)97 public void setMessage(CharSequence s) { 98 mView.setMessage(s); 99 } 100 setMessage(int resId)101 public void setMessage(int resId) { 102 mView.setMessage(resId); 103 } 104 setNextMessageColor(ColorStateList colorState)105 public void setNextMessageColor(ColorStateList colorState) { 106 mView.setNextMessageColor(colorState); 107 } 108 109 /** 110 * Reload colors from resources. 111 **/ reloadColors()112 public void reloadColors() { 113 mView.reloadColor(); 114 } 115 116 /** Factory for creating {@link com.android.keyguard.KeyguardMessageAreaController}. */ 117 public static class Factory { 118 private final KeyguardUpdateMonitor mKeyguardUpdateMonitor; 119 private final ConfigurationController mConfigurationController; 120 121 @Inject Factory(KeyguardUpdateMonitor keyguardUpdateMonitor, ConfigurationController configurationController)122 public Factory(KeyguardUpdateMonitor keyguardUpdateMonitor, 123 ConfigurationController configurationController) { 124 mKeyguardUpdateMonitor = keyguardUpdateMonitor; 125 mConfigurationController = configurationController; 126 } 127 128 /** Build a new {@link KeyguardMessageAreaController}. */ create(KeyguardMessageArea view)129 public KeyguardMessageAreaController create(KeyguardMessageArea view) { 130 return new KeyguardMessageAreaController( 131 view, mKeyguardUpdateMonitor, mConfigurationController); 132 } 133 } 134 } 135