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

Commit 0bf97658 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Ensure a11y long click works on notif guts." into rvc-dev am: 088de38a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11682753

Change-Id: I3cc82d85ea5ff0d668e37288897d8a7c0960f684
parents 5d3425d9 088de38a
Loading
Loading
Loading
Loading
+3 −14
Original line number Original line Diff line number Diff line
@@ -52,7 +52,7 @@ public class AppOpsInfo extends LinearLayout implements NotificationGuts.GutsCon
    private NotificationGuts mGutsContainer;
    private NotificationGuts mGutsContainer;


    private OnClickListener mOnOk = v -> {
    private OnClickListener mOnOk = v -> {
        closeControls(v);
        mGutsContainer.closeControls(v, false);
    };
    };


    public AppOpsInfo(Context context, AttributeSet attrs) {
    public AppOpsInfo(Context context, AttributeSet attrs) {
@@ -117,6 +117,7 @@ public class AppOpsInfo extends LinearLayout implements NotificationGuts.GutsCon
        });
        });
        TextView ok = findViewById(R.id.ok);
        TextView ok = findViewById(R.id.ok);
        ok.setOnClickListener(mOnOk);
        ok.setOnClickListener(mOnOk);
        ok.setAccessibilityDelegate(mGutsContainer.getAccessibilityDelegate());
    }
    }


    private String getPrompt() {
    private String getPrompt() {
@@ -160,19 +161,6 @@ public class AppOpsInfo extends LinearLayout implements NotificationGuts.GutsCon
        }
        }
    }
    }


    private void closeControls(View v) {
        mMetricsLogger.visibility(MetricsEvent.APP_OPS_GUTS, false);
        int[] parentLoc = new int[2];
        int[] targetLoc = new int[2];
        mGutsContainer.getLocationOnScreen(parentLoc);
        v.getLocationOnScreen(targetLoc);
        final int centerX = v.getWidth() / 2;
        final int centerY = v.getHeight() / 2;
        final int x = targetLoc[0] - parentLoc[0] + centerX;
        final int y = targetLoc[1] - parentLoc[1] + centerY;
        mGutsContainer.closeControls(x, y, false, false);
    }

    @Override
    @Override
    public void setGutsParent(NotificationGuts guts) {
    public void setGutsParent(NotificationGuts guts) {
        mGutsContainer = guts;
        mGutsContainer = guts;
@@ -200,6 +188,7 @@ public class AppOpsInfo extends LinearLayout implements NotificationGuts.GutsCon


    @Override
    @Override
    public boolean handleCloseControls(boolean save, boolean force) {
    public boolean handleCloseControls(boolean save, boolean force) {
        mMetricsLogger.visibility(MetricsEvent.APP_OPS_GUTS, false);
        return false;
        return false;
    }
    }


+2 −3
Original line number Original line Diff line number Diff line
@@ -1122,9 +1122,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }
    }


    public void setGutsView(MenuItem item) {
    public void setGutsView(MenuItem item) {
        if (mGuts != null && item.getGutsView() instanceof NotificationGuts.GutsContent) {
        if (getGuts() != null && item.getGutsView() instanceof NotificationGuts.GutsContent) {
            ((NotificationGuts.GutsContent) item.getGutsView()).setGutsParent(mGuts);
            getGuts().setGutsContent((NotificationGuts.GutsContent) item.getGutsView());
            mGuts.setGutsContent((NotificationGuts.GutsContent) item.getGutsView());
        }
        }
    }
    }


+4 −22
Original line number Original line Diff line number Diff line
@@ -137,13 +137,13 @@ public class NotificationConversationInfo extends LinearLayout implements
        mSelectedAction = ACTION_HOME;
        mSelectedAction = ACTION_HOME;
        mShortcutManager.requestPinShortcut(mShortcutInfo, null);
        mShortcutManager.requestPinShortcut(mShortcutInfo, null);
        mShadeController.animateCollapsePanels();
        mShadeController.animateCollapsePanels();
        closeControls(v, true);
        mGutsContainer.closeControls(v, true);
    };
    };


    private OnClickListener mOnSnoozeClick = v -> {
    private OnClickListener mOnSnoozeClick = v -> {
        mSelectedAction = ACTION_SNOOZE;
        mSelectedAction = ACTION_SNOOZE;
        mOnSnoozeClickListener.onClick(v, 1);
        mOnSnoozeClickListener.onClick(v, 1);
        closeControls(v, true);
        mGutsContainer.closeControls(v, true);
    };
    };
    */
    */


