下面列出了android.support.v4.view.accessibility.AccessibilityNodeInfoCompat#ACTION_CLICK 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected boolean onPerformActionForVirtualView(int virtualViewId, int action, Bundle arguments) {
if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
final int type = getTypeFromId(virtualViewId);
final int value = getValueFromId(virtualViewId);
if (type == TYPE_HOUR) {
final int hour = mIs24HourMode ? value : hour12To24(value, mAmOrPm);
setCurrentHour(hour);
return true;
} else if (type == TYPE_MINUTE) {
setCurrentMinute(value);
return true;
}
}
return false;
}
@Override
protected boolean onPerformActionForVirtualView(int virtualViewId, int action,
Bundle arguments) {
if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
final int type = getTypeFromId(virtualViewId);
final int value = getValueFromId(virtualViewId);
if (type == TYPE_HOUR) {
final int hour = mIs24HourMode ? value : hour12To24(value, mAmOrPm);
setCurrentHour(hour);
return true;
} else if (type == TYPE_MINUTE) {
setCurrentMinute(value);
return true;
}
}
return false;
}
/**
* Performs the specified accessibility action for the given key.
*
* @param key The on which to perform the action.
* @param action The action to perform.
* @return The result of performing the action, or false if the action is not supported.
*/
boolean performActionForKey(final Key key, final int action) {
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS:
mAccessibilityFocusedView = getVirtualViewIdOf(key);
sendAccessibilityEventForKey(
key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUSED);
return true;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
mAccessibilityFocusedView = UNDEFINED;
sendAccessibilityEventForKey(
key, AccessibilityEventCompat.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED);
return true;
case AccessibilityNodeInfoCompat.ACTION_CLICK:
sendAccessibilityEventForKey(key, AccessibilityEvent.TYPE_VIEW_CLICKED);
mDelegate.performClickOn(key);
return true;
case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
sendAccessibilityEventForKey(key, AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
mDelegate.performLongClickOn(key);
return true;
default:
return false;
}
}
@Override
protected boolean onPerformActionForVirtualView(int viewId, int action, Bundle args) {
if (action == AccessibilityNodeInfoCompat.ACTION_CLICK && viewId != INVALID_ID) {
String confirmation = getConfirmationForIconDrop(viewId);
mDelegate.handleAccessibleDrop(mView, getItemBounds(viewId), confirmation);
return true;
}
return false;
}
@Override
protected boolean onPerformActionForVirtualView(
int virtualViewId, int action, Bundle arguments) {
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_CLICK:
return true;
}
return false;
}
@Override
protected boolean onPerformActionForVirtualView(
int virtualViewId, int action, Bundle arguments) {
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_CLICK:
return true;
}
return false;
}
@Override
protected boolean onPerformActionForVirtualView(int viewId, int action, Bundle args) {
if (action == AccessibilityNodeInfoCompat.ACTION_CLICK && viewId != INVALID_ID) {
String confirmation = getConfirmationForIconDrop(viewId);
mDelegate.handleAccessibleDrop(mView, getItemBounds(viewId), confirmation);
return true;
}
return false;
}
@Override
protected boolean onPerformActionForVirtualView(int virtualViewId, int action, Bundle arguments) {
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_CLICK:
return onDayClicked(virtualViewId);
}
return false;
}
@Override
protected boolean onPerformActionForVirtualView(
int virtualViewId, int action, Bundle arguments) {
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_CLICK:
mVirtualViews.get(virtualViewId).handleClick(LayoutManager.time());
return true;
}
return false;
}
@Override
protected boolean onPerformActionForVirtualView(int virtualViewId, int action,
Bundle arguments) {
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_CLICK:
return onDayClicked(virtualViewId);
}
return false;
}
@Override
protected boolean onPerformActionForVirtualView(
int virtualViewId, int action, Bundle arguments) {
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_CLICK:
// Click handling should be consistent with
// onTouchEvent(). This ensures that the view works the
// same whether accessibility is turned on or off.
return onItemClicked(virtualViewId);
}
return false;
}
@Nullable
public static String getActions(View view) {
AccessibilityNodeInfoCompat node = createNodeInfoFromView(view);
try {
final StringBuilder actionLabels = new StringBuilder();
final String separator = ", ";
for (AccessibilityActionCompat action : node.getActionList()) {
if (actionLabels.length() > 0) {
actionLabels.append(separator);
}
switch (action.getId()) {
case AccessibilityNodeInfoCompat.ACTION_FOCUS:
actionLabels.append("focus");
break;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_FOCUS:
actionLabels.append("clear-focus");
break;
case AccessibilityNodeInfoCompat.ACTION_SELECT:
actionLabels.append("select");
break;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION:
actionLabels.append("clear-selection");
break;
case AccessibilityNodeInfoCompat.ACTION_CLICK:
actionLabels.append("click");
break;
case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK:
actionLabels.append("long-click");
break;
case AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS:
actionLabels.append("accessibility-focus");
break;
case AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS:
actionLabels.append("clear-accessibility-focus");
break;
case AccessibilityNodeInfoCompat.ACTION_NEXT_AT_MOVEMENT_GRANULARITY:
actionLabels.append("next-at-movement-granularity");
break;
case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY:
actionLabels.append("previous-at-movement-granularity");
break;
case AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT:
actionLabels.append("next-html-element");
break;
case AccessibilityNodeInfoCompat.ACTION_PREVIOUS_HTML_ELEMENT:
actionLabels.append("previous-html-element");
break;
case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD:
actionLabels.append("scroll-forward");
break;
case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD:
actionLabels.append("scroll-backward");
break;
case AccessibilityNodeInfoCompat.ACTION_CUT:
actionLabels.append("cut");
break;
case AccessibilityNodeInfoCompat.ACTION_COPY:
actionLabels.append("copy");
break;
case AccessibilityNodeInfoCompat.ACTION_PASTE:
actionLabels.append("paste");
break;
case AccessibilityNodeInfoCompat.ACTION_SET_SELECTION:
actionLabels.append("set-selection");
break;
default:
CharSequence label = action.getLabel();
if (label != null) {
actionLabels.append(label);
} else {
actionLabels.append("unknown");
}
break;
}
}
return actionLabels.length() > 0 ? actionLabels.toString() : null;
} finally {
node.recycle();
}
}
public ClickActionDelegate(Context context, int resId) {
CharSequence label = context.getString(resId);
mClickAction = new AccessibilityNodeInfoCompat.AccessibilityActionCompat(AccessibilityNodeInfoCompat.ACTION_CLICK,
label);
}
public ClickActionDelegate(Context context, int resId) {
mClickAction = new AccessibilityActionCompat(
AccessibilityNodeInfoCompat.ACTION_CLICK, context.getString(resId));
}
@Override
public boolean performAccessibilityAction( View host, int action, Bundle arguments ) {
if ( super.performAccessibilityAction( host, action, arguments ) ) {
return true;
}
final int position = getPositionForView( host );
final ListAdapter adapter = getAdapter();
if ( ( position == INVALID_POSITION ) || ( adapter == null ) ) {
// Cannot perform actions on invalid items.
return false;
}
if ( !isEnabled() || !adapter.isEnabled( position ) ) {
// Cannot perform actions on disabled items.
return false;
}
final long id = getItemIdAtPosition( position );
switch ( action ) {
case AccessibilityNodeInfoCompat.ACTION_CLEAR_SELECTION: {
if ( getSelectedItemPosition() == position ) {
setSelection( INVALID_POSITION );
return true;
}
}
return false;
case AccessibilityNodeInfoCompat.ACTION_SELECT: {
if ( getSelectedItemPosition() != position ) {
setSelection( position );
return true;
}
}
return false;
case AccessibilityNodeInfoCompat.ACTION_CLICK: {
if ( isClickable() ) {
return performItemClick( host, position, id );
}
}
return false;
case AccessibilityNodeInfoCompat.ACTION_LONG_CLICK: {
if ( isLongClickable() ) {
return performLongPress( host, position, id );
}
}
return false;
}
return false;
}