Style fixing

This commit is contained in:
serso 2016-03-09 22:21:20 +01:00
parent 84be914bd5
commit cc1a7817eb
4 changed files with 18 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import android.content.res.TypedArray;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.Typeface;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextPaint; import android.text.TextPaint;
@ -21,7 +22,7 @@ import java.util.Map;
public class DirectionTextView { 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; public static final float DEF_SCALE = 0.4f;
@NonNull @NonNull
@ -89,6 +90,7 @@ public class DirectionTextView {
@NonNull @NonNull
private final View view; private final View view;
private final float minTextSize; private final float minTextSize;
private float fixedTextHeight = 0;
@NonNull @NonNull
private final PointF position = new PointF(-1, -1); private final PointF position = new PointF(-1, -1);
@NonNull @NonNull
@ -125,7 +127,16 @@ public class DirectionTextView {
paint.set(base); paint.set(base);
paint.setColor(color); paint.setColor(color);
paint.setAlpha(intAlpha()); 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)); paint.setTextSize(Math.max(base.getTextSize() * scale, minTextSize));
invalidate(true); invalidate(true);
} }
@ -188,7 +199,7 @@ public class DirectionTextView {
case down: case down:
position.x = view.getWidth() - paddingLeft - bounds.width(); position.x = view.getWidth() - paddingLeft - bounds.width();
if (direction == DragDirection.up) { if (direction == DragDirection.up) {
position.y = paddingTop + bounds.height(); position.y = paddingTop + fixedTextHeight;
} else { } else {
position.y = view.getHeight() - paddingBottom; position.y = view.getHeight() - paddingBottom;
} }
@ -201,14 +212,14 @@ public class DirectionTextView {
position.x = view.getWidth() - paddingRight - bounds.width(); position.x = view.getWidth() - paddingRight - bounds.width();
} }
final int availableHeight = view.getHeight() - verticalPaddings; final int availableHeight = view.getHeight() - verticalPaddings;
position.y = paddingTop + availableHeight / 2 + bounds.height() / 2; position.y = paddingTop + availableHeight / 2 + fixedTextHeight / 2;
break; break;
} }
} }
@NonNull @NonNull
public String getValue() { public String getValue() {
return value; return visible ? value : "";
} }
public void setValue(@NonNull String value) { public void setValue(@NonNull String value) {

View File

@ -30,6 +30,6 @@
style="?attr/cpp_button_style_digit" style="?attr/cpp_button_style_digit"
a:text="( )" a:text="( )"
c:directionTextDown=")" c:directionTextDown=")"
c:directionTextLeft="()" c:directionTextLeft="()"
c:directionTextUp="(" c:directionTextUp="("
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />

View File

@ -10,7 +10,7 @@
<dimen name="cpp_button_padding">1px</dimen> <dimen name="cpp_button_padding">1px</dimen>
<dimen name="cpp_direction_text_default_padding">2dp</dimen> <dimen name="cpp_direction_text_default_padding">2dp</dimen>
<dimen name="cpp_direction_text_min_size">9dp</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_button_corner">1dp</dimen>
<dimen name="cpp_keyboard_button_direction_text_padding">4dp</dimen> <dimen name="cpp_keyboard_button_direction_text_padding">4dp</dimen>

View File

@ -28,6 +28,7 @@
<style name="CppKeyboardButton.Material.Light.Operation" parent="CppKeyboardButton.Material.Digit"> <style name="CppKeyboardButton.Material.Light.Operation" parent="CppKeyboardButton.Material.Digit">
<item name="android:background">@drawable/material_button_light_primary</item> <item name="android:background">@drawable/material_button_light_primary</item>
<item name="directionTextAlpha">0.7</item>
</style> </style>
<style name="CppKeyboardButton.Material.Light.Control.Image" parent="CppKeyboardButton.Material.Light.Digit"/> <style name="CppKeyboardButton.Material.Light.Control.Image" parent="CppKeyboardButton.Material.Light.Digit"/>