android.graphics.SweepGradient Java Examples

The following examples show how to use android.graphics.SweepGradient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeviceSeekArc.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
private Paint getHiliteStrokePaint(float startAngle, float endAngle, RectF seekArcBounds, int strokeWidth) {
    // Create the gradient shader
    int[] colors = {startColor, startColor, endColor, endColor};
    float[] positions = {0, startAngle / 360f, endAngle / 360f, 1};
    SweepGradient gradient = new SweepGradient(seekArcBounds.left + seekArcBounds.width() / 2, seekArcBounds.top + seekArcBounds.height() / 2, colors , positions);

    // Rotate to match the orientation of the seek arc
    Matrix theMatrix = new Matrix();
    theMatrix.setRotate(90, seekArcBounds.left + seekArcBounds.width() / 2, seekArcBounds.top + seekArcBounds.height() / 2);
    gradient.setLocalMatrix(theMatrix);

    // Create the paint
    Paint p = new Paint();
    p.setStrokeWidth(strokeWidth);
    p.setShader(gradient);
    p.setAntiAlias(true);
    p.setStyle(Paint.Style.STROKE);

    return p;
}
 
Example #2
Source File: ColorPicker.java    From px-android with MIT License 6 votes vote down vote up
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[] = { 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;
    }
 
Example #3
Source File: ThemeEditorView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    int colorCount = 12;
    int colorAngleStep = 360 / 12;
    int[] colors = new int[colorCount + 1];
    float[] hsv = new float[]{0.0f, 1.0f, 1.0f};
    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, Shader.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;
}
 
Example #4
Source File: ColorPickerDialog.java    From AndroidDrawing with MIT License 6 votes vote down vote up
ColorPickerView(Context c, OnColorChangedListener l, int color) {
    super(c);
    mListener = l;
    mColors = new int[]{
            0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00,
            0xFFFFFF00, 0xFFFF0000
    };
    Shader s = new SweepGradient(0, 0, mColors, null);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setShader(s);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(32);

    mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCenterPaint.setColor(color);
    mCenterPaint.setStrokeWidth(5);
}
 
Example #5
Source File: ColorPicker.java    From Android-Color-Picker with Apache License 2.0 6 votes vote down vote up
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;

    }
 
Example #6
Source File: SweepGradientRadarView.java    From AndroidDigIn with Apache License 2.0 6 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    mCx = w / 2;
    mCy = h / 2;
    mSweepGradient = new SweepGradient(mCx, mCy,
            new int[]{Color.argb(25, 0, 255, 0),
                    Color.argb(80, 0, 255, 0),
                    Color.argb(200, 0, 255, 0)},
            new float[]{0, 0.95f, 1.0f});
    mPaint = new Paint();
    mPaint.setShader(mSweepGradient);
    mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCircleDividerColor = Color.BLACK;
    mCrossDividerColor = Color.WHITE;
    mRadarBgColor = Color.rgb(154, 154, 154);
    mDividerPaint.setColor(mCircleDividerColor);
    mDividerPaint.setStrokeWidth(3);
    mDividerPaint.setStyle(Paint.Style.STROKE);
}
 
Example #7
Source File: MultiColorPicker.java    From Android-Color-Picker with Apache License 2.0 6 votes vote down vote up
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;

    }
 
Example #8
Source File: CircleProgressBar.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制载入
 *
 * @param canvas 画布
 */
protected void drawLoading(Canvas canvas) {
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(mProgressSize);
    final float halfCircleSize = mProgressSize * 0.5f;
    SweepGradient sweepGradient = new SweepGradient(0, 0, mGradientColors, mGradientPositions);
    mRotateMatrix.setRotate(mStartAngle - mLoadingStartAngle -
            mLoadingSweepAngle * mLoadingOffset, 0, 0);
    sweepGradient.setLocalMatrix(mRotateMatrix);
    mPaint.setShader(sweepGradient);
    canvas.save();
    canvas.rotate(mLoadingStartAngle);
    canvas.rotate(mLoadingSweepAngle * mLoadingOffset);
    canvas.drawPoint(mRadius - halfCircleSize, 0, mPaint);
    canvas.restore();
}
 
Example #9
Source File: ThemeEditorView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    int colorCount = 12;
    int colorAngleStep = 360 / 12;
    int colors[] = new int[colorCount + 1];
    float hsv[] = new float[] { 0.0f, 1.0f, 1.0f };
    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, Shader.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;
}
 
Example #10
Source File: CircleProgressBar.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
/**
 * 绘制进度
 *
 * @param canvas 画布
 */
