Example usage for android.graphics.drawable Drawable setLevel

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

Introduction

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

Prototype

public final boolean setLevel(@IntRange(from = 0, to = 10000) int level) 

Source Link

Document

Specify the level for the drawable.

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
 *//*from ww w.j av  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.negusoft.greenmatter.drawable.CompoundDrawableWrapper.java

@Override
protected boolean onLevelChange(int level) {
    for (Drawable d : mSecondaryDrawables)
        d.setLevel(level);
    return super.setLevel(level);
}

From source file:com.shizhefei.view.largeimage.UpdateImageView.java

private void updateDrawable(Drawable d) {
    if (mDrawable != null) {
        mDrawable.setCallback(null);//from ww  w .ja  v a  2  s  . com
        unscheduleDrawable(mDrawable);
    }
    mDrawable = d;
    if (d != null) {
        d.setCallback(this);
        DrawableCompat.setLayoutDirection(d, DrawableCompat.getLayoutDirection(d));
        if (d.isStateful()) {
            d.setState(getDrawableState());
        }
        d.setVisible(getVisibility() == VISIBLE, true);
        d.setLevel(mLevel);
        mDrawableWidth = d.getIntrinsicWidth();
        mDrawableHeight = d.getIntrinsicHeight();
        //            applyImageTint();
        //            applyColorMod();
        //
        //            configureBounds();
    } else {
        mDrawableWidth = mDrawableHeight = -1;
    }
}

From source file:com.shizhefei.view.largeimage.LargeImageView.java

private void updateDrawable(Drawable d) {
    if (mDrawable != null) {
        mDrawable.setCallback(null);//  w  ww.j a  va  2s .  c om
        unscheduleDrawable(mDrawable);
    }
    mDrawable = d;
    if (d != null) {
        d.setCallback(this);
        DrawableCompat.setLayoutDirection(d, DrawableCompat.getLayoutDirection(d));
        if (d.isStateful()) {
            d.setState(getDrawableState());
        }
        d.setVisible(getVisibility() == VISIBLE, true);
        d.setLevel(mLevel);
        mDrawableWidth = d.getIntrinsicWidth();
        mDrawableHeight = d.getIntrinsicHeight();
    } else {
        mDrawableWidth = mDrawableHeight = -1;
    }
}

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

/**
 * Convert a AnimationDrawable for use as a barberpole animation.
 * Each frame of the animation is wrapped in a ClipDrawable and
 * given a tiling BitmapShader./*from w  ww  .  ja va2 s . co m*/
 */
private Drawable tileifyIndeterminate(Drawable drawable) {
    if (drawable instanceof AnimationDrawable) {
        AnimationDrawable background = (AnimationDrawable) drawable;
        final int N = background.getNumberOfFrames();
        AnimationDrawable newBg = new AnimationDrawable();
        newBg.setOneShot(background.isOneShot());

        for (int i = 0; i < N; i++) {
            Drawable frame = tileify(background.getFrame(i), true);
            frame.setLevel(10000);
            newBg.addFrame(frame, background.getDuration(i));
        }
        newBg.setLevel(10000);
        drawable = newBg;
    }
    return drawable;
}

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

@Override
protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Drawable d = mCurrentDrawable;
    if (d != null) {
        // Translate canvas so a indeterminate circular progress bar with padding
        // rotates properly in its animation
        canvas.save();//from ww  w  .  ja v  a  2  s  .co  m
        canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop);
        long time = getDrawingTime();
        if (mAnimation != null) {
            mAnimation.getTransformation(time, mTransformation);
            float scale = mTransformation.getAlpha();
            try {
                mInDrawing = true;
                d.setLevel((int) (scale * MAX_LEVEL));
            } finally {
                mInDrawing = false;
            }
            if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) {
                mLastDrawTime = SystemClock.uptimeMillis();
                postInvalidateDelayed(mAnimationResolution);
            }
        }
        d.draw(canvas);
        canvas.restore();
        if (mShouldStartAnimationDrawable && d instanceof Animatable) {
            ((Animatable) d).start();
            mShouldStartAnimationDrawable = false;
        }
    }
}

From source file:org.kde.necessitas.ministro.ExtractStyle.java

public JSONObject getDrawable(Object drawable, String filename) {
    JSONObject json = new JSONObject();
    Bitmap bmp = null;//from   w w w.  j av a 2 s .com
    if (drawable instanceof Bitmap)
        bmp = (Bitmap) drawable;
    else {
        if (drawable instanceof BitmapDrawable)
            bmp = ((BitmapDrawable) drawable).getBitmap();
        else {
            if (drawable instanceof LayerDrawable) {
                return getLayerDrawable(drawable, filename);
            }
            if (drawable instanceof StateListDrawable) {
                return getStateListDrawable(drawable, filename);
            }
            if (drawable instanceof GradientDrawable) {
                return getGradientDrawable((GradientDrawable) drawable);
            }
            if (drawable instanceof ClipDrawable) {
                try {
                    json.put("type", "clipDrawable");
                    json.put("drawable",
                            getDrawable(
                                    getClipStateDrawableObject(((ClipDrawable) drawable).getConstantState()),
                                    filename));
                    Rect padding = new Rect();
                    if (((Drawable) drawable).getPadding(padding))
                        json.put("padding", getJsonRect(padding));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return json;
            }
            if (drawable instanceof ColorDrawable) {
                bmp = Bitmap.createBitmap(1, 1, Config.ARGB_8888);
                Drawable d = (Drawable) drawable;
                d.setBounds(0, 0, 1, 1);
                d.draw(new Canvas(bmp));
                Rect padding = new Rect();
                try {
                    json.put("type", "color");
                    json.put("color", bmp.getPixel(0, 0));
                    if (d.getPadding(padding))
                        json.put("padding", getJsonRect(padding));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                return json;
            } else {
                Drawable d = (Drawable) drawable;
                int w = d.getIntrinsicWidth();
                int h = d.getIntrinsicHeight();
                d.setLevel(10000);
                if (w < 1 || h < 1) {
                    w = 100;
                    h = 100;
                }
                bmp = Bitmap.createBitmap(w, h, Config.ARGB_8888);
                d.setBounds(0, 0, w, h);
                d.draw(new Canvas(bmp));
                if (drawable instanceof NinePatchDrawable) {
                    NinePatchDrawable npd = (NinePatchDrawable) drawable;
                    try {
                        json.put("type", "9patch");
                        json.put("drawable", getDrawable(bmp, filename));
                        Rect padding = new Rect();
                        if (npd.getPadding(padding))
                            json.put("padding", getJsonRect(padding));
                        json.put("chunkInfo", findPatchesMarings(d));
                        return json;
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    FileOutputStream out;
    try {
        filename = m_extractPath + filename + ".png";
        out = new FileOutputStream(filename);
        bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        json.put("type", "image");
        json.put("path", filename);
        json.put("width", bmp.getWidth());
        json.put("height", bmp.getHeight());
        MinistroActivity.nativeChmode(filename, 0644);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return json;
}