Search in sources :

Example 16 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project SmartAndroidSource by jaychou2012.

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)

Example 17 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project nmid-headline by miao1007.

the class EditPage method genBackground.

private void genBackground() {
    background = new ColorDrawable(DIM_COLOR);
    if (backgroundView != null) {
        try {
            Bitmap bgBm = captureView(backgroundView, backgroundView.getWidth(), backgroundView.getHeight());
            bgBm = blur(bgBm, 20, 8);
            BitmapDrawable blurBm = new BitmapDrawable(activity.getResources(), bgBm);
            background = new LayerDrawable(new Drawable[] { blurBm, background });
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
Also used : Bitmap(android.graphics.Bitmap) ColorDrawable(android.graphics.drawable.ColorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable)

Example 18 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project MaterialDesignLibrary by navasmdc.

the class Card method setBackgroundColor.

// Set color of background
public void setBackgroundColor(int color) {
    this.backgroundColor = color;
    if (isEnabled())
        beforeBackground = backgroundColor;
    LayerDrawable layer = (LayerDrawable) getBackground();
    GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
    shape.setColor(backgroundColor);
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 19 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project MaterialDesignLibrary by navasmdc.

the class Button method setBackgroundColor.

// Set color of background
public void setBackgroundColor(int color) {
    this.backgroundColor = color;
    if (isEnabled())
        beforeBackground = backgroundColor;
    try {
        LayerDrawable layer = (LayerDrawable) getBackground();
        GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
        shape.setColor(backgroundColor);
        rippleColor = makePressColor();
    } catch (Exception ex) {
    // Without bacground
    }
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 20 with LayerDrawable

use of android.graphics.drawable.LayerDrawable in project GalleryFinal by pengjianbo.

the class FloatingActionButton method updateBackground.

void updateBackground() {
    float circleLeft = mShadowRadius;
    float circleTop = mShadowRadius - mShadowOffset;
    final RectF circleRect = new RectF(circleLeft, circleTop, circleLeft + mCircleSize, circleTop + mCircleSize);
    LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] { new BitmapDrawable(getResources()), createFillDrawable(circleRect), new BitmapDrawable(getResources()), getIconDrawable() });
    float iconOffset = (mCircleSize - getDimension(R.dimen.fab_icon_size)) / 2f;
    int iconInsetHorizontal = (int) (mShadowRadius + iconOffset);
    int iconInsetTop = (int) (circleTop + iconOffset);
    int iconInsetBottom = (int) (mShadowRadius + mShadowOffset + iconOffset);
    layerDrawable.setLayerInset(3, iconInsetHorizontal, iconInsetTop, iconInsetHorizontal, iconInsetBottom);
    setBackgroundCompat(layerDrawable);
}
Also used : RectF(android.graphics.RectF) LayerDrawable(android.graphics.drawable.LayerDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

LayerDrawable (android.graphics.drawable.LayerDrawable)127 Drawable (android.graphics.drawable.Drawable)87 BitmapDrawable (android.graphics.drawable.BitmapDrawable)60 StateListDrawable (android.graphics.drawable.StateListDrawable)44 AnimationDrawable (android.graphics.drawable.AnimationDrawable)42 ClipDrawable (android.graphics.drawable.ClipDrawable)42 ShapeDrawable (android.graphics.drawable.ShapeDrawable)38 Paint (android.graphics.Paint)23 SuppressLint (android.annotation.SuppressLint)19 GradientDrawable (android.graphics.drawable.GradientDrawable)16 Bitmap (android.graphics.Bitmap)14 BitmapShader (android.graphics.BitmapShader)13 ColorDrawable (android.graphics.drawable.ColorDrawable)12 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)8 OvalShape (android.graphics.drawable.shapes.OvalShape)7 Nullable (android.annotation.Nullable)5 Resources (android.content.res.Resources)5 TypedArray (android.content.res.TypedArray)5 InsetDrawable (android.graphics.drawable.InsetDrawable)5 TransitionDrawable (android.graphics.drawable.TransitionDrawable)5