Java Code Examples for android.view.View.setContentDescription()

The following are Jave code examples for showing how to use setContentDescription() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: CSipSimple   File: CallLogDetailsFragment.java   Source Code and License Vote up 6 votes
/** Configures the call button area using the given entry. */
private void configureCallButton(String callText, CharSequence nbrLabel, CharSequence number) {
    View convertView = getView().findViewById(R.id.call_and_sms);
    convertView.setVisibility(TextUtils.isEmpty(number) ? View.GONE : View.VISIBLE);

    TextView text = (TextView) convertView.findViewById(R.id.call_and_sms_text);

    View mainAction = convertView.findViewById(R.id.call_and_sms_main_action);
    mainAction.setOnClickListener(mPrimaryActionListener);
    mainAction.setContentDescription(callText);
    if(TextUtils.isEmpty(number)) {
        number = "";
    }
    mainAction.setTag(SipUri.getCanonicalSipContact(number.toString(), false));
    text.setText(callText);

    TextView label = (TextView) convertView.findViewById(R.id.call_and_sms_label);
    if (TextUtils.isEmpty(nbrLabel)) {
        label.setVisibility(View.GONE);
    } else {
        label.setText(nbrLabel);
        label.setVisibility(View.VISIBLE);
    }
}
 
Example 2
Project: MyNotes   File: ColorPickerPalette.java   Source Code and License Vote up 6 votes
/**
 * Add a content description to the specified swatch view. Because the colors get added in a
 * snaking form, every other row will need to compensate for the fact that the colors are added
 * in an opposite direction from their left->right/top->bottom order, which is how the system
 * will arrange them for accessibility purposes.
 */
private void setSwatchDescription(int rowNumber, int index, int rowElements, boolean selected,
        View swatch, String[] contentDescriptions) {
    String description;
    if (contentDescriptions != null && contentDescriptions.length > index) {
        description = contentDescriptions[index];
    } else {
        int accessibilityIndex;
        if (rowNumber % 2 == 0) {
            // We're in a regular-ordered row
            accessibilityIndex = index + 1;
        } else {
            // We're in a backwards-ordered row.
            int rowMax = ((rowNumber + 1) * mNumColumns);
            accessibilityIndex = rowMax - rowElements;
        }

        if (selected) {
            description = String.format(mDescriptionSelected, accessibilityIndex);
        } else {
            description = String.format(mDescription, accessibilityIndex);
        }
    }
    swatch.setContentDescription(description);
}
 
Example 3
Project: iosched-reader   File: UIUtils.java   Source Code and License Vote up 6 votes
public static void setAccessibilityIgnore(View view) {
    view.setClickable(false);
    view.setFocusable(false);
    view.setContentDescription("");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    }
}
 
Example 4
Project: RxJanDan   File: UIUtil.java   Source Code and License Vote up 5 votes
public static void setAccessiblityIgnore(View view) {
	view.setClickable(false);
	view.setFocusable(false);
	view.setContentDescription("");
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
		view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
	}
}
 
Example 5
Project: chromium-for-android-56-debug-video   File: ExpandablePreferenceGroup.java   Source Code and License Vote up 5 votes
@Override
protected void onBindView(View view) {
    super.onBindView(view);
    mImageView = (ImageView) view.findViewById(R.id.expando);
    if (mDrawable != null) mImageView.setImageDrawable(mDrawable);

    // For accessibility, read out the whole title and whether the group is collapsed/expanded.
    String description = getTitle() + getContext().getResources().getString(mExpanded
            ? R.string.accessibility_expanded_group
            : R.string.accessibility_collapsed_group);
    view.setContentDescription(description);
}
 
Example 6
Project: chromium-for-android-56-debug-video   File: PreferenceCategoryWithButton.java   Source Code and License Vote up 5 votes
@Override
protected void onBindView(final View view) {
    super.onBindView(view);
    // On pre-L devices, PreferenceCategoryWithButtonStyle is reused for PreferenceCategory,
    // which needs a top padding of 16dp; we don't want this top padding for
    // PreferenceCategoryWithButton views.
    view.setPadding(view.getPaddingLeft(), 0, view.getPaddingRight(), view.getPaddingBottom());
    View button = view.findViewById(android.R.id.icon);
    button.setOnClickListener(this);

    if (!TextUtils.isEmpty(mContentDescription)) {
        button.setContentDescription(mContentDescription);
    }
}
 
Example 7
Project: dagger-android-sample   File: FirstFragment.java   Source Code and License Vote up 5 votes
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
                         @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View view = new View(getContext());
    view.setContentDescription("First Fragment");
    return view;
}
 
