Java 类android.graphics.RadialGradient 实例源码

项目:LaunchEnr    文件:FolderIcon.java   
public void setup(DisplayMetrics dm, DeviceProfile grid, View invalidateDelegate,
           int availableSpace, int topPadding) {
    mInvalidateDelegate = invalidateDelegate;

    final int previewSize = grid.folderIconSizePx;
    final int previewPadding = grid.folderIconPreviewPadding;

    this.previewSize = (previewSize - 2 * previewPadding);

    basePreviewOffsetX = (availableSpace - this.previewSize) / 2;
    basePreviewOffsetY = previewPadding + grid.folderBackgroundOffset + topPadding;

    // Stroke width is 1dp
    mStrokeWidth = dm.density;

    float radius = getScaledRadius();
    float shadowRadius = radius + mStrokeWidth;
    int shadowColor = Color.argb(SHADOW_OPACITY, 0, 0, 0);
    mShadowShader = new RadialGradient(0, 0, 1,
            new int[] {shadowColor, Color.TRANSPARENT},
            new float[] {radius / shadowRadius, 1},
            Shader.TileMode.CLAMP);

    invalidate();
}
项目:CodeScaner    文件:ViewfinderView.java   
private void drawScanLine(Canvas canvas, Rect frame) {
    Shader shader = new RadialGradient(
            (float)(frame.left + frame.width() / 2),
            (float)(scannerStart + SCANNER_LINE_HEIGHT / 2),
            360f,
            laserColor,
            shadeColor(laserColor),
            Shader.TileMode.MIRROR);
    paint.setAlpha(CURRENT_POINT_OPACITY);
    paint.setShader(shader);
    if (scannerStart <= scannerEnd) {
        canvas.drawRect(frame.left, scannerStart, frame.right, scannerStart + SCANNER_LINE_HEIGHT, paint);
        scannerStart += SCANNER_LINE_MOVE_DISTANCE;
    } else {
        scannerStart = frame.top;
    }
    paint.setShader(null);
}
项目:airgram    文件:ColorPicker.java   
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;

    }
项目:airgram    文件:MultiColorPicker.java   
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;

    }
项目:planetcon    文件:ColorPicker.java   
private Bitmap createColorDiscBitmap(int radius) {
    int centerColor, edgeColor;
    Bitmap bitmap = Bitmap.createBitmap(2 * radius, 2 * radius, Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    mHSV[0] = 0; mHSV[1] = 1; mHSV[2] = 1;   //red
    SweepGradient sweepGradient = new SweepGradient(radius, radius, getColors(mHSV), null);
    mColorPaint.setShader(sweepGradient);
    canvas.drawCircle(radius, radius, radius, mColorPaint);

    mHSV[0] = 0; mHSV[1] = 0; mHSV[2] = 1;   //white
    centerColor = Color.HSVToColor(255, mHSV);
    edgeColor = Color.HSVToColor(0, mHSV);
    RadialGradient radialGradient = new RadialGradient(radius, radius, radius, centerColor, edgeColor, TileMode.CLAMP);
    mColorPaint.setShader(radialGradient);
    canvas.drawCircle(radius, radius, radius, mColorPaint);

    return bitmap;
}
项目:AndroidButtonLib    文件:SlideButton.java   
private void startLightAnimation() {

        if (mLightAnimation == null) {

            mLightAnimation = ObjectAnimator.ofFloat(10, getMeasuredWidth());
            mLightAnimation.setRepeatCount(ValueAnimator.INFINITE);
            mLightAnimation.setDuration(3000);
            mLightAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float lightMove = (float) animation.getAnimatedValue();
                    if (Math.abs(lightMove) < getMeasuredWidth()) {
                        mShader = new RadialGradient(lightMove, getMeasuredHeight() / 2, 90f
                                , new int[]{Color.WHITE, mBackgroudColor}, null, Shader.TileMode.CLAMP);
                        postInvalidate();
                    }

                }
            });
        }

        if (mLightAnimation != null && !mLightAnimation.isRunning()) {
            mLightAnimation.start();
        }

    }
项目:buildAPKsApps    文件:ColorPicker.java   
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;

    }
项目:buildAPKsApps    文件:MultiColorPicker.java   
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;

    }
