Search in sources :

Example 26 with SweepGradient

use of android.graphics.SweepGradient in project openhab-android by openhab.

the class ColorPicker method init.

private void init(AttributeSet attrs, int defStyle) {
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
    mColorWheelStrokeWidth = a.getInteger(R.styleable.ColorPicker_wheel_size, 16);
    mPointerRadius = a.getInteger(R.styleable.ColorPicker_pointer_size, 32);
    // initialize X positions of brightness and saturation sliders
    mBrightnessSliderX = mPointerRadius * 2;
    mSaturationSliderX = -mPointerRadius * 2;
    Log.d(TAG, String.format("init %f %f %f %f", mBrightnessSliderStartY, mBrightnessSliderEndY, mSaturationSliderStartY, mSaturationSliderEndY));
    a.recycle();
    Shader s = new SweepGradient(0, 0, COLORS, null);
    mColorWheelPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mColorWheelPaint.setShader(s);
    mColorWheelPaint.setStyle(Paint.Style.STROKE);
    mColorWheelPaint.setStrokeWidth(mColorWheelStrokeWidth);
    mBrightnessSliderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPointerHaloPaint.setColor(Color.BLACK);
    mPointerHaloPaint.setStrokeWidth(5);
    mPointerHaloPaint.setAlpha(0x60);
    mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPointerColor.setStrokeWidth(5);
    mBrightnessPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBrightnessPointerHaloPaint.setColor(Color.BLACK);
    mBrightnessPointerHaloPaint.setStrokeWidth(5);
    mBrightnessPointerHaloPaint.setAlpha(0x60);
    mBrightnessPointerBorderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBrightnessPointerBorderPaint.setColor(Color.WHITE);
    mBrightnessPointerBorderPaint.setStrokeWidth(2);
    mBrightnessPointerBorderPaint.setAlpha(0x60);
    mBrightnessPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBrightnessPointerColor.setStrokeWidth(5);
    mSaturationSliderPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mSaturationPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mSaturationPointerHaloPaint.setColor(Color.BLACK);
    mSaturationPointerHaloPaint.setStrokeWidth(5);
    mSaturationPointerHaloPaint.setAlpha(0x60);
    mSaturationPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
    mSaturationPointerColor.setStrokeWidth(5);
    mAngle = (float) (-Math.PI / 2);
    mPointerColor.setColor(calculateColor(mAngle));
    // mBrightnessPointerColor.setColor(calculateColor(mAngle));
    mBrightnessPointerColor.setColor(Color.BLACK);
}
Also used : TypedArray(android.content.res.TypedArray) SweepGradient(android.graphics.SweepGradient) Paint(android.graphics.Paint) Shader(android.graphics.Shader)

Example 27 with SweepGradient

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

the class ColorPicker method onDraw.

@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
    int centerX = getWidth() / 2;
    int centerY = getHeight() / 2;
    // drawing color wheel
    canvas.drawBitmap(colorWheelBitmap, centerX - colorWheelRadius, centerY - colorWheelRadius, null);
    // drawing color view
    colorViewPaint.setColor(Color.HSVToColor(colorHSV));
    canvas.drawPath(colorViewPath, colorViewPaint);
    // drawing value slider
    float[] hsv = new float[] { colorHSV[0], colorHSV[1], 1f };
    SweepGradient sweepGradient = new SweepGradient(centerX, centerY, new int[] { Color.BLACK, Color.HSVToColor(hsv), Color.WHITE }, null);
    sweepGradient.setLocalMatrix(gradientRotationMatrix);
    valueSliderPaint.setShader(sweepGradient);
    canvas.drawPath(valueSliderPath, valueSliderPaint);
    // drawing color wheel pointer
    float hueAngle = (float) Math.toRadians(colorHSV[0]);
    int colorPointX = (int) (-Math.cos(hueAngle) * colorHSV[1] * colorWheelRadius) + centerX;
    int colorPointY = (int) (-Math.sin(hueAngle) * colorHSV[1] * colorWheelRadius) + centerY;
    float pointerRadius = 0.075f * colorWheelRadius;
    int pointerX = (int) (colorPointX - pointerRadius / 2);
    int pointerY = (int) (colorPointY - pointerRadius / 2);
    colorPointerCoords.set(pointerX, pointerY, pointerX + pointerRadius, pointerY + pointerRadius);
    canvas.drawOval(colorPointerCoords, colorPointerPaint);
    // drawing value pointer
    valuePointerPaint.setColor(Color.HSVToColor(new float[] { 0f, 0f, 1f - colorHSV[2] }));
    double valueAngle = (colorHSV[2] - 0.5f) * Math.PI;
    float valueAngleX = (float) Math.cos(valueAngle);
    float valueAngleY = (float) Math.sin(valueAngle);
    canvas.drawLine(valueAngleX * innerWheelRadius + centerX, valueAngleY * innerWheelRadius + centerY, valueAngleX * outerWheelRadius + centerX, valueAngleY * outerWheelRadius + centerY, valuePointerPaint);
    if (arrowPointerSize > 0) {
        drawPointerArrow(canvas);
    }
}
Also used : SweepGradient(android.graphics.SweepGradient) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint)

Example 28 with SweepGradient

use of android.graphics.SweepGradient 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)

Example 29 with SweepGradient

use of android.graphics.SweepGradient in project AndroidStudy by tinggengyan.

