Java Code Examples for android.support.v4.graphics.drawable.DrawableCompat#unwrap()
The following examples show how to use
android.support.v4.graphics.drawable.DrawableCompat#unwrap() .
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: TintUtil.java From android-material-stepper with Apache License 2.0 | 6 votes |
/** * Tints a drawable with the provided color state list * @param drawable drawable to tint * @param color tint color state list * @return tinted drawable */ public static Drawable tintDrawable(@Nullable Drawable drawable, ColorStateList color) { if (drawable != null) { drawable = DrawableCompat.unwrap(drawable); Rect bounds = drawable.getBounds(); drawable = DrawableCompat.wrap(drawable); // bounds can be all set to zeros when inflating vector drawables in Android Support Library 23.3.0... if (bounds.right == 0 || bounds.bottom == 0) { if (drawable.getIntrinsicHeight() != -1 && drawable.getIntrinsicWidth() != -1) { bounds.right = drawable.getIntrinsicWidth(); bounds.bottom = drawable.getIntrinsicHeight(); } else { Log.w(TAG, "Cannot tint drawable because its bounds cannot be determined!"); return DrawableCompat.unwrap(drawable); } } DrawableCompat.setTintList(drawable, color); drawable.setBounds(bounds); } return drawable; }
Example 2
Source File: Coloring.java From actual-number-picker with GNU General Public License v3.0 | 6 votes |
/** * Tries to clone and just color filter the drawable. Uses mode SRC_ATOP. * * @param drawable Which drawable to color * @param color Which color to use * @return A colored drawable ready for use */ @SuppressWarnings("RedundantCast") public Drawable colorUnknownDrawable(@Nullable Drawable drawable, int color) { if (drawable instanceof DrawableWrapper || drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) { drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(drawable, color); DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_ATOP); drawable = DrawableCompat.unwrap(drawable); return drawable; } else { try { // noinspection ConstantConditions Drawable copy = drawable.getConstantState().newDrawable(); copy.mutate(); copy.setColorFilter(color, SRC_ATOP); return copy; } catch (Exception e) { if (drawable != null) { Log.d(LOG_TAG, "Failed to color unknown drawable: " + drawable.getClass().getSimpleName()); } return drawable; } } }
Example 3
Source File: AlbumActivity.java From Camera-Roll-Android-App with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.album, menu); this.menu = menu; if (pick_photos) { menu.findItem(R.id.share).setVisible(false); menu.findItem(R.id.exclude).setVisible(false); menu.findItem(R.id.pin).setVisible(false); menu.findItem(R.id.rename).setVisible(false); menu.findItem(R.id.copy).setVisible(false); menu.findItem(R.id.move).setVisible(false); menu.findItem(R.id.delete).setVisible(false); } else if (album != null) { setupMenu(); } int sort_by = Settings.getInstance(this).sortAlbumBy(); if (sort_by == SortUtil.BY_DATE) { menu.findItem(R.id.sort_by_date).setChecked(true); } else if (sort_by == SortUtil.BY_NAME) { menu.findItem(R.id.sort_by_name).setChecked(true); } MenuItem selectAll = menu.findItem(R.id.select_all); Drawable d = selectAll.getIcon(); DrawableCompat.wrap(d); DrawableCompat.setTint(d, accentTextColor); DrawableCompat.unwrap(d); return super.onCreateOptionsMenu(menu); }
Example 4
Source File: ExifEditorActivity.java From Camera-Roll-Android-App with Apache License 2.0 | 5 votes |
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.exif_editor, menu); this.menu = menu; MenuItem save = menu.findItem(R.id.save); save.setVisible(editedItems.size() > 0); Drawable d = save.getIcon(); DrawableCompat.wrap(d); DrawableCompat.setTint(d, textColorSecondary); DrawableCompat.unwrap(d); save.setIcon(d); return super.onCreateOptionsMenu(menu); }
Example 5
Source File: FloatingSearchView.java From FloatingSearchView with Apache License 2.0 | 5 votes |
static private Drawable unwrap(Drawable icon) { if(icon instanceof android.support.v7.graphics.drawable.DrawableWrapper) return ((android.support.v7.graphics.drawable.DrawableWrapper)icon).getWrappedDrawable(); if(icon instanceof android.support.v4.graphics.drawable.DrawableWrapper) return ((android.support.v4.graphics.drawable.DrawableWrapper)icon).getWrappedDrawable(); if(Build.VERSION.SDK_INT >= 23 && icon instanceof android.graphics.drawable.DrawableWrapper) return ((android.graphics.drawable.DrawableWrapper)icon).getDrawable(); return DrawableCompat.unwrap(icon); }
Example 6
Source File: FloatingSearchView.java From FloatingSearchView with Apache License 2.0 | 5 votes |
static private Drawable unwrap(Drawable icon) { if(icon instanceof android.support.v7.graphics.drawable.DrawableWrapper) return ((android.support.v7.graphics.drawable.DrawableWrapper)icon).getWrappedDrawable(); if(icon instanceof android.support.v4.graphics.drawable.DrawableWrapper) return ((android.support.v4.graphics.drawable.DrawableWrapper)icon).getWrappedDrawable(); if(Build.VERSION.SDK_INT >= 23 && icon instanceof android.graphics.drawable.DrawableWrapper) return ((android.graphics.drawable.DrawableWrapper)icon).getDrawable(); return DrawableCompat.unwrap(icon); }
Example 7
Source File: Coloring.java From actual-number-picker with GNU General Public License v3.0 | 5 votes |
/** * Colors the given drawable to a specified color set using the drawable wrapping technique. * * @param drawable Which drawable to color * @param colorStates Which color set to use * @return A colored drawable ready to use */ public Drawable colorDrawableWrap(Drawable drawable, ColorStateList colorStates) { if (drawable != null) { drawable = DrawableCompat.wrap(drawable); DrawableCompat.setTintList(drawable, colorStates); DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_ATOP); drawable = DrawableCompat.unwrap(drawable); return drawable; } return null; }
Example 8
Source File: Coloring.java From actual-number-picker with GNU General Public License v3.0 | 5 votes |
/** * Colors the given drawable to a specified color using the drawable wrapping technique. * * @param drawable Which drawable to color * @param color Which color to use * @return A colored drawable ready to use */ public Drawable colorDrawableWrap(Drawable drawable, int color) { if (drawable != null) { Drawable wrapped = DrawableCompat.wrap(drawable); DrawableCompat.setTint(wrapped, color); DrawableCompat.setTintMode(wrapped, PorterDuff.Mode.SRC_ATOP); return DrawableCompat.unwrap(wrapped); } return null; }