|
|
@@ -0,0 +1,119 @@
|
|
|
+package kr.co.zumo.app.lifeplus.view.custom;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.graphics.Canvas;
|
|
|
+import android.graphics.Color;
|
|
|
+import android.graphics.ColorFilter;
|
|
|
+import android.graphics.Paint;
|
|
|
+import android.graphics.PixelFormat;
|
|
|
+import android.graphics.Rect;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
+import android.support.annotation.NonNull;
|
|
|
+import android.support.annotation.Nullable;
|
|
|
+import android.support.v4.content.ContextCompat;
|
|
|
+import android.util.Log;
|
|
|
+
|
|
|
+import kr.co.zumo.app.R;
|
|
|
+import kr.co.zumo.app.lifeplus.util.ResourceUtil;
|
|
|
+
|
|
|
+/**
|
|
|
+ * CoinRadioButtonDrawable
|
|
|
+ * <pre>
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @author 하세미
|
|
|
+ * @version 1.0
|
|
|
+ * @history 하세미 [2018-10-12] [최초 작성]
|
|
|
+ * @since 2018-10-12
|
|
|
+ */
|
|
|
+public class CoinRadioButtonDrawable extends Drawable {
|
|
|
+
|
|
|
+ private Context context;
|
|
|
+ private boolean isChecked;
|
|
|
+ private boolean isSide;
|
|
|
+ private int halfDp = ResourceUtil.dpToPx(.5f);
|
|
|
+ private int oneDp = ResourceUtil.dpToPx(1f);
|
|
|
+
|
|
|
+ public CoinRadioButtonDrawable(@NonNull Context context, boolean isChecked, boolean isSide) {
|
|
|
+ this.context = context;
|
|
|
+ this.isChecked = isChecked;
|
|
|
+ this.isSide = isSide;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void draw(@NonNull Canvas canvas) {
|
|
|
+ Rect bound = canvas.getClipBounds();
|
|
|
+
|
|
|
+ // 라인 두께 값을 위치에 적용해서 영역 안으로 그려지도록
|
|
|
+// float left = halfDp;
|
|
|
+// float top = halfDp;
|
|
|
+// float right = bound.width() - halfDp;
|
|
|
+// float bottom = bound.height() - halfDp;
|
|
|
+
|
|
|
+ Paint paint = new Paint();
|
|
|
+ paint.setStyle(Paint.Style.FILL);
|
|
|
+// paint.setStyle(Paint.Style.STROKE);
|
|
|
+// paint.setStrokeWidth(halfDp);
|
|
|
+// Path path = new Path();
|
|
|
+
|
|
|
+ float left;
|
|
|
+ float top;
|
|
|
+ float right;
|
|
|
+ float bottom;
|
|
|
+ if (isChecked) {
|
|
|
+ paint.setColor(Color.BLACK);
|
|
|
+// path.moveTo(left, top);
|
|
|
+// path.lineTo(right, top);
|
|
|
+// path.lineTo(right, bottom);
|
|
|
+// path.lineTo(left, bottom);
|
|
|
+// path.lineTo(left, top);
|
|
|
+ //
|
|
|
+ left = oneDp;
|
|
|
+ top = oneDp;
|
|
|
+ right = bound.width() - oneDp;
|
|
|
+ bottom = bound.height() - oneDp;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ paint.setColor(ContextCompat.getColor(context, R.color.CE5E5E5));
|
|
|
+// path.moveTo(left, top);
|
|
|
+// path.lineTo(right + oneDp, top);
|
|
|
+// path.moveTo(right + oneDp, bottom);
|
|
|
+// path.lineTo(left, bottom);
|
|
|
+// path.lineTo(left, top);
|
|
|
+
|
|
|
+ // 선택된 버튼 옆쪽은 세로줄을 모두 없애줌
|
|
|
+ if (isSide) {
|
|
|
+ left = 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ left = oneDp;
|
|
|
+ }
|
|
|
+ top = oneDp;
|
|
|
+ right = bound.width();
|
|
|
+ bottom = bound.height() - oneDp;
|
|
|
+ }
|
|
|
+
|
|
|
+// canvas.drawPath(path, paint);
|
|
|
+ canvas.drawRect(bound, paint);
|
|
|
+ paint.setColor(Color.WHITE);
|
|
|
+ canvas.drawRect(left, top, right, bottom, paint);
|
|
|
+
|
|
|
+ Log.d("APP# CoinRadioButtonDrawable | draw", "|" + "draw: " + "check: " + isChecked + ", side: " + isSide);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setAlpha(int i) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setColorFilter(@Nullable ColorFilter colorFilter) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getOpacity() {
|
|
|
+ return PixelFormat.TRANSLUCENT;
|
|
|
+ }
|
|
|
+}
|