Java Examples for android.graphics.SweepGradient
The following java examples will help you to understand the usage of android.graphics.SweepGradient. These source code samples are taken from different open source projects.
Example 1
| Project: android-DecoView-charting-master File: ArcSeries.java View source code |
/**
* Build a gradient if required. This must be executed every time the bounds changes
*/
protected void applyGradientToPaint() {
if (Color.alpha(mSeriesItem.getSecondaryColor()) != 0) {
SweepGradient gradient;
if (mAngleSweep < 360) {
/**
* When we have less than a full circle we change the style of gradient so that
* the two colors start at the same point. The two provided colors meet rather than
* a fade the complete circumference. A matrix is rotated so the meeting of the
* two colors occurs in the middle of the gap when the part circle is not drawn
*/
final int[] colors = { mSeriesItem.getColor(), mSeriesItem.getSecondaryColor() };
final float[] positions = { 0, 1 };
gradient = new SweepGradient(mBounds.centerX(), mBounds.centerY(), colors, positions);
Matrix gradientRotationMatrix = new Matrix();
gradientRotationMatrix.preRotate(mAngleStart - ((360f - mAngleSweep) / 2), mBounds.centerX(), mBounds.centerY());
gradient.setLocalMatrix(gradientRotationMatrix);
} else {
/**
* Drawing a gradient around the complete circumference of the circle. This
* gradient fades gently between the two colors.
*/
final int[] colors = { mSeriesItem.getSecondaryColor(), mSeriesItem.getColor(), mSeriesItem.getSecondaryColor() };
final float[] positions = { 0, 0.5f * (mAngleSweep / 360f), 1 };
gradient = new SweepGradient(mBounds.centerX(), mBounds.centerY(), colors, positions);
}
mPaint.setShader(gradient);
}
}Example 2
| Project: FPSAnimator-master File: CustomDrawerSampleActivity.java View source code |
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_drawer_sample);
mFPSTextureView = (FPSTextureView) findViewById(R.id.animation_texture_view);
final Paint sweepGradientPaint = new Paint();
int[] colors = { 0xFFFF0000, 0xFFFFFF00, 0xFFFF00FF };
SweepGradient sg = new SweepGradient(UIUtil.getWindowWidth(this) / 2, UIUtil.getWindowHeight(this) / 2, colors, null);
sweepGradientPaint.setShader(sg);
final Paint paint1 = new Paint();
paint1.setShader(sg);
final Paint paint2 = new Paint();
paint2.setColor(ContextCompat.getColor(getApplicationContext(), R.color.circle2));
final Paint paint3 = new Paint();
paint3.setColor(ContextCompat.getColor(getApplicationContext(), R.color.circle3));
CustomDrawer customDrawer = new CustomDrawer(new CustomDrawer.CustomDraw() {
@Override
public void draw(Canvas canvas, float x, float y, int alpha) {
paint1.setAlpha(alpha);
paint2.setAlpha(alpha);
paint3.setAlpha(alpha);
canvas.drawCircle(x, y, 100, paint3);
canvas.drawRect(x - 60, y - 60, x + 60, y + 60, paint2);
canvas.drawCircle(x, y, 35, paint1);
}
@Override
public float getWidth() {
return 100;
}
@Override
public float getHeight() {
return 100;
}
});
DisplayObject displayObject1 = new DisplayObject();
displayObject1.with(customDrawer).parabolic().accelerationX(-7).transform(UIUtil.getWindowWidth(this) / 3, UIUtil.getWindowHeight(this) / 6).end();
CircleDrawer circleDrawer = new CircleDrawer(sweepGradientPaint, 100).scaleRegistration(100, 100);
DisplayObject displayObject2 = new DisplayObject();
displayObject2.with(circleDrawer).parabolic().accelerationX(9).transform(UIUtil.getWindowWidth(this) / 2, UIUtil.getWindowHeight(this) / 4).end();
DisplayObject displayObject3 = new DisplayObject();
displayObject3.with(circleDrawer).parabolic().transform(UIUtil.getWindowWidth(this) / 2, UIUtil.getWindowHeight(this) / 4).accelerationX(-9).end();
DisplayObject displayObject4 = new DisplayObject();
displayObject4.with(circleDrawer).parabolic().end();
RectDrawer rectDrawer = new RectDrawer(sweepGradientPaint, 200, 300);
DisplayObject displayObject5 = new DisplayObject();
displayObject5.with(rectDrawer).parabolic().transform(UIUtil.getWindowWidth(this) / 2, 0).end();
DisplayObject displayObject6 = new DisplayObject();
displayObject6.with(rectDrawer).parabolic().transform(UIUtil.getWindowWidth(this) / 2, 0).accelerationX(-10).initialVelocityY(-5).end();
mFPSTextureView.addChild(displayObject1).addChild(displayObject2).addChild(displayObject3).addChild(displayObject4).addChild(displayObject5).addChild(displayObject6);
}Example 3
| Project: KuaiChuan-master File: RadarScanView.java View source code |
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int size = getMeasuredWidth();
setMeasuredDimension(size, size);
mRectF.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
// mArcPaint.setShader(new SweepGradient(size / 2, size / 2, Color.GRAY, Color.BLACK));
mArcPaint.setShader(new SweepGradient(size / 2, size / 2, mArcStartColor, mArcEndColor));
}Example 4
| Project: flatnote-master File: ColorPickerView.java View source code |
public void init(int color) {
// layer type is software, renders all red in hardware mode
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
mColors = new int[] { 0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00, 0xFFFFFF00, 0xFFFF0000 };
final 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
| Project: MiBandDecompiled-master File: DynamicPieChartOld.java View source code |
protected void drawPie(Canvas canvas, RectF rectf, float f1, float f2, float f3, float f4, float f5) {
canvas.drawCircle(f1, f2, f3 - o.getStrokeWidth() / 2.0F - n, o);
canvas.drawCircle(f1, f2, f3 - i.getStrokeWidth() / 2.0F - 2.0F * n, i);
float f6 = f4 * f5;
if (f6 > 1.0F) {
f6 = 1.0F;
}
if (c) {
int ai[] = { 0xffffff, -1, 0xffffff };
if (f6 == 0.0F) {
f6 = 0.5F;
}
k = new SweepGradient(f1, f2, ai, new float[] { 0.0F, f6, 1.0F });
j.setRotate(-90F + mRotate, f1, f2);
k.setLocalMatrix(j);
h.setShader(k);
} else {
h.setShader(null);
h.setColor(-1);
}
if (f6 < 1.0F) {
canvas.drawArc(m, -90F + mRotate + l, f6 * (360F - 2.0F * l), false, h);
} else {
canvas.drawCircle(f1, f2, f3 - i.getStrokeWidth() / 2.0F - 2.0F * n, h);
}
switch(d) {
// '\0'
case 0:
default:
return;
case // '\001'
1:
ChartUtil.erase(canvas, p);
ChartUtil.drawBitmapCenter(canvas, p.centerX(), p.centerY(), mDensityScale, e, null);
return;
case // '\002'
2:
ChartUtil.erase(canvas, p);
ChartUtil.drawBitmapCenter(canvas, p.centerX(), p.centerY(), mDensityScale, f, null);
return;
case // '\003'
3:
ChartUtil.erase(canvas, p);
break;
}
ChartUtil.drawBitmapCenter(canvas, p.centerX(), p.centerY(), mDensityScale, g, null);
}Example 6
| Project: andbase2x-master File: AbCircleProgressBar.java View source code |
@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);
}Example 7
| Project: android-15-master File: GradientDrawable.java View source code |
/**
* 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();
}Example 8
| Project: android-sdk-sources-for-api-level-23-master File: GradientDrawable.java View source code |
/**
* This checks mGradientIsDirty, 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 (mGradientIsDirty) {
mGradientIsDirty = 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[] gradientColors = st.mGradientColors;
if (gradientColors != null) {
final RectF r = mRect;
final float x0, x1, y0, y1;
if (st.mGradient == LINEAR_GRADIENT) {
final float level = st.mUseLevel ? 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, gradientColors, 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;
float radius = st.mGradientRadius;
if (st.mGradientRadiusType == RADIUS_TYPE_FRACTION) {
// Fall back to parent width or height if intrinsic
// size is not specified.
final float width = st.mWidth >= 0 ? st.mWidth : r.width();
final float height = st.mHeight >= 0 ? st.mHeight : r.height();
radius *= Math.min(width, height);
} else if (st.mGradientRadiusType == RADIUS_TYPE_FRACTION_PARENT) {
radius *= Math.min(r.width(), r.height());
}
if (st.mUseLevel) {
radius *= getLevel() / 10000.0f;
}
mGradientRadius = radius;
if (radius <= 0) {
// We can't have a shader with non-positive radius, so
// let's have a very, very small radius.
radius = 0.001f;
}
mFillPaint.setShader(new RadialGradient(x0, y0, radius, gradientColors, 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 = gradientColors;
float[] tempPositions = null;
if (st.mUseLevel) {
tempColors = st.mTempColors;
final int length = gradientColors.length;
if (tempColors == null || tempColors.length != length + 1) {
tempColors = st.mTempColors = new int[length + 1];
}
System.arraycopy(gradientColors, 0, tempColors, 0, length);
tempColors[length] = gradientColors[length - 1];
tempPositions = st.mTempPositions;
final float fraction = 1.0f / (length - 1);
if (tempPositions == null || tempPositions.length != length + 1) {
tempPositions = st.mTempPositions = new float[length + 1];
}
final float level = 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));
}
// maxed out so that alpha modulation works correctly.
if (st.mSolidColors == null) {
mFillPaint.setColor(Color.BLACK);
}
}
}
return !mRect.isEmpty();
}Example 9
| Project: android_frameworks_base-master File: GradientDrawable.java View source code |
/**
* This checks mGradientIsDirty, 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 (mGradientIsDirty) {
mGradientIsDirty = 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[] gradientColors = st.mGradientColors;
if (gradientColors != null) {
final RectF r = mRect;
final float x0, x1, y0, y1;
if (st.mGradient == LINEAR_GRADIENT) {
final float level = st.mUseLevel ? 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, gradientColors, 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;
float radius = st.mGradientRadius;
if (st.mGradientRadiusType == RADIUS_TYPE_FRACTION) {
// Fall back to parent width or height if intrinsic
// size is not specified.
final float width = st.mWidth >= 0 ? st.mWidth : r.width();
final float height = st.mHeight >= 0 ? st.mHeight : r.height();
radius *= Math.min(width, height);
} else if (st.mGradientRadiusType == RADIUS_TYPE_FRACTION_PARENT) {
radius *= Math.min(r.width(), r.height());
}
if (st.mUseLevel) {
radius *= getLevel() / 10000.0f;
}
mGradientRadius = radius;
if (radius <= 0) {
// We can't have a shader with non-positive radius, so
// let's have a very, very small radius.
radius = 0.001f;
}
mFillPaint.setShader(new RadialGradient(x0, y0, radius, gradientColors, 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 = gradientColors;
float[] tempPositions = null;
if (st.mUseLevel) {
tempColors = st.mTempColors;
final int length = gradientColors.length;
if (tempColors == null || tempColors.length != length + 1) {
tempColors = st.mTempColors = new int[length + 1];
}
System.arraycopy(gradientColors, 0, tempColors, 0, length);
tempColors[length] = gradientColors[length - 1];
tempPositions = st.mTempPositions;
final float fraction = 1.0f / (length - 1);
if (tempPositions == null || tempPositions.length != length + 1) {
tempPositions = st.mTempPositions = new float[length + 1];
}
final float level = 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));
}
// maxed out so that alpha modulation works correctly.
if (st.mSolidColors == null) {
mFillPaint.setColor(Color.BLACK);
}
}
}
return !mRect.isEmpty();
}Example 10
| Project: Android_Paint-master File: ColorCircle.java View source code |
/**
* Initializes variables.
*/
void init() {
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);
mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterPaint.setStrokeWidth(5);
}Example 11
| Project: BodhiTimer-master File: CircleAnimation.java View source code |
public void sizeChange(int w, int h) {
mWidth = w;
mHeight = h;
mMsRadius = Math.min(Math.min(w / 2.0f, h / 2.0f), MAX_SIZE * scale);
mMsGap = mMsRadius * .95f;
mSecondRadius = mMsRadius * .97f;
mSecondGap = mMsRadius * .93f;
mRadius = mMsRadius * .93f;
mInnerRadius = mMsRadius * 0.4f;
if (theme != 3) {
int offset = 75;
int r = Color.red(mInnerColor) - offset;
int g = Color.green(mInnerColor) - offset;
int b = Color.blue(mInnerColor) - offset;
int start = Color.rgb(r, g, b);
Shader shader = new RadialGradient(0, 0, mRadius, start, mInnerColor, Shader.TileMode.CLAMP);
mArcPaint.setShader(shader);
} else {
Shader shader = new SweepGradient(0, 0, mInnerColor, mInnerColor);
mArcPaint.setShader(shader);
}
}Example 12
| Project: DMXControl-for-Android-master File: ColorCircle.java View source code |
/**
* Initializes variables.
*/
void init() {
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);
mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterPaint.setStrokeWidth(5);
}Example 13
| Project: FanXin3.0-master File: RadarView.java View source code |
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(measureSize(widthMeasureSpec), measureSize(widthMeasureSpec));
mWidth = getMeasuredWidth();
mHeight = getMeasuredHeight();
mWidth = mHeight = Math.min(mWidth, mHeight);
//设置扫æ??渲染的shader
scanShader = new SweepGradient(mWidth / 2, mHeight / 2, new int[] { Color.TRANSPARENT, Color.parseColor("#b5b5b6") }, null);
}Example 14
| Project: frameworks_base_disabled-master File: GradientDrawable.java View source code |
/**
* 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();
}Example 15
| Project: Gallery3D_EVO_3D-master File: ColorRectView.java View source code |
private void setUpColorPanel() {
float val = mHSVO[2];
int v = 0xFF000000 | 0x10101 * (int) (val * 0xFF);
int[] colors = new int[] { 0x0000000, v };
int[] colors2 = new int[] { 0x0000000, 0xFF000000 };
int[] wheelColor = new int[mColors.length];
float[] hsv = new float[3];
for (int i = 0; i < wheelColor.length; i++) {
Color.colorToHSV(mColors[i], hsv);
hsv[2] = mHSVO[2];
wheelColor[i] = Color.HSVToColor(hsv);
}
updateDot();
updateDotPaint();
SweepGradient sg = new SweepGradient(mCtrX, mCtrY, wheelColor, null);
LinearGradient lg = new LinearGradient(mBorder, 0, mWidth - mBorder, 0, wheelColor, null, Shader.TileMode.CLAMP);
mWheelPaint1.setShader(lg);
LinearGradient rg = new LinearGradient(0, mBorder, 0, mHeight - mBorder, colors, null, Shader.TileMode.CLAMP);
mWheelPaint2.setShader(rg);
LinearGradient rg2 = new LinearGradient(0, mBorder, 0, mHeight - mBorder, colors2, null, Shader.TileMode.CLAMP);
mWheelPaint3.setShader(rg2);
}Example 16
| Project: GoogleMapsAnimations-master File: MapRadar.java View source code |
//not needed for now
private Bitmap drawToBitmap() {
int radarColor = Color.parseColor("#ffffff");
Bitmap.Config config = Bitmap.Config.ARGB_8888;
Bitmap bitmap = Bitmap.createBitmap(distance, distance, config);
Bitmap workingBitmap = Bitmap.createBitmap(bitmap);
Bitmap mutableBitmap = workingBitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas canvas = new Canvas((workingBitmap));
Paint mPaintRadar = new Paint();
mPaintRadar.setColor(radarColor);
mPaintRadar.setAntiAlias(true);
Shader shader = new SweepGradient(0, 0, Color.parseColor("#00000000"), Color.parseColor("#ff000000"));
mPaintRadar.setShader(shader);
//canvas.concat(matrix);
RectF rect = new RectF(0, 0, distance, distance);
canvas.drawRoundRect(rect, distance / 2, distance / 2, mPaintRadar);
//canvas.drawCircle(0, 0, w/2, mPaintRadar);
return workingBitmap;
}Example 17
| Project: platform_frameworks_base-master File: GradientDrawable.java View source code |
/**
* This checks mGradientIsDirty, 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 (mGradientIsDirty) {
mGradientIsDirty = 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[] gradientColors = st.mGradientColors;
if (gradientColors != null) {
final RectF r = mRect;
final float x0, x1, y0, y1;
if (st.mGradient == LINEAR_GRADIENT) {
final float level = st.mUseLevel ? 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, gradientColors, 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;
float radius = st.mGradientRadius;
if (st.mGradientRadiusType == RADIUS_TYPE_FRACTION) {
// Fall back to parent width or height if intrinsic
// size is not specified.
final float width = st.mWidth >= 0 ? st.mWidth : r.width();
final float height = st.mHeight >= 0 ? st.mHeight : r.height();
radius *= Math.min(width, height);
} else if (st.mGradientRadiusType == RADIUS_TYPE_FRACTION_PARENT) {
radius *= Math.min(r.width(), r.height());
}
if (st.mUseLevel) {
radius *= getLevel() / 10000.0f;
}
mGradientRadius = radius;
if (radius <= 0) {
// We can't have a shader with non-positive radius, so
// let's have a very, very small radius.
radius = 0.001f;
}
mFillPaint.setShader(new RadialGradient(x0, y0, radius, gradientColors, 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 = gradientColors;
float[] tempPositions = null;
if (st.mUseLevel) {
tempColors = st.mTempColors;
final int length = gradientColors.length;
if (tempColors == null || tempColors.length != length + 1) {
tempColors = st.mTempColors = new int[length + 1];
}
System.arraycopy(gradientColors, 0, tempColors, 0, length);
tempColors[length] = gradientColors[length - 1];
tempPositions = st.mTempPositions;
final float fraction = 1.0f / (length - 1);
if (tempPositions == null || tempPositions.length != length + 1) {
tempPositions = st.mTempPositions = new float[length + 1];
}
final float level = 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));
}
// maxed out so that alpha modulation works correctly.
if (st.mSolidColors == null) {
mFillPaint.setColor(Color.BLACK);
}
}
}
return !mRect.isEmpty();
}Example 18
| Project: property-db-master File: GradientDrawable.java View source code |
/**
* 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));
if (!mGradientState.mHasSolidColor) {
mFillPaint.setColor(0xff000000);
}
} 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));
if (!mGradientState.mHasSolidColor) {
mFillPaint.setColor(0xff000000);
}
} 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));
if (!mGradientState.mHasSolidColor) {
mFillPaint.setColor(0xff000000);
}
}
}
}
return !mRect.isEmpty();
}Example 19
| Project: RadarScan-master File: RadarView.java View source code |
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(measureSize(widthMeasureSpec), measureSize(widthMeasureSpec));
mWidth = getMeasuredWidth();
mHeight = getMeasuredHeight();
mWidth = mHeight = Math.min(mWidth, mHeight);
centerBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.circle_photo);
//设置扫æ??渲染的shader
scanShader = new SweepGradient(mWidth / 2, mHeight / 2, new int[] { Color.TRANSPARENT, Color.parseColor("#84B5CA") }, null);
}Example 20
| Project: SpeedView-master File: PointerSpeedometer.java View source code |
private SweepGradient updateSweep() { int startColor = Color.argb(150, Color.red(speedometerColor), Color.green(speedometerColor), Color.blue(speedometerColor)); int color2 = Color.argb(220, Color.red(speedometerColor), Color.green(speedometerColor), Color.blue(speedometerColor)); int color3 = Color.argb(70, Color.red(speedometerColor), Color.green(speedometerColor), Color.blue(speedometerColor)); int endColor = Color.argb(15, Color.red(speedometerColor), Color.green(speedometerColor), Color.blue(speedometerColor)); float position = getOffsetSpeed() * (getEndDegree() - getStartDegree()) / 360f; SweepGradient sweepGradient = new SweepGradient(getSize() * .5f, getSize() * .5f, new int[] { startColor, color2, speedometerColor, color3, endColor, startColor }, new float[] { 0f, position * .5f, position, position, .99f, 1f }); Matrix matrix = new Matrix(); matrix.postRotate(getStartDegree(), getSize() * .5f, getSize() * .5f); sweepGradient.setLocalMatrix(matrix); return sweepGradient; }
Example 21
| Project: WanKu_Android-master File: AbCircleProgressBar.java View source code |
@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);
}Example 22
| Project: WashingCar-master File: AbCircleProgressBar.java View source code |
@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);
}Example 23
| Project: WS171-frameworks-base-master File: GradientDrawable.java View source code |
/**
* 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();
}Example 24
| Project: openhab.android-master File: ColorPicker.java View source code |
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);
}Example 25
| Project: RGBControllerAndroid-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
}Example 26
| Project: youtui-core-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
mColorWheelThickness = getDensity(40f);
mColorWheelRadius = getDensity(120f);
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = getDensity(54f);
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = getDensity(60f);
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = 0;
mColorPointerHaloRadius = getDensity(18f);
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x00);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
cusPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
cusPaint.setColor(Color.RED);
cusPaint.setStyle(Paint.Style.STROKE);
cusPaint.setStrokeWidth(4);
cusRectF = new RectF();
}Example 27
| Project: 3House-master File: ColorPicker.java View source code |
@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);
}
}Example 28
| Project: AisenWeiBo-master File: ColorPicker.java View source code |
@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);
}
}Example 29
| Project: AisenWeiBo-master-master File: ColorPicker.java View source code |
@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);
}
}Example 30
| Project: andbase-master File: AbCircleProgressBar.java View source code |
/* (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);
}Example 31
| Project: andFHEM-master File: ColorPicker.java View source code |
@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);
}
}Example 32
| Project: Android-Color-Picker-master File: MultiColorPicker.java View source code |
@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
int[] segmentColors = getColors();
float sweepAngleStep = 180f / paramColorCount;
for (int i = 0; i < paramColorCount; i++) {
colorViewPath.reset();
colorViewPath.arcTo(outerWheelRect, 270 - i * sweepAngleStep, -sweepAngleStep);
colorViewPath.arcTo(innerWheelRect, 90 + (paramColorCount - i - 1) * sweepAngleStep, sweepAngleStep);
colorViewPaint.setColor(segmentColors[i]);
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);
for (int i = 0; i < paramColorCount; i++) {
drawColorWheelPointer(canvas, (float) Math.toRadians(adjacentHue[i]));
}
// 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);
}
}Example 33
| Project: ArduinoPixel-master File: ColorPicker.java View source code |
@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);
}
}Example 34
| Project: BluetoothBacon-master File: MultiColorPicker.java View source code |
@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
int[] segmentColors = getColors();
float sweepAngleStep = 180f / paramColorCount;
for (int i = 0; i < paramColorCount; i++) {
colorViewPath.reset();
colorViewPath.arcTo(outerWheelRect, 270 - i * sweepAngleStep, -sweepAngleStep);
colorViewPath.arcTo(innerWheelRect, 90 + (paramColorCount - i - 1) * sweepAngleStep, sweepAngleStep);
colorViewPaint.setColor(segmentColors[i]);
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);
for (int i = 0; i < paramColorCount; i++) {
drawColorWheelPointer(canvas, (float) Math.toRadians(adjacentHue[i]));
}
// 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);
}
}Example 35
| Project: CarRunningArcViewDemo-master File: CarRunningArcView.java View source code |
@Override
protected void onSizeChanged(int w, int h, int oldW, int oldH) {
super.onSizeChanged(w, h, oldW, oldH);
mWidth = w;
mHeight = h;
mCenterX = mWidth / 2;
mCenterY = mHeight / 2;
if (mRadius + mArcOutSideStroke > Math.min(mWidth / 2, mHeight / 2) || mRadius <= 0) {
mRadius = Math.min(mWidth / 2, mHeight / 2) - mArcOutSideStroke;
}
mRectOval = new RectF(mCenterX - mRadius, mCenterY - mRadius, mCenterX + mRadius, mCenterY + mRadius);
mSweepGradient = new SweepGradient(mCenterX, mCenterX, mArcInsideColors, mPositions);
mPositions = new float[] { 0f, 0.5f, 0.8f, 0.9f };
final float rotationDegrees = mSwipeAngle * 1.0f / 6;
mMatrix.setRotate(rotationDegrees, mCenterX, mCenterX);
mSweepGradient.setLocalMatrix(mMatrix);
}Example 36
| Project: ColorArcProgressBar-master File: ColorArcProgressBar.java View source code |
private void initView() {
diameter = 3 * getScreenWidth() / 5;
//弧形的矩阵区域
bgRect = new RectF();
bgRect.top = longdegree + progressWidth / 2 + DEGREE_PROGRESS_DISTANCE;
bgRect.left = longdegree + progressWidth / 2 + DEGREE_PROGRESS_DISTANCE;
bgRect.right = diameter + (longdegree + progressWidth / 2 + DEGREE_PROGRESS_DISTANCE);
bgRect.bottom = diameter + (longdegree + progressWidth / 2 + DEGREE_PROGRESS_DISTANCE);
//圆心
centerX = (2 * longdegree + progressWidth + diameter + 2 * DEGREE_PROGRESS_DISTANCE) / 2;
centerY = (2 * longdegree + progressWidth + diameter + 2 * DEGREE_PROGRESS_DISTANCE) / 2;
//外部刻度线
degreePaint = new Paint();
degreePaint.setColor(Color.parseColor(longDegreeColor));
//整个弧形
allArcPaint = new Paint();
allArcPaint.setAntiAlias(true);
allArcPaint.setStyle(Paint.Style.STROKE);
allArcPaint.setStrokeWidth(bgArcWidth);
allArcPaint.setColor(Color.parseColor(bgArcColor));
allArcPaint.setStrokeCap(Paint.Cap.ROUND);
//当�进度的弧形
progressPaint = new Paint();
progressPaint.setAntiAlias(true);
progressPaint.setStyle(Paint.Style.STROKE);
progressPaint.setStrokeCap(Paint.Cap.ROUND);
progressPaint.setStrokeWidth(progressWidth);
progressPaint.setColor(Color.GREEN);
//内容显示文å—
vTextPaint = new Paint();
vTextPaint.setTextSize(textSize);
vTextPaint.setColor(Color.BLACK);
vTextPaint.setTextAlign(Paint.Align.CENTER);
//显示å?•ä½?æ–‡å—
hintPaint = new Paint();
hintPaint.setTextSize(hintSize);
hintPaint.setColor(Color.parseColor(hintColor));
hintPaint.setTextAlign(Paint.Align.CENTER);
//æ˜¾ç¤ºæ ‡é¢˜æ–‡å—
curSpeedPaint = new Paint();
curSpeedPaint.setTextSize(curSpeedSize);
curSpeedPaint.setColor(Color.parseColor(hintColor));
curSpeedPaint.setTextAlign(Paint.Align.CENTER);
mDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
sweepGradient = new SweepGradient(centerX, centerY, colors, null);
rotateMatrix = new Matrix();
}Example 37
| Project: dashboard-master File: DashboardView3.java View source code |
private SweepGradient generateSweepGradient() { SweepGradient sweepGradient = new SweepGradient(mCenterX, mCenterY, new int[] { Color.argb(0, 255, 255, 255), Color.argb(200, 255, 255, 255) }, new float[] { 0, calculateRelativeAngleWithValue(mCreditValue) / 360 }); Matrix matrix = new Matrix(); matrix.setRotate(mStartAngle - 1, mCenterX, mCenterY); sweepGradient.setLocalMatrix(matrix); return sweepGradient; }
Example 38
| Project: DashboardView-master File: DashboardView3.java View source code |
private SweepGradient generateSweepGradient() { SweepGradient sweepGradient = new SweepGradient(mCenterX, mCenterY, new int[] { Color.argb(0, 255, 255, 255), Color.argb(200, 255, 255, 255) }, new float[] { 0, calculateRelativeAngleWithValue(mCreditValue) / 360 }); Matrix matrix = new Matrix(); matrix.setRotate(mStartAngle - 1, mCenterX, mCenterY); sweepGradient.setLocalMatrix(matrix); return sweepGradient; }
Example 39
| Project: FingerColoring-Android-master File: ColorPicker.java View source code |
@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);
}
}Example 40
| Project: Flock-master File: ColorPicker.java View source code |
@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);
}
}Example 41
| Project: GlowNotifier-master File: ColorPicker.java View source code |
@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);
}
}Example 42
| Project: jzgs-master File: CircleChartView.java View source code |
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
if (w > 0 && h > 0) {
float cirX = getCenterX();
float cirY = getCenterY();
int startColor = mOuterRingStartColor;
int endColor = mOuterRingEndColor;
mSweepGradient = new SweepGradient(cirX, cirY, startColor, endColor);
}
}Example 43
| Project: MagicProgressWidget-master File: MagicProgressCircle.java View source code |
// ç›®å‰?由于SweepGradient赋值å?ªåœ¨æž„é€ å‡½æ•°ï¼Œæ— æ³•pre allocate & reuse instead
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
final int restore = canvas.save();
final int cx = getMeasuredWidth() / 2;
final int cy = getMeasuredHeight() / 2;
final int radius = getMeasuredWidth() / 2 - strokeWidth / 2;
float drawPercent = percent;
if (drawPercent > 0.97 && drawPercent < 1) {
// è®¾è®¡å¸ˆè¯´è¿™æ ·æ¯”è¾ƒå¥½
drawPercent = 0.97f;
}
// 画��圆
canvas.save();
canvas.rotate(-90, cx, cy);
int[] colors;
float[] positions;
if (drawPercent < 1 && drawPercent > 0) {
calculatePercentEndColor(drawPercent);
customColors[1] = percentEndColor;
colors = customColors;
customPositions[1] = drawPercent;
customPositions[2] = drawPercent;
positions = customPositions;
} else if (drawPercent == 1) {
colors = fullColors;
positions = extremePositions;
} else {
// <= 0 || > 1?
colors = emptyColors;
positions = extremePositions;
}
final SweepGradient sweepGradient = new SweepGradient(getMeasuredWidth() / 2, getMeasuredHeight() / 2, colors, positions);
paint.setShader(sweepGradient);
canvas.drawCircle(cx, cy, radius, paint);
canvas.restore();
if (drawPercent > 0) {
// 绘制结�的�圆
if (drawPercent < 1) {
canvas.save();
endPaint.setColor(percentEndColor);
canvas.rotate((int) Math.floor(360.0f * drawPercent) - 1, cx, cy);
canvas.drawArc(rectF, -90f, 180f, true, endPaint);
canvas.restore();
}
canvas.save();
// 绘制开始的�圆
canvas.drawArc(rectF, 90f, 180f, true, startPaint);
canvas.restore();
}
canvas.restoreToCount(restore);
}Example 44
| Project: Mi-Band-master File: ColorPicker.java View source code |
@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);
}
}Example 45
| Project: Noyze-master File: CircularProgressBarDrawable.java View source code |
/**
* 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);
// maxed out so that alpha modulation works correctly.
if (!st.mHasSolidColor) {
mFillPaint.setColor(Color.BLACK);
}
}
}
return !mRect.isEmpty();
}Example 46
| Project: Random-Penis-master File: ColorPicker.java View source code |
@Override
protected void onDraw(Canvas canvas) {
// 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);
}
}Example 47
| Project: ShootRefreshView-master File: ShootRefreshView.java View source code |
private void resolveAttrs(Context context, AttributeSet attrs) {
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ShootRefreshView);
mStrokeColor = ta.getColor(R.styleable.ShootRefreshView_strokeColor, DEFAULT_STROKE_COLOR);
mGradientStartColor = ta.getColor(R.styleable.ShootRefreshView_gradientStartColor, DEFAULT_GRADIENT_START_COLOR);
mGradientEndColor = ta.getColor(R.styleable.ShootRefreshView_gradientEndColor, DEFAULT_GRADIENT_END_COLOR);
mStrokeWidth = ta.getDimensionPixelSize(R.styleable.ShootRefreshView_strokeWidth, (int) DensityUtil.dp2px(getContext(), 1.0f));
ta.recycle();
mRefreshingShader = new SweepGradient(0, 0, new int[] { mGradientStartColor, mGradientEndColor }, new float[] { 0.0f, 1.0f });
}Example 48
| Project: Spark_Pixels-master File: ColorPicker.java View source code |
@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
//added by me
canvas.drawPath(valueSliderPath, colorViewPaint);
/*
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);
// drawing pointer arrow
if (arrowPointerSize > 0) {
drawPointerArrow(canvas);
}
*/
}Example 49
| Project: SystemBarTint-master File: ColorPicker.java View source code |
@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);
}
}Example 50
| Project: SystemBarTint-master-master File: ColorPicker.java View source code |
@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);
}
}Example 51
| Project: tvframe-master File: TvProgressBar.java View source code |
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// /**
// * 用于进度平滑
// */
// if (targetProgress > progress) {
// progress+=progressPercent;
// if (progress>=targetProgress) {
// progress=targetProgress;
// }
// }else if(targetProgress<progress){
// progress=0;
// }
paint = new Paint();
// 获å?–圆心的xå??æ ‡
int centre = getWidth() / 2;
// 设置空心
paint.setStyle(Paint.Style.STROKE);
paint.setColor(backgroundColor);
// 设置圆环的宽度
paint.setStrokeWidth(roundWidth);
// 消除锯齿
paint.setAntiAlias(true);
paint.setFlags(Paint.ANTI_ALIAS_FLAG);
switch(style) {
case RING:
{
// 圆环的�径
int radius = (int) (centre - roundWidth / 2);
/**
* 画环底色
*/
// 画出圆环
canvas.drawCircle(centre, centre, radius, paint);
/**
* 画环进度
*/
// 设置圆环的宽度
paint.setStrokeWidth(roundWidth);
// 设置进度的颜色
if (progressEndColor == 0) {
paint.setColor(progressStartColor);
} else {
// ��色
Shader sweep = new SweepGradient(centre, centre, new int[] { progressStartColor, progressEndColor, progressStartColor }, null);
paint.setShader(sweep);
}
RectF oval = new RectF(centre - radius, centre - radius, centre + radius, // 用于定义的圆弧的形状和大�的界�
centre + radius);
paint.setStyle(Paint.Style.STROKE);
if (progress != 0)
// æ ¹æ?®è¿›åº¦ç”»åœ†å¼§
canvas.drawArc(oval, -90, 360 * progress / max, false, paint);
break;
}
case FAN:
{
// 圆环的�径
int radius = (int) (centre - roundWidth / 2) + 1;
paint.setStyle(Paint.Style.FILL);
/**
* 画扇底色
*/
if (backgroundColor != 0) {
// 画出圆环
canvas.drawCircle(centre, centre, radius, paint);
}
// 设置进度的颜色
if (progressEndColor == 0) {
paint.setColor(progressStartColor);
} else {
// ��色
Shader sweep = new SweepGradient(centre, centre, new int[] { progressStartColor, progressEndColor, progressStartColor }, null);
paint.setShader(sweep);
}
RectF oval = new RectF(centre - radius, centre - radius, centre + radius, // 定义的圆弧的形状和大�的界�
centre + radius);
if (progress != 0)
// æ ¹æ?®è¿›åº¦ç”»åœ†å¼§
canvas.drawArc(oval, -90, 360 * progress / max, true, paint);
break;
}
case RECT:
{
paint.setStyle(Paint.Style.FILL);
int current = getWidth() * progress / max;
/**
* 画线底色
*/
if (backgroundColor != 0) {
if (rectRadius > getHeight()) {
rectRadius = getHeight();
}
RectF rectF = new RectF(0, 0, getWidth(), getHeight());
canvas.drawRoundRect(rectF, rectRadius, rectRadius, paint);
}
// 设置进度的颜色
if (progressEndColor == 0) {
paint.setColor(progressStartColor);
} else {
// ��色
Shader shader = new LinearGradient(0, 0, current, 0, new int[] { progressStartColor, progressEndColor }, null, Shader.TileMode.REPEAT);
paint.setShader(shader);
}
RectF rectF2 = new RectF(0, 0, current, getHeight());
canvas.drawRoundRect(rectF2, rectRadius, rectRadius, paint);
break;
}
}
/**
* 画进度文å—
*/
paint.setStrokeWidth(0);
paint.setColor(textColor);
paint.setTextSize(textSize);
// 设置å—体
paint.setTypeface(Typeface.DEFAULT_BOLD);
// ä¸é—´çš„进度百分比,先转æ?¢æˆ?float在进行除法è¿?算,ä¸?然都为0
int percent = (int) (((float) progress / (float) max) * 100);
// 测é‡?å—体宽度,我们需è¦?æ ¹æ?®å—体的宽度设置在圆环ä¸é—´
float textWidth = paint.measureText(percent + "%");
if (textDisplayable && percent != 0) {
if (percent < 10) {
canvas.drawText(" " + percent + "%", centre - textWidth / 2, centre + textSize / 2, // 画出进度百分比
paint);
} else {
canvas.drawText(percent + "%", centre - textWidth / 2, centre + textSize / 2, // 画出进度百分比
paint);
}
}
}Example 52
| Project: XKnow-master File: ColorPickerDialog.java View source code |
@Override
protected void onDraw(Canvas canvas) {
float r = CENTER_X - mPaint.getStrokeWidth() * 0.5f;
canvas.translate(CENTER_X, CENTER_X);
Shader s = new SweepGradient(0, 0, mColors, null);
mPaint.setShader(s);
canvas.drawOval(new RectF(-r, -r, r, r), mPaint);
canvas.drawCircle(0, 0, CENTER_RADIUS, mCenterPaint);
canvas.drawRect(new RectF(r + mPaint.getStrokeWidth() + DIVIDER_PAD, -r, r + mPaint.getStrokeWidth() + DIVIDER_PAD + SATURATION_STRIPE, r), mSaturationPaint);
canvas.drawRect(new RectF(-r, r + mPaint.getStrokeWidth() + DIVIDER_PAD, r, r + mPaint.getStrokeWidth() + DIVIDER_PAD + SATURATION_STRIPE), mValuePaint);
if (mTrackingCenter) {
int c = mCenterPaint.getColor();
mCenterPaint.setStyle(Paint.Style.STROKE);
if (mHighlightCenter) {
mCenterPaint.setAlpha(0xFF);
} else {
mCenterPaint.setAlpha(0x80);
}
canvas.drawCircle(0, 0, CENTER_RADIUS + mCenterPaint.getStrokeWidth(), mCenterPaint);
mCenterPaint.setStyle(Paint.Style.FILL);
mCenterPaint.setColor(c);
}
}Example 53
| Project: CircleProgressBar-master File: CircleProgressBar.java View source code |
/**
* The progress bar color gradient,
* need to be invoked in the {@link #onSizeChanged(int, int, int, int)}
*/
private void updateProgressShader() {
if (mProgressStartColor != mProgressEndColor) {
Shader shader = null;
switch(mShader) {
case LINEAR:
shader = new LinearGradient(mProgressRectF.left, mProgressRectF.top, mProgressRectF.left, mProgressRectF.bottom, mProgressStartColor, mProgressEndColor, Shader.TileMode.CLAMP);
break;
case RADIAL:
shader = new RadialGradient(mCenterX, mCenterY, mRadius, mProgressStartColor, mProgressEndColor, Shader.TileMode.CLAMP);
break;
case SWEEP:
//arc = radian * radius
float radian = (float) (mProgressStrokeWidth / Math.PI * 2.0f / mRadius);
float rotateDegrees = (float) (DEFAULT_START_DEGREE - (mCap == Paint.Cap.BUTT && mStyle == SOLID_LINE ? 0 : Math.toDegrees(radian)));
shader = new SweepGradient(mCenterX, mCenterY, new int[] { mProgressStartColor, mProgressEndColor }, new float[] { 0.0f, 1.0f });
Matrix matrix = new Matrix();
matrix.postRotate(rotateDegrees, mCenterX, mCenterY);
shader.setLocalMatrix(matrix);
break;
}
mProgressPaint.setShader(shader);
} else {
mProgressPaint.setShader(null);
mProgressPaint.setColor(mProgressStartColor);
}
}Example 54
| Project: CoolAndroidAnim-master File: ForthPellet.java View source code |
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mState = 2;
mCurValue = (int) animation.getAnimatedValue();
mDifValue = mCurValue - mPreValue;
if (mCurValue <= 180) {
mSeCurR += mDifValue * rate / 2;
mSeStrokeWidth -= mDifValue * rate;
mAngle = mCurValue * 3;
mSweepAngle -= mDifValue * 2;
} else {
mSweepAngle = 0;
positions[1] += (mCurValue - 180) * 0.01f;
mSweepGradient = new SweepGradient(getCurX(), getCurY(), colors, positions);
}
mPreValue = mCurValue;
}Example 55
| Project: CreditSesameRingView-master File: OldCreditSesameView.java View source code |
/**
* �始化
*/
private void init() {
//设置默认宽高值
defaultSize = dp2px(250);
//设置图片线�的抗锯齿
mPaintFlagsDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
//最外层圆环��画笔设置
mGradientRingPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
//设置圆环��色渲染
mGradientRingPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
float position[] = { 0.1f, 0.3f, 0.8f };
Shader mShader = new SweepGradient(width / 2, radius, mColors, position);
mGradientRingPaint.setShader(mShader);
mGradientRingPaint.setStrokeCap(Paint.Cap.ROUND);
mGradientRingPaint.setStyle(Paint.Style.STROKE);
mGradientRingPaint.setStrokeWidth(40);
//最外层圆环大�刻度画笔设置
mSmallCalibrationPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mSmallCalibrationPaint.setColor(Color.WHITE);
mSmallCalibrationPaint.setStyle(Paint.Style.STROKE);
mSmallCalibrationPaint.setStrokeWidth(1);
mBigCalibrationPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBigCalibrationPaint.setColor(Color.WHITE);
mBigCalibrationPaint.setStyle(Paint.Style.STROKE);
mBigCalibrationPaint.setStrokeWidth(4);
//ä¸é—´åœ†çŽ¯ç”»ç¬”è®¾ç½®
mMiddleRingPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mMiddleRingPaint.setStyle(Paint.Style.STROKE);
mMiddleRingPaint.setStrokeCap(Paint.Cap.ROUND);
mMiddleRingPaint.setStrokeWidth(5);
mMiddleRingPaint.setColor(GRAY_COLOR);
//内层圆环画笔设置
mInnerRingPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mInnerRingPaint.setStyle(Paint.Style.STROKE);
mInnerRingPaint.setStrokeCap(Paint.Cap.ROUND);
mInnerRingPaint.setStrokeWidth(4);
mInnerRingPaint.setColor(GRAY_COLOR);
PathEffect mPathEffect = new DashPathEffect(new float[] { 5, 5, 5, 5 }, 1);
mInnerRingPaint.setPathEffect(mPathEffect);
//外层圆环文本画笔设置
mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mTextPaint.setColor(GRAY_COLOR);
mTextPaint.setTextSize(30);
//ä¸é—´æ–‡å—画笔设置
mCenterTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterTextPaint.setTextAlign(Paint.Align.CENTER);
//ä¸é—´åœ†çŽ¯è¿›åº¦ç”»ç¬”è®¾ç½®
mMiddleProgressPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mMiddleProgressPaint.setColor(GREEN_COLOR);
mMiddleProgressPaint.setStrokeCap(Paint.Cap.ROUND);
mMiddleProgressPaint.setStrokeWidth(5);
mMiddleProgressPaint.setStyle(Paint.Style.STROKE);
//指针图片画笔
mPointerBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerBitmapPaint.setColor(GREEN_COLOR);
//获�指针图片
mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_pointer);
mBitmapHeight = mBitmap.getHeight();
mBitmapWidth = mBitmap.getWidth();
}Example 56
| Project: email-master File: ColorPicker.java View source code |
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, 48);
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);
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);
mAngle = (float) (-Math.PI / 2);
mPointerColor.setColor(calculateColor(mAngle));
}Example 57
| Project: k-9-master File: ColorPicker.java View source code |
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, 48);
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);
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);
mAngle = (float) (-Math.PI / 2);
mPointerColor.setColor(calculateColor(mAngle));
}Example 58
| Project: like_netease_news-master File: ColorPickerView.java View source code |
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, 48);
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);
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);
mAngle = (float) (-Math.PI / 2);
mPointerColor.setColor(calculateColor(mAngle));
}Example 59
| Project: CameraSDK-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
}Example 60
| Project: HoloColorPicker-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
}Example 61
| Project: Light-Controller-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
}Example 62
| Project: PhotoEditDemo-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
}Example 63
| Project: PictureTools-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
}Example 64
| Project: BlunoAccessoryShieldDemo-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness*3/2);
mColorWheelPaint.setStrokeWidth(mColorWheelThickness * 4 / 5);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
//0xff4dd5b5
mCenterCirclePaint.setColor(0xff707070);
mCenterCirclePaint.setStyle(Paint.Style.STROKE);
mCenterCirclePaint.setStrokeWidth((float) (mColorWheelThickness));
//Import font for the center Text
String fontPath = "fonts/yueregular.otf";
Typeface txtotf = Typeface.createFromAsset(getContext().getAssets(), fontPath);
mCenterCircleTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterCircleTextPaint.setColor(0xff1bdab1);
mCenterCircleTextPaint.setStyle(Paint.Style.FILL);
mCenterCircleTextPaint.setTextAlign(Align.CENTER);
mCenterCircleTextPaint.setTypeface(txtotf);
mCenterCircleTextPaint.setTextSize((float) (mColorCenterRadius * 0.5));
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
}Example 65
| Project: dejalist-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
}Example 66
| Project: firetweet-master File: ShapedImageView.java View source code |
private void updateBorderShader() {
final int[] colors = mBorderColors;
if (colors == null || colors.length == 0) {
mBorderAlpha = 0;
return;
}
mDestination.set(getPaddingLeft(), getPaddingTop(), getWidth() - getPaddingRight(), getHeight() - getPaddingBottom());
final float cx = mDestination.centerX(), cy = mDestination.centerY();
final int[] sweepColors = new int[colors.length * 2];
final float[] positions = new float[colors.length * 2];
for (int i = 0, j = colors.length; i < j; i++) {
sweepColors[i * 2] = sweepColors[i * 2 + 1] = colors[i];
positions[i * 2] = i == 0 ? 0 : i / (float) j;
positions[i * 2 + 1] = i == j - 1 ? 1 : (i + 1) / (float) j;
}
final SweepGradient shader = new SweepGradient(cx, cy, sweepColors, positions);
final Matrix matrix = new Matrix();
matrix.setRotate(90, cx, cy);
shader.setLocalMatrix(matrix);
mBorderPaint.setShader(shader);
}Example 67
| Project: katbag-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
}Example 68
| Project: synapse-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
}Example 69
| Project: WebChart-master File: ExerciseWebChart.java View source code |
//ç”»ä¸å¿ƒåœ†çš„内容
public void centerCircleContent(Canvas canvas) {
if (!centerWatchDag) {
return;
}
//画出颜色��的圆圈
canvas.rotate(140);
float centerSize = circleRadius - marginCircleSize * 3 - (circleRadius / 20);
mCenterCircle.setShader(new SweepGradient(0, 0, new int[] { friendColor, friendColor, standardColor, averageColor }, null));
canvas.drawCircle(0, 0, centerSize, mCenterCircle);
canvas.rotate(-140);
//画出è¿?åŠ¨çš„æ€»æ¥æ•°
mCenterCircle.setShader(null);
mCenterCircle.setColor(friendColor);
mCenterCircle.setTextSize(circleRadius / 4);
mCenterCircle.setTextAlign(Paint.Align.CENTER);
Rect numRect = new Rect();
mCenterCircle.getTextBounds(allStep, 0, allStep.length(), numRect);
Camera camera = new Camera();
camera.rotateY(centerData);
camera.applyToCanvas(canvas);
canvas.drawText(allStep, 0, (numRect.bottom - numRect.top) / 2, mCenterCircle);
//画出总è¿?åŠ¨æ¥æ•°å?³è¾¹çš„å—
Rect tipRect = new Rect();
mCenterCircle.setTextSize(circleRadius / 12);
mCenterCircle.getTextBounds(tip, 0, tip.length(), tipRect);
canvas.drawText(tip, (numRect.right - numRect.left) / 2 + (tipRect.right - tipRect.left) / 2 + 5, (numRect.bottom - numRect.top) / 2 - 3, mCenterCircle);
//画出总è¿?åŠ¨æ¥æ•°ä¸‹é?¢çš„æ??示
Rect theyRect = new Rect();
mCenterCircle.getTextBounds(theyCount, 0, theyCount.length(), theyRect);
float marginBottom = circleRadius / 12;
mCenterCircle.setTextSize(circleRadius / 11);
canvas.drawText(theyCount, 0, marginBottom + (numRect.bottom - numRect.top) / 2 + (theyRect.bottom - theyRect.top) / 2, mCenterCircle);
}Example 70
| Project: androGister-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
}Example 71
| Project: ArcProgressStackView-master File: ArcProgressStackView.java View source code |
@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);
}Example 72
| Project: folio100_frameworks_base-master File: GradientDrawable.java View source code |
/**
* 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();
}Example 73
| Project: HABDroid-master File: ColorPicker.java View source code |
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);
}Example 74
| Project: lifx-tasker-master File: ColorPicker.java View source code |
private void init(AttributeSet attrs, int defStyle) {
final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ColorPicker, defStyle, 0);
final Resources b = getContext().getResources();
mColorWheelThickness = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_thickness, b.getDimensionPixelSize(R.dimen.color_wheel_thickness));
mColorWheelRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_wheel_radius, b.getDimensionPixelSize(R.dimen.color_wheel_radius));
mPreferredColorWheelRadius = mColorWheelRadius;
mColorCenterRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_radius, b.getDimensionPixelSize(R.dimen.color_center_radius));
mPreferredColorCenterRadius = mColorCenterRadius;
mColorCenterHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_center_halo_radius, b.getDimensionPixelSize(R.dimen.color_center_halo_radius));
mPreferredColorCenterHaloRadius = mColorCenterHaloRadius;
mColorPointerRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_radius, b.getDimensionPixelSize(R.dimen.color_pointer_radius));
mColorPointerHaloRadius = a.getDimensionPixelSize(R.styleable.ColorPicker_color_pointer_halo_radius, b.getDimensionPixelSize(R.dimen.color_pointer_halo_radius));
a.recycle();
mAngle = (float) (-Math.PI / 2);
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(mColorWheelThickness);
mPointerHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerHaloPaint.setColor(Color.BLACK);
mPointerHaloPaint.setAlpha(0x50);
mPointerColor = new Paint(Paint.ANTI_ALIAS_FLAG);
mPointerColor.setColor(calculateColor(mAngle));
mCenterNewPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterNewPaint.setColor(calculateColor(mAngle));
mCenterNewPaint.setStyle(Paint.Style.FILL);
mCenterOldPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterOldPaint.setColor(calculateColor(mAngle));
mCenterOldPaint.setStyle(Paint.Style.FILL);
mCenterHaloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterHaloPaint.setColor(Color.BLACK);
mCenterHaloPaint.setAlpha(0x00);
mCenterNewColor = calculateColor(mAngle);
mCenterOldColor = calculateColor(mAngle);
mShowCenterOldColor = true;
}Example 75
| Project: mayloon-runtime-master File: GradientDrawable.java View source code |
/**
* 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, 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, 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();
}Example 76
| Project: MockTrade-master File: MockTradeFace.java View source code |
private void calcPerformanceGradient() {
Rect frame = getSurfaceHolder().getSurfaceFrame();
Shader shader = null;
if ((mPerformanceItems != null) && mPerformanceItems.size() > 0) {
float extent = getPerformanceExtent(mPerformanceItems.get(0).getValue().getMicroCents());
Calendar cal = Calendar.getInstance();
int size = mPerformanceItems.size();
int[] colors = new int[size];
float[] positions = new float[size];
cal.setTimeInMillis(mPerformanceItems.get(0).getTimestamp().getTime());
float startDegrees = getDegrees(cal);
for (int x = 0; x < size; x++) {
PerformanceItem item = mPerformanceItems.get(x);
long todayChange = item.getTodayChange().getMicroCents();
// todayChange = (long)(-extents + (extents * 2*x/size));
colors[x] = getPerformanceColor(todayChange, extent);
cal.setTimeInMillis(item.getTimestamp().getTime());
float calDegrees = getDegrees(cal);
if (calDegrees < startDegrees) {
calDegrees += 360;
}
positions[x] = (calDegrees - startDegrees) / 360.0f;
}
shader = new SweepGradient(frame.centerX(), frame.centerY(), colors, positions);
cal.setTimeInMillis(mPerformanceItems.get(size - 1).getTimestamp().getTime());
float calDegrees = getDegrees(cal);
if (calDegrees < mMarketOpenDegrees) {
calDegrees += 360;
}
mPerformanceDurationDegrees = calDegrees - mMarketOpenDegrees;
}
mMarketDayRingPaint.setShader(shader);
}Example 77
| Project: MySnippetRepo-master File: PieChart.java View source code |
/**
* Do all of the recalculations needed when the data array changes.
*/
private void onDataChanged() {
// When the data changes, we have to recalculate
// all of the angles.
int currentAngle = 0;
for (Item it : mData) {
it.mStartAngle = currentAngle;
it.mEndAngle = (int) ((float) currentAngle + it.mValue * 360.0f / mTotal);
currentAngle = it.mEndAngle;
// Recalculate the gradient shaders. There are
// three values in this gradient, even though only
// two are necessary, in order to work around
// a bug in certain versions of the graphics engine
// that expects at least three values if the
// positions array is non-null.
//
it.mShader = new SweepGradient(mPieBounds.width() / 2.0f, mPieBounds.height() / 2.0f, new int[] { it.mHighlight, it.mHighlight, it.mColor, it.mColor }, new float[] { 0, (float) (360 - it.mEndAngle) / 360.0f, (float) (360 - it.mStartAngle) / 360.0f, 1.0f });
}
calcCurrentItem();
onScrollFinished();
}Example 78
| Project: OpenHAB_Room_Flipper-master File: ColorPicker.java View source code |
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);
}Example 79
| Project: programming_notes_for_java_android-master File: PieChart.java View source code |
/**
* Do all of the recalculations needed when the data array changes.
*/
private void onDataChanged() {
// When the data changes, we have to recalculate
// all of the angles.
int currentAngle = 0;
for (Item it : mData) {
it.mStartAngle = currentAngle;
it.mEndAngle = (int) ((float) currentAngle + it.mValue * 360.0f / mTotal);
currentAngle = it.mEndAngle;
// Recalculate the gradient shaders. There are
// three values in this gradient, even though only
// two are necessary, in order to work around
// a bug in certain versions of the graphics engine
// that expects at least three values if the
// positions array is non-null.
//
it.mShader = new SweepGradient(mPieBounds.width() / 2.0f, mPieBounds.height() / 2.0f, new int[] { it.mHighlight, it.mHighlight, it.mColor, it.mColor }, new float[] { 0, (float) (360 - it.mEndAngle) / 360.0f, (float) (360 - it.mStartAngle) / 360.0f, 1.0f });
}
calcCurrentItem();
onScrollFinished();
}Example 80
| Project: XobotOS-master File: GradientDrawable.java View source code |
/**
* 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();
}Example 81
| Project: cnAndroidDocs-master File: GradientDrawable.java View source code |
/**
* 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));
if (!mGradientState.mHasSolidColor) {
mFillPaint.setColor(mAlpha << 24);
}
} 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));
if (!mGradientState.mHasSolidColor) {
mFillPaint.setColor(mAlpha << 24);
}
} 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));
if (!mGradientState.mHasSolidColor) {
mFillPaint.setColor(mAlpha << 24);
}
}
}
}
return !mRect.isEmpty();
}Example 82
| Project: Circle-Progress-View-master File: CircleProgressView.java View source code |
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 83
| Project: MiClockView-master File: ClockView.java View source code |
private void initProgressRing() {
paintProgressRing = new Paint(paintBgRing);
paintProgressRing.setColor(Color.WHITE);
sweepGradient = new SweepGradient(centerX, centerY, sweepGradientColors, sweepGradientColorPos);
paintProgressRing.setShader(sweepGradient);
}Example 84
| Project: Protocoder-master File: PCanvasView.java View source code |
public Shader sweepShader(int x, int y, String c1, String c2) {
Shader shader = new SweepGradient(x, y, Color.parseColor(c1), Color.parseColor(c2));
return shader;
}