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

Commit 6f3ca535 authored by Robin Lee's avatar Robin Lee Committed by Android (Google) Code Review
Browse files

Merge "Focus content or button on AlertController"

parents e6c41d27 b96ca99b
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -559,6 +559,13 @@ public class AlertController {
        final boolean hasButtonPanel = buttonPanel != null
                && buttonPanel.getVisibility() != View.GONE;

        if (!parentPanel.isInTouchMode()) {
            final View content = hasCustomPanel ? customPanel : contentPanel;
            if (!requestFocusForContent(content)) {
                requestFocusForDefaultButton();
            }
        }

        // Only display the text spacer if we don't have buttons.
        if (!hasButtonPanel) {
            if (contentPanel != null) {
@@ -624,6 +631,29 @@ public class AlertController {
        a.recycle();
    }

    private boolean requestFocusForContent(View content) {
        if (content != null && content.requestFocus()) {
            return true;
        }

        if (mListView != null) {
            mListView.setSelection(0);
            return true;
        }

        return false;
    }

    private void requestFocusForDefaultButton() {
        if (mButtonPositive.getVisibility() == View.VISIBLE) {
            mButtonPositive.requestFocus();
        } else if (mButtonNegative.getVisibility() == View.VISIBLE) {
            mButtonNegative.requestFocus();
        } else if (mButtonNeutral.getVisibility() == View.VISIBLE) {
            mButtonNeutral.requestFocus();
        }
    }

    private void setupCustomContent(ViewGroup customPanel) {
        final View customView;
        if (mView != null) {