List of usage examples for android.content Context getDrawable
@Nullable public final Drawable getDrawable(@DrawableRes int id)
From source file:Main.java
public static Drawable getDrawable(Context context, int color) { if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { //noinspection deprecation return context.getResources().getDrawable(color); } else {//from w w w .j av a 2 s . co m return context.getDrawable(color); } }
From source file:Main.java
public static Drawable getDrawableByName(String name, Context context) { try {//from w w w . j av a 2s . c om Field field = Class.forName("com.poetic.emotion.R$drawable").getField(name); int drawableRes = field.getInt(field); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return context.getDrawable(drawableRes); } else { return context.getResources().getDrawable(drawableRes); } } catch (Resources.NotFoundException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } return null; }
From source file:at.bitfire.davdroid.App.java
@Nullable @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static Bitmap getLauncherBitmap(@NonNull Context context) { Bitmap bitmapLogo = null;/*from ww w.j a v a2 s. com*/ Drawable drawableLogo = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP ? context.getDrawable(R.mipmap.ic_launcher) : context.getResources().getDrawable(R.mipmap.ic_launcher); if (drawableLogo instanceof BitmapDrawable) bitmapLogo = ((BitmapDrawable) drawableLogo).getBitmap(); return bitmapLogo; }
From source file:com.loserskater.suhidegui.utils.Utils.java
public static Drawable getAppIconByPackageName(Context context, String packageName) { Drawable icon;//from w w w .ja va 2 s . com try { icon = context.getPackageManager().getApplicationIcon(packageName); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); icon = context.getDrawable(R.mipmap.ic_launcher); } return icon; }
From source file:android.support.wear.widget.drawer.WearableDrawerView.java
private static Drawable getDrawable(Context context, TypedArray typedArray, @StyleableRes int index) { Drawable background;/* w w w. j a v a 2s. c o m*/ int backgroundResId = typedArray.getResourceId(index, 0); if (backgroundResId == 0) { background = typedArray.getDrawable(index); } else { background = context.getDrawable(backgroundResId); } return background; }
From source file:io.github.importre.animatedicons.AnimatedButton.java
@SuppressLint("NewApi") private void init(Context context) { if (isLollipop()) { offDrawable = context.getDrawable(getOffDrawable()); onDrawable = context.getDrawable(getOnDrawable()); } else {/* w ww. ja v a 2 s. co m*/ Resources r = context.getResources(); offDrawable = r.getDrawable(getOffDrawable()); onDrawable = r.getDrawable(getOnDrawable()); offDrawable = DrawableCompat.wrap(offDrawable); onDrawable = DrawableCompat.wrap(onDrawable); int color = r.getColor(R.color.ai_primary); DrawableCompat.setTint(offDrawable, color); DrawableCompat.setTint(onDrawable, color); } setScaleType(ScaleType.CENTER_INSIDE); if (isLollipop()) { setImageDrawable(!checked ? onDrawable : offDrawable); } else { setImageDrawable(checked ? onDrawable : offDrawable); } }
From source file:com.halzhang.android.library.BottomTabIndicator.java
private Drawable getDrawable(Context context, int resId) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return context.getResources().getDrawable(resId); } else {/* w ww . j a va 2s .com*/ return context.getDrawable(resId); } }
From source file:com.by_syk.lib.nanoiconpack.widget.DividerItemDecoration.java
/** * Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a * {@link LinearLayoutManager}./*from ww w. j ava 2 s . c om*/ * * @param context Current context, it will be used to access resources. * @param orientation Divider orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}. */ public DividerItemDecoration(Context context, int orientation) { // final TypedArray a = context.obtainStyledAttributes(ATTRS); // mDivider = a.getDrawable(0); // a.recycle(); // @By_syk mDivider = context.getDrawable(R.drawable.app_list_divider); setOrientation(orientation); }
From source file:com.by_syk.schttable.widget.DividerItemDecoration.java
/** * Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a * {@link LinearLayoutManager}./*from w w w .ja v a 2s .c o m*/ * * @param context Current context, it will be used to access resources. * @param orientation Divider orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}. */ public DividerItemDecoration(Context context, int orientation) { // final TypedArray a = context.obtainStyledAttributes(ATTRS); // mDivider = a.getDrawable(0); // a.recycle(); // @By_syk if (C.SDK >= 21) { mDivider = context.getDrawable(R.drawable.list_item_divider); } else { mDivider = context.getResources().getDrawable(R.drawable.list_item_divider); } setOrientation(orientation); }
From source file:com.stepstone.stepper.internal.widget.StepTab.java
/** * Inflates an animated vector drawable. On Lollipop+ this uses the native {@link android.graphics.drawable.AnimatedVectorDrawable} * and below it inflates the drawable as a {@link AnimatedVectorDrawableCompat}. * * @param animatedVectorDrawableResId resource ID for the animated vector * @return animated vector drawable// ww w . j a v a 2 s . c o m */ public Drawable createAnimatedVectorDrawable(@DrawableRes int animatedVectorDrawableResId) { Context context = getContext(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Drawable drawable = context.getDrawable(animatedVectorDrawableResId); return drawable.getConstantState().newDrawable(context.getResources()); } else { return AnimatedVectorDrawableCompat.create(context, animatedVectorDrawableResId); } }