Example usage for android.graphics.drawable Drawable getLevel

List of usage examples for android.graphics.drawable Drawable getLevel

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable getLevel.

Prototype

public final @IntRange(from = 0, to = 10000) int getLevel() 

Source Link

Document

Retrieve the current level.

Usage

From source file:Main.java

/**
 * Copies various properties from one drawable to the other.
 * @param to drawable to copy properties to
 * @param from drawable to copy properties from
 *//*ww  w . j a v  a  2  s. com*/
public static void copyProperties(Drawable to, Drawable from) {
    if (from == null || to == null || to == from) {
        return;
    }

    to.setBounds(from.getBounds());
    to.setChangingConfigurations(from.getChangingConfigurations());
    to.setLevel(from.getLevel());
    to.setVisible(from.isVisible(), /* restart */false);
    to.setState(from.getState());
}

From source file:com.albedinsky.android.ui.graphics.drawable.DrawableWrapper.java

/**
 * Creates a new instance of DrawableWrapper which wraps the given <var>drawable</var>.
 *
 * @param drawable The drawable to wrap.
 *//*  w  ww. jav a 2 s. c o m*/
public DrawableWrapper(@NonNull Drawable drawable) {
    this.mDrawable = drawable;

    /**
     * Copy current state of the wrapped drawable.
     */
    setState(drawable.getState());
    setBounds(drawable.getBounds());
    setLevel(drawable.getLevel());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        setCallback(drawable.getCallback());
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setAlpha(drawable.getAlpha());
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setColorFilter(drawable.getColorFilter());
    }
    mDrawable.setCallback(this);
}

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

private boolean setIcon(final ImageView iconView, GuidedAction action) {
    Drawable icon = null;
    if (iconView != null) {
        Context context = iconView.getContext();
        icon = action.getIcon();//from  w ww  . j av  a2s. c o m
        if (icon != null) {
            // setImageDrawable resets the drawable's level unless we set the view level first.
            iconView.setImageLevel(icon.getLevel());
            iconView.setImageDrawable(icon);
            iconView.setVisibility(View.VISIBLE);
        } else {
            iconView.setVisibility(View.GONE);
        }
    }
    return icon != null;
}