use of android.graphics.LinearGradient 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) {
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) {
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.LinearGradient in project lottie-android by airbnb.
the class GradientFillContent method getGradient.
private LinearGradient getGradient() {
int gradientHash = getGradientHash();
LinearGradient gradient = gradientCache.get(gradientHash);
if (gradient != null) {
return gradient;
}
PointF startPoint = startPointAnimation.getValue();
PointF endPoint = endPointAnimation.getValue();
GradientColor gradientColor = colorAnimation.getValue();
int[] colors = gradientColor.getColors();
float[] positions = gradientColor.getPositions();
int x0 = (int) (boundsRect.left + boundsRect.width() / 2 + startPoint.x);
int y0 = (int) (boundsRect.top + boundsRect.height() / 2 + startPoint.y);
int x1 = (int) (boundsRect.left + boundsRect.width() / 2 + endPoint.x);
int y1 = (int) (boundsRect.top + boundsRect.height() / 2 + endPoint.y);
gradient = new LinearGradient(x0, y0, x1, y1, colors, positions, Shader.TileMode.CLAMP);
gradientCache.put(gradientHash, gradient);
return gradient;
}
use of android.graphics.LinearGradient in project platform_frameworks_base by android.
the class DecorView method initResizingPaints.
private void initResizingPaints() {
final int startColor = mContext.getResources().getColor(R.color.resize_shadow_start_color, null);
final int endColor = mContext.getResources().getColor(R.color.resize_shadow_end_color, null);
final int middleColor = (startColor + endColor) / 2;
mHorizontalResizeShadowPaint.setShader(new LinearGradient(0, 0, 0, mResizeShadowSize, new int[] { startColor, middleColor, endColor }, new float[] { 0f, 0.3f, 1f }, Shader.TileMode.CLAMP));
mVerticalResizeShadowPaint.setShader(new LinearGradient(0, 0, mResizeShadowSize, 0, new int[] { startColor, middleColor, endColor }, new float[] { 0f, 0.3f, 1f }, Shader.TileMode.CLAMP));
}
use of android.graphics.LinearGradient in project plaid by nickbutcher.
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(@ColorInt 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++) {
float x = i * 1f / (numStops - 1);
float opacity = MathUtils.constrain(0, 1, (float) Math.pow(x, 3));
stopColors[i] = ColorUtils.modifyAlpha(baseColor, (int) (alpha * opacity));
}
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) {
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.LinearGradient in project mobile-android by photo.
the class Wheel method makeBitmapIndicator.
/**
* Make bitmap indicator.
*
* @param width
* the width
* @param height
* the height
* @return the bitmap
*/
private static Bitmap makeBitmapIndicator(int width, int height) {
float ellipse = width / 2;
float h = (float) height;
float y = (h + 10.0f) / 10.0f;
float y2 = y * 2.5f;
Bitmap bm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bm);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setDither(true);
p.setColor(0xFF666666);
RectF rect = new RectF(0, y, width, height - y2);
c.drawRoundRect(rect, ellipse, ellipse, p);
p.setColor(0xFFFFFFFF);
rect = new RectF(0, y2, width, height - y);
c.drawRoundRect(rect, ellipse, ellipse, p);
rect = new RectF(0, y + 2, width, height - (y + 2));
int[] colors = { 0xFF0076E7, 0xFF00BBFF, 0xFF0076E7 };
float[] positions = { 0f, 0.5f, 1f };
LinearGradient gradient = new LinearGradient(0, 0, width, 0, colors, positions, TileMode.REPEAT);
p.setShader(gradient);
c.drawRoundRect(rect, ellipse, ellipse, p);
return bm;
}
Aggregations