|
|
@@ -0,0 +1,70 @@
|
|
|
+/*
|
|
|
+ * 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.Nullable;
|
|
|
+import android.util.AttributeSet;
|
|
|
+import android.widget.CompoundButton;
|
|
|
+import android.widget.Switch;
|
|
|
+
|
|
|
+import kr.co.zumo.app.R;
|
|
|
+import kr.co.zumo.app.lifeplus.view.fragment.setting.SwitchTrackTextDrawable;
|
|
|
+
|
|
|
+/**
|
|
|
+ * OnOffSwitch
|
|
|
+ * <pre>
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @author 민효동
|
|
|
+ * @version 1.0
|
|
|
+ * @history 민효동 [2018. 10. 24.] [최초 작성]
|
|
|
+ * @since 2018. 10. 24.
|
|
|
+ */
|
|
|
+public class OnOffSwitch extends Switch {
|
|
|
+
|
|
|
+ protected CompoundButton.OnCheckedChangeListener onCheckedChangeListener;
|
|
|
+
|
|
|
+ public OnOffSwitch(Context context) {
|
|
|
+// super(context);
|
|
|
+ super(context, null, R.style.OnOffSwitch);
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+ public OnOffSwitch(Context context, AttributeSet attrs) {
|
|
|
+ super(context, attrs, R.style.OnOffSwitch);
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+ public OnOffSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
+ super(context, attrs, R.style.OnOffSwitch);
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void init() {
|
|
|
+ setTrackDrawable(new SwitchTrackTextDrawable(getContext(), R.string.on, R.string.off, false));
|
|
|
+
|
|
|
+ super.setOnCheckedChangeListener((compoundButton, isChecked) -> {
|
|
|
+ performOnCheckedChanged(compoundButton, isChecked);
|
|
|
+
|
|
|
+ if (isChecked) {
|
|
|
+ setTrackDrawable(new SwitchTrackTextDrawable(getContext(), R.string.on, R.string.off, true));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ setTrackDrawable(new SwitchTrackTextDrawable(getContext(), R.string.on, R.string.off, false));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void performOnCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
|
|
|
+ if (null != onCheckedChangeListener) {
|
|
|
+ onCheckedChangeListener.onCheckedChanged(compoundButton, isChecked);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void setOnCheckedChangeListener(@Nullable OnCheckedChangeListener listener) {
|
|
|
+ onCheckedChangeListener = listener;
|
|
|
+ }
|
|
|
+}
|