Kaynağa Gözat

[설정][New] 이미지 토글 버튼 -> 커스텀 스위치 버튼으로 변경

Hasemi 7 yıl önce
ebeveyn
işleme
8d98cb201c

+ 7 - 5
app/src/main/java/kr/co/zumo/app/lifeplus/view/fragment/setting/DefaultSettingViewHolder.java

@@ -37,14 +37,16 @@ public class DefaultSettingViewHolder extends RecyclerView.ViewHolder {
     imageViewAccordion = itemView.findViewById(R.id.image_view_setting_menu_accordion);
 
     switchPinOnOff = itemView.findViewById(R.id.switch_pin_on_off);
+    switchPinOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, false));
+
     switchPinOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
       @Override
       public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
-        if(isChecked){
-          switchPinOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.empty_string));
-        }else{
-          switchPinOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.empty_string, R.string.off));
-
+        if (isChecked) {
+          switchPinOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, true));
+        }
+        else {
+          switchPinOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, false));
         }
       }
     });

+ 49 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/fragment/setting/PushAndLocationSettingViewHolder.java

@@ -1,9 +1,12 @@
 package kr.co.zumo.app.lifeplus.view.fragment.setting;
 
+import android.content.Context;
 import android.support.v7.widget.RecyclerView;
 import android.view.View;
+import android.widget.CompoundButton;
 import android.widget.ImageView;
 import android.widget.RelativeLayout;
+import android.widget.Switch;
 import android.widget.TextView;
 
 import kr.co.zumo.app.R;
