本文整理汇总了Java中android.support.v4.graphics.drawable.DrawableCompat.unwrap方法的典型用法代码示例。如果您正苦于以下问题:Java DrawableCompat.unwrap方法的具体用法?Java DrawableCompat.unwrap怎么用?Java DrawableCompat.unwrap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.graphics.drawable.DrawableCompat
的用法示例。
在下文中一共展示了DrawableCompat.unwrap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unwrap
import android.support.v4.graphics.drawable.DrawableCompat; //导入方法依赖的package包/类
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);
}
示例2: colorDrawableWrapped
import android.support.v4.graphics.drawable.DrawableCompat; //导入方法依赖的package包/类
/**
* Colors the given drawable to the specified color set using the drawable wrapping technique ({@link DrawableCompat#wrap(Drawable)}).
* This method also uses {@link PorterDuff.Mode#SRC_ATOP} to color the pixels.
*
* @param drawable Which drawable to color
* @param colorStates Which color set to use
* @return A colored drawable, cached instance in most cases
*/
@NonNull
public static Drawable colorDrawableWrapped(@NonNull final Drawable drawable, @NonNull final ColorStateList colorStates) {
Drawable wrapped = DrawableCompat.wrap(drawable);
DrawableCompat.setTintList(wrapped, colorStates);
DrawableCompat.setTintMode(wrapped, PorterDuff.Mode.SRC_ATOP);
wrapped = DrawableCompat.unwrap(wrapped);
return wrapped;
}
示例3: onCreateOptionsMenu
import android.support.v4.graphics.drawable.DrawableCompat; //导入方法依赖的package包/类
@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);
} 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);
}
示例4: onCreateOptionsMenu
import android.support.v4.graphics.drawable.DrawableCompat; //导入方法依赖的package包/类
@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);
}
示例5: getOpticalBounds
import android.support.v4.graphics.drawable.DrawableCompat; //导入方法依赖的package包/类
/**
* Allows us to get the optical insets for a {@link Drawable}. Since this is hidden we need to
* use reflection. Since the {@code Insets} class is hidden also, we return a Rect instead.
*/
public static Rect getOpticalBounds(Drawable drawable) {
if (sInsetsClazz != null) {
try {
// If the Drawable is wrapped, we need to manually unwrap it and process
// the wrapped drawable.
drawable = DrawableCompat.unwrap(drawable);
final Method getOpticalInsetsMethod = drawable.getClass()
.getMethod("getOpticalInsets");
final Object insets = getOpticalInsetsMethod.invoke(drawable);
if (insets != null) {
// If the drawable has some optical insets, let's copy them into a Rect
final Rect result = new Rect();
for (Field field : sInsetsClazz.getFields()) {
switch (field.getName()) {
case "left":
result.left = field.getInt(insets);
break;
case "top":
result.top = field.getInt(insets);
break;
case "right":
result.right = field.getInt(insets);
break;
case "bottom":
result.bottom = field.getInt(insets);
break;
}
}
return result;
}
} catch (Exception e) {
// Eugh, we hit some kind of reflection issue...
Log.e(TAG, "Couldn't obtain the optical insets. Ignoring.");
}
}
// If we reach here, either we're running on a device pre-v18, the Drawable didn't have
// any optical insets, or a reflection issue, so we'll just return an empty rect
return INSETS_NONE;
}
示例6: getOpticalBounds
import android.support.v4.graphics.drawable.DrawableCompat; //导入方法依赖的package包/类
public static Rect getOpticalBounds(Drawable drawable) {
if (sInsetsClazz != null) {
try {
drawable = DrawableCompat.unwrap(drawable);
Object insets = drawable.getClass().getMethod("getOpticalInsets", new Class[0]).invoke(drawable, new Object[0]);
if (insets != null) {
Rect result = new Rect();
for (Field field : sInsetsClazz.getFields()) {
String name = field.getName();
Object obj = -1;
switch (name.hashCode()) {
case -1383228885:
if (name.equals("bottom")) {
obj = 3;
break;
}
break;
case 115029:
if (name.equals("top")) {
obj = 1;
break;
}
break;
case 3317767:
if (name.equals(PeriodRecord.LEFT)) {
obj = null;
break;
}
break;
case 108511772:
if (name.equals(PeriodRecord.RIGHT)) {
obj = 2;
break;
}
break;
}
switch (obj) {
case null:
result.left = field.getInt(insets);
break;
case 1:
result.top = field.getInt(insets);
break;
case 2:
result.right = field.getInt(insets);
break;
case 3:
result.bottom = field.getInt(insets);
break;
default:
break;
}
}
return result;
}
} catch (Exception e) {
Log.e(TAG, "Couldn't obtain the optical insets. Ignoring.");
}
}
return INSETS_NONE;
}