本文整理汇总了Java中android.support.v4.view.accessibility.AccessibilityRecordCompat.getSource方法的典型用法代码示例。如果您正苦于以下问题:Java AccessibilityRecordCompat.getSource方法的具体用法?Java AccessibilityRecordCompat.getSource怎么用?Java AccessibilityRecordCompat.getSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.accessibility.AccessibilityRecordCompat
的用法示例。
在下文中一共展示了AccessibilityRecordCompat.getSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldDropEvent
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
private boolean shouldDropEvent(AccessibilityEvent event) {
final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
final AccessibilityNodeInfoCompat source = record.getSource();
// Don't drop if we're on pre-ICS or the event was generated (e.g.
// missing a node).
if (source == null) {
return false;
}
// Don't drop if the node is currently focused or accessibility focused.
if (source.isFocused() || source.isAccessibilityFocused()) {
return false;
}
// Don't drop if the node was recently explored.
return true;
}
示例2: accept
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
@Override
public boolean accept(AccessibilityEvent event, TalkBackService context) {
if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED) return false;
AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
AccessibilityNodeInfoCompat node = record.getSource();
if (node == null) {
return false;
}
int liveRegion = node.getLiveRegion();
node.recycle();
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;
}
}
示例3: shouldKeepAutomaticEvent
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
/**
* 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.
*/
private boolean shouldKeepAutomaticEvent(AccessibilityEvent event) {
final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
// Don't drop focus events from EditTexts.
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_FOCUSED) {
AccessibilityNodeInfoCompat node = null;
try {
node = record.getSource();
if (Role.getRole(node) == Role.ROLE_EDIT_TEXT) {
return true;
}
} finally {
AccessibilityNodeInfoUtils.recycleNodes(node);
}
}
return false;
}
示例4: format
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
final AccessibilityNodeInfoCompat source = record.getSource();
if (source == null) return false;
CharSequence text = format(context, source, event);
if (TextUtils.isEmpty(text)) return false;
utterance.addSpoken(text);
utterance.getMetadata().putInt(Utterance.KEY_UTTERANCE_GROUP,
SpeechController.UTTERANCE_GROUP_SEEK_PROGRESS);
utterance.addSpokenFlag(
FeedbackItem.FLAG_CLEAR_QUEUED_UTTERANCES_WITH_SAME_UTTERANCE_GROUP);
utterance.getMetadata().putInt(Utterance.KEY_METADATA_QUEUING,
SpeechController.QUEUE_MODE_UNINTERRUPTIBLE);
return true;
}
示例5: format
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
AccessibilityNodeInfoCompat source = record.getSource();
AccessibilityNodeInfoCompat refreshedSource =
AccessibilityNodeInfoUtils.refreshNode(source);
try {
if (refreshedSource == null) {
// Node no longer exists.
return false;
}
// Is source directly checkable?
if (refreshedSource.isCheckable()) {
utterance.addSpoken(getStateText(refreshedSource, context));
return true;
}
// Does source contain non-focusable checkable child?
if (refreshedSource.isAccessibilityFocused() || refreshedSource.isFocused()) {
AccessibilityNodeInfoCompat checkableChild = findCheckableChild(refreshedSource);
if (checkableChild != null) {
utterance.addSpoken(getStateText(checkableChild, context));
checkableChild.recycle();
return true;
}
}
} finally {
AccessibilityNodeInfoUtils.recycleNodes(source, refreshedSource);
}
utterance.addSpokenFlag(FeedbackItem.FLAG_NO_SPEECH);
return true;
}
示例6: handleViewScrolled
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
private void handleViewScrolled(AccessibilityEvent event, AccessibilityRecordCompat record) {
AccessibilityNodeInfoCompat source = null;
@TraversalStrategy.SearchDirectionOrUnknown int direction;
boolean wasScrollAction;
if (mActionScrolledNode != null) {
source = record.getSource();
if (source == null) return;
if (source.equals(mActionScrolledNode)) {
direction = mLastScrollDirection;
wasScrollAction = true;
clearScrollAction();
} else {
direction = getScrollDirection(event);
wasScrollAction = false;
}
} else {
direction = getScrollDirection(event);
wasScrollAction = false;
}
followScrollEvent(source, record, direction, wasScrollAction);
mLastScrollFromIndex = record.getFromIndex();
mLastScrollToIndex = record.getToIndex();
mLastScrollX = record.getScrollX();
mLastScrollY = record.getScrollY();
tryFocusCachedRecord();
}
示例7: shouldAnnounceEvent
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
/**
* Uses a heuristic to guess whether an event should be announced.
* Any event that comes from an IME, or an invisible window is considered
* an announcement.
*/
private boolean shouldAnnounceEvent(AccessibilityEvent event, int windowId) {
// Assume window ID of 0 is the keyboard.
if (windowId == WINDOW_ID_NONE) {
return true;
}
// If there's an actual window ID, we need to check the window type (if window available).
boolean shouldAnnounceWindow = false;
AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
AccessibilityNodeInfoCompat source = record.getSource();
if (source != null) {
AccessibilityWindowInfoCompat window = source.getWindow();
if (window != null) {
shouldAnnounceWindow =
window.getType() == AccessibilityWindowInfoCompat.TYPE_INPUT_METHOD;
window.recycle();
} else {
// If window is not visible, we cannot know whether the window type is input method
// or not. Let's announce it for the case. If window is visible but window info is
// not available, it can be non-focusable visible window. Don't announce it for the
// case. It can be a toast.
shouldAnnounceWindow = !source.isVisibleToUser();
}
source.recycle();
}
return shouldAnnounceWindow;
}
示例8: onAccessibilityEvent
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
if (!areHintsEnabled()) {
return;
}
// Clear hints that were generated before a click or in an old window configuration.
final int eventType = event.getEventType();
if (eventType == AccessibilityEvent.TYPE_VIEW_CLICKED ||
eventType == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED ||
eventType == AccessibilityEvent.TYPE_WINDOWS_CHANGED) {
cancelA11yHint();
return;
}
if (eventType == AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED) {
EventState eventState = EventState.getInstance();
if (eventState.checkAndClearRecentEvent(
EventState.EVENT_SKIP_HINT_AFTER_GRANULARITY_MOVE)) {
return;
}
if (eventState.checkAndClearRecentEvent(
EventState.EVENT_SKIP_HINT_AFTER_CURSOR_CONTROL)) {
return;
}
AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
AccessibilityNodeInfoCompat source = record.getSource();
if (source != null) {
postA11yHintRunnable(source);
// DO NOT RECYCLE. postA11yHintRunnable will save the node.
}
}
}
示例9: computeQueuingMode
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
/**
* Computes the queuing mode for the current utterance.
*
* @param utterance to compute queuing from
* @return A queuing mode, one of:
* <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;
}
示例10: shouldDropEvent
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
/**
* Returns {@code true} if the specified event is a selection event and
* should be dropped without providing feedback. Always returns
* {@code false} for non-selection events.
*/
private boolean shouldDropEvent(AccessibilityEvent event) {
// Only operate on selection events. Never drop granular movement
// events or other event types.
final int eventType = event.getEventType();
if (eventType != AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED) {
return false;
}
// Drop selected events until we've matched the number of changed
// events. This prevents TalkBack from speaking automatic cursor
// movement events that result from typing.
if (sAwaitingSelectionCount > 0) {
final boolean hasDelayElapsed =
((event.getEventTime() - sChangedTimestamp) >= SELECTION_DELAY);
final boolean hasPackageChanged =
!TextUtils.equals(event.getPackageName(), sChangedPackage);
// If the state is still consistent, update the count and drop
// the event.
if (!hasDelayElapsed && !hasPackageChanged) {
sAwaitingSelectionCount--;
mLastFromIndex = event.getFromIndex();
mLastToIndex = event.getToIndex();
if (mLastNode != null) {
mLastNode.recycle();
}
mLastNode = event.getSource();
return true;
}
// The state became inconsistent, so reset the counter.
sAwaitingSelectionCount = 0;
}
// Drop selection events from views that don't have input focus.
final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
final AccessibilityNodeInfoCompat source = record.getSource();
if ((source != null) && !source.isFocused()) {
LogUtils.log(this, Log.VERBOSE, "Dropped selection event from non-focused field");
return true;
}
return false;
}
示例11: format
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
/**
* Formatter that returns an utterance to announce touch exploration.
*/
@Override
public boolean format(AccessibilityEvent event, TalkBackService context, Utterance utterance) {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED &&
EventState.getInstance().checkAndClearRecentEvent(
EventState.EVENT_SKIP_FOCUS_PROCESSING_AFTER_GRANULARITY_MOVE)) {
return false;
}
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED &&
EventState.getInstance().checkAndClearRecentEvent(
EventState.EVENT_SKIP_FOCUS_PROCESSING_AFTER_CURSOR_CONTROL)) {
return false;
}
final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
final AccessibilityNodeInfoCompat sourceNode = record.getSource();
final AccessibilityNodeInfoCompat focusedNode = getFocusedNode(
event.getEventType(), sourceNode);
// Drop the event if the source node was non-null, but the focus
// algorithm decided to drop the event by returning null.
if ((sourceNode != null) && (focusedNode == null)) {
AccessibilityNodeInfoUtils.recycleNodes(sourceNode);
return false;
}
LogUtils.log(this, Log.VERBOSE, "Announcing node: %s", focusedNode);
// Transition the collection state if necessary.
mCollectionState.updateCollectionInformation(focusedNode, event);
// Populate the utterance.
addEarconWhenAccessibilityFocusMovesToTheDivider(utterance, focusedNode);
addSpeechFeedback(utterance, focusedNode, event, sourceNode);
addAuditoryHapticFeedback(utterance, focusedNode);
// By default, touch exploration flushes all other events.
utterance.getMetadata().putInt(Utterance.KEY_METADATA_QUEUING, DEFAULT_QUEUING_MODE);
// Events formatted by this class should always advance continuous
// reading, if active.
utterance.addSpokenFlag(FeedbackItem.FLAG_ADVANCE_CONTINUOUS_READING);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mLastFocusedWindowId = focusedNode.getWindowId();
}
AccessibilityNodeInfoUtils.recycleNodes(sourceNode, focusedNode);
return true;
}
示例12: format
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
@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();
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;
}
示例13: followScrollEvent
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
private void followScrollEvent(AccessibilityNodeInfoCompat source,
AccessibilityRecordCompat record,
@TraversalStrategy.SearchDirectionOrUnknown int direction,
boolean wasScrollAction) {
// SEARCH_FOCUS_UNKNOWN can be passed, so need to guarantee that direction is a
// @TraversalStrategy.SearchDirection before continuing.
if (direction == TraversalStrategy.SEARCH_FOCUS_UNKNOWN) {
return;
}
AccessibilityNodeInfoCompat root = null;
AccessibilityNodeInfoCompat accessibilityFocused = null;
try {
// First, see if we've already placed accessibility focus.
root = AccessibilityServiceCompatUtils.getRootInAccessibilityFocusedWindow(mService);
if (root == null) {
return;
}
accessibilityFocused = root.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY);
boolean validAccessibilityFocus = AccessibilityNodeInfoUtils.shouldFocusNode(
accessibilityFocused);
// there are cases when scrollable container was scrolled and application set
// focus on node that is on new container page. We should keep this focus
boolean hasInputFocus = accessibilityFocused != null
&& accessibilityFocused.isFocused();
if (validAccessibilityFocus && (hasInputFocus || !wasScrollAction)) {
// focused on valid node and scrolled not by scroll action
// keep focus
return;
}
if (validAccessibilityFocus) {
// focused on valid node and scrolled by scroll action
// focus on next focusable node
if (source == null) {
source = record.getSource();
if (source == null) return;
}
if (!AccessibilityNodeInfoUtils.hasAncestor(accessibilityFocused, source)) {
return;
}
TraversalStrategy traversal = TraversalStrategyUtils.getTraversalStrategy(root,
direction);
try {
focusNextFocusedNode(traversal, accessibilityFocused, direction);
} finally {
traversal.recycle();
}
} else {
if (mLastFocusedItem == null) {
// there was no focus - don't set focus
return;
}
if (source == null) {
source = record.getSource();
if (source == null) return;
}
if (mLastFocusedItem.equals(source) ||
AccessibilityNodeInfoUtils.hasAncestor(mLastFocusedItem, source)) {
// There is no focus now, but it was on source node's child before
// Try focusing the appropriate child node.
if (tryFocusingChild(source, direction)) {
return;
}
// Finally, try focusing the scrollable node itself.
tryFocusing(source);
}
}
} finally {
AccessibilityNodeInfoUtils.recycleNodes(root, accessibilityFocused);
}
}
示例14: setFocusOnView
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
/**
* @param record the AccessbilityRecord for the event
* @param isViewFocusedEvent true if the event is TYPE_VIEW_FOCUSED, otherwise it is
* TYPE_VIEW_SELECTED.
*/
private boolean setFocusOnView(AccessibilityRecordCompat record, boolean isViewFocusedEvent) {
AccessibilityNodeInfoCompat source = null;
AccessibilityNodeInfoCompat existing = null;
AccessibilityNodeInfoCompat child = null;
try {
source = record.getSource();
if (source == null) {
return false;
}
if (record.getItemCount() > 0) {
final int index = (record.getCurrentItemIndex() - record.getFromIndex());
if (index >= 0 && index < source.getChildCount()) {
child = source.getChild(index);
if (child != null) {
if (AccessibilityNodeInfoUtils.isTopLevelScrollItem(child) &&
tryFocusing(child)) {
return true;
}
}
}
}
if (!isViewFocusedEvent) {
return false;
}
// Logic below is only specific to TYPE_VIEW_FOCUSED event
// Try focusing the source node.
if (tryFocusing(source)) {
return true;
}
// If we fail and the source node already contains focus, abort.
existing = source.findFocus(AccessibilityNodeInfo.FOCUS_ACCESSIBILITY);
if (existing != null) {
return false;
}
// If we fail to focus a node, perhaps because it is a focusable
// but non-speaking container, we should still attempt to place
// focus on a speaking child within the container.
child = AccessibilityNodeInfoUtils.searchFromBfs(source,
AccessibilityNodeInfoUtils.FILTER_SHOULD_FOCUS);
return child != null && tryFocusing(child);
} finally {
AccessibilityNodeInfoUtils.recycleNodes(source, existing, child);
}
}
示例15: onAccessibilityEvent
import android.support.v4.view.accessibility.AccessibilityRecordCompat; //导入方法依赖的package包/类
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
// Only announce relevant events
if (!AccessibilityEventUtils.eventMatchesAnyType(event, MASK_ACCEPTED_EVENT_TYPES)) {
return;
}
final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
final AccessibilityNodeInfoCompat source = record.getSource();
// Drop consecutive qualifying events from the same node.
if (mLastNode != null && mLastNode.equals(source)) {
return;
} else {
if (mLastNode != null) {
mLastNode.recycle();
}
mLastNode = source;
}
// Only announce nodes that have legacy web content.
if (!WebInterfaceUtils.hasLegacyWebContent(source)) {
return;
}
if (WebInterfaceUtils.isScriptInjectionEnabled(mService)) {
// Instruct accessibility script to announce the page title as long
// as continuous reading isn't active.
final FullScreenReadController fullScreen = mService.getFullScreenReadController();
if (fullScreen.isReadingLegacyWebContent()) {
// Reset the state for full screen reading now that we've moved
// into web content.
fullScreen.interrupt();
} else {
WebInterfaceUtils.performSpecialAction(
source, WebInterfaceUtils.ACTION_READ_PAGE_TITLE_ELEMENT);
}
} else if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR1) {
// On versions that include a script injection preference, inform
// the user that script injection is disabled.
final String preferenceName = AutomationUtils.getPackageString(
mService, PACKAGE_SETTINGS, RES_NAME_SCRIPT_INJECTION_TITLE);
if (preferenceName != null) {
final CharSequence announcement = mService.getString(
R.string.hint_script_injection, preferenceName);
mService.getSpeechController().speak(
announcement, SpeechController.QUEUE_MODE_INTERRUPT, 0, null);
}
}
}