List of usage examples for android.support.v4.view.accessibility AccessibilityNodeInfoCompat addAction
public void addAction(int action)
From source file:com.android.talkbacktests.testsession.StandardAndroidWidgetTest.java
@Override public View getView(final LayoutInflater inflater, ViewGroup container, final Context context) { View view = inflater.inflate(R.layout.test_standard_android_widget, container, false); final Button contDescButton = (Button) view.findViewById(R.id.test_standard_android_widget_button2); contDescButton.setOnClickListener(new View.OnClickListener() { @Override//from w w w. j a v a2s .c om public void onClick(View view) { mCount++; contDescButton.setContentDescription(getString(R.string.toast_content_changed_template, mCount)); } }); Button toastButton = (Button) view.findViewById(R.id.test_standard_android_widget_button3); toastButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(context, R.string.toast_expand_button_clicked, Toast.LENGTH_LONG).show(); } }); ViewCompat.setAccessibilityDelegate(toastButton, new AccessibilityDelegateCompat() { public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); info.addAction(new AccessibilityNodeInfoCompat.AccessibilityActionCompat( AccessibilityNodeInfoCompat.ACTION_CLICK, getString(R.string.expand_button_action_label))); } }); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, R.array.city_array, android.R.layout.simple_spinner_item); Spinner spinner = (Spinner) view.findViewById(R.id.test_standard_android_widget_spinner); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); AutoCompleteTextView autocomplete = (AutoCompleteTextView) view .findViewById(R.id.test_standard_android_widget_autocomplete); autocomplete.setAdapter(adapter); mProgressBar = (ProgressBar) view.findViewById(R.id.test_standard_android_widget_progress_bar); mRunnable = new Runnable() { @Override public void run() { mProgressStatus += 5; mProgressBar.setProgress(mProgressStatus); if (mProgressStatus < 100) { mHandler.postDelayed(this, 1000); } } }; resetProgressBar(); View resetProgressBarButton = view.findViewById(R.id.test_standard_android_widget_reset_button); resetProgressBarButton.setOnClickListener(this); return view; }
From source file:android.support.design.widget.BottomSheetDialog.java
private View wrapInBottomSheet(int layoutResId, View view, ViewGroup.LayoutParams params) { final CoordinatorLayout coordinator = (CoordinatorLayout) View.inflate(getContext(), R.layout.design_bottom_sheet_dialog, null); if (layoutResId != 0 && view == null) { view = getLayoutInflater().inflate(layoutResId, coordinator, false); }/*from w ww. j av a2 s . co m*/ FrameLayout bottomSheet = (FrameLayout) coordinator.findViewById(R.id.design_bottom_sheet); mBehavior = BottomSheetBehavior.from(bottomSheet); mBehavior.setBottomSheetCallback(mBottomSheetCallback); mBehavior.setHideable(mCancelable); if (params == null) { bottomSheet.addView(view); } else { bottomSheet.addView(view, params); } // We treat the CoordinatorLayout as outside the dialog though it is technically inside coordinator.findViewById(R.id.touch_outside).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCancelable && isShowing() && shouldWindowCloseOnTouchOutside()) { cancel(); } } }); // Handle accessibility events ViewCompat.setAccessibilityDelegate(bottomSheet, new AccessibilityDelegateCompat() { @Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); if (mCancelable) { info.addAction(AccessibilityNodeInfoCompat.ACTION_DISMISS); info.setDismissable(true); } else { info.setDismissable(false); } } @Override public boolean performAccessibilityAction(View host, int action, Bundle args) { if (action == AccessibilityNodeInfoCompat.ACTION_DISMISS && mCancelable) { cancel(); return true; } return super.performAccessibilityAction(host, action, args); } }); return coordinator; }
From source file:com.android.launcher3.accessibility.DragAndDropAccessibilityDelegate.java
@Override protected void onPopulateNodeForVirtualView(int id, AccessibilityNodeInfoCompat node) { if (id == INVALID_ID) { throw new IllegalArgumentException("Invalid virtual view id"); }//from w ww . j a v a2 s .c o m node.setContentDescription(getLocationDescriptionForIconDrop(id)); node.setBoundsInParent(getItemBounds(id)); node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); node.setClickable(true); node.setFocusable(true); }
From source file:org.connectbot.views.CheckableMenuItem.java
public CheckableMenuItem(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mRootView = inflate(context, R.layout.view_checkablemenuitem, this); mTitle = (TextView) mRootView.findViewById(R.id.title); mSummary = (TextView) mRootView.findViewById(R.id.summary); mSwitch = (SwitchCompat) findViewById(R.id.checkbox_switch); setFocusable(true);//from w w w.j a v a2 s . co m mAccessHelper = new ExploreByTouchHelper(this) { private final Rect mTmpRect = new Rect(); @Override protected int getVirtualViewAt(float x, float y) { return HOST_ID; } @Override protected void getVisibleVirtualViews(List<Integer> virtualViewIds) { } @Override protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) { if (virtualViewId != HOST_ID) { // TODO(kroot): remove this when the bug is fixed. event.setContentDescription(PLACEHOLDER_STRING); return; } event.setContentDescription(mTitle.getText() + " " + mSummary.getText()); event.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME); event.setChecked(isChecked()); } @Override protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) { if (virtualViewId != HOST_ID) { // TODO(kroot): remove this when the bug is fixed. node.setBoundsInParent(mPlaceHolderRect); node.setContentDescription(PLACEHOLDER_STRING); return; } mTmpRect.set(0, 0, CheckableMenuItem.this.getWidth(), CheckableMenuItem.this.getHeight()); node.setBoundsInParent(mTmpRect); node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); node.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME); node.setCheckable(true); node.setChecked(isChecked()); node.addChild(mTitle); node.addChild(mSummary); } @Override protected boolean onPerformActionForVirtualView(int virtualViewId, int action, Bundle arguments) { if (virtualViewId != HOST_ID) { return false; } if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) { mSwitch.toggle(); sendAccessibilityEvent(mRootView, AccessibilityEventCompat.CONTENT_CHANGE_TYPE_UNDEFINED); return true; } return false; } }; ViewCompat.setAccessibilityDelegate(mRootView, mAccessHelper); setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mSwitch.toggle(); } }); if (attrs != null) { TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.CheckableMenuItem, 0, 0); @DrawableRes int iconRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_android_icon, 0); @StringRes int titleRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_android_title, 0); @StringRes int summaryRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_summary, 0); typedArray.recycle(); ImageView icon = (ImageView) mRootView.findViewById(R.id.icon); mTitle.setText(titleRes); if (iconRes != 0) { Resources resources = context.getResources(); Resources.Theme theme = context.getTheme(); Drawable iconDrawable = VectorDrawableCompat.create(resources, iconRes, theme); icon.setImageDrawable(iconDrawable); } if (summaryRes != 0) { mSummary.setText(summaryRes); } } }
From source file:com.redinput.datetimepickercompat.date.DayPickerView.java
private void installAccessibilityDelegate() { // The accessibility delegate enables customizing accessibility behavior // via composition as opposed as inheritance. The main benefit is that // one can write a backwards compatible application by setting the delegate // only if the API level is high enough i.e. the delegate is part of the APIs. // The easiest way to achieve that is by using the support library which // takes the burden of checking API version and knowing which API version // introduced the delegate off the developer. ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() { @Override/*ww w. ja v a 2 s. c o m*/ public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { super.onInitializeAccessibilityEvent(host, event); // Note that View.onInitializeAccessibilityNodeInfo was introduced in // ICS and we would like to tweak a bit the text that is reported to // accessibility services via the AccessibilityNodeInfo. event.setItemCount(-1); } @Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); // Note that View.onInitializeAccessibilityNodeInfo was introduced in // ICS and we would like to tweak a bit the text that is reported to // accessibility services via the AccessibilityNodeInfo. info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD); info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD); } @Override public boolean performAccessibilityAction(View host, int action, Bundle args) { if (action != AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD && action != AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) { return super.performAccessibilityAction(host, action, args); } // Figure out what month is showing. int firstVisiblePosition = getFirstVisiblePosition(); int month = firstVisiblePosition % 12; int year = firstVisiblePosition / 12 + mController.getMinYear(); CalendarDay day = new CalendarDay(year, month, 1); // Scroll either forward or backward one month. if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) { day.month++; if (day.month == 12) { day.month = 0; day.year++; } } else if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) { View firstVisibleView = getChildAt(0); // If the view is fully visible, jump one month back. Otherwise, we'll just jump // to the first day of first visible month. if (firstVisibleView != null && firstVisibleView.getTop() >= -1) { // There's an off-by-one somewhere, so the top of the first visible item // will // actually be -1 when it's at the exact top. day.month--; if (day.month == -1) { day.month = 11; day.year--; } } } // Go to that month. Utils.tryAccessibilityAnnounce(host, getMonthAndYearString(day)); goTo(day, true, false, true); mPerformingScroll = true; return true; } }); }
From source file:com.android.datetimepicker.time.RadialPickerLayout.java
private void installAccessibilityDelegate() { ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() { /**//from w ww . j a v a 2 s.c o m * Necessary for accessibility, to ensure we support "scrolling" forward and backward * in the circle. */ @Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD); } }); }
From source file:com.yyl.inputmethod.accessibility.AccessibilityEntityProvider.java
/** * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}. * <p>//from w w w . ja va 2 s . c o m * A virtual descendant is an imaginary View that is reported as a part of * the view hierarchy for accessibility purposes. This enables custom views * that draw complex content to report them selves as a tree of virtual * views, thus conveying their logical structure. * </p> * <p> * The implementer is responsible for obtaining an accessibility node info * from the pool of reusable instances and setting the desired properties of * the node info before returning it. * </p> * * @param virtualViewId A client defined virtual view id. * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host * View. * @see AccessibilityNodeInfoCompat */ @Override public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) { if (virtualViewId == UNDEFINED) { return null; } if (virtualViewId == View.NO_ID) { // We are requested to create an AccessibilityNodeInfo describing // this View, i.e. the root of the virtual sub-tree. final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView); ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo); // Add the virtual children of the root View. final Keyboard keyboard = mKeyboardView.getKeyboard(); final Key[] keys = keyboard.mKeys; for (Key key : keys) { final int childVirtualViewId = generateVirtualViewIdForKey(key); rootInfo.addChild(mKeyboardView, childVirtualViewId); } return rootInfo; } // Find the view that corresponds to the given id. final Key key = mVirtualViewIdToKey.get(virtualViewId); if (key == null) { Log.e(TAG, "Invalid virtual view ID: " + virtualViewId); return null; } final String keyDescription = getKeyDescription(key); final Rect boundsInParent = key.mHitBox; // Calculate the key's in-screen bounds. mTempBoundsInScreen.set(boundsInParent); mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation)); final Rect boundsInScreen = mTempBoundsInScreen; // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view. final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); info.setPackageName(mKeyboardView.getContext().getPackageName()); info.setClassName(key.getClass().getName()); info.setContentDescription(keyDescription); info.setBoundsInParent(boundsInParent); info.setBoundsInScreen(boundsInScreen); info.setParent(mKeyboardView); info.setSource(mKeyboardView, virtualViewId); info.setBoundsInScreen(boundsInScreen); info.setEnabled(true); info.setVisibleToUser(true); if (mAccessibilityFocusedView == virtualViewId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } return info; }
From source file:com.onyx.latinime.accessibility.AccessibilityEntityProvider.java
/** * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}. * <p>// ww w. ja v a 2 s . c om * A virtual descendant is an imaginary View that is reported as a part of * the view hierarchy for accessibility purposes. This enables custom views * that draw complex content to report them selves as a tree of virtual * views, thus conveying their logical structure. * </p> * <p> * The implementer is responsible for obtaining an accessibility node info * from the pool of reusable instances and setting the desired properties of * the node info before returning it. * </p> * * @param virtualViewId A client defined virtual view id. * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host * View. * @see AccessibilityNodeInfoCompat */ @Override public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) { if (virtualViewId == UNDEFINED) { return null; } if (virtualViewId == View.NO_ID) { // We are requested to create an AccessibilityNodeInfo describing // this View, i.e. the root of the virtual sub-tree. final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView); ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo); // Add the virtual children of the root View. final Keyboard keyboard = mKeyboardView.getKeyboard(); final Key[] keys = keyboard.getKeys(); for (Key key : keys) { final int childVirtualViewId = generateVirtualViewIdForKey(key); rootInfo.addChild(mKeyboardView, childVirtualViewId); } return rootInfo; } // Find the view that corresponds to the given id. final Key key = mVirtualViewIdToKey.get(virtualViewId); if (key == null) { Log.e(TAG, "Invalid virtual view ID: " + virtualViewId); return null; } final String keyDescription = getKeyDescription(key); final Rect boundsInParent = key.getHitBox(); // Calculate the key's in-screen bounds. mTempBoundsInScreen.set(boundsInParent); mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation)); final Rect boundsInScreen = mTempBoundsInScreen; // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view. final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); info.setPackageName(mKeyboardView.getContext().getPackageName()); info.setClassName(key.getClass().getName()); info.setContentDescription(keyDescription); info.setBoundsInParent(boundsInParent); info.setBoundsInScreen(boundsInScreen); info.setParent(mKeyboardView); info.setSource(mKeyboardView, virtualViewId); info.setBoundsInScreen(boundsInScreen); info.setEnabled(true); info.setVisibleToUser(true); if (mAccessibilityFocusedView == virtualViewId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } return info; }
From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityNodeProvider.java
/** * Returns an {@link AccessibilityNodeInfoCompat} representing a virtual * view, i.e. a descendant of the host View, with the given <code>virtualViewId</code> or * the host View itself if <code>virtualViewId</code> equals to {@link View#NO_ID}. * <p>//from w w w . j av a 2s .co m * A virtual descendant is an imaginary View that is reported as a part of * the view hierarchy for accessibility purposes. This enables custom views * that draw complex content to report them selves as a tree of virtual * views, thus conveying their logical structure. * </p> * <p> * The implementer is responsible for obtaining an accessibility node info * from the pool of reusable instances and setting the desired properties of * the node info before returning it. * </p> * * @param virtualViewId A client defined virtual view id. * @return A populated {@link AccessibilityNodeInfoCompat} for a virtual descendant or the host * View. * @see AccessibilityNodeInfoCompat */ @Override public AccessibilityNodeInfoCompat createAccessibilityNodeInfo(final int virtualViewId) { if (virtualViewId == UNDEFINED) { return null; } if (virtualViewId == View.NO_ID) { // We are requested to create an AccessibilityNodeInfo describing // this View, i.e. the root of the virtual sub-tree. final AccessibilityNodeInfoCompat rootInfo = AccessibilityNodeInfoCompat.obtain(mKeyboardView); ViewCompat.onInitializeAccessibilityNodeInfo(mKeyboardView, rootInfo); updateParentLocation(); // Add the virtual children of the root View. final List<Key> sortedKeys = mKeyboard.getSortedKeys(); final int size = sortedKeys.size(); for (int index = 0; index < size; index++) { final Key key = sortedKeys.get(index); if (key.isSpacer()) { continue; } // Use an index of the sorted keys list as a virtual view id. rootInfo.addChild(mKeyboardView, index); } return rootInfo; } // Find the key that corresponds to the given virtual view id. final Key key = getKeyOf(virtualViewId); if (key == null) { Log.e(TAG, "Invalid virtual view ID: " + virtualViewId); return null; } final String keyDescription = getKeyDescription(key); final Rect boundsInParent = key.getHitBox(); // Calculate the key's in-screen bounds. mTempBoundsInScreen.set(boundsInParent); mTempBoundsInScreen.offset(CoordinateUtils.x(mParentLocation), CoordinateUtils.y(mParentLocation)); final Rect boundsInScreen = mTempBoundsInScreen; // Obtain and initialize an AccessibilityNodeInfo with information about the virtual view. final AccessibilityNodeInfoCompat info = AccessibilityNodeInfoCompat.obtain(); info.setPackageName(mKeyboardView.getContext().getPackageName()); info.setClassName(key.getClass().getName()); info.setContentDescription(keyDescription); info.setBoundsInParent(boundsInParent); info.setBoundsInScreen(boundsInScreen); info.setParent(mKeyboardView); info.setSource(mKeyboardView, virtualViewId); info.setEnabled(key.isEnabled()); info.setVisibleToUser(true); // Don't add ACTION_CLICK and ACTION_LONG_CLOCK actions while hovering on the key. // See {@link #onHoverEnterTo(Key)} and {@link #onHoverExitFrom(Key)}. if (virtualViewId != mHoveringNodeId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); if (key.isLongPressEnabled()) { info.addAction(AccessibilityNodeInfoCompat.ACTION_LONG_CLICK); } } if (mAccessibilityFocusedView == virtualViewId) { info.addAction(AccessibilityNodeInfoCompat.ACTION_CLEAR_ACCESSIBILITY_FOCUS); } else { info.addAction(AccessibilityNodeInfoCompat.ACTION_ACCESSIBILITY_FOCUS); } return info; }
From source file:com.android.settings.localepicker.LocaleLinearLayoutManager.java
@Override public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info); final int itemCount = this.getItemCount(); final int position = this.getPosition(host); final LocaleDragCell dragCell = (LocaleDragCell) host; // We want the description to be something not localizable, so that any TTS engine for // any language can handle it. And we want the position to be part of it. // So we use something like "2, French (France)" final String description = (position + 1) + ", " + dragCell.getCheckbox().getContentDescription(); info.setContentDescription(description); if (mAdapter.isRemoveMode()) { // We don't move things around in remove mode return;/*ww w. ja va2s .c o m*/ } // The order in which we add the actions is important for the circular selection menu. // With the current order the "up" action will be (more or less) up, and "down" more // or less down ("more or less" because we have 5 actions) if (position > 0) { // it is not the first one info.addAction(mActionMoveUp); info.addAction(mActionMoveTop); } if (position + 1 < itemCount) { // it is not the last one info.addAction(mActionMoveDown); info.addAction(mActionMoveBottom); } if (itemCount > 1) { info.addAction(mActionRemove); } }