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

Commit 19798292 authored by Phil Weaver's avatar Phil Weaver
Browse files

Improve battery saver setting a11y semantics

Adding the ability to override a couple a11y traits
of the Settings version of SeekBarPreference.
Setting semantics for the battery level to report
itself as a percentage. Also tweaking the content
description to use a different title. The title isn't
exactly what I'd like, but it is better than just
saying "At 15% - 15%".

Bug: 74357845
Fixes: 78479637
Test: Used a custom accessibility service to inspect
the information coming from the battery saver seek bar.

Change-Id: I9db55cf0bb3cfee86a46d22c1208262407332d5f
parent ac951a69
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import android.view.accessibility.AccessibilityNodeInfo;

import com.android.settings.R;
import com.android.settings.Utils;
@@ -61,6 +62,8 @@ public class AutoBatterySeekBarPreferenceController extends BasePreferenceContro
        mPreference = (SeekBarPreference) screen.findPreference(
                KEY_AUTO_BATTERY_SEEK_BAR);
        mPreference.setContinuousUpdates(true);
        mPreference.setAccessibilityRangeInfoType(
                AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_PERCENT);
        updatePreference(mPreference);
    }

@@ -123,7 +126,10 @@ public class AutoBatterySeekBarPreferenceController extends BasePreferenceContro
            preference.setVisible(true);
            preference.setTitle(mContext.getString(R.string.battery_saver_seekbar_title,
                    Utils.formatPercentage(level)));
            ((SeekBarPreference) preference).setProgress(level);
            SeekBarPreference seekBarPreference = (SeekBarPreference) preference;
            seekBarPreference.setProgress(level);
            seekBarPreference.setSeekBarContentDescription(
                    mContext.getString(R.string.battery_saver_turn_on_automatically_title));
        }
    }

+37 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;

@@ -48,6 +49,8 @@ public class SeekBarPreference extends RestrictedPreference

    private SeekBar mSeekBar;
    private boolean mShouldBlink;
    private int mAccessibilityRangeInfoType = AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT;
    private CharSequence mSeekBarContentDescription;

    public SeekBarPreference(
            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@@ -100,7 +103,9 @@ public class SeekBarPreference extends RestrictedPreference
        mSeekBar.setProgress(mProgress);
        mSeekBar.setEnabled(isEnabled());
        final CharSequence title = getTitle();
        if (!TextUtils.isEmpty(title)) {
        if (!TextUtils.isEmpty(mSeekBarContentDescription)) {
            mSeekBar.setContentDescription(mSeekBarContentDescription);
        } else if (!TextUtils.isEmpty(title)) {
            mSeekBar.setContentDescription(title);
        }
        if (mSeekBar instanceof DefaultIndicatorSeekBar) {
@@ -119,6 +124,19 @@ public class SeekBarPreference extends RestrictedPreference
                mShouldBlink = false;
            });
        }
        mSeekBar.setAccessibilityDelegate(new View.AccessibilityDelegate() {
            @Override
            public void onInitializeAccessibilityNodeInfo(View view, AccessibilityNodeInfo info) {
                super.onInitializeAccessibilityNodeInfo(view, info);
                // Update the range info with the correct type
                AccessibilityNodeInfo.RangeInfo rangeInfo = info.getRangeInfo();
                if (rangeInfo != null) {
                    info.setRangeInfo(AccessibilityNodeInfo.RangeInfo.obtain(
                                    mAccessibilityRangeInfoType, rangeInfo.getMin(),
                                    rangeInfo.getMax(), rangeInfo.getCurrent()));
                }
            }
        });
    }

    @Override
@@ -252,6 +270,24 @@ public class SeekBarPreference extends RestrictedPreference
        }
    }

    /**
     * Specify the type of range this seek bar represents.
     *
     * @param rangeInfoType The type of range to be shared with accessibility
     *
     * @see android.view.accessibility.AccessibilityNodeInfo.RangeInfo
     */
    public void setAccessibilityRangeInfoType(int rangeInfoType) {
        mAccessibilityRangeInfoType = rangeInfoType;
    }

    public void setSeekBarContentDescription(CharSequence contentDescription) {
        mSeekBarContentDescription = contentDescription;
        if (mSeekBar != null) {
            mSeekBar.setContentDescription(contentDescription);
        }
    }

    @Override
    protected Parcelable onSaveInstanceState() {
        /*