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

Commit 30401328 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Factored out the Accessibility vertical initialization.

1. Accessibility events were filled with data in
   dispatchPopulateAccessibilityEvent and
   onPopulateAccessibilityEvent. These events have
   two axis of population 1) up the class
   hierarchy to populate information for the event
   source; 2) down the view hierarchy to populated
   all the text contained in the source including
   its descendants. These two axis of population
   were done in on population pass now the populating
   the source properties happens in initializeAccessiblityEvent
   and the text in onPopulateAccessibilityEvent which
   is called from dispatchPopulateAccessiblityEvent.

2. Removed the string description from events fired from
   CompoundButton since the event has isChecked()
   property and it is responsibility of the clients
   to decide what utterrance to use and if to use such
   for announcing the checked state.

Change-Id: I5d7f75cf8a87a7a4b3bb7b311e8e642ec9a0faa5
parent 83a7cdc5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21273,6 +21273,7 @@ package android.view {
    method protected void onFocusChanged(boolean, int, android.graphics.Rect);
    method public boolean onGenericMotionEvent(android.view.MotionEvent);
    method public boolean onHoverEvent(android.view.MotionEvent);
    method public void onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
    method public boolean onKeyDown(int, android.view.KeyEvent);
    method public boolean onKeyLongPress(int, android.view.KeyEvent);
    method public boolean onKeyMultiple(int, int, android.view.KeyEvent);
+89 −27
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.os.Parcelable;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.text.format.DateUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pool;
@@ -3440,7 +3441,21 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
    }

    /**
     * {@inheritDoc}
     * Sends an accessibility event of the given type. If accessiiblity is
     * not enabled this method has no effect. The default implementation calls
     * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)} first
     * to populate information about the event source (this View), then calls
     * {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)} to
     * populate the text content of the event source including its descendants,
     * and last calls
     * {@link ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)}
     * on its parent to resuest sending of the event to interested parties.
     *
     * @param eventType The type of the event to send.
     *
     * @see #onInitializeAccessibilityEvent(AccessibilityEvent)
     * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
     * @see ViewParent#requestSendAccessibilityEvent(View, AccessibilityEvent)
     */
    public void sendAccessibilityEvent(int eventType) {
        if (AccessibilityManager.getInstance(mContext).isEnabled()) {
@@ -3449,41 +3464,35 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
    }

    /**
     * {@inheritDoc}
     * This method behaves exactly as {@link #sendAccessibilityEvent(int)} but
     * takes as an argument an empty {@link AccessibilityEvent} and does not
     * perfrom a check whether accessibility is enabled.
     *
     * @param event The event to send.
     *
     * @see #sendAccessibilityEvent(int)
     */
    public void sendAccessibilityEventUnchecked(AccessibilityEvent event) {
        if (!isShown()) {
            return;
        }

        // Populate these here since they are related to the View that
        // sends the event and should not be modified while dispatching
        // to descendants.
        event.setClassName(getClass().getName());
        event.setPackageName(getContext().getPackageName());
        event.setEnabled(isEnabled());
        event.setContentDescription(mContentDescription);

        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) {
            ArrayList<View> focusablesTempList = mAttachInfo.mFocusablesTempList;
            getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, FOCUSABLES_ALL);
            event.setItemCount(focusablesTempList.size());
            event.setCurrentItemIndex(focusablesTempList.indexOf(this));
            focusablesTempList.clear();
        }

        onInitializeAccessibilityEvent(event);
        dispatchPopulateAccessibilityEvent(event);

        // In the beginning we called #isShown(), so we know that getParent() is not null.
        getParent().requestSendAccessibilityEvent(this, event);
    }

    /**
     * Dispatches an {@link AccessibilityEvent} to the {@link View} children to be populated.
     * This method first calls {@link #onPopulateAccessibilityEvent(AccessibilityEvent)}
     * on this view allowing it to populate information about itself and also decide
     * whether to intercept the population i.e. to prevent its children from populating
     * the event.
     * Dispatches an {@link AccessibilityEvent} to the {@link View} first and then
     * to its children for adding their text content to the event. Note that the
     * event text is populated in a separate dispatch path since we add to the
     * event not only the text of the source but also the text of all its descendants.
     * </p>
     * A typical implementation will call
     * {@link #onPopulateAccessibilityEvent(AccessibilityEvent)} on the this view
     * and then call the {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)}
     * on each child. Override this method if custom population of the event text
     * content is required.
     *
     * @param event The event.
     *
@@ -3496,15 +3505,68 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility

    /**
     * Called from {@link #dispatchPopulateAccessibilityEvent(AccessibilityEvent)}
     * giving a chance to this View to populate the accessibility evnet with
     * information about itself.
     * giving a chance to this View to populate the accessibility event with its
     * text content. While the implementation is free to modify other event
     * attributes this should be performed in
     * {@link #onInitializeAccessibilityEvent(AccessibilityEvent)}.
     * <p>
     * Example: Adding formatted date string to an accessibility event in addition
     *          to the text added by the super implementation.
     * </p><p><pre><code>
     * @Override
     * public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
     *     super.onPopulateAccessibilityEvent(event);
     *     final int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY;
     *     String selectedDateUtterance = DateUtils.formatDateTime(mContext,
     *         mCurrentDate.getTimeInMillis(), flags);
     *     event.getText().add(selectedDateUtterance);
     * }
     * </code></pre></p>
     *
     * @param event The accessibility event which to populate.
     *
     * @see #sendAccessibilityEvent(int)
     * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
     */
    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {

    }

    /**
     * Initializes an {@link AccessibilityEvent} with information about the
     * the type of the event and this View which is the event source. In other
     * words, the source of an accessibility event is the view whose state
     * change triggered firing the event.
     * <p>
     * Example: Setting the password property of an event in addition
     *          to properties set by the super implementation.
     * </p><p><pre><code>
     * @Override
     * public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     *    super.onInitializeAccessibilityEvent(event);
     *    event.setPassword(true);
     * }
     * </code></pre></p>
     * @param event The event to initialeze.
     *
     * @see #sendAccessibilityEvent(int)
     * @see #dispatchPopulateAccessibilityEvent(AccessibilityEvent)
     */
    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
        event.setClassName(getClass().getName());
        event.setPackageName(getContext().getPackageName());
        event.setEnabled(isEnabled());
        event.setContentDescription(mContentDescription);

        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED && mAttachInfo != null) {
            ArrayList<View> focusablesTempList = mAttachInfo.mFocusablesTempList;
            getRootView().addFocusables(focusablesTempList, View.FOCUS_FORWARD, FOCUSABLES_ALL);
            event.setItemCount(focusablesTempList.size());
            event.setCurrentItemIndex(focusablesTempList.indexOf(this));
            focusablesTempList.clear();
        }
    }

    /**
     * Gets the {@link View} description. It briefly describes the view and is
     * primarily used for accessibility support. Set this property to enable
+2 −2
Original line number Diff line number Diff line
@@ -898,8 +898,8 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
    }

    @Override
    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
        super.onPopulateAccessibilityEvent(event);
    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
        super.onInitializeAccessibilityEvent(event);

        View selectedView = getSelectedView();
        if (selectedView != null) {
+2 −2
Original line number Diff line number Diff line
@@ -199,8 +199,8 @@ public class CheckedTextView extends TextView implements Checkable {
    }

    @Override
    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
        super.onPopulateAccessibilityEvent(event);
    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
        super.onInitializeAccessibilityEvent(event);
        event.setChecked(mChecked);
    }
}
+2 −11
Original line number Diff line number Diff line
@@ -208,17 +208,8 @@ public abstract class CompoundButton extends Button implements Checkable {
    }

    @Override
    public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
        super.onPopulateAccessibilityEvent(event);

        int resourceId = 0;
        if (mChecked) {
            resourceId = R.string.accessibility_compound_button_selected;
        } else {
            resourceId = R.string.accessibility_compound_button_unselected;
        }
        String state = getResources().getString(resourceId);
        event.getText().add(state);
    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
        super.onInitializeAccessibilityEvent(event);
        event.setChecked(mChecked);
    }

Loading