|
|
@@ -6,6 +6,7 @@ import android.graphics.ColorFilter;
|
|
|
import android.graphics.Paint;
|
|
|
import android.graphics.PixelFormat;
|
|
|
import android.graphics.Rect;
|
|
|
+import android.graphics.Typeface;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.annotation.Nullable;
|
|
|
@@ -32,23 +33,19 @@ public class SwitchTrackTextDrawable extends Drawable {
|
|
|
private Paint textPaint;
|
|
|
private boolean isChecked;
|
|
|
|
|
|
- public SwitchTrackTextDrawable(@NonNull Context context,
|
|
|
- @StringRes int leftTextId,
|
|
|
- @StringRes int rightTextId,
|
|
|
- boolean isChecked
|
|
|
- ) {
|
|
|
+ public SwitchTrackTextDrawable(@NonNull Context context, @StringRes int leftTextId, @StringRes int rightTextId, boolean isChecked) {
|
|
|
this.context = context;
|
|
|
this.isChecked = isChecked;
|
|
|
+ textPaint = doTextPaint();
|
|
|
+ textPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD));
|
|
|
|
|
|
if (isChecked) {
|
|
|
//switch on
|
|
|
- textPaint = doTextPaint();
|
|
|
leftText = context.getString(leftTextId);
|
|
|
rightText = context.getString(R.string.empty_string);
|
|
|
}
|
|
|
else {
|
|
|
//switch off
|
|
|
- textPaint = doTextPaint();
|
|
|
leftText = context.getString(R.string.empty_string);
|
|
|
rightText = context.getString(rightTextId);
|
|
|
}
|
|
|
@@ -69,7 +66,7 @@ public class SwitchTrackTextDrawable extends Drawable {
|
|
|
public void draw(@NonNull Canvas canvas) {
|
|
|
final Rect textBounds = new Rect();
|
|
|
int heightBaseline;
|
|
|
- int widthQuarter = canvas.getClipBounds().width() / 4;;
|
|
|
+ int widthQuarter = canvas.getClipBounds().width() / 4;
|
|
|
|
|
|
if (isChecked) {
|
|
|
//on 텍스트 흰색 변경
|
|
|
@@ -77,8 +74,7 @@ public class SwitchTrackTextDrawable extends Drawable {
|
|
|
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);
|
|
|
+ widthQuarter + 15, heightBaseline, textPaint);
|
|
|
}
|
|
|
else {
|
|
|
//off 텍스트 검정 변경
|
|
|
@@ -87,8 +83,8 @@ public class SwitchTrackTextDrawable extends Drawable {
|
|
|
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);;
|
|
|
+ widthQuarter * 3 - 20, heightBaseline, textPaint);
|
|
|
+ ;
|
|
|
}
|
|
|
|
|
|
|