use of android.graphics.LinearGradient in project android_packages_apps_crDroidSettings by crdroidandroid.
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.LinearGradient in project platform_frameworks_base by android.
the class RectShadowPainter method paintShadow.
public static void paintShadow(Outline viewOutline, float elevation, Canvas canvas) {
Rect outline = new Rect();
if (!viewOutline.getRect(outline)) {
throw new IllegalArgumentException("Outline is not a rect shadow");
}
float shadowSize = elevationToShadow(elevation);
int saved = modifyCanvas(canvas, shadowSize);
if (saved == -1) {
return;
}
try {
Paint cornerPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
cornerPaint.setStyle(Style.FILL);
Paint edgePaint = new Paint(cornerPaint);
edgePaint.setAntiAlias(false);
float radius = viewOutline.getRadius();
float outerArcRadius = radius + shadowSize;
int[] colors = { START_COLOR, START_COLOR, END_COLOR };
cornerPaint.setShader(new RadialGradient(0, 0, outerArcRadius, colors, new float[] { 0f, radius / outerArcRadius, 1f }, TileMode.CLAMP));
edgePaint.setShader(new LinearGradient(0, 0, -shadowSize, 0, START_COLOR, END_COLOR, TileMode.CLAMP));
Path path = new Path();
path.setFillType(FillType.EVEN_ODD);
// A rectangle bounding the complete shadow.
RectF shadowRect = new RectF(outline);
shadowRect.inset(-shadowSize, -shadowSize);
// A rectangle with edges corresponding to the straight edges of the outline.
RectF inset = new RectF(outline);
inset.inset(radius, radius);
// A rectangle used to represent the edge shadow.
RectF edgeShadowRect = new RectF();
// left and right sides.
edgeShadowRect.set(-shadowSize, 0f, 0f, inset.height());
// Left shadow
sideShadow(canvas, edgePaint, edgeShadowRect, outline.left, inset.top, 0);
// Right shadow
sideShadow(canvas, edgePaint, edgeShadowRect, outline.right, inset.bottom, 2);
// Top shadow
edgeShadowRect.set(-shadowSize, 0, 0, inset.width());
sideShadow(canvas, edgePaint, edgeShadowRect, inset.right, outline.top, 1);
// bottom shadow. This needs an inset so that blank doesn't appear when the content is
// moved up.
edgeShadowRect.set(-shadowSize, 0, shadowSize / 2f, inset.width());
edgePaint.setShader(new LinearGradient(edgeShadowRect.right, 0, edgeShadowRect.left, 0, colors, new float[] { 0f, 1 / 3f, 1f }, TileMode.CLAMP));
sideShadow(canvas, edgePaint, edgeShadowRect, inset.left, outline.bottom, 3);
// Draw corners.
drawCorner(canvas, cornerPaint, path, inset.right, inset.bottom, outerArcRadius, 0);
drawCorner(canvas, cornerPaint, path, inset.left, inset.bottom, outerArcRadius, 1);
drawCorner(canvas, cornerPaint, path, inset.left, inset.top, outerArcRadius, 2);
drawCorner(canvas, cornerPaint, path, inset.right, inset.top, outerArcRadius, 3);
} finally {
canvas.restoreToCount(saved);
}
}
use of android.graphics.LinearGradient 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.LinearGradient in project AndroidSDK-RecipeBook by gabu.
the class Recipe051 method createReflectionBitmap.
public static Bitmap createReflectionBitmap(Bitmap src) {
// 元画像と反射画像のマージン
int margin = 4;
int width = src.getWidth();
int height = src.getHeight();
// 上下反転させるMatrix
Matrix matrix = new Matrix();
matrix.preScale(1, -1);
// 元画像の下半分を反転したBitmapを生成
Bitmap reflection;
reflection = Bitmap.createBitmap(src, 0, height / 2, width, height / 2, matrix, true);
// 元画像と反射画像が合体した結果画像のBitmapを生成
// これはまだ空っぽ
Bitmap result;
result = Bitmap.createBitmap(width, height + height / 2, Config.ARGB_8888);
// キャンバスを使って
Canvas canvas;
canvas = new Canvas(result);
// 結果画像に元画像を書き込む
canvas.drawBitmap(src, 0, 0, null);
// 結果画像に反射画像を書き込む
canvas.drawBitmap(reflection, 0, height + margin, null);
// ここまでで反転画像と合体した状態
// ここからぼかし
Paint paint = new Paint();
// LinearGradientという直線方向のグラデーションを使います。
LinearGradient shader;
// だんだん透明になるグラデーションを作る
// 0x90ffffff(やや透明) -> 0x00FFFFFF(完全透明)
shader = new LinearGradient(0, height, 0, result.getHeight() + margin, 0x90ffffff, 0x00ffffff, TileMode.CLAMP);
// Shaderクラスを継承しているのでsetShaderでPaintにセットします。
paint.setShader(shader);
// 色の変換モードを指定
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
// グラデーションを描画
canvas.drawRect(0, height, width, result.getHeight(), paint);
return result;
}
use of android.graphics.LinearGradient in project Lazy by l123456789jy.
the class ImageProcessor method reflection.
/**
* 倒影处理
* @param reflectionSpacing 原图与倒影之间的间距
* @return 加上倒影后的图片
*/
public Bitmap reflection(int reflectionSpacing, int reflectionHeight) {
int width = bitmap.getWidth();
int height = bitmap.getHeight();
/* 获取倒影图片,并创建一张宽度与原图相同,但高度等于原图的高度加上间距加上倒影的高度的图片,并创建画布。画布分为上中下三部分,上:是原图;中:是原图与倒影的间距;下:是倒影 */
//
Bitmap reflectionImage = reverseByVertical(bitmap);
Bitmap bitmapWithReflection = Bitmap.createBitmap(width, height + reflectionSpacing + reflectionHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmapWithReflection);
/* 将原图画到画布的上半部分,将倒影画到画布的下半部分,倒影与画布顶部的间距是原图的高度加上原图与倒影之间的间距 */
canvas.drawBitmap(bitmap, 0, 0, null);
canvas.drawBitmap(reflectionImage, 0, height + reflectionSpacing, null);
reflectionImage.recycle();
/* 将倒影改成半透明,创建画笔,并设置画笔的渐变从半透明的白色到全透明的白色,然后再倒影上面画半透明效果 */
Paint paint = new Paint();
paint.setShader(new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionSpacing, 0x70ffffff, 0x00ffffff, Shader.TileMode.CLAMP));
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
canvas.drawRect(0, height + reflectionSpacing, width, bitmapWithReflection.getHeight() + reflectionSpacing, paint);
return bitmapWithReflection;
}
Aggregations