protected void drawProgress(Canvas canvas) {
    if (mRadius == 0 || mProgressSize == 0 || mAnimatorProgress < 0)
        return;
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(mProgressSize);
    final float halfCircleSize = mProgressSize * 0.5f;
    mRectF.set(-mRadius + halfCircleSize, -mRadius + halfCircleSize,
            mRadius - halfCircleSize, mRadius - halfCircleSize);
    SweepGradient sweepGradient = new SweepGradient(0, 0, mGradientColors, mGradientPositions);
    mRotateMatrix.setRotate(mStartAngle, 0, 0);
    sweepGradient.setLocalMatrix(mRotateMatrix);
    mPaint.setShader(sweepGradient);
    canvas.save();
    canvas.drawArc(mRectF, mStartAngle, mAnimatorProgressAngle, false, mPaint);
    canvas.restore();
}
 
Example #11
Source File: OilTableLine.java    From OXChart with Apache License 2.0 6 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);
    float size = Math.min(w, h) - tableWidth * 2;
    //油表的位置方框
    mTableRectF = new RectF(0, 0, size, size);
    mPath.reset();
    //在油表路径中增加一个从起始弧度
    mPath.addArc(mTableRectF, 60, 240);
    //计算路径的长度
    PathMeasure pathMeasure = new PathMeasure(mPath, false);
    float length = pathMeasure.getLength();
    float step = length / 60;
    dashPathEffect = new DashPathEffect(new float[]{step / 3, step * 2 / 3}, 0);

    float radius = size / 2;
    mColorShader = new SweepGradient(radius, radius,SWEEP_GRADIENT_COLORS,null);
    //设置指针的路径位置
    mPointerPath.reset();
    mPointerPath.moveTo(radius, radius - 20);
    mPointerPath.lineTo(radius, radius + 20);
    mPointerPath.lineTo(radius * 2 - tableWidth, radius);
    mPointerPath.close();
}
 
Example #12
Source File: ColorPicker.java    From redalert-android with Apache License 2.0 6 votes vote down vote up
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;

    }
 
Example #13
Source File: ColorPicker.java    From SystemBarTint with Apache License 2.0 6 votes vote down vote up
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;

    }
 
Example #14
Source File: CircularSlider.java    From circular-slider-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
    // use smaller dimension for calculations (depends on parent size)
    int smallerDim = w > h ? h : w;

    // find circle's rectangle points
    int largestCenteredSquareLeft = (w - smallerDim) / 2;
    int largestCenteredSquareTop = (h - smallerDim) / 2;
    int largestCenteredSquareRight = largestCenteredSquareLeft + smallerDim;
    int largestCenteredSquareBottom = largestCenteredSquareTop + smallerDim;

    // save circle coordinates and radius in fields
    mCircleCenterX = largestCenteredSquareRight / 2 + (w - largestCenteredSquareRight) / 2;
    mCircleCenterY = largestCenteredSquareBottom / 2 + (h - largestCenteredSquareBottom) / 2;
    mCircleRadius = smallerDim / 2 - mBorderThickness / 2 - mPadding;

    if (mBorderGradientColors != null) {
        mGradientShader = new SweepGradient(mCircleRadius, mCircleRadius, mBorderGradientColors, null);
    }

    // works well for now, should we call something else here?
    super.onSizeChanged(w, h, oldW, oldH);
}
 
Example #15
Source File: ColorPicker.java    From Mi-Band with GNU General Public License v2.0 6 votes vote down vote up
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;

    }
 
Example #16
Source File: ThemeEditorView.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    int colorCount = 12;
    int colorAngleStep = 360 / 12;
    int[] colors = new int[colorCount + 1];
    float[] hsv = new float[]{0.0f, 1.0f, 1.0f};
    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, Shader.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;
}
 
Example #17
Source File: ColorPickerDialog.java    From geopaparazzi with GNU General Public License v3.0 6 votes vote down vote up
ColorPickerView(Context c, OnColorChangedListener l, int color) {
    super(c);
    mListener = l;
    mColors = new int[]{
            0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00,
            0xFFFFFF00, 0xFFFF0000
    };
    Shader s = new SweepGradient(0, 0, mColors, null);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setShader(s);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(32);

    mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mCenterPaint.setColor(color);
    mCenterPaint.setStrokeWidth(EasyPaint.DEFAULT_BRUSH_SIZE);
}
 