项目:buildAPKsSamples    文件:BouncingBalls.java   
private ShapeHolder addBall(float x, float y) {
    OvalShape circle = new OvalShape();
    circle.resize(50f, 50f);
    ShapeDrawable drawable = new ShapeDrawable(circle);
    ShapeHolder shapeHolder = new ShapeHolder(drawable);
    shapeHolder.setX(x - 25f);
    shapeHolder.setY(y - 25f);
    int red = (int)(Math.random() * 255);
    int green = (int)(Math.random() * 255);
    int blue = (int)(Math.random() * 255);
    int color = 0xff000000 | red << 16 | green << 8 | blue;
    Paint paint = drawable.getPaint(); //new Paint(Paint.ANTI_ALIAS_FLAG);
    int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;
    RadialGradient gradient = new RadialGradient(37.5f, 12.5f,
            50f, color, darkColor, Shader.TileMode.CLAMP);
    paint.setShader(gradient);
    shapeHolder.setPaint(paint);
    balls.add(shapeHolder);
    return shapeHolder;
}
项目:iosched-reader    文件:SVGParser.java   
private void finishGradients() {
    for(Gradient gradient : gradientMap.values()) {
        if (gradient.xlink != null) {
            Gradient parent = gradientMap.get(gradient.xlink);
            if (parent != null) {
                gradient.inherit(parent);
            }
        }
        int[] colors = new int[gradient.colors.size()];
        for (int i = 0; i < colors.length; i++) {
            colors[i] = gradient.colors.get(i);
        }
        float[] positions = new float[gradient.positions.size()];
        for (int i = 0; i < positions.length; i++) {
            positions[i] = gradient.positions.get(i);
        }
        if (colors.length == 0) {
            Log.d("BAD", "BAD gradient, id="+gradient.id);
        }
        if (gradient.isLinear) {
            gradient.shader= new LinearGradient(gradient.x1, gradient.y1, gradient.x2, gradient.y2, colors, positions, gradient.tilemode);
        } else {
            gradient.shader= new RadialGradient(gradient.x, gradient.y, gradient.radius, colors, positions, gradient.tilemode);
        }
    }
}
项目:Review-    文件:RangeSliderViewEx.java   
@AnimateMethod
public void setRadius(final float radius) {
    rippleRadius = radius;
    if (rippleRadius > 0) {
        RadialGradient radialGradient = new RadialGradient(
                downX,
                downY,
                rippleRadius * 3,
                Color.TRANSPARENT,
                Color.BLACK,
                Shader.TileMode.MIRROR
        );
        ripplePaint.setShader(radialGradient);
    }
    invalidate();
}
项目:ClassifyView    文件:BagDrawable.java   
@Override
    public void draw(Canvas canvas) {
        if (keepShow||inMerge) {
        canvas.save();
        canvas.clipRect(getBounds());
        mRectF.set(getBounds());

        mRectF.inset(mOutlinePadding, mOutlinePadding);
        if (mOutLineWidth > 0) {
            mOutlinePaint.setStrokeWidth(mOutLineWidth);
            mRectF.inset(mOutLineWidth, mOutLineWidth);
            mOutlinePaint.setColor(mOutLineColor);
            canvas.drawRoundRect(mRectF, mRadius, mRadius, mOutlinePaint);
        }
//            mPaint.setShader(new SweepGradient(mRectF.centerX(),mRectF.centerY(),mColors,mPositions));
        mPaint.setShader(new RadialGradient(mRectF.centerX(), mRectF.centerY(), mRectF.width(), mCenterColor, mEdgeColor, Shader.TileMode.CLAMP));
        canvas.drawRoundRect(mRectF, mRadius, mRadius, mPaint);
        canvas.restore();
        }
    }
