|
|
@@ -10,6 +10,7 @@ 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;
|
|
|
@@ -26,13 +27,10 @@ import kr.co.zumo.app.lifeplus.util.ResourceUtil;
|
|
|
*/
|
|
|
public class SwitchTrackTextDrawable extends Drawable {
|
|
|
|
|
|
- private final Context mContext;
|
|
|
-
|
|
|
- private final String mLeftText;
|
|
|
-
|
|
|
- private final String mRightText;
|
|
|
-
|
|
|
- private final Paint mTextPaint;
|
|
|
+ private Context context;
|
|
|
+ private String leftText;
|
|
|
+ private String rightText;
|
|
|
+ private Paint textPaint;
|
|
|
private boolean isChecked;
|
|
|
|
|
|
public SwitchTrackTextDrawable(@NonNull Context context,
|
|
|
@@ -40,27 +38,25 @@ public class SwitchTrackTextDrawable extends Drawable {
|
|
|
@StringRes int rightTextId,
|
|
|
boolean isChecked
|
|
|
) {
|
|
|
- mContext = context;
|
|
|
-
|
|
|
+ this.context = context;
|
|
|
this.isChecked = isChecked;
|
|
|
|
|
|
if (isChecked) {
|
|
|
//switch on
|
|
|
- mLeftText = context.getString(leftTextId);
|
|
|
- mTextPaint = LeftTextPaint();
|
|
|
- mRightText = context.getString(R.string.empty_string);
|
|
|
-
|
|
|
+ textPaint = doTextPaint();
|
|
|
+ leftText = context.getString(leftTextId);
|
|
|
+ rightText = context.getString(R.string.empty_string);
|
|
|
}
|
|
|
else {
|
|
|
//switch off
|
|
|
- mLeftText = context.getString(R.string.empty_string);
|
|
|
- mTextPaint = LeftTextPaint();
|
|
|
- mRightText = context.getString(rightTextId);
|
|
|
+ textPaint = doTextPaint();
|
|
|
+ leftText = context.getString(R.string.empty_string);
|
|
|
+ rightText = context.getString(rightTextId);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
- private Paint LeftTextPaint() {
|
|
|
+ private Paint doTextPaint() {
|
|
|
Paint textPaint = new Paint();
|
|
|
textPaint.setAntiAlias(true);
|
|
|
textPaint.setStyle(Paint.Style.FILL);
|
|
|
@@ -73,23 +69,32 @@ public class SwitchTrackTextDrawable extends Drawable {
|
|
|
@Override
|
|
|
public void draw(@NonNull Canvas canvas) {
|
|
|
final Rect textBounds = new Rect();
|
|
|
- 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 widthQuarter = canvas.getClipBounds().width() / 4;
|
|
|
-
|
|
|
- //on 텍스트 흰색 변경
|
|
|
- mTextPaint.setColor(mContext.getResources().getColor(android.R.color.white));
|
|
|
- canvas.drawText(mLeftText, 0, mLeftText.length(),
|
|
|
- widthQuarter + 15, 53,
|
|
|
- mTextPaint);
|
|
|
-
|
|
|
- //off 텍스트 검정 변경
|
|
|
- mTextPaint.setColor(mContext.getResources().getColor(android.R.color.darker_gray));
|
|
|
- canvas.drawText(mRightText, 0, mRightText.length(),
|
|
|
- widthQuarter * 3 - 25, 53,
|
|
|
- mTextPaint);
|
|
|
+ int heightBaseline;
|
|
|
+ int widthQuarter = canvas.getClipBounds().width() / 4;;
|
|
|
+
|
|
|
+ if (isChecked) {
|
|
|
+ //on 텍스트 흰색 변경
|
|
|
+ textPaint.getTextBounds(leftText, 0, leftText.length(), textBounds);
|
|
|
+ heightBaseline = canvas.getClipBounds().height() / 2 + textBounds.height() / 2;
|
|
|
+ textPaint.setColor(context.getResources().getColor(android.R.color.white));
|
|
|
+ canvas.drawText(leftText, 0, leftText.length(),
|
|
|
+ widthQuarter + 15, heightBaseline,
|
|
|
+ textPaint);
|
|
|
+ Log.e("APP# SwitchTrackTextDrawable | draw", "| on" + widthQuarter);
|
|
|
+ //40
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //off 텍스트 검정 변경
|
|
|
+ textPaint.getTextBounds(rightText, 0, rightText.length(), textBounds);
|
|
|
+ widthQuarter = canvas.getClipBounds().width() / 4;
|
|
|
+ heightBaseline = canvas.getClipBounds().height() / 2 + textBounds.height() / 2;
|
|
|
+ textPaint.setColor(context.getResources().getColor(android.R.color.darker_gray));
|
|
|
+ canvas.drawText(rightText, 0, rightText.length(),
|
|
|
+ widthQuarter * 3 - 20, heightBaseline,
|
|
|
+ textPaint);;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|