Search in sources :

Example 76 with Shader

use of android.graphics.Shader in project CustomShapeImageView by MostafaGazar.

the class SVGHandlerTest method testDoFill_byURL.

@Test
public void testDoFill_byURL() {
    // given
    HashMap<String, Shader> gradients = new HashMap<>();
    Shader shader = mock(Shader.class);
    gradients.put("gr1", shader);
    // when
    boolean res = parserHandler.doFill(new SVGParser.Properties(attributes(attr("fill", "url(#gr1)"))), gradients);
    // then
    assertThat(res, is(true));
    verify(paint).setShader(shader);
    verify(paint).setStyle(Paint.Style.FILL);
}
Also used : HashMap(java.util.HashMap) Shader(android.graphics.Shader) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 77 with Shader

use of android.graphics.Shader in project xDrip by NightscoutFoundation.

the class CircleWatchface method prepareDrawTime.

private synchronized void prepareDrawTime() {
    Log.d(TAG, "CircleWatchface start prepareDrawTime");
    hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY) % 12;
    minute = Calendar.getInstance().get(Calendar.MINUTE);
    angleBig = (((hour + minute / 60f) / 12f * 360) - 90 - BIG_HAND_WIDTH / 2f + 360) % 360;
    angleSMALL = ((minute / 60f * 360) - 90 - SMALL_HAND_WIDTH / 2f + 360) % 360;
    color = 0;
    switch(getSgvLevel()) {
        case -1:
            color = getLowColor();
            break;
        case 0:
            color = getInRangeColor();
            break;
        case 1:
            color = getHighColor();
            break;
    }
    if (isAnimated()) {
        // Animation matrix:
        int[] rainbow = { Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE, Color.CYAN };
        Shader shader = new LinearGradient(0, 0, 0, 20, rainbow, null, Shader.TileMode.MIRROR);
        Matrix matrix = new Matrix();
        matrix.setRotate(animationAngle);
        shader.setLocalMatrix(matrix);
        circlePaint.setShader(shader);
    } else {
        circlePaint.setShader(null);
    }
    circlePaint.setStyle(Paint.Style.STROKE);
    circlePaint.setStrokeWidth(CIRCLE_WIDTH);
    circlePaint.setAntiAlias(true);
    circlePaint.setColor(color);
    removePaint.setStyle(Paint.Style.STROKE);
    removePaint.setStrokeWidth(CIRCLE_WIDTH);
    removePaint.setAntiAlias(true);
    removePaint.setColor(getBackgroundColor());
    ;
    rect = new RectF(PADDING, PADDING, (float) (displaySize.x - PADDING), (float) (displaySize.y - PADDING));
    rectDelete = new RectF(PADDING - CIRCLE_WIDTH / 2, PADDING - CIRCLE_WIDTH / 2, (float) (displaySize.x - PADDING + CIRCLE_WIDTH / 2), (float) (displaySize.y - PADDING + CIRCLE_WIDTH / 2));
    overlapping = ALWAYS_HIGHLIGT_SMALL || areOverlapping(angleSMALL, angleSMALL + SMALL_HAND_WIDTH + NEAR, angleBig, angleBig + BIG_HAND_WIDTH + NEAR);
    Log.d(TAG, "CircleWatchface end prepareDrawTime");
}
Also used : RectF(android.graphics.RectF) LinearGradient(android.graphics.LinearGradient) Matrix(android.graphics.Matrix) Shader(android.graphics.Shader)

Example 78 with Shader

use of android.graphics.Shader in project xDrip-plus by jamorham.

the class BIGChart method updateRainbow.

protected void updateRainbow() {
    animationAngle = (animationAngle + 1) % 360;
    // Animation matrix:
    int[] rainbow = { Color.RED, Color.YELLOW, Color.GREEN, Color.BLUE, Color.CYAN };
    Shader shader = new LinearGradient(0, 0, 0, 20, rainbow, null, Shader.TileMode.MIRROR);
    Matrix matrix = new Matrix();
    matrix.setRotate(animationAngle);
    shader.setLocalMatrix(matrix);
    mSgv.getPaint().setShader(shader);
    invalidate();
}
Also used : LinearGradient(android.graphics.LinearGradient) Matrix(android.graphics.Matrix) Shader(android.graphics.Shader)

Example 79 with Shader

use of android.graphics.Shader in project seven_develop by seven123456.

the class GradientView method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int width = getWidth() / 2;
    int height = getHeight() / 2;
    paint.setColor(Color.WHITE);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(20);
    Matrix matrix = new Matrix();
    matrix.setRotate(-90, width, height);
    Shader shader = new LinearGradient(width, 0, getWidth(), height, Color.RED, Color.GREEN, Shader.TileMode.CLAMP);
    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
    canvas.drawCircle(width, height, 200, paint);
}
Also used : LinearGradient(android.graphics.LinearGradient) Matrix(android.graphics.Matrix) Shader(android.graphics.Shader) Paint(android.graphics.Paint)

Aggregations

Shader (android.graphics.Shader)79 Paint (android.graphics.Paint)42 LinearGradient (android.graphics.LinearGradient)39 BitmapShader (android.graphics.BitmapShader)22 Bitmap (android.graphics.Bitmap)18 ShapeDrawable (android.graphics.drawable.ShapeDrawable)15 Matrix (android.graphics.Matrix)14 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