Search in sources :

Example 16 with LinearGradient

use of android.graphics.LinearGradient in project SmoothProgressBar by castorflex.

the class SmoothProgressDrawable method drawGradient.

private void drawGradient(Canvas canvas) {
    float xSectionWidth = 1f / mSectionsCount;
    int currentIndexColor = mColorsIndex;
    mLinearGradientPositions[0] = 0f;
    mLinearGradientPositions[mLinearGradientPositions.length - 1] = 1f;
    int firstColorIndex = currentIndexColor - 1;
    if (firstColorIndex < 0)
        firstColorIndex += mColors.length;
    mLinearGradientColors[0] = mColors[firstColorIndex];
    for (int i = 0; i < mSectionsCount; ++i) {
        float position = mInterpolator.getInterpolation(i * xSectionWidth + mCurrentOffset);
        mLinearGradientPositions[i + 1] = position;
        mLinearGradientColors[i + 1] = mColors[currentIndexColor];
        currentIndexColor = (currentIndexColor + 1) % mColors.length;
    }
    mLinearGradientColors[mLinearGradientColors.length - 1] = mColors[currentIndexColor];
    float left = mReversed ? (mMirrorMode ? Math.abs(mBounds.left - mBounds.right) / 2 : mBounds.left) : mBounds.left;
    float right = mMirrorMode ? (mReversed ? mBounds.left : Math.abs(mBounds.left - mBounds.right) / 2) : mBounds.right;
    float top = mBounds.centerY() - mStrokeWidth / 2;
    float bottom = mBounds.centerY() + mStrokeWidth / 2;
    LinearGradient linearGradient = new LinearGradient(left, top, right, bottom, mLinearGradientColors, mLinearGradientPositions, mMirrorMode ? Shader.TileMode.MIRROR : Shader.TileMode.CLAMP);
    mPaint.setShader(linearGradient);
}
Also used : LinearGradient(android.graphics.LinearGradient) Paint(android.graphics.Paint)

Example 17 with LinearGradient

use of android.graphics.LinearGradient in project ScrollableTabHost-for-Android by honcheng.

the class RadioStateDrawable method setShade.

public void setShade(int shade) {
    int[] shades = new int[2];
    switch(shade) {
        case SHADE_GRAY:
            {
                shades = new int[] { Color.LTGRAY, Color.DKGRAY };
                break;
            }
        case SHADE_BLUE:
            {
                shades = new int[] { Color.CYAN, Color.BLUE };
                break;
            }
        case SHADE_RED:
            {
                shades = new int[] { Color.MAGENTA, Color.RED };
                break;
            }
        case SHADE_MAGENTA:
            {
                shades = new int[] { Color.MAGENTA, Color.rgb(292, 52, 100) };
                break;
            }
        case SHADE_YELLOW:
            {
                shades = new int[] { Color.YELLOW, Color.rgb(255, 126, 0) };
                break;
            }
        case SHADE_ORANGE:
            {
                shades = new int[] { Color.rgb(255, 126, 0), Color.rgb(255, 90, 0) };
                break;
            }
        case SHADE_GREEN:
            {
                shades = new int[] { Color.GREEN, Color.rgb(0, 79, 4) };
                break;
            }
    }
    shader = new LinearGradient(0, 0, 0, bitmap.getHeight(), shades, null, Shader.TileMode.MIRROR);
    if (highlight)
        textShader = new LinearGradient(0, 0, 0, 10, new int[] { Color.WHITE, Color.LTGRAY }, null, Shader.TileMode.MIRROR);
    else
        textShader = new LinearGradient(0, 0, 0, 10, new int[] { Color.LTGRAY, Color.DKGRAY }, null, Shader.TileMode.MIRROR);
}
Also used : LinearGradient(android.graphics.LinearGradient)

Example 18 with LinearGradient

use of android.graphics.LinearGradient in project nmid-headline by miao1007.

the class ImageUtils method createReflectionImageWithOrigin.

/**
   * 获得带倒影的图片方法
   */
