Example usage for android.view.accessibility AccessibilityEvent getEventType

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

Introduction

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

Prototype

public @EventType int getEventType() 

Source Link

Document

Gets the event type.

Usage

From source file:com.android.incallui.CallCardFragment.java

public void dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_ANNOUNCEMENT) {
        // Indicate this call is in active if no label is provided. The label is empty when
        // the call is in active, not in other status such as onhold or dialing etc.
        if (!mCallStateLabel.isShown() || TextUtils.isEmpty(mCallStateLabel.getText())) {
            event.getText().add(TextUtils.expandTemplate(
                    getResources().getText(R.string.accessibility_call_is_active), mPrimaryName.getText()));
        } else {/*from   w ww .  j  a va  2  s  .  co m*/
            dispatchPopulateAccessibilityEvent(event, mCallStateLabel);
            dispatchPopulateAccessibilityEvent(event, mPrimaryName);
            dispatchPopulateAccessibilityEvent(event, mCallTypeLabel);
            dispatchPopulateAccessibilityEvent(event, mPhoneNumber);
        }
        return;
    }
    dispatchPopulateAccessibilityEvent(event, mCallStateLabel);
    dispatchPopulateAccessibilityEvent(event, mPrimaryName);
    dispatchPopulateAccessibilityEvent(event, mPhoneNumber);
    dispatchPopulateAccessibilityEvent(event, mCallTypeLabel);
    dispatchPopulateAccessibilityEvent(event, mSecondaryCallName);
    dispatchPopulateAccessibilityEvent(event, mSecondaryCallProviderLabel);

    return;
}

From source file:com.android.talkback.controller.CursorControllerApp.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    int eventType = event.getEventType();
    if (eventType == AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        final AccessibilityNodeInfo node = event.getSource();
        if (node == null) {
            if (LogUtils.LOG_LEVEL <= Log.WARN) {
                Log.w(LOGTAG, "TYPE_VIEW_ACCESSIBILITY_FOCUSED event without a source.");
            }/*from   ww  w .  j  a  va  2s  . c o  m*/
            return;
        }

        // When a new view gets focus, clear the state of the granularity
        // manager if this event came from a different node than the locked
        // node but from the same window.
        final AccessibilityNodeInfoCompat nodeCompat = new AccessibilityNodeInfoCompat(node);
        mGranularityManager.onNodeFocused(nodeCompat);
        if (mSwitchNodeWithGranularityDirection == AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY) {
            mGranularityManager.navigate(AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
        } else if (mSwitchNodeWithGranularityDirection == AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY) {
            mGranularityManager.startFromLastNode();
            mGranularityManager.navigate(AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
        }
        mSwitchNodeWithGranularityDirection = 0;
        nodeCompat.recycle();
        mReachedEdge = false;
        mGranularityNavigationReachedEdge = false;
    } else if (eventType == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
        final AccessibilityNodeInfo node = event.getSource();
        if (node != null) {
            final AccessibilityNodeInfoCompat nodeCompat = new AccessibilityNodeInfoCompat(node);

            // Note: we also need to check ROLE_EDIT_TEXT for JB MR1 and lower and for
            // Chrome/WebView 51 and lower. We should check isEditable() first because it's
            // more semantically appropriate for what we want.
            if (nodeCompat.isEditable() || Role.getRole(nodeCompat) == Role.ROLE_EDIT_TEXT) {
                AccessibilityNodeInfoUtils.recycleNodes(mLastEditable);
                mLastEditable = nodeCompat;
            } else {
                nodeCompat.recycle();
            }
        }
    } else if (mIsWindowNavigationAvailable && eventType == AccessibilityEvent.TYPE_WINDOWS_CHANGED) {
        // Remove last focused nodes of non-existing windows.
        Set<Integer> windowIdsToBeRemoved = new HashSet(mLastFocusedNodeMap.keySet());
        for (AccessibilityWindowInfo window : mService.getWindows()) {
            windowIdsToBeRemoved.remove(window.getId());
        }
        for (Integer windowIdToBeRemoved : windowIdsToBeRemoved) {
            AccessibilityNodeInfoCompat removedNode = mLastFocusedNodeMap.remove(windowIdToBeRemoved);
            if (removedNode != null) {
                removedNode.recycle();
            }
        }
    }
}

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/* w  ww  . jav  a2  s .c  o  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);
    }
}

From source file:com.google.android.marvin.mytalkback.TalkBackService.java

/**
 * Helper method for {@link #shouldDropEvent} that handles events that
 * automatically occur immediately after a window state change.
 *
 * @param event The automatically generated event to consider retaining.
 * @return Whether to retain the event./*from  w  w  w .  jav a2  s  . co m*/
 */
private boolean shouldKeepAutomaticEvent(AccessibilityEvent event) {
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);

    // Don't drop focus events from EditTexts.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
        AccessibilityNodeInfoCompat node = null;

        try {
            node = record.getSource();
            if (AccessibilityNodeInfoUtils.nodeMatchesClassByType(this, node, android.widget.EditText.class)) {
                return true;
            }
        } finally {
            AccessibilityNodeInfoUtils.recycleNodes(node);
        }
    }

    return false;
}

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//ww  w.  j a v a2  s . c om
 * @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//from   ww  w. ja va 2  s.  com
 * @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.android.launcher2.PagedView.java

