本文整理汇总了Java中android.graphics.RadialGradient类的典型用法代码示例。如果您正苦于以下问题:Java RadialGradient类的具体用法?Java RadialGradient怎么用?Java RadialGradient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RadialGradient类属于android.graphics包,在下文中一共展示了RadialGradient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setup
import android.graphics.RadialGradient; //导入依赖的package包/类
public void setup(DisplayMetrics dm, DeviceProfile grid, View invalidateDelegate,
int availableSpace, int topPadding) {
mInvalidateDelegate = invalidateDelegate;
final int previewSize = grid.folderIconSizePx;
final int previewPadding = grid.folderIconPreviewPadding;
this.previewSize = (previewSize - 2 * previewPadding);
basePreviewOffsetX = (availableSpace - this.previewSize) / 2;
basePreviewOffsetY = previewPadding + grid.folderBackgroundOffset + topPadding;
// Stroke width is 1dp
mStrokeWidth = dm.density;
float radius = getScaledRadius();
float shadowRadius = radius + mStrokeWidth;
int shadowColor = Color.argb(SHADOW_OPACITY, 0, 0, 0);
mShadowShader = new RadialGradient(0, 0, 1,
new int[] {shadowColor, Color.TRANSPARENT},
new float[] {radius / shadowRadius, 1},
Shader.TileMode.CLAMP);
invalidate();
}
示例2: drawScanLine
import android.graphics.RadialGradient; //导入依赖的package包/类
private void drawScanLine(Canvas canvas, Rect frame) {
Shader shader = new RadialGradient(
(float)(frame.left + frame.width() / 2),
(float)(scannerStart + SCANNER_LINE_HEIGHT / 2),
360f,
laserColor,
shadeColor(laserColor),
Shader.TileMode.MIRROR);
paint.setAlpha(CURRENT_POINT_OPACITY);
paint.setShader(shader);
if (scannerStart <= scannerEnd) {
canvas.drawRect(frame.left, scannerStart, frame.right, scannerStart + SCANNER_LINE_HEIGHT, paint);
scannerStart += SCANNER_LINE_MOVE_DISTANCE;
} else {
scannerStart = frame.top;
}
paint.setShader(null);
}
示例3: createColorWheelBitmap
import android.graphics.RadialGradient; //导入依赖的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;
}
示例4: createColorDiscBitmap
import android.graphics.RadialGradient; //导入依赖的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;
}
示例5: startLightAnimation
import android.graphics.RadialGradient; //导入依赖的package包/类
private void startLightAnimation() {
if (mLightAnimation == null) {
mLightAnimation = ObjectAnimator.ofFloat(10, getMeasuredWidth());
mLightAnimation.setRepeatCount(ValueAnimator.INFINITE);
mLightAnimation.setDuration(3000);
mLightAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
float lightMove = (float) animation.getAnimatedValue();
if (Math.abs(lightMove) < getMeasuredWidth()) {
mShader = new RadialGradient(lightMove, getMeasuredHeight() / 2, 90f
, new int[]{Color.WHITE, mBackgroudColor}, null, Shader.TileMode.CLAMP);
postInvalidate();
}
}
});
}
if (mLightAnimation != null && !mLightAnimation.isRunning()) {
mLightAnimation.start();
}
}
示例6: addBall
import android.graphics.RadialGradient; //导入依赖的package包/类
private ShapeHolder addBall(float x, float y) {
OvalShape circle = new OvalShape();
circle.resize(50f, 50f);
ShapeDrawable drawable = new ShapeDrawable(circle);
ShapeHolder shapeHolder = new ShapeHolder(drawable);
shapeHolder.setX(x - 25f);
shapeHolder.setY(y - 25f);
int red = (int)(Math.random() * 255);
int green = (int)(Math.random() * 255);
int blue = (int)(Math.random() * 255);
int color = 0xff000000 | red << 16 | green << 8 | blue;
Paint paint = drawable.getPaint(); //new Paint(Paint.ANTI_ALIAS_FLAG);
int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;
RadialGradient gradient = new RadialGradient(37.5f, 12.5f,
50f, color, darkColor, Shader.TileMode.CLAMP);
paint.setShader(gradient);
shapeHolder.setPaint(paint);
balls.add(shapeHolder);
return shapeHolder;
}
示例7: finishGradients
import android.graphics.RadialGradient; //导入依赖的package包/类
private void finishGradients() {
for(Gradient gradient : gradientMap.values()) {
if (gradient.xlink != null) {
Gradient parent = gradientMap.get(gradient.xlink);
if (parent != null) {
gradient.inherit(parent);
}
}
int[] colors = new int[gradient.colors.size()];
for (int i = 0; i < colors.length; i++) {
colors[i] = gradient.colors.get(i);
}
float[] positions = new float[gradient.positions.size()];
for (int i = 0; i < positions.length; i++) {
positions[i] = gradient.positions.get(i);
}
if (colors.length == 0) {
Log.d("BAD", "BAD gradient, id="+gradient.id);
}
if (gradient.isLinear) {
gradient.shader= new LinearGradient(gradient.x1, gradient.y1, gradient.x2, gradient.y2, colors, positions, gradient.tilemode);
} else {
gradient.shader= new RadialGradient(gradient.x, gradient.y, gradient.radius, colors, positions, gradient.tilemode);
}
}
}
示例8: setRadius
import android.graphics.RadialGradient; //导入依赖的package包/类
@AnimateMethod
public void setRadius(final float radius) {
rippleRadius = radius;
if (rippleRadius > 0) {
RadialGradient radialGradient = new RadialGradient(
downX,
downY,
rippleRadius * 3,
Color.TRANSPARENT,
Color.BLACK,
Shader.TileMode.MIRROR
);
ripplePaint.setShader(radialGradient);
}
invalidate();
}
示例9: draw
import android.graphics.RadialGradient; //导入依赖的package包/类
@Override
public void draw(Canvas canvas) {
if (keepShow||inMerge) {
canvas.save();
canvas.clipRect(getBounds());
mRectF.set(getBounds());
mRectF.inset(mOutlinePadding, mOutlinePadding);
if (mOutLineWidth > 0) {
mOutlinePaint.setStrokeWidth(mOutLineWidth);
mRectF.inset(mOutLineWidth, mOutLineWidth);
mOutlinePaint.setColor(mOutLineColor);
canvas.drawRoundRect(mRectF, mRadius, mRadius, mOutlinePaint);
}
// mPaint.setShader(new SweepGradient(mRectF.centerX(),mRectF.centerY(),mColors,mPositions));
mPaint.setShader(new RadialGradient(mRectF.centerX(), mRectF.centerY(), mRectF.width(), mCenterColor, mEdgeColor, Shader.TileMode.CLAMP));
canvas.drawRoundRect(mRectF, mRadius, mRadius, mPaint);
canvas.restore();
}
}
示例10: drawBeaconBackground
import android.graphics.RadialGradient; //导入依赖的package包/类
protected void drawBeaconBackground(Canvas canvas, Beacon beacon, PointF beaconCenter) {
float advertisingRadius = (float) canvasProjection.getCanvasUnitsFromMeters(beacon.getEstimatedAdvertisingRange());
Paint innerBeaconRangePaint = new Paint(beaconRangePaint);
innerBeaconRangePaint.setAlpha(100);
Shader rangeShader = new RadialGradient(
beaconCenter.x,
beaconCenter.y,
advertisingRadius - (pixelsPerDip * 0),
primaryFillPaint.getColor(), beaconRangePaint.getColor(),
Shader.TileMode.MIRROR);
innerBeaconRangePaint.setShader(rangeShader);
//canvas.drawCircle(beaconCenter.x, beaconCenter.y, advertisingRadius, innerBeaconRangePaint);
canvas.drawCircle(beaconCenter.x, beaconCenter.y, advertisingRadius, beaconRangePaint);
}
示例11: buildShadowCorners
import android.graphics.RadialGradient; //导入依赖的package包/类
private void buildShadowCorners() {
RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
RectF outerBounds = new RectF(innerBounds);
outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
if (this.mCornerShadowPath == null) {
this.mCornerShadowPath = new Path();
} else {
this.mCornerShadowPath.reset();
}
this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
this.mCornerShadowPath.close();
float startRatio = this.mCornerRadius / (this.mCornerRadius + this.mShadowSize);
this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, this.mCornerRadius + this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, 1.0f}, TileMode.CLAMP));
this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, (-this.mCornerRadius) + this.mShadowSize, 0.0f, (-this.mCornerRadius) - this.mShadowSize, new int[]{this.mShadowStartColor, this.mShadowStartColor, this.mShadowEndColor}, new float[]{0.0f, 0.5f, 1.0f}, TileMode.CLAMP));
this.mEdgeShadowPaint.setAntiAlias(false);
}
示例12: buildShadowCorners
import android.graphics.RadialGradient; //导入依赖的package包/类
private void buildShadowCorners() {
RectF innerBounds = new RectF(-this.mCornerRadius, -this.mCornerRadius, this.mCornerRadius, this.mCornerRadius);
RectF outerBounds = new RectF(innerBounds);
outerBounds.inset(-this.mShadowSize, -this.mShadowSize);
if (this.mCornerShadowPath == null) {
this.mCornerShadowPath = new Path();
} else {
this.mCornerShadowPath.reset();
}
this.mCornerShadowPath.setFillType(FillType.EVEN_ODD);
this.mCornerShadowPath.moveTo(-this.mCornerRadius, 0.0f);
this.mCornerShadowPath.rLineTo(-this.mShadowSize, 0.0f);
this.mCornerShadowPath.arcTo(outerBounds, 180.0f, 90.0f, false);
this.mCornerShadowPath.arcTo(innerBounds, 270.0f, -90.0f, false);
this.mCornerShadowPath.close();
float shadowRadius = -outerBounds.top;
if (shadowRadius > 0.0f) {
float startRatio = this.mCornerRadius / shadowRadius;
float midRatio = startRatio + ((1.0f - startRatio) / 2.0f);
this.mCornerShadowPaint.setShader(new RadialGradient(0.0f, 0.0f, shadowRadius, new int[]{0, this.mShadowStartColor, this.mShadowMiddleColor, this.mShadowEndColor}, new float[]{0.0f, startRatio, midRatio, 1.0f}, TileMode.CLAMP));
}
this.mEdgeShadowPaint.setShader(new LinearGradient(0.0f, innerBounds.top, 0.0f, outerBounds.top, new int[]{this.mShadowStartColor, this.mShadowMiddleColor, this.mShadowEndColor}, new float[]{0.0f, SHADOW_HORIZ_SCALE, 1.0f}, TileMode.CLAMP));
this.mEdgeShadowPaint.setAntiAlias(false);
}
示例13: drawLaserScanner
import android.graphics.RadialGradient; //导入依赖的package包/类
/**
* 绘制移动扫描线
* @param canvas
* @param frame
*/
private void drawLaserScanner(Canvas canvas, Rect frame) {
linePaint.setColor(laserColor);
radialGradient = new RadialGradient(
(float)(frame.left + frame.width() / 2),
(float)(scannerStart + SCANNER_LINE_HEIGHT / 2),
360f,
laserColor,
shadeColor(laserColor),
Shader.TileMode.MIRROR);
linePaint.setShader(radialGradient);
if(scannerStart < scannerEnd) {
rectF.set(frame.left + 2 * SCANNER_LINE_HEIGHT,
scannerStart, frame.right - 2 * SCANNER_LINE_HEIGHT,
scannerStart + SCANNER_LINE_HEIGHT);
canvas.drawOval(rectF, linePaint);
scannerStart += SCANNER_LINE_MOVE_DISTANCE;
} else {
scannerStart = frame.top;
}
linePaint.setShader(null);
radialGradient=null;
}
示例14: createShaderFactory
import android.graphics.RadialGradient; //导入依赖的package包/类
private ShapeDrawable.ShaderFactory createShaderFactory() {
return new ShapeDrawable.ShaderFactory() {
@Override
public Shader resize(int width, int height) {
switch (type) {
case RADIAL:
return new RadialGradient(parentWidth / 2,
parentHeight / 2, getParentRadius(),
upper, lower,
Shader.TileMode.CLAMP);
case LINEAR:
default:
return new LinearGradient(0, 0,
0, parentHeight,
upper, lower,
Shader.TileMode.CLAMP);
}
}
};
}
示例15: createColorWheelBitmap
import android.graphics.RadialGradient; //导入依赖的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;
}