Example usage for android.view.accessibility AccessibilityEvent getSource

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

Introduction

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

Prototype

public AccessibilityNodeInfo getSource() 

Source Link

Document

Gets the AccessibilityNodeInfo of the event source.

Usage

From source file:Main.java

@Nullable
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public static List<AccessibilityNodeInfo> getAccessibilityNodeInfos(AccessibilityEvent event, String[] ids,
        String[] texts) {/*  w w  w .  ja v  a  2 s  . c  o m*/
    List<AccessibilityNodeInfo> result = null;
    AccessibilityNodeInfo source = event.getSource();
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if (ids != null && ids.length > 0) {
            for (String id : ids) {
                if (!TextUtils.isEmpty(id)) {
                    result = source.findAccessibilityNodeInfosByViewId(id);
                    if (result != null && result.size() > 0) {
                        return result;
                    }
                }
            }
        }
    }
    if (texts != null && texts.length > 0) {
        for (String text : texts) {
            if (!TextUtils.isEmpty(text)) {
                result = source.findAccessibilityNodeInfosByText(text);
                if (result != null && result.size() > 0) {
                    return result;
                }
            }
        }
    }
    return result;
}

From source file:com.android.screenspeak.controller.TextCursorControllerApp.java

private void processTextSelectionChange(AccessibilityEvent event) {
    AccessibilityNodeInfo node = event.getSource();
    if (node == null) {
        clear();//from w  w  w. ja va2s  .c o  m
        return;
    }

    AccessibilityNodeInfoCompat compat = new AccessibilityNodeInfoCompat(node);
    if (compat.equals(mNode)) {
        mPreviousCursorPosition = mCurrentCursorPosition;
        mCurrentCursorPosition = event.getToIndex();
    } else {
        clear();
        mNode = compat;
        mCurrentCursorPosition = event.getToIndex();
    }
}

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();/*from  ww w. ja  v  a  2s .c  o 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.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   ww  w  . ja v a 2  s .  c o m*/
        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.LiveViewFormatter.java

@Override
public boolean format(AccessibilityEvent event, ScreenSpeakService context, Utterance utterance) {
    AccessibilityNodeInfoCompat node = new AccessibilityNodeInfoCompat(event.getSource());
    if (node.getInfo() == null) {
        return false;
    }//from   ww w. j  a va 2s . co m

    int liveRegion = node.getLiveRegion();
    switch (liveRegion) {
    case View.ACCESSIBILITY_LIVE_REGION_POLITE:
        break;
    case View.ACCESSIBILITY_LIVE_REGION_ASSERTIVE:
        utterance.getMetadata().putInt(Utterance.KEY_METADATA_QUEUING, SpeechController.QUEUE_MODE_INTERRUPT);
        break;
    case View.ACCESSIBILITY_LIVE_REGION_NONE:
        return false;
    default:
        return false;
    }

    CharSequence text = NodeSpeechRuleProcessor.getInstance().getDescriptionForNode(node, event);

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

    utterance.addSpoken(text);
    utterance.addSpokenFlag(FeedbackItem.FLAG_SKIP_DUPLICATE);
    return true;
}

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

@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
    AccessibilityNodeInfoCompat node = new AccessibilityNodeInfoCompat(event.getSource());
    if (node.getInfo() == null) {
        return false;
    }/* w  w w . ja  v  a2  s.  c om*/

    int liveRegion = node.getLiveRegion();
    switch (liveRegion) {
    case View.ACCESSIBILITY_LIVE_REGION_POLITE:
        break;
    case View.ACCESSIBILITY_LIVE_REGION_ASSERTIVE:
        utterance.getMetadata().putInt(Utterance.KEY_METADATA_QUEUING, SpeechController.QUEUE_MODE_INTERRUPT);
        break;
    case View.ACCESSIBILITY_LIVE_REGION_NONE:
        return false;
    default:
        return false;
    }

    CharSequence text = NodeSpeechRuleProcessor.getInstance().getDescriptionForTree(node, event, node);

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

    utterance.addSpoken(text);
    utterance.addSpokenFlag(FeedbackItem.FLAG_SKIP_DUPLICATE);
    return true;
}

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

@Override
public boolean accept(AccessibilityEvent event, ScreenSpeakService context) {
    if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED)
        return false;

    AccessibilityNodeInfoCompat node = new AccessibilityNodeInfoCompat(event.getSource());
    if (node.getInfo() == null) {
        return false;
    }/*from  ww  w. ja  v a2 s.  co m*/

    int liveRegion = node.getLiveRegion();
    switch (liveRegion) {
    case View.ACCESSIBILITY_LIVE_REGION_POLITE:
        return true;
    case View.ACCESSIBILITY_LIVE_REGION_ASSERTIVE:
        return true;
    case View.ACCESSIBILITY_LIVE_REGION_NONE:
        return false;
    default:
        return false;
    }
}

From source file:com.android.screenspeak.SavedNode.java

@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
    switch (event.getEventType()) {
    case AccessibilityEvent.TYPE_WINDOWS_CHANGED:
        clearCache();/*from  w w  w  .j  a  v a2 s.  c  o m*/
        break;
    case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED:
        AccessibilityNodeInfo source = event.getSource();
        if (source != null) {
            AccessibilityNodeInfoCompat copyNode = new AccessibilityNodeInfoCompat(
                    AccessibilityNodeInfo.obtain(source));
            Selection selection = new Selection(event.getFromIndex(), event.getToIndex());
            mSelectionCache.put(copyNode, selection);
        }
        break;
    }
}

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

/**
 * Given an {@link AccessibilityEvent}, speaks a scroll position.
 *
 * @param event The source event.//from w w w  .  j ava2  s .com
 */
private void handleScrollFeedback(AccessibilityEvent event) {
    final CharSequence text;
    AccessibilityNodeInfo source = event.getSource();
    if (Role.getRole(source) == Role.ROLE_PAGER) {
        text = getDescriptionForPageEvent(event, source);
    } else {
        text = getDescriptionForScrollEvent(event);
    }
    if (source != null) {
        source.recycle();
    }

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

    // don't pronounce non-visible nodes
    AccessibilityNodeInfo node = event.getSource();
    if (node != null && !node.isVisibleToUser()) {
        return;
    }

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

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

private void checkIMEPicker(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED
            && "android".equals(event.getPackageName())
            && "android.app.AlertDialog".equals(event.getClassName())) {
        AccessibilityNodeInfo node = event.getSource();
        if (node == null) {
            return;
        }/* w  w  w  .  j ava  2 s. c o  m*/
        String IMETitle = mContext.getString(R.string.braille_ime_name);
        List<AccessibilityNodeInfo> found = node.findAccessibilityNodeInfosByText(IMETitle);
        if (found.size() == 0) {
            return;
        }
        AccessibilityNodeInfo firstFound = found.get(0);
        AccessibilityNodeInfo toFocus = firstFound.getParent();
        if (toFocus != null) {
            toFocus.performAction(AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS);
        }
    }
}