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