项目:BLE-Indoor-Positioning    文件:BeaconMap.java   
protected void drawBeaconBackground(Canvas canvas, Beacon beacon, PointF beaconCenter) {
    float advertisingRadius = (float) canvasProjection.getCanvasUnitsFromMeters(beacon.getEstimatedAdvertisingRange());

    Paint innerBeaconRangePaint = new Paint(beaconRangePaint);
    innerBeaconRangePaint.setAlpha(100);
    Shader rangeShader = new RadialGradient(
            beaconCenter.x,
            beaconCenter.y,
            advertisingRadius - (pixelsPerDip * 0),
            primaryFillPaint.getColor(), beaconRangePaint.getColor(),
            Shader.TileMode.MIRROR);

    innerBeaconRangePaint.setShader(rangeShader);
    //canvas.drawCircle(beaconCenter.x, beaconCenter.y, advertisingRadius, innerBeaconRangePaint);
    canvas.drawCircle(beaconCenter.x, beaconCenter.y, advertisingRadius, beaconRangePaint);
}
项目:boohee_v5.6    文件:RoundRectDrawableWithShadow.java   
private void buildShadowCorners() {
    RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
    if (this.mCornerShadowPath == null) {
        this.mCornerShadowPath = new Path();
    } else {
        this.mCornerShadowPath.reset();
    }
    this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
    this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
    this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
    this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
    this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
    this.mCornerShadowPath.close();
    float startRatio = this.mCornerRadius / (this.mCornerRadius + this.mShadowSize);
    this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, this.mCornerRadius + this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, (-this.mCornerRadius) + this.mShadowSize, 0.0f, (-this.mCornerRadius) - this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, 0.5f, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setAntiAlias(false);
}
项目:boohee_v5.6    文件:ShadowDrawableWrapper.java   
private void buildShadowCorners() {
    RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
    if (this.mCornerShadowPath == null) {
        this.mCornerShadowPath = new Path();
    } else {
        this.mCornerShadowPath.reset();
    }
    this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
    this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
    this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
    this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
    this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
    this.mCornerShadowPath.close();
    float shadowRadius = -outerBounds.top;
    if (shadowRadius > 0.0f) {
        float startRatio = this.mCornerRadius / shadowRadius;
        float midRatio = startRatio + ((1.0f - startRatio) / 2.0f);
        this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, shadowRadius, new int[]{0, this.mShadowStartColor, this.mShadowMiddleColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, midRatio, 1.0f}, TileMode.CLAMP));
    }
    this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, innerBounds.top, 0.0f, outerBounds.top, new int[]{this.mShadowStartColor, this.mShadowMiddleColor, this.mShadowEndColor}, new float[]{0.0f, SHADOW_HORIZ_SCALE, 1.0f}, TileMode.CLAMP));
    this.mEdgeShadowPaint.setAntiAlias(false);
}
项目:ZxingScan    文件:ViewfinderView.java   
/**
 * 绘制移动扫描线
 * @param canvas
 * @param frame
 */
private void drawLaserScanner(Canvas canvas, Rect frame) {
     linePaint.setColor(laserColor);
     radialGradient = new RadialGradient(
            (float)(frame.left + frame.width() / 2),
            (float)(scannerStart + SCANNER_LINE_HEIGHT / 2),
            360f,
            laserColor,
            shadeColor(laserColor),
            Shader.TileMode.MIRROR);
    linePaint.setShader(radialGradient);
    if(scannerStart < scannerEnd) {
        rectF.set(frame.left + 2 * SCANNER_LINE_HEIGHT,
                scannerStart, frame.right - 2 * SCANNER_LINE_HEIGHT,
                scannerStart + SCANNER_LINE_HEIGHT);
        canvas.drawOval(rectF, linePaint);
        scannerStart += SCANNER_LINE_MOVE_DISTANCE;
    } else {
        scannerStart = frame.top;
    }
    linePaint.setShader(null);
    radialGradient=null;
}
项目:controllerformote-android    文件:ColorPicker.java   
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;

    }
项目:BlendedBackground    文件:Gradient.java   
private ShapeDrawable.ShaderFactory createShaderFactory() {
    return new ShapeDrawable.ShaderFactory() {
        @Override
        public Shader resize(int width, int height) {
            switch (type) {
                case RADIAL:
                    return new RadialGradient(parentWidth / 2,
                            parentHeight / 2, getParentRadius(),
                            upper, lower,
                            Shader.TileMode.CLAMP);

                case LINEAR:
                default:
                    return new LinearGradient(0, 0,
                            0, parentHeight,
                            upper, lower,
                            Shader.TileMode.CLAMP);
            }
        }
    };
}
项目:px-android    文件:ColorPicker.java   
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;

    }
项目:smconf-android    文件:SVGParser.java   
private void finishGradients() {
    for(Gradient gradient : gradientMap.values()) {
        if (gradient.xlink != null) {
            Gradient parent = gradientMap.get(gradient.xlink);
            if (parent != null) {
                gradient.inherit(parent);
            }
        }
        int[] colors = new int[gradient.colors.size()];
        for (int i = 0; i < colors.length; i++) {
            colors[i] = gradient.colors.get(i);
        }
        float[] positions = new float[gradient.positions.size()];
        for (int i = 0; i < positions.length; i++) {
            positions[i] = gradient.positions.get(i);
        }
        if (colors.length == 0) {
            Log.d("BAD", "BAD gradient, id="+gradient.id);
        }
        if (gradient.isLinear) {
            gradient.shader= new LinearGradient(gradient.x1, gradient.y1, gradient.x2, gradient.y2, colors, positions, gradient.tilemode);
        } else {
            gradient.shader= new RadialGradient(gradient.x, gradient.y, gradient.radius, colors, positions, gradient.tilemode);
        }
    }
}
项目:BLE_Toolbox_Android    文件:ColorPicker.java   
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;

    }
