[A11y] Add battery chart slot selected status in content description.

- Let talkback annouce the slot status before battery slot info.
"Selected": If current slot is selected or after the double-tap action to selected a slot.
"Unselected": If current slot is not the seletectd one or after double-tapping an already selected slot(which will selected ALL instead)

Fix: 386027256
Test: Talkback
Flag: EXEMPT for simple fix
Change-Id: I32a665cdf21620aade8397e5bbe4cb44964b0a39
This commit is contained in:
mxyyiyi
2025-03-05 19:19:09 +08:00
parent 744ed22075
commit e853b6b267
3 changed files with 71 additions and 59 deletions

View File

@@ -6600,8 +6600,12 @@
<string name="battery_usage_timestamps_content_description"><xliff:g id="from_timestamp">%1$s</xliff:g> to <xliff:g id="to_timestamp">%2$s</xliff:g></string> <string name="battery_usage_timestamps_content_description"><xliff:g id="from_timestamp">%1$s</xliff:g> to <xliff:g id="to_timestamp">%2$s</xliff:g></string>
<!-- [CHAR_LIMIT=NONE] The first slot is a week day (e.g. "Monday"); the second slot is a hourly time span (e.g. "6 AM - 8 AM"). --> <!-- [CHAR_LIMIT=NONE] The first slot is a week day (e.g. "Monday"); the second slot is a hourly time span (e.g. "6 AM - 8 AM"). -->
<string name="battery_usage_day_and_hour"><xliff:g id="day">%1$s</xliff:g> <xliff:g id="hour">%2$s</xliff:g></string> <string name="battery_usage_day_and_hour"><xliff:g id="day">%1$s</xliff:g> <xliff:g id="hour">%2$s</xliff:g></string>
<!-- [CHAR_LIMIT=NONE] Accessibility content description for each slot in battery chart view. --> <!-- [CHAR_LIMIT=NONE] Accessibility content description for each slot in battery chart view. Please reuse the words in tc/6732629268310936155 -->
<string name="battery_usage_time_info_and_battery_level"><xliff:g id="time_info" example="Battery usage for Monday 6 AM - 8 AM">%1$s</xliff:g> <xliff:g id="battery_level" example="Battery level percentage from 83% to 59%">%2$s</xliff:g></string> <string name="battery_usage_status_time_info_and_battery_level"><xliff:g id="selected_status" example="Selected">%1$s</xliff:g>, <xliff:g id="time_info" example="Battery usage for Monday 6 AM - 8 AM">%2$s</xliff:g> <xliff:g id="battery_level" example="Battery level percentage from 83% to 59%">%3$s</xliff:g></string>
<!-- [CHAR_LIMIT=NONE] Accessibility content description for the battery usage slot is selected. -->
<string name="battery_chart_slot_status_selected">Selected</string>
<!-- [CHAR_LIMIT=NONE] Accessibility content description for the battery usage slot is not selected -->
<string name="battery_chart_slot_status_unselected">Unselected</string>
<!-- [CHAR_LIMIT=NONE] Accessibility content description for battery chart view. --> <!-- [CHAR_LIMIT=NONE] Accessibility content description for battery chart view. -->
<string name="battery_usage_chart">Battery usage chart</string> <string name="battery_usage_chart">Battery usage chart</string>
<!-- [CHAR_LIMIT=NONE] Accessibility content description for daily battery chart view. --> <!-- [CHAR_LIMIT=NONE] Accessibility content description for daily battery chart view. -->

View File

