blob: b46ca401ae0593f59f61c14f4f3c24eca9d69b3f [file] [log] [blame]
Jorim Jaggi4538027d2014-07-30 15:43:13 +02001/*
2 * Copyright (C) 2014 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
17package com.android.systemui.statusbar.phone;
18
Adrian Roos6a4fa0e2018-03-05 19:50:16 +010019import static com.android.systemui.ScreenDecorations.DisplayCutoutView.boundsFromDirection;
20
Lucas Dupin987f1932017-05-13 21:02:52 -070021import android.annotation.ColorInt;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020022import android.content.Context;
Jorim Jaggie210cc82014-08-12 23:44:59 +020023import android.content.res.Configuration;
Daniel Nishif79cd872016-06-27 11:44:01 -070024import android.content.res.Resources;
Lucas Dupin987f1932017-05-13 21:02:52 -070025import android.graphics.Color;
Jason Monk9cac5ff2017-06-02 11:35:50 -040026import android.graphics.Rect;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020027import android.graphics.drawable.Drawable;
28import android.util.AttributeSet;
Adrian Roos13836052018-03-15 21:06:37 +010029import android.util.Pair;
Jorim Jaggie210cc82014-08-12 23:44:59 +020030import android.util.TypedValue;
Evan Laird264275e2018-03-01 19:39:39 -050031import android.view.DisplayCutout;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +010032import android.view.Gravity;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020033import android.view.View;
Jason Monk9cac5ff2017-06-02 11:35:50 -040034import android.view.ViewGroup;
Jorim Jaggi98f85302014-08-07 17:45:04 +020035import android.view.ViewTreeObserver;
Adrian Roosedfab3b2018-03-08 18:39:20 +010036import android.view.WindowInsets;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020037import android.widget.ImageView;
Evan Laird264275e2018-03-01 19:39:39 -050038import android.widget.LinearLayout;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020039import android.widget.RelativeLayout;
40import android.widget.TextView;
41
Lucas Dupin987f1932017-05-13 21:02:52 -070042import com.android.settingslib.Utils;
Dan Sandlerdf14c202017-02-21 14:51:11 -050043import com.android.systemui.BatteryMeterView;
Jason Monk9c7844c2017-01-18 15:21:53 -050044import com.android.systemui.Dependency;
Winsonc0d70582016-01-29 10:24:39 -080045import com.android.systemui.Interpolators;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020046import com.android.systemui.R;
Beverly1be62f42018-12-19 17:17:48 -050047import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
Kaori Katouccf08d72015-05-26 16:25:04 +090048import com.android.systemui.qs.QSPanel;
Dave Mankoffbcaca8a2019-10-31 18:04:08 -040049import com.android.systemui.statusbar.CommandQueue;
Jason Monk9cac5ff2017-06-02 11:35:50 -040050import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020051import com.android.systemui.statusbar.policy.BatteryController;
Jason Monk9c7844c2017-01-18 15:21:53 -050052import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback;
Jason Monk9cac5ff2017-06-02 11:35:50 -040053import com.android.systemui.statusbar.policy.ConfigurationController;
54import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020055import com.android.systemui.statusbar.policy.KeyguardUserSwitcher;
56import com.android.systemui.statusbar.policy.UserInfoController;
Jason Monk9c7844c2017-01-18 15:21:53 -050057import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener;
Lucas Dupin542aebc2017-08-04 11:24:06 -070058import com.android.systemui.statusbar.policy.UserInfoControllerImpl;
Adrian Roosffc90972015-06-09 18:09:49 -070059import com.android.systemui.statusbar.policy.UserSwitcherController;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020060
Lucas Dupinc510d412018-06-12 13:08:23 -070061import java.io.FileDescriptor;
62import java.io.PrintWriter;
63
Jorim Jaggi4538027d2014-07-30 15:43:13 +020064/**
65 * The header group on Keyguard.
66 */
67public class KeyguardStatusBarView extends RelativeLayout
Jason Monk9cac5ff2017-06-02 11:35:50 -040068 implements BatteryStateChangeCallback, OnUserInfoChangedListener, ConfigurationListener {
Jorim Jaggi4538027d2014-07-30 15:43:13 +020069
Evan Laird264275e2018-03-01 19:39:39 -050070 private static final int LAYOUT_NONE = 0;
71 private static final int LAYOUT_CUTOUT = 1;
72 private static final int LAYOUT_NO_CUTOUT = 2;
73
Lucas Dupin7da4f262018-09-20 13:41:46 -070074 private final Rect mEmptyRect = new Rect(0, 0, 0, 0);
75
Evan Laird54ff81b2018-06-13 20:08:17 -040076 private boolean mShowPercentAvailable;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020077 private boolean mBatteryCharging;
78 private boolean mKeyguardUserSwitcherShowing;
79 private boolean mBatteryListening;
80
Jorim Jaggie210cc82014-08-12 23:44:59 +020081 private TextView mCarrierLabel;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020082 private MultiUserSwitch mMultiUserSwitch;
83 private ImageView mMultiUserAvatar;
Dan Sandlerdf14c202017-02-21 14:51:11 -050084 private BatteryMeterView mBatteryView;
Lucas Dupin7da4f262018-09-20 13:41:46 -070085 private StatusIconContainer mStatusIconContainer;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020086
87 private BatteryController mBatteryController;
88 private KeyguardUserSwitcher mKeyguardUserSwitcher;
Daniel Nishi8ba446c2016-06-20 18:56:35 -070089 private UserSwitcherController mUserSwitcherController;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020090
91 private int mSystemIconsSwitcherHiddenExpandedMargin;
Daniel Nishif79cd872016-06-27 11:44:01 -070092 private int mSystemIconsBaseMargin;
Selim Cinek6ebba592016-05-31 15:28:28 -070093 private View mSystemIconsContainer;
Jason Monk9cac5ff2017-06-02 11:35:50 -040094 private TintedIconManager mIconManager;
Jorim Jaggi4538027d2014-07-30 15:43:13 +020095
Evan Laird264275e2018-03-01 19:39:39 -050096 private View mCutoutSpace;
97 private ViewGroup mStatusIconArea;
98 private int mLayoutState = LAYOUT_NONE;
99
Evan Laird17a96ba2018-05-23 18:21:56 -0400100 /**
101 * Draw this many pixels into the left/right side of the cutout to optimally use the space
102 */
103 private int mCutoutSideNudge = 0;
104
shawnlinbd6d0ad2020-01-29 18:38:49 +0800105 private DisplayCutout mDisplayCutout;
106 private int mRoundedCornerPadding = 0;
107
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200108 public KeyguardStatusBarView(Context context, AttributeSet attrs) {
109 super(context, attrs);
110 }
111
112 @Override
113 protected void onFinishInflate() {
114 super.onFinishInflate();
Selim Cinek6ebba592016-05-31 15:28:28 -0700115 mSystemIconsContainer = findViewById(R.id.system_icons_container);
Lucas Dupina39d5b22018-02-26 15:53:43 -0800116 mMultiUserSwitch = findViewById(R.id.multi_user_switch);
117 mMultiUserAvatar = findViewById(R.id.multi_user_avatar);
118 mCarrierLabel = findViewById(R.id.keyguard_carrier_text);
119 mBatteryView = mSystemIconsContainer.findViewById(R.id.battery);
Evan Laird264275e2018-03-01 19:39:39 -0500120 mCutoutSpace = findViewById(R.id.cutout_space_view);
121 mStatusIconArea = findViewById(R.id.status_icon_area);
Lucas Dupin7da4f262018-09-20 13:41:46 -0700122 mStatusIconContainer = findViewById(R.id.statusIcons);
Dan Sandlerdf14c202017-02-21 14:51:11 -0500123
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200124 loadDimens();
125 updateUserSwitcher();
Jason Monk9c7844c2017-01-18 15:21:53 -0500126 mBatteryController = Dependency.get(BatteryController.class);
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200127 }
128
Jorim Jaggie210cc82014-08-12 23:44:59 +0200129 @Override
130 protected void onConfigurationChanged(Configuration newConfig) {
131 super.onConfigurationChanged(newConfig);
132
Adrian Roosd390b892016-05-05 10:50:49 -0400133 MarginLayoutParams lp = (MarginLayoutParams) mMultiUserAvatar.getLayoutParams();
134 lp.width = lp.height = getResources().getDimensionPixelSize(
135 R.dimen.multi_user_avatar_keyguard_size);
136 mMultiUserAvatar.setLayoutParams(lp);
Selim Cinek6ebba592016-05-31 15:28:28 -0700137
Evan Laird264275e2018-03-01 19:39:39 -0500138 // Multi-user switch
Selim Cinek6ebba592016-05-31 15:28:28 -0700139 lp = (MarginLayoutParams) mMultiUserSwitch.getLayoutParams();
140 lp.width = getResources().getDimensionPixelSize(
141 R.dimen.multi_user_switch_width_keyguard);
142 lp.setMarginEnd(getResources().getDimensionPixelSize(
143 R.dimen.multi_user_switch_keyguard_margin));
144 mMultiUserSwitch.setLayoutParams(lp);
145
Evan Laird264275e2018-03-01 19:39:39 -0500146 // System icons
Selim Cinek6ebba592016-05-31 15:28:28 -0700147 lp = (MarginLayoutParams) mSystemIconsContainer.getLayoutParams();
Evan Laird264275e2018-03-01 19:39:39 -0500148 lp.setMarginStart(getResources().getDimensionPixelSize(
149 R.dimen.system_icons_super_container_margin_start));
Selim Cinek6ebba592016-05-31 15:28:28 -0700150 mSystemIconsContainer.setLayoutParams(lp);
Evan Laird264275e2018-03-01 19:39:39 -0500151 mSystemIconsContainer.setPaddingRelative(mSystemIconsContainer.getPaddingStart(),
152 mSystemIconsContainer.getPaddingTop(),
153 getResources().getDimensionPixelSize(R.dimen.system_icons_keyguard_padding_end),
154 mSystemIconsContainer.getPaddingBottom());
Selim Cinek6ebba592016-05-31 15:28:28 -0700155
Selim Cinek6ebba592016-05-31 15:28:28 -0700156 // Respect font size setting.
157 mCarrierLabel.setTextSize(TypedValue.COMPLEX_UNIT_PX,
158 getResources().getDimensionPixelSize(
159 com.android.internal.R.dimen.text_size_small_material));
160 lp = (MarginLayoutParams) mCarrierLabel.getLayoutParams();
161 lp.setMarginStart(
162 getResources().getDimensionPixelSize(R.dimen.keyguard_carrier_text_margin));
163 mCarrierLabel.setLayoutParams(lp);
164
shawnlinbd6d0ad2020-01-29 18:38:49 +0800165 updateKeyguardStatusBarHeight();
166 }
167
168 private void updateKeyguardStatusBarHeight() {
169 final int waterfallTop =
170 mDisplayCutout == null ? 0 : mDisplayCutout.getWaterfallInsets().top;
171 MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams();
Selim Cinek6ebba592016-05-31 15:28:28 -0700172 lp.height = getResources().getDimensionPixelSize(
shawnlinbd6d0ad2020-01-29 18:38:49 +0800173 R.dimen.status_bar_header_height_keyguard) + waterfallTop;
Selim Cinek6ebba592016-05-31 15:28:28 -0700174 setLayoutParams(lp);
Jorim Jaggie210cc82014-08-12 23:44:59 +0200175 }
176
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200177 private void loadDimens() {
Daniel Nishif79cd872016-06-27 11:44:01 -0700178 Resources res = getResources();
179 mSystemIconsSwitcherHiddenExpandedMargin = res.getDimensionPixelSize(
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200180 R.dimen.system_icons_switcher_hidden_expanded_margin);
Daniel Nishif79cd872016-06-27 11:44:01 -0700181 mSystemIconsBaseMargin = res.getDimensionPixelSize(
182 R.dimen.system_icons_super_container_avatarless_margin_end);
Evan Laird17a96ba2018-05-23 18:21:56 -0400183 mCutoutSideNudge = getResources().getDimensionPixelSize(
184 R.dimen.display_cutout_margin_consumption);
Evan Laird54ff81b2018-06-13 20:08:17 -0400185 mShowPercentAvailable = getContext().getResources().getBoolean(
186 com.android.internal.R.bool.config_battery_percentage_setting_available);
shawnlinbd6d0ad2020-01-29 18:38:49 +0800187 mRoundedCornerPadding = res.getDimensionPixelSize(
188 R.dimen.rounded_corner_content_padding);
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200189 }
190
191 private void updateVisibilities() {
Evan Laird264275e2018-03-01 19:39:39 -0500192 if (mMultiUserSwitch.getParent() != mStatusIconArea && !mKeyguardUserSwitcherShowing) {
Jorim Jaggi98f85302014-08-07 17:45:04 +0200193 if (mMultiUserSwitch.getParent() != null) {
194 getOverlay().remove(mMultiUserSwitch);
195 }
Evan Laird264275e2018-03-01 19:39:39 -0500196 mStatusIconArea.addView(mMultiUserSwitch, 0);
197 } else if (mMultiUserSwitch.getParent() == mStatusIconArea && mKeyguardUserSwitcherShowing) {
198 mStatusIconArea.removeView(mMultiUserSwitch);
Jorim Jaggi98f85302014-08-07 17:45:04 +0200199 }
Daniel Nishi8ba446c2016-06-20 18:56:35 -0700200 if (mKeyguardUserSwitcher == null) {
201 // If we have no keyguard switcher, the screen width is under 600dp. In this case,
Fabian Kozynski0f46c342019-03-25 13:23:38 -0400202 // we only show the multi-user switch if it's enabled through UserManager as well as
203 // by the user.
204 if (mMultiUserSwitch.isMultiUserEnabled()) {
Daniel Nishi8ba446c2016-06-20 18:56:35 -0700205 mMultiUserSwitch.setVisibility(View.VISIBLE);
206 } else {
207 mMultiUserSwitch.setVisibility(View.GONE);
208 }
209 }
Lucas Dupin07ed3df2019-03-26 21:23:59 -0700210 mBatteryView.setForceShowPercent(mBatteryCharging && mShowPercentAvailable);
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200211 }
212
213 private void updateSystemIconsLayoutParams() {
Evan Laird264275e2018-03-01 19:39:39 -0500214 LinearLayout.LayoutParams lp =
215 (LinearLayout.LayoutParams) mSystemIconsContainer.getLayoutParams();
Daniel Nishif79cd872016-06-27 11:44:01 -0700216 // If the avatar icon is gone, we need to have some end margin to display the system icons
217 // correctly.
218 int baseMarginEnd = mMultiUserSwitch.getVisibility() == View.GONE
219 ? mSystemIconsBaseMargin
220 : 0;
221 int marginEnd = mKeyguardUserSwitcherShowing ? mSystemIconsSwitcherHiddenExpandedMargin :
222 baseMarginEnd;
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200223 if (marginEnd != lp.getMarginEnd()) {
224 lp.setMarginEnd(marginEnd);
Evan Laird264275e2018-03-01 19:39:39 -0500225 mSystemIconsContainer.setLayoutParams(lp);
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200226 }
227 }
228
Evan Laird264275e2018-03-01 19:39:39 -0500229 @Override
Adrian Roosedfab3b2018-03-08 18:39:20 +0100230 public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Adrian Roos13836052018-03-15 21:06:37 +0100231 mLayoutState = LAYOUT_NONE;
Adrian Roosedfab3b2018-03-08 18:39:20 +0100232 if (updateLayoutConsideringCutout()) {
233 requestLayout();
234 }
235 return super.onApplyWindowInsets(insets);
236 }
237
238 private boolean updateLayoutConsideringCutout() {
shawnlinbd6d0ad2020-01-29 18:38:49 +0800239 mDisplayCutout = getRootWindowInsets().getDisplayCutout();
240 updateKeyguardStatusBarHeight();
241
Adrian Roos13836052018-03-15 21:06:37 +0100242 Pair<Integer, Integer> cornerCutoutMargins =
shawnlinbd6d0ad2020-01-29 18:38:49 +0800243 StatusBarWindowView.cornerCutoutMargins(mDisplayCutout, getDisplay());
244 updatePadding(cornerCutoutMargins);
245 if (mDisplayCutout == null || cornerCutoutMargins != null) {
Adrian Roosedfab3b2018-03-08 18:39:20 +0100246 return updateLayoutParamsNoCutout();
Evan Laird264275e2018-03-01 19:39:39 -0500247 } else {
shawnlinbd6d0ad2020-01-29 18:38:49 +0800248 return updateLayoutParamsForCutout();
Evan Laird264275e2018-03-01 19:39:39 -0500249 }
250 }
251
shawnlinbd6d0ad2020-01-29 18:38:49 +0800252 private void updatePadding(Pair<Integer, Integer> cornerCutoutMargins) {
253 final int waterfallTop =
254 mDisplayCutout == null ? 0 : mDisplayCutout.getWaterfallInsets().top;
255 Pair<Integer, Integer> padding =
256 StatusBarWindowView.paddingNeededForCutoutAndRoundedCorner(
257 mDisplayCutout, cornerCutoutMargins, mRoundedCornerPadding);
258 setPadding(padding.first, waterfallTop, padding.second, 0);
Adrian Roos13836052018-03-15 21:06:37 +0100259 }
260
Adrian Roosedfab3b2018-03-08 18:39:20 +0100261 private boolean updateLayoutParamsNoCutout() {
Evan Laird264275e2018-03-01 19:39:39 -0500262 if (mLayoutState == LAYOUT_NO_CUTOUT) {
Adrian Roosedfab3b2018-03-08 18:39:20 +0100263 return false;
Evan Laird264275e2018-03-01 19:39:39 -0500264 }
265 mLayoutState = LAYOUT_NO_CUTOUT;
266
267 if (mCutoutSpace != null) {
268 mCutoutSpace.setVisibility(View.GONE);
269 }
270
271 RelativeLayout.LayoutParams lp = (LayoutParams) mCarrierLabel.getLayoutParams();
272 lp.addRule(RelativeLayout.START_OF, R.id.status_icon_area);
273
274 lp = (LayoutParams) mStatusIconArea.getLayoutParams();
275 lp.removeRule(RelativeLayout.RIGHT_OF);
276 lp.width = LayoutParams.WRAP_CONTENT;
277
278 LinearLayout.LayoutParams llp =
279 (LinearLayout.LayoutParams) mSystemIconsContainer.getLayoutParams();
280 llp.setMarginStart(getResources().getDimensionPixelSize(
281 R.dimen.system_icons_super_container_margin_start));
Adrian Roosedfab3b2018-03-08 18:39:20 +0100282 return true;
Evan Laird264275e2018-03-01 19:39:39 -0500283 }
284
shawnlinbd6d0ad2020-01-29 18:38:49 +0800285 private boolean updateLayoutParamsForCutout() {
Evan Laird264275e2018-03-01 19:39:39 -0500286 if (mLayoutState == LAYOUT_CUTOUT) {
Adrian Roosedfab3b2018-03-08 18:39:20 +0100287 return false;
Evan Laird264275e2018-03-01 19:39:39 -0500288 }
289 mLayoutState = LAYOUT_CUTOUT;
290
291 if (mCutoutSpace == null) {
292 updateLayoutParamsNoCutout();
293 }
294
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100295 Rect bounds = new Rect();
shawnlinbd6d0ad2020-01-29 18:38:49 +0800296 boundsFromDirection(mDisplayCutout, Gravity.TOP, bounds);
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100297
Evan Laird264275e2018-03-01 19:39:39 -0500298 mCutoutSpace.setVisibility(View.VISIBLE);
299 RelativeLayout.LayoutParams lp = (LayoutParams) mCutoutSpace.getLayoutParams();
Evan Laird17a96ba2018-05-23 18:21:56 -0400300 bounds.left = bounds.left + mCutoutSideNudge;
301 bounds.right = bounds.right - mCutoutSideNudge;
Adrian Roos6a4fa0e2018-03-05 19:50:16 +0100302 lp.width = bounds.width();
303 lp.height = bounds.height();
Evan Laird264275e2018-03-01 19:39:39 -0500304 lp.addRule(RelativeLayout.CENTER_IN_PARENT);
305
306 lp = (LayoutParams) mCarrierLabel.getLayoutParams();
307 lp.addRule(RelativeLayout.START_OF, R.id.cutout_space_view);
308
309 lp = (LayoutParams) mStatusIconArea.getLayoutParams();
310 lp.addRule(RelativeLayout.RIGHT_OF, R.id.cutout_space_view);
311 lp.width = LayoutParams.MATCH_PARENT;
312
313 LinearLayout.LayoutParams llp =
314 (LinearLayout.LayoutParams) mSystemIconsContainer.getLayoutParams();
315 llp.setMarginStart(0);
Adrian Roosedfab3b2018-03-08 18:39:20 +0100316 return true;
Evan Laird264275e2018-03-01 19:39:39 -0500317 }
318
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200319 public void setListening(boolean listening) {
320 if (listening == mBatteryListening) {
321 return;
322 }
323 mBatteryListening = listening;
324 if (mBatteryListening) {
Jason Monk88529052016-11-04 13:29:58 -0400325 mBatteryController.addCallback(this);
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200326 } else {
Jason Monk88529052016-11-04 13:29:58 -0400327 mBatteryController.removeCallback(this);
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200328 }
329 }
330
331 private void updateUserSwitcher() {
332 boolean keyguardSwitcherAvailable = mKeyguardUserSwitcher != null;
333 mMultiUserSwitch.setClickable(keyguardSwitcherAvailable);
334 mMultiUserSwitch.setFocusable(keyguardSwitcherAvailable);
335 mMultiUserSwitch.setKeyguardMode(keyguardSwitcherAvailable);
336 }
337
Jason Monk9c7844c2017-01-18 15:21:53 -0500338 @Override
339 protected void onAttachedToWindow() {
340 super.onAttachedToWindow();
341 UserInfoController userInfoController = Dependency.get(UserInfoController.class);
342 userInfoController.addCallback(this);
343 mUserSwitcherController = Dependency.get(UserSwitcherController.class);
344 mMultiUserSwitch.setUserSwitcherController(mUserSwitcherController);
345 userInfoController.reloadUserInfo();
Jason Monk9cac5ff2017-06-02 11:35:50 -0400346 Dependency.get(ConfigurationController.class).addCallback(this);
Dave Mankoffbcaca8a2019-10-31 18:04:08 -0400347 mIconManager = new TintedIconManager(findViewById(R.id.statusIcons),
348 Dependency.get(CommandQueue.class));
Jason Monk9cac5ff2017-06-02 11:35:50 -0400349 Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager);
Lucas Dupina39d5b22018-02-26 15:53:43 -0800350 onThemeChanged();
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200351 }
352
Jason Monk9c7844c2017-01-18 15:21:53 -0500353 @Override
354 protected void onDetachedFromWindow() {
355 super.onDetachedFromWindow();
356 Dependency.get(UserInfoController.class).removeCallback(this);
Jason Monk9cac5ff2017-06-02 11:35:50 -0400357 Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager);
358 Dependency.get(ConfigurationController.class).removeCallback(this);
Adrian Roosffc90972015-06-09 18:09:49 -0700359 }
360
Jason Monk9c7844c2017-01-18 15:21:53 -0500361 @Override
362 public void onUserInfoChanged(String name, Drawable picture, String userAccount) {
363 mMultiUserAvatar.setImageDrawable(picture);
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200364 }
365
Kaori Katouccf08d72015-05-26 16:25:04 +0900366 public void setQSPanel(QSPanel qsp) {
367 mMultiUserSwitch.setQsPanel(qsp);
368 }
369
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200370 @Override
371 public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
Dan Sandlerdf14c202017-02-21 14:51:11 -0500372 if (mBatteryCharging != charging) {
373 mBatteryCharging = charging;
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200374 updateVisibilities();
375 }
376 }
377
378 @Override
Jason Monkc06fbb12016-01-08 14:12:18 -0500379 public void onPowerSaveChanged(boolean isPowerSave) {
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200380 // could not care less
381 }
382
383 public void setKeyguardUserSwitcher(KeyguardUserSwitcher keyguardUserSwitcher) {
384 mKeyguardUserSwitcher = keyguardUserSwitcher;
385 mMultiUserSwitch.setKeyguardUserSwitcher(keyguardUserSwitcher);
386 updateUserSwitcher();
387 }
388
Jorim Jaggi98f85302014-08-07 17:45:04 +0200389 public void setKeyguardUserSwitcherShowing(boolean showing, boolean animate) {
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200390 mKeyguardUserSwitcherShowing = showing;
Jorim Jaggi98f85302014-08-07 17:45:04 +0200391 if (animate) {
392 animateNextLayoutChange();
393 }
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200394 updateVisibilities();
Evan Laird264275e2018-03-01 19:39:39 -0500395 updateLayoutConsideringCutout();
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200396 updateSystemIconsLayoutParams();
397 }
398
Jorim Jaggi98f85302014-08-07 17:45:04 +0200399 private void animateNextLayoutChange() {
Evan Laird264275e2018-03-01 19:39:39 -0500400 final int systemIconsCurrentX = mSystemIconsContainer.getLeft();
401 final boolean userSwitcherVisible = mMultiUserSwitch.getParent() == mStatusIconArea;
Jorim Jaggi98f85302014-08-07 17:45:04 +0200402 getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
403 @Override
404 public boolean onPreDraw() {
405 getViewTreeObserver().removeOnPreDrawListener(this);
406 boolean userSwitcherHiding = userSwitcherVisible
Evan Laird264275e2018-03-01 19:39:39 -0500407 && mMultiUserSwitch.getParent() != mStatusIconArea;
408 mSystemIconsContainer.setX(systemIconsCurrentX);
409 mSystemIconsContainer.animate()
Jorim Jaggi98f85302014-08-07 17:45:04 +0200410 .translationX(0)
411 .setDuration(400)
412 .setStartDelay(userSwitcherHiding ? 300 : 0)
Selim Cinekc18010f2016-01-20 13:41:30 -0800413 .setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
Jorim Jaggi98f85302014-08-07 17:45:04 +0200414 .start();
415 if (userSwitcherHiding) {
416 getOverlay().add(mMultiUserSwitch);
417 mMultiUserSwitch.animate()
418 .alpha(0f)
419 .setDuration(300)
420 .setStartDelay(0)
Selim Cinekc18010f2016-01-20 13:41:30 -0800421 .setInterpolator(Interpolators.ALPHA_OUT)
Lucas Dupina39d5b22018-02-26 15:53:43 -0800422 .withEndAction(() -> {
423 mMultiUserSwitch.setAlpha(1f);
424 getOverlay().remove(mMultiUserSwitch);
Jorim Jaggi98f85302014-08-07 17:45:04 +0200425 })
426 .start();
427
428 } else {
429 mMultiUserSwitch.setAlpha(0f);
430 mMultiUserSwitch.animate()
431 .alpha(1f)
432 .setDuration(300)
433 .setStartDelay(200)
Selim Cinekc18010f2016-01-20 13:41:30 -0800434 .setInterpolator(Interpolators.ALPHA_IN);
Jorim Jaggi98f85302014-08-07 17:45:04 +0200435 }
436 return true;
437 }
438 });
439
440 }
441
442 @Override
443 public void setVisibility(int visibility) {
444 super.setVisibility(visibility);
445 if (visibility != View.VISIBLE) {
Evan Laird264275e2018-03-01 19:39:39 -0500446 mSystemIconsContainer.animate().cancel();
447 mSystemIconsContainer.setTranslationX(0);
Jorim Jaggi98f85302014-08-07 17:45:04 +0200448 mMultiUserSwitch.animate().cancel();
449 mMultiUserSwitch.setAlpha(1f);
Daniel Nishi8ba446c2016-06-20 18:56:35 -0700450 } else {
451 updateVisibilities();
Daniel Nishif79cd872016-06-27 11:44:01 -0700452 updateSystemIconsLayoutParams();
Jorim Jaggi98f85302014-08-07 17:45:04 +0200453 }
454 }
455
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200456 @Override
457 public boolean hasOverlappingRendering() {
458 return false;
459 }
Lucas Dupin987f1932017-05-13 21:02:52 -0700460
Lucas Dupin8c51ce22017-11-21 13:21:05 -0800461 public void onThemeChanged() {
Lucas Dupin7da4f262018-09-20 13:41:46 -0700462 mBatteryView.setColorsFromContext(mContext);
463 updateIconsAndTextColors();
464 // Reload user avatar
465 ((UserInfoControllerImpl) Dependency.get(UserInfoController.class))
466 .onDensityOrFontScaleChanged();
467 }
468
Fabian Kozynski648e5552018-12-18 16:37:08 -0500469 @Override
shawnlin13051582019-03-07 15:11:17 +0800470 public void onDensityOrFontScaleChanged() {
471 loadDimens();
472 }
473
474 @Override
Fabian Kozynski648e5552018-12-18 16:37:08 -0500475 public void onOverlayChanged() {
476 mCarrierLabel.setTextAppearance(
477 Utils.getThemeAttr(mContext, com.android.internal.R.attr.textAppearanceSmall));
478 onThemeChanged();
479 mBatteryView.updatePercentView();
480 }
481
Lucas Dupin7da4f262018-09-20 13:41:46 -0700482 private void updateIconsAndTextColors() {
Jason Changb4e879d2018-04-11 11:17:58 +0800483 @ColorInt int textColor = Utils.getColorAttrDefaultColor(mContext,
484 R.attr.wallpaperTextColor);
485 @ColorInt int iconColor = Utils.getColorStateListDefaultColor(mContext,
486 Color.luminance(textColor) < 0.5 ? R.color.dark_mode_icon_color_single_tone :
Lucas Dupin6ebc2182017-07-18 12:15:41 -0700487 R.color.light_mode_icon_color_single_tone);
Jason Monk9cac5ff2017-06-02 11:35:50 -0400488 float intensity = textColor == Color.WHITE ? 0 : 1;
Lucas Dupin6ebc2182017-07-18 12:15:41 -0700489 mCarrierLabel.setTextColor(iconColor);
Robert Snoebergerd717b842019-03-08 13:03:07 -0500490 if (mIconManager != null) {
491 mIconManager.setTint(iconColor);
492 }
Jason Monk9cac5ff2017-06-02 11:35:50 -0400493
Lucas Dupin07ed3df2019-03-26 21:23:59 -0700494 applyDarkness(R.id.battery, mEmptyRect, intensity, iconColor);
Lucas Dupin7da4f262018-09-20 13:41:46 -0700495 applyDarkness(R.id.clock, mEmptyRect, intensity, iconColor);
Jason Monk9cac5ff2017-06-02 11:35:50 -0400496 }
497
498 private void applyDarkness(int id, Rect tintArea, float intensity, int color) {
499 View v = findViewById(id);
500 if (v instanceof DarkReceiver) {
501 ((DarkReceiver) v).onDarkChanged(tintArea, intensity, color);
502 }
Lucas Dupin987f1932017-05-13 21:02:52 -0700503 }
Lucas Dupinc510d412018-06-12 13:08:23 -0700504
505 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
506 pw.println("KeyguardStatusBarView:");
507 pw.println(" mBatteryCharging: " + mBatteryCharging);
508 pw.println(" mKeyguardUserSwitcherShowing: " + mKeyguardUserSwitcherShowing);
509 pw.println(" mBatteryListening: " + mBatteryListening);
510 pw.println(" mLayoutState: " + mLayoutState);
511 if (mBatteryView != null) {
512 mBatteryView.dump(fd, pw, args);
513 }
514 }
Jorim Jaggi4538027d2014-07-30 15:43:13 +0200515}