Example #18
Source File: ThemeEditorView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private Bitmap createColorWheelBitmap(int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    int colorCount = 12;
    int colorAngleStep = 360 / 12;
    int colors[] = new int[colorCount + 1];
    float hsv[] = new float[] { 0.0f, 1.0f, 1.0f };
    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, Shader.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;
}
 
Example #19
Source File: ColorPickerControl.java    From whiteboard with Apache License 2.0 5 votes vote down vote up
ColorPickerView(Context c, OnColorChangedListener listener, int color) {
	super(c);
	mListener = listener;
	mRadialColors = new int[] { 0xFFFF0000, 0xFFFF00FF, 0xFF0000FF,
			0xFF00FFFF, 0xFF00FF00, 0xFFFFFF00, 0xFFFF0000 };
	// ʵ������ɫ������
	Shader s = new SweepGradient(0, 0, mRadialColors, null);
	mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	// ���û��ʵ�ָ��ʰɫ��
	mPaint.setShader(s);
	// ���û�����ʽ
	mPaint.setStyle(Paint.Style.STROKE);
	// ���û��ʳߴ�
	mPaint.setStrokeWidth(32);
	
	mLinearColors = getColors(color);
	Shader shader = new LinearGradient(0, 0, Center_X * 2, 0,
			mLinearColors, null, Shader.TileMode.CLAMP);

	mGradientPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mGradientPaint.setStyle(Paint.Style.STROKE);
	mGradientPaint.setShader(shader);
	mGradientPaint.setStrokeWidth(32);

	mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mCenterPaint.setColor(color);
	mCenterPaint.setStrokeWidth(6);

	mRadialPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
	mRadialPaint.setColor(color);
	mRadialPaint.setStrokeWidth(6);
}
 
Example #20
Source File: RadarView.java    From rpi with Apache License 2.0 5 votes vote down vote up
private void initPaint() {
    // TODO Auto-generated method stub
    setBackgroundColor(Color.TRANSPARENT);

    //宽度=5,抗锯齿,描边效果的白色画笔
    mPaintLine = new Paint();
    mPaintLine.setStrokeWidth(5);
    mPaintLine.setAntiAlias(true);
    mPaintLine.setStyle(Paint.Style.STROKE);
    mPaintLine.setColor(Color.WHITE);

    //宽度=5,抗锯齿,描边效果的浅绿色画笔
    mPaintCircle = new Paint();
    mPaintCircle.setStrokeWidth(5);
    mPaintCircle.setAntiAlias(true);
    mPaintCircle.setStyle(Paint.Style.FILL);
    mPaintCircle.setColor(0x99000000);

    //暗绿色的画笔
    mPaintSector = new Paint();
    mPaintSector.setColor(0x9D00ff00);
    mPaintSector.setAntiAlias(true);
    mShader = new SweepGradient(viewSize / 2, viewSize / 2, Color.TRANSPARENT, Color.GREEN);
    mPaintSector.setShader(mShader);

    //白色实心画笔
    mPaintPoint=new Paint();
    mPaintPoint.setColor(Color.WHITE);
    mPaintPoint.setStyle(Paint.Style.FILL);

    //随机生成的点,模拟雷达扫描结果
    point_x = Utils.Getrandomarray(15, 300);
    point_y = Utils.Getrandomarray(15, 300);

}
 
Example #21
Source File: ArcSeekBar.java    From arc-seekbar with Apache License 2.0 5 votes vote down vote up
private void resetShaderColor() {
    // 计算渐变数组
    float startPos = (mOpenAngle / 2) / CIRCLE_ANGLE;
    float stopPos = (CIRCLE_ANGLE - (mOpenAngle / 2)) / CIRCLE_ANGLE;
    int len = mArcColors.length - 1;
    float distance = (stopPos - startPos) / len;
    float pos[] = new float[mArcColors.length];
    for (int i = 0; i < mArcColors.length; i++) {
        pos[i] = startPos + (distance * i);
    }
    SweepGradient gradient = new SweepGradient(mCenterX, mCenterY, mArcColors, pos);
    mArcPaint.setShader(gradient);
}
 
Example #22
Source File: SweepGradientView.java    From hyperion-android-grabber with MIT License 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    viewBounds.set(0, 0, getMeasuredWidth(), getMeasuredHeight());

    gradient = new SweepGradient(viewBounds.centerX(), viewBounds.centerY(), colors, positions);
}
 
