Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 19 | import static com.android.systemui.ScreenDecorations.DisplayCutoutView.boundsFromDirection; |
| 20 | |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 21 | import android.annotation.ColorInt; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 22 | import android.content.Context; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 23 | import android.content.res.Configuration; |
Daniel Nishi | f79cd87 | 2016-06-27 11:44:01 -0700 | [diff] [blame] | 24 | import android.content.res.Resources; |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 25 | import android.graphics.Color; |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 26 | import android.graphics.Rect; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 27 | import android.graphics.drawable.Drawable; |
| 28 | import android.util.AttributeSet; |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 29 | import android.util.Pair; |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 30 | import android.util.TypedValue; |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 31 | import android.view.DisplayCutout; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 32 | import android.view.Gravity; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 33 | import android.view.View; |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 34 | import android.view.ViewGroup; |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 35 | import android.view.ViewTreeObserver; |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 36 | import android.view.WindowInsets; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 37 | import android.widget.ImageView; |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 38 | import android.widget.LinearLayout; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 39 | import android.widget.RelativeLayout; |
| 40 | import android.widget.TextView; |
| 41 | |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 42 | import com.android.settingslib.Utils; |
Dan Sandler | df14c20 | 2017-02-21 14:51:11 -0500 | [diff] [blame] | 43 | import com.android.systemui.BatteryMeterView; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 44 | import com.android.systemui.Dependency; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 45 | import com.android.systemui.Interpolators; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 46 | import com.android.systemui.R; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 47 | import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; |
Kaori Katou | ccf08d7 | 2015-05-26 16:25:04 +0900 | [diff] [blame] | 48 | import com.android.systemui.qs.QSPanel; |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 49 | import com.android.systemui.statusbar.CommandQueue; |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 50 | import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 51 | import com.android.systemui.statusbar.policy.BatteryController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 52 | import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback; |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 53 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 54 | import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 55 | import com.android.systemui.statusbar.policy.KeyguardUserSwitcher; |
| 56 | import com.android.systemui.statusbar.policy.UserInfoController; |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 57 | import com.android.systemui.statusbar.policy.UserInfoController.OnUserInfoChangedListener; |
Lucas Dupin | 542aebc | 2017-08-04 11:24:06 -0700 | [diff] [blame] | 58 | import com.android.systemui.statusbar.policy.UserInfoControllerImpl; |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 59 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 60 | |
Lucas Dupin | c510d41 | 2018-06-12 13:08:23 -0700 | [diff] [blame] | 61 | import java.io.FileDescriptor; |
| 62 | import java.io.PrintWriter; |
| 63 | |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 64 | /** |
| 65 | * The header group on Keyguard. |
| 66 | */ |
| 67 | public class KeyguardStatusBarView extends RelativeLayout |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 68 | implements BatteryStateChangeCallback, OnUserInfoChangedListener, ConfigurationListener { |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 69 | |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 70 | 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 Dupin | 7da4f26 | 2018-09-20 13:41:46 -0700 | [diff] [blame] | 74 | private final Rect mEmptyRect = new Rect(0, 0, 0, 0); |
| 75 | |
Evan Laird | 54ff81b | 2018-06-13 20:08:17 -0400 | [diff] [blame] | 76 | private boolean mShowPercentAvailable; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 77 | private boolean mBatteryCharging; |
| 78 | private boolean mKeyguardUserSwitcherShowing; |
| 79 | private boolean mBatteryListening; |
| 80 | |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 81 | private TextView mCarrierLabel; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 82 | private MultiUserSwitch mMultiUserSwitch; |
| 83 | private ImageView mMultiUserAvatar; |
Dan Sandler | df14c20 | 2017-02-21 14:51:11 -0500 | [diff] [blame] | 84 | private BatteryMeterView mBatteryView; |
Lucas Dupin | 7da4f26 | 2018-09-20 13:41:46 -0700 | [diff] [blame] | 85 | private StatusIconContainer mStatusIconContainer; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 86 | |
| 87 | private BatteryController mBatteryController; |
| 88 | private KeyguardUserSwitcher mKeyguardUserSwitcher; |
Daniel Nishi | 8ba446c | 2016-06-20 18:56:35 -0700 | [diff] [blame] | 89 | private UserSwitcherController mUserSwitcherController; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 90 | |
| 91 | private int mSystemIconsSwitcherHiddenExpandedMargin; |
Daniel Nishi | f79cd87 | 2016-06-27 11:44:01 -0700 | [diff] [blame] | 92 | private int mSystemIconsBaseMargin; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 93 | private View mSystemIconsContainer; |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 94 | private TintedIconManager mIconManager; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 95 | |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 96 | private View mCutoutSpace; |
| 97 | private ViewGroup mStatusIconArea; |
| 98 | private int mLayoutState = LAYOUT_NONE; |
| 99 | |
Evan Laird | 17a96ba | 2018-05-23 18:21:56 -0400 | [diff] [blame] | 100 | /** |
| 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 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 105 | private DisplayCutout mDisplayCutout; |
| 106 | private int mRoundedCornerPadding = 0; |
| 107 | |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 108 | public KeyguardStatusBarView(Context context, AttributeSet attrs) { |
| 109 | super(context, attrs); |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | protected void onFinishInflate() { |
| 114 | super.onFinishInflate(); |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 115 | mSystemIconsContainer = findViewById(R.id.system_icons_container); |
Lucas Dupin | a39d5b2 | 2018-02-26 15:53:43 -0800 | [diff] [blame] | 116 | 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 Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 120 | mCutoutSpace = findViewById(R.id.cutout_space_view); |
| 121 | mStatusIconArea = findViewById(R.id.status_icon_area); |
Lucas Dupin | 7da4f26 | 2018-09-20 13:41:46 -0700 | [diff] [blame] | 122 | mStatusIconContainer = findViewById(R.id.statusIcons); |
Dan Sandler | df14c20 | 2017-02-21 14:51:11 -0500 | [diff] [blame] | 123 | |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 124 | loadDimens(); |
| 125 | updateUserSwitcher(); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 126 | mBatteryController = Dependency.get(BatteryController.class); |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 129 | @Override |
| 130 | protected void onConfigurationChanged(Configuration newConfig) { |
| 131 | super.onConfigurationChanged(newConfig); |
| 132 | |
Adrian Roos | d390b89 | 2016-05-05 10:50:49 -0400 | [diff] [blame] | 133 | 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 Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 137 | |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 138 | // Multi-user switch |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 139 | 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 Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 146 | // System icons |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 147 | lp = (MarginLayoutParams) mSystemIconsContainer.getLayoutParams(); |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 148 | lp.setMarginStart(getResources().getDimensionPixelSize( |
| 149 | R.dimen.system_icons_super_container_margin_start)); |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 150 | mSystemIconsContainer.setLayoutParams(lp); |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 151 | mSystemIconsContainer.setPaddingRelative(mSystemIconsContainer.getPaddingStart(), |
| 152 | mSystemIconsContainer.getPaddingTop(), |
| 153 | getResources().getDimensionPixelSize(R.dimen.system_icons_keyguard_padding_end), |
| 154 | mSystemIconsContainer.getPaddingBottom()); |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 155 | |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 156 | // 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 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 165 | updateKeyguardStatusBarHeight(); |
| 166 | } |
| 167 | |
| 168 | private void updateKeyguardStatusBarHeight() { |
| 169 | final int waterfallTop = |
| 170 | mDisplayCutout == null ? 0 : mDisplayCutout.getWaterfallInsets().top; |
| 171 | MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams(); |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 172 | lp.height = getResources().getDimensionPixelSize( |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 173 | R.dimen.status_bar_header_height_keyguard) + waterfallTop; |
Selim Cinek | 6ebba59 | 2016-05-31 15:28:28 -0700 | [diff] [blame] | 174 | setLayoutParams(lp); |
Jorim Jaggi | e210cc8 | 2014-08-12 23:44:59 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 177 | private void loadDimens() { |
Daniel Nishi | f79cd87 | 2016-06-27 11:44:01 -0700 | [diff] [blame] | 178 | Resources res = getResources(); |
| 179 | mSystemIconsSwitcherHiddenExpandedMargin = res.getDimensionPixelSize( |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 180 | R.dimen.system_icons_switcher_hidden_expanded_margin); |
Daniel Nishi | f79cd87 | 2016-06-27 11:44:01 -0700 | [diff] [blame] | 181 | mSystemIconsBaseMargin = res.getDimensionPixelSize( |
| 182 | R.dimen.system_icons_super_container_avatarless_margin_end); |
Evan Laird | 17a96ba | 2018-05-23 18:21:56 -0400 | [diff] [blame] | 183 | mCutoutSideNudge = getResources().getDimensionPixelSize( |
| 184 | R.dimen.display_cutout_margin_consumption); |
Evan Laird | 54ff81b | 2018-06-13 20:08:17 -0400 | [diff] [blame] | 185 | mShowPercentAvailable = getContext().getResources().getBoolean( |
| 186 | com.android.internal.R.bool.config_battery_percentage_setting_available); |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 187 | mRoundedCornerPadding = res.getDimensionPixelSize( |
| 188 | R.dimen.rounded_corner_content_padding); |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | private void updateVisibilities() { |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 192 | if (mMultiUserSwitch.getParent() != mStatusIconArea && !mKeyguardUserSwitcherShowing) { |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 193 | if (mMultiUserSwitch.getParent() != null) { |
| 194 | getOverlay().remove(mMultiUserSwitch); |
| 195 | } |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 196 | mStatusIconArea.addView(mMultiUserSwitch, 0); |
| 197 | } else if (mMultiUserSwitch.getParent() == mStatusIconArea && mKeyguardUserSwitcherShowing) { |
| 198 | mStatusIconArea.removeView(mMultiUserSwitch); |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 199 | } |
Daniel Nishi | 8ba446c | 2016-06-20 18:56:35 -0700 | [diff] [blame] | 200 | if (mKeyguardUserSwitcher == null) { |
| 201 | // If we have no keyguard switcher, the screen width is under 600dp. In this case, |
Fabian Kozynski | 0f46c34 | 2019-03-25 13:23:38 -0400 | [diff] [blame] | 202 | // 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 Nishi | 8ba446c | 2016-06-20 18:56:35 -0700 | [diff] [blame] | 205 | mMultiUserSwitch.setVisibility(View.VISIBLE); |
| 206 | } else { |
| 207 | mMultiUserSwitch.setVisibility(View.GONE); |
| 208 | } |
| 209 | } |
Lucas Dupin | 07ed3df | 2019-03-26 21:23:59 -0700 | [diff] [blame] | 210 | mBatteryView.setForceShowPercent(mBatteryCharging && mShowPercentAvailable); |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | private void updateSystemIconsLayoutParams() { |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 214 | LinearLayout.LayoutParams lp = |
| 215 | (LinearLayout.LayoutParams) mSystemIconsContainer.getLayoutParams(); |
Daniel Nishi | f79cd87 | 2016-06-27 11:44:01 -0700 | [diff] [blame] | 216 | // 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 Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 223 | if (marginEnd != lp.getMarginEnd()) { |
| 224 | lp.setMarginEnd(marginEnd); |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 225 | mSystemIconsContainer.setLayoutParams(lp); |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 229 | @Override |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 230 | public WindowInsets onApplyWindowInsets(WindowInsets insets) { |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 231 | mLayoutState = LAYOUT_NONE; |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 232 | if (updateLayoutConsideringCutout()) { |
| 233 | requestLayout(); |
| 234 | } |
| 235 | return super.onApplyWindowInsets(insets); |
| 236 | } |
| 237 | |
| 238 | private boolean updateLayoutConsideringCutout() { |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 239 | mDisplayCutout = getRootWindowInsets().getDisplayCutout(); |
| 240 | updateKeyguardStatusBarHeight(); |
| 241 | |
Adrian Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 242 | Pair<Integer, Integer> cornerCutoutMargins = |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 243 | StatusBarWindowView.cornerCutoutMargins(mDisplayCutout, getDisplay()); |
| 244 | updatePadding(cornerCutoutMargins); |
| 245 | if (mDisplayCutout == null || cornerCutoutMargins != null) { |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 246 | return updateLayoutParamsNoCutout(); |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 247 | } else { |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 248 | return updateLayoutParamsForCutout(); |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 252 | 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 Roos | 1383605 | 2018-03-15 21:06:37 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 261 | private boolean updateLayoutParamsNoCutout() { |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 262 | if (mLayoutState == LAYOUT_NO_CUTOUT) { |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 263 | return false; |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 264 | } |
| 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 Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 282 | return true; |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 283 | } |
| 284 | |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 285 | private boolean updateLayoutParamsForCutout() { |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 286 | if (mLayoutState == LAYOUT_CUTOUT) { |
Adrian Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 287 | return false; |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 288 | } |
| 289 | mLayoutState = LAYOUT_CUTOUT; |
| 290 | |
| 291 | if (mCutoutSpace == null) { |
| 292 | updateLayoutParamsNoCutout(); |
| 293 | } |
| 294 | |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 295 | Rect bounds = new Rect(); |
shawnlin | bd6d0ad | 2020-01-29 18:38:49 +0800 | [diff] [blame] | 296 | boundsFromDirection(mDisplayCutout, Gravity.TOP, bounds); |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 297 | |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 298 | mCutoutSpace.setVisibility(View.VISIBLE); |
| 299 | RelativeLayout.LayoutParams lp = (LayoutParams) mCutoutSpace.getLayoutParams(); |
Evan Laird | 17a96ba | 2018-05-23 18:21:56 -0400 | [diff] [blame] | 300 | bounds.left = bounds.left + mCutoutSideNudge; |
| 301 | bounds.right = bounds.right - mCutoutSideNudge; |
Adrian Roos | 6a4fa0e | 2018-03-05 19:50:16 +0100 | [diff] [blame] | 302 | lp.width = bounds.width(); |
| 303 | lp.height = bounds.height(); |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 304 | 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 Roos | edfab3b | 2018-03-08 18:39:20 +0100 | [diff] [blame] | 316 | return true; |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 317 | } |
| 318 | |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 319 | public void setListening(boolean listening) { |
| 320 | if (listening == mBatteryListening) { |
| 321 | return; |
| 322 | } |
| 323 | mBatteryListening = listening; |
| 324 | if (mBatteryListening) { |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 325 | mBatteryController.addCallback(this); |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 326 | } else { |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 327 | mBatteryController.removeCallback(this); |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 328 | } |
| 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 Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 338 | @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 Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 346 | Dependency.get(ConfigurationController.class).addCallback(this); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 347 | mIconManager = new TintedIconManager(findViewById(R.id.statusIcons), |
| 348 | Dependency.get(CommandQueue.class)); |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 349 | Dependency.get(StatusBarIconController.class).addIconGroup(mIconManager); |
Lucas Dupin | a39d5b2 | 2018-02-26 15:53:43 -0800 | [diff] [blame] | 350 | onThemeChanged(); |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 353 | @Override |
| 354 | protected void onDetachedFromWindow() { |
| 355 | super.onDetachedFromWindow(); |
| 356 | Dependency.get(UserInfoController.class).removeCallback(this); |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 357 | Dependency.get(StatusBarIconController.class).removeIconGroup(mIconManager); |
| 358 | Dependency.get(ConfigurationController.class).removeCallback(this); |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 361 | @Override |
| 362 | public void onUserInfoChanged(String name, Drawable picture, String userAccount) { |
| 363 | mMultiUserAvatar.setImageDrawable(picture); |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 364 | } |
| 365 | |
Kaori Katou | ccf08d7 | 2015-05-26 16:25:04 +0900 | [diff] [blame] | 366 | public void setQSPanel(QSPanel qsp) { |
| 367 | mMultiUserSwitch.setQsPanel(qsp); |
| 368 | } |
| 369 | |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 370 | @Override |
| 371 | public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { |
Dan Sandler | df14c20 | 2017-02-21 14:51:11 -0500 | [diff] [blame] | 372 | if (mBatteryCharging != charging) { |
| 373 | mBatteryCharging = charging; |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 374 | updateVisibilities(); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | @Override |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 379 | public void onPowerSaveChanged(boolean isPowerSave) { |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 380 | // could not care less |
| 381 | } |
| 382 | |
| 383 | public void setKeyguardUserSwitcher(KeyguardUserSwitcher keyguardUserSwitcher) { |
| 384 | mKeyguardUserSwitcher = keyguardUserSwitcher; |
| 385 | mMultiUserSwitch.setKeyguardUserSwitcher(keyguardUserSwitcher); |
| 386 | updateUserSwitcher(); |
| 387 | } |
| 388 | |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 389 | public void setKeyguardUserSwitcherShowing(boolean showing, boolean animate) { |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 390 | mKeyguardUserSwitcherShowing = showing; |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 391 | if (animate) { |
| 392 | animateNextLayoutChange(); |
| 393 | } |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 394 | updateVisibilities(); |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 395 | updateLayoutConsideringCutout(); |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 396 | updateSystemIconsLayoutParams(); |
| 397 | } |
| 398 | |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 399 | private void animateNextLayoutChange() { |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 400 | final int systemIconsCurrentX = mSystemIconsContainer.getLeft(); |
| 401 | final boolean userSwitcherVisible = mMultiUserSwitch.getParent() == mStatusIconArea; |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 402 | getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { |
| 403 | @Override |
| 404 | public boolean onPreDraw() { |
| 405 | getViewTreeObserver().removeOnPreDrawListener(this); |
| 406 | boolean userSwitcherHiding = userSwitcherVisible |
Evan Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 407 | && mMultiUserSwitch.getParent() != mStatusIconArea; |
| 408 | mSystemIconsContainer.setX(systemIconsCurrentX); |
| 409 | mSystemIconsContainer.animate() |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 410 | .translationX(0) |
| 411 | .setDuration(400) |
| 412 | .setStartDelay(userSwitcherHiding ? 300 : 0) |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 413 | .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 414 | .start(); |
| 415 | if (userSwitcherHiding) { |
| 416 | getOverlay().add(mMultiUserSwitch); |
| 417 | mMultiUserSwitch.animate() |
| 418 | .alpha(0f) |
| 419 | .setDuration(300) |
| 420 | .setStartDelay(0) |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 421 | .setInterpolator(Interpolators.ALPHA_OUT) |
Lucas Dupin | a39d5b2 | 2018-02-26 15:53:43 -0800 | [diff] [blame] | 422 | .withEndAction(() -> { |
| 423 | mMultiUserSwitch.setAlpha(1f); |
| 424 | getOverlay().remove(mMultiUserSwitch); |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 425 | }) |
| 426 | .start(); |
| 427 | |
| 428 | } else { |
| 429 | mMultiUserSwitch.setAlpha(0f); |
| 430 | mMultiUserSwitch.animate() |
| 431 | .alpha(1f) |
| 432 | .setDuration(300) |
| 433 | .setStartDelay(200) |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 434 | .setInterpolator(Interpolators.ALPHA_IN); |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 435 | } |
| 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 Laird | 264275e | 2018-03-01 19:39:39 -0500 | [diff] [blame] | 446 | mSystemIconsContainer.animate().cancel(); |
| 447 | mSystemIconsContainer.setTranslationX(0); |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 448 | mMultiUserSwitch.animate().cancel(); |
| 449 | mMultiUserSwitch.setAlpha(1f); |
Daniel Nishi | 8ba446c | 2016-06-20 18:56:35 -0700 | [diff] [blame] | 450 | } else { |
| 451 | updateVisibilities(); |
Daniel Nishi | f79cd87 | 2016-06-27 11:44:01 -0700 | [diff] [blame] | 452 | updateSystemIconsLayoutParams(); |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Jorim Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 456 | @Override |
| 457 | public boolean hasOverlappingRendering() { |
| 458 | return false; |
| 459 | } |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 460 | |
Lucas Dupin | 8c51ce2 | 2017-11-21 13:21:05 -0800 | [diff] [blame] | 461 | public void onThemeChanged() { |
Lucas Dupin | 7da4f26 | 2018-09-20 13:41:46 -0700 | [diff] [blame] | 462 | mBatteryView.setColorsFromContext(mContext); |
| 463 | updateIconsAndTextColors(); |
| 464 | // Reload user avatar |
| 465 | ((UserInfoControllerImpl) Dependency.get(UserInfoController.class)) |
| 466 | .onDensityOrFontScaleChanged(); |
| 467 | } |
| 468 | |
Fabian Kozynski | 648e555 | 2018-12-18 16:37:08 -0500 | [diff] [blame] | 469 | @Override |
shawnlin | 1305158 | 2019-03-07 15:11:17 +0800 | [diff] [blame] | 470 | public void onDensityOrFontScaleChanged() { |
| 471 | loadDimens(); |
| 472 | } |
| 473 | |
| 474 | @Override |
Fabian Kozynski | 648e555 | 2018-12-18 16:37:08 -0500 | [diff] [blame] | 475 | public void onOverlayChanged() { |
| 476 | mCarrierLabel.setTextAppearance( |
| 477 | Utils.getThemeAttr(mContext, com.android.internal.R.attr.textAppearanceSmall)); |
| 478 | onThemeChanged(); |
| 479 | mBatteryView.updatePercentView(); |
| 480 | } |
| 481 | |
Lucas Dupin | 7da4f26 | 2018-09-20 13:41:46 -0700 | [diff] [blame] | 482 | private void updateIconsAndTextColors() { |
Jason Chang | b4e879d | 2018-04-11 11:17:58 +0800 | [diff] [blame] | 483 | @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 Dupin | 6ebc218 | 2017-07-18 12:15:41 -0700 | [diff] [blame] | 487 | R.color.light_mode_icon_color_single_tone); |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 488 | float intensity = textColor == Color.WHITE ? 0 : 1; |
Lucas Dupin | 6ebc218 | 2017-07-18 12:15:41 -0700 | [diff] [blame] | 489 | mCarrierLabel.setTextColor(iconColor); |
Robert Snoeberger | d717b84 | 2019-03-08 13:03:07 -0500 | [diff] [blame] | 490 | if (mIconManager != null) { |
| 491 | mIconManager.setTint(iconColor); |
| 492 | } |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 493 | |
Lucas Dupin | 07ed3df | 2019-03-26 21:23:59 -0700 | [diff] [blame] | 494 | applyDarkness(R.id.battery, mEmptyRect, intensity, iconColor); |
Lucas Dupin | 7da4f26 | 2018-09-20 13:41:46 -0700 | [diff] [blame] | 495 | applyDarkness(R.id.clock, mEmptyRect, intensity, iconColor); |
Jason Monk | 9cac5ff | 2017-06-02 11:35:50 -0400 | [diff] [blame] | 496 | } |
| 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 Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 503 | } |
Lucas Dupin | c510d41 | 2018-06-12 13:08:23 -0700 | [diff] [blame] | 504 | |
| 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 Jaggi | 4538027d | 2014-07-30 15:43:13 +0200 | [diff] [blame] | 515 | } |