Update StringUtil#formatElapsedTime method (2/3)
- Update the usage and the test case - Update discharging string to follow new string doc Bug: 183689347 Test: make RunSettingsRoboTests Change-Id: I1e14e7da8cb02755d8cf6e12626a0d94fad87121
This commit is contained in:
committed by
Wesley Wang
parent
acacad4cdf
commit
50f314e45d
@@ -364,7 +364,12 @@ public class AdvancedBluetoothDetailsHeaderController extends BasePreferenceCont
|
||||
final TextView textView = linearLayout.findViewById(R.id.bt_battery_prediction);
|
||||
if (estimateReady == 1) {
|
||||
textView.setVisibility(View.VISIBLE);
|
||||
textView.setText(StringUtil.formatElapsedTime(mContext, batteryEstimate, false));
|
||||
textView.setText(
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
batteryEstimate,
|
||||
/* withSeconds */ false,
|
||||
/* collapseTimeUnit */ false));
|
||||
} else {
|
||||
textView.setVisibility(View.GONE);
|
||||
}
|
||||
|
@@ -318,7 +318,10 @@ public class DataUsageSummaryPreference extends Preference {
|
||||
textResourceId = R.string.no_carrier_update_text;
|
||||
}
|
||||
updateTime = StringUtil.formatElapsedTime(
|
||||
getContext(), updateAgeMillis, false /* withSeconds */);
|
||||
getContext(),
|
||||
updateAgeMillis,
|
||||
false /* withSeconds */,
|
||||
false /* collapseTimeUnit */);
|
||||
}
|
||||
carrierInfo.setText(TextUtils.expandTemplate(
|
||||
getContext().getText(textResourceId),
|
||||
|
@@ -229,10 +229,18 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
|
||||
final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
|
||||
mForegroundPreference.setSummary(
|
||||
TextUtils.expandTemplate(getText(R.string.battery_used_for),
|
||||
StringUtil.formatElapsedTime(context, foregroundTimeMs, false)));
|
||||
StringUtil.formatElapsedTime(
|
||||
context,
|
||||
foregroundTimeMs,
|
||||
/* withSeconds */ false,
|
||||
/* collapseTimeUnit */ false)));
|
||||
mBackgroundPreference.setSummary(
|
||||
TextUtils.expandTemplate(getText(R.string.battery_active_for),
|
||||
StringUtil.formatElapsedTime(context, backgroundTimeMs, false)));
|
||||
StringUtil.formatElapsedTime(
|
||||
context,
|
||||
backgroundTimeMs,
|
||||
/* withSeconds */ false,
|
||||
/* collapseTimeUnit */ false)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -380,7 +380,7 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
|
||||
final long usageTimeMs = entry.getTimeInForegroundMs();
|
||||
if (shouldShowSummary(entry) && usageTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
|
||||
final CharSequence timeSequence =
|
||||
StringUtil.formatElapsedTime(mContext, usageTimeMs, false);
|
||||
StringUtil.formatElapsedTime(mContext, usageTimeMs, false, false);
|
||||
preference.setSummary(
|
||||
entry.isHidden()
|
||||
? timeSequence
|
||||
|
@@ -263,8 +263,11 @@ public class BatteryInfo {
|
||||
context.getString(chargingLimitedResId, info.batteryPercentString);
|
||||
} else if (chargeTimeMs > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
|
||||
info.remainingTimeUs = PowerUtil.convertMsToUs(chargeTimeMs);
|
||||
CharSequence timeString = StringUtil.formatElapsedTime(context,
|
||||
PowerUtil.convertUsToMs(info.remainingTimeUs), false /* withSeconds */);
|
||||
final CharSequence timeString = StringUtil.formatElapsedTime(
|
||||
context,
|
||||
PowerUtil.convertUsToMs(info.remainingTimeUs),
|
||||
false /* withSeconds */,
|
||||
true /* collapseTimeUnit */);
|
||||
int resId = R.string.power_charging_duration;
|
||||
info.remainingLabel = context.getString(
|
||||
R.string.power_remaining_charging_duration_only, timeString);
|
||||
@@ -287,7 +290,7 @@ public class BatteryInfo {
|
||||
context,
|
||||
PowerUtil.convertUsToMs(drainTimeUs),
|
||||
null /* percentageString */,
|
||||
estimate.isBasedOnUsage() && !shortString
|
||||
false /* basedOnUsage */
|
||||
);
|
||||
info.chargeLabel = PowerUtil.getBatteryRemainingStringFormatted(
|
||||
context,
|
||||
|
@@ -480,7 +480,7 @@ public class WifiDetailPreferenceController2 extends AbstractPreferenceControlle
|
||||
return mContext.getString(R.string.wifi_time_remaining, StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
Duration.between(now, expiryTime).getSeconds() * 1000,
|
||||
false /* withSeconds */));
|
||||
false /* withSeconds */, false /* collapseTimeUnit */));
|
||||
}
|
||||
|
||||
// For more than 2 days, show the expiry date
|
||||
|
@@ -473,9 +473,9 @@ public class AdvancedBluetoothDetailsHeaderControllerTest {
|
||||
@Test
|
||||
public void showBatteryPredictionIfNecessary_estimateReadyIsAvailable_showCorrectValue() {
|
||||
final String leftBatteryPrediction =
|
||||
StringUtil.formatElapsedTime(mContext, 12000000, false).toString();
|
||||
StringUtil.formatElapsedTime(mContext, 12000000, false, false).toString();
|
||||
final String rightBatteryPrediction =
|
||||
StringUtil.formatElapsedTime(mContext, 1200000, false).toString();
|
||||
StringUtil.formatElapsedTime(mContext, 1200000, false, false).toString();
|
||||
|
||||
mController.showBatteryPredictionIfNecessary(1, 12000000,
|
||||
mLayoutPreference.findViewById(R.id.layout_left));
|
||||
|
@@ -150,10 +150,9 @@ public class BatteryInfoTest {
|
||||
mBatteryUsageStats, estimate, SystemClock.elapsedRealtime() * 1000,
|
||||
true /* shortString */);
|
||||
|
||||
// We only add special mention for the long string
|
||||
assertThat(info.remainingLabel.toString()).contains(ENHANCED_STRING_SUFFIX);
|
||||
// Both long and short strings should not have extra text
|
||||
assertThat(info.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
|
||||
assertThat(info.suggestionLabel).contains(BATTERY_RUN_OUT_PREFIX);
|
||||
// shortened string should not have extra text
|
||||
assertThat(info2.remainingLabel.toString()).doesNotContain(ENHANCED_STRING_SUFFIX);
|
||||
assertThat(info2.suggestionLabel).contains(BATTERY_RUN_OUT_PREFIX);
|
||||
}
|
||||
|
@@ -579,7 +579,11 @@ public class WifiDetailPreferenceController2Test {
|
||||
ZoneId.of("Europe/London"));
|
||||
doShouldShowRemainingTimeTest(fakeNow, timeRemainingMs);
|
||||
final String expectedSummary = mContext.getString(R.string.wifi_time_remaining,
|
||||
StringUtil.formatElapsedTime(mContext, timeRemainingMs, false /* withSeconds */));
|
||||
StringUtil.formatElapsedTime(
|
||||
mContext,
|
||||
timeRemainingMs,
|
||||
false /* withSeconds */,
|
||||
false /* collapseTimeUnit */));
|
||||
final InOrder inOrder = inOrder(mMockHeaderController);
|
||||
inOrder.verify(mMockHeaderController).setSecondSummary(expectedSummary);
|
||||
|
||||
|
Reference in New Issue
Block a user