Example 8
Project: dagger-android-sample   File: SecondFragment.java   Source Code and License Vote up 5 votes
@Nullable
@Override
public View onCreateView(LayoutInflater inflater,
                         @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {
    View view = new View(getContext());
    view.setContentDescription("Second Fragment");
    return view;
}
 
Example 9
Project: android-WearAccessibilityApp   File: LongListRecyclerViewAdapter.java   Source Code and License Vote up 4 votes
@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
    final View view;
    switch (viewType) {
        case SampleAppConstants.TITLE:
            // Programmatically set the text of the title here.
            view = mInflater.inflate(R.layout.title_layout, parent, false);
            TextView titleView = view.findViewById(R.id.title_text);
            titleView.setText(R.string.a_long_list);
            break;
        case SampleAppConstants.SWITCH:
            // Reference the switch widget's text and view.
            view = mInflater.inflate(R.layout.long_list_switch_widget_layout, parent, false);
            TextView switchText = view.findViewById(R.id.switch_text);
            switchText.setText(R.string.bottom_action_drawer);

            mSwitchWidget = view.findViewById(R.id.switch_widget);

            view.setContentDescription(
                    mContext.getResources()
                            .getString(
                                    R.string.switch_bottom_action_drawer,
                                    getSwitchToggleString(mSwitchWidget.isChecked())));

            // Set the OnClickListener (Observer pattern used here).
            view.setOnClickListener(
                    new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mSwitchWidget.setChecked(!(mSwitchWidget.isChecked()));
                            if (mSwitchChangeListener != null) {
                                mSwitchChangeListener.onChange(mSwitchWidget.isChecked());
                            }
                            view.setContentDescription(
                                    mContext.getResources()
                                            .getString(
                                                    R.string.switch_bottom_action_drawer,
                                                    getSwitchToggleString(
                                                            mSwitchWidget.isChecked())));
                        }
                    });
            break;
        case SampleAppConstants.HEADER_FOOTER:
            view = mInflater.inflate(R.layout.header_footer_layout, parent, false);
            break;
        case SampleAppConstants.PROGRESS_BAR:
            view = mInflater.inflate(R.layout.progress_bar_layout, parent, false);
            break;
        case SampleAppConstants.NORMAL:
            view = mInflater.inflate(R.layout.shifted_app_item_layout, parent, false);
            break;
        default:
            view = mInflater.inflate(R.layout.shifted_app_item_layout, parent, false);
            break;
    }
    return new Holder(view);
}
 
Example 10
Project: Witch-Android   File: TestOnBind.java   Source Code and License Vote up 4 votes
@Override
public void onBind(View view, Object o) {
    view.setContentDescription(TestOnBind.class.getSimpleName());
}
 
Example 11
Project: Boookito-Capstone-Project   File: AddToModalBottomSheet.java   Source Code and License Vote up 4 votes
private void setButtonContentDescription(View v, int stringResouce) {
  v.setContentDescription(
      getResources().getString(R.string.accessibility_search_activity_add_to, // Format string
          getResources().getString(stringResouce))
  );
}
 
Example 12
Project: ucar-weex-core   File: WXComponent.java   Source Code and License Vote up 4 votes
protected void setAriaLabel(String label) {
  View host = getHostView();
  if(host != null){
    host.setContentDescription(label);
  }
}
 
Example 13
Project: iosched-reader   File: ExploreIOFragment.java   Source Code and License Vote up 4 votes
@Override
public void bindCollectionItemView(Context context, View view, int groupId,
        int indexInGroup, int dataIndex, Object tag) {
    if (GROUP_ID_KEYNOTE_STREAM_CARD == groupId ||
            GROUP_ID_MESSAGE_CARDS == groupId) {
        // These two group id types don't have child views.
        populateSubItemInfo(context, view, groupId, tag);
        // Set the object's data into the view's tag so that the click listener on the view can
        // extract it and use the data to handle a click.
        View clickableView = view.findViewById(R.id.explore_io_clickable_item);
        if (clickableView != null) {
            clickableView.setTag(tag);
        }
    } else {
        // These group ids have children who are child items.
        ViewGroup viewWithChildrenSubItems = (ViewGroup)(view.findViewById(
                R.id.explore_io_card_container_contents));
        ItemGroup itemGroup = (ItemGroup) tag;

        // Set Header tag and title.
        viewWithChildrenSubItems.getChildAt(0).setTag(tag);
        TextView titleTextView = ((TextView) view.findViewById(android.R.id.title));
        View headerView = view.findViewById(R.id.explore_io_card_header_layout);
        if (headerView != null) {
            headerView.setContentDescription(
                    getString(R.string.more_items_button_desc_with_label_a11y,
                            itemGroup.getTitle()));
        }

        // Set the tag on the moreButton so it can be accessed by the click listener.
        View moreButton = view.findViewById(android.R.id.button1);
        if (moreButton != null) {
            moreButton.setTag(tag);
        }
        if (titleTextView != null) {
            titleTextView.setText(itemGroup.getTitle());
        }

        // Skipping first child b/c it is a header view.
        for (int viewChildIndex = 1; viewChildIndex < viewWithChildrenSubItems.getChildCount(); viewChildIndex++) {
            View childView = viewWithChildrenSubItems.getChildAt(viewChildIndex);

            int sessionIndex = viewChildIndex - 1;
            int sessionSize = itemGroup.getSessions().size();
            if (childView != null && sessionIndex < sessionSize) {
                childView.setVisibility(View.VISIBLE);
                SessionData sessionData = itemGroup.getSessions().get(sessionIndex);
                childView.setTag(sessionData);
                populateSubItemInfo(context, childView, groupId, sessionData);
            } else if (childView != null) {
                childView.setVisibility(View.GONE);
            }
        }
    }

}
 
Example 14
Project: DateTimePicker   File: DatePickerSpinnerDelegate.java   Source Code and License Vote up 4 votes
private void trySetContentDescription(View root, int viewId, int contDescResId) {
    View target = root.findViewById(viewId);
    if (target != null) {
        target.setContentDescription(mContext.getString(contDescResId));
    }
}
 
Example 15
Project: DateTimePicker   File: TimePickerSpinnerDelegate.java   Source Code and License Vote up 4 votes
private void trySetContentDescription(View root, int viewId, int contDescResId) {
    View target = root.findViewById(viewId);
    if (target != null) {
        target.setContentDescription(mContext.getString(contDescResId));
    }
}