diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin')
5 files changed, 40 insertions, 57 deletions
diff --git a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java index e7c7e2b8a..17d281518 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java +++ b/java/src/com/android/inputmethod/latin/makedict/FusionDictionary.java @@ -647,7 +647,7 @@ public final class FusionDictionary implements Iterable<Word> { if (index < codePoints.length) return null; if (!currentGroup.isTerminal()) return null; - if (DBG && !codePoints.equals(checker.toString())) return null; + if (DBG && !string.equals(checker.toString())) return null; return currentGroup; } @@ -853,16 +853,19 @@ public final class FusionDictionary implements Iterable<Word> { if (currentPos.pos.hasNext()) { final CharGroup currentGroup = currentPos.pos.next(); currentPos.length = mCurrentString.length(); - for (int i : currentGroup.mChars) + for (int i : currentGroup.mChars) { mCurrentString.append(Character.toChars(i)); + } if (null != currentGroup.mChildren) { currentPos = new Position(currentGroup.mChildren.mData); + currentPos.length = mCurrentString.length(); mPositions.addLast(currentPos); } - if (currentGroup.mFrequency >= 0) + if (currentGroup.mFrequency >= 0) { return new Word(mCurrentString.toString(), currentGroup.mFrequency, currentGroup.mShortcutTargets, currentGroup.mBigrams, currentGroup.mIsNotAWord, currentGroup.mIsBlacklistEntry); + } } else { mPositions.removeLast(); currentPos = mPositions.getLast(); diff --git a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java index 2c18b6e38..0c480eaba 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerProximityInfo.java @@ -16,12 +16,11 @@ package com.android.inputmethod.latin.spellcheck; +import android.util.SparseIntArray; + import com.android.inputmethod.keyboard.ProximityInfo; -import com.android.inputmethod.latin.CollectionUtils; import com.android.inputmethod.latin.Constants; -import java.util.TreeMap; - public final class SpellCheckerProximityInfo extends ProximityInfo { public SpellCheckerProximityInfo(final int script) { super(getProximityForScript(script), PROXIMITY_GRID_WIDTH, PROXIMITY_GRID_HEIGHT); @@ -43,29 +42,14 @@ public final class SpellCheckerProximityInfo extends ProximityInfo { public static final int NOT_A_COORDINATE_PAIR = -1; // Helper methods - static void buildProximityIndices(final int[] proximity, - final TreeMap<Integer, Integer> indices) { - for (int i = 0; i < proximity.length; i += ROW_SIZE) { - if (NUL != proximity[i]) indices.put(proximity[i], i / ROW_SIZE); + static void buildProximityIndices(final int[] proximity, final int rowSize, + final SparseIntArray indices) { + for (int i = 0; i < proximity.length; i += rowSize) { + if (NUL != proximity[i]) indices.put(proximity[i], i / rowSize); } } - static int computeIndex(final int characterCode, - final TreeMap<Integer, Integer> indices) { - final Integer result = indices.get(characterCode); - if (null == result) return NOT_AN_INDEX; - return result; - } - private static final class Latin { - // This is a map from the code point to the index in the PROXIMITY array. - // At the time the native code to read the binary dictionary needs the proximity info be - // passed as a flat array spaced by MAX_PROXIMITY_CHARS_SIZE columns, one for each input - // character. - // Since we need to build such an array, we want to be able to search in our big proximity - // data quickly by character, and a map is probably the best way to do this. - private static final TreeMap<Integer, Integer> INDICES = CollectionUtils.newTreeMap(); - // The proximity here is the union of // - the proximity for a QWERTY keyboard. // - the proximity for an AZERTY keyboard. @@ -125,17 +109,20 @@ public final class SpellCheckerProximityInfo extends ProximityInfo { NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, }; - static { - buildProximityIndices(PROXIMITY, INDICES); - } + // This is a mapping array from the code point to the index in the PROXIMITY array. + // When we check the spelling of a word, we need to pass (x,y) coordinates to the native + // code for each letter of the word. These are most easily computed from the index in the + // PROXIMITY array. Since we'll need to do that very often, the index lookup from the code + // point needs to be as fast as possible, and a map is probably the best way to do this. + // To avoid unnecessary boxing conversion to Integer, here we use SparseIntArray. + static final SparseIntArray INDICES = new SparseIntArray(PROXIMITY.length / ROW_SIZE); - static int getIndexOf(int characterCode) { - return computeIndex(characterCode, INDICES); + static { + buildProximityIndices(PROXIMITY, ROW_SIZE, INDICES); } } private static final class Cyrillic { - private static final TreeMap<Integer, Integer> INDICES = CollectionUtils.newTreeMap(); // TODO: The following table is solely based on the keyboard layout. Consult with Russian // speakers on commonly misspelled words/letters. /* @@ -286,17 +273,14 @@ public final class SpellCheckerProximityInfo extends ProximityInfo { NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, }; - static { - buildProximityIndices(PROXIMITY, INDICES); - } + static final SparseIntArray INDICES = new SparseIntArray(PROXIMITY.length / ROW_SIZE); - static int getIndexOf(int characterCode) { - return computeIndex(characterCode, INDICES); + static { + buildProximityIndices(PROXIMITY, ROW_SIZE, INDICES); } } private static final class Greek { - private static final TreeMap<Integer, Integer> INDICES = CollectionUtils.newTreeMap(); // TODO: The following table is solely based on the keyboard layout. Consult with Greek // speakers on commonly misspelled words/letters. /* @@ -427,12 +411,10 @@ public final class SpellCheckerProximityInfo extends ProximityInfo { NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, }; - static { - buildProximityIndices(PROXIMITY, INDICES); - } + static final SparseIntArray INDICES = new SparseIntArray(PROXIMITY.length / ROW_SIZE); - static int getIndexOf(int characterCode) { - return computeIndex(characterCode, INDICES); + static { + buildProximityIndices(PROXIMITY, ROW_SIZE, INDICES); } } @@ -452,11 +434,11 @@ public final class SpellCheckerProximityInfo extends ProximityInfo { private static int getIndexOfCodeForScript(final int codePoint, final int script) { switch (script) { case AndroidSpellCheckerService.SCRIPT_LATIN: - return Latin.getIndexOf(codePoint); + return Latin.INDICES.get(codePoint, NOT_AN_INDEX); case AndroidSpellCheckerService.SCRIPT_CYRILLIC: - return Cyrillic.getIndexOf(codePoint); + return Cyrillic.INDICES.get(codePoint, NOT_AN_INDEX); case AndroidSpellCheckerService.SCRIPT_GREEK: - return Greek.getIndexOf(codePoint); + return Greek.INDICES.get(codePoint, NOT_AN_INDEX); default: throw new RuntimeException("Wrong script supplied: " + script); } diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java index ed408bb3c..3037669c0 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestions.java @@ -16,12 +16,14 @@ package com.android.inputmethod.latin.suggestions; +import android.content.Context; import android.content.res.Resources; import android.graphics.Paint; import android.graphics.drawable.Drawable; import com.android.inputmethod.keyboard.Key; import com.android.inputmethod.keyboard.Keyboard; +import com.android.inputmethod.keyboard.TypefaceUtils; import com.android.inputmethod.keyboard.internal.KeyboardBuilder; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.keyboard.internal.KeyboardParams; @@ -50,16 +52,12 @@ public final class MoreSuggestions extends Keyboard { super(); } - // TODO: Remove {@link MoreSuggestionsView} argument. public int layout(final SuggestedWords suggestions, final int fromPos, final int maxWidth, - final int minWidth, final int maxRow, final MoreSuggestionsView view) { + final int minWidth, final int maxRow, final Paint paint, final Resources res) { clearKeys(); - final Resources res = view.getResources(); mDivider = res.getDrawable(R.drawable.more_suggestions_divider); mDividerWidth = mDivider.getIntrinsicWidth(); - final int padding = (int) res.getDimension( - R.dimen.more_suggestions_key_horizontal_padding); - final Paint paint = view.newDefaultLabelPaint(); + final float padding = res.getDimension(R.dimen.more_suggestions_key_horizontal_padding); int row = 0; int pos = fromPos, rowStartPos = fromPos; @@ -67,7 +65,7 @@ public final class MoreSuggestions extends Keyboard { while (pos < size) { final String word = suggestions.getWord(pos); // TODO: Should take care of text x-scaling. - mWidths[pos] = (int)view.getLabelWidth(word, paint) + padding; + mWidths[pos] = (int)(TypefaceUtils.getLabelWidth(word, paint) + padding); final int numColumn = pos - rowStartPos + 1; final int columnWidth = (maxWidth - mDividerWidth * (numColumn - 1)) / numColumn; @@ -169,8 +167,8 @@ public final class MoreSuggestions extends Keyboard { private int mFromPos; private int mToPos; - public Builder(final MoreSuggestionsView paneView) { - super(paneView.getContext(), new MoreSuggestionsParam()); + public Builder(final Context context, final MoreSuggestionsView paneView) { + super(context, new MoreSuggestionsParam()); mPaneView = paneView; } @@ -183,7 +181,7 @@ public final class MoreSuggestions extends Keyboard { mPaneView.updateKeyboardGeometry(mParams.mDefaultRowHeight); final int count = mParams.layout(suggestions, fromPos, maxWidth, minWidth, maxRow, - mPaneView); + mPaneView.newLabelPaint(null /* key */), mResources); mFromPos = fromPos; mToPos = fromPos + count; mSuggestions = suggestions; diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java index 438820d17..94715cd84 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java @@ -43,7 +43,7 @@ public final class MoreSuggestionsView extends MoreKeysKeyboardView { } public void updateKeyboardGeometry(final int keyHeight) { - mKeyDrawParams.updateParams(keyHeight, mKeyVisualAttributes); + updateKeyDrawParams(keyHeight); } @Override diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index eeaf828a7..4ef36fa46 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -596,7 +596,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null); mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer .findViewById(R.id.more_suggestions_view); - mMoreSuggestionsBuilder = new MoreSuggestions.Builder(mMoreSuggestionsView); + mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView); final Resources res = context.getResources(); mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset( |