Example usage for android.graphics.drawable ShapeDrawable setShaderFactory

List of usage examples for android.graphics.drawable ShapeDrawable setShaderFactory

Introduction

In this page you can find the example usage for android.graphics.drawable ShapeDrawable setShaderFactory.

Prototype

public void setShaderFactory(ShaderFactory fact) 

Source Link

Document

Sets a ShaderFactory to which requests for a android.graphics.Shader object will be made.

Usage

From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static Drawable createLGradient(int shape, final int[] colors, final float[] positions) {

    ShapeDrawable shapeDrawable;
    if (shape == SHAPE_RECT) {
        shapeDrawable = new ShapeDrawable(new RectShape());
    } else {/*from www.  j a v  a2  s .com*/
        shapeDrawable = new ShapeDrawable(new OvalShape());
    }

    ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {

        @Override
        public Shader resize(int width, int height) {
            LinearGradient rg = new LinearGradient(0, 0, 0, height, colors, positions, Shader.TileMode.CLAMP);

            return rg;
        }
    };
    shapeDrawable.setShaderFactory(shaderFactory);

    return shapeDrawable;
}

From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static Drawable createRGradient(int shape, final int[] colors, final float[] positions) {

    ShapeDrawable shapeDrawable;
    if (shape == SHAPE_RECT) {
        shapeDrawable = new ShapeDrawable(new RectShape());
    } else {//from  w w  w. ja v a  2  s . co  m
        shapeDrawable = new ShapeDrawable(new OvalShape());
    }

    ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {

        @Override
        public Shader resize(int width, int height) {
            float gradRadius = Math.max(width, height) / 2;
            RadialGradient rg = new RadialGradient(width / 2, height / 2, gradRadius, colors, positions,
                    Shader.TileMode.CLAMP);

            return rg;
        }
    };
    shapeDrawable.setShaderFactory(shaderFactory);

    return shapeDrawable;
}

From source file:com.tafayor.selfcamerashot.taflib.helpers.GraphicsHelper.java

public static Drawable createRectGradient(final int direction, final int[] colors) {

    final ShapeDrawable shapeDrawable = new ShapeDrawable(new RectShape());
    final ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() {

        @Override/*from w  w  w.  j  ava 2s .c o  m*/
        public Shader resize(int width, int height) {
            int x0, y0, x1, y1;
            x0 = y0 = x1 = y1 = 0;
            if (direction == GRADIENT_DOWN) {
                y1 = height;
            } else if (direction == GRADIENT_UP) {
                y0 = height;
            } else if (direction == GRADIENT_RIGHT) {
                x1 = width;
            } else if (direction == GRADIENT_LEFT) {
                x0 = width;
            }
            LinearGradient lg = new LinearGradient(x0, y0, x1, y1, colors, new float[] { 0, 0.05f, 0.1f, 1 },
                    Shader.TileMode.REPEAT);
            return lg;
        }
    };
    shapeDrawable.setShaderFactory(shaderFactory);

    return shapeDrawable;
}