Search in sources :

Example 31 with Shader

use of android.graphics.Shader in project KeepScore by nolanlawson.

the class TopDownGradientSpan method updateDrawState.

@Override
public void updateDrawState(TextPaint ds) {
    Shader shader = new LinearGradient(0, mStartY, 0, mEndY, new int[] { mStartColor, mEndColor }, null, TileMode.CLAMP);
    ds.setShader(shader);
}
Also used : LinearGradient(android.graphics.LinearGradient) Shader(android.graphics.Shader)

Example 32 with Shader

use of android.graphics.Shader in project shimmer-android by facebook.

the class ShimmerDrawable method updateShader.

private void updateShader() {
    final Rect bounds = getBounds();
    final int boundsWidth = bounds.width();
    final int boundsHeight = bounds.height();
    if (boundsWidth == 0 || boundsHeight == 0 || mShimmer == null) {
        return;
    }
    final int width = mShimmer.width(boundsWidth);
    final int height = mShimmer.height(boundsHeight);
    final Shader shader;
    switch(mShimmer.shape) {
        default:
        case Shimmer.Shape.LINEAR:
            boolean vertical = mShimmer.direction == Shimmer.Direction.TOP_TO_BOTTOM || mShimmer.direction == Shimmer.Direction.BOTTOM_TO_TOP;
            int endX = vertical ? 0 : width;
            int endY = vertical ? height : 0;
            shader = new LinearGradient(0, 0, endX, endY, mShimmer.colors, mShimmer.positions, Shader.TileMode.CLAMP);
            break;
        case Shimmer.Shape.RADIAL:
            shader = new RadialGradient(width / 2f, height / 2f, (float) (Math.max(width, height) / Math.sqrt(2)), mShimmer.colors, mShimmer.positions, Shader.TileMode.CLAMP);
            break;
    }
    mShimmerPaint.setShader(shader);
}
Also used : LinearGradient(android.graphics.LinearGradient) Rect(android.graphics.Rect) RadialGradient(android.graphics.RadialGradient) Shader(android.graphics.Shader) Paint(android.graphics.Paint)

Example 33 with Shader

use of android.graphics.Shader 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 34 with Shader

use of android.graphics.Shader in project lottie-android by airbnb.

the class GradientStrokeContent method draw.

@Override
public void draw(Canvas canvas, Matrix parentMatrix, int parentAlpha) {
    if (hidden) {
        return;
    }
    getBounds(boundsRect, parentMatrix, false);
    Shader shader;
    if (type == GradientType.LINEAR) {
        shader = getLinearGradient();
    } else {
        shader = getRadialGradient();
    }
    shader.setLocalMatrix(parentMatrix);
    paint.setShader(shader);
    super.draw(canvas, parentMatrix, parentAlpha);
}
Also used : Shader(android.graphics.Shader)

Example 35 with Shader

use of android.graphics.Shader in project assertj-android by square.

the class AbstractPaintAssert method hasShader.

public S hasShader(Shader shader) {
    isNotNull();
    Shader actualShader = actual.getShader();
    // 
    assertThat(actualShader).overridingErrorMessage("Expected shader <%s> but was <%s>.", shader, // 
    actualShader).isSameAs(shader);
    return myself;
}
Also used : Shader(android.graphics.Shader)

Aggregations

Shader (android.graphics.Shader)77 Paint (android.graphics.Paint)41 LinearGradient (android.graphics.LinearGradient)38 BitmapShader (android.graphics.BitmapShader)21 Bitmap (android.graphics.Bitmap)17 ShapeDrawable (android.graphics.drawable.ShapeDrawable)15 Matrix (android.graphics.Matrix)13 RectShape (android.graphics.drawable.shapes.RectShape)9 PaintDrawable (android.graphics.drawable.PaintDrawable)8 Point (android.graphics.Point)7 SuppressLint (android.annotation.SuppressLint)6 ColorDrawable (android.graphics.drawable.ColorDrawable)6 Drawable (android.graphics.drawable.Drawable)5 OvalShape (android.graphics.drawable.shapes.OvalShape)5 CallSuper (android.annotation.CallSuper)4 Rect (android.graphics.Rect)4 RectF (android.graphics.RectF)4 ShaderFactory (android.graphics.drawable.ShapeDrawable.ShaderFactory)4 Test (org.junit.Test)4 Canvas (android.graphics.Canvas)3