Java Code Examples for android.widget.ImageButton#setContentDescription()
The following examples show how to use
android.widget.ImageButton#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: ButtonManager.java From Camera2 with Apache License 2.0 | 5 votes |
/** * Initialize a known button with a click listener and a drawable resource id, * and a content description resource id. * Sets the button visible. */ public void initializePushButton(int buttonId, View.OnClickListener cb, int imageId, int contentDescriptionId) { ImageButton button = getImageButtonOrError(buttonId); button.setOnClickListener(cb); if (imageId != NO_RESOURCE) { button.setImageResource(imageId); } if (contentDescriptionId != NO_RESOURCE) { button.setContentDescription(mAppController .getAndroidContext().getResources().getString(contentDescriptionId)); } if (!button.isEnabled()) { button.setEnabled(true); if (mListener != null) { mListener.onButtonEnabledChanged(this, buttonId); } } button.setTag(R.string.tag_enabled_id, buttonId); if (button.getVisibility() != View.VISIBLE) { button.setVisibility(View.VISIBLE); if (mListener != null) { mListener.onButtonVisibilityChanged(this, buttonId); } } }
Example 2
Source File: People.java From android-popup-info with Apache License 2.0 | 5 votes |
public static View inflatePersonView(Context context, ViewGroup parent, Person person) { LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ImageButton personView = (ImageButton)inflater.inflate(R.layout.button_person, parent, false); personView.setImageDrawable(context.getResources().getDrawable(person.getIcon())); personView.setContentDescription(person.getName()); personView.setOnClickListener(mClickPersonView); personView.setTag(person); return personView; }
Example 3
Source File: CommonPlaybackButtonsListener.java From android-vlc-remote with GNU General Public License v3.0 | 5 votes |
private void setupImageButtonListeners(ImageButton... imageButtons) { for(ImageButton b : imageButtons) { if(b != null) { Button info = Buttons.getButton(b.getId(), Preferences.get(b.getContext())); b.setImageResource(info.getIconId()); b.setContentDescription(b.getContext().getString(info.getContentDescriptionId())); b.setOnClickListener(this); b.setOnLongClickListener(this); } } }
Example 4
Source File: PlaybackControlLayer.java From google-media-framework-android with Apache License 2.0 | 5 votes |
/** * Creates a button to put in the set of action buttons at the right of the top chrome. * @param activity The activity that contains the video player. * @param icon The image of the action (ex. trash can). * @param contentDescription The text description this action. This is used in case the * action buttons do not fit in the video player. If so, an overflow * button will appear and, when clicked, it will display a list of the * content descriptions for each action. * @param onClickListener The handler for when the action is triggered. */ public void addActionButton(Activity activity, Drawable icon, String contentDescription, View.OnClickListener onClickListener) { ImageButton button = new ImageButton(activity); button.setContentDescription(contentDescription); button.setImageDrawable(icon); button.setOnClickListener(onClickListener); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ); int margin = activity.getResources().getDisplayMetrics().densityDpi * 5; layoutParams.setMargins(margin, 0, margin, 0); button.setBackgroundColor(Color.TRANSPARENT); button.setLayoutParams(layoutParams); isFullscreen = false; actionButtons.add(button); if (playbackControlRootView != null) { updateActionButtons(); updateColors(); } }
Example 5
Source File: InfoBarLayout.java From 365browser with Apache License 2.0 | 5 votes |
/** * Creates a close button that can be inserted into an infobar. * @param context Context to grab resources from. * @return {@link ImageButton} that represents a close button. */ static ImageButton createCloseButton(Context context) { TypedArray a = context.obtainStyledAttributes(new int[] {R.attr.selectableItemBackground}); Drawable closeButtonBackground = a.getDrawable(0); a.recycle(); ImageButton closeButton = new ImageButton(context); closeButton.setId(R.id.infobar_close_button); closeButton.setImageResource(R.drawable.btn_close); closeButton.setBackground(closeButtonBackground); closeButton.setContentDescription(context.getString(R.string.infobar_close)); closeButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE); return closeButton; }
Example 6
Source File: CustomButtonParams.java From 365browser with Apache License 2.0 | 5 votes |
/** * Builds an {@link ImageButton} from the data in this params. Generated buttons should be * placed on the bottom bar. The button's tag will be its id. * @param parent The parent that the inflated {@link ImageButton}. * @param listener {@link OnClickListener} that should be used with the button. * @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid. */ ImageButton buildBottomBarButton(Context context, ViewGroup parent, OnClickListener listener) { if (mIsOnToolbar) return null; ImageButton button = (ImageButton) LayoutInflater.from(context) .inflate(R.layout.custom_tabs_bottombar_item, parent, false); button.setId(mId); button.setImageBitmap(mIcon); button.setContentDescription(mDescription); if (mPendingIntent == null) { button.setEnabled(false); } else { button.setOnClickListener(listener); } button.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View view) { final int screenWidth = view.getResources().getDisplayMetrics().widthPixels; final int screenHeight = view.getResources().getDisplayMetrics().heightPixels; final int[] screenPos = new int[2]; view.getLocationOnScreen(screenPos); final int width = view.getWidth(); Toast toast = Toast.makeText( view.getContext(), view.getContentDescription(), Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM | Gravity.END, screenWidth - screenPos[0] - width / 2, screenHeight - screenPos[1]); toast.show(); return true; } }); return button; }
Example 7
Source File: CustomButtonParams.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Builds an {@link ImageButton} from the data in this params. Generated buttons should be * placed on the bottom bar. The button's tag will be its id. * @param parent The parent that the inflated {@link ImageButton}. * @param listener {@link OnClickListener} that should be used with the button. * @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid. */ ImageButton buildBottomBarButton(Context context, ViewGroup parent, OnClickListener listener) { if (mIsOnToolbar) return null; ImageButton button = (ImageButton) LayoutInflater.from(context) .inflate(R.layout.custom_tabs_bottombar_item, parent, false); button.setId(mId); button.setImageBitmap(mIcon); button.setContentDescription(mDescription); if (mPendingIntent == null) { button.setEnabled(false); } else { button.setOnClickListener(listener); } button.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View view) { final int screenWidth = view.getResources().getDisplayMetrics().widthPixels; final int screenHeight = view.getResources().getDisplayMetrics().heightPixels; final int[] screenPos = new int[2]; view.getLocationOnScreen(screenPos); final int width = view.getWidth(); Toast toast = Toast.makeText( view.getContext(), view.getContentDescription(), Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM | Gravity.END, screenWidth - screenPos[0] - width / 2, screenHeight - screenPos[1]); toast.show(); return true; } }); return button; }
Example 8
Source File: CustomButtonParams.java From delion with Apache License 2.0 | 5 votes |
/** * Builds an {@link ImageButton} from the data in this params. Generated buttons should be * placed on the bottom bar. The button's tag will be its id. * @param parent The parent that the inflated {@link ImageButton}. * @param listener {@link OnClickListener} that should be used with the button. * @return Parsed list of {@link CustomButtonParams}, which is empty if the input is invalid. */ ImageButton buildBottomBarButton(Context context, ViewGroup parent, OnClickListener listener) { if (mIsOnToolbar) return null; ImageButton button = (ImageButton) LayoutInflater.from(context) .inflate(R.layout.custom_tabs_bottombar_item, parent, false); button.setId(mId); button.setImageBitmap(mIcon); button.setContentDescription(mDescription); if (mPendingIntent == null) { button.setEnabled(false); } else { button.setOnClickListener(listener); } button.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View view) { final int screenWidth = view.getResources().getDisplayMetrics().widthPixels; final int screenHeight = view.getResources().getDisplayMetrics().heightPixels; final int[] screenPos = new int[2]; view.getLocationOnScreen(screenPos); final int width = view.getWidth(); Toast toast = Toast.makeText( view.getContext(), view.getContentDescription(), Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM | Gravity.END, screenWidth - screenPos[0] - width / 2, screenHeight - screenPos[1]); toast.show(); return true; } }); return button; }
Example 9
Source File: RunReviewFragment.java From science-journal with Apache License 2.0 | 5 votes |
public static void updateContentDescription( ImageButton button, int stringId, String sensorId, Context context, AppAccount appAccount, Trial trial) { String content = ProtoSensorAppearance.getAppearanceFromProtoOrProvider( trial.getAppearances().get(sensorId), sensorId, AppSingleton.getInstance(context).getSensorAppearanceProvider(appAccount)) .getName(context); button.setContentDescription(content); }
Example 10
Source File: EmojiView.java From Emoji with Apache License 2.0 | 5 votes |
private ImageButton inflateButton(final Context context, @DrawableRes final int icon, @StringRes final int categoryName, final ViewGroup parent) { final ImageButton button = (ImageButton) LayoutInflater.from(context).inflate(R.layout.emoji_view_category, parent, false); button.setImageDrawable(AppCompatResources.getDrawable(context, icon)); button.setColorFilter(themeIconColor, PorterDuff.Mode.SRC_IN); button.setContentDescription(context.getString(categoryName)); parent.addView(button); return button; }
Example 11
Source File: AnalogComplicationConfigRecyclerViewAdapter.java From wear-os-samples with Apache License 2.0 | 5 votes |
private void updateComplicationView(ComplicationProviderInfo complicationProviderInfo, ImageButton button, ImageView background) { if (complicationProviderInfo != null) { button.setImageIcon(complicationProviderInfo.providerIcon); button.setContentDescription( mContext.getString(R.string.edit_complication, complicationProviderInfo.appName + " " + complicationProviderInfo.providerName)); background.setVisibility(View.VISIBLE); } else { button.setImageDrawable(mDefaultComplicationDrawable); button.setContentDescription(mContext.getString(R.string.add_complication)); background.setVisibility(View.INVISIBLE); } }
Example 12
Source File: InfoBarLayout.java From delion with Apache License 2.0 | 4 votes |
/** * Constructs a layout for the specified infobar. After calling this, be sure to set the * message, the buttons, and/or the custom content using setMessage(), setButtons(), and * setCustomContent(). * * @param context The context used to render. * @param infoBarView InfoBarView that listens to events. * @param iconResourceId ID of the icon to use for the infobar. * @param iconBitmap Bitmap for the icon to use, if the resource ID wasn't passed through. * @param message The message to show in the infobar. */ public InfoBarLayout(Context context, InfoBarView infoBarView, int iconResourceId, Bitmap iconBitmap, CharSequence message) { super(context); mControlLayouts = new ArrayList<InfoBarControlLayout>(); mInfoBarView = infoBarView; // Cache resource values. Resources res = getResources(); mSmallIconSize = res.getDimensionPixelSize(R.dimen.infobar_small_icon_size); mSmallIconMargin = res.getDimensionPixelSize(R.dimen.infobar_small_icon_margin); mBigIconSize = res.getDimensionPixelSize(R.dimen.infobar_big_icon_size); mBigIconMargin = res.getDimensionPixelSize(R.dimen.infobar_big_icon_margin); mMarginAboveButtonGroup = res.getDimensionPixelSize(R.dimen.infobar_margin_above_button_row); mMarginAboveControlGroups = res.getDimensionPixelSize(R.dimen.infobar_margin_above_control_groups); mPadding = res.getDimensionPixelOffset(R.dimen.infobar_padding); mMinWidth = res.getDimensionPixelSize(R.dimen.infobar_min_width); mAccentColor = ApiCompatibilityUtils.getColor(res, R.color.infobar_accent_blue); // Set up the close button. Apply padding so it has a big touch target. mCloseButton = new ImageButton(context); mCloseButton.setId(R.id.infobar_close_button); mCloseButton.setImageResource(R.drawable.btn_close); TypedArray a = getContext().obtainStyledAttributes( new int [] {R.attr.selectableItemBackground}); Drawable closeButtonBackground = a.getDrawable(0); a.recycle(); mCloseButton.setBackground(closeButtonBackground); mCloseButton.setPadding(mPadding, mPadding, mPadding, mPadding); mCloseButton.setOnClickListener(this); mCloseButton.setContentDescription(res.getString(R.string.infobar_close)); mCloseButton.setLayoutParams(new LayoutParams(0, -mPadding, -mPadding, -mPadding)); // Set up the icon. if (iconResourceId != 0 || iconBitmap != null) { mIconView = new ImageView(context); if (iconResourceId != 0) { mIconView.setImageResource(iconResourceId); } else if (iconBitmap != null) { mIconView.setImageBitmap(iconBitmap); } mIconView.setLayoutParams(new LayoutParams(0, 0, mSmallIconMargin, 0)); mIconView.getLayoutParams().width = mSmallIconSize; mIconView.getLayoutParams().height = mSmallIconSize; mIconView.setFocusable(false); } // Set up the message view. mMessageMainText = message; mMessageLayout = new InfoBarControlLayout(context); mMessageTextView = mMessageLayout.addMainMessage(prepareMainMessageString()); }
Example 13
Source File: CustomTabBottomBarDelegate.java From delion with Apache License 2.0 | 4 votes |
/** * Updates the custom buttons on bottom bar area. * @param params The {@link CustomButtonParams} that describes the button to update. */ public void updateBottomBarButtons(CustomButtonParams params) { ImageButton button = (ImageButton) getBottomBarView().findViewById(params.getId()); button.setContentDescription(params.getDescription()); button.setImageDrawable(params.getIcon(mActivity.getResources())); }
Example 14
Source File: CustomTabBottomBarDelegate.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Updates the custom buttons on bottom bar area. * @param params The {@link CustomButtonParams} that describes the button to update. */ public void updateBottomBarButtons(CustomButtonParams params) { ImageButton button = (ImageButton) getBottomBarView().findViewById(params.getId()); button.setContentDescription(params.getDescription()); button.setImageDrawable(params.getIcon(mActivity.getResources())); }
Example 15
Source File: InfoBarLayout.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Constructs a layout for the specified infobar. After calling this, be sure to set the * message, the buttons, and/or the custom content using setMessage(), setButtons(), and * setCustomContent(). * * @param context The context used to render. * @param infoBarView InfoBarView that listens to events. * @param iconResourceId ID of the icon to use for the infobar. * @param iconBitmap Bitmap for the icon to use, if the resource ID wasn't passed through. * @param message The message to show in the infobar. */ public InfoBarLayout(Context context, InfoBarView infoBarView, int iconResourceId, Bitmap iconBitmap, CharSequence message) { super(context); mControlLayouts = new ArrayList<InfoBarControlLayout>(); mInfoBarView = infoBarView; // Cache resource values. Resources res = getResources(); mSmallIconSize = res.getDimensionPixelSize(R.dimen.infobar_small_icon_size); mSmallIconMargin = res.getDimensionPixelSize(R.dimen.infobar_small_icon_margin); mBigIconSize = res.getDimensionPixelSize(R.dimen.infobar_big_icon_size); mBigIconMargin = res.getDimensionPixelSize(R.dimen.infobar_big_icon_margin); mMarginAboveButtonGroup = res.getDimensionPixelSize(R.dimen.infobar_margin_above_button_row); mMarginAboveControlGroups = res.getDimensionPixelSize(R.dimen.infobar_margin_above_control_groups); mPadding = res.getDimensionPixelOffset(R.dimen.infobar_padding); mMinWidth = res.getDimensionPixelSize(R.dimen.infobar_min_width); mAccentColor = ApiCompatibilityUtils.getColor(res, R.color.infobar_accent_blue); // Set up the close button. Apply padding so it has a big touch target. mCloseButton = new ImageButton(context); mCloseButton.setId(R.id.infobar_close_button); mCloseButton.setImageResource(R.drawable.btn_close); TypedArray a = getContext().obtainStyledAttributes( new int [] {R.attr.selectableItemBackground}); Drawable closeButtonBackground = a.getDrawable(0); a.recycle(); mCloseButton.setBackground(closeButtonBackground); mCloseButton.setPadding(mPadding, mPadding, mPadding, mPadding); mCloseButton.setOnClickListener(this); mCloseButton.setContentDescription(res.getString(R.string.infobar_close)); mCloseButton.setLayoutParams(new LayoutParams(0, -mPadding, -mPadding, -mPadding)); // Set up the icon. if (iconResourceId != 0 || iconBitmap != null) { mIconView = new ImageView(context); if (iconResourceId != 0) { mIconView.setImageResource(iconResourceId); } else if (iconBitmap != null) { mIconView.setImageBitmap(iconBitmap); } mIconView.setLayoutParams(new LayoutParams(0, 0, mSmallIconMargin, 0)); mIconView.getLayoutParams().width = mSmallIconSize; mIconView.getLayoutParams().height = mSmallIconSize; mIconView.setFocusable(false); } // Set up the message view. mMessageMainText = message; mMessageLayout = new InfoBarControlLayout(context); mMessageTextView = mMessageLayout.addMainMessage(prepareMainMessageString()); }
Example 16
Source File: CustomTabBottomBarDelegate.java From 365browser with Apache License 2.0 | 4 votes |
/** * Updates the custom buttons on bottom bar area. * @param params The {@link CustomButtonParams} that describes the button to update. */ public void updateBottomBarButtons(CustomButtonParams params) { ImageButton button = (ImageButton) getBottomBarView().findViewById(params.getId()); button.setContentDescription(params.getDescription()); button.setImageDrawable(params.getIcon(mActivity.getResources())); }
Example 17
Source File: PlaybackController.java From AntennaPodSP with MIT License | 4 votes |
private void updatePlayButtonAppearance(int resource, CharSequence contentDescription) { ImageButton butPlay = getPlayButton(); butPlay.setImageResource(resource); butPlay.setContentDescription(contentDescription); }
Example 18
Source File: ButtonManager.java From Camera2 with Apache License 2.0 | 4 votes |
/** * Initialize a panorama orientation buttons. */ public void initializePanoOrientationButtons(final ButtonCallback cb) { int resIdImages = PhotoSphereHelper.getPanoramaOrientationOptionArrayId(); int resIdDescriptions = PhotoSphereHelper.getPanoramaOrientationDescriptions(); if (resIdImages > 0) { TypedArray imageIds = null; TypedArray descriptionIds = null; try { mModeOptions.setMainBar(ModeOptions.BAR_PANO); imageIds = mAppController .getAndroidContext().getResources().obtainTypedArray(resIdImages); descriptionIds = mAppController .getAndroidContext().getResources().obtainTypedArray(resIdDescriptions); mModeOptionsPano.removeAllViews(); final boolean isHorizontal = (mModeOptionsPano.getOrientation() == LinearLayout.HORIZONTAL); final int numImageIds = imageIds.length(); for (int index = 0; index < numImageIds; index++) { int i; // if in portrait orientation (pano bar horizonal), order buttons normally // if in landscape orientation (pano bar vertical), reverse button order if (isHorizontal) { i = index; } else { i = numImageIds - index - 1; } int imageId = imageIds.getResourceId(i, 0); if (imageId > 0) { ImageButton imageButton = (ImageButton) LayoutInflater .from(mAppController.getAndroidContext()) .inflate(R.layout.mode_options_imagebutton_template, mModeOptionsPano, false); imageButton.setImageResource(imageId); imageButton.setTag(String.valueOf(i)); mModeOptionsPano.addView(imageButton); int descriptionId = descriptionIds.getResourceId(i, 0); if (descriptionId > 0) { imageButton.setContentDescription( mAppController.getAndroidContext().getString(descriptionId)); } } } mModeOptionsPano.updateListeners(); mModeOptionsPano .setOnOptionClickListener(new RadioOptions.OnOptionClickListener() { @Override public void onOptionClicked(View v) { if (cb != null) { int state = Integer.parseInt((String) v.getTag()); mSettingsManager.setValueByIndex(SettingsManager.SCOPE_GLOBAL, Keys.KEY_CAMERA_PANO_ORIENTATION, state); cb.onStateChanged(state); } } }); updatePanoButtons(); } finally { if (imageIds != null) { imageIds.recycle(); } if (descriptionIds != null) { descriptionIds.recycle(); } } } }