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

Commit 2e12d349 authored by Tom Natan's avatar Tom Natan Committed by Android (Google) Code Review
Browse files

Merge "[16/n] Letterbox Education: focus on the dialog title for accessibility." into tm-dev

parents ecd166ee 3beba95a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

@@ -38,6 +39,7 @@ class LetterboxEduDialogLayout extends ConstraintLayout {
    // 204 is simply 255 * 0.8.
    static final int BACKGROUND_DIM_ALPHA = 204;
    private View mDialogContainer;
    private TextView mDialogTitle;
    private Drawable mBackgroundDim;

    public LetterboxEduDialogLayout(Context context) {
@@ -61,6 +63,10 @@ class LetterboxEduDialogLayout extends ConstraintLayout {
        return mDialogContainer;
    }

    TextView getDialogTitle() {
        return mDialogTitle;
    }

    Drawable getBackgroundDim() {
        return mBackgroundDim;
    }
@@ -84,6 +90,7 @@ class LetterboxEduDialogLayout extends ConstraintLayout {
    protected void onFinishInflate() {
        super.onFinishInflate();
        mDialogContainer = findViewById(R.id.letterbox_education_dialog_container);
        mDialogTitle = findViewById(R.id.letterbox_education_dialog_title);
        mBackgroundDim = getBackground().mutate();
        // Set the alpha of the background dim to 0 for enter animation.
        mBackgroundDim.setAlpha(0);
+5 −2
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;

import com.android.internal.annotations.VisibleForTesting;
import com.android.wm.shell.R;
@@ -132,7 +133,7 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {
        updateDialogMargins();

        mAnimationController.startEnterAnimation(mLayout, /* endCallback= */
                this::setDismissOnClickListener);
                this::onDialogEnterAnimationEnded);

        return mLayout;
    }
@@ -157,11 +158,13 @@ public class LetterboxEduWindowManager extends CompatUIWindowManagerAbstract {
                R.layout.letterbox_education_dialog_layout, null);
    }

    private void setDismissOnClickListener() {
    private void onDialogEnterAnimationEnded() {
        if (mLayout == null) {
            return;
        }
        mLayout.setDismissOnClickListener(this::onDismiss);
        // Focus on the dialog title for accessibility.
        mLayout.getDialogTitle().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    private void onDismiss() {
+2 −0
Original line number Diff line number Diff line
@@ -70,6 +70,8 @@ public class LetterboxEduDialogLayoutTest extends ShellTestCase {
    public void testOnFinishInflate() {
        assertEquals(mLayout.getDialogContainer(),
                mLayout.findViewById(R.id.letterbox_education_dialog_container));
        assertEquals(mLayout.getDialogTitle(),
                mLayout.findViewById(R.id.letterbox_education_dialog_title));
        assertEquals(mLayout.getBackgroundDim(), mLayout.getBackground());
        assertEquals(mLayout.getBackground().getAlpha(), 0);
    }
+8 −0
Original line number Diff line number Diff line
@@ -41,9 +41,11 @@ import android.testing.AndroidTestingRunner;
import android.view.DisplayCutout;
import android.view.DisplayInfo;
import android.view.SurfaceControlViewHost;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;

import androidx.test.filters.SmallTest;

@@ -173,13 +175,19 @@ public class LetterboxEduWindowManagerTest extends ShellTestCase {
        verifyLayout(layout, mWindowAttrsCaptor.getValue(), /* expectedWidth= */ TASK_WIDTH,
                /* expectedHeight= */ TASK_HEIGHT, /* expectedExtraTopMargin= */ DISPLAY_CUTOUT_TOP,
                /* expectedExtraBottomMargin= */ DISPLAY_CUTOUT_BOTTOM);
        View dialogTitle = layout.getDialogTitle();
        assertNotNull(dialogTitle);
        spyOn(dialogTitle);

        // Clicking the layout does nothing until enter animation is done.
        layout.performClick();
        verify(mAnimationController, never()).startExitAnimation(any(), any());
        // The dialog title shouldn't be focused for Accessibility until enter animation is done.
        verify(dialogTitle, never()).sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);

        verifyAndFinishEnterAnimation(layout);

        verify(dialogTitle).sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
        // Exit animation should start following a click on the layout.
        layout.performClick();