@@ -16,6 +16,9 @@
package com.android.settings.fuelgauge.batteryusage; package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.fuelgauge.batteryusage.BatteryChartViewModel.SELECTED_INDEX_ALL;
import static com.android.settings.fuelgauge.batteryusage.BatteryChartViewModel.SELECTED_INDEX_INVALID;
import android.animation.Animator; import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.app.settings.SettingsEnums; import android.app.settings.SettingsEnums;
@@ -82,10 +85,10 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
@VisibleForTesting TextView mChartSummaryTextView; @VisibleForTesting TextView mChartSummaryTextView;
@VisibleForTesting BatteryChartView mDailyChartView; @VisibleForTesting BatteryChartView mDailyChartView;
@VisibleForTesting BatteryChartView mHourlyChartView; @VisibleForTesting BatteryChartView mHourlyChartView;
@VisibleForTesting int mDailyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL; @VisibleForTesting int mDailyChartIndex = SELECTED_INDEX_ALL;
@VisibleForTesting int mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL; @VisibleForTesting int mHourlyChartIndex = SELECTED_INDEX_ALL;
@VisibleForTesting int mDailyHighlightSlotIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID; @VisibleForTesting int mDailyHighlightSlotIndex = SELECTED_INDEX_INVALID;
@VisibleForTesting int mHourlyHighlightSlotIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID; @VisibleForTesting int mHourlyHighlightSlotIndex = SELECTED_INDEX_INVALID;
private boolean mIs24HourFormat; private boolean mIs24HourFormat;
private View mBatteryChartViewGroup; private View mBatteryChartViewGroup;
@@ -198,8 +201,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
getTotalHours(batteryLevelData)); getTotalHours(batteryLevelData));
if (batteryLevelData == null) { if (batteryLevelData == null) {
mDailyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL; mDailyChartIndex = SELECTED_INDEX_ALL;
mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL; mHourlyChartIndex = SELECTED_INDEX_ALL;
mDailyViewModel = null; mDailyViewModel = null;
mHourlyViewModels = null; mHourlyViewModels = null;
refreshUi(); refreshUi();
@@ -226,9 +229,9 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} }
boolean isHighlightSlotFocused() { boolean isHighlightSlotFocused() {
return (mDailyHighlightSlotIndex != BatteryChartViewModel.SELECTED_INDEX_INVALID return (mDailyHighlightSlotIndex != SELECTED_INDEX_INVALID
&& mDailyHighlightSlotIndex == mDailyChartIndex && mDailyHighlightSlotIndex == mDailyChartIndex
&& mHourlyHighlightSlotIndex != BatteryChartViewModel.SELECTED_INDEX_INVALID && mHourlyHighlightSlotIndex != SELECTED_INDEX_INVALID
&& mHourlyHighlightSlotIndex == mHourlyChartIndex); && mHourlyHighlightSlotIndex == mHourlyChartIndex);
} }
@@ -242,8 +245,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} }
void selectHighlightSlotIndex() { void selectHighlightSlotIndex() {
if (mDailyHighlightSlotIndex == BatteryChartViewModel.SELECTED_INDEX_INVALID if (mDailyHighlightSlotIndex == SELECTED_INDEX_INVALID
|| mHourlyHighlightSlotIndex == BatteryChartViewModel.SELECTED_INDEX_INVALID) { || mHourlyHighlightSlotIndex == SELECTED_INDEX_INVALID) {
return; return;
} }
if (mDailyHighlightSlotIndex == mDailyChartIndex if (mDailyHighlightSlotIndex == mDailyChartIndex
@@ -258,8 +261,11 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
"onDailyChartSelect:%d, onHourlyChartSelect:%d", "onDailyChartSelect:%d, onHourlyChartSelect:%d",
mDailyChartIndex, mHourlyChartIndex)); mDailyChartIndex, mHourlyChartIndex));
refreshUi(); refreshUi();
// The highlight slot must be selected.
mHandler.post( mHandler.post(
() -> mDailyChartView.setAccessibilityPaneTitle(getAccessibilityAnnounceMessage())); () ->
mDailyChartView.setAccessibilityPaneTitle(
getAccessibilityAnnounceMessage(/* isSlotSelected= */ true)));
if (mOnSelectedIndexUpdatedListener != null) { if (mOnSelectedIndexUpdatedListener != null) {
mOnSelectedIndexUpdatedListener.onSelectedIndexUpdated(); mOnSelectedIndexUpdatedListener.onSelectedIndexUpdated();
} }
@@ -295,15 +301,16 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} }
Log.d(TAG, "onDailyChartSelect:" + trapezoidIndex); Log.d(TAG, "onDailyChartSelect:" + trapezoidIndex);
mDailyChartIndex = trapezoidIndex; mDailyChartIndex = trapezoidIndex;
mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL; mHourlyChartIndex = SELECTED_INDEX_ALL;
refreshUi(); refreshUi();
mHandler.post( mHandler.post(
() -> () ->
mDailyChartView.setAccessibilityPaneTitle( mDailyChartView.setAccessibilityPaneTitle(
getAccessibilityAnnounceMessage())); getAccessibilityAnnounceMessage(
mDailyChartIndex != SELECTED_INDEX_ALL)));
mMetricsFeatureProvider.action( mMetricsFeatureProvider.action(
mPrefContext, mPrefContext,
trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL trapezoidIndex == SELECTED_INDEX_ALL
? SettingsEnums.ACTION_BATTERY_USAGE_DAILY_SHOW_ALL ? SettingsEnums.ACTION_BATTERY_USAGE_DAILY_SHOW_ALL
: SettingsEnums.ACTION_BATTERY_USAGE_DAILY_TIME_SLOT, : SettingsEnums.ACTION_BATTERY_USAGE_DAILY_TIME_SLOT,
mDailyChartIndex); mDailyChartIndex);
@@ -314,7 +321,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mHourlyChartView = hourlyChartView; mHourlyChartView = hourlyChartView;
mHourlyChartView.setOnSelectListener( mHourlyChartView.setOnSelectListener(
trapezoidIndex -> { trapezoidIndex -> {
if (mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) { if (mDailyChartIndex == SELECTED_INDEX_ALL) {
// This will happen when a daily slot and an hour slot are clicked together. // This will happen when a daily slot and an hour slot are clicked together.
return; return;
} }
@@ -327,10 +334,11 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
mHandler.post( mHandler.post(
() -> () ->
mHourlyChartView.setAccessibilityPaneTitle( mHourlyChartView.setAccessibilityPaneTitle(
getAccessibilityAnnounceMessage())); getAccessibilityAnnounceMessage(
mHourlyChartIndex != SELECTED_INDEX_ALL)));
mMetricsFeatureProvider.action( mMetricsFeatureProvider.action(
mPrefContext, mPrefContext,
trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL trapezoidIndex == SELECTED_INDEX_ALL
? SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL ? SettingsEnums.ACTION_BATTERY_USAGE_SHOW_ALL
: SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT, : SettingsEnums.ACTION_BATTERY_USAGE_TIME_SLOT,
mHourlyChartIndex); mHourlyChartIndex);
@@ -378,27 +386,27 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} else { } else {
mDailyChartView.setVisibility(View.VISIBLE); mDailyChartView.setVisibility(View.VISIBLE);
if (mDailyChartIndex >= mDailyViewModel.size()) { if (mDailyChartIndex >= mDailyViewModel.size()) {
mDailyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL; mDailyChartIndex = SELECTED_INDEX_ALL;
} }
mDailyViewModel.setSelectedIndex(mDailyChartIndex); mDailyViewModel.setSelectedIndex(mDailyChartIndex);
mDailyViewModel.setHighlightSlotIndex(mDailyHighlightSlotIndex); mDailyViewModel.setHighlightSlotIndex(mDailyHighlightSlotIndex);
mDailyChartView.setViewModel(mDailyViewModel); mDailyChartView.setViewModel(mDailyViewModel);
} }
if (mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) { if (mDailyChartIndex == SELECTED_INDEX_ALL) {
// Multiple days are selected, hide the hourly chart view. // Multiple days are selected, hide the hourly chart view.
animateBatteryHourlyChartView(/* visible= */ false); animateBatteryHourlyChartView(/* visible= */ false);
} else { } else {
animateBatteryHourlyChartView(/* visible= */ true); animateBatteryHourlyChartView(/* visible= */ true);
final BatteryChartViewModel hourlyViewModel = mHourlyViewModels.get(mDailyChartIndex); final BatteryChartViewModel hourlyViewModel = mHourlyViewModels.get(mDailyChartIndex);
if (mHourlyChartIndex >= hourlyViewModel.size()) { if (mHourlyChartIndex >= hourlyViewModel.size()) {
mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL; mHourlyChartIndex = SELECTED_INDEX_ALL;
} }
hourlyViewModel.setSelectedIndex(mHourlyChartIndex); hourlyViewModel.setSelectedIndex(mHourlyChartIndex);
hourlyViewModel.setHighlightSlotIndex( hourlyViewModel.setHighlightSlotIndex(
(mDailyChartIndex == mDailyHighlightSlotIndex) (mDailyChartIndex == mDailyHighlightSlotIndex)
? mHourlyHighlightSlotIndex ? mHourlyHighlightSlotIndex
: BatteryChartViewModel.SELECTED_INDEX_INVALID); : SELECTED_INDEX_INVALID);
mHourlyChartView.setViewModel(hourlyViewModel); mHourlyChartView.setViewModel(hourlyViewModel);
} }
} }
@@ -416,7 +424,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
isAccessibilityText isAccessibilityText
? mDailyViewModel.getContentDescription(mDailyChartIndex) ? mDailyViewModel.getContentDescription(mDailyChartIndex)
: mDailyViewModel.getFullText(mDailyChartIndex); : mDailyViewModel.getFullText(mDailyChartIndex);
if (mHourlyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) { if (mHourlyChartIndex == SELECTED_INDEX_ALL) {
return selectedDayText; return selectedDayText;
} }
@@ -441,15 +449,19 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return ""; return "";
} }
if (mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL if (mDailyChartIndex == SELECTED_INDEX_ALL || mHourlyChartIndex == SELECTED_INDEX_ALL) {
|| mHourlyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) {
return mDailyViewModel.getSlotBatteryLevelText(mDailyChartIndex); return mDailyViewModel.getSlotBatteryLevelText(mDailyChartIndex);
} }
return mHourlyViewModels.get(mDailyChartIndex).getSlotBatteryLevelText(mHourlyChartIndex); return mHourlyViewModels.get(mDailyChartIndex).getSlotBatteryLevelText(mHourlyChartIndex);
} }
private String getAccessibilityAnnounceMessage() { private String getAccessibilityAnnounceMessage(final boolean isSlotSelected) {
final String selectedInformation =
mPrefContext.getString(
isSlotSelected
? R.string.battery_chart_slot_status_selected
: R.string.battery_chart_slot_status_unselected);
final String slotInformation = getSlotInformation(/* isAccessibilityText= */ true); final String slotInformation = getSlotInformation(/* isAccessibilityText= */ true);
final String slotInformationMessage = final String slotInformationMessage =
slotInformation == null slotInformation == null
@@ -460,7 +472,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
final String batteryLevelPercentageMessage = getBatteryLevelPercentageInfo(); final String batteryLevelPercentageMessage = getBatteryLevelPercentageInfo();
return mPrefContext.getString( return mPrefContext.getString(
R.string.battery_usage_time_info_and_battery_level, R.string.battery_usage_status_time_info_and_battery_level,
selectedInformation,
slotInformationMessage, slotInformationMessage,
batteryLevelPercentageMessage); batteryLevelPercentageMessage);
} }
@@ -533,9 +546,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
} }
private boolean isAllSelected() { private boolean isAllSelected() {
return (isBatteryLevelDataInOneDay() return (isBatteryLevelDataInOneDay() || mDailyChartIndex == SELECTED_INDEX_ALL)
|| mDailyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) && mHourlyChartIndex == SELECTED_INDEX_ALL;
&& mHourlyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL;
} }
@VisibleForTesting @VisibleForTesting
@@ -571,9 +583,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return null; return null;
} }
BatteryDiffData allBatteryDiffData = BatteryDiffData allBatteryDiffData =
batteryUsageData batteryUsageData.get(SELECTED_INDEX_ALL).get(SELECTED_INDEX_ALL);
.get(BatteryChartViewModel.SELECTED_INDEX_ALL)
.get(BatteryChartViewModel.SELECTED_INDEX_ALL);
return allBatteryDiffData == null ? null : allBatteryDiffData.getAppDiffEntryList(); return allBatteryDiffData == null ? null : allBatteryDiffData.getAppDiffEntryList();
} }
@@ -613,12 +623,9 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
@Override @Override
public String generateSlotBatteryLevelText(List<Integer> levels, int index) { public String generateSlotBatteryLevelText(List<Integer> levels, int index) {
final int fromBatteryLevelIndex = final int fromBatteryLevelIndex = index == SELECTED_INDEX_ALL ? 0 : index;
index == BatteryChartViewModel.SELECTED_INDEX_ALL ? 0 : index;
final int toBatteryLevelIndex = final int toBatteryLevelIndex =
index == BatteryChartViewModel.SELECTED_INDEX_ALL index == SELECTED_INDEX_ALL ? levels.size() - 1 : index + 1;
? levels.size() - 1
: index + 1;
return mPrefContext.getString( return mPrefContext.getString(
R.string.battery_level_percentage, R.string.battery_level_percentage,
generateBatteryLevelText(levels.get(fromBatteryLevelIndex)), generateBatteryLevelText(levels.get(fromBatteryLevelIndex)),
@@ -687,9 +694,9 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
return index == timestamps.size() - 1 return index == timestamps.size() - 1
? generateText(timestamps, index) ? generateText(timestamps, index)
: mContext.getString( : mContext.getString(
R.string.battery_usage_timestamps_content_description, R.string.battery_usage_timestamps_content_description,
generateText(timestamps, index), generateText(timestamps, index),
generateText(timestamps, index + 1)); generateText(timestamps, index + 1));
} }
HourlyChartLabelTextGenerator updateSpecialCaseContext( HourlyChartLabelTextGenerator updateSpecialCaseContext(

View File

@@ -17,6 +17,8 @@ package com.android.settings.fuelgauge.batteryusage;
import static com.android.settings.Utils.formatPercentage; import static com.android.settings.Utils.formatPercentage;
import static com.android.settings.fuelgauge.batteryusage.BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS; import static com.android.settings.fuelgauge.batteryusage.BatteryChartViewModel.AxisLabelPosition.BETWEEN_TRAPEZOIDS;
import static com.android.settings.fuelgauge.batteryusage.BatteryChartViewModel.SELECTED_INDEX_ALL;
import static com.android.settings.fuelgauge.batteryusage.BatteryChartViewModel.SELECTED_INDEX_INVALID;
import static com.android.settingslib.fuelgauge.BatteryStatus.BATTERY_LEVEL_UNKNOWN; import static com.android.settingslib.fuelgauge.BatteryStatus.BATTERY_LEVEL_UNKNOWN;
import static java.lang.Math.abs; import static java.lang.Math.abs;
@@ -81,7 +83,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
getContext().getResources().getConfiguration().getLayoutDirection(); getContext().getResources().getConfiguration().getLayoutDirection();
private BatteryChartViewModel mViewModel; private BatteryChartViewModel mViewModel;
private int mHoveredIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID; private int mHoveredIndex = SELECTED_INDEX_INVALID;
private int mDividerWidth; private int mDividerWidth;
private int mDividerHeight; private int mDividerHeight;
private float mTrapezoidVOffset; private float mTrapezoidVOffset;
@@ -245,9 +247,9 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// sent here. // sent here.
return true; return true;
case MotionEvent.ACTION_HOVER_EXIT: case MotionEvent.ACTION_HOVER_EXIT:
if (mHoveredIndex != BatteryChartViewModel.SELECTED_INDEX_INVALID) { if (mHoveredIndex != SELECTED_INDEX_INVALID) {
sendAccessibilityEventForHover(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT); sendAccessibilityEventForHover(AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
mHoveredIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID; // reset mHoveredIndex = SELECTED_INDEX_INVALID; // reset
invalidate(); invalidate();
} }
// Ignore the super.onHoverEvent() because the hovered trapezoid has already been // Ignore the super.onHoverEvent() because the hovered trapezoid has already been
@@ -262,7 +264,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
public void onHoverChanged(boolean hovered) { public void onHoverChanged(boolean hovered) {
super.onHoverChanged(hovered); super.onHoverChanged(hovered);
if (!hovered) { if (!hovered) {
mHoveredIndex = BatteryChartViewModel.SELECTED_INDEX_INVALID; // reset mHoveredIndex = SELECTED_INDEX_INVALID; // reset
invalidate(); invalidate();
} }
} }
@@ -295,9 +297,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
if (mOnSelectListener != null) { if (mOnSelectListener != null) {
// Selects all if users click the same trapezoid item two times. // Selects all if users click the same trapezoid item two times.
mOnSelectListener.onSelect( mOnSelectListener.onSelect(
index == mViewModel.selectedIndex() index == mViewModel.selectedIndex() ? SELECTED_INDEX_ALL : index);
? BatteryChartViewModel.SELECTED_INDEX_ALL
: index);
} }
view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK); view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK);
} }
@@ -332,8 +332,8 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
setBackgroundColor(Color.TRANSPARENT); setBackgroundColor(Color.TRANSPARENT);
mTrapezoidSolidColor = Utils.getColorAccentDefaultColor(context); mTrapezoidSolidColor = Utils.getColorAccentDefaultColor(context);
mTrapezoidColor = Utils.getDisabled(context, mTrapezoidSolidColor); mTrapezoidColor = Utils.getDisabled(context, mTrapezoidSolidColor);
mTrapezoidHoverColor = context.getColor( mTrapezoidHoverColor =
com.android.internal.R.color.materialColorSecondaryContainer); context.getColor(com.android.internal.R.color.materialColorSecondaryContainer);
// Initializes the divider line paint. // Initializes the divider line paint.
final Resources resources = getContext().getResources(); final Resources resources = getContext().getResources();
mDividerWidth = resources.getDimensionPixelSize(R.dimen.chartview_divider_width); mDividerWidth = resources.getDimensionPixelSize(R.dimen.chartview_divider_width);
@@ -623,8 +623,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// Configures the trapezoid paint color. // Configures the trapezoid paint color.
final int trapezoidColor = final int trapezoidColor =
(mViewModel.selectedIndex() == index (mViewModel.selectedIndex() == index
|| mViewModel.selectedIndex() || mViewModel.selectedIndex() == SELECTED_INDEX_ALL)
== BatteryChartViewModel.SELECTED_INDEX_ALL)
? mTrapezoidSolidColor ? mTrapezoidSolidColor
: mTrapezoidColor; : mTrapezoidColor;
final boolean isHoverState = final boolean isHoverState =
@@ -659,9 +658,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
} }
private boolean isHighlightSlotValid() { private boolean isHighlightSlotValid() {
return mViewModel != null return mViewModel != null && mViewModel.getHighlightSlotIndex() != SELECTED_INDEX_INVALID;
&& mViewModel.getHighlightSlotIndex()
!= BatteryChartViewModel.SELECTED_INDEX_INVALID;
} }
private void drawTransomLine(Canvas canvas) { private void drawTransomLine(Canvas canvas) {
@@ -715,7 +712,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
// Searches the corresponding trapezoid index from x location. // Searches the corresponding trapezoid index from x location.
private int getTrapezoidIndex(float x) { private int getTrapezoidIndex(float x) {
if (mTrapezoidSlots == null) { if (mTrapezoidSlots == null) {
return BatteryChartViewModel.SELECTED_INDEX_INVALID; return SELECTED_INDEX_INVALID;
} }
for (int index = 0; index < mTrapezoidSlots.length; index++) { for (int index = 0; index < mTrapezoidSlots.length; index++) {
final TrapezoidSlot slot = mTrapezoidSlots[index]; final TrapezoidSlot slot = mTrapezoidSlots[index];
@@ -723,7 +720,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
return index; return index;
} }
} }
return BatteryChartViewModel.SELECTED_INDEX_INVALID; return SELECTED_INDEX_INVALID;
} }
private void initializeAxisLabelsBounds() { private void initializeAxisLabelsBounds() {
@@ -796,7 +793,11 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
childInfo.setText(slotTimeInfo); childInfo.setText(slotTimeInfo);
childInfo.setContentDescription( childInfo.setContentDescription(
mContext.getString( mContext.getString(
R.string.battery_usage_time_info_and_battery_level, R.string.battery_usage_status_time_info_and_battery_level,
mContext.getString(
mViewModel.selectedIndex() == virtualViewId
? R.string.battery_chart_slot_status_selected
: R.string.battery_chart_slot_status_unselected),
slotTimeInfo, slotTimeInfo,
batteryLevelInfo)); batteryLevelInfo));
childInfo.setAccessibilityFocused(virtualViewId == mAccessibilityFocusNodeViewId); childInfo.setAccessibilityFocused(virtualViewId == mAccessibilityFocusNodeViewId);