Search in sources :

Example 16 with Shader

use of android.graphics.Shader in project android_packages_apps_crDroidSettings by crdroidandroid.

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 17 with Shader

use of android.graphics.Shader in project YhLibraryForAndroid by android-coco.

the class LineChartView method drawLine.

// 画折线
private void drawLine(Canvas canvas) {
    // 画坐标点
    for (int i = 0; i < mItems.size(); i++) {
        float x = i * xInterval + xOrigin + mAxesWidth;
        if (i == 0) {
            mPathShader.moveTo(x, yOrigin - (mItems.get(i).getValue() - min) / yInterval);
            mPath.moveTo(x, yOrigin - (mItems.get(i).getValue() - min) / yInterval);
        } else {
            mPath.lineTo(x - mMargin10 - mAxesWidth, yOrigin - (mItems.get(i).getValue() - min) / yInterval);
            mPathShader.lineTo(x - mMargin10 - mAxesWidth, yOrigin - (mItems.get(i).getValue() - min) / yInterval);
            if (i == mItems.size() - 1) {
                mPathShader.lineTo(x - mMargin10 - mAxesWidth, yOrigin);
                mPathShader.lineTo(xOrigin, yOrigin);
                mPathShader.close();
            }
        }
    }
    // 渐变阴影
    Shader mShader = new LinearGradient(0, 0, 0, getHeight(), shadeColors, null, Shader.TileMode.CLAMP);
    mPaintShader.setShader(mShader);
    // 绘制渐变阴影
    canvas.drawPath(mPathShader, mPaintShader);
}
Also used : LinearGradient(android.graphics.LinearGradient) Shader(android.graphics.Shader) Paint(android.graphics.Paint)

Example 18 with Shader

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

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 19 with Shader

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

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 20 with Shader

use of android.graphics.Shader in project android_packages_apps_Gallery2 by LineageOS.

the class ColorBrightnessView method updatePaint.

private void updatePaint() {
    float[] hsvo = Arrays.copyOf(mHSVO, 4);
    hsvo[2] = 1;
    hsvo[1] = 1;
    hsvo[3] = 1;
    int color2 = Color.HSVToColor(hsvo);
    hsvo[2] = 0;
    int color1 = Color.HSVToColor(hsvo);
    Shader sg = new LinearGradient(mBorder, mBorder, mWidth - mBorder, mBorder, color1, color2, Shader.TileMode.CLAMP);
    mBarPaint1.setShader(sg);
}
Also used : LinearGradient(android.graphics.LinearGradient) BitmapShader(android.graphics.BitmapShader) Shader(android.graphics.Shader) Paint(android.graphics.Paint)

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