Example usage for android.view.accessibility AccessibilityEvent isChecked

List of usage examples for android.view.accessibility AccessibilityEvent isChecked

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityEvent isChecked.

Prototype

public boolean isChecked() 

Source Link

Document

Gets if the source is checked.

Usage

From source file:com.android.screenspeak.formatter.CheckableClickedFormatter.java

@Override
public boolean accept(AccessibilityEvent event, ScreenSpeakService context) {
    int type = event.getEventType();

    if (type == AccessibilityEvent.TYPE_VIEW_CLICKED) {
        mClickedNode = null;/*from www  . j av a  2 s .  c o m*/
        mClickedTime = -1;

        if (event.isChecked()) {
            return true;
        }

        AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
        AccessibilityNodeInfoCompat source = record.getSource();
        if (source != null) {
            if (source.isCheckable()) {
                return true;
            }

            // it is bug in settings application that does not include clicked state on node
            // so we need to restore it later from TYPE_WINDOW_CONTENT_CHANGED event
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mClickedNode = source;
                mClickedTime = System.currentTimeMillis();
            }
        }

        return false;
    }

    if (type == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            return false;
        if (mClickedTime == -1 || mClickedNode == null)
            return false;

        long now = System.currentTimeMillis();
        if ((mClickedTime + 1000) < now) {
            mClickedTime = -1;
            if (mClickedNode != null) {
                mClickedNode.recycle();
                mClickedNode = null;
            }
            return false;
        }

        AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
        AccessibilityNodeInfoCompat source = record.getSource();
        return findClickedCheckableNode(source);
    }

    return false;
}

From source file:com.android.talkback.formatter.CheckableClickedFormatter.java

@Override
public boolean accept(AccessibilityEvent event, TalkBackService context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return false;

    int type = event.getEventType();

    if (type == AccessibilityEvent.TYPE_VIEW_CLICKED) {
        mClickedNode = null;/*from  w  w  w.  j av  a2 s .  com*/
        mClickedTime = -1;

        if (event.isChecked()) {
            return true;
        }

        AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
        AccessibilityNodeInfoCompat source = record.getSource();
        if (source != null) {
            if (source.isCheckable()) {
                return true;
            }

            // it is bug in settings application that does not include clicked state on node
            // so we need to restore it later from TYPE_WINDOW_CONTENT_CHANGED event
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                mClickedNode = source;
                mClickedTime = System.currentTimeMillis();
            }
        }

        return false;
    }

    if (type == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
            return false;
        if (mClickedTime == -1 || mClickedNode == null)
            return false;

        long now = System.currentTimeMillis();
        if ((mClickedTime + 1000) < now) {
            mClickedTime = -1;
            if (mClickedNode != null) {
                mClickedNode.recycle();
                mClickedNode = null;
            }
            return false;
        }

        AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
        AccessibilityNodeInfoCompat source = record.getSource();
        return findClickedCheckableNode(source);
    }

    return false;
}

From source file:Main.java

/**
 * @return If the <code>first</code> event is equal to the <code>second</code>.
 *///from ww w  .j av a 2  s.  com
public static boolean eventEquals(AccessibilityEvent first, AccessibilityEvent second) {
    // TODO: The framework should implement AccessibilityEvent#equals()
    if (first == null || second == null) {
        return false;
    }
    if (first.getEventType() != second.getEventType()) {
        return false;
    }
    if (first.getPackageName() == null) {
        if (second.getPackageName() != null) {
            return false;
        }
    } else if (!first.getPackageName().equals(second.getPackageName())) {
        return false;
    }
    if (first.getClassName() == null) {
        if (second.getClassName() != null) {
            return false;
        }
    } else if (!first.getClassName().equals(second.getClassName())) {
        return false;
    }
    if (!first.getText().equals(second.getText())) {
        // The result of getText() is never null.
        return false;
    }
    if (first.getContentDescription() == null) {
        if (second.getContentDescription() != null) {
            return false;
        }
    } else if (!first.getContentDescription().equals(second.getContentDescription())) {
        return false;
    }
    if (first.getBeforeText() == null) {
        if (second.getBeforeText() != null) {
            return false;
        }
    } else if (!first.getBeforeText().equals(second.getBeforeText())) {
        return false;
    }
    if (first.getParcelableData() != null) {
        // Parcelable data may not implement equals() correctly.
        return false;
    }
    if (first.getAddedCount() != second.getAddedCount()) {
        return false;
    }
    if (first.isChecked() != second.isChecked()) {
        return false;
    }
    if (first.isEnabled() != second.isEnabled()) {
        return false;
    }
    if (first.getFromIndex() != second.getFromIndex()) {
        return false;
    }
    if (first.isFullScreen() != second.isFullScreen()) {
        return false;
    }
    if (first.getCurrentItemIndex() != second.getCurrentItemIndex()) {
        return false;
    }
    if (first.getItemCount() != second.getItemCount()) {
        return false;
    }
    if (first.isPassword() != second.isPassword()) {
        return false;
    }
    if (first.getRemovedCount() != second.getRemovedCount()) {
        return false;
    }
    if (first.getEventTime() != second.getEventTime()) {
        return false;
    }
    return true;
}

