use of android.graphics.LinearGradient in project android_frameworks_base by AOSPA.
the class FakeShadowDrawable method buildShadowCorners.
private void buildShadowCorners() {
RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
RectF outerBounds = new RectF(innerBounds);
outerBounds.inset(-mShadowSize, -mShadowSize);
if (mCornerShadowPath == null) {
mCornerShadowPath = new Path();
} else {
mCornerShadowPath.reset();
}
mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
mCornerShadowPath.moveTo(-mCornerRadius, 0);
mCornerShadowPath.rLineTo(-mShadowSize, 0);
// outer arc
mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
// inner arc
mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
mCornerShadowPath.close();
float startRatio = mCornerRadius / (mCornerRadius + mShadowSize);
mCornerShadowPaint.setShader(new RadialGradient(0, 0, mCornerRadius + mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP));
// we offset the content shadowSize/2 pixels up to make it more realistic.
// this is why edge shadow shader has some extra space
// When drawing bottom edge shadow, we use that extra space.
mEdgeShadowPaint.setShader(new LinearGradient(0, -mCornerRadius + mShadowSize, 0, -mCornerRadius - mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP));
}
use of android.graphics.LinearGradient in project ABPlayer by winkstu.
the class ColorPickerView method drawHuePanel.
private void drawHuePanel(Canvas canvas) {
final RectF rect = mHueRect;
if (BORDER_WIDTH_PX > 0) {
mBorderPaint.setColor(mBorderColor);
canvas.drawRect(rect.left - BORDER_WIDTH_PX, rect.top - BORDER_WIDTH_PX, rect.right + BORDER_WIDTH_PX, rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
}
if (mHueShader == null) {
mHueShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom, buildHueColorArray(), null, TileMode.CLAMP);
mHuePaint.setShader(mHueShader);
}
canvas.drawRect(rect, mHuePaint);
float rectHeight = 4 * mDensity / 2;
Point p = hueToPoint(mHue);
RectF r = new RectF();
r.left = rect.left - RECTANGLE_TRACKER_OFFSET;
r.right = rect.right + RECTANGLE_TRACKER_OFFSET;
r.top = p.y - rectHeight;
r.bottom = p.y + rectHeight;
canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
}
use of android.graphics.LinearGradient in project Lightning-Browser by anthonycr.
the class Utils method drawTrapezoid.
/**
* Draws the trapezoid background for the horizontal tabs on a canvas object using
* the specified color.
*
* @param canvas the canvas to draw upon
* @param color the color to use to draw the tab
*/
public static void drawTrapezoid(@NonNull Canvas canvas, int color, boolean withShader) {
Paint paint = new Paint();
paint.setColor(color);
paint.setStyle(Paint.Style.FILL);
// paint.setFilterBitmap(true);
paint.setAntiAlias(true);
paint.setDither(true);
if (withShader) {
paint.setShader(new LinearGradient(0, 0.9f * canvas.getHeight(), 0, canvas.getHeight(), color, mixTwoColors(Color.BLACK, color, 0.5f), Shader.TileMode.CLAMP));
} else {
paint.setShader(null);
}
int width = canvas.getWidth();
int height = canvas.getHeight();
double radians = Math.PI / 3;
int base = (int) (height / Math.tan(radians));
Path wallpath = new Path();
wallpath.reset();
wallpath.moveTo(0, height);
wallpath.lineTo(width, height);
wallpath.lineTo(width - base, 0);
wallpath.lineTo(base, 0);
wallpath.close();
canvas.drawPath(wallpath, paint);
}
use of android.graphics.LinearGradient in project muzei by romannurik.
the class ScrimUtil method makeCubicGradientScrimDrawable.
/**
* Creates an approximated cubic gradient using a multi-stop linear gradient. See
* <a href="https://plus.google.com/+RomanNurik/posts/2QvHVFWrHZf">this post</a> for more
* details.
*/
public static Drawable makeCubicGradientScrimDrawable(int baseColor, int numStops, int gravity) {
// Generate a cache key by hashing together the inputs, based on the method described in the Effective Java book
int cacheKeyHash = baseColor;
cacheKeyHash = 31 * cacheKeyHash + numStops;
cacheKeyHash = 31 * cacheKeyHash + gravity;
Drawable cachedGradient = cubicGradientScrimCache.get(cacheKeyHash);
if (cachedGradient != null) {
return cachedGradient;
}
numStops = Math.max(numStops, 2);
PaintDrawable paintDrawable = new PaintDrawable();
paintDrawable.setShape(new RectShape());
final int[] stopColors = new int[numStops];
int red = Color.red(baseColor);
int green = Color.green(baseColor);
int blue = Color.blue(baseColor);
int alpha = Color.alpha(baseColor);
for (int i = 0; i < numStops; i++) {
float x = i * 1f / (numStops - 1);
float opacity = MathUtil.constrain(0, 1, (float) Math.pow(x, 3));
stopColors[i] = Color.argb((int) (alpha * opacity), red, green, blue);
}
final float x0, x1, y0, y1;
switch(gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.LEFT:
x0 = 1;
x1 = 0;
break;
case Gravity.RIGHT:
x0 = 0;
x1 = 1;
break;
default:
x0 = 0;
x1 = 0;
break;
}
switch(gravity & Gravity.VERTICAL_GRAVITY_MASK) {
case Gravity.TOP:
y0 = 1;
y1 = 0;
break;
case Gravity.BOTTOM:
y0 = 0;
y1 = 1;
break;
default:
y0 = 0;
y1 = 0;
break;
}
paintDrawable.setShaderFactory(new ShapeDrawable.ShaderFactory() {
@Override
public Shader resize(int width, int height) {
return new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null, Shader.TileMode.CLAMP);
}
});
cubicGradientScrimCache.put(cacheKeyHash, paintDrawable);
return paintDrawable;
}
use of android.graphics.LinearGradient in project JustAndroid by chinaltz.
the class AbHorizontalProgressBar method onDraw.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (reset) {
canvas.drawColor(Color.TRANSPARENT);
reset = false;
}
this.width = getMeasuredWidth();
this.height = getMeasuredHeight();
// 设置画笔颜色
pathPaint.setColor(pathColor);
// 设置画笔宽度
pathPaint.setStrokeWidth(pathWidth);
//添加浮雕效果
pathPaint.setMaskFilter(emboss);
canvas.drawRect(0, 0, this.width, this.height, pathPaint);
pathPaint.setColor(pathBorderColor);
canvas.drawRect(0, 0, this.width, this.height, pathPaint);
LinearGradient linearGradient = new LinearGradient(0, 0, this.width, this.height, fillColors[0], fillColors[1], TileMode.CLAMP);
fillPaint.setShader(linearGradient);
//模糊效果
fillPaint.setMaskFilter(mBlur);
//设置线的类型,边是圆的
fillPaint.setStrokeCap(Paint.Cap.ROUND);
fillPaint.setStrokeWidth(pathWidth);
canvas.drawRect(0, 0, ((float) progress / max) * this.width, this.height, fillPaint);
}
Aggregations