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