public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap) {
    final int reflectionGap = 4;
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height / 2, width, height / 2, matrix, false);
    Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height / 2), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapWithReflection);
    canvas.drawBitmap(bitmap, 0, 0, null);
    Paint deafalutPaint = new Paint();
    canvas.drawRect(0, height, width, height + reflectionGap, deafalutPaint);
    canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null);
    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    // Set the Transfer mode to be porter duff and destination in
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    // Draw a rectangle using the paint with our linear gradient
    canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint);
    return bitmapWithReflection;
}
Also used : LinearGradient(android.graphics.LinearGradient) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 19 with LinearGradient

use of android.graphics.LinearGradient in project Signal-Android by WhisperSystems.

the class VerticalSlideColorPicker method onSizeChanged.

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    viewWidth = w;
    viewHeight = h;
    centerX = viewWidth / 2;
    colorPickerRadius = (viewWidth / 2) - borderWidth;
    colorPickerBody = new RectF(centerX - colorPickerRadius, borderWidth + colorPickerRadius, centerX + colorPickerRadius, viewHeight - (borderWidth + colorPickerRadius));
    LinearGradient gradient = new LinearGradient(0, colorPickerBody.top, 0, colorPickerBody.bottom, colors, null, Shader.TileMode.CLAMP);
    paint.setShader(gradient);
    if (bitmap != null) {
        bitmap.recycle();
    }
    bitmap = Bitmap.createBitmap(viewWidth, viewHeight, Bitmap.Config.ARGB_8888);
    bitmapCanvas = new Canvas(bitmap);
    resetToDefault();
}
Also used : RectF(android.graphics.RectF) LinearGradient(android.graphics.LinearGradient) Canvas(android.graphics.Canvas)

Example 20 with LinearGradient

use of android.graphics.LinearGradient in project LoadingView by ldoublem.

the class LVRingProgress method drawProgress.

private void drawProgress(Canvas canvas, Paint paint, int sweepAngle) {
    paint.reset();
    paint.setAntiAlias(true);
    paint.setStrokeWidth(mPadding);
    paint.setStyle(Paint.Style.STROKE);
    Path pathProgress = new Path();
    pathProgress.addArc(rectFBg, -90, sweepAngle);
    Shader mShader = new LinearGradient(rectFBg.left, rectFBg.top, rectFBg.left, rectFBg.bottom, new int[] { ProStartColor, ProEndColor }, new float[] { 0f, 1f }, Shader.TileMode.CLAMP);
    paint.setShader(mShader);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setStrokeJoin(Paint.Join.ROUND);
    canvas.drawPath(pathProgress, paint);
    paint.setShader(null);
    mPaintText.setTextSize(mPaint.getStrokeWidth() / 2);
    String text = String.valueOf((int) (sweepAngle / MaxAngle * 100)) + "%";
    canvas.drawTextOnPath(text, pathProgress, (float) (Math.PI * rectFBg.width() * (sweepAngle / MaxAngle) - getFontlength(mPaintText, text) * 1.5f), getFontHeight(mPaintText) / 3, mPaintText);
}
Also used : Path(android.graphics.Path) LinearGradient(android.graphics.LinearGradient) Shader(android.graphics.Shader)

Aggregations

LinearGradient (android.graphics.LinearGradient)128 Paint (android.graphics.Paint)74 RectF (android.graphics.RectF)41 RadialGradient (android.graphics.RadialGradient)27 Canvas (android.graphics.Canvas)23 Rect (android.graphics.Rect)21 Shader (android.graphics.Shader)19 Path (android.graphics.Path)18 Bitmap (android.graphics.Bitmap)16 Matrix (android.graphics.Matrix)16 Point (android.graphics.Point)16 SweepGradient (android.graphics.SweepGradient)12 PorterDuffXfermode (android.graphics.PorterDuffXfermode)10 ShapeDrawable (android.graphics.drawable.ShapeDrawable)10 SuppressLint (android.annotation.SuppressLint)7 ComposeShader (android.graphics.ComposeShader)7 PaintDrawable (android.graphics.drawable.PaintDrawable)5 RectShape (android.graphics.drawable.shapes.RectShape)5 ColorDrawable (android.graphics.drawable.ColorDrawable)4 ShaderFactory (android.graphics.drawable.ShapeDrawable.ShaderFactory)4