@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);
    event.setScrollable(true);/*from www .  j  ava  2s  . c  o  m*/
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
        event.setFromIndex(mCurrentPage);
        event.setToIndex(mCurrentPage);
        event.setItemCount(getChildCount());
    }
}

From source file:com.google.android.marvin.mytalkback.TalkBackService.java

/**
 * Returns whether the device should drop this event. Caches notifications
 * if necessary.//from  w w w.  ja  v  a 2 s.  c o  m
 *
 * @param event The current event.
 * @return {@code true} if the event should be dropped.
 */
private boolean shouldDropEvent(AccessibilityEvent event) {
    // Always drop null events.
    if (event == null) {
        return true;
    }

    // Always drop events if the service is suspended.
    if (!isServiceActive()) {
        return true;
    }

    // Always drop duplicate events (only applies to API < 14).
    if (AccessibilityEventUtils.eventEquals(mLastSpokenEvent, event)) {
        LogUtils.log(this, Log.VERBOSE, "Drop duplicate event");
        return true;
    }

    // If touch exploration is enabled, drop automatically generated events
    // that are sent immediately after a window state change... unless we
    // decide to keep the event.
    if (AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager)
            && ((event.getEventType() & AUTOMATIC_AFTER_STATE_CHANGE) != 0)
            && ((event.getEventTime() - mLastWindowStateChanged) < DELAY_AUTO_AFTER_STATE)
            && !shouldKeepAutomaticEvent(event)) {
        LogUtils.log(this, Log.VERBOSE, "Drop event after window state change");
        return true;
    }

    // Real notification events always have parcelable data.
    final boolean isNotification = (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED)
            && (event.getParcelableData() != null);

    final boolean isPhoneActive = (mCallStateMonitor != null)
            && (mCallStateMonitor.getCurrentCallState() != TelephonyManager.CALL_STATE_IDLE);
    final boolean shouldSpeakCallerId = (mSpeakCallerId && (mCallStateMonitor != null)
            && (mCallStateMonitor.getCurrentCallState() == TelephonyManager.CALL_STATE_RINGING));

    if (!mPowerManager.isScreenOn() && !shouldSpeakCallerId) {
        if (!mSpeakWhenScreenOff) {
            // If the user doesn't allow speech when the screen is
            // off, drop the event immediately.
            LogUtils.log(this, Log.VERBOSE, "Drop event due to screen state and user pref");
            return true;
        } else if (!isNotification) {
            // If the user allows speech when the screen is off, drop
            // all non-notification events.
            LogUtils.log(this, Log.VERBOSE, "Drop non-notification event due to screen state");
            return true;
        }
    }

    final boolean canInterruptRadialMenu = AccessibilityEventUtils.eventMatchesAnyType(event,
            MASK_EVENT_TYPES_INTERRUPT_RADIAL_MENU);
    final boolean silencedByRadialMenu = (mRadialMenuManager.isRadialMenuShowing() && !canInterruptRadialMenu);

    // Don't speak events that cannot interrupt the radial menu, if showing
    if (silencedByRadialMenu) {
        LogUtils.log(this, Log.VERBOSE, "Drop event due to radial menu state");
        return true;
    }

    // Don't speak notification events if the user is touch exploring or a phone call is active.
    if (isNotification && (mIsUserTouchExploring || isPhoneActive)) {
        LogUtils.log(this, Log.VERBOSE, "Drop notification due to touch or phone state");
        return true;
    }

    final int touchscreenState = getResources().getConfiguration().touchscreen;
    final boolean isTouchInteractionStateChange = AccessibilityEventUtils.eventMatchesAnyType(event,
            MASK_EVENT_TYPES_TOUCH_STATE_CHANGES);

    // Drop all events related to touch interaction state on devices that don't support touch.
    final int touchscreenConfig = getResources().getConfiguration().touchscreen;
    if ((touchscreenState == Configuration.TOUCHSCREEN_NOTOUCH) && isTouchInteractionStateChange) {
        return true;
    }

    return false;
}

From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java

@Override
public boolean dispatchPopulateAccessibilityEventInternal(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        event.getText().add(getKeyguardOrLockScreenString());
        mLastAnnouncementWasQuickSettings = false;
        return true;
    }/*  w  w  w .j  av  a 2s  . c o m*/
    return super.dispatchPopulateAccessibilityEventInternal(event);
}

From source file:com.isapp.android.circularviewpager.CircularViewPager.java

@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    // Dispatch scroll events from this ViewPager.
    if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED) {
        return super.dispatchPopulateAccessibilityEvent(event);
    }//from   w w w. ja v  a  2 s. c om
    // Dispatch all other accessibility events from the current page.
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == VISIBLE) {
            final ItemInfo ii = infoForChild(child);
            if (ii != null && ii.position == mCurItem && child.dispatchPopulateAccessibilityEvent(event)) {
                return true;
            }
        }
    }
    return false;
}