项目:BB8    文件:JoystickPuck.java   
@Override
public void draw(Canvas canvas) {

    RadialGradient gradient = new RadialGradient(
            this.position.x,
            this.position.y,
            this.radius,
            this.color_0,
            this.color_1,
            Shader.TileMode.MIRROR
    );

    this.paint.setShader(gradient);

    canvas.drawCircle(this.position.x, this.position.y, this.radius, this.paint);
}
项目:WebCards    文件:DismissAreaView.java   
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    backgroundPaint.setShader(new RadialGradient(w, h, h, Color.BLACK, Color.TRANSPARENT, Shader.TileMode.MIRROR));

    indicatorRect =  new Rect(
            w - indicatorSize - indicatorMargin,
            h - indicatorSize - indicatorMargin,
            w - indicatorMargin,
            h - indicatorMargin);

    final int centerX = w - indicatorMargin - (indicatorSize / 2);
    final int centerY = h - indicatorMargin - (indicatorSize / 2);

    final int left = centerX - (crossSize / 2);
    final int top = centerY - (crossSize / 2);
    final int right = centerX + (crossSize / 2);
    final int bottom = centerY + (crossSize / 2);

    crossLines = new float[] {
            left, top, right, bottom,
            right, top, left, bottom
    };
}
项目:FingerColoring-Android    文件:ColorPicker.java   
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;

    }
项目:UofT-Timetable    文件:ColorPicker.java   
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;

    }
项目:2015-Google-I-O-app    文件:SVGParser.java   
private void finishGradients() {
    for(Gradient gradient : gradientMap.values()) {
        if (gradient.xlink != null) {
            Gradient parent = gradientMap.get(gradient.xlink);
            if (parent != null) {
                gradient.inherit(parent);
            }
        }
        int[] colors = new int[gradient.colors.size()];
        for (int i = 0; i < colors.length; i++) {
            colors[i] = gradient.colors.get(i);
        }
        float[] positions = new float[gradient.positions.size()];
        for (int i = 0; i < positions.length; i++) {
            positions[i] = gradient.positions.get(i);
        }
        if (colors.length == 0) {
            Log.d("BAD", "BAD gradient, id="+gradient.id);
        }
        if (gradient.isLinear) {
            gradient.shader= new LinearGradient(gradient.x1, gradient.y1, gradient.x2, gradient.y2, colors, positions, gradient.tilemode);
        } else {
            gradient.shader= new RadialGradient(gradient.x, gradient.y, gradient.radius, colors, positions, gradient.tilemode);
        }
    }
}
项目:iOffice    文件:RadialGradientShader.java   
public Shader createShader(IControl control, int viewIndex, Rect rect)
  {
int[] coordinate = getCircleCoordinate();
if(positionType == Center_Center && getFocus() == 0)
{
    int size = colors.length;
    int nTem = 0;
    for(int i = 0; i < size / 2; i++)
    {
        nTem = colors[i];
        colors[i] = colors[size - 1 - i];
        colors[size - 1 - i] = nTem;
    }
}
    shader = new RadialGradient(coordinate[0], coordinate[1], coordinate[2],
            colors, positions, Shader.TileMode.REPEAT);
    return shader;
  }
