From e5cf2f1fce807883fb40d32da257d21367c3793c Mon Sep 17 00:00:00 2001 From: sspanak Date: Tue, 18 Apr 2023 13:30:41 +0300 Subject: [PATCH] added numpad separators and imporved the overall readability --- res/layout/main_numpad.xml | 45 ++++++++++++++++--- res/values/colors.xml | 2 + res/values/styles.xml | 5 +++ .../sspanak/tt9/ui/main/MainLayoutNumpad.java | 27 +++++++++++ .../sspanak/tt9/ui/main/keys/SoftKey.java | 18 +++++--- .../tt9/ui/main/keys/SoftNumberKey.java | 5 ++- .../tt9/ui/main/keys/SoftPunctuationKey.java | 2 +- 7 files changed, 87 insertions(+), 17 deletions(-) diff --git a/res/layout/main_numpad.xml b/res/layout/main_numpad.xml index cbb9de40..c09a636c 100644 --- a/res/layout/main_numpad.xml +++ b/res/layout/main_numpad.xml @@ -52,6 +52,10 @@ android:text="⚙" android:textSize="@dimen/soft_key_icon_size" /> + + + + + android:textSize="@dimen/soft_key_icon_size" /> @@ -99,7 +106,12 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" - android:text="+WORD" /> + android:text="+" + android:textStyle="bold" /> + + + + + android:text="⌨️" + android:textSize="@dimen/soft_key_icon_size" /> + + + + + android:text="🌐" /> + + + + #888888 #E7F0E7 + #CCC #C0C0C0 @@ -18,4 +19,5 @@ #555555 #353835 + #555 diff --git a/res/values/styles.xml b/res/values/styles.xml index bef88603..f2c88d9f 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -6,4 +6,9 @@ 1dp 1dp + + diff --git a/src/io/github/sspanak/tt9/ui/main/MainLayoutNumpad.java b/src/io/github/sspanak/tt9/ui/main/MainLayoutNumpad.java index 7927a7f3..34c6c8e8 100644 --- a/src/io/github/sspanak/tt9/ui/main/MainLayoutNumpad.java +++ b/src/io/github/sspanak/tt9/ui/main/MainLayoutNumpad.java @@ -6,6 +6,7 @@ import android.view.ViewGroup; import androidx.core.content.ContextCompat; import java.util.ArrayList; +import java.util.Arrays; import io.github.sspanak.tt9.R; import io.github.sspanak.tt9.ime.TraditionalT9; @@ -32,6 +33,18 @@ class MainLayoutNumpad extends BaseMainLayout { for (SoftKey key : getKeys()) { key.setDarkTheme(darkEnabled); } + + // separators + int separatorColor = ContextCompat.getColor( + view.getContext(), + darkEnabled ? R.color.dark_numpad_separator : R.color.numpad_separator + ); + + for (View separator : getSeparators()) { + if (separator != null) { + separator.setBackgroundColor(separatorColor); + } + } } @Override @@ -61,4 +74,18 @@ class MainLayoutNumpad extends BaseMainLayout { return keys; } + + protected ArrayList getSeparators() { + // it's fine... it's shorter, faster and easier to read than searching with 3 nested loops + return new ArrayList<>(Arrays.asList( + view.findViewById(R.id.separator_1_1), + view.findViewById(R.id.separator_1_2), + view.findViewById(R.id.separator_2_1), + view.findViewById(R.id.separator_2_2), + view.findViewById(R.id.separator_3_1), + view.findViewById(R.id.separator_3_2), + view.findViewById(R.id.separator_4_1), + view.findViewById(R.id.separator_4_2) + )); + } } diff --git a/src/io/github/sspanak/tt9/ui/main/keys/SoftKey.java b/src/io/github/sspanak/tt9/ui/main/keys/SoftKey.java index 2fe77a40..60366490 100644 --- a/src/io/github/sspanak/tt9/ui/main/keys/SoftKey.java +++ b/src/io/github/sspanak/tt9/ui/main/keys/SoftKey.java @@ -18,6 +18,8 @@ import io.github.sspanak.tt9.ime.TraditionalT9; public class SoftKey extends androidx.appcompat.widget.AppCompatButton implements View.OnTouchListener { protected TraditionalT9 tt9; + protected float COMPLEX_LABEL_TITLE_SIZE = 0.55f; + protected float COMPLEX_LABEL_SUB_TITLE_SIZE = 0.8f; public SoftKey(Context context) { super(context); @@ -77,19 +79,21 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement } /** + * getTitle * Generates the name of the key, for example: "OK", "Backspace", "1", etc... */ - protected String getKeyNameLabel() { + protected String getTitle() { return null; } /** + * getSubTitle * Generates a String describing what the key does. * For example: "ABC" for 2-key; "⌫" for Backspace key, "⚙" for Settings key, and so on. * - * The function label is optional. + * The sub title label is optional. */ - protected String getKeyFunctionLabel() { + protected String getSubTitle() { return null; } @@ -103,8 +107,8 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement * have their font size adjusted to fit inside the key. */ public void render() { - String name = getKeyNameLabel(); - String func = getKeyFunctionLabel(); + String name = getTitle(); + String func = getSubTitle(); if (name == null) { return; @@ -117,9 +121,9 @@ public class SoftKey extends androidx.appcompat.widget.AppCompatButton implement sb.append('\n'); sb.append(func); - sb.setSpan(new RelativeSizeSpan(0.55f), 0, 2, Spanned.SPAN_INCLUSIVE_INCLUSIVE); + sb.setSpan(new RelativeSizeSpan(COMPLEX_LABEL_TITLE_SIZE), 0, 2, Spanned.SPAN_INCLUSIVE_INCLUSIVE); sb.setSpan(new StyleSpan(Typeface.ITALIC), 0, 2, Spanned.SPAN_EXCLUSIVE_INCLUSIVE); - sb.setSpan(new RelativeSizeSpan(0.75f), 1, sb.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + sb.setSpan(new RelativeSizeSpan(COMPLEX_LABEL_SUB_TITLE_SIZE), 1, sb.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); setText(sb); } diff --git a/src/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java b/src/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java index 8d55809e..86a84de8 100644 --- a/src/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java +++ b/src/io/github/sspanak/tt9/ui/main/keys/SoftNumberKey.java @@ -59,12 +59,12 @@ public class SoftNumberKey extends SoftKey { } @Override - protected String getKeyNameLabel() { + protected String getTitle() { return String.valueOf(getNumber(getId())); } @Override - protected String getKeyFunctionLabel() { + protected String getSubTitle() { if (tt9 == null || tt9.getSettings().getInputMode() == InputMode.MODE_123) { return null; } @@ -79,6 +79,7 @@ public class SoftNumberKey extends SoftKey { } if (number == 0) { + COMPLEX_LABEL_SUB_TITLE_SIZE = 1; return "␣"; } diff --git a/src/io/github/sspanak/tt9/ui/main/keys/SoftPunctuationKey.java b/src/io/github/sspanak/tt9/ui/main/keys/SoftPunctuationKey.java index c1ecc6d5..afe6228b 100644 --- a/src/io/github/sspanak/tt9/ui/main/keys/SoftPunctuationKey.java +++ b/src/io/github/sspanak/tt9/ui/main/keys/SoftPunctuationKey.java @@ -39,7 +39,7 @@ public class SoftPunctuationKey extends SoftKey { } @Override - protected String getKeyNameLabel() { + protected String getTitle() { int keyId = getId(); if (tt9.getSettings().getInputMode() == InputMode.MODE_123) {