Skip to content

Commit 2ecf93d

Browse files
authored
Candidates view improvements (#1168)
* Refactor: Create subpackage 'suggestions' * Candidates view: Status message when no dictionary installed Show a message on the candidates view instead of leaving it empty. A button points to the dictionary installation activity. * Add an option to disable the suggestions * Refactor: Remove Config.should_show_candidates_view This was moved to EditorConfig. * Don't disable text suggestions in some text boxes * Suggestion text size matching settings The candidates view height is based on the height of keyboard rows and the suggestion text size is based on the size of labels on the keys. This is influenced by symbol size and keyboard height options.
1 parent b9072da commit 2ecf93d

14 files changed

Lines changed: 110 additions & 31 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/candidates_status">
3+
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/candidates_status_no_dict"/>
4+
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/candidates_status_install"/>
5+
</LinearLayout>

res/layout/keyboard.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:hardwareAccelerated="false" android:orientation="vertical" android:background="?attr/colorKeyboard">
3-
<juloo.keyboard2.CandidatesView android:id="@+id/candidates_view" android:layout_width="match_parent" android:layout_height="48dp" android:orientation="horizontal">
3+
<juloo.keyboard2.suggestions.CandidatesView android:id="@+id/candidates_view" android:layout_width="match_parent" android:layout_height="48dp" android:orientation="horizontal" android:gravity="center">
44
<TextView android:id="@+id/candidates_left" style="@style/candidates_item" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>
55
<TextView android:id="@+id/candidates_middle" style="@style/candidates_item" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>
66
<TextView android:id="@+id/candidates_right" style="@style/candidates_item" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1"/>
7-
</juloo.keyboard2.CandidatesView>
7+
</juloo.keyboard2.suggestions.CandidatesView>
88
<juloo.keyboard2.Keyboard2View android:id="@+id/keyboard_view" android:layout_width="match_parent" android:layout_height="wrap_content"/>
99
</LinearLayout>

res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
<string name="pref_extra_keys_title">Add keys to the keyboard</string>
3434
<string name="pref_extra_keys_custom">Add custom keys</string>
3535
<string name="pref_extra_keys_internal">Select keys to add to the keyboard</string>
36+
<string name="pref_category_suggestions">Suggestions</string>
37+
<string name="pref_suggestions_title">Suggestions</string>
38+
<string name="pref_suggestions_summary">Enable word completion and spell checking</string>
3639
<string name="pref_category_typing">Typing</string>
3740
<string name="pref_swipe_dist_title">Swiping distance</string>
3841
<string name="pref_swipe_dist_summary">Distance of characters in the corners of the keys (%s)</string>
@@ -151,4 +154,6 @@
151154
<string name="pref_clipboard_history_duration_30">At most 30 minutes</string>
152155
<string name="pref_clipboard_history_duration_stop">Until the app stops</string>
153156
<string name="pref_dialog_edit_text">Custom definition</string>
157+
<string name="candidates_status_no_dict">No dictionary installed</string>
158+
<string name="candidates_status_install">Install</string>
154159
</resources>

res/values/styles.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
<!-- Candidates view -->
44
<style name="candidates_item">
55
<item name="android:gravity">center</item>
6-
<item name="android:textSize">18sp</item>
6+
<item name="android:textColor">?attr/colorLabel</item>
7+
</style>
8+
<style name="candidates_status">
9+
<item name="android:layout_width">match_parent</item>
10+
<item name="android:layout_height">wrap_content</item>
11+
<item name="android:gravity">center</item>
712
<item name="android:textColor">?attr/colorLabel</item>
813
</style>
914
<!-- Emoji pane -->

res/xml/settings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<ListPreference android:key="show_numpad" android:title="@string/pref_show_numpad_title" android:summary="%s" android:defaultValue="1" android:entries="@array/pref_show_numpad_entries" android:entryValues="@array/pref_show_numpad_values"/>
1313
<ListPreference android:key="numpad_layout" android:title="@string/pref_numpad_layout" android:summary="%s" android:defaultValue="high_first" android:entries="@array/pref_numpad_layout_entries" android:entryValues="@array/pref_numpad_layout_values"/>
1414
</PreferenceCategory>
15+
<PreferenceCategory android:title="@string/pref_category_suggestions">
16+
<CheckBoxPreference android:key="suggestions" android:title="@string/pref_suggestions_title" android:summary="@string/pref_suggestions_summary" android:defaultValue="true"/>
17+
</PreferenceCategory>
1518
<PreferenceCategory android:title="@string/pref_category_typing">
1619
<ListPreference android:key="swipe_dist" android:title="@string/pref_swipe_dist_title" android:summary="@string/pref_swipe_dist_summary" android:defaultValue="15" android:entries="@array/pref_swipe_dist_entries" android:entryValues="@array/pref_swipe_dist_values"/>
1720
<ListPreference android:key="circle_sensitivity" android:title="@string/pref_circle_sensitivity_title" android:summary="%s" android:defaultValue="2" android:entries="@array/pref_circle_sensitivity_entries" android:entryValues="@array/pref_circle_sensitivity_values"/>

srcs/juloo.keyboard2/Config.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public final class Config
4242
public boolean number_row_symbols;
4343
public float swipe_dist_px;
4444
public float slide_step_px;
45+
public boolean suggestions_enabled;
4546
// Let the system handle vibration when false.
4647
public boolean vibrate_custom;
4748
// Control the vibration if [vibrate_custom] is true.
@@ -50,7 +51,7 @@ public final class Config
5051
public long longPressInterval;
5152
public boolean keyrepeat_enabled;
5253
public float margin_bottom;
53-
public int keyboardHeightPercent;
54+
public int keyboard_rows_height_pixels;
5455
public int screenHeightPixels;
5556
public float horizontal_margin;
5657
public float key_vertical_margin;
@@ -75,7 +76,6 @@ public final class Config
7576
// Dynamically set
7677
/** Configuration options implied by the connected editor. */
7778
public EditorConfig editor_config;
78-
public boolean should_show_candidates_view;
7979
public boolean shouldOfferVoiceTyping;
8080
public ExtraKeys extra_keys_subtype;
8181
public Map<KeyValue, KeyboardData.PreferredPos> extra_keys_param;
@@ -102,7 +102,6 @@ private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h, Boole
102102
// from prefs
103103
refresh(res, foldableUnfolded);
104104
// initialized later
105-
should_show_candidates_view = false;
106105
shouldOfferVoiceTyping = false;
107106
extra_keys_subtype = null;
108107
handler = h;
@@ -120,6 +119,7 @@ public void refresh(Resources res, Boolean foldableUnfolded)
120119
float characterSizeScale = 1.f;
121120
String show_numpad_s = _prefs.getString("show_numpad", "never");
122121
show_numpad = "always".equals(show_numpad_s);
122+
int keyboardHeightPercent;
123123
if (orientation_landscape)
124124
{
125125
if ("landscape".equals(show_numpad_s))
@@ -136,6 +136,7 @@ public void refresh(Resources res, Boolean foldableUnfolded)
136136
String number_row = _prefs.getString("number_row", "no_number_row");
137137
add_number_row = !number_row.equals("no_number_row");
138138
number_row_symbols = number_row.equals("symbols");
139+
suggestions_enabled = _prefs.getBoolean("suggestions", true);
139140
// The baseline for the swipe distance correspond to approximately the
140141
// width of a key in portrait mode, as most layouts have 10 columns.
141142
// Multipled by the DPI ratio because most swipes are made in the diagonals.
@@ -165,6 +166,12 @@ public void refresh(Resources res, Boolean foldableUnfolded)
165166
customBorderRadius = _prefs.getInt("custom_border_radius", 0) / 100.f;
166167
customBorderLineWidth = get_dip_pref(dm, "custom_border_line_width", 0);
167168
screenHeightPixels = dm.heightPixels;
169+
// Rows height is proportional to the screen height, meaning it doesn't
170+
// change for layouts with more or less rows. 3.95 is the usual height of
171+
// a layout in KeyboardData unit. The keyboard will be higher if the layout
172+
// has more rows and smaller if it has less because rows stay the same
173+
// height.
174+
keyboard_rows_height_pixels = screenHeightPixels * keyboardHeightPercent / 395;
168175
horizontal_margin =
169176
get_dip_pref_oriented(dm, "horizontal_margin", 3, 28);
170177
double_tap_lock_shift = _prefs.getBoolean("lock_double_tap", false);

srcs/juloo.keyboard2/CurrentlyTypedWord.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,9 @@ void refresh_current_word()
113113
/** Refresh the current word by immediately querying the editor. */
114114
void set_current_word(CharSequence text_before_cursor)
115115
{
116+
_w.setLength(0);
116117
if (text_before_cursor == null)
117-
{
118-
_enabled = false;
119118
return;
120-
}
121-
_w.setLength(0);
122119
int saved_cursor = _cursor;
123120
type_chars(text_before_cursor.toString());
124121
_cursor = saved_cursor;

srcs/juloo.keyboard2/EditorConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import android.text.InputType;
66
import android.text.TextUtils;
77
import android.view.inputmethod.EditorInfo;
8-
import juloo.keyboard2.CandidatesView;
8+
import juloo.keyboard2.suggestions.CandidatesView;
99

1010
public final class EditorConfig
1111
{

srcs/juloo.keyboard2/KeyEventHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package juloo.keyboard2;
22

33
import android.annotation.SuppressLint;
4-
import android.os.Looper;
54
import android.os.Handler;
5+
import android.os.Looper;
66
import android.view.KeyCharacterMap;
77
import android.view.KeyEvent;
88
import android.view.inputmethod.ExtractedText;
99
import android.view.inputmethod.ExtractedTextRequest;
1010
import android.view.inputmethod.InputConnection;
1111
import java.util.Iterator;
12+
import juloo.keyboard2.suggestions.Suggestions;
1213

1314
public final class KeyEventHandler
1415
implements Config.IKeyEventHandler,

srcs/juloo.keyboard2/Keyboard2.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Set;
2626
import juloo.keyboard2.prefs.LayoutsPreference;
27+
import juloo.keyboard2.suggestions.CandidatesView;
2728

2829
public class Keyboard2 extends InputMethodService
2930
implements SharedPreferences.OnSharedPreferenceChangeListener
@@ -164,7 +165,11 @@ private void refreshSubtypeImm()
164165

165166
private void refresh_candidates_view()
166167
{
167-
boolean should_show = _config.editor_config.should_show_candidates_view;
168+
boolean should_show =
169+
_config.suggestions_enabled
170+
&& _config.editor_config.should_show_candidates_view;
171+
if (should_show)
172+
_candidates_view.refresh_config(_config);
168173
_candidates_view.setVisibility(should_show ? View.VISIBLE : View.GONE);
169174
}
170175

@@ -185,6 +190,7 @@ private void refresh_config()
185190
// Set keyboard background opacity
186191
_container_view.getBackground().setAlpha(_config.keyboardOpacity);
187192
_keyboardView.reset();
193+
refresh_candidates_view();
188194
}
189195

190196
private KeyboardData refresh_special_layout()
@@ -205,7 +211,6 @@ public void onStartInputView(EditorInfo info, boolean restarting)
205211
{
206212
_config.editor_config.refresh(info, getResources());
207213
refresh_config();
208-
refresh_candidates_view();
209214
_currentSpecialLayout = refresh_special_layout();
210215
_keyboardView.setKeyboard(current_layout());
211216
_keyeventhandler.started(_config);

0 commit comments

Comments
 (0)