Fix b/265746746: Announce "Battery usage for [slot_timestamp]" instead of changing focus when Talk Back on.
https://drive.google.com/file/d/173RPKsnIE7ZhBAJLrivqkbiWg9Ay41bC/view?usp=sharing&resourcekey=0-jHJ7vZ9BEhzxdWncqCQVQg Bug: 265746746 Fix: 265746746 Test: manual Change-Id: Iad92eff50d73853793daa9d6d3551768678c2eb2
This commit is contained in:
@@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<com.android.settings.fuelgauge.batteryusage.AccessibilityFocusablePreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="battery_usage_breakdown"
|
android:key="battery_usage_breakdown"
|
||||||
settings:controller=
|
settings:controller=
|
||||||
"com.android.settings.fuelgauge.batteryusage.BatteryUsageBreakdownController"
|
"com.android.settings.fuelgauge.batteryusage.BatteryUsageBreakdownController"
|
||||||
@@ -58,5 +58,5 @@
|
|||||||
settings:isPreferenceVisible="false"
|
settings:isPreferenceVisible="false"
|
||||||
settings:searchable="false" />
|
settings:searchable="false" />
|
||||||
|
|
||||||
</com.android.settings.fuelgauge.batteryusage.AccessibilityFocusablePreferenceCategory>
|
</PreferenceCategory>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
@@ -1,68 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
}
|
|
@@ -296,6 +296,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
mDailyChartIndex = trapezoidIndex;
|
mDailyChartIndex = trapezoidIndex;
|
||||||
mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
|
mHourlyChartIndex = BatteryChartViewModel.SELECTED_INDEX_ALL;
|
||||||
refreshUi();
|
refreshUi();
|
||||||
|
mHandler.post(() -> mDailyChartView.announceForAccessibility(
|
||||||
|
getAccessibilityAnnounceMessage()));
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(
|
||||||
mPrefContext,
|
mPrefContext,
|
||||||
trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
|
trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
|
||||||
@@ -311,6 +313,8 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
Log.d(TAG, "onHourlyChartSelect:" + trapezoidIndex);
|
Log.d(TAG, "onHourlyChartSelect:" + trapezoidIndex);
|
||||||
mHourlyChartIndex = trapezoidIndex;
|
mHourlyChartIndex = trapezoidIndex;
|
||||||
refreshUi();
|
refreshUi();
|
||||||
|
mHandler.post(() -> mHourlyChartView.announceForAccessibility(
|
||||||
|
getAccessibilityAnnounceMessage()));
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(
|
||||||
mPrefContext,
|
mPrefContext,
|
||||||
trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
|
trapezoidIndex == BatteryChartViewModel.SELECTED_INDEX_ALL
|
||||||
@@ -439,6 +443,15 @@ public class BatteryChartPreferenceController extends AbstractPreferenceControll
|
|||||||
return String.format("%s %s", selectedDayText, selectedHourText);
|
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() {
|
private void animateBatteryChartViewGroup() {
|
||||||
if (mBatteryChartViewGroup != null && mBatteryChartViewGroup.getAlpha() == 0) {
|
if (mBatteryChartViewGroup != null && mBatteryChartViewGroup.getAlpha() == 0) {
|
||||||
mBatteryChartViewGroup.animate().alpha(1f).setDuration(FADE_IN_ANIMATION_DURATION)
|
mBatteryChartViewGroup.animate().alpha(1f).setDuration(FADE_IN_ANIMATION_DURATION)
|
||||||
|
@@ -27,6 +27,7 @@ import android.view.View;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceGroup;
|
import androidx.preference.PreferenceGroup;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
@@ -74,7 +75,7 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
Context mPrefContext;
|
Context mPrefContext;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
AccessibilityFocusablePreferenceCategory mRootPreference;
|
PreferenceCategory mRootPreference;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
SpinnerPreference mSpinnerPreference;
|
SpinnerPreference mSpinnerPreference;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -203,9 +204,6 @@ public class BatteryUsageBreakdownController extends BasePreferenceController
|
|||||||
: mPrefContext.getString(
|
: mPrefContext.getString(
|
||||||
R.string.battery_usage_breakdown_title_for_slot, slotTimestamp));
|
R.string.battery_usage_breakdown_title_for_slot, slotTimestamp));
|
||||||
mRootPreference.setVisible(true);
|
mRootPreference.setVisible(true);
|
||||||
mHandler.post(() -> {
|
|
||||||
mRootPreference.requestAccessibilityFocus();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showFooterPreference(boolean isAllBatteryUsageEmpty, String slotTimestamp) {
|
private void showFooterPreference(boolean isAllBatteryUsageEmpty, String slotTimestamp) {
|
||||||
|
Reference in New Issue
Block a user