Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 39506320 authored by mxyyiyi's avatar mxyyiyi
Browse files

Help talkback to read the hyphen of time frame '{day}{time}-{time}'

Talkback Hover: https://screenshot.googleplex.com/6Z5KMhXRPRWrqh9
Talkback Click: https://screenshot.googleplex.com/5iYVWXE95rgH98D

Bug: 322855775
Test: atest SettingsRoboTests:com.android.settings.fuelgauge.batteryusage
Change-Id: I54b78e9e29c67d514c0346ddae8331450bf53f01
parent 66098635
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6080,6 +6080,8 @@
    <string name="battery_usage_chart_label_now">now</string>
    <!-- [CHAR_LIMIT=NONE] A hyphen for two timestamps. For example, "6 AM - 8 AM", which means "from 6 AM to 8 AM". Please notice the spaces around the hyphen -->
    <string name="battery_usage_timestamps_hyphen"><xliff:g id="from_timestamp">%1$s</xliff:g> - <xliff:g id="to_timestamp">%2$s</xliff:g></string>
    <!-- [CHAR_LIMIT=NONE] Accessibility content description for two timestamps. For example, Battery usage for "6 AM to 8 PM" -->
    <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"). -->
    <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. -->
+26 −4
Original line number Diff line number Diff line
@@ -404,7 +404,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
        }
    }

    String getSlotInformation() {
    String getSlotInformation(boolean isAccessibilityText) {
        if (mDailyViewModel == null || mHourlyViewModels == null) {
            // No data
            return null;
@@ -413,13 +413,20 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
            return null;
        }

        final String selectedDayText = mDailyViewModel.getFullText(mDailyChartIndex);
        final String selectedDayText =
                isAccessibilityText
                        ? mDailyViewModel.getContentDescription(mDailyChartIndex)
                        : mDailyViewModel.getFullText(mDailyChartIndex);
        if (mHourlyChartIndex == BatteryChartViewModel.SELECTED_INDEX_ALL) {
            return selectedDayText;
        }

        final String selectedHourText =
                mHourlyViewModels.get(mDailyChartIndex).getFullText(mHourlyChartIndex);
                isAccessibilityText
                        ? mHourlyViewModels
                                .get(mDailyChartIndex)
                                .getContentDescription(mHourlyChartIndex)
                        : mHourlyViewModels.get(mDailyChartIndex).getFullText(mHourlyChartIndex);
        if (isBatteryLevelDataInOneDay()) {
            return selectedHourText;
        }
@@ -444,7 +451,7 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
    }

    private String getAccessibilityAnnounceMessage() {
        final String slotInformation = getSlotInformation();
        final String slotInformation = getSlotInformation(/* isAccessibilityText= */ true);
        final String slotInformationMessage =
                slotInformation == null
                        ? mPrefContext.getString(
@@ -600,6 +607,11 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll

    private abstract class BaseLabelTextGenerator
            implements BatteryChartViewModel.LabelTextGenerator {
        @Override
        public String generateContentDescription(List<Long> timestamps, int index) {
            return generateFullText(timestamps, index);
        }

        @Override
        public String generateSlotBatteryLevelText(List<Integer> levels, int index) {
            final int fromBatteryLevelIndex =
@@ -673,6 +685,16 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
                            generateText(timestamps, index + 1));
        }

        @Override
        public String generateContentDescription(List<Long> timestamps, int index) {
            return index == timestamps.size() - 1
                    ? generateText(timestamps, index)
                    : mContext.getString(
                    R.string.battery_usage_timestamps_content_description,
                    generateText(timestamps, index),
                    generateText(timestamps, index + 1));
        }

        HourlyChartLabelTextGenerator updateSpecialCaseContext(
                @NonNull final BatteryLevelData batteryLevelData) {
            BatteryLevelData.PeriodBatteryLevelData firstDayLevelData =
+1 −1
Original line number Diff line number Diff line
@@ -784,7 +784,7 @@ public class BatteryChartView extends AppCompatImageView implements View.OnClick
            }
            final AccessibilityNodeInfo childInfo =
                    new AccessibilityNodeInfo(BatteryChartView.this, index);
            final String slotTimeInfo = mViewModel.getFullText(index);
            final String slotTimeInfo = mViewModel.getContentDescription(index);
            final String batteryLevelInfo = mViewModel.getSlotBatteryLevelText(index);
            onInitializeAccessibilityNodeInfo(childInfo);
            childInfo.setClickable(isValidToDraw(mViewModel, index));
+14 −1
Original line number Diff line number Diff line
@@ -43,9 +43,12 @@ class BatteryChartViewModel {
        /** Generates the label text. The text may be abbreviated to save space. */
        String generateText(List<Long> timestamps, int index);

        /** Generates the full text for accessibility. */
        /** Generates the full text for slot information. */
        String generateFullText(List<Long> timestamps, int index);

        /** Generates the full text for accessibility. */
        String generateContentDescription(List<Long> timestamps, int index);

        /** Generates the battery level text of a slot for accessibility.*/
        String generateSlotBatteryLevelText(List<Integer> levels, int index);
    }
@@ -56,6 +59,7 @@ class BatteryChartViewModel {
    private final LabelTextGenerator mLabelTextGenerator;
    private final String[] mTexts;
    private final String[] mFullTexts;
    private final String[] mContentDescription;
    private final String[] mBatteryLevelTexts;

    private int mSelectedIndex = SELECTED_INDEX_ALL;
@@ -79,6 +83,7 @@ class BatteryChartViewModel {
        mLabelTextGenerator = labelTextGenerator;
        mTexts = new String[size()];
        mFullTexts = new String[size()];
        mContentDescription = new String[size()];
        // Last one for SELECTED_INDEX_ALL
        mBatteryLevelTexts = new String[size() + 1];
    }
@@ -105,6 +110,14 @@ class BatteryChartViewModel {
        return mFullTexts[index];
    }

    public String getContentDescription(int index) {
        if (mContentDescription[index] == null) {
            mContentDescription[index] =
                    mLabelTextGenerator.generateContentDescription(mTimestamps, index);
        }
        return mContentDescription[index];
    }

    public String getSlotBatteryLevelText(int index) {
        final int textIndex = index != SELECTED_INDEX_ALL ? index : size();
        if (mBatteryLevelTexts[textIndex] == null) {
+3 −1
Original line number Diff line number Diff line
@@ -239,7 +239,9 @@ public class PowerUsageAdvanced extends PowerUsageBase {
        }
        final int dailyIndex = mBatteryChartPreferenceController.getDailyChartIndex();
        final int hourlyIndex = mBatteryChartPreferenceController.getHourlyChartIndex();
        final String slotInformation = mBatteryChartPreferenceController.getSlotInformation();
        final String slotInformation =
                mBatteryChartPreferenceController.getSlotInformation(
                        /* isAccessibilityText= */ false);
        final BatteryDiffData slotUsageData = mBatteryUsageMap.get(dailyIndex).get(hourlyIndex);
        mScreenOnTimeController.handleSceenOnTimeUpdated(
                slotUsageData != null ? slotUsageData.getScreenOnTime() : 0L, slotInformation);
Loading