Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | */ |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 16 | package com.android.systemui; |
| 17 | |
Charles He | 6a79b0d | 2017-09-18 09:50:58 +0100 | [diff] [blame] | 18 | import static android.app.StatusBarManager.DISABLE2_SYSTEM_ICONS; |
| 19 | import static android.app.StatusBarManager.DISABLE_NONE; |
Evan Laird | bcf631d | 2017-03-10 10:56:45 -0500 | [diff] [blame] | 20 | import static android.provider.Settings.System.SHOW_BATTERY_PERCENT; |
| 21 | |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 22 | import android.animation.ArgbEvaluator; |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 23 | import android.app.ActivityManager; |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 24 | import android.content.Context; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 25 | import android.content.res.Resources; |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 26 | import android.content.res.TypedArray; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 27 | import android.database.ContentObserver; |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 28 | import android.graphics.Rect; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 29 | import android.net.Uri; |
| 30 | import android.os.Handler; |
| 31 | import android.provider.Settings; |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 32 | import android.util.ArraySet; |
| 33 | import android.util.AttributeSet; |
| 34 | import android.util.TypedValue; |
| 35 | import android.view.ContextThemeWrapper; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 36 | import android.view.Gravity; |
| 37 | import android.view.LayoutInflater; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 38 | import android.view.View; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 39 | import android.view.ViewGroup; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 40 | import android.widget.ImageView; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 41 | import android.widget.LinearLayout; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 42 | import android.widget.TextView; |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 43 | |
| 44 | import com.android.settingslib.Utils; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 45 | import com.android.settingslib.graph.BatteryMeterDrawableBase; |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 46 | import com.android.systemui.settings.CurrentUserTracker; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 47 | import com.android.systemui.statusbar.phone.StatusBarIconController; |
Jorim Jaggi | 708f772 | 2014-08-20 17:30:38 +0200 | [diff] [blame] | 48 | import com.android.systemui.statusbar.policy.BatteryController; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 49 | import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback; |
| 50 | import com.android.systemui.statusbar.policy.ConfigurationController; |
| 51 | import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener; |
| 52 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
| 53 | import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; |
Jason Monk | f8c2f7b | 2017-09-06 09:22:29 -0400 | [diff] [blame] | 54 | import com.android.systemui.statusbar.policy.IconLogger; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 55 | import com.android.systemui.tuner.TunerService; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 56 | import com.android.systemui.tuner.TunerService.Tunable; |
Charles He | 6a79b0d | 2017-09-18 09:50:58 +0100 | [diff] [blame] | 57 | import com.android.systemui.util.Utils.DisableStateTracker; |
Jorim Jaggi | 708f772 | 2014-08-20 17:30:38 +0200 | [diff] [blame] | 58 | |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 59 | import java.text.NumberFormat; |
| 60 | |
| 61 | public class BatteryMeterView extends LinearLayout implements |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 62 | BatteryStateChangeCallback, Tunable, DarkReceiver, ConfigurationListener { |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 63 | |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 64 | private final BatteryMeterDrawableBase mDrawable; |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 65 | private final String mSlotBattery; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 66 | private final ImageView mBatteryIconView; |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 67 | private final CurrentUserTracker mUserTracker; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 68 | private TextView mBatteryPercentView; |
| 69 | |
Jorim Jaggi | 708f772 | 2014-08-20 17:30:38 +0200 | [diff] [blame] | 70 | private BatteryController mBatteryController; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 71 | private SettingObserver mSettingObserver; |
| 72 | private int mTextColor; |
| 73 | private int mLevel; |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 74 | private boolean mForceShowPercent; |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 75 | |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 76 | private int mDarkModeBackgroundColor; |
| 77 | private int mDarkModeFillColor; |
| 78 | |
| 79 | private int mLightModeBackgroundColor; |
| 80 | private int mLightModeFillColor; |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 81 | private float mDarkIntensity; |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 82 | private int mUser; |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 83 | |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 84 | public BatteryMeterView(Context context) { |
| 85 | this(context, null, 0); |
| 86 | } |
| 87 | |
| 88 | public BatteryMeterView(Context context, AttributeSet attrs) { |
| 89 | this(context, attrs, 0); |
| 90 | } |
| 91 | |
| 92 | public BatteryMeterView(Context context, AttributeSet attrs, int defStyle) { |
| 93 | super(context, attrs, defStyle); |
| 94 | |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 95 | setOrientation(LinearLayout.HORIZONTAL); |
| 96 | setGravity(Gravity.CENTER_VERTICAL | Gravity.START); |
| 97 | |
John Spurlock | 29786fc | 2014-02-04 17:55:47 -0500 | [diff] [blame] | 98 | TypedArray atts = context.obtainStyledAttributes(attrs, R.styleable.BatteryMeterView, |
| 99 | defStyle, 0); |
| 100 | final int frameColor = atts.getColor(R.styleable.BatteryMeterView_frameColor, |
Daniel Nishi | 8af93cb | 2017-05-15 14:37:20 -0700 | [diff] [blame] | 101 | context.getColor(R.color.meter_background_color)); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 102 | mDrawable = new BatteryMeterDrawableBase(context, frameColor); |
John Spurlock | 29786fc | 2014-02-04 17:55:47 -0500 | [diff] [blame] | 103 | atts.recycle(); |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 104 | |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 105 | mSettingObserver = new SettingObserver(new Handler(context.getMainLooper())); |
| 106 | |
Charles He | 6a79b0d | 2017-09-18 09:50:58 +0100 | [diff] [blame] | 107 | addOnAttachStateChangeListener( |
| 108 | new DisableStateTracker(DISABLE_NONE, DISABLE2_SYSTEM_ICONS)); |
| 109 | |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 110 | mSlotBattery = context.getString( |
| 111 | com.android.internal.R.string.status_bar_battery); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 112 | mBatteryIconView = new ImageView(context); |
| 113 | mBatteryIconView.setImageDrawable(mDrawable); |
| 114 | final MarginLayoutParams mlp = new MarginLayoutParams( |
| 115 | getResources().getDimensionPixelSize(R.dimen.status_bar_battery_icon_width), |
| 116 | getResources().getDimensionPixelSize(R.dimen.status_bar_battery_icon_height)); |
| 117 | mlp.setMargins(0, 0, 0, |
| 118 | getResources().getDimensionPixelOffset(R.dimen.battery_margin_bottom)); |
| 119 | addView(mBatteryIconView, mlp); |
| 120 | |
| 121 | updateShowPercent(); |
Evan Laird | ef160f2 | 2018-01-29 14:08:45 -0500 | [diff] [blame] | 122 | setColorsFromContext(context); |
Jason Monk | d866b8a | 2017-03-29 15:30:44 -0400 | [diff] [blame] | 123 | // Init to not dark at all. |
| 124 | onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT); |
Evan Laird | ef160f2 | 2018-01-29 14:08:45 -0500 | [diff] [blame] | 125 | |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 126 | mUserTracker = new CurrentUserTracker(mContext) { |
| 127 | @Override |
| 128 | public void onUserSwitched(int newUserId) { |
| 129 | mUser = newUserId; |
| 130 | getContext().getContentResolver().unregisterContentObserver(mSettingObserver); |
| 131 | getContext().getContentResolver().registerContentObserver( |
| 132 | Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver, |
| 133 | newUserId); |
| 134 | } |
| 135 | }; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 136 | } |
| 137 | |
Dan Sandler | df14c20 | 2017-02-21 14:51:11 -0500 | [diff] [blame] | 138 | public void setForceShowPercent(boolean show) { |
| 139 | mForceShowPercent = show; |
Jason Monk | f13413e | 2017-02-15 15:49:32 -0500 | [diff] [blame] | 140 | updateShowPercent(); |
| 141 | } |
| 142 | |
Evan Laird | ef160f2 | 2018-01-29 14:08:45 -0500 | [diff] [blame] | 143 | public void setColorsFromContext(Context context) { |
| 144 | if (context == null) { |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | Context dualToneDarkTheme = new ContextThemeWrapper(context, |
| 149 | Utils.getThemeAttr(context, R.attr.darkIconTheme)); |
| 150 | Context dualToneLightTheme = new ContextThemeWrapper(context, |
| 151 | Utils.getThemeAttr(context, R.attr.lightIconTheme)); |
| 152 | mDarkModeBackgroundColor = Utils.getColorAttr(dualToneDarkTheme, R.attr.backgroundColor); |
| 153 | mDarkModeFillColor = Utils.getColorAttr(dualToneDarkTheme, R.attr.fillColor); |
| 154 | mLightModeBackgroundColor = Utils.getColorAttr(dualToneLightTheme, R.attr.backgroundColor); |
| 155 | mLightModeFillColor = Utils.getColorAttr(dualToneLightTheme, R.attr.fillColor); |
| 156 | } |
| 157 | |
Jorim Jaggi | 0d26689 | 2014-07-28 14:49:13 +0200 | [diff] [blame] | 158 | @Override |
| 159 | public boolean hasOverlappingRendering() { |
| 160 | return false; |
| 161 | } |
| 162 | |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 163 | @Override |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 164 | public void onTuningChanged(String key, String newValue) { |
| 165 | if (StatusBarIconController.ICON_BLACKLIST.equals(key)) { |
| 166 | ArraySet<String> icons = StatusBarIconController.getIconBlacklist(newValue); |
Jason Monk | f8c2f7b | 2017-09-06 09:22:29 -0400 | [diff] [blame] | 167 | boolean hidden = icons.contains(mSlotBattery); |
| 168 | Dependency.get(IconLogger.class).onIconVisibility(mSlotBattery, !hidden); |
| 169 | setVisibility(hidden ? View.GONE : View.VISIBLE); |
Jason Monk | 3e18987 | 2016-01-12 09:10:34 -0500 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
| 173 | @Override |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 174 | public void onAttachedToWindow() { |
| 175 | super.onAttachedToWindow(); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 176 | mBatteryController = Dependency.get(BatteryController.class); |
Jason Monk | 9c7844c | 2017-01-18 15:21:53 -0500 | [diff] [blame] | 177 | mBatteryController.addCallback(this); |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 178 | mUser = ActivityManager.getCurrentUser(); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 179 | getContext().getContentResolver().registerContentObserver( |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 180 | Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mSettingObserver, mUser); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 181 | updateShowPercent(); |
Rohan Shah | 8a0d3fc | 2018-03-29 18:28:07 +0000 | [diff] [blame] | 182 | Dependency.get(TunerService.class).addTunable(this, StatusBarIconController.ICON_BLACKLIST); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 183 | Dependency.get(ConfigurationController.class).addCallback(this); |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 184 | mUserTracker.startTracking(); |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 185 | } |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 186 | |
| 187 | @Override |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 188 | public void onDetachedFromWindow() { |
| 189 | super.onDetachedFromWindow(); |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 190 | mUserTracker.stopTracking(); |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 191 | mBatteryController.removeCallback(this); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 192 | getContext().getContentResolver().unregisterContentObserver(mSettingObserver); |
Jason Monk | de850bb | 2017-02-01 19:26:30 -0500 | [diff] [blame] | 193 | Dependency.get(TunerService.class).removeTunable(this); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 194 | Dependency.get(ConfigurationController.class).removeCallback(this); |
John Spurlock | 3c87566 | 2013-08-31 15:07:25 -0400 | [diff] [blame] | 195 | } |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 196 | |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 197 | @Override |
| 198 | public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 199 | mDrawable.setBatteryLevel(level); |
jackqdyulei | ff5bd94 | 2017-04-04 10:54:21 -0700 | [diff] [blame] | 200 | mDrawable.setCharging(pluggedIn); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 201 | mLevel = level; |
| 202 | updatePercentText(); |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 203 | setContentDescription( |
Adrian Roos | 70dcf83 | 2016-04-20 15:51:42 -0700 | [diff] [blame] | 204 | getContext().getString(charging ? R.string.accessibility_battery_level_charging |
| 205 | : R.string.accessibility_battery_level, level)); |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 206 | } |
| 207 | |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 208 | @Override |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 209 | public void onPowerSaveChanged(boolean isPowerSave) { |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 210 | mDrawable.setPowerSave(isPowerSave); |
| 211 | } |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 212 | |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 213 | private TextView loadPercentView() { |
| 214 | return (TextView) LayoutInflater.from(getContext()) |
| 215 | .inflate(R.layout.battery_percentage_view, null); |
| 216 | } |
| 217 | |
| 218 | private void updatePercentText() { |
| 219 | if (mBatteryPercentView != null) { |
| 220 | mBatteryPercentView.setText( |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 221 | NumberFormat.getPercentInstance().format(mLevel / 100f)); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | private void updateShowPercent() { |
| 226 | final boolean showing = mBatteryPercentView != null; |
Jason Monk | a6f1db3a | 2017-08-30 19:18:00 -0400 | [diff] [blame] | 227 | if (0 != Settings.System.getIntForUser(getContext().getContentResolver(), |
| 228 | SHOW_BATTERY_PERCENT, 0, mUser) || mForceShowPercent) { |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 229 | if (!showing) { |
| 230 | mBatteryPercentView = loadPercentView(); |
| 231 | if (mTextColor != 0) mBatteryPercentView.setTextColor(mTextColor); |
| 232 | updatePercentText(); |
| 233 | addView(mBatteryPercentView, |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 234 | new ViewGroup.LayoutParams( |
| 235 | LayoutParams.WRAP_CONTENT, |
| 236 | LayoutParams.MATCH_PARENT)); |
| 237 | } |
| 238 | } else { |
| 239 | if (showing) { |
| 240 | removeView(mBatteryPercentView); |
| 241 | mBatteryPercentView = null; |
| 242 | } |
| 243 | } |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 246 | @Override |
| 247 | public void onDensityOrFontScaleChanged() { |
| 248 | scaleBatteryMeterViews(); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Looks up the scale factor for status bar icons and scales the battery view by that amount. |
| 253 | */ |
| 254 | private void scaleBatteryMeterViews() { |
| 255 | Resources res = getContext().getResources(); |
| 256 | TypedValue typedValue = new TypedValue(); |
| 257 | |
| 258 | res.getValue(R.dimen.status_bar_icon_scale_factor, typedValue, true); |
| 259 | float iconScaleFactor = typedValue.getFloat(); |
| 260 | |
| 261 | int batteryHeight = res.getDimensionPixelSize(R.dimen.status_bar_battery_icon_height); |
| 262 | int batteryWidth = res.getDimensionPixelSize(R.dimen.status_bar_battery_icon_width); |
| 263 | int marginBottom = res.getDimensionPixelSize(R.dimen.battery_margin_bottom); |
| 264 | |
| 265 | LinearLayout.LayoutParams scaledLayoutParams = new LinearLayout.LayoutParams( |
| 266 | (int) (batteryWidth * iconScaleFactor), (int) (batteryHeight * iconScaleFactor)); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 267 | scaledLayoutParams.setMargins(0, 0, 0, marginBottom); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 268 | |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 269 | mBatteryIconView.setLayoutParams(scaledLayoutParams); |
Evan Laird | ecc93f2 | 2017-06-16 09:57:29 -0400 | [diff] [blame] | 270 | FontSizeUtils.updateFontSize(mBatteryPercentView, R.dimen.qs_time_expanded_size); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public void onDarkChanged(Rect area, float darkIntensity, int tint) { |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 275 | mDarkIntensity = darkIntensity; |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 276 | float intensity = DarkIconDispatcher.isInArea(area, this) ? darkIntensity : 0; |
Rohan Shah | 8a0d3fc | 2018-03-29 18:28:07 +0000 | [diff] [blame] | 277 | int foreground = getColorForDarkIntensity(intensity, mLightModeFillColor, |
| 278 | mDarkModeFillColor); |
| 279 | int background = getColorForDarkIntensity(intensity, mLightModeBackgroundColor, |
| 280 | mDarkModeBackgroundColor); |
| 281 | mDrawable.setColors(foreground, background); |
| 282 | setTextColor(foreground); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 283 | } |
| 284 | |
Rohan Shah | 8a0d3fc | 2018-03-29 18:28:07 +0000 | [diff] [blame] | 285 | public void setTextColor(int color) { |
| 286 | mTextColor = color; |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 287 | if (mBatteryPercentView != null) { |
Rohan Shah | 8a0d3fc | 2018-03-29 18:28:07 +0000 | [diff] [blame] | 288 | mBatteryPercentView.setTextColor(color); |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 289 | } |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 290 | } |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 291 | |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 292 | public void setFillColor(int color) { |
| 293 | if (mLightModeFillColor == color) { |
| 294 | return; |
| 295 | } |
| 296 | mLightModeFillColor = color; |
| 297 | onDarkChanged(new Rect(), mDarkIntensity, DarkIconDispatcher.DEFAULT_ICON_TINT); |
| 298 | } |
| 299 | |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 300 | private int getColorForDarkIntensity(float darkIntensity, int lightColor, int darkColor) { |
| 301 | return (int) ArgbEvaluator.getInstance().evaluate(darkIntensity, lightColor, darkColor); |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 302 | } |
Dan Sandler | 055bb61 | 2017-02-08 16:21:49 -0800 | [diff] [blame] | 303 | |
| 304 | private final class SettingObserver extends ContentObserver { |
| 305 | public SettingObserver(Handler handler) { |
| 306 | super(handler); |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void onChange(boolean selfChange, Uri uri) { |
| 311 | super.onChange(selfChange, uri); |
| 312 | updateShowPercent(); |
| 313 | } |
| 314 | } |
Daniel Sandler | dfaf3bd | 2013-04-12 01:39:02 -0400 | [diff] [blame] | 315 | } |