Example #23
Source File: CircleLoadingView.java    From ImageLoader with Apache License 2.0 5 votes vote down vote up
private void initRect(float width, float height) {
    if (width > height) {
        rect.left = (width - height) / 2;
        rect.right = width - rect.left;
        rect.top = 0;
        rect.bottom = height;
    } else {
        rect.left = 0;
        rect.right = width;
        rect.top = (height - width) / 2;
        rect.bottom = height - rect.top;
    }

   int  circleThickness = (int) (width*circleThicknessRatio);
    paint.setStrokeWidth(circleThickness);

    rect.left = rect.left + circleThickness / 2;
    rect.right = rect.right - circleThickness / 2;
    rect.top = rect.top + circleThickness / 2;
    rect.bottom = rect.bottom - circleThickness / 2;

    //因为这个圆环是顺时针旋转的,所有endColor, startColor在shader上反过来写了
    shader = new SweepGradient(width / 2, height / 2, endColor, startColor);
    matrix = new Matrix();
    matrix.setRotate(-90 + 20,width/2,height/2);//着色器初始位置,12点钟方法加20度,收尾留一点空隙
    shader.setLocalMatrix(matrix);
    paint.setShader(shader);
}
 
Example #24
Source File: CircularProgressBarDrawable.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * 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;

        final CircularProgressBarState st = mCircularProgressBarState;

        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, y0;

            x0 = r.left + (r.right - r.left) * st.mCenterX;
            y0 = r.top + (r.bottom - r.top) * st.mCenterY;

            final SweepGradient sweepGradient = new SweepGradient(x0, y0, colors, null);
            Matrix flipMatrix = new Matrix();
            flipMatrix.setScale(1, -1);
            flipMatrix.postTranslate(0, (r.bottom - r.top));
            flipMatrix.postRotate(-startingAngle, x0, y0);
            sweepGradient.setLocalMatrix(flipMatrix);
            mFillPaint.setShader(sweepGradient);

            // If we don't have a solid color, the alpha channel must be
            // maxed out so that alpha modulation works correctly.
            if (!st.mHasSolidColor) {
                mFillPaint.setColor(Color.BLACK);
            }
        }
    }
    return !mRect.isEmpty();
}
 
Example #25
Source File: CircularProgressBarDrawable.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * 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;

        final CircularProgressBarState st = mCircularProgressBarState;

        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, y0;

            x0 = r.left + (r.right - r.left) * st.mCenterX;
            y0 = r.top + (r.bottom - r.top) * st.mCenterY;

            final SweepGradient sweepGradient = new SweepGradient(x0, y0, colors, null);
            Matrix flipMatrix = new Matrix();
            flipMatrix.setScale(1, -1);
            flipMatrix.postTranslate(0, (r.bottom - r.top));
            flipMatrix.postRotate(-startingAngle, x0, y0);
            sweepGradient.setLocalMatrix(flipMatrix);
            mFillPaint.setShader(sweepGradient);

            // If we don't have a solid color, the alpha channel must be
            // maxed out so that alpha modulation works correctly.
            if (!st.mHasSolidColor) {
                mFillPaint.setColor(Color.BLACK);
            }
        }
    }
    return !mRect.isEmpty();
}
 