@@ -164,7 +164,7 @@ public class NotificationConversationInfo extends LinearLayout implements


    private OnClickListener mOnDone = v -> {
    private OnClickListener mOnDone = v -> {
        mPressedApply = true;
        mPressedApply = true;
        closeControls(v, true);
        mGutsContainer.closeControls(v, true);
    };
    };


    public NotificationConversationInfo(Context context, AttributeSet attrs) {
    public NotificationConversationInfo(Context context, AttributeSet attrs) {
@@ -258,6 +258,7 @@ public class NotificationConversationInfo extends LinearLayout implements


        View done = findViewById(R.id.done);
        View done = findViewById(R.id.done);
        done.setOnClickListener(mOnDone);
        done.setOnClickListener(mOnDone);
        done.setAccessibilityDelegate(mGutsContainer.getAccessibilityDelegate());
    }
    }


    private void bindActions() {
    private void bindActions() {
@@ -543,25 +544,6 @@ public class NotificationConversationInfo extends LinearLayout implements
        controller.show();
        controller.show();
    }
    }


    /**
     * Closes the controls and commits the updated importance values (indirectly).
     *
     * <p><b>Note,</b> this will only get called once the view is dismissing. This means that the
     * user does not have the ability to undo the action anymore.
     */
    @VisibleForTesting
    void closeControls(View v, boolean save) {
        int[] parentLoc = new int[2];
        int[] targetLoc = new int[2];
        mGutsContainer.getLocationOnScreen(parentLoc);
        v.getLocationOnScreen(targetLoc);
        final int centerX = v.getWidth() / 2;
        final int centerY = v.getHeight() / 2;
        final int x = targetLoc[0] - parentLoc[0] + centerX;
        final int y = targetLoc[1] - parentLoc[1] + centerY;
        mGutsContainer.closeControls(x, y, save, false /* force */);
    }

    @Override
    @Override
    public void setGutsParent(NotificationGuts guts) {
    public void setGutsParent(NotificationGuts guts) {
        mGutsContainer = guts;
        mGutsContainer = guts;
+51 −1
Original line number Original line Diff line number Diff line
@@ -22,12 +22,14 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.view.View;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewAnimationUtils;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.FrameLayout;
import android.widget.FrameLayout;


import androidx.annotation.Nullable;
import androidx.annotation.Nullable;
@@ -59,6 +61,31 @@ public class NotificationGuts extends FrameLayout {


    private GutsContent mGutsContent;
    private GutsContent mGutsContent;


    private View.AccessibilityDelegate mGutsContentAccessibilityDelegate =
            new View.AccessibilityDelegate() {
                @Override
                public void onInitializeAccessibilityNodeInfo(
                        View host, AccessibilityNodeInfo info) {
                    super.onInitializeAccessibilityNodeInfo(host, info);
                    info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK);
                }

                @Override
                public boolean performAccessibilityAction(View host, int action, Bundle args) {
                    if (super.performAccessibilityAction(host, action, args)) {
                        return true;
                    }

                    switch (action) {
                        case AccessibilityNodeInfo.ACTION_LONG_CLICK:
                            closeControls(host, false);
                            return true;
                    }

                    return false;
                }
            };

    public interface GutsContent {
    public interface GutsContent {


        public void setGutsParent(NotificationGuts listener);
        public void setGutsParent(NotificationGuts listener);
@@ -110,6 +137,11 @@ public class NotificationGuts extends FrameLayout {
         * view on the lockscreen
         * view on the lockscreen
         */
         */
        boolean needsFalsingProtection();
        boolean needsFalsingProtection();

        /**
         * Equivalent to {@link View#setAccessibilityDelegate(AccessibilityDelegate)}
         */
        void setAccessibilityDelegate(AccessibilityDelegate gutsContentAccessibilityDelegate);
    }
    }


    public interface OnGutsClosedListener {
    public interface OnGutsClosedListener {
@@ -146,6 +178,8 @@ public class NotificationGuts extends FrameLayout {
    }
    }


    public void setGutsContent(GutsContent content) {
    public void setGutsContent(GutsContent content) {
        content.setGutsParent(this);
        content.setAccessibilityDelegate(mGutsContentAccessibilityDelegate);
        mGutsContent = content;
        mGutsContent = content;
        removeAllViews();
        removeAllViews();
        addView(mGutsContent.getContentView());
        addView(mGutsContent.getContentView());
@@ -235,6 +269,22 @@ public class NotificationGuts extends FrameLayout {
        }
        }
    }
    }


    /**
     * Closes any exposed guts/views.
     */
    public void closeControls(View eventSource, boolean save) {
        int[] parentLoc = new int[2];
        int[] targetLoc = new int[2];
        getLocationOnScreen(parentLoc);
        eventSource.getLocationOnScreen(targetLoc);
        final int centerX = eventSource.getWidth() / 2;
        final int centerY = eventSource.getHeight() / 2;
        final int x = targetLoc[0] - parentLoc[0] + centerX;
        final int y = targetLoc[1] - parentLoc[1] + centerY;

        closeControls(x, y, save, false);
    }

    /**
    /**
     * Closes any exposed guts/views.
     * Closes any exposed guts/views.
     *
     *
@@ -243,7 +293,7 @@ public class NotificationGuts extends FrameLayout {
     * @param save whether the state should be saved
     * @param save whether the state should be saved
     * @param force whether the guts should be force-closed regardless of state.
     * @param force whether the guts should be force-closed regardless of state.
     */
     */
    public void closeControls(int x, int y, boolean save, boolean force) {
    private void closeControls(int x, int y, boolean save, boolean force) {
        // First try to dismiss any blocking helper.
        // First try to dismiss any blocking helper.
        boolean wasBlockingHelperDismissed =
        boolean wasBlockingHelperDismissed =
                Dependency.get(NotificationBlockingHelperManager.class)
                Dependency.get(NotificationBlockingHelperManager.class)
+3 −22
Original line number Original line Diff line number Diff line
@@ -141,7 +141,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
    // used by standard ui
    // used by standard ui
    private OnClickListener mOnDismissSettings = v -> {
    private OnClickListener mOnDismissSettings = v -> {
        mPressedApply = true;
        mPressedApply = true;
        closeControls(v, true);
        mGutsContainer.closeControls(v, true);
    };
    };


    public NotificationInfo(Context context, AttributeSet attrs) {
    public NotificationInfo(Context context, AttributeSet attrs) {
@@ -250,7 +250,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G


        View done = findViewById(R.id.done);
        View done = findViewById(R.id.done);
        done.setOnClickListener(mOnDismissSettings);
        done.setOnClickListener(mOnDismissSettings);

        done.setAccessibilityDelegate(mGutsContainer.getAccessibilityDelegate());


        View silent = findViewById(R.id.silence);
        View silent = findViewById(R.id.silence);
        View alert = findViewById(R.id.alert);
        View alert = findViewById(R.id.alert);
@@ -330,7 +330,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
                        mUniqueChannelsInRow, mPkgIcon, mOnSettingsClickListener);
                        mUniqueChannelsInRow, mPkgIcon, mOnSettingsClickListener);
                mChannelEditorDialogController.setOnFinishListener(() -> {
                mChannelEditorDialogController.setOnFinishListener(() -> {
                    mPresentingChannelEditorDialog = false;
                    mPresentingChannelEditorDialog = false;
                    closeControls(this, false);
                    mGutsContainer.closeControls(this, false);
                });
                });
                mChannelEditorDialogController.show();
                mChannelEditorDialogController.show();
            }
            }
@@ -528,25 +528,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
        return intent;
        return intent;
    }
    }


    /**
     * Closes the controls and commits the updated importance values (indirectly).
     *
     * <p><b>Note,</b> this will only get called once the view is dismissing. This means that the
     * user does not have the ability to undo the action anymore.
     */
    @VisibleForTesting
    void closeControls(View v, boolean save) {
        int[] parentLoc = new int[2];
        int[] targetLoc = new int[2];
        mGutsContainer.getLocationOnScreen(parentLoc);
        v.getLocationOnScreen(targetLoc);
        final int centerX = v.getWidth() / 2;
        final int centerY = v.getHeight() / 2;
        final int x = targetLoc[0] - parentLoc[0] + centerX;
        final int y = targetLoc[1] - parentLoc[1] + centerY;
        mGutsContainer.closeControls(x, y, save, false /* force */);
    }

    @Override
    @Override
    public void setGutsParent(NotificationGuts guts) {
    public void setGutsParent(NotificationGuts guts) {
        mGutsContainer = guts;
        mGutsContainer = guts;
Loading