Impl highlight effect on BatteryChartView slots.
Screenshot: https://screenshot.googleplex.com/F5VrGjj5kdNHMV6 Bug: 284893240 Bug: 291689623 Test: manual Change-Id: I846d95d31e8bb839481b86a94d5191ff205f8328
This commit is contained in:
@@ -20,6 +20,7 @@ import static com.android.settingslib.fuelgauge.BatteryStatus.BATTERY_LEVEL_UNKN
|
||||
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Pair;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -69,6 +70,16 @@ public final class BatteryLevelData {
|
||||
return String.format(Locale.ENGLISH, "timestamps: %s; levels: %s",
|
||||
Objects.toString(mTimestamps), Objects.toString(mLevels));
|
||||
}
|
||||
|
||||
private int getIndexByTimestamps(long startTimestamp, long endTimestamp) {
|
||||
for (int index = 0; index < mTimestamps.size() - 1; index++) {
|
||||
if (mTimestamps.get(index) <= startTimestamp
|
||||
&& endTimestamp <= mTimestamps.get(index + 1)) {
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return BatteryChartViewModel.SELECTED_INDEX_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,6 +111,18 @@ public final class BatteryLevelData {
|
||||
}
|
||||
}
|
||||
|
||||
/** Gets daily and hourly index between start and end timestamps. */
|
||||
public Pair<Integer, Integer> getIndexByTimestamps(long startTimestamp, long endTimestamp) {
|
||||
final int dailyHighlightIndex =
|
||||
mDailyBatteryLevels.getIndexByTimestamps(startTimestamp, endTimestamp);
|
||||
final int hourlyHighlightIndex =
|
||||
(dailyHighlightIndex == BatteryChartViewModel.SELECTED_INDEX_INVALID)
|
||||
? BatteryChartViewModel.SELECTED_INDEX_INVALID
|
||||
: mHourlyBatteryLevelsPerDay.get(dailyHighlightIndex)
|
||||
.getIndexByTimestamps(startTimestamp, endTimestamp);
|
||||
return Pair.create(dailyHighlightIndex, hourlyHighlightIndex);
|
||||
}
|
||||
|
||||
public PeriodBatteryLevelData getDailyBatteryLevels() {
|
||||
return mDailyBatteryLevels;
|
||||
}
|
||||
|
Reference in New Issue
Block a user