Browse Source

[코인][New] 코인 디테일 필터 GUI 적용 중

hyodong.min 6 years ago
parent
commit
e0b04cd2ca

+ 37 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/CoinEndRadioButton.java

@@ -0,0 +1,37 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view.custom;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+
+/**
+ * CoinEndRadioButton
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 2. 22.]   [최초 작성]
+ * @since 2019. 2. 22.
+ */
+public class CoinEndRadioButton extends CoinRadioButton {
+  public CoinEndRadioButton(Context context) {
+    super(context);
+  }
+
+  public CoinEndRadioButton(Context context, AttributeSet attrs) {
+    super(context, attrs);
+  }
+
+  public CoinEndRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
+    super(context, attrs, defStyleAttr);
+  }
+
+  @Override
+  protected Drawable getBackgroundDrawable(boolean isChecked) {
+    return new CoinEndRadioButtonDrawable(getContext(), isChecked, isSide);
+  }
+}

+ 96 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/CoinEndRadioButtonDrawable.java

@@ -0,0 +1,96 @@
+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 kr.co.zumo.app.R;
+import kr.co.zumo.app.lifeplus.util.ResourceUtil;
+
+/**
+ * CoinEndRadioButtonDrawable
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2018-10-12]   [최초 작성]
+ * @since 2018-10-12
+ */
+public class CoinEndRadioButtonDrawable extends Drawable {
+
+  private Context context;
+  private boolean isChecked;
+  private boolean isSide;
+  private int halfDp = ResourceUtil.dpToPx(.5f);
+  private int oneDp = ResourceUtil.dpToPx(1f);
+
+  public CoinEndRadioButtonDrawable(@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();
+
+    Paint paint = new Paint();
+    paint.setStyle(Paint.Style.FILL);
+
+    float left;
+    float top;
+    float right;
+    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;
+    }
+
+    canvas.drawRect(bound, paint);
+    paint.setColor(Color.WHITE);
+    canvas.drawRect(left, top, right, bottom, paint);
+
+  }
+
+  @Override
+  public void setAlpha(int i) {
+
+  }
+
+  @Override
+  public void setColorFilter(@Nullable ColorFilter colorFilter) {
+
+  }
+
+  @Override
+  public int getOpacity() {
+    return PixelFormat.TRANSLUCENT;
+  }
+}

+ 81 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/CoinRadioButton.java

@@ -0,0 +1,81 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view.custom;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+
+/**
+ * CoinRadioButton
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 2. 22.]   [최초 작성]
+ * @since 2019. 2. 22.
+ */
+public class CoinRadioButton extends android.support.v7.widget.AppCompatRadioButton {
+  protected boolean isSide;
+  private CoinRadioManager coinRadioManager;
+
+  public CoinRadioButton(Context context) {
+    super(context);
+    init();
+  }
+
+  public CoinRadioButton(Context context, AttributeSet attrs) {
+    super(context, attrs);
+    init();
+  }
+
+  public CoinRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
+    super(context, attrs, defStyleAttr);
+    init();
+  }
+
+  private void init() {
+    update();
+
+//    super.setOnCheckedChangeListener(new OnCheckedChangeListener() {
+//      @Override
+//      public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+//        Log.d("APP# CoinRadioButton | onCheckedChanged", "|" + " checked: " + isChecked);
+//      }
+//    });
+  }
+
+  @Override
+  public void setChecked(boolean checked) {
+    super.setChecked(checked);
+  }
+
+//  public boolean isSide() {
+//    return isSide;
+//  }
+//
+//  public void setSide(boolean side) {
+//    isSide = side;
+//  }
+
+  public void setManager(CoinRadioManager coinRadioManager) {
+    this.coinRadioManager = coinRadioManager;
+  }
+
+  public void update() {
+    update(isChecked());
+  }
+
+  public void update(boolean isChecked) {
+    if (null != coinRadioManager) {
+      isSide = coinRadioManager.hasSide(this);
+    }
+    setBackground(getBackgroundDrawable(isChecked));
+  }
+
+  protected Drawable getBackgroundDrawable(boolean isChecked) {
+    return new CoinRadioButtonDrawable(getContext(), isChecked, isSide);
+  }
+}

+ 119 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/CoinRadioButtonDrawable.java

@@ -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;
+  }
+}

+ 51 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/CoinRadioGroup.java

