Fix for potential race condition in Spinners

Added measure to try & ensure popups have time to collapse before trying to send TYPE_VIEW_SELECTED

Bug: 256048559
Test: Test in topic
Change-Id: I8ef5ff37ca08a4adb8c7ffda53a7ac810ba2763d
This commit is contained in:
Riley Jones
2022-10-28 22:48:27 +00:00
parent c05fb4a0d7
commit 70fe4d6031
3 changed files with 18 additions and 1 deletions

View File

@@ -3252,6 +3252,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();