Search in sources :

Example 11 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project Klyph by jonathangerbaud.

the class DefaultHeaderTransformer method applyProgressBarSettings.

private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        final int strokeWidth = mHeaderProgressBar.getResources().getDimensionPixelSize(R.dimen.ptr_progress_bar_stroke_width);
        mHeaderProgressBar.setIndeterminateDrawable(new SmoothProgressDrawable.Builder(mHeaderProgressBar.getContext()).color(mProgressDrawableColor).width(strokeWidth).build());
        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);
        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
Also used : RectShape(android.graphics.drawable.shapes.RectShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 12 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project HoloEverywhere by Prototik.

the class ProgressBar method tileify.

private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];
        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i), id == android.R.id.progress || id == android.R.id.secondaryProgress);
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);
        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }
        return newBg;
    } else if (drawable instanceof StateListDrawable) {
        StateListDrawable in = (StateListDrawable) drawable;
        StateListDrawable out = new StateListDrawable();
        int numStates = ReflectHelper.invoke(in, "getStateCount", int.class);
        for (int i = 0; i < numStates; i++) {
            out.addState(ReflectHelper.invoke(in, "getStateSet", int[].class, i), tileify(ReflectHelper.invoke(in, "getStateDrawable", Drawable.class, i), clip));
        }
        return out;
    } else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }
        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        return clip ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }
    return drawable;
}
Also used : Bitmap(android.graphics.Bitmap) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) BitmapShader(android.graphics.BitmapShader) SuppressLint(android.annotation.SuppressLint) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 13 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project Bitocle by mthli.

the class DefaultHeaderTransformer method applyProgressBarSettings.

private void applyProgressBarSettings() {
    if (mHeaderProgressBar != null) {
        ShapeDrawable shape = new ShapeDrawable();
        shape.setShape(new RectShape());
        shape.getPaint().setColor(mProgressDrawableColor);
        ClipDrawable clipDrawable = new ClipDrawable(shape, Gravity.CENTER, ClipDrawable.HORIZONTAL);
        mHeaderProgressBar.setProgressDrawable(clipDrawable);
    }
}
Also used : RectShape(android.graphics.drawable.shapes.RectShape) ShapeDrawable(android.graphics.drawable.ShapeDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 14 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project AndroidTraining by mixi-inc.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final Handler handler = new Handler();
    final Timer timer = new Timer();
    // 5秒ごとにレベルを変更するタスク
    final Drawable levelListDrawable = findViewById(R.id.LevelListButton).getBackground();
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            final int level = levelListDrawable.getLevel();
            handler.post(new Runnable() {

                @Override
                public void run() {
                    if (level == 0) {
                        levelListDrawable.setLevel(1);
                    } else {
                        levelListDrawable.setLevel(0);
                    }
                }
            });
        }
    }, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
    // クロスフェードを開始する
    final TransitionDrawable transition = (TransitionDrawable) findViewById(R.id.TransitionView).getBackground();
    transition.startTransition(TRANSITION_DURATION);
    // 5秒ごとにレベルを変更し、クリップの範囲を変化させるタスク
    final ClipDrawable clipDrawable = (ClipDrawable) findViewById(R.id.ClipView).getBackground();
    timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            handler.post(new Runnable() {

                @Override
                public void run() {
                    clipDrawable.setLevel(clipDrawable.getLevel() + 1000);
                }
            });
        }
    }, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
    // スケールのレベルを変更する
    ScaleDrawable scale = (ScaleDrawable) findViewById(R.id.ScaleView).getBackground();
    scale.setLevel(1);
}
Also used : ScaleDrawable(android.graphics.drawable.ScaleDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) Timer(java.util.Timer) TimerTask(java.util.TimerTask) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) Drawable(android.graphics.drawable.Drawable) ScaleDrawable(android.graphics.drawable.ScaleDrawable) Handler(android.os.Handler) ClipDrawable(android.graphics.drawable.ClipDrawable)

Example 15 with ClipDrawable

use of android.graphics.drawable.ClipDrawable in project ActionBarSherlock by JakeWharton.

the class IcsProgressBar method tileify.

/**
     * Converts a drawable to a tiled version of itself. It will recursively
     * traverse layer and state list drawables.
     */
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];
        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i), (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);
        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }
        return newBg;
    } else /* else if (drawable instanceof StateListDrawable) {
            StateListDrawable in = (StateListDrawable) drawable;
            StateListDrawable out = new StateListDrawable();
            int numStates = in.getStateCount();
            for (int i = 0; i < numStates; i++) {
                out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
            }
            return out;

        }*/
    if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }
        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL) : shapeDrawable;
    }
    return drawable;
}
Also used : Bitmap(android.graphics.Bitmap) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) ClipDrawable(android.graphics.drawable.ClipDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapShader(android.graphics.BitmapShader) ClipDrawable(android.graphics.drawable.ClipDrawable)

Aggregations

ClipDrawable (android.graphics.drawable.ClipDrawable)40 BitmapDrawable (android.graphics.drawable.BitmapDrawable)35 Drawable (android.graphics.drawable.Drawable)35 LayerDrawable (android.graphics.drawable.LayerDrawable)35 AnimationDrawable (android.graphics.drawable.AnimationDrawable)34 ShapeDrawable (android.graphics.drawable.ShapeDrawable)27 StateListDrawable (android.graphics.drawable.StateListDrawable)16 Bitmap (android.graphics.Bitmap)13 BitmapShader (android.graphics.BitmapShader)13 RectShape (android.graphics.drawable.shapes.RectShape)3 SuppressLint (android.annotation.SuppressLint)2 TypedArray (android.content.res.TypedArray)1 RectF (android.graphics.RectF)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 PaintDrawable (android.graphics.drawable.PaintDrawable)1 RotateDrawable (android.graphics.drawable.RotateDrawable)1 ScaleDrawable (android.graphics.drawable.ScaleDrawable)1 TransitionDrawable (android.graphics.drawable.TransitionDrawable)1 Handler (android.os.Handler)1 DrawableWrapper (android.support.v4.graphics.drawable.DrawableWrapper)1