• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.graphics.Rect;
20 import android.util.Slog;
21 
22 import com.android.keyguard.KeyguardClockSwitch.ClockSize;
23 import com.android.keyguard.logging.KeyguardLogger;
24 import com.android.systemui.plugins.ClockAnimations;
25 import com.android.systemui.statusbar.notification.AnimatableProperty;
26 import com.android.systemui.statusbar.notification.PropertyAnimator;
27 import com.android.systemui.statusbar.notification.stack.AnimationProperties;
28 import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
29 import com.android.systemui.statusbar.phone.DozeParameters;
30 import com.android.systemui.statusbar.phone.ScreenOffAnimationController;
31 import com.android.systemui.statusbar.policy.ConfigurationController;
32 import com.android.systemui.statusbar.policy.KeyguardStateController;
33 import com.android.systemui.util.ViewController;
34 
35 import javax.inject.Inject;
36 
37 /**
38  * Injectable controller for {@link KeyguardStatusView}.
39  */
40 public class KeyguardStatusViewController extends ViewController<KeyguardStatusView> {
41     private static final boolean DEBUG = KeyguardConstants.DEBUG;
42     private static final String TAG = "KeyguardStatusViewController";
43 
44     private static final AnimationProperties CLOCK_ANIMATION_PROPERTIES =
45             new AnimationProperties().setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
46 
47     private final KeyguardSliceViewController mKeyguardSliceViewController;
48     private final KeyguardClockSwitchController mKeyguardClockSwitchController;
49     private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
50     private final ConfigurationController mConfigurationController;
51     private final KeyguardVisibilityHelper mKeyguardVisibilityHelper;
52     private final Rect mClipBounds = new Rect();
53 
54     @Inject
KeyguardStatusViewController( KeyguardStatusView keyguardStatusView, KeyguardSliceViewController keyguardSliceViewController, KeyguardClockSwitchController keyguardClockSwitchController, KeyguardStateController keyguardStateController, KeyguardUpdateMonitor keyguardUpdateMonitor, ConfigurationController configurationController, DozeParameters dozeParameters, ScreenOffAnimationController screenOffAnimationController, KeyguardLogger logger)55     public KeyguardStatusViewController(
56             KeyguardStatusView keyguardStatusView,
57             KeyguardSliceViewController keyguardSliceViewController,
58             KeyguardClockSwitchController keyguardClockSwitchController,
59             KeyguardStateController keyguardStateController,
60             KeyguardUpdateMonitor keyguardUpdateMonitor,
61             ConfigurationController configurationController,
62             DozeParameters dozeParameters,
63             ScreenOffAnimationController screenOffAnimationController,
64             KeyguardLogger logger) {
65         super(keyguardStatusView);
66         mKeyguardSliceViewController = keyguardSliceViewController;
67         mKeyguardClockSwitchController = keyguardClockSwitchController;
68         mKeyguardUpdateMonitor = keyguardUpdateMonitor;
69         mConfigurationController = configurationController;
70         mKeyguardVisibilityHelper = new KeyguardVisibilityHelper(mView, keyguardStateController,
71                 dozeParameters, screenOffAnimationController, /* animateYPos= */ true,
72                 logger.getBuffer());
73     }
74 
75     @Override
onInit()76     public void onInit() {
77         mKeyguardClockSwitchController.init();
78     }
79 
80     @Override
onViewAttached()81     protected void onViewAttached() {
82         mKeyguardUpdateMonitor.registerCallback(mInfoCallback);
83         mConfigurationController.addCallback(mConfigurationListener);
84     }
85 
86     @Override
onViewDetached()87     protected void onViewDetached() {
88         mKeyguardUpdateMonitor.removeCallback(mInfoCallback);
89         mConfigurationController.removeCallback(mConfigurationListener);
90     }
91 
92     /**
93      * Updates views on doze time tick.
94      */
dozeTimeTick()95     public void dozeTimeTick() {
96         refreshTime();
97         mKeyguardSliceViewController.refresh();
98     }
99 
100     /**
101      * Set which clock should be displayed on the keyguard. The other one will be automatically
102      * hidden.
103      */
displayClock(@lockSize int clockSize, boolean animate)104     public void displayClock(@ClockSize int clockSize, boolean animate) {
105         mKeyguardClockSwitchController.displayClock(clockSize, animate);
106     }
107 
108     /**
109      * Performs fold to aod animation of the clocks (changes font weight from bold to thin).
110      * This animation is played when AOD is enabled and foldable device is fully folded, it is
111      * displayed on the outer screen
112      * @param foldFraction current fraction of fold animation complete
113      */
animateFoldToAod(float foldFraction)114     public void animateFoldToAod(float foldFraction) {
115         mKeyguardClockSwitchController.animateFoldToAod(foldFraction);
116     }
117 
118     /**
119      * Sets a translationY on the views on the keyguard, except on the media view.
120      */
setTranslationY(float translationY, boolean excludeMedia)121     public void setTranslationY(float translationY, boolean excludeMedia) {
122         mView.setChildrenTranslationY(translationY, excludeMedia);
123     }
124 
125     /**
126      * Set keyguard status view alpha.
127      */
setAlpha(float alpha)128     public void setAlpha(float alpha) {
129         if (!mKeyguardVisibilityHelper.isVisibilityAnimating()) {
130             mView.setAlpha(alpha);
131         }
132     }
133 
134     /**
135      * Update the pivot position based on the parent view
136      */
updatePivot(float parentWidth, float parentHeight)137     public void updatePivot(float parentWidth, float parentHeight) {
138         mView.setPivotX(parentWidth / 2f);
139         mView.setPivotY(mKeyguardClockSwitchController.getClockHeight() / 2f);
140     }
141 
142     /**
143      * Get the height of the keyguard status view without the notification icon area, as that's
144      * only visible on AOD.
145      */
getLockscreenHeight()146     public int getLockscreenHeight() {
147         return mView.getHeight() - mKeyguardClockSwitchController.getNotificationIconAreaHeight();
148     }
149 
150     /**
151      * Get y-bottom position of the currently visible clock.
152      */
getClockBottom(int statusBarHeaderHeight)153     public int getClockBottom(int statusBarHeaderHeight) {
154         return mKeyguardClockSwitchController.getClockBottom(statusBarHeaderHeight);
155     }
156 
157     /**
158      * @return true if the currently displayed clock is top aligned (as opposed to center aligned)
159      */
isClockTopAligned()160     public boolean isClockTopAligned() {
161         return mKeyguardClockSwitchController.isClockTopAligned();
162     }
163 
164     /**
165      * Set whether the view accessibility importance mode.
166      */
setStatusAccessibilityImportance(int mode)167     public void setStatusAccessibilityImportance(int mode) {
168         mView.setImportantForAccessibility(mode);
169     }
170 
171     /**
172      * Update position of the view with an optional animation
173      */
updatePosition(int x, int y, float scale, boolean animate)174     public void updatePosition(int x, int y, float scale, boolean animate) {
175         PropertyAnimator.setProperty(mView, AnimatableProperty.Y, y, CLOCK_ANIMATION_PROPERTIES,
176                 animate);
177 
178         mKeyguardClockSwitchController.updatePosition(x, scale, CLOCK_ANIMATION_PROPERTIES,
179                 animate);
180     }
181 
182     /**
183      * Set the visibility of the keyguard status view based on some new state.
184      */
setKeyguardStatusViewVisibility( int statusBarState, boolean keyguardFadingAway, boolean goingToFullShade, int oldStatusBarState)185     public void setKeyguardStatusViewVisibility(
186             int statusBarState,
187             boolean keyguardFadingAway,
188             boolean goingToFullShade,
189             int oldStatusBarState) {
190         mKeyguardVisibilityHelper.setViewVisibility(
191                 statusBarState, keyguardFadingAway, goingToFullShade, oldStatusBarState);
192     }
193 
refreshTime()194     private void refreshTime() {
195         mKeyguardClockSwitchController.refresh();
196     }
197 
198     private final ConfigurationController.ConfigurationListener mConfigurationListener =
199             new ConfigurationController.ConfigurationListener() {
200         @Override
201         public void onLocaleListChanged() {
202             refreshTime();
203             mKeyguardClockSwitchController.onLocaleListChanged();
204         }
205 
206         @Override
207         public void onDensityOrFontScaleChanged() {
208             mKeyguardClockSwitchController.onDensityOrFontScaleChanged();
209         }
210     };
211 
212     private KeyguardUpdateMonitorCallback mInfoCallback = new KeyguardUpdateMonitorCallback() {
213         @Override
214         public void onTimeChanged() {
215             refreshTime();
216         }
217 
218         @Override
219         public void onKeyguardVisibilityChanged(boolean visible) {
220             if (visible) {
221                 if (DEBUG) Slog.v(TAG, "refresh statusview visible:true");
222                 refreshTime();
223             }
224         }
225     };
226 
227     /**
228      * Rect that specifies how KSV should be clipped, on its parent's coordinates.
229      */
setClipBounds(Rect clipBounds)230     public void setClipBounds(Rect clipBounds) {
231         if (clipBounds != null) {
232             mClipBounds.set(clipBounds.left, (int) (clipBounds.top - mView.getY()),
233                     clipBounds.right, (int) (clipBounds.bottom - mView.getY()));
234             mView.setClipBounds(mClipBounds);
235         } else {
236             mView.setClipBounds(null);
237         }
238     }
239 
240     /** Gets the animations for the current clock. */
getClockAnimations()241     public ClockAnimations getClockAnimations() {
242         return mKeyguardClockSwitchController.getClockAnimations();
243     }
244 }
245