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

Commit 6f6d5783 authored by Ben Lin's avatar Ben Lin
Browse files

Request focus on "OK" for Delete dialog.

Bug: 29571289
Change-Id: Id101883e5ac92f839058aa1968554e959052848f
parent 8f06585b
Loading
Loading
Loading
Loading
+23 −12
Original line number Original line Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.documentsui.ui;
import android.app.Activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.content.DialogInterface.OnShowListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TextView;


import com.android.documentsui.R;
import com.android.documentsui.R;
@@ -73,7 +75,7 @@ public interface DialogController {
            // but as a simple runtime dialog. So rotating a device with an
            // but as a simple runtime dialog. So rotating a device with an
            // active delete dialog...results in that dialog disappearing.
            // active delete dialog...results in that dialog disappearing.
            // We can do better, but don't have cycles for it now.
            // We can do better, but don't have cycles for it now.
            new AlertDialog.Builder(mActivity)
            final AlertDialog alertDialog = new AlertDialog.Builder(mActivity)
                    .setView(message)
                    .setView(message)
                    .setPositiveButton(
                    .setPositiveButton(
                            android.R.string.ok,
                            android.R.string.ok,
@@ -84,7 +86,16 @@ public interface DialogController {
                                }
                                }
                            })
                            })
                    .setNegativeButton(android.R.string.cancel, null)
                    .setNegativeButton(android.R.string.cancel, null)
                .show();
                    .create();

            alertDialog.setOnShowListener(
                    (DialogInterface) -> {
                        Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
                        positive.setFocusable(true);
                        positive.setFocusableInTouchMode(true);
                        positive.requestFocus();
                    });
            alertDialog.show();
        }
        }


        @Override
        @Override
+7 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.documentsui.bots;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.hasFocus;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
@@ -31,6 +32,7 @@ import static org.hamcrest.Matchers.endsWith;


import android.content.Context;
import android.content.Context;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.Espresso;
import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.action.ViewActions;
import android.support.test.espresso.matcher.BoundedMatcher;
import android.support.test.espresso.matcher.BoundedMatcher;
import android.support.test.espresso.matcher.ViewMatchers;
import android.support.test.espresso.matcher.ViewMatchers;
@@ -190,6 +192,11 @@ public class UiBot extends Bots.BaseBot {
        return title;
        return title;
    }
    }


    @SuppressWarnings("unchecked")
    public void assertDialogOkButtonFocused() {
        onView(withId(android.R.id.button1)).check(matches(hasFocus()));
    }

    public void clickDialogOkButton() {
    public void clickDialogOkButton() {
        // Espresso has flaky results when keyboard shows up, so hiding it for now
        // Espresso has flaky results when keyboard shows up, so hiding it for now
        // before trying to click on any dialog button
        // before trying to click on any dialog button
+1 −0
Original line number Original line Diff line number Diff line
@@ -75,6 +75,7 @@ public class FileManagementUiTest extends ActivityTest<ManageActivity> {
        device.waitForIdle();
        device.waitForIdle();
        bots.main.clickToolbarItem(R.id.menu_delete);
        bots.main.clickToolbarItem(R.id.menu_delete);


        bots.main.assertDialogOkButtonFocused();
        bots.main.clickDialogOkButton();
        bots.main.clickDialogOkButton();
        device.waitForIdle();
        device.waitForIdle();