abouttreesummaryrefslogcommitdiff
diff options
context:
space:
mode:
authorJules Aguillon2026-05-01 20:25:20 +0200
committerGitHub2026-05-01 20:25:20 +0200
commitd164820bca8d2182869108f8a015ce3d987d048d (patch)
tree7890ce5114766ba91e8092c2bf388d0b7820e11a
parentb844af1f289921592a8bfb7e5a174d4e1b33c0dd (diff)
downloadunexpected-keyboard-d164820bca8d2182869108f8a015ce3d987d048d.tar.gz
unexpected-keyboard-d164820bca8d2182869108f8a015ce3d987d048d.zip
Reduce the size of suggestions to fit (#1248)
The font size of the suggested words is reduced if the word would otherwise split on two lines.
-rw-r--r--res/layout/keyboard.xml8
-rw-r--r--res/values/styles.xml11
-rw-r--r--res/values/values.xml2
-rw-r--r--srcs/juloo.keyboard2/suggestions/CandidatesView.java14
4 files changed, 27 insertions, 8 deletions
diff --git a/res/layout/keyboard.xml b/res/layout/keyboard.xml
index f512979..3fb611f 100644
--- a/res/layout/keyboard.xml
+++ b/res/layout/keyboard.xml
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:hardwareAccelerated="false" android:orientation="vertical" android:background="?attr/colorKeyboard">
- <juloo.keyboard2.suggestions.CandidatesView android:id="@+id/candidates_view" android:layout_width="match_parent" android:layout_height="48dp" android:orientation="horizontal" android:gravity="center">
- <TextView android:id="@+id/candidates_left" style="@style/candidates_item" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>
- <TextView android:id="@+id/candidates_middle" style="@style/candidates_item" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>
- <TextView android:id="@+id/candidates_right" style="@style/candidates_item" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>
+ <juloo.keyboard2.suggestions.CandidatesView android:id="@+id/candidates_view" style="@style/candidates_view">
+ <TextView android:id="@+id/candidates_left" style="@style/candidates_item" android:layout_width="match_parent"/>
+ <TextView android:id="@+id/candidates_middle" style="@style/candidates_item" android:layout_width="match_parent"/>
+ <TextView android:id="@+id/candidates_right" style="@style/candidates_item" android:layout_width="match_parent"/>
</juloo.keyboard2.suggestions.CandidatesView>
<juloo.keyboard2.Keyboard2View android:id="@+id/keyboard_view" android:layout_width="match_parent" android:layout_height="wrap_content"/>
</LinearLayout>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 6977e00..ce8894a 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -1,9 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Candidates view -->
+ <style name="candidates_view">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">48dp</item>
+ <item name="android:orientation">horizontal</item>
+ <item name="android:gravity">center</item>
+ </style>
<style name="candidates_item">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">match_parent</item>
+ <item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:textColor">?attr/colorLabel</item>
+ <item name="android:maxLines">1</item>
+ <item name="android:paddingHorizontal">@dimen/candidates_padding</item>
</style>
<style name="candidates_status">
<item name="android:layout_width">match_parent</item>
diff --git a/res/values/values.xml b/res/values/values.xml
index 9f23212..321f0b1 100644
--- a/res/values/values.xml
+++ b/res/values/values.xml
@@ -6,7 +6,7 @@
<dimen name="emoji_text_size">28dp</dimen>
<dimen name="clipboard_view_height">300dp</dimen>
<dimen name="pref_button_size">28dp</dimen>
- <dimen name="candidates_spacing">8dp</dimen>
+ <dimen name="candidates_padding">3dp</dimen>
<!-- Will be overwritten automatically by Gradle for the debug build variant -->
<bool name="debug_logs">false</bool>
<!-- Color fallback for the Monet themes on Android API < 31. This makes the
diff --git a/srcs/juloo.keyboard2/suggestions/CandidatesView.java b/srcs/juloo.keyboard2/suggestions/CandidatesView.java
index 1768a52..6eba62a 100644
--- a/srcs/juloo.keyboard2/suggestions/CandidatesView.java
+++ b/srcs/juloo.keyboard2/suggestions/CandidatesView.java
@@ -1,6 +1,7 @@
package juloo.keyboard2.suggestions;
import android.content.Context;
+import android.os.Build.VERSION;
import android.text.InputType;
import android.util.AttributeSet;
import android.util.TypedValue;
@@ -76,10 +77,11 @@ public class CandidatesView extends LinearLayout
_status_no_dict = inflate_and_show(_status_no_dict,
(config.current_dictionary == null),
R.layout.candidates_status_no_dict);
- set_height(config);
+ set_sizes(config);
}
- void set_height(Config config)
+ /** Set the height of the suggestion row and the text size. */
+ void set_sizes(Config config)
{
// Make the candidates view about as high as a keyboard row.
int height = (int)(config.keyboard_rows_height_pixels * (1 - config.key_vertical_margin));
@@ -88,11 +90,17 @@ public class CandidatesView extends LinearLayout
for (int i = 0; i < NUM_CANDIDATES; i++)
{
TextView v = _item_views[i];
+ // Set view height
ViewGroup.MarginLayoutParams p =
(ViewGroup.MarginLayoutParams)v.getLayoutParams();
p.height = height;
v.setLayoutParams(p);
- v.setTextSize(TypedValue.COMPLEX_UNIT_PX, text_size);
+ // Set text size and enable auto size if supported.
+ if (VERSION.SDK_INT < 26)
+ v.setTextSize(TypedValue.COMPLEX_UNIT_PX, text_size);
+ else
+ v.setAutoSizeTextTypeUniformWithConfiguration(
+ (int)(text_size / 2.), (int)text_size, 1, TypedValue.COMPLEX_UNIT_PX);
}
}