aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java6
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardId.java56
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java6
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java29
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java13
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/Word.java23
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java6
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java24
8 files changed, 98 insertions, 65 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index b09a27540..0a2b010b6 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -180,7 +180,7 @@ public class Key {
mY = y;
mHitBox.set(x, y, x + width + 1, y + height);
- mHashCode = hashCode(this);
+ mHashCode = computeHashCode(this);
}
/**
@@ -334,7 +334,7 @@ public class Key {
mAltCode = adjustCaseOfCodeForKeyboardId(style.getInt(keyAttr,
R.styleable.Keyboard_Key_altCode, Keyboard.CODE_UNSPECIFIED), preserveCase,
params.mId);
- mHashCode = hashCode(this);
+ mHashCode = computeHashCode(this);
keyAttr.recycle();
@@ -366,7 +366,7 @@ public class Key {
}
}
- private static int hashCode(Key key) {
+ private static int computeHashCode(Key key) {
return Arrays.hashCode(new Object[] {
key.mX,
key.mY,
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
index 6703b9301..3b2b11e4e 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java
@@ -70,23 +70,23 @@ public class KeyboardId {
public KeyboardId(int elementId, Locale locale, int orientation, int width, int mode,
EditorInfo editorInfo, boolean clobberSettingsKey, boolean shortcutKeyEnabled,
boolean hasShortcutKey, boolean languageSwitchKeyEnabled) {
- this.mLocale = locale;
- this.mOrientation = orientation;
- this.mWidth = width;
- this.mMode = mode;
- this.mElementId = elementId;
- this.mEditorInfo = editorInfo;
- this.mClobberSettingsKey = clobberSettingsKey;
- this.mShortcutKeyEnabled = shortcutKeyEnabled;
- this.mHasShortcutKey = hasShortcutKey;
- this.mLanguageSwitchKeyEnabled = languageSwitchKeyEnabled;
- this.mCustomActionLabel = (editorInfo.actionLabel != null)
+ mLocale = locale;
+ mOrientation = orientation;
+ mWidth = width;
+ mMode = mode;
+ mElementId = elementId;
+ mEditorInfo = editorInfo;
+ mClobberSettingsKey = clobberSettingsKey;
+ mShortcutKeyEnabled = shortcutKeyEnabled;
+ mHasShortcutKey = hasShortcutKey;
+ mLanguageSwitchKeyEnabled = languageSwitchKeyEnabled;
+ mCustomActionLabel = (editorInfo.actionLabel != null)
? editorInfo.actionLabel.toString() : null;
- this.mHashCode = hashCode(this);
+ mHashCode = computeHashCode(this);
}
- private static int hashCode(KeyboardId id) {
+ private static int computeHashCode(KeyboardId id) {
return Arrays.hashCode(new Object[] {
id.mOrientation,
id.mElementId,
@@ -109,21 +109,21 @@ public class KeyboardId {
private boolean equals(KeyboardId other) {
if (other == this)
return true;
- return other.mOrientation == this.mOrientation
- && other.mElementId == this.mElementId
- && other.mMode == this.mMode
- && other.mWidth == this.mWidth
- && other.passwordInput() == this.passwordInput()
- && other.mClobberSettingsKey == this.mClobberSettingsKey
- && other.mShortcutKeyEnabled == this.mShortcutKeyEnabled
- && other.mHasShortcutKey == this.mHasShortcutKey
- && other.mLanguageSwitchKeyEnabled == this.mLanguageSwitchKeyEnabled
- && other.isMultiLine() == this.isMultiLine()
- && other.imeAction() == this.imeAction()
- && TextUtils.equals(other.mCustomActionLabel, this.mCustomActionLabel)
- && other.navigateNext() == this.navigateNext()
- && other.navigatePrevious() == this.navigatePrevious()
- && other.mLocale.equals(this.mLocale);
+ return other.mOrientation == mOrientation
+ && other.mElementId == mElementId
+ && other.mMode == mMode
+ && other.mWidth == mWidth
+ && other.passwordInput() == passwordInput()
+ && other.mClobberSettingsKey == mClobberSettingsKey
+ && other.mShortcutKeyEnabled == mShortcutKeyEnabled
+ && other.mHasShortcutKey == mHasShortcutKey
+ && other.mLanguageSwitchKeyEnabled == mLanguageSwitchKeyEnabled
+ && other.isMultiLine() == isMultiLine()
+ && other.imeAction() == imeAction()
+ && TextUtils.equals(other.mCustomActionLabel, mCustomActionLabel)
+ && other.navigateNext() == navigateNext()
+ && other.navigatePrevious() == navigatePrevious()
+ && other.mLocale.equals(mLocale);
}
public boolean isAlphabetKeyboard() {
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index aa499ed24..5c1808613 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -79,10 +79,12 @@ public class ProximityInfo {
final ProximityInfo spellCheckerProximityInfo = createDummyProximityInfo();
spellCheckerProximityInfo.mNativeProximityInfo =
spellCheckerProximityInfo.setProximityInfoNative("",
- SpellCheckerProximityInfo.ROW_SIZE, 480, 300,
+ SpellCheckerProximityInfo.ROW_SIZE,
SpellCheckerProximityInfo.PROXIMITY_GRID_WIDTH,
SpellCheckerProximityInfo.PROXIMITY_GRID_HEIGHT,
- (480 / 10), proximity, 0, null, null, null, null, null, null, null, null);
+ SpellCheckerProximityInfo.PROXIMITY_GRID_WIDTH,
+ SpellCheckerProximityInfo.PROXIMITY_GRID_HEIGHT,
+ 1, proximity, 0, null, null, null, null, null, null, null, null);
return spellCheckerProximityInfo;
}
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 9f23f174f..231211d31 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -127,12 +127,8 @@ public class WordComposer {
final int[] codes;
final int keyX;
final int keyY;
- if (x == KeyboardActionListener.SPELL_CHECKER_COORDINATE
- || y == KeyboardActionListener.SPELL_CHECKER_COORDINATE) {
- // only used for tests in InputLogicTests
- addKeyForSpellChecker(primaryCode, AndroidSpellCheckerService.SCRIPT_LATIN);
- return;
- } else if (x == KeyboardActionListener.SUGGESTION_STRIP_COORDINATE
+ if (null == keyDetector
+ || x == KeyboardActionListener.SUGGESTION_STRIP_COORDINATE
|| y == KeyboardActionListener.SUGGESTION_STRIP_COORDINATE
|| x == KeyboardActionListener.NOT_A_TOUCH_COORDINATE
|| y == KeyboardActionListener.NOT_A_TOUCH_COORDINATE) {
@@ -149,27 +145,6 @@ public class WordComposer {
add(primaryCode, codes, keyX, keyY);
}
- // TODO: remove this function
- public void addKeyForSpellChecker(int primaryCode, int script) {
- final int[] proximities;
- final int proximityIndex =
- SpellCheckerProximityInfo.getIndexOfCodeForScript(primaryCode, script);
- if (-1 == proximityIndex) {
- proximities = new int[] { primaryCode };
- } else {
- // TODO: an initial examination seems to reveal this is actually used
- // read-only. It should be possible to compute the arrays statically once
- // and skip doing a copy each time here.
- proximities = Arrays.copyOfRange(
- SpellCheckerProximityInfo.getProximityForScript(script),
- proximityIndex,
- proximityIndex + SpellCheckerProximityInfo.ROW_SIZE);
- }
- add(primaryCode, proximities,
- KeyboardActionListener.NOT_A_TOUCH_COORDINATE,
- KeyboardActionListener.NOT_A_TOUCH_COORDINATE);
- }
-
/**
* 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.
diff --git a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
index e88ab685a..70530c338 100644
--- a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
+++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java
@@ -64,6 +64,19 @@ public class FusionDictionary implements Iterable<Word> {
mWord = word;
mFrequency = frequency;
}
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(new Object[] { mWord, mFrequency });
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (!(o instanceof WeightedString)) return false;
+ WeightedString w = (WeightedString)o;
+ return mWord.equals(w.mWord) && mFrequency == w.mFrequency;
+ }
}
/**
diff --git a/java/src/com/android/inputmethod/latin/makedict/Word.java b/java/src/com/android/inputmethod/latin/makedict/Word.java
index c2c01e1f8..4e0ab1049 100644
--- a/java/src/com/android/inputmethod/latin/makedict/Word.java
+++ b/java/src/com/android/inputmethod/latin/makedict/Word.java
@@ -19,6 +19,7 @@ package com.android.inputmethod.latin.makedict;
import com.android.inputmethod.latin.makedict.FusionDictionary.WeightedString;
import java.util.ArrayList;
+import java.util.Arrays;
/**
* Utility class for a word with a frequency.
@@ -32,6 +33,8 @@ public class Word implements Comparable<Word> {
final ArrayList<WeightedString> mShortcutTargets;
final ArrayList<WeightedString> mBigrams;
+ private int mHashCode = 0;
+
public Word(final String word, final int frequency,
final ArrayList<WeightedString> shortcutTargets,
final ArrayList<WeightedString> bigrams, final boolean isShortcutOnly) {
@@ -42,6 +45,16 @@ public class Word implements Comparable<Word> {
mIsShortcutOnly = isShortcutOnly;
}
+ private static int computeHashCode(Word word) {
+ return Arrays.hashCode(new Object[] {
+ word.mWord,
+ word.mFrequency,
+ word.mIsShortcutOnly,
+ word.mShortcutTargets.hashCode(),
+ word.mBigrams.hashCode()
+ });
+ }
+
/**
* Three-way comparison.
*
@@ -63,10 +76,20 @@ public class Word implements Comparable<Word> {
*/
@Override
public boolean equals(Object o) {
+ if (o == this) return true;
if (!(o instanceof Word)) return false;
Word w = (Word)o;
return mFrequency == w.mFrequency && mWord.equals(w.mWord)
+ && mIsShortcutOnly == w.mIsShortcutOnly
&& mShortcutTargets.equals(w.mShortcutTargets)
&& mBigrams.equals(w.mBigrams);
}
+
+ @Override
+ public int hashCode() {
+ if (mHashCode == 0) {
+ mHashCode = computeHashCode(this);
+ }
+ return mHashCode;
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 35a5c0f52..973a448ee 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -570,7 +570,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService
final WordComposer composer = new WordComposer();
final int length = text.length();
for (int i = 0; i < length; i = text.offsetByCodePoints(i, 1)) {
- composer.addKeyForSpellChecker(text.codePointAt(i), mScript);
+ final int codePoint = text.codePointAt(i);
+ // The getXYForCodePointAndScript method returns (Y << 16) + X
+ final int xy = SpellCheckerProximityInfo.getXYForCodePointAndScript(
+ codePoint, mScript);
+ composer.add(codePoint, xy & 0xFFFF, xy >> 16, null);
}
final int capitalizeType = getCapitalizationType(text);
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java
index f4c66d04c..90c0aac1b 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java
@@ -87,7 +87,7 @@ public class SpellCheckerProximityInfo {
// Proximity for row 2. See comment above about size.
'a', 'z', 'x', 's', 'w', 'q', 'e', 'i', 'o', 'u', NUL, NUL, NUL, NUL, NUL, NUL,
's', 'q', 'a', 'z', 'x', 'c', 'd', 'e', 'w', NUL, NUL, NUL, NUL, NUL, NUL, NUL,
- 'd', 'w', 's', 'x', 'c', 'v', 'f', 'r', 'e', 'w', NUL, NUL, NUL, NUL, NUL, NUL,
+ 'd', 'w', 's', 'x', 'c', 'v', 'f', 'r', 'e', NUL, NUL, NUL, NUL, NUL, NUL, NUL,
'f', 'e', 'd', 'c', 'v', 'b', 'g', 't', 'r', NUL, NUL, NUL, NUL, NUL, NUL, NUL,
'g', 'r', 'f', 'v', 'b', 'n', 'h', 'y', 't', NUL, NUL, NUL, NUL, NUL, NUL, NUL,
'h', 't', 'g', 'b', 'n', 'm', 'j', 'u', 'y', NUL, NUL, NUL, NUL, NUL, NUL, NUL,
@@ -181,14 +181,30 @@ public class SpellCheckerProximityInfo {
throw new RuntimeException("Wrong script supplied: " + script);
}
}
- public static int getIndexOfCodeForScript(final int characterCode, final int script) {
+
+ private static int getIndexOfCodeForScript(final int codePoint, final int script) {
switch (script) {
case AndroidSpellCheckerService.SCRIPT_LATIN:
- return Latin.getIndexOf(characterCode);
+ return Latin.getIndexOf(codePoint);
case AndroidSpellCheckerService.SCRIPT_CYRILLIC:
- return Cyrillic.getIndexOf(characterCode);
+ return Cyrillic.getIndexOf(codePoint);
default:
throw new RuntimeException("Wrong script supplied: " + script);
}
}
+
+ // Returns (Y << 16) + X to avoid creating a temporary object. This is okay because
+ // X and Y are limited to PROXIMITY_GRID_WIDTH resp. PROXIMITY_GRID_HEIGHT which is very
+ // inferior to 1 << 16
+ public static int getXYForCodePointAndScript(final int codePoint, final int script) {
+ final int index = getIndexOfCodeForScript(codePoint, script);
+ // TODO: precompute index / ROW_SIZE
+ final int y = index / (PROXIMITY_GRID_WIDTH * ROW_SIZE);
+ final int x = (index / ROW_SIZE) % PROXIMITY_GRID_WIDTH;
+ if (y > PROXIMITY_GRID_HEIGHT) {
+ // Safety check, should be entirely useless
+ throw new RuntimeException("Wrong y coordinate in spell checker proximity");
+ }
+ return (y << 16) + x;
+ }
}