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

Commit 6f76d5dc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix b/265746746: Announce "Battery usage for [slot_timestamp]" instead...

Merge "Fix b/265746746: Announce "Battery usage for [slot_timestamp]" instead of changing focus when Talk Back on."
parents 8a913f79 e04ffdea
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@

    </PreferenceCategory>

    <com.android.settings.fuelgauge.batteryusage.AccessibilityFocusablePreferenceCategory
    <PreferenceCategory
        android:key="battery_usage_breakdown"
        settings:controller=
            "com.android.settings.fuelgauge.batteryusage.BatteryUsageBreakdownController"
@@ -58,5 +58,5 @@
            settings:isPreferenceVisible="false"
            settings:searchable="false" />

    </com.android.settings.fuelgauge.batteryusage.AccessibilityFocusablePreferenceCategory>
    </PreferenceCategory>
</PreferenceScreen>
+0 −68
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.fuelgauge.batteryusage;

import android.content.Context;
import android.util.AttributeSet;
import android.view.accessibility.AccessibilityManager;

import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceViewHolder;

/**
 * Preference category that supports requesting accessibility focus.
 */
public class AccessibilityFocusablePreferenceCategory extends PreferenceCategory {
    private PreferenceViewHolder mView;

    public AccessibilityFocusablePreferenceCategory(Context context, AttributeSet attrs,
            int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    public AccessibilityFocusablePreferenceCategory(Context context, AttributeSet attrs,
            int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public AccessibilityFocusablePreferenceCategory(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public AccessibilityFocusablePreferenceCategory(Context context) {
        super(context);
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder view) {
        super.onBindViewHolder(view);
        mView = view;
    }

    /**
     * Call this to try to give accessibility focus to the category title.
     */
    public void requestAccessibilityFocus() {
        if (mView == null || mView.itemView == null) {
            return;
        }
        if (!AccessibilityManager.getInstance(getContext()).isEnabled()) {
            return;
        }
        mView.itemView.requestAccessibilityFocus();
    }
}
+13 −0
Original line number Diff line number Diff line
@@ -296,6 +296,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
            mDailyChartIndex = trapezoidIndex;
            mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
            refreshUi();
            mHandler.post(() -> mDailyChartView.announceForAccessibility(
                    getAccessibilityAnnounceMessage()));
            mMetricsFeatureProvider.action(
                    mPrefContext,
                    trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
@@ -311,6 +313,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
            Log.d(TAG, "onHourlyChartSelect:" + trapezoidIndex);
            mHourlyChartIndex = trapezoidIndex;
            refreshUi();
            mHandler.post(() -> mHourlyChartView.announceForAccessibility(
                    getAccessibilityAnnounceMessage()));
            mMetricsFeatureProvider.action(
                    mPrefContext,
                    trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
@@ -439,6 +443,15 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
        return String.format("%s %s", selectedDayText, selectedHourText);
    }

    private String getAccessibilityAnnounceMessage() {
        final String slotInformation = getSlotInformation();
        return slotInformation == null
                ? mPrefContext.getString(
                       R.string.battery_usage_breakdown_title_since_last_full_charge)
                : mPrefContext.getString(
                        R.string.battery_usage_breakdown_title_for_slot, slotInformation);
    }

    private void animateBatteryChartViewGroup() {
        if (mBatteryChartViewGroup != null && mBatteryChartViewGroup.getAlpha() == 0) {
            mBatteryChartViewGroup.animate().alpha(1f).setDuration(FADE_IN_ANIMATION_DURATION)
+2 −4
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.View;
import android.widget.AdapterView;

import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;

@@ -74,7 +75,7 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
    @VisibleForTesting
    Context mPrefContext;
    @VisibleForTesting
    AccessibilityFocusablePreferenceCategory mRootPreference;
    PreferenceCategory mRootPreference;
    @VisibleForTesting
    SpinnerPreference mSpinnerPreference;
    @VisibleForTesting
@@ -203,9 +204,6 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
                : mPrefContext.getString(
                        R.string.battery_usage_breakdown_title_for_slot, slotTimestamp));
        mRootPreference.setVisible(true);
        mHandler.post(() -> {
            mRootPreference.requestAccessibilityFocus();
        });
    }

    private void showFooterPreference(boolean isAllBatteryUsageEmpty, String slotTimestamp) {