List of usage examples for android.view View getContentDescription
@ViewDebug.ExportedProperty(category = "accessibility") public CharSequence getContentDescription()
From source file:Main.java
/** * Sets up a cheat sheet (tooltip) for the given view by setting its {@link * View.OnLongClickListener}. When the view is long-pressed, a {@link Toast} with * the view's {@link View#getContentDescription() content description} will be * shown either above (default) or below the view (if there isn't room above it). * * @param view The view to add a cheat sheet for. *//* ww w. ja v a 2s . c o m*/ public static void setup(View view) { view.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { return show(view, view.getContentDescription()); } }); }
From source file:com.google.android.apps.common.testing.accessibility.framework.ViewAccessibilityUtils.java
/** * Determines if the supplied {@link View} has a contentDescription or text. * * @param view The {@link View} to evaluate * @return {@code true} if {@code view} has a contentDescription or text. *//*from ww w. j ava2 s .co m*/ private static boolean hasText(View view) { if (!TextUtils.isEmpty(view.getContentDescription())) { return true; } else if (view instanceof TextView) { return !TextUtils.isEmpty(((TextView) view).getText()); } return false; }
From source file:edu.ucla.cens.systemlog.Analytics.java
/** * Log information about a view being interacted with * /*from w w w . ja va2 s.com*/ * @param view * @param name Human readable name for widget */ public static void widget(View view, String name, String extra) { StringBuilder builder = new StringBuilder(); builder.append(view.getId()); if (name != null) builder.append(" ").append(name); else if (!TextUtils.isEmpty(view.getContentDescription())) builder.append(" ").append(view.getContentDescription()); if (extra != null) builder.append(" [").append(extra).append("]"); log(view.getContext(), "widget", builder); }
From source file:com.facebook.appevents.codeless.internal.ViewHierarchy.java
public static JSONObject setBasicInfoOfView(View view, JSONObject json) { try {//from w ww . jav a2s.c o m String text = getTextOfView(view); String hint = getHintOfView(view); Object tag = view.getTag(); CharSequence description = view.getContentDescription(); json.put(CLASS_NAME_KEY, view.getClass().getCanonicalName()); json.put(CLASS_TYPE_BITMASK_KEY, getClassTypeBitmask(view)); json.put(ID_KEY, view.getId()); if (!SensitiveUserDataUtils.isSensitiveUserData(view)) { json.put(TEXT_KEY, text); } else { json.put(TEXT_KEY, ""); } json.put(HINT_KEY, hint); if (tag != null) { json.put(TAG_KEY, tag.toString()); } if (description != null) { json.put(DESC_KEY, description.toString()); } JSONObject dimension = getDimensionOfView(view); json.put(DIMENSION_KEY, dimension); } catch (JSONException e) { Utility.logd(TAG, e); } return json; }
From source file:com.google.android.apps.common.testing.accessibility.framework.AccessibilityCheckUtils.java
/** * Retrieve text for a {@link View}, which may include text from the children of the {@code View}. * This text is an approximation of, but not identical to, what TalkBack would speak for the * {@link View}. One difference is that there are no separators between the speakable text from * different nodes.//from ww w . ja v a 2 s. c o m * <p> * TalkBack also will not speak {@link View}s that aren't visible. This method assumes that the * {@link View} passed in is visible. The visibility of the rest of child nodes is inferred from * {@code view.getVisibility}. * * @param view The {@link View} whose text should be returned. * * @return Speakable text derived from the {@link View} and its children. Returns an empty string * if there is no such text, and {@code null} if {@code view == null}. */ static CharSequence getSpeakableTextForView(View view) { if (view == null) { return null; } View labelForThisView = ViewAccessibilityUtils.getLabelForView(view); if (labelForThisView != null) { return getSpeakableTextForView(labelForThisView); } SpannableStringBuilder returnStringBuilder = new SpannableStringBuilder(""); // Accessibility importance is considered only on Jelly Bean and above if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) || ViewAccessibilityUtils.isImportantForAccessibility(view)) { if (!TextUtils.isEmpty(view.getContentDescription())) { // contentDescription always wins out over other properties return view.getContentDescription(); } if (view instanceof TextView) { if (!TextUtils.isEmpty(((TextView) view).getText())) { returnStringBuilder.append(((TextView) view).getText()); } else if (!TextUtils.isEmpty(((TextView) view).getHint())) { returnStringBuilder.append(((TextView) view).getHint()); } } } if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; // TODO(sjrush): Only evaluate child views if they're importantForAccessibility. for (int i = 0; i < group.getChildCount(); ++i) { View childView = group.getChildAt(i); if ((childView.getVisibility() == View.VISIBLE) && !ViewAccessibilityUtils.isActionableForAccessibility(childView)) { returnStringBuilder.append(getSpeakableTextForView(childView)); } } } if (view instanceof CompoundButton) { if (((CompoundButton) view).isChecked()) { StringBuilderUtils.appendWithSeparator(returnStringBuilder, "Checked"); } else { StringBuilderUtils.appendWithSeparator(returnStringBuilder, "Not checked"); } } return returnStringBuilder; }
From source file:Main.java
/** * Display a {@link Toast} letting the user know what an item does when long * pressed.//from w w w. j a va 2s .c o m * * @param view The {@link View} to copy the content description from. */ public static void showCheatSheet(final View view) { final int[] screenPos = new int[2]; // origin is device display final Rect displayFrame = new Rect(); // includes decorations (e.g. // status bar) view.getLocationOnScreen(screenPos); view.getWindowVisibleDisplayFrame(displayFrame); final Context context = view.getContext(); final int viewWidth = view.getWidth(); final int viewHeight = view.getHeight(); final int viewCenterX = screenPos[0] + viewWidth / 2; final int screenWidth = context.getResources().getDisplayMetrics().widthPixels; final int estimatedToastHeight = (int) (48 * context.getResources().getDisplayMetrics().density); final Toast cheatSheet = Toast.makeText(context, view.getContentDescription(), Toast.LENGTH_SHORT); final boolean showBelow = screenPos[1] < estimatedToastHeight; if (showBelow) { // Show below // Offsets are after decorations (e.g. status bar) are factored in cheatSheet.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, screenPos[1] - displayFrame.top + viewHeight); } else { // Show above // Offsets are after decorations (e.g. status bar) are factored in cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, viewCenterX - screenWidth / 2, displayFrame.bottom - screenPos[1]); } cheatSheet.show(); }
From source file:com.adkdevelopment.e_contact.DetailFragment.java
@Override public void onImageItemClick(View view, int position) { Toast.makeText(getContext(), view.getContentDescription() + " " + position, Toast.LENGTH_SHORT).show(); }
From source file:net.reichholf.dreamdroid.fragment.abs.DreamDroidFragment.java
protected void registerFab(int id, View view, View.OnClickListener onClickListener) { FloatingActionButton fab = (FloatingActionButton) view.findViewById(id); if (fab == null) return;/*from w w w . j av a2 s . c o m*/ fab.setOnClickListener(onClickListener); fab.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(getActionBarActivity(), v.getContentDescription(), Toast.LENGTH_SHORT).show(); return true; } }); fab.show(); }
From source file:net.reichholf.dreamdroid.fragment.abs.DreamDroidListFragment.java
protected void registerFab(int id, View view, View.OnClickListener onClickListener, AbsListView listView, boolean topAligned, boolean inverted) { FloatingActionButton fab = (FloatingActionButton) view.findViewById(id); if (fab == null) return;/*from w w w . j a v a 2s. c o m*/ if (listView != null) fab.attachToListView(listView, topAligned, inverted); fab.setOnClickListener(onClickListener); fab.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(getActionBarActivity(), v.getContentDescription(), Toast.LENGTH_SHORT).show(); return true; } }); }
From source file:net.reichholf.dreamdroid.fragment.abs.BaseFragment.java
protected void registerFab(int id, int descriptionId, int backgroundResId, View.OnClickListener onClickListener) { FloatingActionButton fab = (FloatingActionButton) getAppCompatActivity().findViewById(id); if (fab == null) return;//from w w w .j a va2 s. co m fab.setTag(R.id.fab_scrolling_view_behavior_enabled, true); fab.show(); fab.setContentDescription(getString(descriptionId)); fab.setImageResource(backgroundResId); fab.setOnClickListener(onClickListener); fab.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Toast.makeText(getAppCompatActivity(), v.getContentDescription(), Toast.LENGTH_SHORT).show(); return true; } }); }