项目:FlyoutMenus    文件:FlyoutMenuView.java   
Bitmap createButtonShadowBitmap() {
    int shadowRadius = (int) buttonElevation * 2;
    int bitmapRadius = buttonRadius + (shadowRadius / 2);
    int bitmapSize = bitmapRadius * 2;
    Bitmap shadowBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888);
    shadowBitmap.eraseColor(0x0);

    int colors[] = {
            ColorUtils.setAlphaComponent(SHADOW_COLOR, SHADOW_ALPHA),
            ColorUtils.setAlphaComponent(SHADOW_COLOR, 0)
    };

    float stops[] = {
            (float) (buttonRadius - (shadowRadius / 2)) / (float) bitmapRadius,
            1f
    };

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new RadialGradient(bitmapRadius, bitmapRadius, bitmapRadius, colors, stops, Shader.TileMode.CLAMP));

    Canvas canvas = new Canvas(shadowBitmap);
    canvas.drawRect(0, 0, bitmapSize, bitmapSize, paint);

    return shadowBitmap;
}
项目:FlyoutMenus    文件:FlyoutMenuView.java   
Bitmap createMenuShadowBitmap() {
    menuShadowRadius = (int) flyoutMenuView.menuElevation * 2;
    menuShadowInset = menuShadowRadius / 2;
    int size = 2 * menuShadowRadius + 1;
    Bitmap shadowBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    shadowBitmap.eraseColor(0x0); // clear

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setShader(new RadialGradient(
            menuShadowRadius + 1,
            menuShadowRadius + 1,
            menuShadowRadius,
            ColorUtils.setAlphaComponent(SHADOW_COLOR, SHADOW_ALPHA),
            ColorUtils.setAlphaComponent(SHADOW_COLOR, 0),
            Shader.TileMode.CLAMP));

    Canvas canvas = new Canvas(shadowBitmap);
    canvas.drawRect(0, 0, size, size, paint);

    return shadowBitmap;
}
项目:AyoSunny    文件:ColorPicker.java   
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;

    }
项目:AndroidReview    文件:RangeSliderViewEx.java   
@AnimateMethod
public void setRadius(final float radius) {
    rippleRadius = radius;
    if (rippleRadius > 0) {
        RadialGradient radialGradient = new RadialGradient(
                downX,
                downY,
                rippleRadius * 3,
                Color.TRANSPARENT,
                Color.BLACK,
                Shader.TileMode.MIRROR
        );
        ripplePaint.setShader(radialGradient);
    }
    invalidate();
}
项目:EspLight-APP    文件:ColorPicker.java   
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;

    }
项目:Domo-Android    文件:MultiColorPicker.java   
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;

    }
