Example usage for android.support.v4.view.accessibility AccessibilityEventCompat TYPE_VIEW_HOVER_ENTER

List of usage examples for android.support.v4.view.accessibility AccessibilityEventCompat TYPE_VIEW_HOVER_ENTER

Introduction

In this page you can find the example usage for android.support.v4.view.accessibility AccessibilityEventCompat TYPE_VIEW_HOVER_ENTER.

Prototype

int TYPE_VIEW_HOVER_ENTER

To view the source code for android.support.v4.view.accessibility AccessibilityEventCompat TYPE_VIEW_HOVER_ENTER.

Click Source Link

Document

Represents the event of a hover enter over a android.view.View .

Usage

From source file:com.android.talkback.eventprocessor.ProcessorFocusAndSingleTapTest.java

@MediumTest
public void testOnAccessibilityEvent_viewHoverEnter_shouldFocus() {
    AccessibilityNodeInfoCompat buttonNode = getNodeForId(R.id.sign_in);
    final View buttonView = getViewForId(R.id.sign_in);

    sendAccessibilityEvent(buttonView, AccessibilityEventCompat.TYPE_TOUCH_INTERACTION_START);
    sendAccessibilityEvent(buttonView, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
    sendAccessibilityEvent(buttonView, AccessibilityEventCompat.TYPE_TOUCH_INTERACTION_END);

    AccessibilityNodeInfoCompat cursor = mService.getCursorController().getCursor();
    assertEquals(buttonNode, cursor);//  w w w.j a v  a  2 s  . c o m
}

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

@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
    final AccessibilityNodeInfo source = event.getSource();

    // Drop events that have source nodes.
    if (source != null) {
        source.recycle();//from  w  w w.  j  a  v  a 2  s  .c  om
        return false;
    }

    boolean hasEarcons = true;

    // Add earcons and patterns since the event doesn't have a source node
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_FOCUSED:
        utterance.addHaptic(R.array.view_focused_or_selected_pattern);
        utterance.addAuditory(R.raw.focus_actionable);
        break;
    case AccessibilityEvent.TYPE_VIEW_SELECTED:
        utterance.addHaptic(R.array.view_focused_or_selected_pattern);
        utterance.addAuditory(R.raw.focus_actionable);
        break;
    case AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER:
        utterance.addHaptic(R.array.view_hovered_pattern);
        utterance.addAuditory(R.raw.focus);
        break;
    default:
        hasEarcons = false;
        break;
    }

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

    return hasEarcons || !utterance.getSpoken().isEmpty();
}

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

@Override
public boolean format(AccessibilityEvent event, ScreenSpeakService context, Utterance utterance) {
    final AccessibilityNodeInfo source = event.getSource();

    // Drop events that have source nodes.
    if (source != null) {
        source.recycle();//  www  .ja va  2s . co  m
        return false;
    }

    // Add earcons and patterns since the event doesn't have a source node
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_VIEW_FOCUSED:
        utterance.addHaptic(R.array.view_focused_or_selected_pattern);
        utterance.addAuditory(R.raw.focus_actionable);
        break;
    case AccessibilityEvent.TYPE_VIEW_SELECTED:
        utterance.addHaptic(R.array.view_focused_or_selected_pattern);
        utterance.addAuditory(R.raw.focus_actionable);
        break;
    case AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER:
        utterance.addHaptic(R.array.view_hovered_pattern);
        utterance.addAuditory(R.raw.focus);
        break;
    }

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

    return true;
}

From source file:com.android.talkback.eventprocessor.ProcessorFocusAndSingleTapTest.java

@MediumTest
public void testOnAccessibilityEvent_viewHoverEnter_shouldRefocus() {
    AccessibilityNodeInfoCompat buttonNode = getNodeForId(R.id.sign_in);
    final View buttonView = getViewForId(R.id.sign_in);

    mService.getCursorController().setCursor(buttonNode);
    waitForAccessibilityIdleSync();/*from   w  ww . jav a  2  s .c om*/

    // Refocus only occurs if TTS is silent, so let's make sure nothing's speaking!
    mService.getSpeechController().interrupt();
    waitForAccessibilityIdleSync();

    sendAccessibilityEvent(buttonView, AccessibilityEventCompat.TYPE_TOUCH_INTERACTION_START);
    sendAccessibilityEvent(buttonView, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
    sendAccessibilityEvent(buttonView, AccessibilityEventCompat.TYPE_TOUCH_INTERACTION_END);

    AccessibilityNodeInfoCompat cursor = mService.getCursorController().getCursor();
    assertEquals(buttonNode, cursor);
}

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

private void updateRecentlyExplored(AccessibilityEvent event) {
    // TODO(alanv): We track this in several places. Need to refactor.

    // We only need to track recently explored views on ICS.
    if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)) {
        return;// w ww.ja  v  a  2 s .  c  om
    }

    // Exploration is the result of HOVER_ENTER events.
    if (event.getEventType() != AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER) {
        return;
    }

    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final AccessibilityNodeInfoCompat node = record.getSource();

    if (mRecentlyExplored != null) {
        if (mRecentlyExplored.equals(node)) {
            return;
        }

        mRecentlyExplored.recycle();
        mRecentlyExplored = null;
    }

    if (node != null) {
        mRecentlyExplored = AccessibilityNodeInfoCompat.obtain(node);
    }
}

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

