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.screenspeak.eventprocessor.ProcessorAccessibilityHints.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    final int eventType = event.getEventType();

    if (eventType == AccessibilityEvent.TYPE_VIEW_HOVER_ENTER
            || eventType == AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START) {
        mIsTouchExploring = true;//from   ww w  . j  a v a 2s  .c o  m
    }

    if (eventType == AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END
            || eventType == AccessibilityEvent.TYPE_VIEW_CLICKED) {
        mIsTouchExploring = false;
        cacheEnteredNode(null);
        cancelA11yHint();
        return;
    }

    if (!mIsTouchExploring || ((eventType != AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED)
            && (eventType != AccessibilityEvent.TYPE_VIEW_HOVER_EXIT))) {
        return;
    }

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

    if (source == null) {
        return;
    }

    if (eventType == AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
        cacheEnteredNode(source);
        String hint = getHintFromEvent(event);
        if (hint != null) {
            postA11yHintRunnable(hint);
        }
    } else if (eventType == AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT) {
        if (source.equals(mWaitingForExit)) {
            cancelA11yHint();
        }
    }

    source.recycle();
}

From source file:com.android.screenspeak.eventprocessor.ProcessorVolumeStream.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_START:
        mTouchingScreen = true;//from ww  w .j  a  v a 2s .c o m
        break;
    case AccessibilityEvent.TYPE_TOUCH_INTERACTION_END:
        mTouchingScreen = false;
        break;
    }
}

From source file:com.android.screenspeak.eventprocessor.EventQueue.java

/**
 * Enforces that the event queue has no more than
 * {@code MAXIMUM_QUALIFYING_EVENTS} events of each type defined by
 * {@code MASK_LIMITED_EVENT_TYPES}. The excessive events are pruned by
 * removing the oldest event first./*from   w  w w  .j av a  2 s.  c o m*/
 */
private void enforceEventLimits() {
    int eventTypesToPrune = 0;
    // Locate event types which exceed the allowable limit
    for (int i = 0; i < mQualifyingEvents.size(); i++) {
        final int eventType = mQualifyingEvents.keyAt(i);
        final int eventsOfType = mQualifyingEvents.valueAt(i);
        if (eventsOfType > MAXIMUM_QUALIFYING_EVENTS) {
            eventTypesToPrune |= eventType;
        }
    }

    final Iterator<AccessibilityEvent> iterator = mEventQueue.iterator();
    while (iterator.hasNext() && (eventTypesToPrune != 0)) {
        final AccessibilityEvent next = iterator.next();

        // Prune offending events
        if (AccessibilityEventUtils.eventMatchesAnyType(next, eventTypesToPrune)) {
            final int eventType = next.getEventType();
            int eventCountOfType = mQualifyingEvents.get(eventType, 0);
            eventCountOfType--;
            mQualifyingEvents.put(eventType, eventCountOfType);
            iterator.remove();

            // Stop pruning further events of this type if the number of
            // events is below the limit
            if (eventCountOfType <= MAXIMUM_QUALIFYING_EVENTS) {
                eventTypesToPrune &= ~eventType;
            }
        }
    }
}

From source file:com.hrs.filltheform.service.ServiceEventResolver.java

private void notifyEventResolverListener(AccessibilityNodeInfoCompat nodeInfo, AccessibilityEvent event,
        String idGroupKey) {//from  ww w . j  a va 2s  .co m
    List<ConfigurationItem> selectedConfigurationItems = configuration.getIdGroups().get(idGroupKey);
    if (eventResolverListener != null) {
        eventResolverListener.onDataForSelectedNodeAvailable(nodeInfo, event.getEventType(),
                selectedConfigurationItems);
    }
}

From source file:com.android.screenspeak.tutorial.TutorialModule.java

/**
 * Constructs a new tutorial module for the given tutorial activity context
 * with the specified layout and title./*from   w w w  .  j  av a  2  s .  c o m*/
 *
 * @param parentTutorial The tutorial activity containing this module.
 * @param layoutResId The resource identifier for this module's layout.
 * @param titleResId The resource identifier for this module's title string.
 */
