Merge "Resolve localization issue and refine UI for chart view" into sc-dev
This commit is contained in:
@@ -15,6 +15,8 @@ package com.android.settings.fuelgauge;
|
||||
|
||||
import static java.lang.Math.round;
|
||||
|
||||
import static com.android.settings.Utils.formatPercentage;
|
||||
|
||||
import android.accessibilityservice.AccessibilityServiceInfo;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
@@ -53,8 +55,13 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
||||
private static final String TAG = "BatteryChartView";
|
||||
private static final List<String> ACCESSIBILITY_SERVICE_NAMES =
|
||||
Arrays.asList("SwitchAccessService", "TalkBackService", "JustSpeakService");
|
||||
|
||||
// For drawing the percentage information.
|
||||
private static final String[] PERCENTAGES = new String[] {"100%", "50%", "0%"};
|
||||
private static final String[] PERCENTAGES = new String[] {
|
||||
formatPercentage(/*percentage=*/ 100, /*round=*/ true),
|
||||
formatPercentage(/*percentage=*/ 50, /*round=*/ true),
|
||||
formatPercentage(/*percentage=*/ 0, /*round=*/ true)};
|
||||
|
||||
private static final int DEFAULT_TRAPEZOID_COUNT = 12;
|
||||
private static final int DEFAULT_TIMESTAMP_COUNT = 4;
|
||||
private static final int DIVIDER_COLOR = Color.parseColor("#CDCCC5");
|
||||
@@ -220,13 +227,14 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
||||
mIndent.right = mPercentageBounds[0].width() + mTextPadding;
|
||||
|
||||
if (mTimestamps != null) {
|
||||
int maxHeight = 0;
|
||||
for (int index = 0; index < DEFAULT_TIMESTAMP_COUNT; index++) {
|
||||
mTextPaint.getTextBounds(
|
||||
mTimestamps[index], 0, mTimestamps[index].length(),
|
||||
mTimestampsBounds[index]);
|
||||
maxHeight = Math.max(maxHeight, mTimestampsBounds[index].height());
|
||||
}
|
||||
mIndent.bottom = mTimestampsBounds[0].height()
|
||||
+ round(mTextPadding * 1.5f);
|
||||
mIndent.bottom = maxHeight + round(mTextPadding * 1.5f);
|
||||
}
|
||||
Log.d(TAG, "setIndent:" + mPercentageBounds[0]);
|
||||
} else {
|
||||
@@ -451,7 +459,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
|
||||
|
||||
private int getTimestampY(int index) {
|
||||
return getHeight() - mTimestampsBounds[index].height()
|
||||
- mTimestampsBounds[index].top;
|
||||
+ (mTimestampsBounds[index].height() + mTimestampsBounds[index].top)
|
||||
+ round(mTextPadding * 1.5f);
|
||||
}
|
||||
|
||||
private void drawTrapezoids(Canvas canvas) {
|
||||
|
@@ -74,8 +74,12 @@ public final class ConvertUtils {
|
||||
public static final int CONSUMER_TYPE_USER_BATTERY = 2;
|
||||
public static final int CONSUMER_TYPE_SYSTEM_BATTERY = 3;
|
||||
|
||||
private static String sZoneId;
|
||||
private static String sZoneIdForHour;
|
||||
// For language is changed.
|
||||
@VisibleForTesting static Locale sLocale;
|
||||
@VisibleForTesting static Locale sLocaleForHour;
|
||||
// For time zone is changed.
|
||||
@VisibleForTesting static String sZoneId;
|
||||
@VisibleForTesting static String sZoneIdForHour;
|
||||
private static boolean sIs24HourFormat;
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -130,28 +134,35 @@ public final class ConvertUtils {
|
||||
|
||||
/** Converts UTC timestamp to human readable local time string. */
|
||||
public static String utcToLocalTime(long timestamp) {
|
||||
final Locale currentLocale = Locale.getDefault();
|
||||
final String currentZoneId = TimeZone.getDefault().getID();
|
||||
if (!currentZoneId.equals(sZoneId) || sSimpleDateFormat == null) {
|
||||
if (!currentZoneId.equals(sZoneId)
|
||||
|| !currentLocale.equals(sLocale)
|
||||
|| sSimpleDateFormat == null) {
|
||||
sLocale = currentLocale;
|
||||
sZoneId = currentZoneId;
|
||||
sSimpleDateFormat =
|
||||
new SimpleDateFormat("MMM dd,yyyy HH:mm:ss", Locale.ENGLISH);
|
||||
new SimpleDateFormat("MMM dd,yyyy HH:mm:ss", currentLocale);
|
||||
}
|
||||
return sSimpleDateFormat.format(new Date(timestamp));
|
||||
}
|
||||
|
||||
/** Converts UTC timestamp to local time hour data. */
|
||||
public static String utcToLocalTimeHour(long timestamp, boolean is24HourFormat) {
|
||||
final Locale currentLocale = Locale.getDefault();
|
||||
final String currentZoneId = TimeZone.getDefault().getID();
|
||||
if (!currentZoneId.equals(sZoneIdForHour)
|
||||
|| !currentLocale.equals(sLocaleForHour)
|
||||
|| sIs24HourFormat != is24HourFormat
|
||||
|| sSimpleDateFormatForHour == null) {
|
||||
sLocaleForHour = currentLocale;
|
||||
sZoneIdForHour = currentZoneId;
|
||||
sIs24HourFormat = is24HourFormat;
|
||||
sSimpleDateFormatForHour = new SimpleDateFormat(
|
||||
sIs24HourFormat ? "HH" : "h aa", Locale.ENGLISH);
|
||||
sIs24HourFormat ? "HH" : "h aa", currentLocale);
|
||||
}
|
||||
return sSimpleDateFormatForHour.format(new Date(timestamp))
|
||||
.toLowerCase(Locale.getDefault());
|
||||
.toLowerCase(currentLocale);
|
||||
}
|
||||
|
||||
/** Gets indexed battery usage data for each corresponding time slot. */
|
||||
|
Reference in New Issue
Block a user