From source file:com.android.screenspeak.formatter.CheckableClickedFormatter.java

@Override
public boolean format(AccessibilityEvent event, ScreenSpeakService context, Utterance utterance) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
        if (sCachedCheckableNode == null)
            return false;

        utterance.addAuditory(R.raw.tick);
        utterance.addHaptic(R.array.view_clicked_pattern);
        utterance.addSpoken(context.getString(
                sCachedCheckableNode.isChecked() ? R.string.value_checked : R.string.value_not_checked));
        sCachedCheckableNode.recycle();//from w ww  .j a v  a 2 s  . c  o m
        sCachedCheckableNode = null;
        return true;
    }

    AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    AccessibilityNodeInfoCompat source = record.getSource();

    utterance.addAuditory(R.raw.tick);
    utterance.addHaptic(R.array.view_clicked_pattern);

    CharSequence eventText = AccessibilityEventUtils.getEventTextOrDescription(event);
    if (!TextUtils.isEmpty(eventText)) {
        utterance.addSpoken(eventText);
    }

    // Switch and ToggleButton state is sent along with the event, so only
    // append checked / not checked state for other types of controls.
    if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(source, ToggleButton.class)
            || AccessibilityNodeInfoUtils.nodeMatchesClassByType(source, Switch.class)) {
        return true;
    }

    if (source == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        if (event.isChecked()) {
            utterance.addSpoken(context.getString(R.string.value_checked));
        } else {
            utterance.addSpoken(context.getString(R.string.value_not_checked));
        }

        return true;
    }

    if (source.isCheckable()) {
        if (source.isChecked()) {
            utterance.addSpoken(context.getString(R.string.value_checked));
        } else {
            utterance.addSpoken(context.getString(R.string.value_not_checked));
        }
    }

    return true;
}

From source file:com.android.talkback.formatter.CheckableClickedFormatter.java

@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
        if (sCachedCheckableNode == null)
            return false;

        // Need to get latest state of cached node before accessing.
        sCachedCheckableNode.refresh();/* www .  j  a va  2s  .co  m*/

        utterance.addAuditory(R.raw.tick);
        utterance.addHaptic(R.array.view_clicked_pattern);
        utterance.addSpoken(context.getString(
                sCachedCheckableNode.isChecked() ? R.string.value_checked : R.string.value_not_checked));
        sCachedCheckableNode.recycle();
        sCachedCheckableNode = null;
        return true;
    }

    AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    AccessibilityNodeInfoCompat source = record.getSource();

    utterance.addAuditory(R.raw.tick);
    utterance.addHaptic(R.array.view_clicked_pattern);

    CharSequence eventText = AccessibilityEventUtils.getEventTextOrDescription(event);
    if (!TextUtils.isEmpty(eventText)) {
        utterance.addSpoken(eventText);
    }

    // Switch and ToggleButton state is sent along with the event, so only
    // append checked / not checked state for other types of controls.
    // TODO: node.isTwoState()
    if (Role.getRole(source) == Role.ROLE_TOGGLE_BUTTON || Role.getRole(source) == Role.ROLE_SWITCH) {
        return true;
    }

    if (source == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        if (event.isChecked()) {
            utterance.addSpoken(context.getString(R.string.value_checked));
        } else {
            utterance.addSpoken(context.getString(R.string.value_not_checked));
        }

        return true;
    }

    if (source.isCheckable()) {
        if (source.isChecked()) {
            utterance.addSpoken(context.getString(R.string.value_checked));
        } else {
            utterance.addSpoken(context.getString(R.string.value_not_checked));
        }
    }

    return true;
}

From source file:com.android.screenspeak.formatter.EventSpeechRule.java

/**
 * Returns the value of a given <code>property</code> of an <code>event</code>.
 *
 * @param property The property//from  ww  w.j a  v a2s  .  c o  m
 * @param event The event.
 * @return the value.
 */