the class AbCircleProgressBar method onDraw.

/* (non-Javadoc)
     * @see android.view.View#onDraw(android.graphics.Canvas)
     */
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (reset) {
        canvas.drawColor(Color.TRANSPARENT);
        reset = false;
    }
    this.width = getMeasuredWidth();
    this.height = getMeasuredHeight();
    this.radius = getMeasuredWidth() / 2 - pathWidth;
    // 设置画笔颜色
    pathPaint.setColor(pathColor);
    // 设置画笔宽度
    pathPaint.setStrokeWidth(pathWidth);
    // 添加浮雕效果
    pathPaint.setMaskFilter(emboss);
    // 在中心的地方画个半径为r的圆
    canvas.drawCircle(this.width / 2, this.height / 2, radius, pathPaint);
    // 边线
    pathPaint.setStrokeWidth(0.5f);
    pathPaint.setColor(pathBorderColor);
    canvas.drawCircle(this.width / 2, this.height / 2, radius + pathWidth / 2 + 0.5f, pathPaint);
    canvas.drawCircle(this.width / 2, this.height / 2, radius - pathWidth / 2 - 0.5f, pathPaint);
    /*int[] gradientColors = new int[3];  
                gradientColors[0] = Color.GREEN;
		gradientColors[1] = Color.YELLOW;  
		gradientColors[2] = Color.RED;  
		float[] gradientPositions = new float[3];  
		gradientPositions[0] = 0.0f;  
		gradientPositions[1] = 0.5f;  
		gradientPositions[2] = 1.0f;  
		
		//按颜色比例圆形填充
		RadialGradient radialGradientShader = new RadialGradient(this.width/2,this.height/2, 
				radius, gradientColors, gradientPositions, TileMode.CLAMP); 
		
		paint1.setShader(radialGradientShader);*/
    // 环形颜色填充
    SweepGradient sweepGradient = new SweepGradient(this.width / 2, this.height / 2, arcColors, null);
    fillArcPaint.setShader(sweepGradient);
    // 设置画笔为白色
    // 模糊效果
    fillArcPaint.setMaskFilter(mBlur);
    // 设置线的类型,边是圆的
    fillArcPaint.setStrokeCap(Paint.Cap.ROUND);
    // fillArcPaint.setColor(Color.BLUE);
    fillArcPaint.setStrokeWidth(pathWidth);
    // 设置类似于左上角坐标,右下角坐标
    oval.set(this.width / 2 - radius, this.height / 2 - radius, this.width / 2 + radius, this.height / 2 + radius);
    // 画圆弧,第二个参数为:起始角度,第三个为跨的角度,第四个为true的时候是实心,false的时候为空心
    canvas.drawArc(oval, -90, ((float) progress / max) * 360, false, fillArcPaint);
}
Also used : SweepGradient(android.graphics.SweepGradient) SuppressLint(android.annotation.SuppressLint)

Example 30 with SweepGradient

use of android.graphics.SweepGradient in project GossipView by jianghejie.

the class GossipView method onMeasure.

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
    int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
    int min = Math.min(width, height);
    mWidth = min;
    outArctrokeWidth = min / 6;
    mInnerArctrokeWidth = outArctrokeWidth / 7;
    mInnerArcPaint.setStrokeWidth(mInnerArctrokeWidth);
    mOuterTextPaint.setTextSize(outArctrokeWidth / 3);
    mOuterArcPaint.setStrokeWidth(outArctrokeWidth);
    mOuterArcRadius = mWidth - outArctrokeWidth / 2 - padding;
    mInnerArcRadius = mWidth / 6;
    mProgressPaint.setStrokeWidth(mInnerArctrokeWidth);
    mSweepGradient = new SweepGradient(getOriginal().x, getOriginal().y, 0xfff39700, Color.WHITE);
    mProgressPaint.setShader(mSweepGradient);
    mOuterArcRectangle.set(outArctrokeWidth / 2 + padding, outArctrokeWidth / 2 + padding, mOuterArcRadius, mOuterArcRadius);
    mInnerArcRectangle.set(mWidth / 2 - mInnerArcRadius, mWidth / 2 - mInnerArcRadius, mWidth / 2 + mInnerArcRadius, mWidth / 2 + mInnerArcRadius);
    mInnerBackGroud.setBounds((int) outArctrokeWidth + padding, (int) outArctrokeWidth + padding, (int) (min - outArctrokeWidth - padding), (int) (min - outArctrokeWidth - padding));
    mOuterBackGroud.setBounds(0, 0, mWidth, mWidth);
    setMeasuredDimension(min, min);
}
Also used : SweepGradient(android.graphics.SweepGradient) Paint(android.graphics.Paint)

Aggregations

SweepGradient (android.graphics.SweepGradient)30 Paint (android.graphics.Paint)17 RadialGradient (android.graphics.RadialGradient)15 LinearGradient (android.graphics.LinearGradient)14 RectF (android.graphics.RectF)8 Rect (android.graphics.Rect)7 SuppressLint (android.annotation.SuppressLint)5 ComposeShader (android.graphics.ComposeShader)3 TypedArray (android.content.res.TypedArray)2 Bitmap (android.graphics.Bitmap)2 Canvas (android.graphics.Canvas)2 Matrix (android.graphics.Matrix)2 Shader (android.graphics.Shader)2 BitmapShader (android.graphics.BitmapShader)1 Path (android.graphics.Path)1