當前位置: 首頁>>代碼示例>>Java>>正文


Java DrawableCompat.unwrap方法代碼示例

本文整理匯總了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);
}
 
開發者ID:zuoweitan,項目名稱:Hitalk,代碼行數:10,代碼來源:FloatingSearchView.java

示例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;
}
 
開發者ID:milosmns,項目名稱:silly-android,代碼行數:17,代碼來源:Coloring.java

示例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);
}
 
開發者ID:kollerlukas,項目名稱:Camera-Roll-Android-App,代碼行數:32,代碼來源:AlbumActivity.java

示例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);
}
 
開發者ID:kollerlukas,項目名稱:Camera-Roll-Android-App,代碼行數:15,代碼來源:ExifEditorActivity.java

示例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;
}
 
開發者ID:commonsguy,項目名稱:cwac-crossport,代碼行數:48,代碼來源:DrawableUtils.java

示例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;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:62,代碼來源:DrawableUtils.java


注:本文中的android.support.v4.graphics.drawable.DrawableCompat.unwrap方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。