private Object getPropertyValue(Context context, String property, AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);

    if (property == null) {
        throw new IllegalArgumentException("Unknown property : " + property);
    }

    // TODO(AV): Don't do so many string comparisons here.
    switch (property) {
    case PROPERTY_EVENT_TYPE:
        return event.getEventType();
    case PROPERTY_PACKAGE_NAME:
        return event.getPackageName();
    case PROPERTY_CLASS_NAME:
        return event.getClassName();
    case PROPERTY_CLASS_NAME_STRICT:
        return event.getClassName();
    case PROPERTY_TEXT:
        return AccessibilityEventUtils.getEventAggregateText(event);
    case PROPERTY_BEFORE_TEXT:
        return event.getBeforeText();
    case PROPERTY_CONTENT_DESCRIPTION:
        return event.getContentDescription();
    case PROPERTY_CONTENT_DESCRIPTION_OR_TEXT:
        return AccessibilityEventUtils.getEventTextOrDescription(event);
    case PROPERTY_NODE_DESCRIPTION_OR_FALLBACK:
        return getNodeDescriptionOrFallback(event);
    case PROPERTY_EVENT_TIME:
        return event.getEventTime();
    case PROPERTY_ITEM_COUNT:
        return event.getItemCount();
    case PROPERTY_CURRENT_ITEM_INDEX:
        return event.getCurrentItemIndex();
    case PROPERTY_FROM_INDEX:
        return event.getFromIndex();
    case PROPERTY_TO_INDEX:
        return record.getToIndex();
    case PROPERTY_SCROLLABLE:
        return record.isScrollable();
    case PROPERTY_SCROLL_X:
        return record.getScrollX();
    case PROPERTY_SCROLL_Y:
        return record.getScrollY();
    case PROPERTY_RECORD_COUNT:
        return AccessibilityEventCompat.getRecordCount(event);
    case PROPERTY_CHECKED:
        return event.isChecked();
    case PROPERTY_ENABLED:
        return event.isEnabled();
    case PROPERTY_FULL_SCREEN:
        return event.isFullScreen();
    case PROPERTY_PASSWORD:
        return event.isPassword();
    case PROPERTY_ADDED_COUNT:
        return event.getAddedCount();
    case PROPERTY_REMOVED_COUNT:
        return event.getRemovedCount();
    case PROPERTY_VERSION_CODE:
        return PackageManagerUtils.getVersionCode(context, event.getPackageName());
    case PROPERTY_VERSION_NAME:
        return PackageManagerUtils.getVersionName(context, event.getPackageName());
    case PROPERTY_PLATFORM_RELEASE:
        return Build.VERSION.RELEASE;
    case PROPERTY_PLATFORM_SDK:
        return Build.VERSION.SDK_INT;
    default:
        throw new IllegalArgumentException("Unknown property : " + property);
    }
}

From source file:com.android.talkback.formatter.EventSpeechRule.java

/**
 * Returns the value of a given <code>property</code> of an <code>event</code>.
 *
 * @param property The property/*www.jav a  2 s. co m*/
 * @param event The event.
 * @return the value.
 */
private Object getPropertyValue(Context context, String property, AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);

    if (property == null) {
        throw new IllegalArgumentException("Unknown property : " + property);
    }

    // TODO: Don't do so many string comparisons here.
    switch (property) {
    case PROPERTY_EVENT_TYPE:
        return event.getEventType();
    case PROPERTY_PACKAGE_NAME:
        return event.getPackageName();
    case PROPERTY_CLASS_NAME:
        return event.getClassName();
    case PROPERTY_CLASS_NAME_STRICT:
        return event.getClassName();
    case PROPERTY_TEXT:
        return AccessibilityEventUtils.getEventAggregateText(event);
    case PROPERTY_BEFORE_TEXT:
        return event.getBeforeText();
    case PROPERTY_CONTENT_DESCRIPTION:
        return event.getContentDescription();
    case PROPERTY_CONTENT_DESCRIPTION_OR_TEXT:
        return AccessibilityEventUtils.getEventTextOrDescription(event);
    case PROPERTY_NODE_DESCRIPTION_OR_FALLBACK:
        return getNodeDescriptionOrFallback(event);
    case PROPERTY_EVENT_TIME:
        return event.getEventTime();
    case PROPERTY_ITEM_COUNT:
        return event.getItemCount();
    case PROPERTY_CURRENT_ITEM_INDEX:
        return event.getCurrentItemIndex();
    case PROPERTY_FROM_INDEX:
        return event.getFromIndex();
    case PROPERTY_TO_INDEX:
        return record.getToIndex();
    case PROPERTY_SCROLLABLE:
        return record.isScrollable();
    case PROPERTY_SCROLL_X:
        return record.getScrollX();
    case PROPERTY_SCROLL_Y:
        return record.getScrollY();
    case PROPERTY_RECORD_COUNT:
        return AccessibilityEventCompat.getRecordCount(event);
    case PROPERTY_CHECKED:
        return event.isChecked();
    case PROPERTY_ENABLED:
        return event.isEnabled();
    case PROPERTY_FULL_SCREEN:
        return event.isFullScreen();
    case PROPERTY_PASSWORD:
        return event.isPassword();
    case PROPERTY_ADDED_COUNT:
        return event.getAddedCount();
    case PROPERTY_REMOVED_COUNT:
        return event.getRemovedCount();
    case PROPERTY_VERSION_CODE:
        return PackageManagerUtils.getVersionCode(context, event.getPackageName());
    case PROPERTY_VERSION_NAME:
        return PackageManagerUtils.getVersionName(context, event.getPackageName());
    case PROPERTY_PLATFORM_RELEASE:
        return Build.VERSION.RELEASE;
    case PROPERTY_PLATFORM_SDK:
        return Build.VERSION.SDK_INT;
    default:
        throw new IllegalArgumentException("Unknown property : " + property);
    }
}

