use of android.graphics.drawable.shapes.OvalShape in project PhotoNoter by yydcdut.
the class CircleProgressBar method onLayout.
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
final float density = getContext().getResources().getDisplayMetrics().density;
mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
if (mDiameter <= 0) {
mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
}
if (getBackground() == null && mCircleBackgroundEnabled) {
final int shadowYOffset = (int) (density * Y_OFFSET);
final int shadowXOffset = (int) (density * X_OFFSET);
mShadowRadius = (int) (density * SHADOW_RADIUS);
if (elevationSupported()) {
mBgCircle = new ShapeDrawable(new OvalShape());
ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
} else {
OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
mBgCircle = new ShapeDrawable(oval);
ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
final int padding = (int) mShadowRadius;
// set padding so the inner image sits correctly within the shadow.
setPadding(padding, padding, padding, padding);
}
mBgCircle.getPaint().setColor(mBackGroundColor);
setBackgroundDrawable(mBgCircle);
}
mProgressDrawable.setBackgroundColor(mBackGroundColor);
mProgressDrawable.setColorSchemeColors(mColors);
mProgressDrawable.setSizeParameters(mDiameter, mDiameter, mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius, mProgressStokeWidth, mArrowWidth < 0 ? mProgressStokeWidth * 4 : mArrowWidth, mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
if (isShowArrow()) {
mProgressDrawable.showArrowOnFirstStart(true);
mProgressDrawable.setArrowScale(1f);
mProgressDrawable.showArrow(true);
}
super.setImageDrawable(null);
super.setImageDrawable(mProgressDrawable);
mProgressDrawable.setAlpha(255);
if (getVisibility() == VISIBLE) {
mProgressDrawable.start();
}
}
use of android.graphics.drawable.shapes.OvalShape in project PhotoNoter by yydcdut.
the class TextDrawable method drawBorder.
/**
* 画边界
*
* @param canvas
*/
private void drawBorder(Canvas canvas) {
RectF rect = new RectF(getBounds());
//上下左右都加个borderThickness / 2长度
rect.inset(borderThickness / 2, borderThickness / 2);
if (shape instanceof OvalShape) {
//椭圆
canvas.drawOval(rect, borderPaint);
} else if (shape instanceof RoundRectShape) {
//圆角Rect
canvas.drawRoundRect(rect, radius, radius, borderPaint);
} else {
//Rect
canvas.drawRect(rect, borderPaint);
}
}
use of android.graphics.drawable.shapes.OvalShape 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.shapes.OvalShape 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.shapes.OvalShape in project weex-example by KalicyZhou.
the class CircleProgressBar method onLayout.
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
final float density = getContext().getResources().getDisplayMetrics().density;
mDiameter = Math.min(getMeasuredWidth(), getMeasuredHeight());
if (mDiameter <= 0) {
mDiameter = (int) density * DEFAULT_CIRCLE_DIAMETER;
}
if (getBackground() == null && mCircleBackgroundEnabled) {
final int shadowYOffset = (int) (density * Y_OFFSET);
final int shadowXOffset = (int) (density * X_OFFSET);
mShadowRadius = (int) (density * SHADOW_RADIUS);
if (elevationSupported()) {
mBgCircle = new ShapeDrawable(new OvalShape());
ViewCompat.setElevation(this, SHADOW_ELEVATION * density);
} else {
OvalShape oval = new OvalShadow(mShadowRadius, mDiameter - mShadowRadius * 2);
mBgCircle = new ShapeDrawable(oval);
ViewCompat.setLayerType(this, ViewCompat.LAYER_TYPE_SOFTWARE, mBgCircle.getPaint());
mBgCircle.getPaint().setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR);
final int padding = (int) mShadowRadius;
// set padding so the inner image sits correctly within the shadow.
setPadding(padding, padding, padding, padding);
}
mBgCircle.getPaint().setColor(mBackGroundColor);
setBackgroundDrawable(mBgCircle);
}
mProgressDrawable.setBackgroundColor(mBackGroundColor);
mProgressDrawable.setColorSchemeColors(mColors);
if (isShowArrow()) {
mProgressDrawable.setArrowScale(1f);
mProgressDrawable.showArrow(true);
}
super.setImageDrawable(null);
super.setImageDrawable(mProgressDrawable);
mProgressDrawable.setAlpha(255);
if (getVisibility() == VISIBLE) {
mProgressDrawable.setStartEndTrim(0, (float) 0.8);
}
}
Aggregations