Search in sources :

Example 11 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 12 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 13 with LinearGradient

use of android.graphics.LinearGradient 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 14 with LinearGradient

use of android.graphics.LinearGradient in project weiciyuan by qii.

the class LinearGradientCoverImageView method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (linearGradient == null) {
        int[] colorLinear = { Color.TRANSPARENT, getResources().getColor(R.color.dark_gray) };
        linearGradient = new LinearGradient(0, 0, 0, getHeight(), colorLinear, null, Shader.TileMode.REPEAT);
        paint.setShader(linearGradient);
    }
    canvas.drawPaint(paint);
}
Also used : LinearGradient(android.graphics.LinearGradient)

Example 15 with LinearGradient

use of android.graphics.LinearGradient in project muzei by romannurik.

the class ScrimUtil method makeCubicGradientScrimDrawable.

/**
     * Creates an approximated cubic gradient using a multi-stop linear gradient. See
     * <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
     * details.
     */
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
    // Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
    int cacheKeyHash = baseColor;
    cacheKeyHash = 31 * cacheKeyHash + numStops;
    cacheKeyHash = 31 * cacheKeyHash + gravity;
    Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
    if (cachedGradient != null) {
        return cachedGradient;
    }
    numStops = Math.max(numStops, 2);
    PaintDrawable paintDrawable = new PaintDrawable();
    paintDrawable.setShape(new RectShape());
    final int[] stopColors = new int[numStops];
    int red = Color.red(baseColor);
    int green = Color.green(baseColor);
    int blue = Color.blue(baseColor);
    int alpha = Color.alpha(baseColor);
    for (int i = 0; i < numStops; i++) {
        float x = i * 1f / (numStops - 1);
        float opacity = MathUtil.constrain(0, 1, (float) Math.pow(x, 3));
        stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
    }
    final float x0, x1, y0, y1;
    switch(gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:
            x0 = 1;
            x1 = 0;
            break;
        case Gravity.RIGHT:
            x0 = 0;
            x1 = 1;
            break;
        default:
            x0 = 0;
            x1 = 0;
            break;
    }
    switch(gravity & Gravity.VERTICAL_GRAVITY_MASK) {
        case Gravity.TOP:
            y0 = 1;
            y1 = 0;
            break;
        case Gravity.BOTTOM:
            y0 = 0;
            y1 = 1;
            break;
        default:
            y0 = 0;
            y1 = 0;
            break;
    }
    paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {

        @Override
        public Shader resize(int width, int height) {
            return new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null, Shader.TileMode.CLAMP);
        }
    });
    cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
    return paintDrawable;
}
Also used : LinearGradient(android.graphics.LinearGradient) RectShape(android.graphics.drawable.shapes.RectShape) PaintDrawable(android.graphics.drawable.PaintDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) Drawable(android.graphics.drawable.Drawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) PaintDrawable(android.graphics.drawable.PaintDrawable) Shader(android.graphics.Shader)

Aggregations

LinearGradient (android.graphics.LinearGradient)123 Paint (android.graphics.Paint)70 RectF (android.graphics.RectF)38 RadialGradient (android.graphics.RadialGradient)27 Canvas (android.graphics.Canvas)22 Rect (android.graphics.Rect)21 Path (android.graphics.Path)18 Shader (android.graphics.Shader)18 Bitmap (android.graphics.Bitmap)15 Matrix (android.graphics.Matrix)15 Point (android.graphics.Point)13 SweepGradient (android.graphics.SweepGradient)12 PorterDuffXfermode (android.graphics.PorterDuffXfermode)9 ShapeDrawable (android.graphics.drawable.ShapeDrawable)9 SuppressLint (android.annotation.SuppressLint)6 ComposeShader (android.graphics.ComposeShader)6 PaintDrawable (android.graphics.drawable.PaintDrawable)5 RectShape (android.graphics.drawable.shapes.RectShape)5 ColorMatrix (android.graphics.ColorMatrix)3 PointF (android.graphics.PointF)3