本文整理汇总了Java中android.graphics.SweepGradient类的典型用法代码示例。如果您正苦于以下问题:Java SweepGradient类的具体用法?Java SweepGradient怎么用?Java SweepGradient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SweepGradient类属于android.graphics包,在下文中一共展示了SweepGradient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createColorWheelBitmap
import android.graphics.SweepGradient; //导入依赖的package包/类
private Bitmap createColorWheelBitmap(int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
int colorCount = 12;
int colorAngleStep = 360 / 12;
int colors[] = new int[colorCount + 1];
float hsv[] = new float[] { 0f, 1f, 1f };
for (int i = 0; i < colors.length; i++) {
hsv[0] = (i * colorAngleStep + 180) % 360;
colors[i] = Color.HSVToColor(hsv);
}
colors[colorCount] = colors[0];
SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);
colorWheelPaint.setShader(composeShader);
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);
return bitmap;
}
示例2: ColorPickerView
import android.graphics.SweepGradient; //导入依赖的package包/类
ColorPickerView(Context c, OnColorChangedListener l, int color) {
super(c);
mListener = l;
mColors = new int[]{
0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00,
0xFFFFFF00, 0xFFFF0000
};
Shader s = new SweepGradient(0, 0, mColors, null);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setShader(s);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(32);
mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterPaint.setColor(color);
mCenterPaint.setStrokeWidth(5);
}
示例3: createColorDiscBitmap
import android.graphics.SweepGradient; //导入依赖的package包/类
private Bitmap createColorDiscBitmap(int radius) {
int centerColor, edgeColor;
Bitmap bitmap = Bitmap.createBitmap(2 * radius, 2 * radius, Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
mHSV[0] = 0; mHSV[1] = 1; mHSV[2] = 1; //red
SweepGradient sweepGradient = new SweepGradient(radius, radius, getColors(mHSV), null);
mColorPaint.setShader(sweepGradient);
canvas.drawCircle(radius, radius, radius, mColorPaint);
mHSV[0] = 0; mHSV[1] = 0; mHSV[2] = 1; //white
centerColor = Color.HSVToColor(255, mHSV);
edgeColor = Color.HSVToColor(0, mHSV);
RadialGradient radialGradient = new RadialGradient(radius, radius, radius, centerColor, edgeColor, TileMode.CLAMP);
mColorPaint.setShader(radialGradient);
canvas.drawCircle(radius, radius, radius, mColorPaint);
return bitmap;
}
示例4: onSizeChanged
import android.graphics.SweepGradient; //导入依赖的package包/类
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mCx = w / 2;
mCy = h / 2;
mSweepGradient = new SweepGradient(mCx, mCy,
new int[]{Color.argb(25, 0, 255, 0),
Color.argb(80, 0, 255, 0),
Color.argb(200, 0, 255, 0)},
new float[]{0, 0.95f, 1.0f});
mPaint = new Paint();
mPaint.setShader(mSweepGradient);
mDividerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCircleDividerColor = Color.BLACK;
mCrossDividerColor = Color.WHITE;
mRadarBgColor = Color.rgb(154, 154, 154);
mDividerPaint.setColor(mCircleDividerColor);
mDividerPaint.setStrokeWidth(3);
mDividerPaint.setStyle(Paint.Style.STROKE);
}
示例5: drawCircle
import android.graphics.SweepGradient; //导入依赖的package包/类
private void drawCircle(Canvas canvas) {
canvas.save();
canvas.translate(getPaddingLeft(), getPaddingTop());
canvas.drawCircle(defaultCircleRadius, defaultCircleRadius, defaultCircleRadius, defaultCriclePaint);
mCenterPoint.x = defaultCircleRadius;
mCenterPoint.y = defaultCircleRadius;
canvas.rotate(270, mCenterPoint.x, mCenterPoint.y);
mSweepGradient = new SweepGradient(mCenterPoint.x, mCenterPoint.y, mGradientColors, null);
progressPaint.setShader(mSweepGradient);
canvas.drawArc(new RectF(0, 0, defaultCircleRadius * 2, defaultCircleRadius * 2), 1, 360 * currentAngle, false, progressPaint);
float currentDegreeFlag = 360 * currentAngle + extraDistance + 90;
float smallCircleX = 0, smallCircleY = 0;
float hudu = (float) Math.abs(Math.PI * currentDegreeFlag / 180);//Math.abs:绝对值 ,Math.PI:表示π , 弧度 = 度*π / 180
smallCircleX = (float) Math.abs(Math.sin(hudu) * defaultCircleRadius + defaultCircleRadius);
smallCircleY = (float) Math.abs(defaultCircleRadius - Math.cos(hudu) * defaultCircleRadius);
canvas.drawCircle(smallCircleX, smallCircleY, smallCircleRadius, smallCirclePaint);
canvas.drawCircle(smallCircleX, smallCircleY, smallCircleRadius - smallCircleStrokeWidth, smallCircleSolidePaint);//画小圆的实心
canvas.restore();
}
示例6: RadarView
import android.graphics.SweepGradient; //导入依赖的package包/类
public RadarView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context,attrs);
mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBgPaint.setColor(mRadarBackGroundColor);
mBgPaint.setStyle(Paint.Style.FILL);
mRadarPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mRadarPaint.setColor(mRadarCircleColor);
mRadarPaint.setStyle(Paint.Style.STROKE);
mRadarPaint.setStrokeWidth(2);
mRadarGradient = new SweepGradient(0,0,mRadarStartColor,mRadarEndColor);
mMatrix = new Matrix();
}
示例7: createColorWheelBitmap
import android.graphics.SweepGradient; //导入依赖的package包/类
private Bitmap createColorWheelBitmap(int width, int height) {
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
int colorCount = 12;
int colorAngleStep = 360 / 12;
int colors[] = new int[colorCount + 1];
float hsv[] = new float[]{0f, 1f, 1f};
for (int i = 0; i < colors.length; i++) {
hsv[0] = (i * colorAngleStep + 180) % 360;
colors[i] = Color.HSVToColor(hsv);
}
colors[colorCount] = colors[0];
SweepGradient sweepGradient = new SweepGradient(width / 2, height / 2, colors, null);
RadialGradient radialGradient = new RadialGradient(width / 2, height / 2, colorWheelRadius, 0xFFFFFFFF, 0x00FFFFFF, TileMode.CLAMP);
ComposeShader composeShader = new ComposeShader(sweepGradient, radialGradient, PorterDuff.Mode.SRC_OVER);
colorWheelPaint.setShader(composeShader);
Canvas canvas = new Canvas(bitmap);
canvas.drawCircle(width / 2, height / 2, colorWheelRadius, colorWheelPaint);
return bitmap;
}
示例8: init
import android.graphics.SweepGradient; //导入依赖的package包/类
private void init() {
mPaint = new Paint();
mPaint.setStrokeWidth(3);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setAntiAlias(true);
mPaint.setColor(0xFFD72E1F);
mGradientPaint = new Paint();
mGradientPaint.setStrokeWidth(3);
mGradientPaint.setAntiAlias(true);
mGradientPaint.setColor(0xFFBC131F);
SweepGradient shader = new SweepGradient(mWidth / 2, mHeight / 2, Color.TRANSPARENT, 0xFFD72E1F);
mGradientPaint.setShader(shader);
rotateMatrix = new Matrix();
}
示例9: init
import android.graphics.SweepGradient; //导入依赖的package包/类
/**
* 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);
}
示例10: configurePaintParams
import android.graphics.SweepGradient; //导入依赖的package包/类
private void configurePaintParams() {
int delta = (numberOfRings * outerRingsSpacingPx + innerRingRadiousPx * 2) / 2;
radarShadowBoundsRectF =
new RectF(viewWidth / 2 - delta, viewHeight / 2 - delta, viewWidth / 2 + delta,
viewHeight / 2 + delta);
innerLoadingViewBoundsRecF =
new RectF(viewWidth / 2 - innerRingRadiousPx, viewHeight / 2 - innerRingRadiousPx,
viewWidth / 2 + innerRingRadiousPx, viewHeight / 2 + innerRingRadiousPx);
int colors[] = {
Color.parseColor("#b5615e"), Color.parseColor("#b5a15c"), Color.parseColor("#93bb5c"),
Color.parseColor("#b5615e")
};
float[] positions = { 0f, .25f, .50f, .95f };
innerLoadingGradientPaint.setShader(
new SweepGradient(viewWidth / 2, viewHeight / 2, colors, positions));
shadowPaint.setShadowLayer(10.0f, 0.0f, 2.0f, Color.BLACK);
int colors2[] = { Color.TRANSPARENT, Color.GRAY };
float[] positions2 = { 0f, .90f, };
radarFillSectionPaint.setShader(
new SweepGradient(viewWidth / 2, viewHeight / 2, colors2, positions2));
}
示例11: ColorPickerView
import android.graphics.SweepGradient; //导入依赖的package包/类
ColorPickerView(Context c, OnColorChangedListener l, int color, int pickerViewRadius, int pickerCentreRadius) {
super(c);
CENTER_X = pickerViewRadius * 2;
CENTER_Y = pickerViewRadius * 2;
CENTER_RADIUS = pickerCentreRadius;
mListener = l;
mColors = new int[]{
0xFFFF0000, 0xFFFF00FF, 0xFFFFFFFF, 0xFF000000, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00,
0xFFFFFF00, 0xFFFF0000
};
Shader s = new SweepGradient(0, 0, mColors, null);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setShader(s);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setAlpha(0x99);
mPaint.setStrokeWidth((float) 0.6 * pickerViewRadius);
mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterPaint.setColor(color);
//mPaint.setAlpha(0x99);
mCenterPaint.setStrokeWidth((float) 0.10 * pickerCentreRadius);
}
示例12: ColorPickerView
import android.graphics.SweepGradient; //导入依赖的package包/类
ColorPickerView(Context c, int color) {
super(c);
mColors = new int[] {
0xFFFF0000, 0xFFFF00FF, 0xFF0000FF, 0xFF00FFFF, 0xFF00FF00,
0xFFFFFFFF, 0xFF000000, 0xFFFFFF00, 0xFFFF0000
};
Shader s = new SweepGradient(0, 0, mColors, null);
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setShader(s);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(32);
mCenterPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCenterPaint.setColor(color);
mCenterPaint.setStrokeWidth(5);
alpha = Color.alpha(color);
}
示例13: drawBackgroundArc
import android.graphics.SweepGradient; //导入依赖的package包/类
private void drawBackgroundArc(Canvas canvas, float centerX, float centerY, int radius, double angle) {
if (decoration != Decoration.MINUTE_HAND) return;
canvas.save();
paint.setAlpha(70);
paint.setColorFilter(customColorFilter);
final int[] colors = {Color.TRANSPARENT, Color.WHITE};
final float[] positions = {0.5f, 1.f};
Shader gradient = new SweepGradient(centerX, centerY, colors, positions);
float rotate = (float) radiansToDegrees(angle);
Matrix gradientMatrix = new Matrix();
gradientMatrix.preRotate(rotate, centerX, centerY);
gradient.setLocalMatrix(gradientMatrix);
paint.setShader(gradient);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawCircle(centerX, centerY, handLengthMinutes * radius, paint);
paint.setShader(null);
canvas.restore();
}
示例14: ColorPickerView
import android.graphics.SweepGradient; //导入依赖的package包/类
/**
* @param context
* @param listener
* @param color
*/
ColorPickerView(Context context, T16RGBAdvancedFragment.OnColorChangedListener listener, int color, RelativeLayout canv, SoulissTypical16AdvancedRGB typ) {
super(context);
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setShader(new SweepGradient(0, 0, colors, null));
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(STROKE_WIDTH);
centerPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
centerPaint.setColor(color);
centerPaint.setStrokeWidth(5);
dialogColorChangedListener = listener;
colorSwitchRelativeLayout = canv;
collected = typ;
}
示例15: onCursorsMoved
import android.graphics.SweepGradient; //导入依赖的package包/类
public void onCursorsMoved(IntervalSlider i, float leftMovement,
float rightMovement) {
setLeftText(getLeftTime().toString());
setRightText(getRightTime().toString());
int colors[] = new int[] {0xFF000000, 0xFF000000, m_color, m_color};
Shader s = new SweepGradient(0, 0, colors, null);
s = new LinearGradient(
getLeftPos()*getWidth()-0.1F, 0,
getRightPos()*getWidth()+0.1F, 0,
0xFF000000, m_color,
Shader.TileMode.CLAMP);
m_paint.setShader(s);
setRectPaint(m_paint);
if((leftMovement != 0.0F || rightMovement != 0.0F) &&
(m_timesChangedListener != null))
{
m_timesChangedListener.onTimesChanged((TimeSlider) i);
}
}