abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/Config.java1
-rw-r--r--srcs/juloo.keyboard2/CurrentlyTypedWord.java4
-rw-r--r--srcs/juloo.keyboard2/KeyEventHandler.java4
-rw-r--r--srcs/juloo.keyboard2/Keyboard2.java9
-rw-r--r--srcs/juloo.keyboard2/Keyboard2View.java4
-rw-r--r--srcs/juloo.keyboard2/suggestions/CandidatesView.java46
-rw-r--r--srcs/juloo.keyboard2/suggestions/Suggestions.java88
-rw-r--r--srcs/layouts/cyrl_jcuken_ru.xml46
8 files changed, 125 insertions, 77 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index 98bb72b..e4694e8 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -84,6 +84,7 @@ public final class Config
public Map<KeyValue, KeyboardData.PreferredPos> extra_keys_param;
public Map<KeyValue, KeyboardData.PreferredPos> extra_keys_custom;
public Cdict current_dictionary = null; // Might be 'null'.
+ public Cdict emoji_dictionary = null; // Might be 'null'.
public IKeyEventHandler handler;
public boolean orientation_landscape = false;
public boolean foldable_unfolded = false;
diff --git a/srcs/juloo.keyboard2/CurrentlyTypedWord.java b/srcs/juloo.keyboard2/CurrentlyTypedWord.java
index 674a90d..2852fa8 100644
--- a/srcs/juloo.keyboard2/CurrentlyTypedWord.java
+++ b/srcs/juloo.keyboard2/CurrentlyTypedWord.java
@@ -127,7 +127,9 @@ public final class CurrentlyTypedWord
int c = Character.codePointAt(s, i);
i += Character.charCount(c);
_cursor++;
- if (!Character.isLetter(c))
+ // [i >= end] might happen when the cursor is in the middle of a
+ // surrogate pair
+ if (!Character.isLetter(c) && i < end)
insert_start = i;
}
if (insert_start > 0)
diff --git a/srcs/juloo.keyboard2/KeyEventHandler.java b/srcs/juloo.keyboard2/KeyEventHandler.java
index 66a10df..78a4095 100644
--- a/srcs/juloo.keyboard2/KeyEventHandler.java
+++ b/srcs/juloo.keyboard2/KeyEventHandler.java
@@ -532,10 +532,10 @@ public final class KeyEventHandler
/** Implement autocorrect when enabled in the settings. */
void handle_space_bar()
{
- if (_space_bar_auto_complete && _suggestions.best_suggestion != null
+ if (_space_bar_auto_complete && _suggestions.count > 0
&& !_typedword.is_selection_not_empty()
&& _typedword.cursor_relative() == 0)
- suggestion_entered(_suggestions.best_suggestion);
+ suggestion_entered(_suggestions.suggestions[0]);
else
send_text(" ");
}
diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java
index d0d6047..7493956 100644
--- a/srcs/juloo.keyboard2/Keyboard2.java
+++ b/srcs/juloo.keyboard2/Keyboard2.java
@@ -23,11 +23,12 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import juloo.cdict.Cdict;
import juloo.keyboard2.dict.Dictionaries;
import juloo.keyboard2.dict.DictionariesActivity;
import juloo.keyboard2.prefs.LayoutsPreference;
import juloo.keyboard2.suggestions.CandidatesView;
-import juloo.cdict.Cdict;
+import juloo.keyboard2.suggestions.Suggestions;
public class Keyboard2 extends InputMethodService
implements SharedPreferences.OnSharedPreferenceChangeListener
@@ -173,6 +174,9 @@ public class Keyboard2 extends InputMethodService
private void refresh_current_dictionary()
{
_config.current_dictionary = null;
+ _config.emoji_dictionary = null;
+ if (_device_locales.default_ == null)
+ return;
String current = _device_locales.default_.dictionary;
if (current == null)
return;
@@ -180,6 +184,7 @@ public class Keyboard2 extends InputMethodService
if (dicts == null)
return;
_config.current_dictionary = Dictionaries.find_by_name(dicts, "main");
+ _config.emoji_dictionary = Dictionaries.find_by_name(dicts, "emoji");
}
private void refresh_candidates_view()
@@ -490,7 +495,7 @@ public class Keyboard2 extends InputMethodService
return _handler;
}
- public void set_suggestions(List<String> suggestions)
+ public void set_suggestions(Suggestions suggestions)
{
_candidates_view.set_candidates(suggestions);
}
diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java
index 5d6e0fa..098bec1 100644
--- a/srcs/juloo.keyboard2/Keyboard2View.java
+++ b/srcs/juloo.keyboard2/Keyboard2View.java
@@ -264,13 +264,11 @@ public class Keyboard2View extends View
@Override
public void onMeasure(int wSpec, int hSpec)
{
- int width;
DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
- width = dm.widthPixels;
+ int width = dm.widthPixels;
_marginLeft = Math.max(_config.horizontal_margin, _insets_left);
_marginRight = Math.max(_config.horizontal_margin, _insets_right);
_marginBottom = _config.margin_bottom + _insets_bottom;
- width += _insets_left + _insets_right;
_keyWidth = (width - _marginLeft - _marginRight) / _keyboard.keysWidth;
_tc = new Theme.Computed(_theme, _config, _keyWidth, _keyboard);
// Compute the size of labels based on the width or the height of keys. The
diff --git a/srcs/juloo.keyboard2/suggestions/CandidatesView.java b/srcs/juloo.keyboard2/suggestions/CandidatesView.java
index 1768a52..5485ccf 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;
@@ -16,10 +17,12 @@ import juloo.keyboard2.R;
public class CandidatesView extends LinearLayout
{
- static final int NUM_CANDIDATES = 3;
+ static final int NUM_CANDIDATES = 4;
/** Candidates currently visible. Entries can be [null] when there are less
- than [NUM_CANDIDATES] suggestions. */
+ than [NUM_CANDIDATES] suggestions.
+ - Entries at indexes [0] to [2] are word suggestions.
+ - Entry at index [3] is the emoji suggestion. */
String[] _items = new String[NUM_CANDIDATES];
/** Text views showing the candidates in [_items]. Text views visibility is
@@ -42,44 +45,55 @@ public class CandidatesView extends LinearLayout
setup_item_view(0, R.id.candidates_middle);
setup_item_view(1, R.id.candidates_right);
setup_item_view(2, R.id.candidates_left);
+ setup_item_view(3, R.id.candidates_emoji);
}
- public void set_candidates(List<String> suggestions)
+ public void set_candidates(Suggestions s)
{
- int s_count = suggestions.size();
+ int s_count = s.count;
+ for (int i = 0; i < Suggestions.MAX_COUNT; i++)
+ _items[i] = (i < s_count) ? s.suggestions[i] : null;
+ _items[3] = s.emoji_suggestion;
// Hide the status message when showing candidates.
if (s_count != 0 && _status_no_dict != null)
_status_no_dict.setVisibility(View.GONE);
for (int i = 0; i < _item_views.length; i++)
{
TextView v = _item_views[i];
- if (i < s_count)
+ if (_items[i] != null)
{
- String it = suggestions.get(i);
- _items[i] = it;
- v.setText(it);
+ v.setText(_items[i]);
v.setVisibility(View.VISIBLE);
}
else
{
- _items[i] = null;
v.setVisibility(View.GONE);
}
}
}
+ public void clear_candidates()
+ {
+ for (int i = 0; i < _item_views.length; i++)
+ {
+ _items[i] = null;
+ _item_views[i].setVisibility(View.GONE);
+ }
+ }
+
public void refresh_config(Config config)
{
- set_candidates(Suggestions.NO_SUGGESTIONS);
+ clear_candidates();
// The status message indicates whether the dictionaries should be
// installed.
_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 +102,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);
}
}
diff --git a/srcs/juloo.keyboard2/suggestions/Suggestions.java b/srcs/juloo.keyboard2/suggestions/Suggestions.java
index 41a7941..f72257b 100644
--- a/srcs/juloo.keyboard2/suggestions/Suggestions.java
+++ b/srcs/juloo.keyboard2/suggestions/Suggestions.java
@@ -16,9 +16,14 @@ public final class Suggestions
Config _config;
boolean _enabled;
- /** The suggestion displayed at the center of the candidates view and entered
- by the space bar. */
- public String best_suggestion = null;
+ /** Current suggestions. The best suggestion is at index [0]. */
+ public String[] suggestions = new String[MAX_COUNT];
+ /** Number of suggestions at the beginning of the [suggestions] array that
+ are not [null]. */
+ public int count = 0;
+ public String emoji_suggestion = null;
+ /** Number of suggestions in [suggestions]. */
+ public static final int MAX_COUNT = 3;
public Suggestions(Callback c, Config conf)
{
@@ -29,55 +34,74 @@ public final class Suggestions
public void started()
{
_enabled = _config.editor_config.should_show_candidates_view;
- best_suggestion = null;
+ clear();
}
public void currently_typed_word(String word)
{
if (!_enabled)
return;
- Cdict dict = _config.current_dictionary;
- if (word.length() < 2 || dict == null)
- {
- set_suggestions(NO_SUGGESTIONS);
- }
+ if (word.length() < 2 || _config.current_dictionary == null)
+ clear();
else
- {
- String[] dst = new String[3];
- query_suggestions(dict, word, dst, 3);
- set_suggestions(Arrays.asList(dst));
- }
+ query_suggestions(word);
+ set_suggestions();
+ }
+
+ void clear()
+ {
+ count = 0;
+ suggestions[0] = null;
+ emoji_suggestion = null;
}
- int query_suggestions(Cdict dict, String word, String[] dst, int max_count)
+ int query_suggestions(String word)
{
+ Cdict dict = _config.current_dictionary;
boolean first_char_upper = Character.isUpperCase(word.charAt(0));
word = apply_substitutions(word);
Cdict.Result r = dict.find(word);
int i = 0;
if (r.found)
- dst[i++] = dict.word(r.index);
- int[] suffixes = dict.suffixes(r, max_count);
+ suggestions[i++] = dict.word(r.index);
+ int[] suffixes = dict.suffixes(r, MAX_COUNT);
// Disable distance search for small words
- int[] dist = (word.length() < 3 || i + 1 >= max_count) ? NO_RESULTS :
- dict.distance(word, 1, max_count);
- for (int j = 0; j < max_count && i < max_count; j++)
+ int[] dist = (word.length() < 3 || i + 1 >= MAX_COUNT) ? NO_RESULTS :
+ dict.distance(word, 1, MAX_COUNT);
+ for (int j = 0; j < MAX_COUNT && i < MAX_COUNT; j++)
{
if (suffixes.length > j)
- dst[i++] = dict.word(suffixes[j]);
- if (dist.length > j && i < max_count)
- dst[i++] = dict.word(dist[j]);
+ suggestions[i++] = dict.word(suffixes[j]);
+ if (dist.length > j && i < MAX_COUNT)
+ suggestions[i++] = dict.word(dist[j]);
}
if (first_char_upper)
- capitalize_results(dst);
+ capitalize_results();
+ emoji_suggestion = query_emoji(word); // word with substitutions applied
+ count = i;
return i;
}
- void capitalize_results(String[] rs)
+ void capitalize_results()
{
- for (int i = 0; i < rs.length; i++)
- if (rs[i] != null)
- rs[i] = rs[i].substring(0, 1).toUpperCase() + rs[i].substring(1);
+ for (int i = 0; i < count; i++)
+ suggestions[i] = suggestions[i].substring(0, 1).toUpperCase()
+ + suggestions[i].substring(1);
+ }
+
+ String query_emoji(String word)
+ {
+ Cdict dict = _config.emoji_dictionary;
+ // Disable emoji suggestion for short words
+ if (dict == null || word.length() < 3)
+ return null;
+ Cdict.Result r = dict.find(word);
+ if (r.found)
+ return dict.word(r.index);
+ int[] s = dict.suffixes(r, 1);
+ if (s.length > 0)
+ return dict.word(s[0]);
+ return null;
}
/** Apply the same substitutions that were used when building the
@@ -96,17 +120,15 @@ public final class Suggestions
return b.toString();
}
- void set_suggestions(List<String> ws)
+ void set_suggestions()
{
- _callback.set_suggestions(ws);
- best_suggestion = (ws.size() > 0) ? ws.get(0) : null;
+ _callback.set_suggestions(this);
}
- static final List<String> NO_SUGGESTIONS = Arrays.asList();
static final int[] NO_RESULTS = new int[0];
public static interface Callback
{
- public void set_suggestions(List<String> suggestions);
+ public void set_suggestions(Suggestions suggestions);
}
}
diff --git a/srcs/layouts/cyrl_jcuken_ru.xml b/srcs/layouts/cyrl_jcuken_ru.xml
index 15eeba3..ed863d6 100644
--- a/srcs/layouts/cyrl_jcuken_ru.xml
+++ b/srcs/layouts/cyrl_jcuken_ru.xml
@@ -2,41 +2,41 @@
<keyboard name="ЙЦУКЕН (Русский)" script="cyrillic">
<row>
<key key0="й" key2="1" key4="loc esc"/>
- <key key0="ц" key1="loc ї" key2="2" key3="№"/>
- <key key0="у" key1="loc ў" key2="3" key3="-"/>
- <key key0="к" key2="4" key3="/"/>
- <key key0="е" key1="ё" key2="5" key3="&quot;"/>
- <key key0="н" key1="loc є" key2="6" key3=":"/>
- <key key0="г" key1="loc ґ" key2="7" key3=","/>
- <key key0="ш" key2="8" key3="."/>
- <key key0="щ" key2="9" key3="_"/>
- <key key0="з" key2="0" key3="\?"/>
- <key key0="х" key3="%"/>
+ <key key0="ц" key1="loc ї" key2="2" key3="\@" key4="~"/>
+ <key key0="у" key1="loc ў" key2="3" key3="\#" key4="!"/>
+ <key key0="к" key2="4" key3="$"/>
+ <key key0="е" key1="ё" key2="5" key3="%"/>
+ <key key0="н" key1="loc є" key2="6" key3="^"/>
+ <key key0="г" key1="loc ґ" key2="7" key3="&amp;"/>
+ <key key0="ш" key2="8" key3="*"/>
+ <key key0="щ" key2="9" key3="(" key4=")"/>
+ <key key0="з" key2="0" key3="{" key4="}"/>
+ <key key0="х" key3="[" key4="]"/>
</row>
<row>
- <key key0="ф" key1="loc tab" key2="+" key3="|"/>
+ <key key0="ф" key1="loc tab" key2="`"/>
<key key0="ы"/>
<key key0="в"/>
<key key0="а"/>
<key key0="п"/>
<key key0="р"/>
<key key0="о"/>
- <key key0="л" key4="₽"/>
- <key key0="д" key2="=" key3="!"/>
- <key key0="ж" key2="\\" key3=";"/>
- <key key0="э" key2=")" key3="("/>
+ <key key0="л" key1="₽"/>
+ <key key0="д" key2="-" key3="_"/>
+ <key key0="ж" key2="=" key3="+"/>
+ <key key0="э" key2="|" key3="\\"/>
</row>
- <row>
- <key key0="shift" key2="loc capslock"/>
+ <row scale="11">
+ <key width="1.22" key0="shift" key2="loc capslock"/>
<key key0="я"/>
<key key0="ч"/>
<key key0="с"/>
<key key0="м"/>
- <key key0="и" key1="loc і"/>
- <key key0="т"/>
- <key key0="ь" key1="ъ"/>
- <key key0="б" key2="«"/>
- <key key0="ю" key2="»"/>
- <key key0="backspace" key2="delete"/>
+ <key key0="и" key1="loc і" key2="&lt;" key3="."/>
+ <key key0="т" key2="&gt;" key3=","/>
+ <key key0="ь" key1="ъ" key2="\?" key3="/"/>
+ <key key0="б" key2=":" key3=";"/>
+ <key key0="ю" key2="&quot;" key3="'"/>
+ <key width="1.22" key0="backspace" key2="delete"/>
</row>
</keyboard>