Search in sources :

Example 36 with RadialGradient

use of android.graphics.RadialGradient in project platform_frameworks_base by android.

the class KeyguardUserSwitcherScrim method updatePaint.

private void updatePaint() {
    if (mLayoutWidth == 0) {
        return;
    }
    float radius = mLayoutWidth * OUTER_EXTENT;
    boolean isLtr = getLayoutDirection() == LayoutDirection.LTR;
    mRadialGradientPaint.setShader(new RadialGradient(isLtr ? mLayoutWidth : 0, 0, radius, new int[] { Color.argb((int) (Color.alpha(mDarkColor) * mAlpha / 255f), 0, 0, 0), Color.TRANSPARENT }, new float[] { Math.max(0f, mLayoutWidth * INNER_EXTENT / radius), 1f }, Shader.TileMode.CLAMP));
}
Also used : RadialGradient(android.graphics.RadialGradient)

Example 37 with RadialGradient

use of android.graphics.RadialGradient in project android_frameworks_base by DirtyUnicorns.

the class RectShadowPainter method paintShadow.

public static void paintShadow(Outline viewOutline, float elevation, Canvas canvas) {
    Rect outline = new Rect();
    if (!viewOutline.getRect(outline)) {
        throw new IllegalArgumentException("Outline is not a rect shadow");
    }
    float shadowSize = elevationToShadow(elevation);
    int saved = modifyCanvas(canvas, shadowSize);
    if (saved == -1) {
        return;
    }
    try {
        Paint cornerPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
        cornerPaint.setStyle(Style.FILL);
        Paint edgePaint = new Paint(cornerPaint);
        edgePaint.setAntiAlias(false);
        float radius = viewOutline.getRadius();
        float outerArcRadius = radius + shadowSize;
        int[] colors = { START_COLOR, START_COLOR, END_COLOR };
        cornerPaint.setShader(new RadialGradient(0, 0, outerArcRadius, colors, new float[] { 0f, radius / outerArcRadius, 1f }, TileMode.CLAMP));
        edgePaint.setShader(new LinearGradient(0, 0, -shadowSize, 0, START_COLOR, END_COLOR, TileMode.CLAMP));
        Path path = new Path();
        path.setFillType(FillType.EVEN_ODD);
        // A rectangle bounding the complete shadow.
        RectF shadowRect = new RectF(outline);
        shadowRect.inset(-shadowSize, -shadowSize);
        // A rectangle with edges corresponding to the straight edges of the outline.
        RectF inset = new RectF(outline);
        inset.inset(radius, radius);
        // A rectangle used to represent the edge shadow.
        RectF edgeShadowRect = new RectF();
        // left and right sides.
        edgeShadowRect.set(-shadowSize, 0f, 0f, inset.height());
        // Left shadow
        sideShadow(canvas, edgePaint, edgeShadowRect, outline.left, inset.top, 0);
        // Right shadow
        sideShadow(canvas, edgePaint, edgeShadowRect, outline.right, inset.bottom, 2);
        // Top shadow
        edgeShadowRect.set(-shadowSize, 0, 0, inset.width());
        sideShadow(canvas, edgePaint, edgeShadowRect, inset.right, outline.top, 1);
        // bottom shadow. This needs an inset so that blank doesn't appear when the content is
        // moved up.
        edgeShadowRect.set(-shadowSize, 0, shadowSize / 2f, inset.width());
        edgePaint.setShader(new LinearGradient(edgeShadowRect.right, 0, edgeShadowRect.left, 0, colors, new float[] { 0f, 1 / 3f, 1f }, TileMode.CLAMP));
        sideShadow(canvas, edgePaint, edgeShadowRect, inset.left, outline.bottom, 3);
        // Draw corners.
        drawCorner(canvas, cornerPaint, path, inset.right, inset.bottom, outerArcRadius, 0);
        drawCorner(canvas, cornerPaint, path, inset.left, inset.bottom, outerArcRadius, 1);
        drawCorner(canvas, cornerPaint, path, inset.left, inset.top, outerArcRadius, 2);
        drawCorner(canvas, cornerPaint, path, inset.right, inset.top, outerArcRadius, 3);
    } finally {
        canvas.restoreToCount(saved);
    }
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF) LinearGradient(android.graphics.LinearGradient) Rect(android.graphics.Rect) RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 38 with RadialGradient

