Skip to content

Commit c8b72bb

Browse files
Julowpashol
authored andcommitted
Candidates view improvements (Julow#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 32a4c13 commit c8b72bb

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
@@ -34,6 +34,9 @@
3434
<string name="pref_extra_keys_title">Add keys to the keyboard</string>
3535
<string name="pref_extra_keys_custom">Add custom keys</string>
3636
<string name="pref_extra_keys_internal">Select keys to add to the keyboard</string>
37+
<string name="pref_category_suggestions">Suggestions</string>
38+
<string name="pref_suggestions_title">Suggestions</string>
39+
<string name="pref_suggestions_summary">Enable word completion and spell checking</string>
3740
<string name="pref_category_typing">Typing</string>
3841
<string name="pref_swipe_dist_title">Swiping distance</string>
3942
<string name="pref_swipe_dist_summary">Distance of characters in the corners of the keys (%s)</string>
@@ -135,4 +138,6 @@
135138
<string name="clipboard_remove_confirm">Remove this clipboard item?</string>
136139
<string name="clipboard_remove_confirmed">Yes</string>
137140
<string name="toast_no_voice_input">No voice typing app installed</string>
141+
<string name="candidates_status_no_dict">No dictionary installed</string>
142+
<string name="candidates_status_install">Install</string>
138143
</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
@@ -34,6 +34,7 @@ public final class Config
3434
public boolean number_row_symbols;
3535
public float swipe_dist_px;
3636
public float slide_step_px;
37+
public boolean suggestions_enabled;
3738
// Let the system handle vibration when false.
3839
public boolean vibrate_custom;
3940
// Control the vibration if [vibrate_custom] is true.
@@ -42,7 +43,7 @@ public final class Config
4243
public long longPressInterval;
4344
public boolean keyrepeat_enabled;
4445
public float margin_bottom;
45-
public int keyboardHeightPercent;
46+
public int keyboard_rows_height_pixels;
4647
public int screenHeightPixels;
4748
public float horizontal_margin;
4849
public float key_vertical_margin;
@@ -66,7 +67,6 @@ public final class Config
6667
// Dynamically set
6768
/** Configuration options implied by the connected editor. */
6869
public EditorConfig editor_config;
69-
public boolean should_show_candidates_view;
7070
public boolean shouldOfferVoiceTyping;
7171
public ExtraKeys extra_keys_subtype;
7272
public Map<KeyValue, KeyboardData.PreferredPos> extra_keys_param;
@@ -94,7 +94,6 @@ private Config(SharedPreferences prefs, Resources res, IKeyEventHandler h, Boole
9494
// from prefs
9595
refresh(res, foldableUnfolded);
9696
// initialized later
97-
should_show_candidates_view = false;
9897
shouldOfferVoiceTyping = false;
9998
extra_keys_subtype = null;
10099
handler = h;
@@ -112,6 +111,7 @@ public void refresh(Resources res, Boolean foldableUnfolded)
112111
float characterSizeScale = 1.f;
113112
String show_numpad_s = _prefs.getString("show_numpad", "never");
114113
show_numpad = "always".equals(show_numpad_s);
114+
int keyboardHeightPercent;
115115
if (orientation_landscape)
116116
{
117117
if ("landscape".equals(show_numpad_s))
@@ -128,6 +128,7 @@ public void refresh(Resources res, Boolean foldableUnfolded)
128128
String number_row = _prefs.getString("number_row", "no_number_row");
129129
add_number_row = !number_row.equals("no_number_row");
130130
number_row_symbols = number_row.equals("symbols");
131+
suggestions_enabled = _prefs.getBoolean("suggestions", true);
131132
// The baseline for the swipe distance correspond to approximately the
132133
// width of a key in portrait mode, as most layouts have 10 columns.
133134
// Multipled by the DPI ratio because most swipes are made in the diagonals.
@@ -156,6 +157,12 @@ public void refresh(Resources res, Boolean foldableUnfolded)
156157
customBorderRadius = _prefs.getInt("custom_border_radius", 0) / 100.f;
157158
customBorderLineWidth = get_dip_pref(dm, "custom_border_line_width", 0);
158159
screenHeightPixels = dm.heightPixels;
160+
// Rows height is proportional to the screen height, meaning it doesn't
161+
// change for layouts with more or less rows. 3.95 is the usual height of
162+
// a layout in KeyboardData unit. The keyboard will be higher if the layout
163+
// has more rows and smaller if it has less because rows stay the same
164+
// height.
165+
keyboard_rows_height_pixels = screenHeightPixels * keyboardHeightPercent / 395;
159166
horizontal_margin =
160167
get_dip_pref_oriented(dm, "horizontal_margin", 3, 28);
161168
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)