Search in sources :

Example 1 with ShaderFactory

use of android.graphics.drawable.ShapeDrawable.ShaderFactory in project PhotoNoter by yydcdut.

the class FloatingActionButton method createInnerStrokesDrawable.

/**
     * 创建内层drawable
     *
     * @param color
     * @param strokeWidth
     * @return
     */
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
    //不描边的话直接返回一个颜色为透明的drawable
    if (!mStrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }
    //圆 drawable
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    //这个暗颜色
    final int bottomStrokeColor = darkenColor(color);
    //比bottomStrokeColor透明一半
    final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
    //这个亮颜色
    final int topStrokeColor = lightenColor(color);
    //比topStrokeColor透明一半
    final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
    final Paint paint = shapeDrawable.getPaint();
    //锯齿
    paint.setAntiAlias(true);
    //描边宽度
    paint.setStrokeWidth(strokeWidth);
    //描边
    paint.setStyle(Style.STROKE);
    //draws a linear gradient
    shapeDrawable.setShaderFactory(new ShaderFactory() {

        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP);
        }
    });
    return shapeDrawable;
}
Also used : LinearGradient(android.graphics.LinearGradient) ShaderFactory(android.graphics.drawable.ShapeDrawable.ShaderFactory) ColorDrawable(android.graphics.drawable.ColorDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape) Shader(android.graphics.Shader) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 2 with ShaderFactory

use of android.graphics.drawable.ShapeDrawable.ShaderFactory in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class FloatingActionButton method createInnerStrokesDrawable.

private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
    if (!mStrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    final int bottomStrokeColor = darkenColor(color);
    final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
    final int topStrokeColor = lightenColor(color);
    final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
    final Paint paint = shapeDrawable.getPaint();
    paint.setAntiAlias(true);
    paint.setStrokeWidth(strokeWidth);
    paint.setStyle(Style.STROKE);
    shapeDrawable.setShaderFactory(new ShaderFactory() {

        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP);
        }
    });
    return shapeDrawable;
}
Also used : LinearGradient(android.graphics.LinearGradient) ShaderFactory(android.graphics.drawable.ShapeDrawable.ShaderFactory) ColorDrawable(android.graphics.drawable.ColorDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape) Shader(android.graphics.Shader) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 3 with ShaderFactory

use of android.graphics.drawable.ShapeDrawable.ShaderFactory in project android-floating-action-button by futuresimple.

the class FloatingActionButton method createInnerStrokesDrawable.

private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
    if (!mStrokeVisible) {
        return new ColorDrawable(Color.TRANSPARENT);
    }
    ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
    final int bottomStrokeColor = darkenColor(color);
    final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
    final int topStrokeColor = lightenColor(color);
    final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
    final Paint paint = shapeDrawable.getPaint();
    paint.setAntiAlias(true);
    paint.setStrokeWidth(strokeWidth);
    paint.setStyle(Style.STROKE);
    shapeDrawable.setShaderFactory(new ShaderFactory() {

        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP);
        }
    });
    return shapeDrawable;
}
Also used : LinearGradient(android.graphics.LinearGradient) ShaderFactory(android.graphics.drawable.ShapeDrawable.ShaderFactory) ColorDrawable(android.graphics.drawable.ColorDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Paint(android.graphics.Paint) OvalShape(android.graphics.drawable.shapes.OvalShape) Shader(android.graphics.Shader) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

SuppressLint (android.annotation.SuppressLint)3 LinearGradient (android.graphics.LinearGradient)3 Paint (android.graphics.Paint)3 Shader (android.graphics.Shader)3 ColorDrawable (android.graphics.drawable.ColorDrawable)3 ShapeDrawable (android.graphics.drawable.ShapeDrawable)3 ShaderFactory (android.graphics.drawable.ShapeDrawable.ShaderFactory)3 OvalShape (android.graphics.drawable.shapes.OvalShape)3