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

Commit 6a4bf6a3 authored by Anthony Tripaldi's avatar Anthony Tripaldi Committed by Android (Google) Code Review
Browse files

Merge "Updating accessibility content for buttons in SysUI for captions" into qt-dev

parents c1a0fbce d7962fb0
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -1331,6 +1331,14 @@
    <!-- Content description for accessibility: Clear the odi caption tool tip. [CHAR LIMIT=NONE] -->
    <string name="accessibility_volume_close_odi_captions_tip">Close captions tip</string>

    <!-- Content description for accessibility: Captions button. [CHAR LIMIT=NONE] -->
    <string name="volume_odi_captions_content_description">Captions overlay</string>

    <!-- Content description for accessibility: Hint if click will enable. [CHAR LIMIT=NONE] -->
    <string name="volume_odi_captions_hint_enable">enable</string>
    <!-- Content description for accessibility: Hint if click will disable. [CHAR LIMIT=NONE] -->
    <string name="volume_odi_captions_hint_disable">disable</string>

    <!-- content description for audio output chooser [CHAR LIMIT=NONE]-->
    <string name="accessibility_output_chooser">Switch output device</string>

+28 −11
Original line number Diff line number Diff line
@@ -22,6 +22,9 @@ import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;

import androidx.core.view.ViewCompat;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat.AccessibilityActionCompat;

import com.android.keyguard.AlphaOptimizedImageButton;
import com.android.systemui.R;

@@ -31,7 +34,7 @@ public class CaptionsToggleImageButton extends AlphaOptimizedImageButton {
    private static final int[] OPTED_OUT_STATE = new int[] { R.attr.optedOut };

    private ConfirmedTapListener mConfirmedTapListener;
    private boolean mComponentEnabled = false;
    private boolean mCaptionsEnabled = false;
    private boolean mOptedOut = false;

    private GestureDetector mGestureDetector;
@@ -39,16 +42,14 @@ public class CaptionsToggleImageButton extends AlphaOptimizedImageButton {
            new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (mConfirmedTapListener != null) {
                mConfirmedTapListener.onConfirmedTap();
                return true;
            }
            return false;
            return tryToSendTapConfirmedEvent();
        }
    };

    public CaptionsToggleImageButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setContentDescription(
                getContext().getString(R.string.volume_odi_captions_content_description));
    }

    @Override
@@ -66,16 +67,32 @@ public class CaptionsToggleImageButton extends AlphaOptimizedImageButton {
        return state;
    }

    Runnable setComponentEnabled(boolean isComponentEnabled) {
        this.mComponentEnabled = isComponentEnabled;
    Runnable setCaptionsEnabled(boolean areCaptionsEnabled) {
        this.mCaptionsEnabled = areCaptionsEnabled;

        ViewCompat.replaceAccessibilityAction(
                this,
                AccessibilityActionCompat.ACTION_CLICK,
                mCaptionsEnabled
                        ? getContext().getString(R.string.volume_odi_captions_hint_disable)
                        : getContext().getString(R.string.volume_odi_captions_hint_enable),
                (view, commandArguments) -> tryToSendTapConfirmedEvent());

        return this.setImageResourceAsync(this.mComponentEnabled
        return this.setImageResourceAsync(mCaptionsEnabled
                ? R.drawable.ic_volume_odi_captions
                : R.drawable.ic_volume_odi_captions_disabled);
    }

    boolean getComponentEnabled() {
        return this.mComponentEnabled;
    private boolean tryToSendTapConfirmedEvent() {
        if (mConfirmedTapListener != null) {
            mConfirmedTapListener.onConfirmedTap();
            return true;
        }
        return false;
    }

    boolean getCaptionsEnabled() {
        return this.mCaptionsEnabled;
    }

    /** Sets whether or not the current stream has opted out of captions */
+3 −4
Original line number Diff line number Diff line
@@ -596,9 +596,9 @@ public class VolumeDialogImpl implements VolumeDialog,
    }

    private void updateCaptionsIcon() {
        boolean componentEnabled = mController.areCaptionsEnabled();
        if (mODICaptionsIcon.getComponentEnabled() != componentEnabled) {
            mHandler.post(mODICaptionsIcon.setComponentEnabled(componentEnabled));
        boolean captionsEnabled = mController.areCaptionsEnabled();
        if (mODICaptionsIcon.getCaptionsEnabled() != captionsEnabled) {
            mHandler.post(mODICaptionsIcon.setCaptionsEnabled(captionsEnabled));
        }

        boolean isOptedOut = mController.isCaptionStreamOptedOut();
@@ -878,7 +878,6 @@ public class VolumeDialogImpl implements VolumeDialog,
        }

        view.setContentDescription(mContext.getString(currStateResId));

        view.setAccessibilityDelegate(new AccessibilityDelegate() {
            public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
                super.onInitializeAccessibilityNodeInfo(host, info);