/**
 * Given an {@link AccessibilityEvent}, obtains and speaks a long
 * hover utterance./*from   w  w w. ja  v  a 2  s.  c  o m*/
 *
 * @param event The source event.
 */
private void speakLongHover(AccessibilityEvent event) {
    // Never speak hint text if the tutorial is active
    if (AccessibilityTutorialActivity.isTutorialActive()) {
        LogUtils.log(this, Log.VERBOSE, "Dropping long hover hint speech because tutorial is active.");
        return;
    }

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

    if (source == null) {
        return;
    }

    // If this was a HOVER_ENTER event, we need to compute the focused node.
    // TODO: We're already doing this in the touch exploration formatter --
    // maybe this belongs there instead?
    if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER) {
        source = AccessibilityNodeInfoUtils.findFocusFromHover(mContext, source);
        if (source == null) {
            return;
        }
    }

    final CharSequence text = mRuleProcessor.getHintForNode(source);
    source.recycle();

    // Use QUEUE mode so that we don't interrupt more important messages.
    mSpeechController.speak(text, SpeechController.QUEUE_MODE_QUEUE, FeedbackItem.FLAG_NO_HISTORY, null);
}

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

/**
 * Computes a focused node based on the device's supported APIs and the
 * event type.// w w w.j  a v a 2s.  c om
 *
 * @param eventType The event type.
 * @param sourceNode The source node.
 * @return The focused node, or {@code null} to drop the event.
 */
private AccessibilityNodeInfoCompat getFocusedNode(int eventType, AccessibilityNodeInfoCompat sourceNode) {
    if (sourceNode == null) {
        return null;
    }

    // On Jelly Bean, use the source node of accessibility focus events and
    // discard all other event types.
    if (SUPPORTS_A11Y_FOCUS) {
        if (eventType != AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
            return null;
        }

        return AccessibilityNodeInfoCompat.obtain(sourceNode);
    }

    // On previous versions, simulate accessibility focus by computing a
    // focused node for hover enter events and discard all other events.
    if (eventType != AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER) {
        return null;
    }

    final AccessibilityNodeInfoCompat focusedNode = AccessibilityNodeInfoUtils.findFocusFromHover(mContext,
            sourceNode);

    // If the focused node already has accessibility focus, abort.
    if ((focusedNode != null) && focusedNode.equals(mLastFocusedNode)) {
        AccessibilityNodeInfoUtils.recycleNodes(focusedNode);
        return null;
    }

    // Cache the current focus target for later comparison.
    if (mLastFocusedNode != null) {
        mLastFocusedNode.recycle();
    }

    if (focusedNode != null) {
        mLastFocusedNode = AccessibilityNodeInfoCompat.obtain(focusedNode);
    } else {
        // TODO(alanv): Calling AccessibilityNodeInfoCompat.obtain(null)
        // should return null. Is there a bug in the support library?
        mLastFocusedNode = null;
    }

    // Since API <16 doesn't support accessibility focus, we need to fake it
    // by keeping track of the most recently explored view.
    // TODO(alanv): Add global support for keeping track of fake A11y focus.
    ProgressBarFormatter.updateRecentlyExplored(focusedNode);

    return focusedNode;
}

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityNodeProvider.java

public void onHoverEnterTo(final Key key) {
    final int id = getVirtualViewIdOf(key);
    if (id == View.NO_ID) {
        return;/* w w w  .j a  v  a  2s  .c o  m*/
    }
    // Start hovering on the key. Because our accessibility model is lift-to-type, we should
    // report the node info without click and long click actions to avoid unnecessary
    // announcements.
    mHoveringNodeId = id;
    // Invalidate the node info of the key.
    sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_WINDOW_CONTENT_CHANGED);
    sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
}

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

/**
 * Given an {@link AccessibilityEvent}, obtains the long hover utterance.
 *
 * @param event The source event./*from w ww.  j  a va  2  s  . c o  m*/
 */
private String getHintFromEvent(AccessibilityEvent event) {
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    AccessibilityNodeInfoCompat source = record.getSource();

    if (source == null) {
        return null;
    }

    // If this was a HOVER_ENTER event, we need to compute the focused node.
    // TODO: We're already doing this in the touch exploration formatter --
    // maybe this belongs there instead?
    if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER) {
        source = AccessibilityNodeInfoUtils.findFocusFromHover(source);
        if (source == null) {
            return null;
        }
    }

    final CharSequence text = mRuleProcessor.getHintForNode(source);
    source.recycle();

    if (TextUtils.isEmpty(text)) {
        return null;
    }

    return text.toString();
}

From source file:com.android.hareime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Handles a hover event on a key. If {@link Key} extended View, this would
 * be analogous to calling View.onHoverEvent(MotionEvent).
 *
 * @param key The currently hovered key.
 * @param event The hover event./*w ww  .  j ava  2s.  c  o m*/
 * @return {@code true} if the event was handled.
 */
private boolean onHoverKey(Key key, MotionEvent event) {
    // Null keys can't receive events.
    if (key == null) {
        return false;
    }

    final AccessibilityEntityProvider provider = getAccessibilityNodeProvider();

    switch (event.getAction()) {
    case MotionEvent.ACTION_HOVER_ENTER:
        provider.sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_ENTER);
        provider.performActionForKey(key, AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS, null);
        break;
    case MotionEvent.ACTION_HOVER_EXIT:
        provider.sendAccessibilityEventForKey(key, AccessibilityEventCompat.TYPE_VIEW_HOVER_EXIT);
        break;
    }

    return true;
}