List of usage examples for android.content.res Resources getDrawable
@Deprecated public Drawable getDrawable(@DrawableRes int id) throws NotFoundException
From source file:Main.java
private static Drawable getShortcutIcon(Context context, Intent shortcutIntent) { if (!shortcutIntent.hasExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE)) { return null; }/*from w w w.j av a 2 s . c o m*/ try { Intent.ShortcutIconResource iconRes = shortcutIntent .getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE); Resources appRes = context.getPackageManager().getResourcesForApplication(iconRes.packageName); int resId = appRes.getIdentifier(iconRes.resourceName, null, null); return appRes.getDrawable(resId); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:Main.java
private static void brandGlowDrawableColor(final Resources resources, final String drawable, final int color) { final int drawableRes = resources.getIdentifier(drawable, "drawable", "android"); try {/*from ww w .j ava2 s.co m*/ final Drawable d = resources.getDrawable(drawableRes); if (d != null) { d.setColorFilter(color, PorterDuff.Mode.SRC_IN); } } catch (final Resources.NotFoundException rnfe) { Log.e(LOG_TAG, "Failed to find drawable for resource " + drawable); } }
From source file:Main.java
public static Map<Integer, Bitmap> loadBitmaps(int arrayId, Resources resources) { Map<Integer, Bitmap> bitmapsMaps = new HashMap<>(); int[] bitmapIds = getIntArray(arrayId, resources); for (int i = 0; i < bitmapIds.length; i++) { Drawable backgroundDrawable = resources.getDrawable(bitmapIds[i]); Bitmap bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap(); bitmapsMaps.put(bitmapIds[i], bitmap); }/*from w w w . j ava 2 s. co m*/ return bitmapsMaps; }
From source file:Main.java
public static void applySampledResourceToImageView(Resources res, int resId, int reqWidth, int reqHeight, ImageView imageView) {/*from w ww.j a v a 2 s . c om*/ if (resId != 0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { imageView.setImageDrawable(res.getDrawable(resId)); } else { // workaround for old versions of android imageView.setImageBitmap(decodeSampledBitmapFromResource(res, resId, reqWidth, reqHeight)); } } }
From source file:com.dmitrymalkovich.android.githubanalytics.Utils.java
@SuppressWarnings("deprecation") public static Drawable getColor(Context context, String language) { Resources resources = context.getResources(); if (language == null) { return resources.getDrawable(R.drawable.shape_oval_java); }/*from w w w . ja va 2 s . c o m*/ switch (language) { case GithubLocalDataSource.TrendingLanguage.C: return resources.getDrawable(R.drawable.shape_oval_c); case GithubLocalDataSource.TrendingLanguage.RUBY: return resources.getDrawable(R.drawable.shape_oval_ruby); case GithubLocalDataSource.TrendingLanguage.JAVASCRIPT: return resources.getDrawable(R.drawable.shape_oval_javascript); case GithubLocalDataSource.TrendingLanguage.SWIFT: return resources.getDrawable(R.drawable.shape_oval_swift); case GithubLocalDataSource.TrendingLanguage.OBJECTIVE_C: return resources.getDrawable(R.drawable.shape_oval_objective_c); case GithubLocalDataSource.TrendingLanguage.C_PLUS_PLUS: return resources.getDrawable(R.drawable.shape_oval_c_plus); case GithubLocalDataSource.TrendingLanguage.PYTHON: return resources.getDrawable(R.drawable.shape_oval_python); case GithubLocalDataSource.TrendingLanguage.C_SHARP: return resources.getDrawable(R.drawable.shape_oval_c_sharp); case GithubLocalDataSource.TrendingLanguage.HTML: return resources.getDrawable(R.drawable.shape_oval_html); default: case GithubLocalDataSource.TrendingLanguage.JAVA: return resources.getDrawable(R.drawable.shape_oval_java); } }
From source file:com.google.android.apps.forscience.whistlepunk.metadata.TriggerHelper.java
public static void populateAutoTextViews(TextView autoTextView, String autoText, int drawableId, Resources res) { autoTextView.setText(autoText);// ww w .j a v a 2s .c o m autoTextView .setContentDescription(res.getString(R.string.trigger_label_icon_content_description, autoText)); Drawable drawable = res.getDrawable(drawableId); DrawableCompat.setTint(drawable.mutate(), res.getColor(R.color.text_color_light_grey)); autoTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null); }
From source file:com.achep.acdisplay.graphics.IconFactory.java
@NonNull private static Bitmap createEmptyIcon(@NonNull Resources res, int size) { Paint paint = new Paint(); paint.setAntiAlias(true);// w w w . j a v a2 s. c o m paint.setColor(0xDDCCCCCC); // white gray final float radius = size / 2f; Bitmap icon = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(icon); canvas.drawCircle(radius, radius, radius, paint); Drawable drawable = res.getDrawable(R.drawable.ic_action_warning_white); drawable.setBounds(0, 0, size, size); drawable.draw(canvas); return icon; }
From source file:de.vanita5.twittnuker.util.CustomTabUtils.java
public static Drawable getTabIconDrawable(final Resources res, final Object iconObj) { if (res == null) return null; if (iconObj instanceof Integer) { try {//from w ww .j a v a 2s . co m return res.getDrawable((Integer) iconObj); } catch (final Resources.NotFoundException e) { // Ignore. } } else if (iconObj instanceof Bitmap) return new BitmapDrawable(res, (Bitmap) iconObj); else if (iconObj instanceof Drawable) return (Drawable) iconObj; else if (iconObj instanceof File) { final Bitmap b = getTabIconFromFile((File) iconObj, res); if (b != null) return new BitmapDrawable(res, b); } return res.getDrawable(R.drawable.ic_iconic_action_list); }
From source file:com.battlelancer.seriesguide.util.Utils.java
/** * Sets the Drawables (if any) to appear to the start of, above, to the end of, and below the * text. Use 0 if you do not want a Drawable there. The Drawables' bounds will be set to their * intrinsic bounds./*ww w. ja v a 2 s . c om*/ */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static void setCompoundDrawablesRelativeWithIntrinsicBounds(Button button, int left, int top, int right, int bottom) { if (AndroidUtils.isJellyBeanMR1OrHigher()) { button.setCompoundDrawablesRelativeWithIntrinsicBounds(left, top, right, bottom); return; } final Resources resources = button.getContext().getResources(); setCompoundDrawablesRelativeWithIntrinsicBounds(button, left != 0 ? resources.getDrawable(left) : null, top != 0 ? resources.getDrawable(top) : null, right != 0 ? resources.getDrawable(right) : null, bottom != 0 ? resources.getDrawable(bottom) : null); }
From source file:com.docd.purefm.adapters.BrowserBaseAdapter.java
/** * Loads drawable from resources cache. If not found in cache, loads the * {@link android.graphics.drawable.Drawable} from {@link android.content.res.Resources} * * @param res Resources to load drawable from * @param resId Id of resource to load// www . j a v a 2s. co m * @return Drawable from resources */ @NonNull private static Drawable getDrawableForRes(final Resources res, final int resId) { Drawable drawable = sDrawableLruCache.get(resId); if (drawable == null) { drawable = res.getDrawable(resId); sDrawableLruCache.put(resId, drawable); } return drawable; }