use of android.graphics.drawable.ShapeDrawable.ShaderFactory 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.drawable.ShapeDrawable.ShaderFactory in project Resurrection_packages_apps_Settings by ResurrectionRemix.
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.drawable.ShapeDrawable.ShaderFactory 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;
}
Aggregations