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

Commit 1686e9af authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

CheckBoxPreferences do not fire accessibility events

bug:4091160

We no longer allow not shown views to fire accessibility
events. Therefore, CheckBoxPreference can no longer ask its
associated checkbox to fire an accessibility event because
the latter is not attached to the view hierarchy
(i.e. not shown) by the time the CheckBoxPreference has a
chance to send an accessibility event. Instead the
CheckBoxPreference itself is responsible for firing the event.

Change-Id: Ia742882b13bf6c441cc76fa1e84b47a55cee601c
parent e65711b2
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -24,8 +24,10 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.widget.CheckBox;
import android.widget.Checkable;
import android.widget.TextView;

@@ -90,8 +92,16 @@ public class CheckBoxPreference extends Preference {
                    checkboxView.isEnabled()) {
                mSendAccessibilityEventViewClickedType = false;

                int eventType = AccessibilityEvent.TYPE_VIEW_CLICKED;
                checkboxView.sendAccessibilityEventUnchecked(AccessibilityEvent.obtain(eventType));
                // we send an event on behalf of the check box because in onBind the latter
                // is detached from its parent and such views do not send accessibility events
                AccessibilityEvent event = AccessibilityEvent.obtain(
                        AccessibilityEvent.TYPE_VIEW_CLICKED);
                event.setClassName(checkboxView.getClass().getName());
                event.setPackageName(getContext().getPackageName());
                event.setEnabled(checkboxView.isEnabled());
                event.setContentDescription(checkboxView.getContentDescription());
                event.setChecked(((Checkable) checkboxView).isChecked());
                mAccessibilityManager.sendAccessibilityEvent(event);
            }
        }