aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/res/values/donottranslate-altchars.xml3
-rw-r--r--java/res/xml-xlarge/kbd_number.xml14
-rw-r--r--java/res/xml-xlarge/kbd_phone.xml14
-rw-r--r--java/res/xml-xlarge/kbd_phone_symbols.xml14
-rw-r--r--java/res/xml-xlarge/kbd_qwerty_row4.xml12
-rw-r--r--java/res/xml-xlarge/kbd_symbols.xml17
-rw-r--r--java/res/xml-xlarge/kbd_symbols_shift.xml12
-rw-r--r--java/res/xml/kbd_currency_key_styles.xml269
-rw-r--r--java/res/xml/kbd_symbols.xml5
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java12
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java77
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java77
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java38
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java42
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java54
-rw-r--r--native/Android.mk3
-rw-r--r--native/jni/com_android_inputmethod_keyboard_ProximityInfo.cpp90
-rw-r--r--native/jni/com_android_inputmethod_keyboard_ProximityInfo.h27
-rw-r--r--native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp55
-rw-r--r--native/jni/com_android_inputmethod_latin_BinaryDictionary.h27
-rw-r--r--native/jni/onload.cpp62
-rw-r--r--native/src/defines.h2
-rw-r--r--native/src/dictionary.cpp4
-rw-r--r--native/src/dictionary.h8
-rw-r--r--native/src/proximity_info.cpp34
-rw-r--r--native/src/proximity_info.h40
-rw-r--r--native/src/unigram_dictionary.cpp16
-rw-r--r--native/src/unigram_dictionary.h8
-rw-r--r--tests/src/com/android/inputmethod/latin/SuggestHelper.java8
30 files changed, 906 insertions, 142 deletions
diff --git a/java/res/values/donottranslate-altchars.xml b/java/res/values/donottranslate-altchars.xml
index 4b1a6ae6d..518e74af1 100644
--- a/java/res/values/donottranslate-altchars.xml
+++ b/java/res/values/donottranslate-altchars.xml
@@ -44,6 +44,9 @@
<string name="alternates_for_scandinavia_row2_11"></string>
<string name="alternates_for_cyrillic_e"></string>
<string name="alternates_for_cyrillic_soft_sign"></string>
+ <string name="alternates_for_currency_dollar">¢,£,€,¥,₱</string>
+ <string name="alternates_for_currency_euro">¢,£,$,¥,₱</string>
+ <string name="alternates_for_currency_pound">¢,$,€,¥,₱</string>
<string name="alternates_for_mic">"\@drawable/sym_keyboard_settings|\@integer/key_settings,\@drawable/sym_keyboard_mic|\@integer/key_voice"</string>
<string name="alternates_for_smiley">":-)|:-) ,:-(|:-( ,;-)|;-) ,:-P|:-P ,=-O|=-O ,:-*|:-* ,:O|:O ,B-)|B-) ,:-$|:-$ ,:-!|:-! ,:-[|:-[ ,O:-)|O:-) ,:-\\\\\\\\|:-\\\\\\\\ ,:\'(|:\'( ,:-D|:-D "</string>
<string name="alternates_for_settings_slash">"\@drawable/sym_keyboard_settings|\@integer/key_settings,/"</string>
diff --git a/java/res/xml-xlarge/kbd_number.xml b/java/res/xml-xlarge/kbd_number.xml
index 152ec8285..ce3277b5d 100644
--- a/java/res/xml-xlarge/kbd_number.xml
+++ b/java/res/xml-xlarge/kbd_number.xml
@@ -187,9 +187,17 @@
left edge key. -->
<Spacer
latin:horizontalGap="8.362%p" />
- <Key
- latin:keyStyle="settingsKeyStyle"
- latin:keyWidth="8.042%p" />
+ <switch>
+ <case latin:hasSettingsKey="true">
+ <Key
+ latin:keyStyle="settingsKeyStyle"
+ latin:keyWidth="8.042%p" />
+ </case>
+ <default>
+ <Spacer
+ latin:horizontalGap="8.042%p" />
+ </default>
+ </switch>
<Key
latin:keyStyle="nonSpecialBackgroundSpaceKeyStyle"
latin:keyWidth="24.127%p" />
diff --git a/java/res/xml-xlarge/kbd_phone.xml b/java/res/xml-xlarge/kbd_phone.xml
index b9444ad50..9122176a9 100644
--- a/java/res/xml-xlarge/kbd_phone.xml
+++ b/java/res/xml-xlarge/kbd_phone.xml
@@ -129,9 +129,17 @@
the touch event on the area, "space" is intentionally not marked as a left edge key. -->
<Spacer
latin:horizontalGap="12.340%p" />
- <Key
- latin:keyStyle="settingsKeyStyle"
- latin:keyWidth="8.042%p" />
+ <switch>
+ <case latin:hasSettingsKey="true">
+ <Key
+ latin:keyStyle="settingsKeyStyle"
+ latin:keyWidth="8.042%p" />
+ </case>
+ <default>
+ <Spacer
+ latin:horizontalGap="8.042%p" />
+ </default>
+ </switch>
<Key
latin:keyStyle="nonSpecialBackgroundSpaceKeyStyle"
latin:keyWidth="16.084%p" />
diff --git a/java/res/xml-xlarge/kbd_phone_symbols.xml b/java/res/xml-xlarge/kbd_phone_symbols.xml
index 690bcde0c..055c14867 100644
--- a/java/res/xml-xlarge/kbd_phone_symbols.xml
+++ b/java/res/xml-xlarge/kbd_phone_symbols.xml
@@ -141,9 +141,17 @@
the touch event on the area, "space" is intentionally not marked as a left edge key. -->
<Spacer
latin:horizontalGap="8.362%p" />
- <Key
- latin:keyStyle="settingsKeyStyle"
- latin:keyWidth="8.042%p" />
+ <switch>
+ <case latin:hasSettingsKey="true">
+ <Key
+ latin:keyStyle="settingsKeyStyle"
+ latin:keyWidth="8.042%p" />
+ </case>
+ <default>
+ <Spacer
+ latin:horizontalGap="8.042%p" />
+ </default>
+ </switch>
<Key
latin:keyStyle="nonSpecialBackgroundSpaceKeyStyle"
latin:keyWidth="24.127%p" />
diff --git a/java/res/xml-xlarge/kbd_qwerty_row4.xml b/java/res/xml-xlarge/kbd_qwerty_row4.xml
index 8011064a4..f36b61fc7 100644
--- a/java/res/xml-xlarge/kbd_qwerty_row4.xml
+++ b/java/res/xml-xlarge/kbd_qwerty_row4.xml
@@ -27,8 +27,16 @@
>
<Spacer
latin:horizontalGap="8.362%p" />
- <Key
- latin:keyStyle="settingsKeyStyle" />
+ <switch>
+ <case latin:hasSettingsKey="true">
+ <Key
+ latin:keyStyle="settingsKeyStyle" />
+ </case>
+ <default>
+ <Spacer
+ latin:horizontalGap="8.042%p" />
+ </default>
+ </switch>
<switch>
<case
latin:languageCode="ru"
diff --git a/java/res/xml-xlarge/kbd_symbols.xml b/java/res/xml-xlarge/kbd_symbols.xml
index 640dd0904..f81cea7fb 100644
--- a/java/res/xml-xlarge/kbd_symbols.xml
+++ b/java/res/xml-xlarge/kbd_symbols.xml
@@ -30,6 +30,8 @@
>
<include
latin:keyboardLayout="@xml/kbd_key_styles" />
+ <include
+ latin:keyboardLayout="@xml/kbd_currency_key_styles" />
<!-- This row is intentionally not marked as a top row -->
<Row
latin:keyWidth="8.272%p"
@@ -82,8 +84,7 @@
<Key
latin:keyLabel="#" />
<Key
- latin:keyLabel="$"
- latin:popupCharacters="¢,£,€,¥,₣,₤,₱" />
+ latin:keyStyle="currencyKeyStyle" />
<Key
latin:keyLabel="%"
latin:popupCharacters="‰" />
@@ -167,8 +168,16 @@
>
<Spacer
latin:horizontalGap="8.362%p" />
- <Key
- latin:keyStyle="settingsKeyStyle" />
+ <switch>
+ <case latin:hasSettingsKey="true">
+ <Key
+ latin:keyStyle="settingsKeyStyle" />
+ </case>
+ <default>
+ <Spacer
+ latin:horizontalGap="8.042%p" />
+ </default>
+ </switch>
<Key
latin:keyLabel="/" />
<Key
diff --git a/java/res/xml-xlarge/kbd_symbols_shift.xml b/java/res/xml-xlarge/kbd_symbols_shift.xml
index 1f5513b83..8359b7571 100644
--- a/java/res/xml-xlarge/kbd_symbols_shift.xml
+++ b/java/res/xml-xlarge/kbd_symbols_shift.xml
@@ -155,8 +155,16 @@
>
<Spacer
latin:horizontalGap="24.446%p" />
- <Key
- latin:keyStyle="settingsKeyStyle" />
+ <switch>
+ <case latin:hasSettingsKey="true">
+ <Key
+ latin:keyStyle="settingsKeyStyle" />
+ </case>
+ <default>
+ <Spacer
+ latin:horizontalGap="8.042%p" />
+ </default>
+ </switch>
<Key
latin:keyStyle="spaceKeyStyle"
latin:keyWidth="37.454%p" />
diff --git a/java/res/xml/kbd_currency_key_styles.xml b/java/res/xml/kbd_currency_key_styles.xml
new file mode 100644
index 000000000..b30dd6451
--- /dev/null
+++ b/java/res/xml/kbd_currency_key_styles.xml
@@ -0,0 +1,269 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<merge
+ xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"
+>
+ <switch>
+ <case
+ latin:passwordInput="true"
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="$"
+ latin:popupCharacters="@string/alternates_for_currency_dollar" />
+ </case>
+ <!-- Countries using Euro currency, 23 countries as for January 2011. -->
+ <!-- 1. Andorra (ca_AD, ca_ES) -->
+ <case
+ latin:languageCode="ca"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 2. Austria (de_AT) -->
+<!-- <case-->
+<!-- latin:countryCode="AT"-->
+<!-- >-->
+<!-- <key-style-->
+<!-- latin:styleName="currencyKeyStyle"-->
+<!-- latin:keyLabel="€"-->
+<!-- latin:popupCharacters="@string/alternates_for_currency_euro" />-->
+<!-- </case>-->
+ <!-- 3. Belgium (nl_BE, fr_BE, de_BE) -->
+<!-- <case-->
+<!-- latin:countryCode="BE"-->
+<!-- >-->
+<!-- <key-style-->
+<!-- latin:styleName="currencyKeyStyle"-->
+<!-- latin:keyLabel="€"-->
+<!-- latin:popupCharacters="@string/alternates_for_currency_euro" />-->
+<!-- </case>-->
+ <!-- 4. Cyprus (el_CY, tr_CY) -->
+ <case
+ latin:countryCode="CY"
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 5. Estonia (et_EE) -->
+<!-- <case-->
+<!-- latin:languageCode="et"-->
+<!-- latin:countryCode=""-->
+<!-- >-->
+<!-- <key-style-->
+<!-- latin:styleName="currencyKeyStyle"-->
+<!-- latin:keyLabel="€"-->
+<!-- latin:popupCharacters="@string/alternates_for_currency_euro" />-->
+<!-- </case>-->
+ <!-- 6. Finland (fi_FI, sv_FI) -->
+ <case
+ latin:languageCode="fi"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 7. France (fr_FR) -->
+ <case
+ latin:languageCode="fr"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 8. Germany (de_DE) -->
+ <case
+ latin:languageCode="de"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 9. Greece (el_GR) -->
+ <case
+ latin:languageCode="el"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 10. Ireland (ga_IE, en_IE) -->
+ <case
+ latin:countryCode="IE"
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 11. Italy (it_IT) -->
+ <case
+ latin:languageCode="it"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 12. Kosovo -->
+<!-- <case-->
+<!-- latin:countryCode="XK"-->
+<!-- >-->
+<!-- <key-style-->
+<!-- latin:styleName="currencyKeyStyle"-->
+<!-- latin:keyLabel="€"-->
+<!-- latin:popupCharacters="@string/alternates_for_currency_euro" />-->
+<!-- </case>-->
+ <!-- 13. Luxembourg (lb_LU, fr_LU, de_LU) -->
+ <case
+ latin:countryCode="LU"
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 14. Malta (mt_MT, en_MT) -->
+ <case
+ latin:countryCode="MT"
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 15. Monaco (fr_MO) -->
+<!-- <case-->
+<!-- latin:countryCode="MO"-->
+<!-- >-->
+<!-- <key-style-->
+<!-- latin:styleName="currencyKeyStyle"-->
+<!-- latin:keyLabel="€"-->
+<!-- latin:popupCharacters="@string/alternates_for_currency_euro" />-->
+<!-- </case>-->
+ <!-- 16. Montenegro (sla_ME) -->
+ <case
+ latin:countryCode="ME"
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 17. Netherlands (nl_NL) -->
+ <case
+ latin:languageCode="nl"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 18. Portugal (pt_PT) -->
+ <case
+ latin:languageCode="pt"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 19. San Marino (it_SM) -->
+<!-- <case-->
+<!-- latin:countryCode="SM"-->
+<!-- >-->
+<!-- <key-style-->
+<!-- latin:styleName="currencyKeyStyle"-->
+<!-- latin:keyLabel="€"-->
+<!-- latin:popupCharacters="@string/alternates_for_currency_euro" />-->
+<!-- </case>-->
+ <!-- 20. Slovakia (sk_SK) -->
+ <case
+ latin:languageCode="sk"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 21. Slovenia (sl_SI) -->
+ <case
+ latin:languageCode="sl"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 22. Spain (es_ES, ca_ES) -->
+ <case
+ latin:languageCode="es"
+ latin:countryCode=""
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="€"
+ latin:popupCharacters="@string/alternates_for_currency_euro" />
+ </case>
+ <!-- 23. Vatican City (it_VA) -->
+<!-- <case-->
+<!-- latin:countryCode="VA"-->
+<!-- >-->
+<!-- <key-style-->
+<!-- latin:styleName="currencyKeyStyle"-->
+<!-- latin:keyLabel="€"-->
+<!-- latin:popupCharacters="@string/alternates_for_currency_euro" />-->
+<!-- </case>-->
+ <!-- United Kingdom -->
+ <case
+ latin:countryCode="GB"
+ >
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="£"
+ latin:popupCharacters="@string/alternates_for_currency_pound" />
+ </case>
+ <default>
+ <key-style
+ latin:styleName="currencyKeyStyle"
+ latin:keyLabel="$"
+ latin:popupCharacters="@string/alternates_for_currency_dollar" />
+ </default>
+ </switch>
+</merge> \ No newline at end of file
diff --git a/java/res/xml/kbd_symbols.xml b/java/res/xml/kbd_symbols.xml
index 5d62deaa4..b3b3f4ebd 100644
--- a/java/res/xml/kbd_symbols.xml
+++ b/java/res/xml/kbd_symbols.xml
@@ -31,6 +31,8 @@
>
<include
latin:keyboardLayout="@xml/kbd_key_styles" />
+ <include
+ latin:keyboardLayout="@xml/kbd_currency_key_styles" />
<Row
latin:rowEdgeFlags="top"
>
@@ -71,8 +73,7 @@
<Key
latin:keyLabel="\#" />
<Key
- latin:keyLabel="$"
- latin:popupCharacters="¢,£,€,¥,₣,₤,₱" />
+ latin:keyStyle="currencyKeyStyle" />
<Key
latin:keyLabel="%"
latin:popupCharacters="‰" />
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 3a0bf53ab..3005920b1 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -132,6 +132,7 @@ public class Keyboard {
// Variables for pre-computing nearest keys.
+ // TODO: Change GRID_WIDTH and GRID_HEIGHT to private.
public final int GRID_WIDTH;
public final int GRID_HEIGHT;
private final int GRID_SIZE;
@@ -143,6 +144,8 @@ public class Keyboard {
/** Number of key widths from current touch point to search for nearest keys. */
private static float SEARCH_DISTANCE = 1.2f;
+ private final ProximityInfo mProximityInfo;
+
/**
* Creates a keyboard from the given xml key layout file.
* @param context the application or service context
@@ -171,6 +174,11 @@ public class Keyboard {
mDefaultHeight = mDefaultWidth;
mId = id;
loadKeyboard(context, xmlLayoutResId);
+ mProximityInfo = new ProximityInfo(mDisplayWidth, mDisplayHeight, GRID_WIDTH, GRID_HEIGHT);
+ }
+
+ public int getProximityInfo() {
+ return mProximityInfo.getNativeProximityInfo(this);
}
public List<Key> getKeys() {
@@ -345,7 +353,8 @@ public class Keyboard {
return mId != null && mId.isNumberKeyboard();
}
- private void computeNearestNeighbors() {
+ // TODO: Move this function to ProximityInfo and make this private.
+ public void computeNearestNeighbors() {
// Round-up so we don't have any pixels outside the grid
mCellWidth = (getMinWidth() + GRID_WIDTH - 1) / GRID_WIDTH;
mCellHeight = (getHeight() + GRID_HEIGHT - 1) / GRID_HEIGHT;
@@ -369,6 +378,7 @@ public class Keyboard {
mGridNeighbors[(y / mCellHeight) * GRID_WIDTH + (x / mCellWidth)] = cell;
}
}
+ mProximityInfo.setProximityInfo(mGridNeighbors);
}
public boolean isInside(Key key, int x, int y) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
index 86e80ecac..6651f9ffa 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -83,8 +83,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
private static final int AUTO_MODE_SWITCH_STATE_CHORDING = 4;
private int mAutoModeSwitchState = AUTO_MODE_SWITCH_STATE_ALPHA;
- // Indicates whether or not we have the settings key
- private boolean mHasSettingsKey;
+ // Indicates whether or not we have the settings key in option of settings
+ private boolean mSettingsKeyEnabledInSettings;
private static final int SETTINGS_KEY_MODE_AUTO = R.string.settings_key_mode_auto;
private static final int SETTINGS_KEY_MODE_ALWAYS_SHOW =
R.string.settings_key_mode_always_show;
@@ -122,32 +122,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
prefs.registerOnSharedPreferenceChangeListener(sInstance);
}
- private void makeSymbolsKeyboardIds(final int mode) {
- final Locale locale = mSubtypeSwitcher.getInputLocale();
- final Resources res = mInputMethodService.getResources();
- final int orientation = res.getConfiguration().orientation;
- final int colorScheme = getColorScheme();
- final boolean hasVoiceKey = mVoiceKeyEnabled && !mVoiceButtonOnPrimary;
- // Note: This comment is only applied for phone number keyboard layout.
- // On non-xlarge device, "@integer/key_switch_alpha_symbol" key code is used to switch
- // between "phone keyboard" and "phone symbols keyboard". But on xlarge device,
- // "@integer/key_shift" key code is used for that purpose in order to properly display
- // "more" and "locked more" key labels. To achieve these behavior, we should initialize
- // mSymbolsId and mSymbolsShiftedId to "phone keyboard" and "phone symbols keyboard"
- // respectively here for xlarge device's layout switching.
- int xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_symbols;
- final String xmlName = res.getResourceEntryName(xmlId);
- mSymbolsId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode,
- mAttribute, mHasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true);
- xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols_shift;
- mSymbolsShiftedId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode,
- mAttribute, mHasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true);
- }
-
- private boolean hasVoiceKey(boolean isSymbols) {
- return mVoiceKeyEnabled && (isSymbols != mVoiceButtonOnPrimary);
- }
-
public void loadKeyboard(EditorInfo attribute, boolean voiceKeyEnabled,
boolean voiceButtonOnPrimary) {
mAutoModeSwitchState = AUTO_MODE_SWITCH_STATE_ALPHA;
@@ -170,14 +144,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
mVoiceButtonOnPrimary = voiceButtonOnPrimary;
mIsSymbols = isSymbols;
// Update the settings key state because number of enabled IMEs could have been changed
- mHasSettingsKey = getSettingsKeyMode(mPrefs, mInputMethodService);
+ mSettingsKeyEnabledInSettings = getSettingsKeyMode(mPrefs, mInputMethodService);
final KeyboardId id = getKeyboardId(attribute, isSymbols);
final Keyboard oldKeyboard = mInputView.getKeyboard();
if (oldKeyboard != null && oldKeyboard.mId.equals(id))
return;
- makeSymbolsKeyboardIds(id.mMode);
+ makeSymbolsKeyboardIds(id.mMode, attribute);
mCurrentId = id;
mInputView.setPreviewEnabled(mInputMethodService.getPopupOn());
setKeyboard(getKeyboard(id));
@@ -224,6 +198,16 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
return keyboard;
}
+ private boolean hasVoiceKey(boolean isSymbols) {
+ return mVoiceKeyEnabled && (isSymbols != mVoiceButtonOnPrimary);
+ }
+
+ private boolean hasSettingsKey(EditorInfo attribute) {
+ return mSettingsKeyEnabledInSettings
+ && !Utils.inPrivateImeOptions(mInputMethodService.getPackageName(),
+ LatinIME.IME_OPTION_NO_SETTINGS_KEY, attribute);
+ }
+
private KeyboardId getKeyboardId(EditorInfo attribute, boolean isSymbols) {
final int mode = Utils.getKeyboardMode(attribute);
final boolean hasVoiceKey = hasVoiceKey(isSymbols);
@@ -253,12 +237,36 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
enableShiftLock = true;
}
}
+ final boolean hasSettingsKey = hasSettingsKey(attribute);
final Resources res = mInputMethodService.getResources();
final int orientation = res.getConfiguration().orientation;
final Locale locale = mSubtypeSwitcher.getInputLocale();
return new KeyboardId(
res.getResourceEntryName(xmlId), xmlId, charColorId, locale, orientation, mode,
- attribute, mHasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, enableShiftLock);
+ attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, enableShiftLock);
+ }
+
+ private void makeSymbolsKeyboardIds(final int mode, EditorInfo attribute) {
+ final Locale locale = mSubtypeSwitcher.getInputLocale();
+ final Resources res = mInputMethodService.getResources();
+ final int orientation = res.getConfiguration().orientation;
+ final int colorScheme = getColorScheme();
+ final boolean hasVoiceKey = mVoiceKeyEnabled && !mVoiceButtonOnPrimary;
+ final boolean hasSettingsKey = hasSettingsKey(attribute);
+ // Note: This comment is only applied for phone number keyboard layout.
+ // On non-xlarge device, "@integer/key_switch_alpha_symbol" key code is used to switch
+ // between "phone keyboard" and "phone symbols keyboard". But on xlarge device,
+ // "@integer/key_shift" key code is used for that purpose in order to properly display
+ // "more" and "locked more" key labels. To achieve these behavior, we should initialize
+ // mSymbolsId and mSymbolsShiftedId to "phone keyboard" and "phone symbols keyboard"
+ // respectively here for xlarge device's layout switching.
+ int xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone : R.xml.kbd_symbols;
+ final String xmlName = res.getResourceEntryName(xmlId);
+ mSymbolsId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode,
+ attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true);
+ xmlId = mode == KeyboardId.MODE_PHONE ? R.xml.kbd_phone_symbols : R.xml.kbd_symbols_shift;
+ mSymbolsShiftedId = new KeyboardId(xmlName, xmlId, colorScheme, locale, orientation, mode,
+ attribute, hasSettingsKey, mVoiceKeyEnabled, hasVoiceKey, true);
}
public int getKeyboardMode() {
@@ -709,7 +717,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
createInputViewInternal(layoutId, false);
postSetInputView();
} else if (Settings.PREF_SETTINGS_KEY.equals(key)) {
- mHasSettingsKey = getSettingsKeyMode(sharedPreferences, mInputMethodService);
+ mSettingsKeyEnabledInSettings = getSettingsKeyMode(sharedPreferences,
+ mInputMethodService);
createInputViewInternal(mLayoutId, true);
postSetInputView();
}
@@ -745,7 +754,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
Context.INPUT_METHOD_SERVICE))))) {
return true;
}
+ return false;
}
- return false;
+ // If the show settings key option is disabled, we always try showing the settings key.
+ return true;
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index d9526e4d6..851430fb8 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -788,6 +788,8 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
canvas.translate(-key.mX - kbdPaddingLeft, -key.mY - kbdPaddingTop);
}
+ // TODO: Move this function to ProximityInfo for getting rid of public declarations for
+ // GRID_WIDTH and GRID_HEIGHT
if (DEBUG_KEYBOARD_GRID) {
Paint p = new Paint();
p.setStyle(Paint.Style.STROKE);
@@ -1054,7 +1056,7 @@ public class KeyboardView extends View implements PointerTracker.UIProxy {
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
}
- private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) {
+ private void onDoubleTapShiftKey(PointerTracker tracker) {
// When shift key is double tapped, the first tap is correctly processed as usual tap. And
// the second tap is treated as this double tap event, so that we need not mark tracker
// calling setAlreadyProcessed() nor remove the tracker from mPointerQueueueue.
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
new file mode 100644
index 000000000..fe836c1e2
--- /dev/null
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.keyboard;
+
+public class ProximityInfo {
+ public static final int MAX_PROXIMITY_CHARS_SIZE = 16;
+
+ private final int mDisplayWidth;
+ private final int mDisplayHeight;
+ private final int mGridWidth;
+ private final int mGridHeight;
+ private final int mGridSize;
+
+ ProximityInfo(int displayWidth, int displayHeight, int gridWidth, int gridHeight) {
+ mDisplayWidth = displayWidth;
+ mDisplayHeight = displayHeight;
+ mGridWidth = gridWidth;
+ mGridHeight = gridHeight;
+ mGridSize = mGridWidth * mGridHeight;
+ }
+
+ private int mNativeProximityInfo;
+ private native int setProximityInfoNative(int maxProximityCharsSize, int displayWidth,
+ int displayHeight, int gridWidth, int gridHeight, int[] proximityCharsArray);
+ private native void releaseProximityInfoNative(int nativeProximityInfo);
+
+ public final void setProximityInfo(int[][] gridNeighbors) {
+ int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE];
+ for (int i = 0; i < mGridSize; ++i) {
+ final int proximityCharsLength = gridNeighbors[i].length;
+ for (int j = 0; j < MAX_PROXIMITY_CHARS_SIZE; ++j) {
+ int charCode = KeyDetector.NOT_A_KEY;
+ if (j < proximityCharsLength) {
+ charCode = gridNeighbors[i][j];
+ }
+ proximityCharsArray[i * MAX_PROXIMITY_CHARS_SIZE + j] = charCode;
+ }
+ }
+ mNativeProximityInfo = setProximityInfoNative(MAX_PROXIMITY_CHARS_SIZE,
+ mDisplayWidth, mDisplayHeight, mGridWidth, mGridHeight, proximityCharsArray);
+ }
+
+ // TODO: Get rid of this function's input (keyboard).
+ public int getNativeProximityInfo(Keyboard keyboard) {
+ if (mNativeProximityInfo == 0) {
+ // TODO: Move this function to ProximityInfo and make this private.
+ keyboard.computeNearestNeighbors();
+ }
+ return mNativeProximityInfo;
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ try {
+ if (mNativeProximityInfo != 0) {
+ releaseProximityInfoNative(mNativeProximityInfo);
+ mNativeProximityInfo = 0;
+ }
+ } finally {
+ super.finalize();
+ }
+ }
+}
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index ff7e2b88a..33b8c7af6 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -16,6 +16,9 @@
package com.android.inputmethod.latin;
+import com.android.inputmethod.keyboard.KeyboardSwitcher;
+import com.android.inputmethod.keyboard.ProximityInfo;
+
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.util.Log;
@@ -34,10 +37,10 @@ public class BinaryDictionary extends Dictionary {
* It is necessary to keep it at this value because some languages e.g. German have
* really long words.
*/
- protected static final int MAX_WORD_LENGTH = 48;
+ public static final int MAX_WORD_LENGTH = 48;
private static final String TAG = "BinaryDictionary";
- private static final int MAX_ALTERNATIVES = 16;
+ private static final int MAX_PROXIMITY_CHARS_SIZE = ProximityInfo.MAX_PROXIMITY_CHARS_SIZE;
private static final int MAX_WORDS = 18;
private static final int MAX_BIGRAMS = 60;
@@ -47,19 +50,13 @@ public class BinaryDictionary extends Dictionary {
private int mDicTypeId;
private int mNativeDict;
private long mDictLength;
- private final int[] mInputCodes = new int[MAX_WORD_LENGTH * MAX_ALTERNATIVES];
+ private final int[] mInputCodes = new int[MAX_WORD_LENGTH * MAX_PROXIMITY_CHARS_SIZE];
private final char[] mOutputChars = new char[MAX_WORD_LENGTH * MAX_WORDS];
private final char[] mOutputChars_bigrams = new char[MAX_WORD_LENGTH * MAX_BIGRAMS];
private final int[] mFrequencies = new int[MAX_WORDS];
private final int[] mFrequencies_bigrams = new int[MAX_BIGRAMS];
- static {
- try {
- System.loadLibrary("jni_latinime");
- } catch (UnsatisfiedLinkError ule) {
- Log.e(TAG, "Could not load native library jni_latinime");
- }
- }
+ private final KeyboardSwitcher mKeyboardSwitcher = KeyboardSwitcher.getInstance();
private BinaryDictionary() {
}
@@ -117,8 +114,9 @@ public class BinaryDictionary extends Dictionary {
int maxWords, int maxAlternatives);
private native void closeNative(int dict);
private native boolean isValidWordNative(int nativeData, char[] word, int wordLength);
- private native int getSuggestionsNative(int dict, int[] inputCodes, int codesSize,
- char[] outputChars, int[] frequencies);
+ private native int getSuggestionsNative(int dict, int proximityInfo, int[] xCoordinates,
+ int[] yCoordinates, int[] inputCodes, int codesSize, char[] outputChars,
+ int[] frequencies);
private native int getBigramsNative(int dict, char[] prevWord, int prevWordLength,
int[] inputCodes, int inputCodesLength, char[] outputChars, int[] frequencies,
int maxWordLength, int maxBigrams, int maxAlternatives);
@@ -126,7 +124,7 @@ public class BinaryDictionary extends Dictionary {
private final void loadDictionary(String path, long startOffset, long length) {
mNativeDict = openNative(path, startOffset, length,
TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER,
- MAX_WORD_LENGTH, MAX_WORDS, MAX_ALTERNATIVES);
+ MAX_WORD_LENGTH, MAX_WORDS, MAX_PROXIMITY_CHARS_SIZE);
mDictLength = length;
}
@@ -143,11 +141,11 @@ public class BinaryDictionary extends Dictionary {
Arrays.fill(mInputCodes, -1);
int[] alternatives = codes.getCodesAt(0);
System.arraycopy(alternatives, 0, mInputCodes, 0,
- Math.min(alternatives.length, MAX_ALTERNATIVES));
+ Math.min(alternatives.length, MAX_PROXIMITY_CHARS_SIZE));
int count = getBigramsNative(mNativeDict, chars, chars.length, mInputCodes, codesSize,
mOutputChars_bigrams, mFrequencies_bigrams, MAX_WORD_LENGTH, MAX_BIGRAMS,
- MAX_ALTERNATIVES);
+ MAX_PROXIMITY_CHARS_SIZE);
for (int j = 0; j < count; ++j) {
if (mFrequencies_bigrams[j] < 1) break;
@@ -174,14 +172,16 @@ public class BinaryDictionary extends Dictionary {
Arrays.fill(mInputCodes, WordComposer.NOT_A_CODE);
for (int i = 0; i < codesSize; i++) {
int[] alternatives = codes.getCodesAt(i);
- System.arraycopy(alternatives, 0, mInputCodes, i * MAX_ALTERNATIVES,
- Math.min(alternatives.length, MAX_ALTERNATIVES));
+ System.arraycopy(alternatives, 0, mInputCodes, i * MAX_PROXIMITY_CHARS_SIZE,
+ Math.min(alternatives.length, MAX_PROXIMITY_CHARS_SIZE));
}
Arrays.fill(mOutputChars, (char) 0);
Arrays.fill(mFrequencies, 0);
- int count = getSuggestionsNative(mNativeDict, mInputCodes, codesSize, mOutputChars,
- mFrequencies);
+ int count = getSuggestionsNative(
+ mNativeDict, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(),
+ codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize,
+ mOutputChars, mFrequencies);
for (int j = 0; j < count; ++j) {
if (mFrequencies[j] < 1) break;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 1e6238e69..97f6b8d83 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -100,7 +100,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
* shown for a given text field. For instance, this is specified by the
* search dialog when the dialog is already showing a voice search button.
*/
- public static final String IME_OPTION_NO_MICROPHONE = "noMicrophone";
+ public static final String IME_OPTION_NO_MICROPHONE = "noMicrophoneKey";
+
+ /**
+ * The private IME option used to indicate that no settings key should be
+ * shown for a given text field.
+ */
+ public static final String IME_OPTION_NO_SETTINGS_KEY = "noSettingsKey";
private static final int DELAY_UPDATE_SUGGESTIONS = 180;
private static final int DELAY_UPDATE_OLD_SUGGESTIONS = 300;
@@ -205,6 +211,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final ArrayList<WordAlternatives> mWordHistory = new ArrayList<WordAlternatives>();
+ static {
+ try {
+ System.loadLibrary("jni_latinime");
+ } catch (UnsatisfiedLinkError ule) {
+ Log.e(TAG, "Could not load native library jni_latinime");
+ }
+ }
+
public abstract static class WordAlternatives {
protected CharSequence mChosenWord;
@@ -415,7 +429,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
private void initSuggest() {
- updateAutoTextEnabled();
String locale = mSubtypeSwitcher.getInputLocaleStr();
Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(new Locale(locale));
@@ -429,6 +442,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
int mainDicResId = Utils.getMainDictionaryResourceId(res);
mSuggest = new Suggest(this, mainDicResId);
loadAndSetAutoCorrectionThreshold(prefs);
+ updateAutoTextEnabled();
mUserDictionary = new UserDictionary(this, locale);
mSuggest.setUserDictionary(mUserDictionary);
@@ -1133,7 +1147,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (isWordSeparator(primaryCode)) {
handleSeparator(primaryCode);
} else {
- handleCharacter(primaryCode, keyCodes);
+ handleCharacter(primaryCode, keyCodes, x, y);
}
// Cancel the just reverted state
mJustReverted = false;
@@ -1258,7 +1272,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- private void handleCharacter(int primaryCode, int[] keyCodes) {
+ private void handleCharacter(int primaryCode, int[] keyCodes, int x, int y) {
mVoiceConnector.handleCharacter();
if (mLastSelectionStart == mLastSelectionEnd && TextEntryState.isCorrecting()) {
@@ -1299,7 +1313,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mWord.setFirstCharCapitalized(true);
}
mComposing.append((char) code);
- mWord.add(code, keyCodes);
+ mWord.add(code, keyCodes, x, y);
InputConnection ic = getCurrentInputConnection();
if (ic != null) {
// If it's the first letter, make note of auto-caps state
@@ -1635,9 +1649,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mJustAddedAutoSpace = true;
}
- final boolean showingAddToDictionaryHint = index == 0 && mCorrectionMode > 0
+ // We should show the hint if the user pressed the first entry AND either:
+ // - There is no dictionary (we know that because we tried to load it => null != mSuggest
+ // AND mHasDictionary is false)
+ // - There is a dictionary and the word is not in it
+ // Please note that if mSuggest is null, it means that everything is off: suggestion
+ // and correction, so we shouldn't try to show the hint
+ // We used to look at mCorrectionMode here, but showing the hint should have nothing
+ // to do with the autocorrection setting.
+ final boolean showingAddToDictionaryHint = index == 0 &&
+ // Test for no dictionary:
+ ((!mHasDictionary && null != mSuggest) ||
+ // Test for dictionary && word is inside:
+ (mHasDictionary && null != mSuggest
&& !mSuggest.isValidWord(suggestion)
- && !mSuggest.isValidWord(suggestion.toString().toLowerCase());
+ && !mSuggest.isValidWord(suggestion.toString().toLowerCase())));
if (!correcting) {
// Fool the state watcher so that a subsequent backspace will not do a revert, unless
@@ -1706,7 +1732,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
for (int i = 0; i < touching.mWord.length(); i++) {
foundWord.add(touching.mWord.charAt(i), new int[] {
touching.mWord.charAt(i)
- });
+ }, WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
}
foundWord.setFirstCharCapitalized(Character.isUpperCase(touching.mWord.charAt(0)));
}
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index e003dcd5b..02583895b 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -24,18 +24,24 @@ import java.util.ArrayList;
* A place to store the currently composing word with information such as adjacent key codes as well
*/
public class WordComposer {
+
public static final int NOT_A_CODE = KeyDetector.NOT_A_CODE;
+ public static final int NOT_A_COORDINATE = -1;
/**
* The list of unicode values for each keystroke (including surrounding keys)
*/
private final ArrayList<int[]> mCodes;
-
+
+ private int mTypedLength;
+ private final int[] mXCoordinates;
+ private final int[] mYCoordinates;
+
/**
* The word chosen from the candidate list, until it is committed.
*/
private String mPreferredWord;
-
+
private final StringBuilder mTypedWord;
private int mCapsCount;
@@ -48,17 +54,24 @@ public class WordComposer {
private boolean mIsFirstCharCapitalized;
public WordComposer() {
- mCodes = new ArrayList<int[]>(12);
- mTypedWord = new StringBuilder(20);
+ final int N = BinaryDictionary.MAX_WORD_LENGTH;
+ mCodes = new ArrayList<int[]>(N);
+ mTypedWord = new StringBuilder(N);
+ mTypedLength = 0;
+ mXCoordinates = new int[N];
+ mYCoordinates = new int[N];
}
- WordComposer(WordComposer copy) {
- mCodes = new ArrayList<int[]>(copy.mCodes);
- mPreferredWord = copy.mPreferredWord;
- mTypedWord = new StringBuilder(copy.mTypedWord);
- mCapsCount = copy.mCapsCount;
- mAutoCapitalized = copy.mAutoCapitalized;
- mIsFirstCharCapitalized = copy.mIsFirstCharCapitalized;
+ WordComposer(WordComposer source) {
+ mCodes = new ArrayList<int[]>(source.mCodes);
+ mPreferredWord = source.mPreferredWord;
+ mTypedWord = new StringBuilder(source.mTypedWord);
+ mCapsCount = source.mCapsCount;
+ mAutoCapitalized = source.mAutoCapitalized;
+ mIsFirstCharCapitalized = source.mIsFirstCharCapitalized;
+ mTypedLength = source.mTypedLength;
+ mXCoordinates = source.mXCoordinates;
+ mYCoordinates = source.mYCoordinates;
}
/**
@@ -66,6 +79,7 @@ public class WordComposer {
*/
public void reset() {
mCodes.clear();
+ mTypedLength = 0;
mIsFirstCharCapitalized = false;
mPreferredWord = null;
mTypedWord.setLength(0);
@@ -89,15 +103,28 @@ public class WordComposer {
return mCodes.get(index);
}
+ public int[] getXCoordinates() {
+ return mXCoordinates;
+ }
+
+ public int[] getYCoordinates() {
+ return mYCoordinates;
+ }
+
/**
* Add a new keystroke, with codes[0] containing the pressed key's unicode and the rest of
* the array containing unicode for adjacent keys, sorted by reducing probability/proximity.
* @param codes the array of unicode values
*/
- public void add(int primaryCode, int[] codes) {
+ public void add(int primaryCode, int[] codes, int x, int y) {
mTypedWord.append((char) primaryCode);
correctPrimaryJuxtapos(primaryCode, codes);
mCodes.add(codes);
+ if (mTypedLength < BinaryDictionary.MAX_WORD_LENGTH) {
+ mXCoordinates[mTypedLength] = x;
+ mYCoordinates[mTypedLength] = y;
+ }
+ ++mTypedLength;
if (Character.isUpperCase((char) primaryCode)) mCapsCount++;
}
@@ -128,6 +155,9 @@ public class WordComposer {
mTypedWord.deleteCharAt(lastPos);
if (Character.isUpperCase(last)) mCapsCount--;
}
+ if (mTypedLength > 0) {
+ --mTypedLength;
+ }
}
/**
diff --git a/native/Android.mk b/native/Android.mk
index a8fe06d50..c8342e31f 100644
--- a/native/Android.mk
+++ b/native/Android.mk
@@ -4,10 +4,13 @@ include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/src
LOCAL_SRC_FILES := \
+ jni/com_android_inputmethod_keyboard_ProximityInfo.cpp \
jni/com_android_inputmethod_latin_BinaryDictionary.cpp \
+ jni/onload.cpp \
src/bigram_dictionary.cpp \
src/char_utils.cpp \
src/dictionary.cpp \
+ src/proximity_info.cpp \
src/unigram_dictionary.cpp
#FLAG_DBG := true
diff --git a/native/jni/com_android_inputmethod_keyboard_ProximityInfo.cpp b/native/jni/com_android_inputmethod_keyboard_ProximityInfo.cpp
new file mode 100644
index 000000000..3db89edf1
--- /dev/null
+++ b/native/jni/com_android_inputmethod_keyboard_ProximityInfo.cpp
@@ -0,0 +1,90 @@
+/*
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#define LOG_TAG "LatinIME: jni: ProximityInfo"
+
+#include "com_android_inputmethod_keyboard_ProximityInfo.h"
+#include "jni.h"
+#include "proximity_info.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+
+// ----------------------------------------------------------------------------
+
+namespace latinime {
+
+//
+// helper function to throw an exception
+//
+static void throwException(JNIEnv *env, const char* ex, const char* fmt, int data) {
+ if (jclass cls = env->FindClass(ex)) {
+ char msg[1000];
+ snprintf(msg, sizeof(msg), fmt, data);
+ env->ThrowNew(cls, msg);
+ env->DeleteLocalRef(cls);
+ }
+}
+
+static jint latinime_Keyboard_setProximityInfo(JNIEnv *env, jobject object,
+ jint maxProximityCharsSize, jint displayWidth, jint displayHeight, jint gridWidth,
+ jint gridHeight, jintArray proximityCharsArray) {
+ jint* proximityChars = env->GetIntArrayElements(proximityCharsArray, NULL);
+ ProximityInfo *proximityInfo = new ProximityInfo(maxProximityCharsSize, displayWidth,
+ displayHeight, gridWidth, gridHeight, (const uint32_t *)proximityChars);
+ env->ReleaseIntArrayElements(proximityCharsArray, proximityChars, 0);
+ return (jint)proximityInfo;
+}
+
+static void latinime_Keyboard_release(JNIEnv *env, jobject object, jint proximityInfo) {
+ ProximityInfo *pi = (ProximityInfo*)proximityInfo;
+ if (!pi) return;
+ delete pi;
+}
+
+// ----------------------------------------------------------------------------
+
+static JNINativeMethod sKeyboardMethods[] = {
+ {"setProximityInfoNative", "(IIIII[I)I", (void*)latinime_Keyboard_setProximityInfo},
+ {"releaseProximityInfoNative", "(I)V", (void*)latinime_Keyboard_release}
+};
+
+static int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMethod* gMethods,
+ int numMethods) {
+ jclass clazz;
+
+ clazz = env->FindClass(className);
+ if (clazz == NULL) {
+ LOGE("Native registration unable to find class '%s'", className);
+ return JNI_FALSE;
+ }
+ if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) {
+ LOGE("RegisterNatives failed for '%s'", className);
+ return JNI_FALSE;
+ }
+
+ return JNI_TRUE;
+}
+
+int register_ProximityInfo(JNIEnv *env) {
+ const char* const kClassPathName = "com/android/inputmethod/keyboard/ProximityInfo";
+ return registerNativeMethods(env, kClassPathName, sKeyboardMethods,
+ sizeof(sKeyboardMethods) / sizeof(sKeyboardMethods[0]));
+}
+
+}; // namespace latinime
diff --git a/native/jni/com_android_inputmethod_keyboard_ProximityInfo.h b/native/jni/com_android_inputmethod_keyboard_ProximityInfo.h
new file mode 100644
index 000000000..bdeeb8f37
--- /dev/null
+++ b/native/jni/com_android_inputmethod_keyboard_ProximityInfo.h
@@ -0,0 +1,27 @@
+/*
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#ifndef _COM_ANDROID_INPUTMETHOD_KEYBOARD_PROXIMITYINFO_H
+#define _COM_ANDROID_INPUTMETHOD_KEYBOARD_PROXIMITYINFO_H
+
+#include "jni.h"
+
+namespace latinime {
+int register_ProximityInfo(JNIEnv *env);
+}
+
+#endif // _COM_ANDROID_INPUTMETHOD_KEYBOARD_PROXIMITYINFO_H
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
index 4660103b1..b10dd6d7b 100644
--- a/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
+++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.cpp
@@ -15,10 +15,12 @@
** limitations under the License.
*/
-#define LOG_TAG "LatinIME: jni"
+#define LOG_TAG "LatinIME: jni: BinaryDictionary"
+#include "com_android_inputmethod_latin_BinaryDictionary.h"
#include "dictionary.h"
#include "jni.h"
+#include "proximity_info.h"
#include <assert.h>
#include <errno.h>
@@ -35,7 +37,7 @@
// ----------------------------------------------------------------------------
-using namespace latinime;
+namespace latinime {
//
// helper function to throw an exception
@@ -43,7 +45,7 @@ using namespace latinime;
static void throwException(JNIEnv *env, const char* ex, const char* fmt, int data) {
if (jclass cls = env->FindClass(ex)) {
char msg[1000];
- sprintf(msg, fmt, data);
+ snprintf(msg, sizeof(msg), fmt, data);
env->ThrowNew(cls, msg);
env->DeleteLocalRef(cls);
}
@@ -123,19 +125,27 @@ static jint latinime_BinaryDictionary_open(JNIEnv *env, jobject object,
}
static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object, jint dict,
+ jint proximityInfo, jintArray xCoordinatesArray, jintArray yCoordinatesArray,
jintArray inputArray, jint arraySize, jcharArray outputArray, jintArray frequencyArray) {
Dictionary *dictionary = (Dictionary*)dict;
if (!dictionary) return 0;
+ ProximityInfo *pInfo = (ProximityInfo*)proximityInfo;
+ if (!pInfo) return 0;
+
+ int *xCoordinates = env->GetIntArrayElements(xCoordinatesArray, NULL);
+ int *yCoordinates = env->GetIntArrayElements(yCoordinatesArray, NULL);
int *frequencies = env->GetIntArrayElements(frequencyArray, NULL);
int *inputCodes = env->GetIntArrayElements(inputArray, NULL);
jchar *outputChars = env->GetCharArrayElements(outputArray, NULL);
- int count = dictionary->getSuggestions(inputCodes, arraySize, (unsigned short*) outputChars,
- frequencies);
+ int count = dictionary->getSuggestions(pInfo, xCoordinates, yCoordinates, inputCodes,
+ arraySize, (unsigned short*) outputChars, frequencies);
env->ReleaseIntArrayElements(frequencyArray, frequencies, 0);
env->ReleaseIntArrayElements(inputArray, inputCodes, JNI_ABORT);
+ env->ReleaseIntArrayElements(xCoordinatesArray, xCoordinates, 0);
+ env->ReleaseIntArrayElements(yCoordinatesArray, yCoordinates, 0);
env->ReleaseCharArrayElements(outputArray, outputChars, 0);
return count;
@@ -200,10 +210,10 @@ static void latinime_BinaryDictionary_close(JNIEnv *env, jobject object, jint di
// ----------------------------------------------------------------------------
-static JNINativeMethod gMethods[] = {
+static JNINativeMethod sMethods[] = {
{"openNative", "(Ljava/lang/String;JJIIIII)I", (void*)latinime_BinaryDictionary_open},
{"closeNative", "(I)V", (void*)latinime_BinaryDictionary_close},
- {"getSuggestionsNative", "(I[II[C[I)I", (void*)latinime_BinaryDictionary_getSuggestions},
+ {"getSuggestionsNative", "(II[I[I[II[C[I)I", (void*)latinime_BinaryDictionary_getSuggestions},
{"isValidWordNative", "(I[CI)Z", (void*)latinime_BinaryDictionary_isValidWord},
{"getBigramsNative", "(I[CI[II[C[IIII)I", (void*)latinime_BinaryDictionary_getBigrams}
};
@@ -225,33 +235,10 @@ static int registerNativeMethods(JNIEnv* env, const char* className, JNINativeMe
return JNI_TRUE;
}
-static int registerNatives(JNIEnv *env) {
+int register_BinaryDictionary(JNIEnv *env) {
const char* const kClassPathName = "com/android/inputmethod/latin/BinaryDictionary";
- return registerNativeMethods(env, kClassPathName, gMethods,
- sizeof(gMethods) / sizeof(gMethods[0]));
+ return registerNativeMethods(env, kClassPathName, sMethods,
+ sizeof(sMethods) / sizeof(sMethods[0]));
}
-/*
- * Returns the JNI version on success, -1 on failure.
- */
-jint JNI_OnLoad(JavaVM* vm, void* reserved) {
- JNIEnv* env = NULL;
- jint result = -1;
-
- if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
- LOGE("ERROR: GetEnv failed");
- goto bail;
- }
- assert(env != NULL);
-
- if (!registerNatives(env)) {
- LOGE("ERROR: BinaryDictionary native registration failed");
- goto bail;
- }
-
- /* success -- return valid version number */
- result = JNI_VERSION_1_4;
-
-bail:
- return result;
-}
+}; // namespace latinime
diff --git a/native/jni/com_android_inputmethod_latin_BinaryDictionary.h b/native/jni/com_android_inputmethod_latin_BinaryDictionary.h
new file mode 100644
index 000000000..f7cd81fa7
--- /dev/null
+++ b/native/jni/com_android_inputmethod_latin_BinaryDictionary.h
@@ -0,0 +1,27 @@
+/*
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#ifndef _COM_ANDROID_INPUTMETHOD_LATIN_BINARYDICTIONARY_H
+#define _COM_ANDROID_INPUTMETHOD_LATIN_BINARYDICTIONARY_H
+
+#include "jni.h"
+
+namespace latinime {
+int register_BinaryDictionary(JNIEnv *env);
+}
+
+#endif // _COM_ANDROID_INPUTMETHOD_LATIN_BINARYDICTIONARY_H
diff --git a/native/jni/onload.cpp b/native/jni/onload.cpp
new file mode 100644
index 000000000..f02c9a052
--- /dev/null
+++ b/native/jni/onload.cpp
@@ -0,0 +1,62 @@
+/*
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+
+#define LOG_TAG "LatinIME: jni"
+
+#include "com_android_inputmethod_keyboard_ProximityInfo.h"
+#include "com_android_inputmethod_latin_BinaryDictionary.h"
+#include "jni.h"
+#include "proximity_info.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+
+// ----------------------------------------------------------------------------
+
+using namespace latinime;
+
+
+/*
+ * Returns the JNI version on success, -1 on failure.
+ */
+jint JNI_OnLoad(JavaVM* vm, void* reserved) {
+ JNIEnv* env = NULL;
+ jint result = -1;
+
+ if (vm->GetEnv((void**) &env, JNI_VERSION_1_4) != JNI_OK) {
+ LOGE("ERROR: GetEnv failed");
+ goto bail;
+ }
+ assert(env != NULL);
+
+ if (!register_BinaryDictionary(env)) {
+ LOGE("ERROR: BinaryDictionary native registration failed");
+ goto bail;
+ }
+
+ if (!register_ProximityInfo(env)) {
+ LOGE("ERROR: ProximityInfo native registration failed");
+ goto bail;
+ }
+
+ /* success -- return valid version number */
+ result = JNI_VERSION_1_4;
+
+bail:
+ return result;
+}
diff --git a/native/src/defines.h b/native/src/defines.h
index 918028afe..ddd65c9fa 100644
--- a/native/src/defines.h
+++ b/native/src/defines.h
@@ -28,6 +28,7 @@
#define DEBUG_SHOW_FOUND_WORD DEBUG_DICT_FULL
#define DEBUG_NODE DEBUG_DICT_FULL
#define DEBUG_TRACE DEBUG_DICT_FULL
+#define DEBUG_PROXIMITY_INFO true
// Profiler
#include <time.h>
@@ -83,6 +84,7 @@ static void prof_out(void) {
#define DEBUG_SHOW_FOUND_WORD false
#define DEBUG_NODE false
#define DEBUG_TRACE false
+#define DEBUG_PROXIMITY_INFO false
#define PROF_BUF_SIZE 0
#define PROF_RESET
diff --git a/native/src/dictionary.cpp b/native/src/dictionary.cpp
index fe3375706..d69cb2a53 100644
--- a/native/src/dictionary.cpp
+++ b/native/src/dictionary.cpp
@@ -23,6 +23,7 @@
namespace latinime {
+// TODO: Change the type of all keyCodes to uint32_t
Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
int typedLetterMultiplier, int fullWordMultiplier,
int maxWordLength, int maxWords, int maxAlternatives)
@@ -53,8 +54,7 @@ bool Dictionary::hasBigram() {
}
// TODO: use uint16_t instead of unsigned short
-bool Dictionary::isValidWord(unsigned short *word, int length)
-{
+bool Dictionary::isValidWord(unsigned short *word, int length) {
if (IS_LATEST_DICT_VERSION) {
return (isValidWordRec(DICTIONARY_HEADER_SIZE, word, 0, length) != NOT_VALID_WORD);
} else {
diff --git a/native/src/dictionary.h b/native/src/dictionary.h
index 941bd191a..fbbb8312b 100644
--- a/native/src/dictionary.h
+++ b/native/src/dictionary.h
@@ -19,6 +19,7 @@
#include "bigram_dictionary.h"
#include "defines.h"
+#include "proximity_info.h"
#include "unigram_dictionary.h"
namespace latinime {
@@ -27,8 +28,10 @@ class Dictionary {
public:
Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, int typedLetterMultipler,
int fullWordMultiplier, int maxWordLength, int maxWords, int maxAlternatives);
- int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies) {
- return mUnigramDictionary->getSuggestions(codes, codesSize, outWords, frequencies);
+ int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
+ int *codes, int codesSize, unsigned short *outWords, int *frequencies) {
+ return mUnigramDictionary->getSuggestions(proximityInfo, xcoordinates, ycoordinates, codes,
+ codesSize, outWords, frequencies);
}
// TODO: Call mBigramDictionary instead of mUnigramDictionary
@@ -38,6 +41,7 @@ public:
return mBigramDictionary->getBigrams(word, length, codes, codesSize, outWords, frequencies,
maxWordLength, maxBigrams, maxAlternatives);
}
+
bool isValidWord(unsigned short *word, int length);
int isValidWordRec(int pos, unsigned short *word, int offset, int length);
void *getDict() { return (void *)mDict; }
diff --git a/native/src/proximity_info.cpp b/native/src/proximity_info.cpp
new file mode 100644
index 000000000..d0cba3eb6
--- /dev/null
+++ b/native/src/proximity_info.cpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "proximity_info.h"
+
+namespace latinime {
+ProximityInfo::ProximityInfo(int maxProximityCharsSize, int displayWidth, int displayHeight,
+ int gridWidth, int gridHeight, uint32_t const *proximityCharsArray)
+ : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), DISPLAY_WIDTH(displayWidth),
+ DISPLAY_HEIGHT(displayHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight) {
+ mProximityCharsArray = new uint32_t[GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE];
+ memcpy(mProximityCharsArray, proximityCharsArray, sizeof(mProximityCharsArray));
+}
+
+ProximityInfo::~ProximityInfo() {
+ delete[] mProximityCharsArray;
+}
+}
diff --git a/native/src/proximity_info.h b/native/src/proximity_info.h
new file mode 100644
index 000000000..54e995059
--- /dev/null
+++ b/native/src/proximity_info.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef LATINIME_PROXIMITY_INFO_H
+#define LATINIME_PROXIMITY_INFO_H
+
+#include <stdint.h>
+
+#include "defines.h"
+
+namespace latinime {
+
+class ProximityInfo {
+public:
+ ProximityInfo(int maxProximityCharsSize, int displayWidth, int displayHeight, int gridWidth,
+ int gridHeight, uint32_t const *proximityCharsArray);
+ ~ProximityInfo();
+private:
+ const int MAX_PROXIMITY_CHARS_SIZE;
+ const int DISPLAY_WIDTH;
+ const int DISPLAY_HEIGHT;
+ const int GRID_WIDTH;
+ const int GRID_HEIGHT;
+ uint32_t *mProximityCharsArray;
+};
+}; // namespace latinime
+#endif // LATINIME_PROXIMITY_INFO_H
diff --git a/native/src/unigram_dictionary.cpp b/native/src/unigram_dictionary.cpp
index 0ea650629..72b0f361a 100644
--- a/native/src/unigram_dictionary.cpp
+++ b/native/src/unigram_dictionary.cpp
@@ -41,13 +41,19 @@ UnigramDictionary::UnigramDictionary(const unsigned char *dict, int typedLetterM
UnigramDictionary::~UnigramDictionary() {}
-int UnigramDictionary::getSuggestions(int *codes, int codesSize, unsigned short *outWords,
- int *frequencies) {
+int UnigramDictionary::getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates,
+ int *ycoordinates, int *codes, int codesSize, unsigned short *outWords, int *frequencies) {
PROF_OPEN;
PROF_START(0);
initSuggestions(codes, codesSize, outWords, frequencies);
if (DEBUG_DICT) assert(codesSize == mInputLength);
+ if (DEBUG_PROXIMITY_INFO) {
+ for (int i = 0; i < codesSize; ++i) {
+ LOGI("Input[%d] x = %d, y = %d", i, xcoordinates[i], ycoordinates[i]);
+ }
+ }
+
const int MAX_DEPTH = min(mInputLength * MAX_DEPTH_MULTIPLIER, MAX_WORD_LENGTH);
PROF_END(0);
@@ -406,7 +412,7 @@ inline void UnigramDictionary::onTerminalWhenUserTypedLengthIsSameAsInputLength(
inline bool UnigramDictionary::needsToSkipCurrentNode(const unsigned short c,
const int inputIndex, const int skipPos, const int depth) {
- const unsigned short userTypedChar = (mInputCodes + (inputIndex * MAX_PROXIMITY_CHARS))[0];
+ const unsigned short userTypedChar = getInputCharsAt(inputIndex)[0];
// Skip the ' or other letter and continue deeper
return (c == QUOTE && userTypedChar != QUOTE) || skipPos == depth;
}
@@ -517,7 +523,7 @@ inline bool UnigramDictionary::processCurrentNode(const int pos, const int depth
*newDiffs = diffs;
*newInputIndex = inputIndex;
} else {
- int *currentChars = mInputCodes + (inputIndex * MAX_PROXIMITY_CHARS);
+ int *currentChars = getInputCharsAt(inputIndex);
if (transposedPos >= 0) {
if (inputIndex == transposedPos) currentChars += MAX_PROXIMITY_CHARS;
@@ -620,7 +626,7 @@ inline bool UnigramDictionary::processCurrentNodeForExactMatch(const int firstCh
const int startInputIndex, const int depth, unsigned short *word, int *newChildPosition,
int *newCount, bool *newTerminal, int *newFreq, int *siblingPos) {
const int inputIndex = startInputIndex + depth;
- const int *currentChars = mInputCodes + (inputIndex * MAX_PROXIMITY_CHARS);
+ const int *currentChars = getInputCharsAt(inputIndex);
unsigned short c;
*siblingPos = Dictionary::setDictionaryValues(DICT, IS_LATEST_DICT_VERSION, firstChildPos, &c,
newChildPosition, newTerminal, newFreq);
diff --git a/native/src/unigram_dictionary.h b/native/src/unigram_dictionary.h
index db40646e1..e84875b59 100644
--- a/native/src/unigram_dictionary.h
+++ b/native/src/unigram_dictionary.h
@@ -18,6 +18,7 @@
#define LATINIME_UNIGRAM_DICTIONARY_H
#include "defines.h"
+#include "proximity_info.h"
namespace latinime {
@@ -32,7 +33,8 @@ class UnigramDictionary {
public:
UnigramDictionary(const unsigned char *dict, int typedLetterMultipler, int fullWordMultiplier,
int maxWordLength, int maxWords, int maxProximityChars, const bool isLatestDictVersion);
- int getSuggestions(int *codes, int codesSize, unsigned short *outWords, int *frequencies);
+ int getSuggestions(ProximityInfo *proximityInfo, int *xcoordinates, int *ycoordinates,
+ int *codes, int codesSize, unsigned short *outWords, int *frequencies);
~UnigramDictionary();
private:
@@ -84,7 +86,9 @@ private:
const int startInputIndex, const int depth, unsigned short *word,
int *newChildPosition, int *newCount, bool *newTerminal, int *newFreq, int *siblingPos);
bool existsAdjacentProximityChars(const int inputIndex, const int inputLength);
- int* getInputCharsAt(const int index) {return mInputCodes + (index * MAX_PROXIMITY_CHARS);}
+ inline int* getInputCharsAt(const int index) {
+ return mInputCodes + (index * MAX_PROXIMITY_CHARS);
+ }
const unsigned char *DICT;
const int MAX_WORD_LENGTH;
const int MAX_WORDS;
diff --git a/tests/src/com/android/inputmethod/latin/SuggestHelper.java b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
index 88f89d9ae..a845acb9a 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestHelper.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestHelper.java
@@ -64,7 +64,7 @@ public class SuggestHelper {
return mSuggest.hasMainDictionary();
}
- private int[] getProximityCodes(char c) {
+ private void addKeyInfo(WordComposer word, char c) {
final List<Key> keys = mKeyboard.getKeys();
for (final Key key : keys) {
if (key.mCode == c) {
@@ -72,17 +72,17 @@ public class SuggestHelper {
final int y = key.mY + key.mHeight / 2;
final int[] codes = mKeyDetector.newCodeArray();
mKeyDetector.getKeyIndexAndNearbyCodes(x, y, codes);
- return codes;
+ word.add(c, codes, x, y);
}
}
- return new int[] { c };
+ word.add(c, new int[] { c }, WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
}
protected WordComposer createWordComposer(CharSequence s) {
WordComposer word = new WordComposer();
for (int i = 0; i < s.length(); i++) {
final char c = s.charAt(i);
- word.add(c, getProximityCodes(c));
+ addKeyInfo(word, c);
}
return word;
}