public static Drawable getMaskDrawable(Context context, int maskId) { Drawable drawable; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { drawable = context.getDrawable(maskId); } else { drawable = context.getResources().getDrawable(maskId); } if (drawable == null) { throw new IllegalArgumentException("maskId is invalid"); } return drawable; } }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public static Drawable getDrawable(Context context, @DrawableRes int drawableRes) { if (Build.VERSION.SDK_INT < 21) { //noinspection deprecation return context.getResources().getDrawable(drawableRes); } else { return context.getDrawable(drawableRes); } }
@SuppressWarnings("deprecation") private static Drawable getDrawable(Context context, @DrawableRes int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return context.getDrawable(id); } else { return context.getResources().getDrawable(id); } }
/** * Set the background drawable for the spinner's popup window of choices. * * @param resId Resource ID of a background drawable * * @attr ref android.R.styleable#Spinner_popupBackground */ public void setPopupBackgroundResource(int resId) { setPopupBackgroundDrawable(getContext().getDrawable(resId)); }
private void addTabIcon(EmojiconPage page, int index) { ImageButton icon = new ImageButton(getContext()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT); params.weight = 1; icon.setBackground(null); icon.setScaleType(ImageView.ScaleType.CENTER); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { icon.setImageDrawable(getContext().getResources().getDrawable(page.getIcon())); } else { icon.setImageDrawable(getContext().getDrawable(page.getIcon())); } mTabsContainer.addView(icon, mTabsContainer.getChildCount() - 2, params); mTabs[index] = icon; final int indexToMove = index; icon.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mViewPager.setCurrentItem(indexToMove, true); } }); }
mLeftSelectionHandle = (BitmapDrawable) getContext().getDrawable(R.drawable.text_select_handle_left_material); mRightSelectionHandle = (BitmapDrawable) getContext().getDrawable(R.drawable.text_select_handle_right_material);
public static Drawable getMaskDrawable(Context context, int maskId) { Drawable drawable; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { drawable = context.getDrawable(maskId); } else { drawable = context.getResources().getDrawable(maskId); } if (drawable == null) { throw new IllegalArgumentException("maskId is invalid"); } return drawable; } }
void updateState() { iconView.setImageAlpha(255 * 87 / 100); if (stateChoices == 2) { switch (item.state) { case Configuration.Item.STATE_IGNORE: case Configuration.Item.STATE_DENY: iconView.setImageDrawable(context.getDrawable(R.drawable.ic_check_box_outline_blank_black_24dp)); iconView.setContentDescription(context.getString(R.string.do_not_use_dns_server)); break; case Configuration.Item.STATE_ALLOW: iconView.setImageDrawable(context.getDrawable(R.drawable.ic_check_box_black_24dp)); iconView.setContentDescription(context.getString(R.string.use_dns_server)); break; } } else { switch (item.state) { case Configuration.Item.STATE_IGNORE: iconView.setImageDrawable(context.getDrawable(R.drawable.ic_state_ignore)); iconView.setImageAlpha(255 * 38 / 100); break; case Configuration.Item.STATE_DENY: iconView.setImageDrawable(context.getDrawable(R.drawable.ic_state_deny)); break; case Configuration.Item.STATE_ALLOW: iconView.setImageDrawable(context.getDrawable(R.drawable.ic_state_allow)); break; } iconView.setContentDescription(context.getResources().getStringArray(R.array.item_states)[item.state]); } }
@Override public void onClick(View v) { if (extra.getVisibility() == View.GONE) { if (preferences.getBoolean("extraBarClosed:" + name, false)) { SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("extraBarClosed:" + name, false); editor.apply(); } view.announceForAccessibility(view.getContext().getString(R.string.expand_bar_expanded)); expand.setImageDrawable(view.getContext().getDrawable(R.drawable.ic_expand_less_black_24dp)); expand.setContentDescription(view.getContext().getString(R.string.expand_bar_toggle_close)); extra.setVisibility(View.VISIBLE); } else { if (!preferences.getBoolean("extraBarClosed:" + name, false)) { SharedPreferences.Editor editor = preferences.edit(); editor.putBoolean("extraBarClosed:" + name, true); editor.apply(); } view.announceForAccessibility(view.getContext().getString(R.string.expand_bar_closed)); expand.setImageDrawable(view.getContext().getDrawable(R.drawable.ic_expand_more_black_24dp)); expand.setContentDescription(view.getContext().getString(R.string.expand_bar_toggle_expand)); extra.setVisibility(View.GONE); } } };
case AdVpnService.VPN_STATUS_STARTING: case AdVpnService.VPN_STATUS_STOPPING: stateImage.setImageDrawable(context.getDrawable(R.drawable.ic_settings_black_24dp)); startButton.setText(R.string.action_stop); break; case AdVpnService.VPN_STATUS_STOPPED: stateImage.setImageDrawable(context.getDrawable(R.mipmap.app_icon_large)); stateImage.setImageAlpha(32); stateImage.setImageTintList(null); break; case AdVpnService.VPN_STATUS_RUNNING: stateImage.setImageDrawable(context.getDrawable(R.drawable.ic_verified_user_black_24dp)); startButton.setText(R.string.action_stop); break; case AdVpnService.VPN_STATUS_RECONNECTING_NETWORK_ERROR: stateImage.setImageDrawable(context.getDrawable(R.drawable.ic_error_black_24dp)); startButton.setText(R.string.action_stop); break;
public TintedDrawableSpan(Context context, int resourceId) { super(ALIGN_BOTTOM); mDrawable = context.getDrawable(resourceId); mOldTint = 0; }
@Override public Drawable getDrawable(Context context, int id) { return context.getDrawable(id); } }
@NonNull private Drawable getDrawable(int resId) { final Drawable drawable; if (IS_L) { drawable = context.getDrawable(resId); } else { drawable = resources.getDrawable(resId); } //noinspection ConstantConditions return drawable; } }
@Override public FloatingMenuItem setIcon(int icon) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mIcon = mContext.getDrawable(icon); else mIcon = mContext.getResources().getDrawable(icon); return this; }
static Drawable getDrawable(@NonNull Context context, @DrawableRes int id) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) return context.getDrawable(id); else return context.getResources().getDrawable(id); } }
public void setDefaultComplicationDrawable(int resourceId) { Context context = mWatchFaceArmsAndTicksView.getContext(); mDefaultComplicationDrawable = context.getDrawable(resourceId); mLeftComplication.setImageDrawable(mDefaultComplicationDrawable); mLeftComplicationBackground.setVisibility(View.INVISIBLE); mRightComplication.setImageDrawable(mDefaultComplicationDrawable); mRightComplicationBackground.setVisibility(View.INVISIBLE); }
@SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) static Marker createMarker(Context c, int resourceIdentifier, LatLong latLong) { Drawable drawable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? c.getDrawable(resourceIdentifier) : c.getResources().getDrawable(resourceIdentifier); Bitmap bitmap = AndroidGraphicFactory.convertToBitmap(drawable); return new Marker(latLong, bitmap, 0, -bitmap.getHeight() / 2); }
public void setIcon(int resourceId) { Context context = mBackgroundComplicationButton.getContext(); mBackgroundComplicationButton.setCompoundDrawablesWithIntrinsicBounds( context.getDrawable(resourceId), null, null, null); }
private void updateIcon(Context context, Boolean currentState) { int currentIconResourceId; if (currentState) { currentIconResourceId = mEnabledIconResourceId; } else { currentIconResourceId = mDisabledIconResourceId; } mUnreadNotificationSwitch.setChecked(currentState); mUnreadNotificationSwitch.setCompoundDrawablesWithIntrinsicBounds( context.getDrawable(currentIconResourceId), null, null, null); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @SuppressWarnings("deprecation") public void setChildBackgroundDrawable(int whichChild, @DrawableRes int drawableResId) { try { setChildBackgroundDrawable(whichChild, hasLollipop() ? getContext().getDrawable(drawableResId) : getContext().getResources().getDrawable(drawableResId)); } catch (Resources.NotFoundException e) { Log.e(TAG, "Resource with id " + drawableResId + " could not be found. Drawable cannot be set!"); } }