Style fixing
This commit is contained in:
parent
84be914bd5
commit
cc1a7817eb
@ -5,6 +5,7 @@ import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.TextPaint;
|
||||
@ -21,7 +22,7 @@ import java.util.Map;
|
||||
|
||||
public class DirectionTextView {
|
||||
|
||||
public static final float DEF_ALPHA = 0.55f;
|
||||
public static final float DEF_ALPHA = 0.4f;
|
||||
public static final float DEF_SCALE = 0.4f;
|
||||
|
||||
@NonNull
|
||||
@ -89,6 +90,7 @@ public class DirectionTextView {
|
||||
@NonNull
|
||||
private final View view;
|
||||
private final float minTextSize;
|
||||
private float fixedTextHeight = 0;
|
||||
@NonNull
|
||||
private final PointF position = new PointF(-1, -1);
|
||||
@NonNull
|
||||
@ -125,7 +127,16 @@ public class DirectionTextView {
|
||||
paint.set(base);
|
||||
paint.setColor(color);
|
||||
paint.setAlpha(intAlpha());
|
||||
paint.setTypeface(Typeface.DEFAULT);
|
||||
|
||||
// pre-calculate fixed height
|
||||
paint.setTextSize(Math.max(base.getTextSize() * DEF_SCALE, minTextSize));
|
||||
paint.getTextBounds("|", 0, 1, bounds);
|
||||
fixedTextHeight = bounds.height();
|
||||
|
||||
// set real text size value
|
||||
paint.setTextSize(Math.max(base.getTextSize() * scale, minTextSize));
|
||||
|
||||
invalidate(true);
|
||||
}
|
||||
|
||||
@ -188,7 +199,7 @@ public class DirectionTextView {
|
||||
case down:
|
||||
position.x = view.getWidth() - paddingLeft - bounds.width();
|
||||
if (direction == DragDirection.up) {
|
||||
position.y = paddingTop + bounds.height();
|
||||
position.y = paddingTop + fixedTextHeight;
|
||||
} else {
|
||||
position.y = view.getHeight() - paddingBottom;
|
||||
}
|
||||
@ -201,14 +212,14 @@ public class DirectionTextView {
|
||||
position.x = view.getWidth() - paddingRight - bounds.width();
|
||||
}
|
||||
final int availableHeight = view.getHeight() - verticalPaddings;
|
||||
position.y = paddingTop + availableHeight / 2 + bounds.height() / 2;
|
||||
position.y = paddingTop + availableHeight / 2 + fixedTextHeight / 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getValue() {
|
||||
return value;
|
||||
return visible ? value : "";
|
||||
}
|
||||
|
||||
public void setValue(@NonNull String value) {
|
||||
|
@ -30,6 +30,6 @@
|
||||
style="?attr/cpp_button_style_digit"
|
||||
a:text="( )"
|
||||
c:directionTextDown=")"
|
||||
c:directionTextLeft="(…)"
|
||||
c:directionTextLeft="(∙)"
|
||||
c:directionTextUp="("
|
||||
tools:ignore="HardcodedText" />
|
@ -10,7 +10,7 @@
|
||||
<dimen name="cpp_button_padding">1px</dimen>
|
||||
<dimen name="cpp_direction_text_default_padding">2dp</dimen>
|
||||
<dimen name="cpp_direction_text_min_size">9dp</dimen>
|
||||
<item name="cpp_direction_text_scale" format="float" type="dimen">0.3</item>
|
||||
<item name="cpp_direction_text_scale" format="float" type="dimen">0.45</item>
|
||||
<dimen name="cpp_button_corner">1dp</dimen>
|
||||
|
||||
<dimen name="cpp_keyboard_button_direction_text_padding">4dp</dimen>
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
<style name="CppKeyboardButton.Material.Light.Operation" parent="CppKeyboardButton.Material.Digit">
|
||||
<item name="android:background">@drawable/material_button_light_primary</item>
|
||||
<item name="directionTextAlpha">0.7</item>
|
||||
</style>
|
||||
|
||||
<style name="CppKeyboardButton.Material.Light.Control.Image" parent="CppKeyboardButton.Material.Light.Digit"/>
|
||||
|
Loading…
Reference in New Issue
Block a user