Fix wrong visibility of link button in a11y tutorial dialog
Root cause: the visibility of link button is not correctly set due to the onPageSelected callback isn't called when the first page shows Solution: Manually set the visibility of link button according to the first tutirial page type when dialog is shown Bug: 242141428 Test: make RunSettingsRoboTests ROBOTEST_FILTER=AccessibilityGestureNavigationTutorialTest Change-Id: I33ed07bc7ae39d96baeeed85771c5f13e00ebf44
This commit is contained in:
@@ -136,11 +136,26 @@ public final class AccessibilityGestureNavigationTutorial {
|
|||||||
linkButtonListener)
|
linkButtonListener)
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
final TutorialPageChangeListener.OnPageSelectedCallback callback =
|
final List<TutorialPage> tutorialPages =
|
||||||
type -> alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(
|
createShortcutTutorialPages(context, shortcutTypes);
|
||||||
type == UserShortcutType.SOFTWARE ? VISIBLE : GONE);
|
Preconditions.checkArgument(!tutorialPages.isEmpty(),
|
||||||
|
/* errorMessage= */ "Unexpected tutorial pages size");
|
||||||
|
|
||||||
alertDialog.setView(createShortcutNavigationContentView(context, shortcutTypes, callback));
|
final TutorialPageChangeListener.OnPageSelectedCallback callback = index -> {
|
||||||
|
final int pageType = tutorialPages.get(index).getType();
|
||||||
|
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(
|
||||||
|
pageType == UserShortcutType.SOFTWARE ? VISIBLE : GONE);
|
||||||
|
};
|
||||||
|
|
||||||
|
alertDialog.setView(createShortcutNavigationContentView(context, tutorialPages, callback));
|
||||||
|
|
||||||
|
// Showing first page won't invoke onPageSelectedCallback. Need to check the first tutorial
|
||||||
|
// page type manually to set correct visibility of the link button.
|
||||||
|
alertDialog.setOnShowListener(dialog -> {
|
||||||
|
final int firstPageType = tutorialPages.get(0).getType();
|
||||||
|
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(
|
||||||
|
firstPageType == UserShortcutType.SOFTWARE ? VISIBLE : GONE);
|
||||||
|
});
|
||||||
|
|
||||||
return alertDialog;
|
return alertDialog;
|
||||||
}
|
}
|
||||||
@@ -274,16 +289,13 @@ public final class AccessibilityGestureNavigationTutorial {
|
|||||||
return inflater.inflate(R.layout.accessibility_lottie_animation_view, /* root= */ null);
|
return inflater.inflate(R.layout.accessibility_lottie_animation_view, /* root= */ null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static View createShortcutNavigationContentView(Context context, int shortcutTypes,
|
private static View createShortcutNavigationContentView(Context context,
|
||||||
|
List<TutorialPage> tutorialPages,
|
||||||
TutorialPageChangeListener.OnPageSelectedCallback onPageSelectedCallback) {
|
TutorialPageChangeListener.OnPageSelectedCallback onPageSelectedCallback) {
|
||||||
|
|
||||||
final LayoutInflater inflater = context.getSystemService(LayoutInflater.class);
|
final LayoutInflater inflater = context.getSystemService(LayoutInflater.class);
|
||||||
final View contentView = inflater.inflate(
|
final View contentView = inflater.inflate(
|
||||||
R.layout.accessibility_shortcut_tutorial_dialog, /* root= */ null);
|
R.layout.accessibility_shortcut_tutorial_dialog, /* root= */ null);
|
||||||
final List<TutorialPage> tutorialPages =
|
|
||||||
createShortcutTutorialPages(context, shortcutTypes);
|
|
||||||
Preconditions.checkArgument(!tutorialPages.isEmpty(),
|
|
||||||
/* errorMessage= */ "Unexpected tutorial pages size");
|
|
||||||
|
|
||||||
final LinearLayout indicatorContainer = contentView.findViewById(R.id.indicator_container);
|
final LinearLayout indicatorContainer = contentView.findViewById(R.id.indicator_container);
|
||||||
indicatorContainer.setVisibility(tutorialPages.size() > 1 ? VISIBLE : GONE);
|
indicatorContainer.setVisibility(tutorialPages.size() > 1 ? VISIBLE : GONE);
|
||||||
@@ -575,7 +587,7 @@ public final class AccessibilityGestureNavigationTutorial {
|
|||||||
currentPageNumber, mTutorialPages.size()));
|
currentPageNumber, mTutorialPages.size()));
|
||||||
|
|
||||||
if (mOnPageSelectedCallback != null) {
|
if (mOnPageSelectedCallback != null) {
|
||||||
mOnPageSelectedCallback.onPageSelected(mTutorialPages.get(position).getType());
|
mOnPageSelectedCallback.onPageSelected(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,7 +600,7 @@ public final class AccessibilityGestureNavigationTutorial {
|
|||||||
private interface OnPageSelectedCallback {
|
private interface OnPageSelectedCallback {
|
||||||
|
|
||||||
/** The callback method after tutorial page is selected. */
|
/** The callback method after tutorial page is selected. */
|
||||||
void onPageSelected(int type);
|
void onPageSelected(int index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@ import android.app.settings.SettingsEnums;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@@ -111,6 +112,44 @@ public final class AccessibilityGestureNavigationTutorialTest {
|
|||||||
assertThat(alertDialog).isNotNull();
|
assertThat(alertDialog).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createTutorialPages_turnOnSoftwareShortcut_linkButtonVisible() {
|
||||||
|
mShortcutTypes |= UserShortcutType.SOFTWARE;
|
||||||
|
|
||||||
|
final AlertDialog alertDialog =
|
||||||
|
createAccessibilityTutorialDialog(mContext, mShortcutTypes);
|
||||||
|
alertDialog.show();
|
||||||
|
|
||||||
|
assertThat(alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).getVisibility())
|
||||||
|
.isEqualTo(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createTutorialPages_turnOnSoftwareAndHardwareShortcut_linkButtonVisible() {
|
||||||
|
mShortcutTypes |= UserShortcutType.SOFTWARE;
|
||||||
|
mShortcutTypes |= UserShortcutType.HARDWARE;
|
||||||
|
|
||||||
|
final AlertDialog alertDialog =
|
||||||
|
createAccessibilityTutorialDialog(mContext, mShortcutTypes);
|
||||||
|
alertDialog.show();
|
||||||
|
|
||||||
|
assertThat(alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).getVisibility())
|
||||||
|
.isEqualTo(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createTutorialPages_turnOnHardwareShortcut_linkButtonGone() {
|
||||||
|
mShortcutTypes |= UserShortcutType.HARDWARE;
|
||||||
|
|
||||||
|
final AlertDialog alertDialog =
|
||||||
|
createAccessibilityTutorialDialog(mContext, mShortcutTypes);
|
||||||
|
alertDialog.show();
|
||||||
|
|
||||||
|
assertThat(alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).getVisibility())
|
||||||
|
.isEqualTo(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void performClickOnPositiveButton_turnOnSoftwareShortcut_dismiss() {
|
public void performClickOnPositiveButton_turnOnSoftwareShortcut_dismiss() {
|
||||||
mShortcutTypes |= UserShortcutType.SOFTWARE;
|
mShortcutTypes |= UserShortcutType.SOFTWARE;
|
||||||
|
Reference in New Issue
Block a user