Example #26
Source File: CircularProgressBarDrawable.java    From android-circular-progress-bar with Apache License 2.0 5 votes vote down vote up
/**
 * 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;

        final CircularProgressBarState st = mCircularProgressBarState;

        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, y0;

            x0 = r.left + (r.right - r.left) * st.mCenterX;
            y0 = r.top + (r.bottom - r.top) * st.mCenterY;

            final SweepGradient sweepGradient = new SweepGradient(x0, y0, colors, null);
            Matrix flipMatrix = new Matrix();
            flipMatrix.setScale(1, -1);
            flipMatrix.postTranslate(0, (r.bottom - r.top));
            flipMatrix.postRotate(-startingAngle, x0, y0);
            sweepGradient.setLocalMatrix(flipMatrix);
            mFillPaint.setShader(sweepGradient);

            // If we don't have a solid color, the alpha channel must be
            // maxed out so that alpha modulation works correctly.
            if (!st.mHasSolidColor) {
                mFillPaint.setColor(Color.BLACK);
            }
        }
    }
    return !mRect.isEmpty();
}
 
Example #27
Source File: CircleProgressView.java    From Circle-Progress-View with MIT License 5 votes vote down vote up
private void setupBarPaint() {
    if (mBarColors.length > 1) {
        mBarPaint.setShader(new SweepGradient(mCircleBounds.centerX(), mCircleBounds.centerY(), mBarColors, null));
        Matrix matrix = new Matrix();
        mBarPaint.getShader().getLocalMatrix(matrix);

        matrix.postTranslate(-mCircleBounds.centerX(), -mCircleBounds.centerY());
        matrix.postRotate(mStartAngle);
        matrix.postTranslate(mCircleBounds.centerX(), mCircleBounds.centerY());
        mBarPaint.getShader().setLocalMatrix(matrix);
        mBarPaint.setColor(mBarColors[0]);
    } else if (mBarColors.length == 1) {
        mBarPaint.setColor(mBarColors[0]);
        mBarPaint.setShader(null);
    } else {
        mBarPaint.setColor(mBarColorStandard);
        mBarPaint.setShader(null);
    }

    mBarPaint.setAntiAlias(true);
    mBarPaint.setStrokeCap(mBarStrokeCap);
    mBarPaint.setStyle(Style.STROKE);
    mBarPaint.setStrokeWidth(mBarWidth);

    if (mBarStrokeCap != Paint.Cap.BUTT) {
        mShaderlessBarPaint = new Paint(mBarPaint);
        mShaderlessBarPaint.setShader(null);
        mShaderlessBarPaint.setColor(mBarColors[0]);
    }
}
 
Example #28
Source File: CircleBar.java    From CircleProgressBar with MIT License 5 votes vote down vote up
private void init(AttributeSet attrs, int defStyle) {

        /**
         * 设置画笔渐变色
         */
        mColors = new int[]{0xFF6BB7ED, 0xFF47D9CE, 0xFF56CADC};
        Shader s = new SweepGradient(0, 0, mColors, null);
        mColorWheelPaint = new Paint();
        mColorWheelPaint.setShader(s);
        mColorWheelPaint.setStyle(Paint.Style.STROKE);// 空心,只绘制轮廓线
        mColorWheelPaint.setStrokeCap(Paint.Cap.ROUND);// 圆角画笔
        mColorWheelPaint.setAntiAlias(true);// 去锯齿

        mColorWheelPaintCentre = new Paint();
        mColorWheelPaintCentre.setColor(Color.rgb(214, 246, 254));
        mColorWheelPaintCentre.setStyle(Paint.Style.STROKE);
        mColorWheelPaintCentre.setStrokeCap(Paint.Cap.ROUND);
        mColorWheelPaintCentre.setAntiAlias(true);

        mDefaultWheelPaint = new Paint();
        mDefaultWheelPaint.setColor(Color.rgb(127, 127, 127));
        mDefaultWheelPaint.setStyle(Paint.Style.STROKE);
        mDefaultWheelPaint.setStrokeCap(Paint.Cap.ROUND);
        mDefaultWheelPaint.setAntiAlias(true);

        anim = new BarAnimation();
    }
 
Example #29
Source File: ColorWheelView.java    From SimpleDialogFragments with Apache License 2.0 5 votes vote down vote up
private void updateShader(){
    int[] gradient = new int[]{Color.RED, Color.YELLOW, Color.GREEN,
            Color.CYAN, Color.BLUE, Color.MAGENTA, Color.RED};
    SweepGradient rainbow = new SweepGradient(center.x, center.y, gradient, null);

    paint.setShader(rainbow);
}
 
Example #30
Source File: ArcProgressStackView.java    From ArcProgressStackView with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    // Get measured sizes
    final int width = MeasureSpec.getSize(widthMeasureSpec);
    final int height = MeasureSpec.getSize(heightMeasureSpec);

    // Get size for square dimension
    if (width > height) mSize = height;
    else mSize = width;

    // Get progress offsets
    final float divider = mDrawWidthFraction == 0 ? mDrawWidthDimension : mSize * mDrawWidthFraction;
    mProgressModelSize = divider / mModels.size();
    final float paintOffset = mProgressModelSize * 0.5F;
    final float shadowOffset = mIsShadowed ? (mShadowRadius + mShadowDistance) : 0.0F;

    // Set bound with offset for models
    for (int i = 0; i < mModels.size(); i++) {
        final Model model = mModels.get(i);
        final float modelOffset = (mProgressModelSize * i) +
                (paintOffset + shadowOffset) - (mProgressModelOffset * i);

        // Set bounds to progress
        model.mBounds.set(
                modelOffset, modelOffset,
                mSize - modelOffset, mSize - modelOffset
        );

        // Set sweep gradient shader
        if (model.getColors() != null)
            model.mSweepGradient = new SweepGradient(
                    model.mBounds.centerX(), model.mBounds.centerY(), model.getColors(), null
            );
    }

    // Set square measured dimension
    setMeasuredDimension(mSize, mSize);
}