项目:minimalist-flashlight    文件:OldIconDrawable.java   
public void updateSize(int size) {
  mSize = size > 0 ? size : 100;
  createPath(size);

  mRadius = mSize * (0.8f / 2f);
  mShadowRadius = mSize * (0.95f / 2);

  float startRatio = mRadius / mShadowRadius;
  float midRatio = startRatio + ((1f - startRatio) / 2f);

  mShadow = new RadialGradient(mSize / 2, mSize / 2, mShadowRadius,
      new int[]{0, 0x44000000, 0x14000000, 0},
      new float[]{0f, startRatio, midRatio, 1f},
      Shader.TileMode.CLAMP);
  mLightShadow = new RadialGradient(mSize / 2, mSize / 2, mShadowRadius,
      new int[]{0, 0x6433b5e5, 0x1433b5e5, 0},
      new float[]{0f, startRatio, midRatio, 1f},
      Shader.TileMode.CLAMP);
}
项目:FMTech    文件:SVGParser.java   
private void finishGradients() {
    for(Gradient gradient : gradientMap.values()) {
        if (gradient.xlink != null) {
            Gradient parent = gradientMap.get(gradient.xlink);
            if (parent != null) {
                gradient.inherit(parent);
            }
        }
        int[] colors = new int[gradient.colors.size()];
        for (int i = 0; i < colors.length; i++) {
            colors[i] = gradient.colors.get(i);
        }
        float[] positions = new float[gradient.positions.size()];
        for (int i = 0; i < positions.length; i++) {
            positions[i] = gradient.positions.get(i);
        }
        if (colors.length == 0) {
            Log.d("BAD", "BAD gradient, id="+gradient.id);
        }
        if (gradient.isLinear) {
            gradient.shader= new LinearGradient(gradient.x1, gradient.y1, gradient.x2, gradient.y2, colors, positions, gradient.tilemode);
        } else {
            gradient.shader= new RadialGradient(gradient.x, gradient.y, gradient.radius, colors, positions, gradient.tilemode);
        }
    }
}
项目:CodenameOne    文件:AndroidGraphics.java   
public void fillRectRadialGradient(int startColor, int endColor, int x, int y, int width, int height, float relativeX, float relativeY, float relativeSize) {
    boolean antialias = paint.isAntiAlias();
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(false);
    paint.setAlpha(255);
    float radius = Math.min((float)width, (float)height) * relativeSize;
    int centerX = (int) (width * (1 - relativeX));
    int centerY = (int) (height * (1 - relativeY));

    paint.setShader(new RadialGradient(x + centerX, y + centerY, radius, 0xff000000 | startColor, 0xff000000 | endColor, Shader.TileMode.MIRROR));
    canvas.save();
    applyTransform();
    canvas.drawRect(x, y, x + width, y + height, paint);
    paint.setAntiAlias(antialias);
    paint.setShader(null);
    unapplyTransform();
    canvas.restore();
}
项目:ApiDemos    文件:AnimationCloning.java   
private ShapeHolder addBall(float x, float y) {
    OvalShape circle = new OvalShape();
    circle.resize(50f * mDensity, 50f * mDensity);
    ShapeDrawable drawable = new ShapeDrawable(circle);
    ShapeHolder shapeHolder = new ShapeHolder(drawable);
    shapeHolder.setX(x - 25f);
    shapeHolder.setY(y - 25f);
    int red = (int)(100 + Math.random() * 155);
    int green = (int)(100 + Math.random() * 155);
    int blue = (int)(100 + Math.random() * 155);
    int color = 0xff000000 | red << 16 | green << 8 | blue;
    Paint paint = drawable.getPaint(); //new Paint(Paint.ANTI_ALIAS_FLAG);
    int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;
    RadialGradient gradient = new RadialGradient(37.5f, 12.5f,
            50f, color, darkColor, Shader.TileMode.CLAMP);
    paint.setShader(gradient);
    shapeHolder.setPaint(paint);
    balls.add(shapeHolder);
    return shapeHolder;
}
项目:AndroidCourses    文件:RadialGradientFillBitmapTextureAtlasSourceDecorator.java   
public RadialGradientFillBitmapTextureAtlasSourceDecorator(final IBitmapTextureAtlasSource pBitmapTextureAtlasSource, final IBitmapTextureAtlasSourceDecoratorShape pBitmapTextureAtlasSourceDecoratorShape, final int[] pColors, final float[] pPositions, final RadialGradientDirection pRadialGradientDirection, final TextureAtlasSourceDecoratorOptions pTextureAtlasSourceDecoratorOptions) {
    super(pBitmapTextureAtlasSource, pBitmapTextureAtlasSourceDecoratorShape, pTextureAtlasSourceDecoratorOptions);
    this.mColors = pColors;
    this.mPositions = pPositions;
    this.mRadialGradientDirection = pRadialGradientDirection;

    this.mPaint.setStyle(Style.FILL);

    final int width = pBitmapTextureAtlasSource.getTextureWidth();
    final int height = pBitmapTextureAtlasSource.getTextureHeight();

    final float centerX = width * 0.5f;
    final float centerY = height * 0.5f;

    final float radius = Math.max(centerX, centerY);

    switch (pRadialGradientDirection) {
        case INSIDE_OUT:
            this.mPaint.setShader(new RadialGradient(centerX, centerY, radius, pColors, pPositions, TileMode.CLAMP));
            break;
        case OUTSIDE_IN:
            ArrayUtils.reverse(pColors);
            this.mPaint.setShader(new RadialGradient(centerX, centerY, radius, pColors, pPositions, TileMode.CLAMP));
            break;
    }
}
项目:MyCTFWriteUps    文件:CircleImageView.java   
public OvalShadow(int i, int j)
{
    this$0 = CircleImageView.this;
    super();
    mShadowPaint = new Paint();
    mShadowRadius = i;
    mCircleDiameter = j;
    float f = mCircleDiameter / 2;
    float f1 = mCircleDiameter / 2;
    float f2 = mShadowRadius;
    circleimageview = android.graphics.Shader.TileMode.CLAMP;
    mRadialGradient = new RadialGradient(f, f1, f2, new int[] {
        0x3d000000, 0
    }, null, CircleImageView.this);
    mShadowPaint.setShader(mRadialGradient);
}
项目:ApiDemos    文件:CustomEvaluator.java   
private ShapeHolder createBall(float x, float y) {
    OvalShape circle = new OvalShape();
    circle.resize(50f, 50f);
    ShapeDrawable drawable = new ShapeDrawable(circle);
    ShapeHolder shapeHolder = new ShapeHolder(drawable);
    shapeHolder.setX(x - 25f);
    shapeHolder.setY(y - 25f);
    int red = (int)(Math.random() * 255);
    int green = (int)(Math.random() * 255);
    int blue = (int)(Math.random() * 255);
    int color = 0xff000000 | red << 16 | green << 8 | blue;
    Paint paint = drawable.getPaint(); //new Paint(Paint.ANTI_ALIAS_FLAG);
    int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;
    RadialGradient gradient = new RadialGradient(37.5f, 12.5f,
            50f, color, darkColor, Shader.TileMode.CLAMP);
    paint.setShader(gradient);
    shapeHolder.setPaint(paint);
    return shapeHolder;
}