@@ -23,12 +26,57 @@ public class PushAndLocationSettingViewHolder extends RecyclerView.ViewHolder {
   public TextView textViewMenuText;
   public RelativeLayout customLayout;
   public ImageView imageViewAccordion;
+  public Switch switchPushOnOff;
+  public Switch switchMarketingOnOff;
+  public Switch switchLocationOnOff;
 
-  public PushAndLocationSettingViewHolder(View itemView) {
+  public PushAndLocationSettingViewHolder(View itemView, Context context) {
     super(itemView);
     textViewMenuText = itemView.findViewById(R.id.text_view_setting_menu_text);
     customLayout = itemView.findViewById(R.id.layout_push_location_setting);
     imageViewAccordion = itemView.findViewById(R.id.image_view_setting_menu_accordion);
+    switchPushOnOff = itemView.findViewById(R.id.switch_push_on_off);
+    switchMarketingOnOff = itemView.findViewById(R.id.switch_marketing_on_off);
+    switchLocationOnOff = itemView.findViewById(R.id.switch_location_on_off);
+    switchPushOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, false));
+    switchPushOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+      @Override
+      public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+        if (isChecked) {
+          switchPushOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, true));
+        }
+        else {
+          switchPushOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, false));
+        }
+      }
+    });
+
+    switchMarketingOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, false));
+    switchMarketingOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+      @Override
+      public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+        if (isChecked) {
+          switchMarketingOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, true));
+        }
+        else {
+          switchMarketingOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, false));
+        }
+      }
+    });
+
+
+    switchLocationOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, false));
+    switchLocationOnOff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+      @Override
+      public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+        if (isChecked) {
+          switchLocationOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, true));
+        }
+        else {
+          switchLocationOnOff.setTrackDrawable(new SwitchTrackTextDrawable(context, R.string.on, R.string.off, false));
+        }
+      }
+    });
   }
 
   public void onClick() {

+ 1 - 1
app/src/main/java/kr/co/zumo/app/lifeplus/view/fragment/setting/SettingExpandableListViewAdapter.java

@@ -48,7 +48,7 @@ public class SettingExpandableListViewAdapter extends RecyclerView.Adapter<Recyc
         view = LayoutInflater
           .from(parent.getContext())
           .inflate(R.layout.setting_custom_menu3, parent, false);
-        return new PushAndLocationSettingViewHolder(view);
+        return new PushAndLocationSettingViewHolder(view, context);
       case 3:
         view = LayoutInflater
           .from(parent.getContext())

+ 23 - 16
app/src/main/java/kr/co/zumo/app/lifeplus/view/fragment/setting/SwitchTrackTextDrawable.java

@@ -10,8 +10,8 @@ import android.graphics.drawable.Drawable;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.StringRes;
-import android.util.Log;
 
+import kr.co.zumo.app.R;
 import kr.co.zumo.app.lifeplus.util.ResourceUtil;
 
 /**
@@ -33,30 +33,39 @@ public class SwitchTrackTextDrawable extends Drawable {
   private final String mRightText;
 
   private final Paint mTextPaint;
-
+  private boolean isChecked;
 
   public SwitchTrackTextDrawable(@NonNull Context context,
                                  @StringRes int leftTextId,
-                                 @StringRes int rightTextId) {
+                                 @StringRes int rightTextId,
+                                 boolean isChecked
+  ) {
     mContext = context;
 
-    // Left text
-    mLeftText = context.getString(leftTextId);
-    mTextPaint = LeftTextPaint();
+    this.isChecked = isChecked;
+
+    if (isChecked) {
+      //switch on
+      mLeftText = context.getString(leftTextId);
+      mTextPaint = LeftTextPaint();
+      mRightText = context.getString(R.string.empty_string);
+
+    }
+    else {
+      //switch off
+      mLeftText = context.getString(R.string.empty_string);
+      mTextPaint = LeftTextPaint();
+      mRightText = context.getString(rightTextId);
+    }
 
-    // Right text
-    mRightText = context.getString(rightTextId);
   }
 
   private Paint LeftTextPaint() {
     Paint textPaint = new Paint();
-    //noinspection deprecation
-    //textPaint.setColor(mContext.getResources().getColor(android.R.color.black));
     textPaint.setAntiAlias(true);
     textPaint.setStyle(Paint.Style.FILL);
     textPaint.setTextAlign(Paint.Align.CENTER);
     textPaint.setTextSize(ResourceUtil.dpToPx(9));
-
     return textPaint;
   }
 
@@ -67,21 +76,19 @@ public class SwitchTrackTextDrawable extends Drawable {
     mTextPaint.getTextBounds(mRightText, 0, mRightText.length(), textBounds);
 
     // The baseline for the text: centered, including the height of the text itself
-    final int heightBaseline = canvas.getClipBounds().height() / 2 + textBounds.height() / 2;
+    //final int heightBaseline = canvas.getClipBounds().height() / 2 + textBounds.height() / 2;
     final int widthQuarter = canvas.getClipBounds().width() / 4;
 
-    Log.e("APP#  SwitchTrackTextDrawable | draw", "|" + widthQuarter);
-
     //on 텍스트 흰색 변경
     mTextPaint.setColor(mContext.getResources().getColor(android.R.color.white));
     canvas.drawText(mLeftText, 0, mLeftText.length(),
-      widthQuarter + 15, heightBaseline,
+      widthQuarter + 15, 53,
       mTextPaint);
 
     //off  텍스트 검정 변경
     mTextPaint.setColor(mContext.getResources().getColor(android.R.color.darker_gray));
     canvas.drawText(mRightText, 0, mRightText.length(),
-      widthQuarter * 3 - 10, heightBaseline,
+      widthQuarter * 3 - 25, 53,
       mTextPaint);
   }
 

+ 1 - 1
app/src/main/res/layout/setting_custom_menu1.xml

@@ -133,7 +133,7 @@
           android:layout_alignParentEnd="true"
           android:layout_marginTop="48dp"
           android:layout_marginBottom="28dp"
-          android:switchMinWidth="44dp"
+          android:switchMinWidth="46dp"
           android:thumb="@drawable/switch_thumb_selector"
           android:background="@drawable/switch_track_selector"
         />

+ 24 - 27
app/src/main/res/layout/setting_custom_menu3.xml

@@ -88,18 +88,17 @@
         android:textColor="@color/C999999"
         android:textSize="12sp"/>
 
-
-      <ToggleButton
-        style="?android:attr/borderlessButtonStyle"
-        android:layout_width="44dp"
-        android:layout_height="18dp"
+      <Switch
+        android:id="@+id/switch_push_on_off"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
         android:layout_alignParentEnd="true"
         android:layout_marginEnd="25dp"
         android:layout_marginBottom="22dp"
-        android:background="@drawable/toggle_selector"
-        android:text=""
-        android:textOff=""
-        android:textOn=""/>
+        android:switchMinWidth="46dp"
+        android:thumb="@drawable/switch_thumb_selector"
+        android:background="@drawable/switch_track_selector"
+        />
 
       <TextView
         android:id="@+id/text_view_marketing_setting"
@@ -118,20 +117,18 @@
         android:textColor="@color/C999999"
         android:textSize="12sp"/>
 
-
-      <ToggleButton
-        style="?android:attr/borderlessButtonStyle"
-        android:layout_width="44dp"
-        android:layout_height="18dp"
+      <Switch
+        android:id="@+id/switch_marketing_on_off"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
         android:layout_alignParentEnd="true"
         android:layout_marginTop="40dp"
         android:layout_marginEnd="25dp"
         android:layout_marginBottom="22dp"
-        android:background="@drawable/toggle_selector"
-        android:text=""
-        android:textOff=""
-        android:textOn=""/>
-
+        android:switchMinWidth="46dp"
+        android:thumb="@drawable/switch_thumb_selector"
+        android:background="@drawable/switch_track_selector"
+        />
       <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
@@ -147,18 +144,18 @@
         android:textColor="@color/C999999"
         android:textSize="12sp"/>
 
-      <ToggleButton
-        style="?android:attr/borderlessButtonStyle"
-        android:layout_width="44dp"
-        android:layout_height="18dp"
+      <Switch
+        android:id="@+id/switch_location_on_off"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
         android:layout_alignParentEnd="true"
         android:layout_marginTop="86dp"
         android:layout_marginEnd="26dp"
         android:layout_marginBottom="28dp"
-        android:background="@drawable/toggle_selector"
-        android:text=""
-        android:textOff=""
-        android:textOn=""/>
+        android:switchMinWidth="46dp"
+        android:thumb="@drawable/switch_thumb_selector"
+        android:background="@drawable/switch_track_selector"
+        />
     </RelativeLayout>
   </FrameLayout>
 </LinearLayout>

+ 2 - 2
app/src/main/res/values/strings.xml

@@ -333,8 +333,8 @@
 
 
   <string name="setting">설정</string>
-  <string name="on"><b>ON</b></string>
-  <string name="off"><b>OFF</b></string>
+  <string name="on"><b>ON  </b></string>
+  <string name="off"><b>  OFF</b></string>
   <string name="user_quit_fail">회원님의 경우 탈퇴가 불가능합니다.\n아래 내용을 확인해주세요.</string>
   <string name="user_quit_fail_message">Lifeplus 회원탈퇴 전 유의사항을 확인해주세요.</string>
   <string name="user_coin">보유코인</string>