TutorialModule(AccessibilityTutorialActivity parentTutorial, int layoutResId, int titleResId) {
    super(parentTutorial);

    mParentTutorial = parentTutorial;
    mTitleResId = titleResId;

    final LayoutInflater inflater = mParentTutorial.getLayoutInflater();
    final View container = inflater.inflate(R.layout.tutorial_container, this, true);

    mInstructions = (TextView) container.findViewById(R.id.instructions);
    mSkip = (Button) container.findViewById(R.id.skip_button);
    mSkip.setOnClickListener(this);
    mBack = (Button) container.findViewById(R.id.back_button);
    mBack.setOnClickListener(this);
    mNext = (Button) container.findViewById(R.id.next_button);
    mNext.setOnClickListener(this);
    mFinish = (Button) container.findViewById(R.id.finish_button);
    mFinish.setOnClickListener(this);

    final TextView title = (TextView) container.findViewById(R.id.title);

    if (title != null) {
        title.setText(titleResId);
    }

    if (layoutResId != -1) {
        final ViewGroup contentHolder = (ViewGroup) container.findViewById(R.id.content);

        // Inflate the tutorial module content while dropping certain accessibility events
        // A delegate used to drop accessibility events related to AbsListView's
        // inflation of module content.
        contentHolder.setAccessibilityDelegate(new AccessibilityDelegate() {
            @Override
            public boolean onRequestSendAccessibilityEvent(@NonNull ViewGroup host, View child,
                    AccessibilityEvent event) {
                return event.getEventType() != AccessibilityEvent.TYPE_VIEW_SCROLLED
                        && super.onRequestSendAccessibilityEvent(host, child, event);

            }
        });
        inflater.inflate(layoutResId, contentHolder, true);
        contentHolder.setAccessibilityDelegate(null);
    }
}

From source file:com.android.screenspeak.eventprocessor.ProcessorScrollPosition.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    if (shouldIgnoreEvent(event)) {
        return;//from   www  . ja  v  a  2 s.c om
    }

    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        // Window state changes clear the cache.
        mCachedFromValues.clear();
        mCachedItemCounts.clear();
        mHandler.cancelScrollFeedback();
        break;
    case AccessibilityEvent.TYPE_VIEW_SCROLLED:
    case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
        mHandler.postScrollFeedback(event);
        break;
    }
}

From source file:com.tr4android.support.extension.picker.date.YearPickerView.java

/** @hide */
@Override/*from  www .  j  a v  a 2s. co m*/
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
    super.onInitializeAccessibilityEvent(event);

    // There are a bunch of years, so don't bother.
    if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
        AccessibilityEventCompat.asRecord(event).setFromIndex(0);
        AccessibilityEventCompat.asRecord(event).setToIndex(0);
    }
}

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

private boolean shouldIgnoreEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED:
    case AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
    case AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED:
        return true;
    case AccessibilityEventCompat.TYPE_VIEW_SCROLLED:
        return shouldIgnoreScrollEvent(event);
    default:/*  ww w.  j  a  v a  2s.c o  m*/
        return false;
    }
}

From source file:com.android.screenspeak.eventprocessor.ProcessorEventQueue.java

/**
 * Computes the queuing mode for the current utterance.
 *
 * @param utterance to compute queuing from
 * @return A queuing mode, one of:/* w ww .j  av  a2 s  . c  om*/
 *         <ul>
 *         <li>{@link SpeechController#QUEUE_MODE_INTERRUPT}
 *         <li>{@link SpeechController#QUEUE_MODE_QUEUE}
 *         <li>{@link SpeechController#QUEUE_MODE_UNINTERRUPTIBLE}
 *         </ul>
 */
private int computeQueuingMode(Utterance utterance, AccessibilityEvent event) {
    final Bundle metadata = utterance.getMetadata();
    final int eventType = event.getEventType();

    // Queue events that occur automatically after window state changes.
    if (((event.getEventType() & AccessibilityEventProcessor.AUTOMATIC_AFTER_STATE_CHANGE) != 0)
            && ((event.getEventTime()
                    - mLastWindowStateChanged) < AccessibilityEventProcessor.DELAY_AUTO_AFTER_STATE)) {
        return SpeechController.QUEUE_MODE_QUEUE;
    }

    if (eventType == AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) {
        AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
        AccessibilityNodeInfoCompat node = record.getSource();
        if (node != null) {
            int liveRegionMode = node.getLiveRegion();
            if (liveRegionMode == View.ACCESSIBILITY_LIVE_REGION_POLITE) {
                return SpeechController.QUEUE_MODE_QUEUE;
            }
        }
    }

    int queueMode = metadata.getInt(Utterance.KEY_METADATA_QUEUING, SpeechController.QUEUE_MODE_INTERRUPT);

    // Always collapse events of the same type.
    if (mLastEventType == eventType && queueMode != SpeechController.QUEUE_MODE_UNINTERRUPTIBLE) {
        return SpeechController.QUEUE_MODE_INTERRUPT;
    }

    mLastEventType = eventType;

    return queueMode;
}

From source file:com.googlecode.eyesfree.brailleback.BrailleMenuNavigationMode.java

@Override
public boolean onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED:
    case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED:
        closeMenu();/*from   ww  w  . j a va  2 s . c o m*/
        return true;
    }
    // Don't let fall through.
    return true;
}