Align system time 12-24 hour format in the time slot information
align the time format configuration in the Settings -> System -> Date/Time to show 12- or 24- hour format in the usage time slot screenshot: https://screenshot.googleplex.com/3w2SFvBLpC5oHBs screenshot: https://screenshot.googleplex.com/86uCq6R4PKEg9RD screenshot: https://screenshot.googleplex.com/3easrEFMQdZEjGP screenshot: https://screenshot.googleplex.com/7dPWVJNTbSShFPa Bug: 187783891 Test: make SettingsRoboTests Change-Id: I9af0a69bd7c67562526bd5ee74a657635068ef44
This commit is contained in:
@@ -24,6 +24,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateFormat;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -47,7 +48,6 @@ import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
|
||||
import com.android.settingslib.utils.StringUtil;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@@ -88,6 +88,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
@VisibleForTesting long[] mBatteryHistoryKeys;
|
||||
@VisibleForTesting int mTrapezoidIndex = BatteryChartView.SELECTED_INDEX_INVALID;
|
||||
|
||||
private boolean mIs24HourFormat = false;
|
||||
|
||||
private final String mPreferenceKey;
|
||||
private final SettingsActivity mActivity;
|
||||
private final InstrumentedPreferenceFragment mFragment;
|
||||
@@ -110,6 +112,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
mActivity = activity;
|
||||
mFragment = fragment;
|
||||
mPreferenceKey = preferenceKey;
|
||||
mIs24HourFormat = DateFormat.is24HourFormat(context);
|
||||
mNotAllowShowSummaryPackages = context.getResources()
|
||||
.getTextArray(R.array.allowlist_hide_summary_in_battery_usage);
|
||||
mNotAllowShowEntryPackages = context.getResources()
|
||||
@@ -144,6 +147,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
BatteryDiffEntry.clearCache();
|
||||
Log.d(TAG, "clear icon and label cache since uiMode is changed");
|
||||
}
|
||||
mIs24HourFormat = DateFormat.is24HourFormat(mContext);
|
||||
mMetricsFeatureProvider.action(mPrefContext, SettingsEnums.OPEN_BATTERY_USAGE);
|
||||
}
|
||||
|
||||
@@ -493,10 +497,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
return null;
|
||||
}
|
||||
final String fromHour = ConvertUtils.utcToLocalTimeHour(
|
||||
mBatteryHistoryKeys[mTrapezoidIndex * 2]);
|
||||
mBatteryHistoryKeys[mTrapezoidIndex * 2], mIs24HourFormat);
|
||||
final String toHour = ConvertUtils.utcToLocalTimeHour(
|
||||
mBatteryHistoryKeys[(mTrapezoidIndex + 1) * 2]);
|
||||
return String.format("%s-%s", fromHour, toHour);
|
||||
mBatteryHistoryKeys[(mTrapezoidIndex + 1) * 2], mIs24HourFormat);
|
||||
return String.format("%s - %s", fromHour, toHour);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -563,21 +567,9 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
||||
if (mBatteryChartView == null || mBatteryHistoryKeys == null) {
|
||||
return;
|
||||
}
|
||||
long latestTimestamp =
|
||||
final long latestTimestamp =
|
||||
mBatteryHistoryKeys[mBatteryHistoryKeys.length - 1];
|
||||
// Uses the current time if we don't have history data.
|
||||
if (latestTimestamp == 0) {
|
||||
latestTimestamp = Clock.systemUTC().millis();
|
||||
}
|
||||
// Generates timestamp label for chart graph (every 8 hours).
|
||||
final long timeSlotOffset = DateUtils.HOUR_IN_MILLIS * 8;
|
||||
final String[] timestampLabels = new String[4];
|
||||
for (int index = 0; index < timestampLabels.length; index++) {
|
||||
timestampLabels[index] =
|
||||
ConvertUtils.utcToLocalTimeHour(
|
||||
latestTimestamp - (3 - index) * timeSlotOffset);
|
||||
}
|
||||
mBatteryChartView.setTimestamps(timestampLabels);
|
||||
mBatteryChartView.setLatestTimestamp(latestTimestamp);
|
||||
}
|
||||
|
||||
private static String utcToLocalTime(long[] timestamps) {
|
||||
|
Reference in New Issue
Block a user