use of android.graphics.drawable.ShapeDrawable in project PhotoNoter by yydcdut.
the class FloatingActionButton method createOuterStrokeDrawable.
/**
* 绘制外层的drawable
* 就是画边框
*
* @param strokeWidth
* @return
*/
private Drawable createOuterStrokeDrawable(float strokeWidth) {
//圆
ShapeDrawable shapeDrawable = new ShapeDrawable(new OvalShape());
//笔
final Paint paint = shapeDrawable.getPaint();
//锯齿
paint.setAntiAlias(true);
//描边宽度
paint.setStrokeWidth(strokeWidth);
//描边style,就是中空
paint.setStyle(Style.STROKE);
//颜色黑色,用来画边框
paint.setColor(Color.BLACK);
//透明度
paint.setAlpha(opacityToAlpha(0.02f));
return shapeDrawable;
}
use of android.graphics.drawable.ShapeDrawable 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 in project Genius-Android by qiujuer.
the class EditText method initBackground.
private void initBackground() {
final int lineSize = getLineSize();
Drawable background;
if (lineSize == 0) {
background = null;
} else {
int increment = getResources().getDimensionPixelSize(R.dimen.g_editText_lineSize_active_increment);
int lineActive = lineSize + increment;
int lineHalf = lineSize >> 1;
// Creating normal state drawable
ShapeDrawable normal = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineSize)));
normal.getPaint().setColor(getLineColor(new int[] { android.R.attr.state_enabled }));
// Creating pressed state drawable
ShapeDrawable pressed = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineActive)));
pressed.getPaint().setColor(getLineColor(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }));
// Creating focused state drawable
ShapeDrawable focused = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineActive)));
focused.getPaint().setColor(getLineColor(new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }));
// Creating disabled state drawable
ShapeDrawable disabled = new ShapeDrawable(new BorderShape(new RectF(0, 0, 0, lineHalf), lineHalf, lineSize));
disabled.getPaint().setColor(getLineColor(new int[] { -android.R.attr.state_enabled }));
// disabled.getPaint().setAlpha(0xA0);
Drawable[] drawable = new Drawable[] { pressed, focused, normal, disabled };
background = createStateListDrawable(drawable);
}
// Set Background
UiCompat.setBackground(this, background);
}
use of android.graphics.drawable.ShapeDrawable in project FlyRefresh by race604.
the class PullHeaderLayout method setActionDrawable.
public void setActionDrawable(Drawable actionDrawable) {
mActionDrawable = actionDrawable;
if (mActionDrawable != null) {
if (mActionView == null) {
final int bgColor = UIUtils.getThemeColorFromAttrOrRes(getContext(), R.attr.colorAccent, R.color.accent);
final int pressedColor = UIUtils.darkerColor(bgColor, 0.8f);
final ShapeDrawable bgDrawable = new ShapeDrawable(new OvalShape());
bgDrawable.getPaint().setColor(bgColor);
mActionView = new FloatingActionButton(getContext());
mActionView.setRippleColor(pressedColor);
mActionView.setBackgroundDrawable(bgDrawable);
addView(mActionView, new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
}
if (mFlyView == null) {
mFlyView = new ImageView(getContext());
mFlyView.setScaleType(ImageView.ScaleType.FIT_XY);
addView(mFlyView, new LayoutParams(ACTION_ICON_SIZE, ACTION_ICON_SIZE));
mFlyView.bringToFront();
float elevation = ViewCompat.getElevation(mActionView);
ViewCompat.setElevation(mFlyView, elevation + 1);
}
mFlyView.setImageDrawable(mActionDrawable);
} else {
if (mActionView != null) {
removeView(mActionView);
removeView(mFlyView);
mActionView = null;
mFlyView = null;
}
}
}
use of android.graphics.drawable.ShapeDrawable in project MusicVideoPlayer by MartingKing.
the class CircleImageView method setBackgroundColor.
/**
* Update the background color of the circle image view.
*/
public void setBackgroundColor(int colorRes) {
if (getBackground() instanceof ShapeDrawable) {
final Resources res = getResources();
((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(R.color.green));
}
}
Aggregations