Java Code Examples for android.view.View#getContentDescription()

The following examples show how to use android.view.View#getContentDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From onpc with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Procedure hows toast that contains description of the given button
 */
@SuppressLint("RtlHardcoded")
public static boolean showButtonDescription(Context context, View button)
{
    CharSequence contentDesc = button.getContentDescription();
    if (contentDesc != null && contentDesc.length() > 0)
    {
        int[] pos = new int[2];
        button.getLocationOnScreen(pos);

        Toast t = Toast.makeText(context, contentDesc, Toast.LENGTH_SHORT);
        t.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
        t.getView().measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        final int x = pos[0] + button.getMeasuredWidth() / 2 - (t.getView().getMeasuredWidth() / 2);
        final int y = pos[1] - button.getMeasuredHeight() / 2 - t.getView().getMeasuredHeight()
                - context.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin_port);
        t.setGravity(Gravity.TOP | Gravity.LEFT, x, y);
        t.show();
        return true;
    }
    return false;
}
 
Example 2
Source File: BaseFragment.java    From onpc with GNU General Public License v3.0 6 votes vote down vote up
void prepareButtonListeners(@NonNull View b, final ISCPMessage msg, final ButtonListener listener)
{
    b.setClickable(true);
    b.setOnClickListener(v ->
    {
        if (activity.isConnected() && msg != null)
        {
            activity.getStateManager().sendMessage(msg);
        }
        if (listener != null)
        {
            listener.onPostProcessing();
        }
    });

    if (b.getContentDescription() != null && b.getContentDescription().length() > 0)
    {
        b.setLongClickable(true);
        b.setOnLongClickListener(v -> Utils.showButtonDescription(activity, v));
    }
}
 
Example 3
Source File: ActivityELMe.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
private void showHeadView() {
    headerLayout.setTranslationY(0);
    View underView = mRightMenu.findChildViewUnder(headerView.getX(), 0);
    if (underView != null && underView.getContentDescription() != null) {
        int position = Integer.parseInt(underView.getContentDescription().toString());
        ModelDishMenu menu = rightAdapter.getMenuOfMenuByPosition(position + 1);
        headMenu = menu;
        headerView.setText(headMenu.getMenuName());
        for (int i = 0; i < mModelDishMenuList.size(); i++) {
            if (mModelDishMenuList.get(i) == headMenu) {
                leftAdapter.setSelectedNum(i);
                break;
            }
        }
    }
}
 
Example 4
Source File: ViewUtils.java    From microMathematics with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Procedure hows toast that contains description of the given button
 */
@SuppressLint("RtlHardcoded")
public static boolean showButtonDescription(Context context, View button)
{
    CharSequence contentDesc = button.getContentDescription();
    if (contentDesc != null && contentDesc.length() > 0)
    {
        int[] pos = new int[2];
        button.getLocationOnScreen(pos);

        Toast t = Toast.makeText(context, contentDesc, Toast.LENGTH_SHORT);
        t.setGravity(Gravity.TOP | Gravity.LEFT, 0, 0);
        t.getView().measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
                MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
        final int x = pos[0] + button.getMeasuredWidth() / 2 - (t.getView().getMeasuredWidth() / 2);
        final int y = pos[1] - button.getMeasuredHeight() / 2 - t.getView().getMeasuredHeight()
                - context.getResources().getDimensionPixelSize(R.dimen.activity_vertical_margin);
        t.setGravity(Gravity.TOP | Gravity.LEFT, x, y);
        t.show();
        return true;
    }
    return false;
}
 
Example 5
Source File: ViewMatchers.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Override
public boolean matchesSafely(View view) {
  if (null == this.expectedText) {
    try {
      expectedText = view.getResources().getString(resourceId);
      resourceName = view.getResources().getResourceEntryName(resourceId);
    } catch (Resources.NotFoundException ignored) {
      // view could be from a context unaware of the resource id.
    }
  }
  if (null != expectedText && null != view.getContentDescription()) {
    return expectedText.equals(view.getContentDescription().toString());
  } else {
    return false;
  }
}
 
Example 6
Source File: WaypointListAdapter.java    From msdkui-android with Apache License 2.0 5 votes vote down vote up
/**
 * Swap the content descriptions.
 */
void swapContentDescriptions(WaypointsListViewHolder endViewHolder) {
    final View startDragView = getDraggableView();
    final View endDragView = endViewHolder.getDraggableView();
    final View startRemoveView = getRemovableView();
    final View endRemoveView = endViewHolder.getRemovableView();
    final CharSequence startDragViewContentDescription = startDragView.getContentDescription();
    final CharSequence startRemoveViewContentDescription = startRemoveView.getContentDescription();
    // start swapping
    startDragView.setContentDescription(endDragView.getContentDescription());
    startRemoveView.setContentDescription(endRemoveView.getContentDescription());
    endDragView.setContentDescription(startDragViewContentDescription);
    endRemoveView.setContentDescription(startRemoveViewContentDescription);
}
 