@@ -0,0 +1,51 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view.custom;
+
+import android.content.Context;
+import android.support.annotation.IdRes;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.autofill.AutofillValue;
+import android.widget.RadioGroup;
+
+/**
+ * CoinRadioGroup
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 2. 22.]   [최초 작성]
+ * @since 2019. 2. 22.
+ */
+public class CoinRadioGroup extends RadioGroup {
+  public CoinRadioGroup(Context context) {
+    super(context);
+  }
+
+  public CoinRadioGroup(Context context, AttributeSet attrs) {
+    super(context, attrs);
+  }
+
+  @Override
+  protected void onFinishInflate() {
+    super.onFinishInflate();
+
+    Log.i("APP# CoinRadioGroup | onFinishInflate", "|" + " -------- ");
+  }
+
+  @Override
+  public void check(@IdRes int id) {
+    Log.i("APP# CoinRadioGroup | check", "|" + " id -------------> " + id);
+    super.check(id);
+  }
+
+  @Override
+  public void autofill(AutofillValue value) {
+    super.autofill(value);
+
+    Log.i("APP# CoinRadioGroup | autofill", "|" + "========================");
+  }
+}

+ 46 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/CoinRadioManager.java

@@ -0,0 +1,46 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view.custom;
+
+/**
+ * CoinRadioManager
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 2. 22.]   [최초 작성]
+ * @since 2019. 2. 22.
+ */
+public class CoinRadioManager {
+  private final CoinRadioGroup coinRadioGroup;
+  private int selectedIndex = 0;
+
+  public CoinRadioManager(CoinRadioGroup coinRadioGroup) {
+    this.coinRadioGroup = coinRadioGroup;
+  }
+
+  public boolean hasSide(CoinRadioButton coinRadioButton) {
+    int idx = getSelectedIndexByChild(coinRadioButton);
+    return selectedIndex + 1 == idx;
+  }
+
+  public void setSelectedChild(CoinRadioButton coinRadioButton) {
+    selectedIndex = getSelectedIndexByChild(coinRadioButton);
+//    Log.d("APP# CoinRadioManager | setSelectedChild", "|" + " selectedIndex: ------------------------------------------- " + selectedIndex);
+  }
+
+  private int getSelectedIndexByChild(CoinRadioButton coinRadioButton) {
+    int len = coinRadioGroup.getChildCount();
+    CoinRadioButton button;
+    for (int i = 0; i < len; ++i) {
+      button = (CoinRadioButton) coinRadioGroup.getChildAt(i);
+      if (button.getId() == coinRadioButton.getId()) {
+        return i;
+      }
+    }
+
+    return -1;
+  }
+}

+ 37 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/CoinStartRadioButton.java

@@ -0,0 +1,37 @@
+/*
+ * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
+ */
+package kr.co.zumo.app.lifeplus.view.custom;
+
+import android.content.Context;
+import android.graphics.drawable.Drawable;
+import android.util.AttributeSet;
+
+/**
+ * CoinStartRadioButton
+ * <pre>
+ * </pre>
+ *
+ * @author 민효동
+ * @version 1.0
+ * @history 민효동   [2019. 2. 22.]   [최초 작성]
+ * @since 2019. 2. 22.
+ */
+public class CoinStartRadioButton extends CoinRadioButton {
+  public CoinStartRadioButton(Context context) {
+    super(context);
+  }
+
+  public CoinStartRadioButton(Context context, AttributeSet attrs) {
+    super(context, attrs);
+  }
+
+  public CoinStartRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {
+    super(context, attrs, defStyleAttr);
+  }
+
+  @Override
+  protected Drawable getBackgroundDrawable(boolean isChecked) {
+    return new CoinStartRadioButtonDrawable(getContext(), isChecked, isSide);
+  }
+}

+ 101 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/CoinStartRadioButtonDrawable.java

@@ -0,0 +1,101 @@
+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.RectF;
+import android.graphics.drawable.Drawable;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.content.ContextCompat;
+
+import kr.co.zumo.app.R;
+import kr.co.zumo.app.lifeplus.util.ResourceUtil;
+
+/**
+ * CoinStartRadioButtonDrawable
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2018-10-12]   [최초 작성]
+ * @since 2018-10-12
+ */
+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);
+
+  public CoinStartRadioButtonDrawable(@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();
+
+    Paint paint = new Paint();
+    paint.setStyle(Paint.Style.FILL);
+
+    float left;
+    float top;
+    float right;
+    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);
+    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);
+
+  }
+
+  @Override
+  public void setAlpha(int i) {
+
+  }
+
+  @Override
+  public void setColorFilter(@Nullable ColorFilter colorFilter) {
+
+  }
+
+  @Override
+  public int getOpacity() {
+    return PixelFormat.TRANSLUCENT;
+  }
+}

+ 27 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/my/coin/MyCoinDetailMemberFragment.java

@@ -8,6 +8,7 @@ import android.support.constraint.ConstraintLayout;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.text.Spanned;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -23,6 +24,9 @@ import kr.co.zumo.app.lifeplus.helper.ActionBarHelper;
 import kr.co.zumo.app.lifeplus.util.ResourceUtil;
 import kr.co.zumo.app.lifeplus.util.StringUtil;
 import kr.co.zumo.app.lifeplus.view.Event;