use of android.graphics.RadialGradient in project QLibrary by DragonsQC.

the class ResourceUtils method addRoundeBitmapWhiteBorder.

/**
     * 给 圆形图 添加 白色边框
     *
     * @param bitmap
     * @return
     */
public static Bitmap addRoundeBitmapWhiteBorder(Bitmap bitmap) {
    int size = bitmap.getWidth() < bitmap.getHeight() ? bitmap.getWidth() : bitmap.getHeight();
    int num = 14;
    int sizebig = size + num;
    Bitmap output = Bitmap.createBitmap(sizebig, sizebig, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);
    final int color = Color.parseColor("#FFFFFF");
    final Paint paint = new Paint();
    final float roundPx = sizebig / 2;
    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    canvas.drawBitmap(bitmap, num / 2, num / 2, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));
    RadialGradient gradient = new RadialGradient(roundPx, roundPx, roundPx, new int[] { Color.WHITE, Color.WHITE, Color.parseColor("#AAAAAAAA") }, new float[] { 0.f, 0.97f, 1.0f }, Shader.TileMode.CLAMP);
    paint.setShader(gradient);
    canvas.drawCircle(roundPx, roundPx, roundPx, paint);
    return output;
}
Also used : Bitmap(android.graphics.Bitmap) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Canvas(android.graphics.Canvas) RadialGradient(android.graphics.RadialGradient) Paint(android.graphics.Paint) Paint(android.graphics.Paint)

Example 39 with RadialGradient

use of android.graphics.RadialGradient in project XobotOS by xamarin.

the class GradientDrawable method ensureValidRect.

/**
     * This checks mRectIsDirty, and if it is true, recomputes both our drawing
     * rectangle (mRect) and the gradient itself, since it depends on our
     * rectangle too.
     * @return true if the resulting rectangle is not empty, false otherwise
     */