Example 7
Source File: ViewExtractors.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public String apply(@Nullable View input) {
  if (input == null) {
    return "Provided view was null";
  }
  if (input.getContentDescription() == null) {
    return String.format(
        "No content description found, view is %s",
        getVisibilityString(input.getVisibility()));
  }
  return String.format(
      "Found content description: \"%s\", view is %s",
      input.getContentDescription(), getVisibilityString(input.getVisibility()));
}
 
Example 8
Source File: ViewUtil.java    From sa-sdk-android with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 view  text
 */
public static String getViewContent(View view) {
    String value = "";
    View selected = null;
    if (view instanceof RatingBar) {
        value = String.valueOf(((RatingBar) view).getRating());
    } else if (view instanceof Spinner) {
        Object item = ((Spinner) view).getSelectedItem();
        if (item instanceof String) {
            value = (String) item;
        } else {
            selected = ((Spinner) view).getSelectedView();
            if ((selected instanceof TextView) && ((TextView) selected).getText() != null) {
                value = ((TextView) selected).getText().toString();
            }
        }
    } else if (view instanceof SeekBar) {
        value = String.valueOf(((SeekBar) view).getProgress());
    } else if (view instanceof RadioGroup) {
        RadioGroup group = (RadioGroup) view;
        selected = group.findViewById(group.getCheckedRadioButtonId());
        if ((selected instanceof RadioButton) && ((RadioButton) selected).getText() != null) {
            value = ((RadioButton) selected).getText().toString();
        }
    } else if (view instanceof TextView) {
        if (((TextView) view).getText() != null) {
            value = ((TextView) view).getText().toString();
        }
    }

    if (TextUtils.isEmpty(value)) {
        if (view.getContentDescription() != null) {
            value = view.getContentDescription().toString();
        }
    }
    return value;
}
 
Example 9
Source File: MainActivity.java    From UI-Motion with Apache License 2.0 5 votes vote down vote up
public void pictureClick(View view) {
    // Create an object containing information about our scene transition animation
    ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,
            view, getString(R.string.picture_transition_name));
    PictureView pictureView = (PictureView) view;
    int picture = pictureView.getImageResource();
    CharSequence title = view.getContentDescription();
    // Pass information to Detail Activity in order to show the chosen image and its details
    Intent intent = new Intent(this, DetailActivity.class);
    intent.putExtra(DetailActivity.EXTRA_PICTURE, picture);
    intent.putExtra(DetailActivity.EXTRA_TITLE, title);
    startActivity(intent, options.toBundle());
}
 
Example 10
Source File: XposedUniversalCopyHandler.java    From timecat with Apache License 2.0 4 votes vote down vote up
private ArrayList<CopyNode> traverseNode(View nodeInfo, int screenWidth, int scerrnHeight) {
    ArrayList nodeList = new ArrayList();
    if(nodeInfo != null ) {
        if (!nodeInfo.isShown()){
            return nodeList;
        }
        if (nodeInfo instanceof ViewGroup){
            ViewGroup viewGroup = (ViewGroup) nodeInfo;
            for(int var4 = 0; var4 < viewGroup.getChildCount(); ++var4) {
                nodeList.addAll(this.traverseNode(viewGroup.getChildAt(var4), screenWidth, scerrnHeight));
            }
        }
        if(nodeInfo.getClass().getName() != null && nodeInfo.getClass().getName().equals("android.webkit.WebView")) {
            return nodeList;
        } else {
            String content = null;
            String description = content;
            if(nodeInfo.getContentDescription() != null) {
                description = content;
                if(!"".equals(nodeInfo.getContentDescription())) {
                    description = nodeInfo.getContentDescription().toString();
                }
            }

            content = description;
            String text=getTextInFilters(nodeInfo,mFilters);
            if(text != null) {
                content = description;
                if(!"".equals(text)) {
                    content = text.toString();
                }
            }

            if(content != null) {
                Rect var8 = new Rect();
                nodeInfo.getGlobalVisibleRect(var8);
                if(checkBound(var8, screenWidth, scerrnHeight)) {
                    nodeList.add(new CopyNode(var8, content));
                }
            }

            return nodeList;
        }
    } else {
        return nodeList;
    }
}
 