+import kr.co.zumo.app.lifeplus.view.custom.CoinRadioButton;
+import kr.co.zumo.app.lifeplus.view.custom.CoinRadioGroup;
+import kr.co.zumo.app.lifeplus.view.custom.CoinRadioManager;
 import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
 import kr.co.zumo.app.lifeplus.view.screen.setting.SettingExpandableListViewDecoration;
 
@@ -94,13 +98,27 @@ public class MyCoinDetailMemberFragment extends FragmentBase<MyCoinDetailPresent
     });//setOnclickListener 끝
 
     radioGroupPeriod = findViewById(R.id.radio_group_period);
+    CoinRadioManager coinRadioManager = new CoinRadioManager((CoinRadioGroup) radioGroupPeriod);
     int len = radioGroupPeriod.getChildCount();
     for (int i = 0; i < len; ++i) {
       int periodIndex = i;
-      (radioGroupPeriod.getChildAt(i)).setOnClickListener(v -> {
+      CoinRadioButton radioButton = (CoinRadioButton) radioGroupPeriod.getChildAt(i);
+      radioButton.setManager(coinRadioManager);
+
+      if (i < 2) {
+        radioButton.update();
+      }
+
+      radioButton.setOnClickListener(v -> {
+        Log.d("APP# MyCoinDetailMemberFragment | onAfterActivityCreated", "|" + " v: " + v.getId());
+        Log.d("APP# MyCoinDetailMemberFragment | onAfterActivityCreated", "|" + " checked: " + radioButton.isChecked());
+        coinRadioManager.setSelectedChild(radioButton);
+        updateRadioButtons();
+
         presenter.onClickPeriod(periodIndex);
       });
     }
+
     radioGroupFlag = findViewById(R.id.radio_group_flag);
     len = radioGroupFlag.getChildCount();
     for (int i = 0; i < len; ++i) {
@@ -116,6 +134,14 @@ public class MyCoinDetailMemberFragment extends FragmentBase<MyCoinDetailPresent
     recyclerViewCoinList.addItemDecoration(decoration);
   }
 
+  private void updateRadioButtons() {
+    int len = radioGroupPeriod.getChildCount();
+    for (int i = 0; i < len; ++i) {
+      CoinRadioButton radioButton = (CoinRadioButton) radioGroupPeriod.getChildAt(i);
+      radioButton.update();
+    }
+  }
+
   @Override
   protected void defineActionBar(ActionBarHelper actionBarHelper) {
     actionBarHelper.begin().title(R.string.use_coin)

+ 7 - 12
app/src/main/res/layout/my_coin_filter_view.xml

@@ -52,7 +52,7 @@
     app:layout_constraintTop_toBottomOf="@+id/filter_divider"
     tools:visibility="visible">
 
-    <RadioGroup
+    <kr.co.zumo.app.lifeplus.view.custom.CoinRadioGroup
       android:id="@+id/radio_group_period"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
@@ -60,12 +60,11 @@
       android:orientation="horizontal"
       android:weightSum="5">
 
-      <RadioButton
+      <kr.co.zumo.app.lifeplus.view.custom.CoinStartRadioButton
         android:id="@+id/radio_a_week"
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
-        android:background="@drawable/filter_radio_selector"
         android:button="@null"
         android:paddingTop="8dp"
         android:paddingBottom="8dp"
@@ -76,11 +75,10 @@
         tools:checked="true"
         />
 
-      <RadioButton
+      <kr.co.zumo.app.lifeplus.view.custom.CoinRadioButton
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
-        android:background="@drawable/filter_radio_selector"
         android:button="@null"
         android:paddingTop="8dp"
         android:paddingBottom="8dp"
@@ -90,11 +88,10 @@
         android:textSize="12sp"
         />
 
-      <RadioButton
+      <kr.co.zumo.app.lifeplus.view.custom.CoinRadioButton
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
-        android:background="@drawable/filter_radio_selector"
         android:button="@null"
         android:paddingTop="8dp"
         android:paddingBottom="8dp"
@@ -104,11 +101,10 @@
         android:textSize="12sp"
         />
 
-      <RadioButton
+      <kr.co.zumo.app.lifeplus.view.custom.CoinRadioButton
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
-        android:background="@drawable/filter_radio_selector"
         android:button="@null"
         android:paddingTop="8dp"
         android:paddingBottom="8dp"
@@ -118,11 +114,10 @@
         android:textSize="12sp"
         />
 
-      <RadioButton
+      <kr.co.zumo.app.lifeplus.view.custom.CoinEndRadioButton
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
-        android:background="@drawable/filter_radio_selector"
         android:button="@null"
         android:paddingTop="8dp"
         android:paddingBottom="8dp"
@@ -131,7 +126,7 @@
         android:textColor="@drawable/my_faq_radio_text_selector"
         android:textSize="12sp"
         />
-    </RadioGroup>
+    </kr.co.zumo.app.lifeplus.view.custom.CoinRadioGroup>
 
     <RadioGroup
       android:id="@+id/radio_group_flag"