Loading packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java +5 −12 Original line number Diff line number Diff line Loading @@ -195,19 +195,12 @@ public class PowerUtil { } private static String getRegularTimeRemainingShortString(Context context, long drainTimeMs) { // Get the time of day we think device will die rounded to the nearest 15 min. final long roundedTimeOfDayMs = roundTimeToNearestThreshold( System.currentTimeMillis() + drainTimeMs, FIFTEEN_MINUTES_MILLIS); // convert the time to a properly formatted string. String skeleton = android.text.format.DateFormat.getTimeFormatString(context); DateFormat fmt = DateFormat.getInstanceForSkeleton(skeleton); Date date = Date.from(Instant.ofEpochMilli(roundedTimeOfDayMs)); CharSequence timeString = fmt.format(date); // Get the time remaining rounded to the nearest 15 min final long roundedTimeMs = roundTimeToNearestThreshold(drainTimeMs, FIFTEEN_MINUTES_MILLIS); CharSequence timeString = StringUtil.formatElapsedTime(context, roundedTimeMs, false /* withSeconds */); return context.getString(R.string.power_discharge_by_only_short, timeString); return context.getString(R.string.power_remaining_duration_only_short, timeString); } public static long convertUsToMs(long timeUs) { Loading packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +11 −3 Original line number Diff line number Diff line Loading @@ -355,15 +355,23 @@ public class BatteryMeterView extends LinearLayout implements if (mBatteryPercentView != null) { if (mShowPercentMode == MODE_ESTIMATE && !mCharging) { mBatteryController.getEstimatedTimeRemainingString((String estimate) -> { if (estimate != null) { mBatteryPercentView.setText(estimate); } else { setPercentTextAtCurrentLevel(); } }); } else { mBatteryPercentView.setText( NumberFormat.getPercentInstance().format(mLevel / 100f)); setPercentTextAtCurrentLevel(); } } } private void setPercentTextAtCurrentLevel() { mBatteryPercentView.setText( NumberFormat.getPercentInstance().format(mLevel / 100f)); } private void updateShowPercent() { final boolean showing = mBatteryPercentView != null; final boolean systemSetting = 0 != Settings.System Loading packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java +4 −37 Original line number Diff line number Diff line Loading @@ -15,7 +15,6 @@ package com.android.systemui.qs; import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS; import static android.provider.Settings.System.SHOW_BATTERY_PERCENT; import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; Loading @@ -31,15 +30,12 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; import android.content.res.Resources; import android.database.ContentObserver; import android.graphics.Color; import android.graphics.Rect; import android.media.AudioManager; import android.net.Uri; import android.os.Handler; import android.os.Looper; import android.provider.AlarmClock; import android.provider.Settings; import android.service.notification.ZenModeConfig; import android.text.format.DateUtils; import android.util.AttributeSet; Loading Loading @@ -75,7 +71,6 @@ import com.android.systemui.statusbar.phone.StatusBarIconController; import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager; import com.android.systemui.statusbar.phone.StatusIconContainer; import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.Clock; import com.android.systemui.statusbar.policy.DateView; import com.android.systemui.statusbar.policy.NextAlarmController; Loading Loading @@ -107,7 +102,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements public static final int MAX_TOOLTIP_SHOWN_COUNT = 2; private final Handler mHandler = new Handler(); private final BatteryController mBatteryController; private final NextAlarmController mAlarmController; private final ZenModeController mZenController; private final StatusBarIconController mStatusBarIconController; Loading Loading @@ -162,9 +156,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements }; private boolean mHasTopCutout = false; private final PercentSettingObserver mPercentSettingObserver = new PercentSettingObserver(new Handler(mContext.getMainLooper())); /** * Runnable for automatically fading out the long press tooltip (as if it were animating away). */ Loading @@ -181,12 +172,11 @@ public class QuickStatusBarHeader extends RelativeLayout implements @Inject public QuickStatusBarHeader(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs, NextAlarmController nextAlarmController, ZenModeController zenModeController, BatteryController batteryController, StatusBarIconController statusBarIconController, StatusBarIconController statusBarIconController, ActivityStarter activityStarter, PrivacyItemController privacyItemController) { super(context, attrs); mAlarmController = nextAlarmController; mZenController = zenModeController; mBatteryController = batteryController; mStatusBarIconController = statusBarIconController; mActivityStarter = activityStarter; mPrivacyItemController = privacyItemController; Loading Loading @@ -241,7 +231,9 @@ public class QuickStatusBarHeader extends RelativeLayout implements mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon); // Don't need to worry about tuner settings for this icon mBatteryRemainingIcon.setIgnoreTunerUpdates(true); updateShowPercent(); // QS will always show the estimate, and BatteryMeterView handles the case where // it's unavailable or charging mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_ESTIMATE); } private List<String> getIgnoredIconSlots() { Loading Loading @@ -480,9 +472,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements super.onAttachedToWindow(); mStatusBarIconController.addIconGroup(mIconManager); requestApplyInsets(); mContext.getContentResolver().registerContentObserver( Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mPercentSettingObserver, ActivityManager.getCurrentUser()); } @Override Loading Loading @@ -521,7 +510,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements public void onDetachedFromWindow() { setListening(false); mStatusBarIconController.removeIconGroup(mIconManager); mContext.getContentResolver().unregisterContentObserver(mPercentSettingObserver); super.onDetachedFromWindow(); } Loading Loading @@ -743,25 +731,4 @@ public class QuickStatusBarHeader extends RelativeLayout implements lp.rightMargin = sideMargins; } } private void updateShowPercent() { final boolean systemSetting = 0 != Settings.System .getIntForUser(getContext().getContentResolver(), SHOW_BATTERY_PERCENT, 0, ActivityManager.getCurrentUser()); mBatteryRemainingIcon.setPercentShowMode(systemSetting ? BatteryMeterView.MODE_ESTIMATE : BatteryMeterView.MODE_ON); } private final class PercentSettingObserver extends ContentObserver { PercentSettingObserver(Handler handler) { super(handler); } @Override public void onChange(boolean selfChange, Uri uri) { super.onChange(selfChange, uri); updateShowPercent(); } } } packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java +3 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.systemui.statusbar.policy; import android.annotation.Nullable; import com.android.systemui.DemoMode; import com.android.systemui.Dumpable; import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback; Loading Loading @@ -78,6 +80,6 @@ public interface BatteryController extends DemoMode, Dumpable, * The callback * @param estimate the estimate */ void onBatteryRemainingEstimateRetrieved(String estimate); void onBatteryRemainingEstimateRetrieved(@Nullable String estimate); } } packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java +2 −2 Original line number Diff line number Diff line Loading @@ -237,10 +237,10 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC mFetchingEstimate = true; Dependency.get(Dependency.BG_HANDLER).post(() -> { mEstimate = mEstimates.getEstimate(); // Only fetch the estimate if they are enabled mEstimate = mEstimates.isHybridNotificationEnabled() ? mEstimates.getEstimate() : null; mLastEstimateTimestamp = System.currentTimeMillis(); mFetchingEstimate = false; Dependency.get(Dependency.MAIN_HANDLER).post(this::notifyEstimateFetchCallbacks); }); } Loading Loading
packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java +5 −12 Original line number Diff line number Diff line Loading @@ -195,19 +195,12 @@ public class PowerUtil { } private static String getRegularTimeRemainingShortString(Context context, long drainTimeMs) { // Get the time of day we think device will die rounded to the nearest 15 min. final long roundedTimeOfDayMs = roundTimeToNearestThreshold( System.currentTimeMillis() + drainTimeMs, FIFTEEN_MINUTES_MILLIS); // convert the time to a properly formatted string. String skeleton = android.text.format.DateFormat.getTimeFormatString(context); DateFormat fmt = DateFormat.getInstanceForSkeleton(skeleton); Date date = Date.from(Instant.ofEpochMilli(roundedTimeOfDayMs)); CharSequence timeString = fmt.format(date); // Get the time remaining rounded to the nearest 15 min final long roundedTimeMs = roundTimeToNearestThreshold(drainTimeMs, FIFTEEN_MINUTES_MILLIS); CharSequence timeString = StringUtil.formatElapsedTime(context, roundedTimeMs, false /* withSeconds */); return context.getString(R.string.power_discharge_by_only_short, timeString); return context.getString(R.string.power_remaining_duration_only_short, timeString); } public static long convertUsToMs(long timeUs) { Loading
packages/SystemUI/src/com/android/systemui/BatteryMeterView.java +11 −3 Original line number Diff line number Diff line Loading @@ -355,15 +355,23 @@ public class BatteryMeterView extends LinearLayout implements if (mBatteryPercentView != null) { if (mShowPercentMode == MODE_ESTIMATE && !mCharging) { mBatteryController.getEstimatedTimeRemainingString((String estimate) -> { if (estimate != null) { mBatteryPercentView.setText(estimate); } else { setPercentTextAtCurrentLevel(); } }); } else { mBatteryPercentView.setText( NumberFormat.getPercentInstance().format(mLevel / 100f)); setPercentTextAtCurrentLevel(); } } } private void setPercentTextAtCurrentLevel() { mBatteryPercentView.setText( NumberFormat.getPercentInstance().format(mLevel / 100f)); } private void updateShowPercent() { final boolean showing = mBatteryPercentView != null; final boolean systemSetting = 0 != Settings.System Loading
packages/SystemUI/src/com/android/systemui/qs/QuickStatusBarHeader.java +4 −37 Original line number Diff line number Diff line Loading @@ -15,7 +15,6 @@ package com.android.systemui.qs; import static android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS; import static android.provider.Settings.System.SHOW_BATTERY_PERCENT; import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT; Loading @@ -31,15 +30,12 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.res.Configuration; import android.content.res.Resources; import android.database.ContentObserver; import android.graphics.Color; import android.graphics.Rect; import android.media.AudioManager; import android.net.Uri; import android.os.Handler; import android.os.Looper; import android.provider.AlarmClock; import android.provider.Settings; import android.service.notification.ZenModeConfig; import android.text.format.DateUtils; import android.util.AttributeSet; Loading Loading @@ -75,7 +71,6 @@ import com.android.systemui.statusbar.phone.StatusBarIconController; import com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager; import com.android.systemui.statusbar.phone.StatusIconContainer; import com.android.systemui.statusbar.phone.SystemUIDialog; import com.android.systemui.statusbar.policy.BatteryController; import com.android.systemui.statusbar.policy.Clock; import com.android.systemui.statusbar.policy.DateView; import com.android.systemui.statusbar.policy.NextAlarmController; Loading Loading @@ -107,7 +102,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements public static final int MAX_TOOLTIP_SHOWN_COUNT = 2; private final Handler mHandler = new Handler(); private final BatteryController mBatteryController; private final NextAlarmController mAlarmController; private final ZenModeController mZenController; private final StatusBarIconController mStatusBarIconController; Loading Loading @@ -162,9 +156,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements }; private boolean mHasTopCutout = false; private final PercentSettingObserver mPercentSettingObserver = new PercentSettingObserver(new Handler(mContext.getMainLooper())); /** * Runnable for automatically fading out the long press tooltip (as if it were animating away). */ Loading @@ -181,12 +172,11 @@ public class QuickStatusBarHeader extends RelativeLayout implements @Inject public QuickStatusBarHeader(@Named(VIEW_CONTEXT) Context context, AttributeSet attrs, NextAlarmController nextAlarmController, ZenModeController zenModeController, BatteryController batteryController, StatusBarIconController statusBarIconController, StatusBarIconController statusBarIconController, ActivityStarter activityStarter, PrivacyItemController privacyItemController) { super(context, attrs); mAlarmController = nextAlarmController; mZenController = zenModeController; mBatteryController = batteryController; mStatusBarIconController = statusBarIconController; mActivityStarter = activityStarter; mPrivacyItemController = privacyItemController; Loading Loading @@ -241,7 +231,9 @@ public class QuickStatusBarHeader extends RelativeLayout implements mBatteryRemainingIcon = findViewById(R.id.batteryRemainingIcon); // Don't need to worry about tuner settings for this icon mBatteryRemainingIcon.setIgnoreTunerUpdates(true); updateShowPercent(); // QS will always show the estimate, and BatteryMeterView handles the case where // it's unavailable or charging mBatteryRemainingIcon.setPercentShowMode(BatteryMeterView.MODE_ESTIMATE); } private List<String> getIgnoredIconSlots() { Loading Loading @@ -480,9 +472,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements super.onAttachedToWindow(); mStatusBarIconController.addIconGroup(mIconManager); requestApplyInsets(); mContext.getContentResolver().registerContentObserver( Settings.System.getUriFor(SHOW_BATTERY_PERCENT), false, mPercentSettingObserver, ActivityManager.getCurrentUser()); } @Override Loading Loading @@ -521,7 +510,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements public void onDetachedFromWindow() { setListening(false); mStatusBarIconController.removeIconGroup(mIconManager); mContext.getContentResolver().unregisterContentObserver(mPercentSettingObserver); super.onDetachedFromWindow(); } Loading Loading @@ -743,25 +731,4 @@ public class QuickStatusBarHeader extends RelativeLayout implements lp.rightMargin = sideMargins; } } private void updateShowPercent() { final boolean systemSetting = 0 != Settings.System .getIntForUser(getContext().getContentResolver(), SHOW_BATTERY_PERCENT, 0, ActivityManager.getCurrentUser()); mBatteryRemainingIcon.setPercentShowMode(systemSetting ? BatteryMeterView.MODE_ESTIMATE : BatteryMeterView.MODE_ON); } private final class PercentSettingObserver extends ContentObserver { PercentSettingObserver(Handler handler) { super(handler); } @Override public void onChange(boolean selfChange, Uri uri) { super.onChange(selfChange, uri); updateShowPercent(); } } }
packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryController.java +3 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.systemui.statusbar.policy; import android.annotation.Nullable; import com.android.systemui.DemoMode; import com.android.systemui.Dumpable; import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback; Loading Loading @@ -78,6 +80,6 @@ public interface BatteryController extends DemoMode, Dumpable, * The callback * @param estimate the estimate */ void onBatteryRemainingEstimateRetrieved(String estimate); void onBatteryRemainingEstimateRetrieved(@Nullable String estimate); } }
packages/SystemUI/src/com/android/systemui/statusbar/policy/BatteryControllerImpl.java +2 −2 Original line number Diff line number Diff line Loading @@ -237,10 +237,10 @@ public class BatteryControllerImpl extends BroadcastReceiver implements BatteryC mFetchingEstimate = true; Dependency.get(Dependency.BG_HANDLER).post(() -> { mEstimate = mEstimates.getEstimate(); // Only fetch the estimate if they are enabled mEstimate = mEstimates.isHybridNotificationEnabled() ? mEstimates.getEstimate() : null; mLastEstimateTimestamp = System.currentTimeMillis(); mFetchingEstimate = false; Dependency.get(Dependency.MAIN_HANDLER).post(this::notifyEstimateFetchCallbacks); }); } Loading