Merge "Use new time format in BatteryInfo"

This commit is contained in:
Lei Yu
2017-06-05 17:19:04 +00:00
committed by Android (Google) Code Review
4 changed files with 46 additions and 66 deletions

View File

@@ -510,7 +510,7 @@ public class BatteryHistoryChart extends View {
mInfo = info;
mDrainString = "";
mChargeDurationString = "";
setContentDescription(mInfo.chargeLabelString);
setContentDescription(mInfo.chargeLabel);
int pos = 0;
int lastInteresting = 0;
@@ -589,7 +589,8 @@ public class BatteryHistoryChart extends View {
mMaxPercentLabelStringWidth = (int)mTextPaint.measureText(mMaxPercentLabelString);
mMinPercentLabelStringWidth = (int)mTextPaint.measureText(mMinPercentLabelString);
mDrainStringWidth = (int)mHeaderTextPaint.measureText(mDrainString);
mChargeLabelStringWidth = (int)mHeaderTextPaint.measureText(mInfo.chargeLabelString);
mChargeLabelStringWidth = (int) mHeaderTextPaint.measureText(
mInfo.chargeLabel.toString());
mChargeDurationStringWidth = (int)mHeaderTextPaint.measureText(mChargeDurationString);
mTextAscent = (int)mTextPaint.ascent();
mTextDescent = (int)mTextPaint.descent();
@@ -1211,8 +1212,9 @@ public class BatteryHistoryChart extends View {
int headerTop = -mHeaderTextAscent + (mHeaderTextDescent-mHeaderTextAscent)/3;
mHeaderTextPaint.setTextAlign(textAlignLeft);
if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.chargeLabelString);
canvas.drawText(mInfo.chargeLabelString, textStartX, headerTop, mHeaderTextPaint);
if (DEBUG) Log.d(TAG, "Drawing charge label string: " + mInfo.chargeLabel);
canvas.drawText(mInfo.chargeLabel.toString(), textStartX, headerTop,
mHeaderTextPaint);
int stringHalfWidth = mChargeDurationStringWidth / 2;
if (layoutRtl) stringHalfWidth = -stringHalfWidth;
int headerCenter = ((width-mChargeDurationStringWidth-mDrainStringWidth)/2)

View File

@@ -25,23 +25,25 @@ import android.os.BatteryStats.HistoryItem;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.WorkerThread;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.SparseIntArray;
import com.android.internal.os.BatteryStatsHelper;
import android.support.annotation.VisibleForTesting;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.R;
import com.android.settingslib.Utils;
import com.android.settings.Utils;
import com.android.settingslib.graph.UsageView;
public class BatteryInfo {
public String chargeLabelString;
public CharSequence chargeLabel;
public CharSequence remainingLabel;
public int batteryLevel;
public boolean discharging = true;
public long remainingTimeUs = 0;
public String batteryPercentString;
public String remainingLabel;
public String statusLabel;
private boolean mCharging;
private BatteryStats mStats;
@@ -172,27 +174,25 @@ public class BatteryInfo {
if (!info.mCharging) {
if (drainTimeUs > 0) {
info.remainingTimeUs = drainTimeUs;
String timeString = Formatter.formatShortElapsedTime(context,
batteryUtils.convertUsToMs(drainTimeUs));
info.remainingLabel = resources.getString(
shortString ?
(basedOnUsage ?
R.string.power_remaining_duration_only_short_enhanced :
R.string.power_remaining_duration_only_short) :
(basedOnUsage ?
R.string.power_remaining_duration_only_enhanced :
R.string.power_remaining_duration_only),
timeString);
info.chargeLabelString = resources.getString(
CharSequence timeString = Utils.formatElapsedTime(context,
batteryUtils.convertUsToMs(drainTimeUs), false /* withSeconds */);
info.remainingLabel = TextUtils.expandTemplate(context.getText(shortString ?
(basedOnUsage ?
R.string.power_remaining_duration_only_short_enhanced :
R.string.power_remaining_duration_only_short) :
(basedOnUsage ?
R.string.power_remaining_duration_only_enhanced :
R.string.power_remaining_duration_only)), timeString);
info.chargeLabel = TextUtils.expandTemplate(context.getText(
shortString ?
R.string.power_discharging_duration_short :
basedOnUsage ?
R.string.power_discharging_duration_enhanced :
R.string.power_discharging_duration,
R.string.power_discharging_duration),
info.batteryPercentString, timeString);
} else {
info.remainingLabel = null;
info.chargeLabelString = info.batteryPercentString;
info.chargeLabel = info.batteryPercentString;
}
} else {
final long chargeTime = stats.computeChargeTimeRemaining(elapsedRealtimeUs);
@@ -201,19 +201,19 @@ public class BatteryInfo {
info.discharging = false;
if (chargeTime > 0 && status != BatteryManager.BATTERY_STATUS_FULL) {
info.remainingTimeUs = chargeTime;
String timeString = Formatter.formatShortElapsedTime(context,
batteryUtils.convertUsToMs(chargeTime));
CharSequence timeString = Utils.formatElapsedTime(context,
batteryUtils.convertUsToMs(drainTimeUs), false /* withSeconds */);
int resId = shortString ? R.string.power_charging_duration_short
: R.string.power_charging_duration;
info.remainingLabel = resources.getString(
R.string.power_remaining_charging_duration_only, timeString);
info.chargeLabelString = resources.getString(
resId, info.batteryPercentString, timeString);
info.remainingLabel = TextUtils.expandTemplate(context.getText(
R.string.power_remaining_charging_duration_only), timeString);
info.chargeLabel = TextUtils.expandTemplate(context.getText(resId),
info.batteryPercentString, timeString);
} else {
final String chargeStatusLabel = resources.getString(
R.string.battery_info_status_charging_lower);
info.remainingLabel = null;
info.chargeLabelString = resources.getString(
info.chargeLabel = resources.getString(
R.string.power_charging, info.batteryPercentString, chargeStatusLabel);
}
}

View File

@@ -769,7 +769,7 @@ public class PowerUsageSummary extends PowerUsageBase implements
BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() {
@Override
public void onBatteryInfoLoaded(BatteryInfo info) {
mLoader.setSummary(SummaryProvider.this, info.chargeLabelString);
mLoader.setSummary(SummaryProvider.this, info.chargeLabel);
}
});
});