use of android.graphics.Shader in project iosched by google.
the class UIUtils method makeCubicGradientScrimDrawable.
// private static final float[] mAlphaMatrixValues = {
// 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0,
// 0, 0, 0, 1, 0
// };
// private static final ColorMatrix mMultiplyBlendMatrix = new ColorMatrix();
// private static final float[] mMultiplyBlendMatrixValues = {
// 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0,
// 0, 0, 0, 0, 0,
// 0, 0, 0, 1, 0
// };
// private static final ColorMatrix mWhitenessColorMatrix = new ColorMatrix();
//
// /**
// * Simulates alpha blending an image with {@param color}.
// */
// private static ColorMatrix alphaMatrix(float alpha, int color) {
// mAlphaMatrixValues[0] = 255 * alpha / 255;
// mAlphaMatrixValues[6] = Color.green(color) * alpha / 255;
// mAlphaMatrixValues[12] = Color.blue(color) * alpha / 255;
// mAlphaMatrixValues[4] = 255 * (1 - alpha);
// mAlphaMatrixValues[9] = 255 * (1 - alpha);
// mAlphaMatrixValues[14] = 255 * (1 - alpha);
// mWhitenessColorMatrix.set(mAlphaMatrixValues);
// return mWhitenessColorMatrix;
// }
// /**
// * Simulates multiply blending an image with a single {@param color}.
// *
// * Multiply blending is [Sa * Da, Sc * Dc]. See {@link android.graphics.PorterDuff}.
// */
// private static ColorMatrix multiplyBlendMatrix(int color, float alpha) {
// mMultiplyBlendMatrixValues[0] = multiplyBlend(Color.red(color), alpha);
// mMultiplyBlendMatrixValues[6] = multiplyBlend(Color.green(color), alpha);
// mMultiplyBlendMatrixValues[12] = multiplyBlend(Color.blue(color), alpha);
// mMultiplyBlendMatrix.set(mMultiplyBlendMatrixValues);
// return mMultiplyBlendMatrix;
// }
//
// private static float multiplyBlend(int color, float alpha) {
// return color * alpha / 255.0f + (1 - alpha);
// }
/**
* This helper method creates a 'nice' scrim or background protection for layering text over an
* image. This non-linear scrim is less noticable than a linear or constant one.
* <p/>
* Borrowed from github.com/romannurik/muzei
* <p/>
* 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) {
numStops = Math.max(numStops, 2);
PaintDrawable paintDrawable = new PaintDrawable();
paintDrawable.setShape(new RectShape());
final int[] stopColors = new int[numStops];
int alpha = Color.alpha(baseColor);
for (int i = 0; i < numStops; i++) {
double x = i * 1f / (numStops - 1);
double opacity = Math.max(0, Math.min(1, Math.pow(x, 3)));
stopColors[i] = (baseColor & 0x00ffffff) | ((int) (alpha * opacity) << 24);
}
final float x0, x1, y0, y1;
switch(gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
// noinspection RtlHardcoded
case Gravity.LEFT:
x0 = 1;
x1 = 0;
break;
// noinspection RtlHardcoded
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) {
LinearGradient linearGradient = new LinearGradient(width * x0, height * y0, width * x1, height * y1, stopColors, null, Shader.TileMode.CLAMP);
return linearGradient;
}
});
return paintDrawable;
}
use of android.graphics.Shader in project FBReaderJ by geometer.
the class AmbilWarnaKotak method onDraw.
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (paint == null) {
paint = new Paint();
luar = new LinearGradient(0.f, 0.f, 0.f, this.getMeasuredHeight(), 0xffffffff, 0xff000000, TileMode.CLAMP);
}
int rgb = Color.HSVToColor(color);
Shader dalam = new LinearGradient(0.f, 0.f, this.getMeasuredWidth(), 0.f, 0xffffffff, rgb, TileMode.CLAMP);
ComposeShader shader = new ComposeShader(luar, dalam, PorterDuff.Mode.MULTIPLY);
paint.setShader(shader);
canvas.drawRect(0.f, 0.f, this.getMeasuredWidth(), this.getMeasuredHeight(), paint);
}
use of android.graphics.Shader in project lottie-android by airbnb.
the class GradientFillContent method draw.
@Override
public void draw(Canvas canvas, Matrix parentMatrix, int parentAlpha) {
if (hidden) {
return;
}
L.beginSection("GradientFillContent#draw");
path.reset();
for (int i = 0; i < paths.size(); i++) {
path.addPath(paths.get(i).getPath(), parentMatrix);
}
path.computeBounds(boundsRect, false);
Shader shader;
if (type == GradientType.LINEAR) {
shader = getLinearGradient();
} else {
shader = getRadialGradient();
}
shader.setLocalMatrix(parentMatrix);
paint.setShader(shader);
if (colorFilterAnimation != null) {
paint.setColorFilter(colorFilterAnimation.getValue());
}
if (blurAnimation != null) {
float blurRadius = blurAnimation.getValue();
if (blurRadius == 0f) {
paint.setMaskFilter(null);
} else if (blurRadius != blurMaskFilterRadius) {
BlurMaskFilter blur = new BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.NORMAL);
paint.setMaskFilter(blur);
}
blurMaskFilterRadius = blurRadius;
}
if (dropShadowAnimation != null) {
dropShadowAnimation.applyTo(paint);
}
int alpha = (int) ((parentAlpha / 255f * opacityAnimation.getValue() / 100f) * 255);
paint.setAlpha(clamp(alpha, 0, 255));
canvas.drawPath(path, paint);
L.endSection("GradientFillContent#draw");
}
use of android.graphics.Shader in project android-floating-action-button by futuresimple.
the class FloatingActionButton method createInnerStrokesDrawable.
private Drawable createInnerStrokesDrawable(final int color, float strokeWidth) {
if (!mStrokeVisible) {
return new ColorDrawable(Color.TRANSPARENT);
}
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
final int bottomStrokeColor = darkenColor(color);
final int bottomStrokeColorHalfTransparent = halfTransparent(bottomStrokeColor);
final int topStrokeColor = lightenColor(color);
final int topStrokeColorHalfTransparent = halfTransparent(topStrokeColor);
final Paint paint = shapeDrawable.getPaint();
paint.setAntiAlias(true);
paint.setStrokeWidth(strokeWidth);
paint.setStyle(Style.STROKE);
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 CustomShapeImageView by MostafaGazar.
the class SVGHandlerTest method testDoFill_byURL_shaderNotFound.
@Test
public void testDoFill_byURL_shaderNotFound() {
// given
HashMap<String, Shader> gradients = new HashMap<>();
Shader shader = mock(Shader.class);
gradients.put("gr1", shader);
// when
boolean res = parserHandler.doFill(new SVGParser.Properties(attributes(attr("fill", "#gr2)"))), gradients);
// then
assertThat(res, is(false));
}
Aggregations