From cc1a7817eb31b3497e3e4ae8143359baaa544ccd Mon Sep 17 00:00:00 2001 From: serso Date: Wed, 9 Mar 2016 22:21:20 +0100 Subject: [PATCH] Style fixing --- .../views/dragbutton/DirectionTextView.java | 19 +++++++++++++++---- .../layout/cpp_app_button_round_brackets.xml | 2 +- app/src/main/res/values/dimens.xml | 2 +- .../main/res/values/theme_material_light.xml | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java index 9923c6a8..0e997b71 100644 --- a/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java +++ b/app/src/main/java/org/solovyev/android/views/dragbutton/DirectionTextView.java @@ -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) { diff --git a/app/src/main/res/layout/cpp_app_button_round_brackets.xml b/app/src/main/res/layout/cpp_app_button_round_brackets.xml index 06dac7c6..0f7d104a 100644 --- a/app/src/main/res/layout/cpp_app_button_round_brackets.xml +++ b/app/src/main/res/layout/cpp_app_button_round_brackets.xml @@ -30,6 +30,6 @@ style="?attr/cpp_button_style_digit" a:text="( )" c:directionTextDown=")" - c:directionTextLeft="(…)" + c:directionTextLeft="(∙)" c:directionTextUp="(" tools:ignore="HardcodedText" /> \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 8781d513..2fc75e09 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -10,7 +10,7 @@ 1px 2dp 9dp - 0.3 + 0.45 1dp 4dp diff --git a/app/src/main/res/values/theme_material_light.xml b/app/src/main/res/values/theme_material_light.xml index 06664524..6a4dd8f7 100644 --- a/app/src/main/res/values/theme_material_light.xml +++ b/app/src/main/res/values/theme_material_light.xml @@ -28,6 +28,7 @@