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

Commit 70fe4d60 authored by Riley Jones's avatar Riley Jones
Browse files

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
parent c05fb4a0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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 {
+2 −1
Original line number Diff line number Diff line
@@ -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));
        }
    }

+15 −0
Original line number Diff line number Diff line
@@ -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();