Example 11
Source File: Clicker.java    From robotium-extensions with Apache License 2.0 4 votes vote down vote up
<T extends View> void click(
        Class<T> clazz, View view, Integer index, String text, boolean longClick, Integer time) {
    final View toClick = (view != null) ? view : (index != null) ? extSolo.getView(clazz, index) : null;

    StringBuilder sb = new StringBuilder();
    sb.append("Click ").append(longClick ? "long on " : "on ");

    String[] parts = clazz.getName().split("\\.");

    sb.append(parts[parts.length - 1]);

    if (text != null) {
        sb.append(" with text: ").append(text);
    } else if (index != null) {
        sb.append(" with index: ").append(index);
    } else if (view != null) {
        if (view.getId() != View.NO_ID) {
            try {
                sb.append(" with id: ").append(view.getContext().getResources().getResourceEntryName(view.getId()));
            } catch (NotFoundException e) {
                sb.append(" with id: ").append(view.getId());
            }
        } else if (view.getContentDescription() != null) {
            sb.append(" with description: ").append(view.getContentDescription());
        }
    }
    extSolo.getOtherUtils().addAction(sb.toString(), Type.click);

    if (toClick != null && toClick instanceof EditText && view != null && view.hasFocusable() && !view.hasFocus()) {
        extSolo.getInstrumentation().runOnMainSync(new Runnable() {
            public void run() {
                toClick.requestFocus();
            }
        });
    }
    if (text == null) {
        extSolo.soloClick(toClick, longClick, time);
    } else {
        extSolo.clickOnTextBySolo(clazz, text);
    }
    extSolo.getOtherUtils().addDurationToAction();
}
 
Example 12
Source File: ViewMatchers.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matchesSafely(View view) {
  String descriptionText =
      (view.getContentDescription() != null) ? view.getContentDescription().toString() : null;
  return textMatcher.matches(descriptionText);
}
 
Example 13
Source File: ViewMatchers.java    From android-test with Apache License 2.0 4 votes vote down vote up
@Override
public boolean matchesSafely(View view) {
  return view.getContentDescription() != null;
}
 
Example 14
Source File: HumanReadables.java    From android-test with Apache License 2.0 4 votes vote down vote up
/**
 * Transforms an arbitrary view into a string with (hopefully) enough debug info.
 *
 * @param v nullable view
 * @return a string for human consumption.
 */
public static String describe(View v) {
  if (null == v) {
    return "null";
  }
  ToStringHelper helper = MoreObjects.toStringHelper(v).add("id", v.getId());
  if (v.getId() != -1 && v.getResources() != null && !isViewIdGenerated(v.getId())) {
    try {
      helper.add("res-name", v.getResources().getResourceEntryName(v.getId()));
    } catch (Resources.NotFoundException ignore) {
      // Do nothing.
    }
  }
  if (null != v.getContentDescription()) {
    helper.add("desc", v.getContentDescription());
  }

  switch (v.getVisibility()) {
    case View.GONE:
      helper.add("visibility", "GONE");
      break;
    case View.INVISIBLE:
      helper.add("visibility", "INVISIBLE");
      break;
    case View.VISIBLE:
      helper.add("visibility", "VISIBLE");
      break;
    default:
      helper.add("visibility", v.getVisibility());
  }

  helper
      .add("width", v.getWidth())
      .add("height", v.getHeight())
      .add("has-focus", v.hasFocus())
      .add("has-focusable", v.hasFocusable())
      .add("has-window-focus", v.hasWindowFocus())
      .add("is-clickable", v.isClickable())
      .add("is-enabled", v.isEnabled())
      .add("is-focused", v.isFocused())
      .add("is-focusable", v.isFocusable())
      .add("is-layout-requested", v.isLayoutRequested())
      .add("is-selected", v.isSelected())
      .add("layout-params", v.getLayoutParams())
      .add("tag", v.getTag());

  if (null != v.getRootView()) {
    // pretty much only true in unit-tests.
    helper.add("root-is-layout-requested", v.getRootView().isLayoutRequested());
  }

  EditorInfo ei = new EditorInfo();
  InputConnection ic = v.onCreateInputConnection(ei);
  boolean hasInputConnection = ic != null;
  helper.add("has-input-connection", hasInputConnection);
  if (hasInputConnection) {
    StringBuilder sb = new StringBuilder();
    sb.append("[");
    Printer p = new StringBuilderPrinter(sb);
    ei.dump(p, "");
    sb.append("]");
    helper.add("editor-info", sb.toString().replace("\n", " "));
  }

  if (Build.VERSION.SDK_INT > 10) {
    helper.add("x", v.getX()).add("y", v.getY());
  }

  if (v instanceof TextView) {
    innerDescribe((TextView) v, helper);
  }
  if (v instanceof Checkable) {
    innerDescribe((Checkable) v, helper);
  }
  if (v instanceof ViewGroup) {
    innerDescribe((ViewGroup) v, helper);
  }
  return helper.toString();
}