private boolean ensureValidRect() {
    if (mRectIsDirty) {
        mRectIsDirty = false;
        Rect bounds = getBounds();
        float inset = 0;
        if (mStrokePaint != null) {
            inset = mStrokePaint.getStrokeWidth() * 0.5f;
        }
        final GradientState st = mGradientState;
        mRect.set(bounds.left + inset, bounds.top + inset, bounds.right - inset, bounds.bottom - inset);
        final int[] colors = st.mColors;
        if (colors != null) {
            RectF r = mRect;
            float x0, x1, y0, y1;
            if (st.mGradient == LINEAR_GRADIENT) {
                final float level = st.mUseLevel ? (float) getLevel() / 10000.0f : 1.0f;
                switch(st.mOrientation) {
                    case TOP_BOTTOM:
                        x0 = r.left;
                        y0 = r.top;
                        x1 = x0;
                        y1 = level * r.bottom;
                        break;
                    case TR_BL:
                        x0 = r.right;
                        y0 = r.top;
                        x1 = level * r.left;
                        y1 = level * r.bottom;
                        break;
                    case RIGHT_LEFT:
                        x0 = r.right;
                        y0 = r.top;
                        x1 = level * r.left;
                        y1 = y0;
                        break;
                    case BR_TL:
                        x0 = r.right;
                        y0 = r.bottom;
                        x1 = level * r.left;
                        y1 = level * r.top;
                        break;
                    case BOTTOM_TOP:
                        x0 = r.left;
                        y0 = r.bottom;
                        x1 = x0;
                        y1 = level * r.top;
                        break;
                    case BL_TR:
                        x0 = r.left;
                        y0 = r.bottom;
                        x1 = level * r.right;
                        y1 = level * r.top;
                        break;
                    case LEFT_RIGHT:
                        x0 = r.left;
                        y0 = r.top;
                        x1 = level * r.right;
                        y1 = y0;
                        break;
                    default:
                        /* TL_BR */
                        x0 = r.left;
                        y0 = r.top;
                        x1 = level * r.right;
                        y1 = level * r.bottom;
                        break;
                }
                mFillPaint.setShader(new LinearGradient(x0, y0, x1, y1, colors, st.mPositions, Shader.TileMode.CLAMP));
            } else if (st.mGradient == RADIAL_GRADIENT) {
                x0 = r.left + (r.right - r.left) * st.mCenterX;
                y0 = r.top + (r.bottom - r.top) * st.mCenterY;
                final float level = st.mUseLevel ? (float) getLevel() / 10000.0f : 1.0f;
                mFillPaint.setShader(new RadialGradient(x0, y0, level * st.mGradientRadius, colors, null, Shader.TileMode.CLAMP));
            } else if (st.mGradient == SWEEP_GRADIENT) {
                x0 = r.left + (r.right - r.left) * st.mCenterX;
                y0 = r.top + (r.bottom - r.top) * st.mCenterY;
                int[] tempColors = colors;
                float[] tempPositions = null;
                if (st.mUseLevel) {
                    tempColors = st.mTempColors;
                    final int length = colors.length;
                    if (tempColors == null || tempColors.length != length + 1) {
                        tempColors = st.mTempColors = new int[length + 1];
                    }
                    System.arraycopy(colors, 0, tempColors, 0, length);
                    tempColors[length] = colors[length - 1];
                    tempPositions = st.mTempPositions;
                    final float fraction = 1.0f / (float) (length - 1);
                    if (tempPositions == null || tempPositions.length != length + 1) {
                        tempPositions = st.mTempPositions = new float[length + 1];
                    }
                    final float level = (float) getLevel() / 10000.0f;
                    for (int i = 0; i < length; i++) {
                        tempPositions[i] = i * fraction * level;
                    }
                    tempPositions[length] = 1.0f;
                }
                mFillPaint.setShader(new SweepGradient(x0, y0, tempColors, tempPositions));
            }
        }
    }
    return !mRect.isEmpty();
}
Also used : RectF(android.graphics.RectF) LinearGradient(android.graphics.LinearGradient) Rect(android.graphics.Rect) RadialGradient(android.graphics.RadialGradient) SweepGradient(android.graphics.SweepGradient) Paint(android.graphics.Paint)

Example 40 with RadialGradient

use of android.graphics.RadialGradient in project AisenWeiBo by wangdan.

the class ColorPicker method createColorWheelBitmap.

private Bitmap createColorWheelBitmap(int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    int colorCount = 12;
    int colorAngleStep = 360 / 12;
    int[] colors = new int[colorCount + 1];
    float[] hsv = new float[] { 0f, 1f, 1f };
    for (int i = 0; i < colors.length; i++) {
        hsv[0] = (i * colorAngleStep + 180) % 360;
        colors[i] = Color.HSVToColor(hsv);
    }
    colors[colorCount] = colors[0];
    SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
    RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
    ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);
    colorWheelPaint.setShader(composeShader);
    Canvas canvas = new Canvas(bitmap);
    canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) ComposeShader(android.graphics.ComposeShader) Canvas(android.graphics.Canvas) RadialGradient(android.graphics.RadialGradient) SweepGradient(android.graphics.SweepGradient) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Aggregations

RadialGradient (android.graphics.RadialGradient)49 LinearGradient (android.graphics.LinearGradient)27 Paint (android.graphics.Paint)23 RectF (android.graphics.RectF)21 Path (android.graphics.Path)15 SweepGradient (android.graphics.SweepGradient)14 Rect (android.graphics.Rect)12 Canvas (android.graphics.Canvas)6 Bitmap (android.graphics.Bitmap)4 ComposeShader (android.graphics.ComposeShader)4 Matrix (android.graphics.Matrix)4 SuppressLint (android.annotation.SuppressLint)2 PorterDuffXfermode (android.graphics.PorterDuffXfermode)2 Shader (android.graphics.Shader)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ColorMatrix (android.graphics.ColorMatrix)1 ArrayList (java.util.ArrayList)1 Point (org.achartengine.model.Point)1 SimpleSeriesRenderer (org.achartengine.renderer.SimpleSeriesRenderer)1