changes: themes support, scale for direction text
This commit is contained in:
@@ -13,6 +13,7 @@ import android.text.TextPaint;
|
||||
import android.util.AttributeSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.common.utils.Point2d;
|
||||
import org.solovyev.common.utils.StringUtils;
|
||||
|
||||
@@ -23,6 +24,9 @@ import org.solovyev.common.utils.StringUtils;
|
||||
*/
|
||||
public class DirectionDragButton extends DragButton {
|
||||
|
||||
@NotNull
|
||||
private final static Float DEFAULT_DIRECTION_TEXT_SCALE = 0.33f;
|
||||
|
||||
@Nullable
|
||||
private String textUp;
|
||||
|
||||
@@ -41,6 +45,9 @@ public class DirectionDragButton extends DragButton {
|
||||
@NotNull
|
||||
private TextPaint upDownTextPaint;
|
||||
|
||||
@Nullable
|
||||
private Float directionTextScale = DEFAULT_DIRECTION_TEXT_SCALE;
|
||||
|
||||
public DirectionDragButton(Context context, @NotNull AttributeSet attrs) {
|
||||
super(context, attrs, false);
|
||||
init(context, attrs);
|
||||
@@ -76,12 +83,15 @@ public class DirectionDragButton extends DragButton {
|
||||
for (int i = 0; i < N; i++) {
|
||||
int attr = a.getIndex(i);
|
||||
switch (attr) {
|
||||
case org.solovyev.android.calculator.R.styleable.DragButton_textUp:
|
||||
case R.styleable.DragButton_textUp:
|
||||
this.textUp = a.getString(attr);
|
||||
break;
|
||||
case org.solovyev.android.calculator.R.styleable.DragButton_textDown:
|
||||
case R.styleable.DragButton_textDown:
|
||||
this.textDown = a.getString(attr);
|
||||
break;
|
||||
case R.styleable.DragButton_directionTextScale:
|
||||
this.directionTextScale = Float.valueOf(a.getString(attr));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,15 +109,15 @@ public class DirectionDragButton extends DragButton {
|
||||
initUpDownTextPaint(basePaint);
|
||||
|
||||
if (textUp != null) {
|
||||
textUpPosition = getTextPosition(upDownTextPaint, basePaint, textUp, getText(), 1, getWidth(), getHeight());
|
||||
textUpPosition = getTextPosition(upDownTextPaint, basePaint, textUp, getText(), 1, getWidth(), getHeight(), getDirectionTextScale());
|
||||
}
|
||||
|
||||
if (textDown != null) {
|
||||
textDownPosition = getTextPosition(upDownTextPaint, basePaint, textDown, getText(), -1, getWidth(), getHeight());
|
||||
textDownPosition = getTextPosition(upDownTextPaint, basePaint, textDown, getText(), -1, getWidth(), getHeight(), getDirectionTextScale());
|
||||
}
|
||||
|
||||
if ( textDownPosition != null && textUpPosition != null ) {
|
||||
if ( textDownPosition.getX() > textUpPosition.getX() ) {
|
||||
if (textDownPosition != null && textUpPosition != null) {
|
||||
if (textDownPosition.getX() > textUpPosition.getX()) {
|
||||
textDownPosition.setX(textUpPosition.getX());
|
||||
} else {
|
||||
textUpPosition.setX(textDownPosition.getX());
|
||||
@@ -116,7 +126,7 @@ public class DirectionDragButton extends DragButton {
|
||||
|
||||
}
|
||||
|
||||
public static Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, float direction, int w, int h) {
|
||||
public static Point2d getTextPosition(@NotNull Paint paint, @NotNull Paint basePaint, @NotNull CharSequence text, CharSequence baseText, float direction, int w, int h, float scale) {
|
||||
final Point2d result = new Point2d();
|
||||
|
||||
float width = paint.measureText(text.toString() + " ");
|
||||
@@ -157,15 +167,7 @@ public class DirectionDragButton extends DragButton {
|
||||
|
||||
upDownTextPaint = new TextPaint(paint);
|
||||
upDownTextPaint.setAlpha(150);
|
||||
upDownTextPaint.setTextSize(paint.getTextSize() / 3);
|
||||
}
|
||||
|
||||
private String getStyledUpDownText(@Nullable String text) {
|
||||
return StringUtils.getNotEmpty(text, " ");
|
||||
}
|
||||
|
||||
public void setTextUp(@Nullable String textUp) {
|
||||
this.textUp = textUp;
|
||||
upDownTextPaint.setTextSize(paint.getTextSize() * getDirectionTextScale());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -173,19 +175,11 @@ public class DirectionDragButton extends DragButton {
|
||||
return textUp;
|
||||
}
|
||||
|
||||
public void setTextDown(@Nullable String textDown) {
|
||||
this.textDown = textDown;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getTextDown() {
|
||||
return textDown;
|
||||
}
|
||||
|
||||
public void setTextMiddle(@Nullable String textMiddle) {
|
||||
this.textMiddle = textMiddle;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getTextMiddle() {
|
||||
return textMiddle;
|
||||
@@ -197,7 +191,7 @@ public class DirectionDragButton extends DragButton {
|
||||
|
||||
if (direction == DragDirection.up) {
|
||||
result = getTextUp();
|
||||
} else if ( direction == DragDirection.down ) {
|
||||
} else if (direction == DragDirection.down) {
|
||||
result = getTextDown();
|
||||
} else {
|
||||
result = null;
|
||||
@@ -205,4 +199,10 @@ public class DirectionDragButton extends DragButton {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Float getDirectionTextScale() {
|
||||
return directionTextScale == null ? DEFAULT_DIRECTION_TEXT_SCALE : directionTextScale;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ package org.solovyev.android.view.widgets;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -146,8 +145,7 @@ public class SimpleOnDragListener implements OnDragListener, DragPreferencesChan
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Preferences getPreferences(@NotNull Context context) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
public static Preferences getPreferences(@NotNull final SharedPreferences preferences, @NotNull Context context) {
|
||||
|
||||
final Mapper<Interval<Float>> mapper = new NumberIntervalMapper<Float>(Float.class);
|
||||
|
||||
|
Reference in New Issue
Block a user