Ver código fonte

[공통][Common] 설정 스위치 API 대응

Hasemi 7 anos atrás
pai
commit
dc7e57fba7

+ 10 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/OnOffSwitch.java

@@ -6,6 +6,7 @@ package kr.co.zumo.app.lifeplus.view.custom;
 import android.content.Context;
 import android.graphics.Rect;
 import android.support.annotation.Nullable;
+import android.graphics.drawable.StateListDrawable;
 import android.util.AttributeSet;
 import android.widget.CompoundButton;
 import android.widget.Switch;
@@ -25,19 +26,23 @@ import kr.co.zumo.app.R;
 public class OnOffSwitch extends Switch {
 
   protected CompoundButton.OnCheckedChangeListener onCheckedChangeListener;
+  private Context context;
 
   public OnOffSwitch(Context context) {
     super(context, null, R.attr.customSwitchStyle);
+    this.context = context;
     init();
   }
 
   public OnOffSwitch(Context context, AttributeSet attrs) {
     super(context, attrs, R.attr.customSwitchStyle);
+    this.context = context;
     init();
   }
 
   public OnOffSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
     super(context, attrs, R.attr.customSwitchStyle);
+    this.context = context;
     init();
   }
 
@@ -45,6 +50,11 @@ public class OnOffSwitch extends Switch {
     Rect paddingRect = new Rect(getPaddingStart(), getPaddingTop(), getPaddingRight(), getPaddingBottom());
     setTrackDrawable(new SwitchTrackTextDrawable(getContext(), R.string.on, R.string.off, false, paddingRect));
 
+    StateListDrawable stateListDrawable = new StateListDrawable();
+    stateListDrawable.addState(new int[]{android.R.attr.state_checked}, context.getResources().getDrawable(R.drawable.switch_thumb_on));
+    stateListDrawable.addState(new int[]{-android.R.attr.state_checked}, context.getResources().getDrawable(R.drawable.switch_thumb_off));
+    setThumbDrawable(stateListDrawable);
+
     super.setOnCheckedChangeListener((compoundButton, isChecked) -> {
       performOnCheckedChanged(compoundButton, isChecked);
 

+ 2 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/view/custom/SwitchTrackTextDrawable.java

@@ -81,7 +81,7 @@ public class SwitchTrackTextDrawable extends Drawable {
     if (isChecked) {
 
       // track
-      Drawable d = ResourceUtil.getDrawable(context, R.drawable.switch_track_on);
+      Drawable d = context.getResources().getDrawable(R.drawable.switch_track_on);
       d.setBounds((int) left, (int) top, (int) right, (int) bottom);
       d.draw(canvas);
 
@@ -94,7 +94,7 @@ public class SwitchTrackTextDrawable extends Drawable {
     else {
 
       // track
-      Drawable d = ResourceUtil.getDrawable(context, R.drawable.switch_track_off);
+      Drawable d = context.getResources().getDrawable(R.drawable.switch_track_off);
       d.setBounds((int) left, (int) top, (int) right, (int) bottom);
       d.draw(canvas);
 

+ 7 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/view/dialog/PromotionDialog.java

@@ -1,5 +1,6 @@
 package kr.co.zumo.app.lifeplus.view.dialog;
 
+import android.graphics.drawable.StateListDrawable;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
@@ -59,14 +60,18 @@ public class PromotionDialog extends DialogBase<ICustomDialogListener<PromotionD
       }
     });
     checkBoxNotShowing = getView().findViewById(R.id.check_box_not_show);
+    StateListDrawable stateListDrawable = new StateListDrawable();
+    stateListDrawable.addState(new int[]{android.R.attr.state_checked}, getView().getContext().getResources().getDrawable(R.drawable.ic_checkbox_on));
+    stateListDrawable.addState(new int[]{-android.R.attr.state_checked}, getView().getContext().getResources().getDrawable(R.drawable.ic_checkbox_off));
+    ((CheckBox) checkBoxNotShowing).setButtonDrawable(stateListDrawable);
     checkBoxNotShowing.setOnClickListener(view -> {
-      if(null != getCustomListener()){
+      if (null != getCustomListener()) {
         getCustomListener().onDialogResult(PromotionDialog.this, new Event.Builder(Event.TODAY).build());
       }
     });
 
     mainBannerView.init(getActivity(), imageBeanList, event -> {
-      if(null != getCustomListener()){
+      if (null != getCustomListener()) {
         getCustomListener().onDialogResult(PromotionDialog.this, event);
       }
     }, false);

+ 1 - 0
app/src/main/res/values/styles.xml

@@ -47,6 +47,7 @@
     <item name="android:windowBackground">@android:color/transparent</item>
     <item name="android:windowTranslucentStatus">true</item>
   </style>
+
   <style name="SignUpButton" parent="@android:style/Widget.DeviceDefault.Button.Borderless">
     <item name="android:layout_width">wrap_content</item>
     <item name="android:layout_height">wrap_content</item>