|
|
@@ -5,6 +5,7 @@ import android.graphics.Canvas;
|
|
|
import android.graphics.Color;
|
|
|
import android.graphics.ColorFilter;
|
|
|
import android.graphics.Paint;
|
|
|
+import android.graphics.PaintFlagsDrawFilter;
|
|
|
import android.graphics.PixelFormat;
|
|
|
import android.graphics.Rect;
|
|
|
import android.graphics.RectF;
|
|
|
@@ -31,8 +32,8 @@ public class CoinStartRadioButtonDrawable extends Drawable {
|
|
|
private Context context;
|
|
|
private boolean isChecked;
|
|
|
private boolean isSide;
|
|
|
- private int halfDp = ResourceUtil.dpToPx(.5f);
|
|
|
- private int oneDp = ResourceUtil.dpToPx(1f);
|
|
|
+ private int oneDp = ResourceUtil.dpToPx(CoinRadioButtonDrawable.DP_1);
|
|
|
+ private int twoDp = ResourceUtil.dpToPx(CoinRadioButtonDrawable.DP_2);
|
|
|
|
|
|
public CoinStartRadioButtonDrawable(@NonNull Context context, boolean isChecked, boolean isSide) {
|
|
|
this.context = context;
|
|
|
@@ -42,9 +43,11 @@ public class CoinStartRadioButtonDrawable extends Drawable {
|
|
|
|
|
|
@Override
|
|
|
public void draw(@NonNull Canvas canvas) {
|
|
|
+ canvas.setDrawFilter(new PaintFlagsDrawFilter(1, Paint.ANTI_ALIAS_FLAG));
|
|
|
Rect bound = canvas.getClipBounds();
|
|
|
|
|
|
Paint paint = new Paint();
|
|
|
+ paint.setAntiAlias(true);
|
|
|
paint.setStyle(Paint.Style.FILL);
|
|
|
|
|
|
float left;
|
|
|
@@ -53,34 +56,35 @@ public class CoinStartRadioButtonDrawable extends Drawable {
|
|
|
float bottom;
|
|
|
if (isChecked) {
|
|
|
paint.setColor(Color.BLACK);
|
|
|
-
|
|
|
- left = oneDp;
|
|
|
- top = oneDp;
|
|
|
- right = bound.width() - oneDp;
|
|
|
- bottom = bound.height() - oneDp;
|
|
|
}
|
|
|
else {
|
|
|
paint.setColor(ContextCompat.getColor(context, R.color.CE5E5E5));
|
|
|
-
|
|
|
- // 선택된 버튼 옆쪽은 세로줄을 모두 없애줌
|
|
|
- if (isSide) {
|
|
|
- left = 0;
|
|
|
- }
|
|
|
- else {
|
|
|
- left = oneDp;
|
|
|
- }
|
|
|
- top = oneDp;
|
|
|
- right = bound.width();
|
|
|
- bottom = bound.height() - oneDp;
|
|
|
}
|
|
|
|
|
|
- RectF rectF = new RectF(bound);
|
|
|
-
|
|
|
- canvas.drawRoundRect(rectF, 5, 5, paint);
|
|
|
+ // 외곽선 라운드 부분
|
|
|
+ // 라운드와 아닌 것 2개 겹쳐줌
|
|
|
+ // 라운드
|
|
|
+ left = 0;
|
|
|
+ top = 0;
|
|
|
+ right = bound.width();
|
|
|
+ bottom = bound.height();
|
|
|
+ Rect rect1 = new Rect((int) left, (int) top, (int) right - twoDp, (int) bottom);
|
|
|
+ canvas.drawRoundRect(new RectF(rect1), twoDp, twoDp, paint);
|
|
|
+ // 라운드 아닌 것
|
|
|
+ Rect rect2 = new Rect((int) right - twoDp - twoDp, (int) top, (int) right, (int) bottom);
|
|
|
+ canvas.drawRect(rect2, paint);
|
|
|
+
|
|
|
+ // 흰색 안쪽
|
|
|
+ left = oneDp;
|
|
|
+ top = oneDp;
|
|
|
+ right = isChecked ? bound.width() - oneDp : bound.width();
|
|
|
+ bottom = bound.height() - oneDp;
|
|
|
paint.setColor(Color.WHITE);
|
|
|
- Rect rect = new Rect((int) left, (int) top, (int) right, (int) bottom);
|
|
|
- RectF rectF2 = new RectF(rect);
|
|
|
- canvas.drawRoundRect(rectF2, 5, 5, paint);
|
|
|
+ Rect rect3 = new Rect((int) left, (int) top, (int) right - twoDp, (int) bottom);
|
|
|
+ canvas.drawRoundRect(new RectF(rect3), oneDp, oneDp, paint);
|
|
|
+ // 라운드 아닌 것
|
|
|
+ Rect rect4 = new Rect((int) right - twoDp - twoDp, (int) top, (int) right, (int) bottom);
|
|
|
+ canvas.drawRect(rect4, paint);
|
|
|
|
|
|
}
|
|
|
|