From source file:com.google.android.marvin.mytalkback.formatter.EventSpeechRule.java

/**
 * Returns the value of a given <code>property</code> of an <code>event</code>.
 *
 * @param property The property/*  ww  w.ja va  2  s. co  m*/
 * @param event The event.
 * @return the value.
 */
private Object getPropertyValue(Context context, String property, AccessibilityEvent event) {
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);

    // TODO(alanv): Don't do so many string comparisons here.
    if (PROPERTY_EVENT_TYPE.equals(property)) {
        return event.getEventType();
    } else if (PROPERTY_PACKAGE_NAME.equals(property)) {
        return event.getPackageName();
    } else if (PROPERTY_CLASS_NAME.equals(property)) {
        return event.getClassName();
    } else if (PROPERTY_CLASS_NAME_STRICT.equals(property)) {
        return event.getClassName();
    } else if (PROPERTY_TEXT.equals(property)) {
        return AccessibilityEventUtils.getEventAggregateText(event);
    } else if (PROPERTY_BEFORE_TEXT.equals(property)) {
        return event.getBeforeText();
    } else if (PROPERTY_CONTENT_DESCRIPTION.equals(property)) {
        return event.getContentDescription();
    } else if (PROPERTY_CONTENT_DESCRIPTION_OR_TEXT.equals(property)) {
        return AccessibilityEventUtils.getEventTextOrDescription(event);
    } else if (PROPERTY_NODE_DESCRIPTION_OR_FALLBACK.equals(property)) {
        return getNodeDescriptionOrFallback(event);
    } else if (PROPERTY_EVENT_TIME.equals(property)) {
        return event.getEventTime();
    } else if (PROPERTY_ITEM_COUNT.equals(property)) {
        return event.getItemCount();
    } else if (PROPERTY_CURRENT_ITEM_INDEX.equals(property)) {
        return event.getCurrentItemIndex();
    } else if (PROPERTY_FROM_INDEX.equals(property)) {
        return event.getFromIndex();
    } else if (PROPERTY_TO_INDEX.equals(property)) {
        return record.getToIndex();
    } else if (PROPERTY_SCROLLABLE.equals(property)) {
        return record.isScrollable();
    } else if (PROPERTY_SCROLL_X.equals(property)) {
        return record.getScrollX();
    } else if (PROPERTY_SCROLL_Y.equals(property)) {
        return record.getScrollY();
    } else if (PROPERTY_RECORD_COUNT.equals(property)) {
        return AccessibilityEventCompat.getRecordCount(event);
    } else if (PROPERTY_CHECKED.equals(property)) {
        return event.isChecked();
    } else if (PROPERTY_ENABLED.equals(property)) {
        return event.isEnabled();
    } else if (PROPERTY_FULL_SCREEN.equals(property)) {
        return event.isFullScreen();
    } else if (PROPERTY_PASSWORD.equals(property)) {
        return event.isPassword();
    } else if (PROPERTY_ADDED_COUNT.equals(property)) {
        return event.getAddedCount();
    } else if (PROPERTY_REMOVED_COUNT.equals(property)) {
        return event.getRemovedCount();
    } else if (PROPERTY_VERSION_CODE.equals(property)) {
        return PackageManagerUtils.getVersionCode(context, event.getPackageName());
    } else if (PROPERTY_VERSION_NAME.equals(property)) {
        return PackageManagerUtils.getVersionName(context, event.getPackageName());
    } else if (PROPERTY_PLATFORM_RELEASE.equals(property)) {
        return Build.VERSION.RELEASE;
    } else if (PROPERTY_PLATFORM_SDK.equals(property)) {
        return Build.VERSION.SDK_INT;
    } else {
        throw new IllegalArgumentException("Unknown property : " + property);
    }
}