use of android.graphics.Shader in project KeepScore by nolanlawson.
the class TopDownGradientSpan method updateDrawState.
@Override
public void updateDrawState(TextPaint ds) {
Shader shader = new LinearGradient(0, mStartY, 0, mEndY, new int[] { mStartColor, mEndColor }, null, TileMode.CLAMP);
ds.setShader(shader);
}
use of android.graphics.Shader in project shimmer-android by facebook.
the class ShimmerDrawable method updateShader.
private void updateShader() {
final Rect bounds = getBounds();
final int boundsWidth = bounds.width();
final int boundsHeight = bounds.height();
if (boundsWidth == 0 || boundsHeight == 0 || mShimmer == null) {
return;
}
final int width = mShimmer.width(boundsWidth);
final int height = mShimmer.height(boundsHeight);
final Shader shader;
switch(mShimmer.shape) {
default:
case Shimmer.Shape.LINEAR:
boolean vertical = mShimmer.direction == Shimmer.Direction.TOP_TO_BOTTOM || mShimmer.direction == Shimmer.Direction.BOTTOM_TO_TOP;
int endX = vertical ? 0 : width;
int endY = vertical ? height : 0;
shader = new LinearGradient(0, 0, endX, endY, mShimmer.colors, mShimmer.positions, Shader.TileMode.CLAMP);
break;
case Shimmer.Shape.RADIAL:
shader = new RadialGradient(width / 2f, height / 2f, (float) (Math.max(width, height) / Math.sqrt(2)), mShimmer.colors, mShimmer.positions, Shader.TileMode.CLAMP);
break;
}
mShimmerPaint.setShader(shader);
}
use of android.graphics.Shader in project PhotoNoter by yydcdut.
the class FloatingActionButton method createInnerStrokesDrawable.
/**
* 创建内层drawable
*
* @param color
* @param strokeWidth
* @return
*/
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
// 不描边的话直接返回一个颜色为透明的drawable
if (!mStrokeVisible) {
return new ColorDrawable(Color.TRANSPARENT);
}
// 圆 drawable
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
// 这个暗颜色
final int bottomStrokeColor = darkenColor(color);
// 比bottomStrokeColor透明一半
final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
// 这个亮颜色
final int topStrokeColor = lightenColor(color);
// 比topStrokeColor透明一半
final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
final Paint paint = shapeDrawable.getPaint();
// 锯齿
paint.setAntiAlias(true);
// 描边宽度
paint.setStrokeWidth(strokeWidth);
// 描边
paint.setStyle(Style.STROKE);
// draws a linear gradient
shapeDrawable.setShaderFactory(new ShaderFactory() {
@Override
public Shader resize(int width, int height) {
return new LinearGradient(width / 2, 0, width / 2, height, new int[] { topStrokeColor, topStrokeColorHalfTransparent, color, bottomStrokeColorHalfTransparent, bottomStrokeColor }, new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f }, TileMode.CLAMP);
}
});
return shapeDrawable;
}
use of android.graphics.Shader in project lottie-android by airbnb.
the class GradientStrokeContent method draw.
@Override
public void draw(Canvas canvas, Matrix parentMatrix, int parentAlpha) {
if (hidden) {
return;
}
getBounds(boundsRect, parentMatrix, false);
Shader shader;
if (type == GradientType.LINEAR) {
shader = getLinearGradient();
} else {
shader = getRadialGradient();
}
shader.setLocalMatrix(parentMatrix);
paint.setShader(shader);
super.draw(canvas, parentMatrix, parentAlpha);
}
use of android.graphics.Shader in project assertj-android by square.
the class AbstractPaintAssert method hasShader.
public S hasShader(Shader shader) {
isNotNull();
Shader actualShader = actual.getShader();
//
assertThat(actualShader).overridingErrorMessage("Expected shader <%s> but was <%s>.", shader, //
actualShader).isSameAs(shader);
return myself;
}
Aggregations