Java Code Examples for android.view.View#setContentDescription()
The following examples show how to use
android.view.View#setContentDescription() .
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: ColorPickerPalette.java From Augendiagnose with GNU General Public License v2.0 | 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 to right/top to bottom order, which is how the system will arrange them for accessibility purposes. * * @param rowNumber The row number. * @param index The index of the view. * @param rowElements The number of elements in the row. * @param selected Flag indicating if the swatch is selected. * @param swatch The swatch to be affected. */ private void setSwatchDescription(final int rowNumber, final int index, final int rowElements, final boolean selected, @NonNull final View swatch) { int accessibilityIndex; if (rowNumber % 2 == 0) { // We're in a regular-ordered row accessibilityIndex = index; } else { // We're in a backwards-ordered row. int rowMax = (rowNumber + 1) * mNumColumns; accessibilityIndex = rowMax - rowElements; } String description; if (selected) { description = String.format(mDescriptionSelected, accessibilityIndex); } else { description = String.format(mDescription, accessibilityIndex); } swatch.setContentDescription(description); }
Example 2
Source File: ColorPickerPalette.java From Tweetin with Apache License 2.0 | 6 votes |
private void setSwatchDescription(int rowNumber, int index, int rowElements, boolean selected, View swatch) { int accessibilityIndex; if (rowNumber % 2 == 0) { // We're in a regular-ordered row accessibilityIndex = index; } else { // We're in a backwards-ordered row. int rowMax = ((rowNumber + 1) * mNumColumns); accessibilityIndex = rowMax - rowElements; } String description; if (selected) { description = String.format(mDescriptionSelected, accessibilityIndex); } else { description = String.format(mDescription, accessibilityIndex); } swatch.setContentDescription(description); }
Example 3
Source File: HistoryManagerToolbar.java From 365browser with Apache License 2.0 | 6 votes |
@Override public void onSelectionStateChange(List<HistoryItem> selectedItems) { boolean wasSelectionEnabled = mIsSelectionEnabled; super.onSelectionStateChange(selectedItems); if (mIsSelectionEnabled) { int numSelected = mSelectionDelegate.getSelectedItems().size(); // If the delete menu item is shown in the overflow menu instead of as an action, there // may not be a view associated with it. View deleteButton = findViewById(R.id.selection_mode_delete_menu_id); if (deleteButton != null) { deleteButton.setContentDescription(getResources().getQuantityString( R.plurals.accessibility_remove_selected_items, numSelected, numSelected)); } // The copy link option should only be visible when one item is selected. getItemById(R.id.selection_mode_copy_link).setVisible(numSelected == 1); if (!wasSelectionEnabled) { mManager.recordUserActionWithOptionalSearch("SelectionEstablished"); } } }
Example 4
Source File: ColorPickerPalette.java From privacy-friendly-ludo with GNU General Public License v3.0 | 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 5
Source File: CallLogDetailsFragment.java From CSipSimple with GNU General Public License v3.0 | 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 6
Source File: UIUtils.java From ZhihuDaily with Apache License 2.0 | 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 7
Source File: WXPageActivity.java From incubator-weex-playground with Apache License 2.0 | 5 votes |
@Override public void run() { View container = findViewById(R.id.container); collectId(mInstance.getRootComponent(),mIDMap); container.setContentDescription(JSON.toJSONString(mIDMap)); mWXHandler.removeCallbacks(this); mWXHandler.postDelayed(this,2000); }
Example 8
Source File: ColorPickerPalette.java From ColorPicker with Apache License 2.0 | 5 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 (mBackwardsOrder) { 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; } } else { accessibilityIndex = index + 1; } if (selected) { description = String.format(mDescriptionSelected, accessibilityIndex); } else { description = String.format(mDescription, accessibilityIndex); } } swatch.setContentDescription(description); }
Example 9
Source File: TabLayout.java From tns-core-modules-widgets with Apache License 2.0 | 5 votes |
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; TabItemSpec tabItem; if (this.mTabItems != null && this.mTabItems.length > i) { tabItem = this.mTabItems[i]; } else { tabItem = new TabItemSpec(); tabItem.title = adapter.getPageTitle(i).toString(); } tabView = createDefaultTabView(getContext(), tabItem); tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }
Example 10
Source File: WaypointListAdapter.java From msdkui-android with Apache License 2.0 | 5 votes |
/** * 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 11
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void hasContentDescriptionTest() { View view = new View(context); view.setContentDescription(null); assertFalse(hasContentDescription().matches(view)); CharSequence testText = "test text!"; view.setContentDescription(testText); assertTrue(hasContentDescription().matches(view)); }
Example 12
Source File: ViewMatchersTest.java From android-test with Apache License 2.0 | 5 votes |
@Test public void withContentDescriptionFromResourceId() { View view = new View(context); view.setContentDescription(context.getString(R.string.something)); assertFalse(withContentDescription(R.string.other_string).matches(view)); assertTrue(withContentDescription(R.string.something).matches(view)); }
Example 13
Source File: SuggestionView.java From 365browser with Apache License 2.0 | 4 votes |
/** * Constructs a new omnibox suggestion view. * * @param context The context used to construct the suggestion view. * @param locationBar The location bar showing these suggestions. */ public SuggestionView(Context context, LocationBar locationBar) { super(context); mLocationBar = locationBar; mSuggestionHeight = context.getResources().getDimensionPixelOffset(R.dimen.omnibox_suggestion_height); mSuggestionAnswerHeight = context.getResources().getDimensionPixelOffset( R.dimen.omnibox_suggestion_answer_height); TypedArray a = getContext().obtainStyledAttributes( new int [] {R.attr.selectableItemBackground}); Drawable itemBackground = a.getDrawable(0); a.recycle(); mContentsView = new SuggestionContentsContainer(context, itemBackground); addView(mContentsView); mRefineView = new View(context) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mRefineIcon == null) return; canvas.save(); canvas.translate( (getMeasuredWidth() - mRefineIcon.getIntrinsicWidth()) / 2f, (getMeasuredHeight() - mRefineIcon.getIntrinsicHeight()) / 2f); mRefineIcon.draw(canvas); canvas.restore(); } @Override public void setVisibility(int visibility) { super.setVisibility(visibility); if (visibility == VISIBLE) { setClickable(true); setFocusable(true); } else { setClickable(false); setFocusable(false); } } @Override protected void drawableStateChanged() { super.drawableStateChanged(); if (mRefineIcon != null && mRefineIcon.isStateful()) { mRefineIcon.setState(getDrawableState()); } } }; mRefineView.setContentDescription(getContext().getString( R.string.accessibility_omnibox_btn_refine)); // Although this has the same background as the suggestion view, it can not be shared as // it will result in the state of the drawable being shared and always showing up in the // refine view. mRefineView.setBackground(itemBackground.getConstantState().newDrawable()); mRefineView.setId(R.id.refine_view_id); mRefineView.setClickable(true); mRefineView.setFocusable(true); mRefineView.setLayoutParams(new LayoutParams(0, 0)); addView(mRefineView); mRefineWidth = getResources() .getDimensionPixelSize(R.dimen.omnibox_suggestion_refine_width); mUrlBar = (UrlBar) locationBar.getContainerView().findViewById(R.id.url_bar); mPhoneUrlBarLeftOffsetPx = getResources().getDimensionPixelOffset( R.dimen.omnibox_suggestion_phone_url_bar_left_offset); mPhoneUrlBarLeftOffsetRtlPx = getResources().getDimensionPixelOffset( R.dimen.omnibox_suggestion_phone_url_bar_left_offset_rtl); }
Example 14
Source File: SlidingTabLayout.java From AndroidStarterKit with MIT License | 4 votes |
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; View tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } if (TextView.class.isInstance(tabTitleView)) { ((TextView) tabTitleView).setText(adapter.getPageTitle(i)); } else if (ImageView.class.isInstance(tabTitleView) && adapter instanceof TabIconProvider){ TabIconProvider mTabIconProvider = (TabIconProvider) adapter; tabTitleView.setBackgroundResource(mTabIconProvider.getPageIconResId(i)); } tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }
Example 15
Source File: DatePicker.java From ticdesign with Apache License 2.0 | 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 16
Source File: VideoItem.java From Camera2 with Apache License 2.0 | 4 votes |
@Override public View getView(Optional<View> optionalView, LocalFilmstripDataAdapter adapter, boolean isInProgress, final VideoClickedCallback videoClickedCallback) { View view; VideoViewHolder viewHolder; if (optionalView.isPresent()) { view = optionalView.get(); viewHolder = getViewHolder(view); } else { view = LayoutInflater.from(mContext).inflate(R.layout.filmstrip_video, null); view.setTag(R.id.mediadata_tag_viewtype, getItemViewType().ordinal()); ImageView videoView = (ImageView) view.findViewById(R.id.video_view); ImageView playButton = (ImageView) view.findViewById(R.id.play_button); viewHolder = new VideoViewHolder(videoView, playButton); view.setTag(R.id.mediadata_tag_target, viewHolder); } if (viewHolder != null) { // ImageView for the play icon. viewHolder.mPlayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { videoClickedCallback.playVideo(mData.getUri(), mData.getTitle()); } }); view.setContentDescription(mContext.getResources().getString( R.string.video_date_content_description, mDateFormatter.format(mData.getLastModifiedDate()))); renderTiny(viewHolder); } else { Log.w(TAG, "getView called with a view that is not compatible with VideoItem."); } return view; }
Example 17
Source File: TimePickerSpinnerDelegate.java From android_9.0.0_r45 with Apache License 2.0 | 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 18
Source File: TutorialLessonFragment.java From talkback with Apache License 2.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { int layoutId; if (exercise == null || tutorialController == null || callback == null) { return null; } if (exercise.needScrollableContainer()) { layoutId = R.layout.tutorial_lesson_fragment_scrollable; } else { layoutId = R.layout.tutorial_lesson_fragment; } View view = inflater.inflate(layoutId, container, false); description = (TextView) view.findViewById(R.id.description); description.setText(page.getDescription()); TextView subTitle = (TextView) view.findViewById(R.id.part_subtitle); subTitle.setText(page.getSubtitle()); TextView currentPage = (TextView) view.findViewById(R.id.current_page); TextView next = (TextView) view.findViewById(R.id.next); if (this.currentPage < lesson.getPagesCount() - 1) { next.setText(R.string.tutorial_next); currentPage.setVisibility(View.VISIBLE); currentPage.setText( getString( R.string.tutorial_page_number_of, this.currentPage + 1, lesson.getPagesCount() - 1)); } else if (tutorialController.getNextLesson(lesson) == null) { next.setText(R.string.tutorial_home); } else { next.setText(R.string.tutorial_next_lesson); } next.setOnClickListener(this); View previous = view.findViewById(R.id.previous_page); previous.setOnClickListener(this); previous.setContentDescription(getString(R.string.tutorial_previous)); ViewGroup contentContainer = (ViewGroup) view.findViewById(R.id.practice_area); View contentView = page.getExercise().getContentView(inflater, contentContainer); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); contentContainer.addView(contentView, params); return view; }
Example 19
Source File: SuggestionView.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Constructs a new omnibox suggestion view. * * @param context The context used to construct the suggestion view. * @param locationBar The location bar showing these suggestions. */ public SuggestionView(Context context, LocationBar locationBar) { super(context); mLocationBar = locationBar; mSuggestionHeight = context.getResources().getDimensionPixelOffset(R.dimen.omnibox_suggestion_height); mSuggestionAnswerHeight = context.getResources().getDimensionPixelOffset( R.dimen.omnibox_suggestion_answer_height); TypedArray a = getContext().obtainStyledAttributes( new int [] {R.attr.selectableItemBackground}); Drawable itemBackground = a.getDrawable(0); a.recycle(); mContentsView = new SuggestionContentsContainer(context, itemBackground); addView(mContentsView); mRefineView = new View(context) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (mRefineIcon == null) return; canvas.save(); canvas.translate( (getMeasuredWidth() - mRefineIcon.getIntrinsicWidth()) / 2f, (getMeasuredHeight() - mRefineIcon.getIntrinsicHeight()) / 2f); mRefineIcon.draw(canvas); canvas.restore(); } @Override public void setVisibility(int visibility) { super.setVisibility(visibility); if (visibility == VISIBLE) { setClickable(true); setFocusable(true); } else { setClickable(false); setFocusable(false); } } @Override protected void drawableStateChanged() { super.drawableStateChanged(); if (mRefineIcon != null && mRefineIcon.isStateful()) { mRefineIcon.setState(getDrawableState()); } } }; mRefineView.setContentDescription(getContext().getString( R.string.accessibility_omnibox_btn_refine)); // Although this has the same background as the suggestion view, it can not be shared as // it will result in the state of the drawable being shared and always showing up in the // refine view. mRefineView.setBackground(itemBackground.getConstantState().newDrawable()); mRefineView.setId(R.id.refine_view_id); mRefineView.setClickable(true); mRefineView.setFocusable(true); mRefineView.setLayoutParams(new LayoutParams(0, 0)); addView(mRefineView); mRefineWidth = getResources() .getDimensionPixelSize(R.dimen.omnibox_suggestion_refine_width); mUrlBar = (UrlBar) locationBar.getContainerView().findViewById(R.id.url_bar); mPhoneUrlBarLeftOffsetPx = getResources().getDimensionPixelOffset( R.dimen.omnibox_suggestion_phone_url_bar_left_offset); mPhoneUrlBarLeftOffsetRtlPx = getResources().getDimensionPixelOffset( R.dimen.omnibox_suggestion_phone_url_bar_left_offset_rtl); }
Example 20
Source File: SlidingTabLayout.java From arcusandroid with Apache License 2.0 | 4 votes |
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; Version1TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (Version1TextView) tabView.findViewById(mTabViewTextViewId); } if (tabView == null) { tabView = createDefaultTabView(getContext()); } if (tabTitleView == null && Version1TextView.class.isInstance(tabView)) { tabTitleView = (Version1TextView) tabView; } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabTitleView.setText(adapter.getPageTitle(i)); tabTitleView.setTextSize(12); tabTitleView.setTypeface(FontUtils.getDemi(getContext())); tabTitleView.setTextColor(getResources().getColorStateList(R.color.sliding_tab_text_color_selector)); tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }