Always show time remaining estimate string in QS
QS will always show the time remaining estimate string, unless charging or the estimate is unavailable Test: visual Fixes: 127519046 Change-Id: Iaa268ce631d3196967748b7f562d26e19ddeb465
This commit is contained in:
@@ -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);
|
||||
// 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 */);
|
||||
|
||||
// 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);
|
||||
|
||||
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) {
|
||||
|
||||
@@ -355,15 +355,23 @@ public class BatteryMeterView extends LinearLayout implements
|
||||
if (mBatteryPercentView != null) {
|
||||
if (mShowPercentMode == MODE_ESTIMATE && !mCharging) {
|
||||
mBatteryController.getEstimatedTimeRemainingString((String estimate) -> {
|
||||
mBatteryPercentView.setText(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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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).
|
||||
*/
|
||||
@@ -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;
|
||||
@@ -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() {
|
||||
@@ -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
|
||||
@@ -521,7 +510,6 @@ public class QuickStatusBarHeader extends RelativeLayout implements
|
||||
public void onDetachedFromWindow() {
|
||||
setListening(false);
|
||||
mStatusBarIconController.removeIconGroup(mIconManager);
|
||||
mContext.getContentResolver().unregisterContentObserver(mPercentSettingObserver);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user