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

Commit 499f965c authored by Michael Mikhail's avatar Michael Mikhail
Browse files

Add content description to volume title in settings.

Adds content description that is announced by talkback when a11y focus
is on volume preference. This improves talkback announcement when view changes.

Fixes: 285529113
Bug: 285455826
Fixes: 285487766
Test: atest VolumeSeekBarPreferenceControllerTest
Test: atest VolumeSeekBarPreferenceTest
Change-Id: Ibe80b4b1d489dc058df1cc79c96b034d5ddc6e56
parent b452bc9f
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -7151,6 +7151,18 @@
    <!-- Sound: Title for the option managing notification volume. [CHAR LIMIT=30] -->
    <string name="notification_volume_option_title">Notification volume</string>
    <!-- Sound: Content description of ring volume title in silent mode. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=8994620163934249882] -->
    <string name="ringer_content_description_silent_mode">Ringer silent</string>
    <!-- Sound: Content description of ring volume title in vibrate mode. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=6261841170896561364] -->
    <string name="ringer_content_description_vibrate_mode">Ringer vibrate</string>
    <!-- Sound: Content description of notification volume title in vibrate mode. [CHAR LIMIT=NONE] -->
    <string name="notification_volume_content_description_vibrate_mode">Notification volume muted, notifications will vibrate</string>
    <!-- Sound: Content description of volume title in silent mode [CHAR LIMIT=NONE] -->
    <string name="volume_content_description_silent_mode"> <xliff:g id="volume type" example="notification volume">%1$s</xliff:g> muted</string>
    <!-- Sound: Summary for when notification volume is disabled. [CHAR LIMIT=100] -->
    <string name="notification_volume_disabled_summary">Unavailable because ring is muted</string>
+13 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceCont

    public MediaVolumePreferenceController(Context context) {
        super(context, KEY_MEDIA_VOLUME);
        mVolumePreferenceListener = this::updateContentDescription;
    }

    @Override
@@ -109,6 +110,18 @@ public class MediaVolumePreferenceController extends VolumeSeekBarPreferenceCont
        return false;
    }

    private void updateContentDescription() {
        if (mPreference != null) {
            if (mPreference.isMuted()) {
                mPreference.updateContentDescription(
                        mContext.getString(R.string.volume_content_description_silent_mode,
                        mPreference.getTitle()));
            } else {
                mPreference.updateContentDescription(mPreference.getTitle());
            }
        }
    }

    @Override
    public SliceAction getSliceEndItem(Context context) {
        if (!isSupportEndItem()) {
+27 −16
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ public class NotificationVolumePreferenceController extends

        updateEffectsSuppressor();
        selectPreferenceIconState();
        updateContentDescription();
        updateEnabledState();
    }

@@ -120,23 +121,32 @@ public class NotificationVolumePreferenceController extends
    }

    @Override
    protected void selectPreferenceIconState() {
        if (mPreference != null) {
            if (mVibrator != null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
                mMuteIcon = mVibrateIconId;
                mPreference.showIcon(mVibrateIconId);
            } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT
                    || mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
                mMuteIcon = mSilentIconId;
                mPreference.showIcon(mSilentIconId);
            } else { // ringmode normal: could be that we are still silent
    protected int getEffectiveRingerMode() {
        if (mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
            return AudioManager.RINGER_MODE_SILENT;
        } else if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
            if (mHelper.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
                    // ring is in normal, but notification is in silent
                    mMuteIcon = mSilentIconId;
                    mPreference.showIcon(mSilentIconId);
                } else {
                    mPreference.showIcon(mNormalIconId);
                // Ring is in normal, but notification is in silent.
                return AudioManager.RINGER_MODE_SILENT;
            }
        }
        return mRingerMode;
    }

    @Override
    protected void updateContentDescription() {
        if (mPreference != null) {
            int ringerMode = getEffectiveRingerMode();
            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
                mPreference.updateContentDescription(
                        mContext.getString(
                                R.string.notification_volume_content_description_vibrate_mode));
            } else if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
                mPreference.updateContentDescription(
                        mContext.getString(R.string.volume_content_description_silent_mode,
                                mPreference.getTitle()));
            } else {
                mPreference.updateContentDescription(mPreference.getTitle());
            }
        }
    }
@@ -169,6 +179,7 @@ public class NotificationVolumePreferenceController extends
                    break;
                case NOTIFICATION_VOLUME_CHANGED:
                    selectPreferenceIconState();
                    updateContentDescription();
                    updateEnabledState();
                    break;
            }
+28 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Vibrator;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;

import java.util.Objects;

@@ -54,6 +55,7 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
        if (mVibrator != null && !mVibrator.hasVibrator()) {
            mVibrator = null;
        }
        mVolumePreferenceListener = this::updateContentDescription;
    }

    protected void updateEffectsSuppressor() {
@@ -123,6 +125,7 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
        }
        mRingerMode = ringerMode;
        selectPreferenceIconState();
        updateContentDescription();
        return true;
    }

@@ -131,10 +134,11 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
     */
    protected void selectPreferenceIconState() {
        if (mPreference != null) {
            if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
            int ringerMode = getEffectiveRingerMode();
            if (ringerMode == AudioManager.RINGER_MODE_NORMAL) {
                mPreference.showIcon(mNormalIconId);
            } else {
                if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE && mVibrator != null) {
                if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
                    mMuteIcon = mVibrateIconId;
                } else {
                    mMuteIcon = mSilentIconId;
@@ -144,6 +148,28 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
        }
    }

    protected int getEffectiveRingerMode() {
        if (mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
            return AudioManager.RINGER_MODE_SILENT;
        }
        return mRingerMode;
    }

    protected void updateContentDescription() {
        if (mPreference != null) {
            int ringerMode = getEffectiveRingerMode();
            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
                mPreference.updateContentDescription(
                        mContext.getString(R.string.ringer_content_description_vibrate_mode));
            } else if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
                mPreference.updateContentDescription(
                        mContext.getString(R.string.ringer_content_description_silent_mode));
            } else {
                mPreference.updateContentDescription(mPreference.getTitle());
            }
        }
    }

    protected abstract boolean hintsMatch(int hints);

}
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public class SeparateRingVolumePreferenceController extends
        mReceiver.register(true);
        updateEffectsSuppressor();
        selectPreferenceIconState();
        updateContentDescription();

        if (mPreference != null) {
            mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
Loading