Loading packages/SystemUI/res/layout/quick_qs_status_icons.xml +0 −7 Original line number Diff line number Diff line Loading @@ -51,11 +51,4 @@ android:layout_width="wrap_content" android:paddingEnd="2dp" /> <TextView android:id="@+id/batteryRemainingText" android:textAppearance="@style/TextAppearance.QS.TileLabel" android:layout_height="match_parent" android:layout_width="wrap_content" android:gravity="center_vertical" /> </LinearLayout> packages/SystemUI/res/layout/quick_status_bar_header_system_icons.xml +0 −6 Original line number Diff line number Diff line Loading @@ -64,11 +64,5 @@ <include layout="@layout/ongoing_privacy_chip" /> <com.android.systemui.BatteryMeterView android:id="@+id/battery" android:layout_height="match_parent" android:layout_width="wrap_content" android:gravity="center_vertical|end" android:layout_gravity="center_vertical|end" /> </LinearLayout> </LinearLayout> packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +17 −4 Original line number Diff line number Diff line Loading @@ -69,11 +69,12 @@ public class BatteryMeterView extends LinearLayout implements @Retention(SOURCE) @IntDef({MODE_DEFAULT, MODE_ON, MODE_OFF}) @IntDef({MODE_DEFAULT, MODE_ON, MODE_OFF, MODE_ESTIMATE}) public @interface BatteryPercentMode {} public static final int MODE_DEFAULT = 0; public static final int MODE_ON = 1; public static final int MODE_OFF = 2; public static final int MODE_ESTIMATE = 3; private final BatteryMeterDrawableBase mDrawable; private final String mSlotBattery; Loading @@ -91,6 +92,7 @@ public class BatteryMeterView extends LinearLayout implements // Some places may need to show the battery conditionally, and not obey the tuner private boolean mIgnoreTunerUpdates; private boolean mIsSubscribedForTunerUpdates; private boolean mCharging; private int mDarkModeBackgroundColor; private int mDarkModeFillColor; Loading Loading @@ -303,6 +305,7 @@ public class BatteryMeterView extends LinearLayout implements public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { mDrawable.setBatteryLevel(level); mDrawable.setCharging(pluggedIn); mCharging = pluggedIn; mLevel = level; updatePercentText(); setContentDescription( Loading Loading @@ -332,11 +335,21 @@ public class BatteryMeterView extends LinearLayout implements } private void updatePercentText() { if (mBatteryController == null) { return; } if (mBatteryPercentView != null) { if (mShowPercentMode == MODE_ESTIMATE && !mCharging) { mBatteryController.getEstimatedTimeRemainingString((String estimate) -> { mBatteryPercentView.setText(estimate); }); } else { mBatteryPercentView.setText( NumberFormat.getPercentInstance().format(mLevel / 100f)); } } } private void updateShowPercent() { final boolean showing = mBatteryPercentView != null; Loading @@ -345,7 +358,7 @@ public class BatteryMeterView extends LinearLayout implements SHOW_BATTERY_PERCENT, 0, mUser); if ((mShowPercentAvailable && systemSetting && mShowPercentMode != MODE_OFF) || mShowPercentMode == MODE_ON) { || mShowPercentMode == MODE_ON || mShowPercentMode == MODE_ESTIMATE) { if (!showing) { mBatteryPercentView = loadPercentView(); if (mTextColor != 0) mBatteryPercentView.setTextColor(mTextColor); Loading packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java +2 −49 Original line number Diff line number Diff line Loading @@ -141,14 +141,11 @@ public class QuickStatusBarHeader extends RelativeLayout implements private View mStatusSeparator; private ImageView mRingerModeIcon; private TextView mRingerModeTextView; private BatteryMeterView mBatteryMeterView; private Clock mClockView; private DateView mDateView; private OngoingPrivacyChip mPrivacyChip; private Space mSpace; private BatteryMeterView mBatteryRemainingIcon; private TextView mBatteryRemainingText; private boolean mShowBatteryPercentAndEstimate; private PrivacyItemController mPrivacyItemController; /** Counts how many times the long press tooltip has been shown to the user. */ Loading Loading @@ -229,13 +226,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements // Set the correct tint for the status icons so they contrast mIconManager.setTint(fillColor); mShowBatteryPercentAndEstimate = mContext.getResources().getBoolean( com.android.internal.R.bool.config_battery_percentage_setting_available); mBatteryMeterView = findViewById(R.id.battery); mBatteryMeterView.setPercentShowMode(mShowBatteryPercentAndEstimate ? BatteryMeterView.MODE_ON : BatteryMeterView.MODE_OFF); mBatteryMeterView.setOnClickListener(this); mClockView = findViewById(R.id.clock); mClockView.setOnClickListener(this); mDateView = findViewById(R.id.date); Loading @@ -245,13 +235,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements // Tint for the battery icons are handled in setupHost() mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon); mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_OFF); // Don't need to worry about tuner settings for this icon mBatteryRemainingIcon.setIgnoreTunerUpdates(true); mBatteryRemainingText = findViewById(R.id.batteryRemainingText); mBatteryRemainingText.setTextColor(fillColor); updateShowPercent(); } Loading @@ -268,10 +253,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements } private void setChipVisibility(boolean chipVisible) { mBatteryMeterView.setVisibility(View.VISIBLE); if (chipVisible) { mPrivacyChip.setVisibility(View.VISIBLE); if (mHasTopCutout) mBatteryMeterView.setVisibility(View.GONE); } else { mPrivacyChip.setVisibility(View.GONE); } Loading Loading @@ -339,7 +322,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements // Update color schemes in landscape to use wallpaperTextColor boolean shouldUseWallpaperTextColor = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE; mBatteryMeterView.useWallpaperTextColor(shouldUseWallpaperTextColor); mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor); } Loading Loading @@ -415,13 +397,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements .build(); } private void updateBatteryRemainingText() { if (!mShowBatteryPercentAndEstimate) { return; } mBatteryRemainingText.setText(mBatteryController.getEstimatedTimeRemainingString()); } public void setExpanded(boolean expanded) { if (mExpanded == expanded) return; mExpanded = expanded; Loading Loading @@ -519,7 +494,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements } } mSpace.setLayoutParams(lp); // Decide whether to show BatteryMeterView setChipVisibility(mPrivacyChip.getVisibility() == View.VISIBLE); return super.onApplyWindowInsets(insets); } Loading @@ -546,7 +520,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements mAlarmController.addCallback(this); mContext.registerReceiver(mRingerReceiver, new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)); updateBatteryRemainingText(); } else { mZenController.removeCallback(this); mAlarmController.removeCallback(this); Loading @@ -559,9 +532,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements if (v == mClockView) { mActivityStarter.postStartActivityDismissingKeyguard(new Intent( AlarmClock.ACTION_SHOW_ALARMS),0); } else if (v == mBatteryMeterView) { mActivityStarter.postStartActivityDismissingKeyguard(new Intent( Intent.ACTION_POWER_USAGE_SUMMARY),0); } else if (v == mPrivacyChip) { Handler mUiHandler = new Handler(Looper.getMainLooper()); mUiHandler.post(() -> { Loading Loading @@ -713,9 +683,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); mHeaderQsPanel.setHost(host, null /* No customization in header */); // Use SystemUI context to get battery meter colors, and let it use the default tint (white) mBatteryMeterView.setColorsFromContext(mHost.getContext()); mBatteryMeterView.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT); Rect tintArea = new Rect(0, 0, 0, 0); int colorForeground = Utils.getColorAttrDefaultColor(getContext(), Loading Loading @@ -763,22 +730,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements .getIntForUser(getContext().getContentResolver(), SHOW_BATTERY_PERCENT, 0, ActivityManager.getCurrentUser()); mShowBatteryPercentAndEstimate = systemSetting; updateBatteryViews(); } private void updateBatteryViews() { if (mShowBatteryPercentAndEstimate) { mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_ON); mBatteryRemainingIcon.setVisibility(View.VISIBLE); mBatteryRemainingText.setVisibility(View.VISIBLE); updateBatteryRemainingText(); } else { mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_OFF); mBatteryRemainingIcon.setVisibility(View.GONE); mBatteryRemainingText.setVisibility(View.GONE); } mBatteryRemainingIcon.setPercentShowMode(systemSetting ? BatteryMeterView.MODE_ESTIMATE : BatteryMeterView.MODE_ON); } private final class PercentSettingObserver extends ContentObserver { Loading packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java +25 −7 Original line number Diff line number Diff line Loading @@ -48,18 +48,36 @@ public interface BatteryController extends DemoMode, Dumpable, } /** * A listener that will be notified whenever a change in battery level or power save mode * has occurred. * A listener that will be notified whenever a change in battery level or power save mode has * occurred. */ interface BatteryStateChangeCallback { default void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {} default void onPowerSaveChanged(boolean isPowerSave) {} default void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { } default void onPowerSaveChanged(boolean isPowerSave) { } } /** * If available, get the estimated battery time remaining as a string. * * @param completion A lambda that will be called with the result of fetching the estimate. The * first time this method is called may need to be dispatched to a background thread. The * completion is called on the main thread */ default void getEstimatedTimeRemainingString(EstimateFetchCompletion completion) {} /** * Callback called when the estimated time remaining text is fetched. */ public interface EstimateFetchCompletion { /** * If available, get the estimated battery time remaining as a string * The callback * @param estimate the estimate */ default String getEstimatedTimeRemainingString() { return null; void onBatteryRemainingEstimateRetrieved(String estimate); } } Loading
packages/SystemUI/res/layout/quick_qs_status_icons.xml +0 −7 Original line number Diff line number Diff line Loading @@ -51,11 +51,4 @@ android:layout_width="wrap_content" android:paddingEnd="2dp" /> <TextView android:id="@+id/batteryRemainingText" android:textAppearance="@style/TextAppearance.QS.TileLabel" android:layout_height="match_parent" android:layout_width="wrap_content" android:gravity="center_vertical" /> </LinearLayout>
packages/SystemUI/res/layout/quick_status_bar_header_system_icons.xml +0 −6 Original line number Diff line number Diff line Loading @@ -64,11 +64,5 @@ <include layout="@layout/ongoing_privacy_chip" /> <com.android.systemui.BatteryMeterView android:id="@+id/battery" android:layout_height="match_parent" android:layout_width="wrap_content" android:gravity="center_vertical|end" android:layout_gravity="center_vertical|end" /> </LinearLayout> </LinearLayout>
packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +17 −4 Original line number Diff line number Diff line Loading @@ -69,11 +69,12 @@ public class BatteryMeterView extends LinearLayout implements @Retention(SOURCE) @IntDef({MODE_DEFAULT, MODE_ON, MODE_OFF}) @IntDef({MODE_DEFAULT, MODE_ON, MODE_OFF, MODE_ESTIMATE}) public @interface BatteryPercentMode {} public static final int MODE_DEFAULT = 0; public static final int MODE_ON = 1; public static final int MODE_OFF = 2; public static final int MODE_ESTIMATE = 3; private final BatteryMeterDrawableBase mDrawable; private final String mSlotBattery; Loading @@ -91,6 +92,7 @@ public class BatteryMeterView extends LinearLayout implements // Some places may need to show the battery conditionally, and not obey the tuner private boolean mIgnoreTunerUpdates; private boolean mIsSubscribedForTunerUpdates; private boolean mCharging; private int mDarkModeBackgroundColor; private int mDarkModeFillColor; Loading Loading @@ -303,6 +305,7 @@ public class BatteryMeterView extends LinearLayout implements public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { mDrawable.setBatteryLevel(level); mDrawable.setCharging(pluggedIn); mCharging = pluggedIn; mLevel = level; updatePercentText(); setContentDescription( Loading Loading @@ -332,11 +335,21 @@ public class BatteryMeterView extends LinearLayout implements } private void updatePercentText() { if (mBatteryController == null) { return; } if (mBatteryPercentView != null) { if (mShowPercentMode == MODE_ESTIMATE && !mCharging) { mBatteryController.getEstimatedTimeRemainingString((String estimate) -> { mBatteryPercentView.setText(estimate); }); } else { mBatteryPercentView.setText( NumberFormat.getPercentInstance().format(mLevel / 100f)); } } } private void updateShowPercent() { final boolean showing = mBatteryPercentView != null; Loading @@ -345,7 +358,7 @@ public class BatteryMeterView extends LinearLayout implements SHOW_BATTERY_PERCENT, 0, mUser); if ((mShowPercentAvailable && systemSetting && mShowPercentMode != MODE_OFF) || mShowPercentMode == MODE_ON) { || mShowPercentMode == MODE_ON || mShowPercentMode == MODE_ESTIMATE) { if (!showing) { mBatteryPercentView = loadPercentView(); if (mTextColor != 0) mBatteryPercentView.setTextColor(mTextColor); Loading
packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java +2 −49 Original line number Diff line number Diff line Loading @@ -141,14 +141,11 @@ public class QuickStatusBarHeader extends RelativeLayout implements private View mStatusSeparator; private ImageView mRingerModeIcon; private TextView mRingerModeTextView; private BatteryMeterView mBatteryMeterView; private Clock mClockView; private DateView mDateView; private OngoingPrivacyChip mPrivacyChip; private Space mSpace; private BatteryMeterView mBatteryRemainingIcon; private TextView mBatteryRemainingText; private boolean mShowBatteryPercentAndEstimate; private PrivacyItemController mPrivacyItemController; /** Counts how many times the long press tooltip has been shown to the user. */ Loading Loading @@ -229,13 +226,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements // Set the correct tint for the status icons so they contrast mIconManager.setTint(fillColor); mShowBatteryPercentAndEstimate = mContext.getResources().getBoolean( com.android.internal.R.bool.config_battery_percentage_setting_available); mBatteryMeterView = findViewById(R.id.battery); mBatteryMeterView.setPercentShowMode(mShowBatteryPercentAndEstimate ? BatteryMeterView.MODE_ON : BatteryMeterView.MODE_OFF); mBatteryMeterView.setOnClickListener(this); mClockView = findViewById(R.id.clock); mClockView.setOnClickListener(this); mDateView = findViewById(R.id.date); Loading @@ -245,13 +235,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements // Tint for the battery icons are handled in setupHost() mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon); mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_OFF); // Don't need to worry about tuner settings for this icon mBatteryRemainingIcon.setIgnoreTunerUpdates(true); mBatteryRemainingText = findViewById(R.id.batteryRemainingText); mBatteryRemainingText.setTextColor(fillColor); updateShowPercent(); } Loading @@ -268,10 +253,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements } private void setChipVisibility(boolean chipVisible) { mBatteryMeterView.setVisibility(View.VISIBLE); if (chipVisible) { mPrivacyChip.setVisibility(View.VISIBLE); if (mHasTopCutout) mBatteryMeterView.setVisibility(View.GONE); } else { mPrivacyChip.setVisibility(View.GONE); } Loading Loading @@ -339,7 +322,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements // Update color schemes in landscape to use wallpaperTextColor boolean shouldUseWallpaperTextColor = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE; mBatteryMeterView.useWallpaperTextColor(shouldUseWallpaperTextColor); mClockView.useWallpaperTextColor(shouldUseWallpaperTextColor); } Loading Loading @@ -415,13 +397,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements .build(); } private void updateBatteryRemainingText() { if (!mShowBatteryPercentAndEstimate) { return; } mBatteryRemainingText.setText(mBatteryController.getEstimatedTimeRemainingString()); } public void setExpanded(boolean expanded) { if (mExpanded == expanded) return; mExpanded = expanded; Loading Loading @@ -519,7 +494,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements } } mSpace.setLayoutParams(lp); // Decide whether to show BatteryMeterView setChipVisibility(mPrivacyChip.getVisibility() == View.VISIBLE); return super.onApplyWindowInsets(insets); } Loading @@ -546,7 +520,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements mAlarmController.addCallback(this); mContext.registerReceiver(mRingerReceiver, new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION)); updateBatteryRemainingText(); } else { mZenController.removeCallback(this); mAlarmController.removeCallback(this); Loading @@ -559,9 +532,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements if (v == mClockView) { mActivityStarter.postStartActivityDismissingKeyguard(new Intent( AlarmClock.ACTION_SHOW_ALARMS),0); } else if (v == mBatteryMeterView) { mActivityStarter.postStartActivityDismissingKeyguard(new Intent( Intent.ACTION_POWER_USAGE_SUMMARY),0); } else if (v == mPrivacyChip) { Handler mUiHandler = new Handler(Looper.getMainLooper()); mUiHandler.post(() -> { Loading Loading @@ -713,9 +683,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements mHeaderQsPanel.setQSPanelAndHeader(mQsPanel, this); mHeaderQsPanel.setHost(host, null /* No customization in header */); // Use SystemUI context to get battery meter colors, and let it use the default tint (white) mBatteryMeterView.setColorsFromContext(mHost.getContext()); mBatteryMeterView.onDarkChanged(new Rect(), 0, DarkIconDispatcher.DEFAULT_ICON_TINT); Rect tintArea = new Rect(0, 0, 0, 0); int colorForeground = Utils.getColorAttrDefaultColor(getContext(), Loading Loading @@ -763,22 +730,8 @@ public class QuickStatusBarHeader extends RelativeLayout implements .getIntForUser(getContext().getContentResolver(), SHOW_BATTERY_PERCENT, 0, ActivityManager.getCurrentUser()); mShowBatteryPercentAndEstimate = systemSetting; updateBatteryViews(); } private void updateBatteryViews() { if (mShowBatteryPercentAndEstimate) { mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_ON); mBatteryRemainingIcon.setVisibility(View.VISIBLE); mBatteryRemainingText.setVisibility(View.VISIBLE); updateBatteryRemainingText(); } else { mBatteryMeterView.setPercentShowMode(BatteryMeterView.MODE_OFF); mBatteryRemainingIcon.setVisibility(View.GONE); mBatteryRemainingText.setVisibility(View.GONE); } mBatteryRemainingIcon.setPercentShowMode(systemSetting ? BatteryMeterView.MODE_ESTIMATE : BatteryMeterView.MODE_ON); } private final class PercentSettingObserver extends ContentObserver { Loading
packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java +25 −7 Original line number Diff line number Diff line Loading @@ -48,18 +48,36 @@ public interface BatteryController extends DemoMode, Dumpable, } /** * A listener that will be notified whenever a change in battery level or power save mode * has occurred. * A listener that will be notified whenever a change in battery level or power save mode has * occurred. */ interface BatteryStateChangeCallback { default void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {} default void onPowerSaveChanged(boolean isPowerSave) {} default void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { } default void onPowerSaveChanged(boolean isPowerSave) { } } /** * If available, get the estimated battery time remaining as a string. * * @param completion A lambda that will be called with the result of fetching the estimate. The * first time this method is called may need to be dispatched to a background thread. The * completion is called on the main thread */ default void getEstimatedTimeRemainingString(EstimateFetchCompletion completion) {} /** * Callback called when the estimated time remaining text is fetched. */ public interface EstimateFetchCompletion { /** * If available, get the estimated battery time remaining as a string * The callback * @param estimate the estimate */ default String getEstimatedTimeRemainingString() { return null; void onBatteryRemainingEstimateRetrieved(String estimate); } }