Merge "Fix for potential race condition in Spinners Added measure to try & ensure popups have time to collapse before trying to send TYPE_VIEW_SELECTED"

This commit is contained in:
Riley Jones
2022-12-01 21:05:45 +00:00
committed by Android (Google) Code Review
3 changed files with 18 additions and 1 deletions

View File

@@ -3274,6 +3274,7 @@ package android.widget {
public class Spinner extends android.widget.AbsSpinner implements android.content.DialogInterface.OnClickListener {
method public boolean isPopupShowing();
method public void onClick(int);
}
@android.widget.RemoteViews.RemoteView public class TextClock extends android.widget.TextView {

View File

@@ -968,7 +968,8 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
final int position = getSelectedItemPosition();
if (position >= 0) {
// we fire selection events here not in View
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
// posting the event should delay it long enough for UI changes to take effect.
post(() -> sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED));
}
}

View File

@@ -802,6 +802,21 @@ public class Spinner extends AbsSpinner implements OnClickListener {
dialog.dismiss();
}
/**
* Sets selection and dismisses the spinner's popup if it can be dismissed.
* For ease of use in tests, where publicly obtaining the spinner's popup is difficult.
*
* @param which index of the item to be selected.
* @hide
*/
@TestApi
public void onClick(int which) {
setSelection(which);
if (mPopup != null && mPopup.isShowing()) {
mPopup.dismiss();
}
}
@Override
public CharSequence getAccessibilityClassName() {
return Spinner.class.getName();