diff options
Diffstat (limited to 'java/src')
8 files changed, 118 insertions, 64 deletions
diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java index 9986f6ec0..ba08c593c 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityEntityProvider.java @@ -85,9 +85,20 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat */ public void setView(KeyboardView keyboardView) { mKeyboardView = keyboardView; + updateParentLocation(); + + // Since this class is constructed lazily, we might not get a subsequent + // call to setKeyboard() and therefore need to call it now. + setKeyboard(mKeyboardView.getKeyboard()); + } + /** + * Sets the keyboard represented by this node provider. + * + * @param keyboard The keyboard to represent. + */ + public void setKeyboard(Keyboard keyboard) { assignVirtualViewIds(); - updateParentLocation(); } /** diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index 59f1eec04..f6376d5f4 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -86,6 +86,12 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat { } } + public void setKeyboard(Keyboard keyboard) { + if (mAccessibilityNodeProvider != null) { + mAccessibilityNodeProvider.setKeyboard(keyboard); + } + } + /** * Proxy method for View.getAccessibilityNodeProvider(). This method is * called in SDK version 15 and higher to obtain the virtual node hierarchy diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index e917a8128..383298de9 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -468,6 +468,10 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinKeyboardView_setKeyboard(keyboard); } + + // This always needs to be set since the accessibility state can + // potentially change without the keyboard being set again. + AccessibleKeyboardViewProxy.getInstance().setKeyboard(keyboard); } /** diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 98cf76cd0..7092b4e7e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -982,7 +982,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView == null || mSuggestionsContainer == null) return; - final int backingHeight = getAdjustedBackingViewHeight(); + final int adjustedBackingHeight = getAdjustedBackingViewHeight(); + final boolean backingGone = (mKeyPreviewBackingView.getVisibility() == View.GONE); + final int backingHeight = backingGone ? 0 : adjustedBackingHeight; // In fullscreen mode, the height of the extract area managed by InputMethodService should // be considered. // See {@link android.inputmethodservice.InputMethodService#onComputeInsets}. diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java index 4994e5902..673b54500 100644 --- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java @@ -20,12 +20,13 @@ import android.content.Context; import com.android.inputmethod.keyboard.ProximityInfo; +import java.util.Locale; + public class SynchronouslyLoadedContactsBinaryDictionary extends ContactsBinaryDictionary { private boolean mClosed; - public SynchronouslyLoadedContactsBinaryDictionary(final Context context) { - // TODO: add locale information. - super(context, Suggest.DIC_CONTACTS, null); + public SynchronouslyLoadedContactsBinaryDictionary(final Context context, final Locale locale) { + super(context, Suggest.DIC_CONTACTS, locale); } @Override @@ -51,4 +52,4 @@ public class SynchronouslyLoadedContactsBinaryDictionary extends ContactsBinaryD mClosed = true; super.close(); } -}
\ No newline at end of file +} diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java index c8ad40b12..a6ff8953d 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryDictionary.java @@ -72,10 +72,10 @@ public class UserHistoryDictionary extends ExpandableDictionary { private static final String FREQ_TABLE_NAME = "frequency"; private static final String FREQ_COLUMN_ID = BaseColumns._ID; private static final String FREQ_COLUMN_PAIR_ID = "pair_id"; - private static final String FREQ_COLUMN_FREQUENCY = "freq"; + private static final String COLUMN_FORGETTING_CURVE_VALUE = "freq"; - /** Locale for which this auto dictionary is storing words */ - private String mLocale; + /** Locale for which this user history dictionary is storing words */ + private final String mLocale; private UserHistoryDictionaryBigramList mBigramList = new UserHistoryDictionaryBigramList(); @@ -94,7 +94,7 @@ public class UserHistoryDictionary extends ExpandableDictionary { sDictProjectionMap.put(FREQ_COLUMN_ID, FREQ_COLUMN_ID); sDictProjectionMap.put(FREQ_COLUMN_PAIR_ID, FREQ_COLUMN_PAIR_ID); - sDictProjectionMap.put(FREQ_COLUMN_FREQUENCY, FREQ_COLUMN_FREQUENCY); + sDictProjectionMap.put(COLUMN_FORGETTING_CURVE_VALUE, COLUMN_FORGETTING_CURVE_VALUE); } private static DatabaseHelper sOpenHelper = null; @@ -214,25 +214,26 @@ public class UserHistoryDictionary extends ExpandableDictionary { if (cursor.moveToFirst()) { final int word1Index = cursor.getColumnIndex(MAIN_COLUMN_WORD1); final int word2Index = cursor.getColumnIndex(MAIN_COLUMN_WORD2); - final int frequencyIndex = cursor.getColumnIndex(FREQ_COLUMN_FREQUENCY); + final int fcIndex = cursor.getColumnIndex(COLUMN_FORGETTING_CURVE_VALUE); while (!cursor.isAfterLast()) { final String word1 = cursor.getString(word1Index); final String word2 = cursor.getString(word2Index); - final int frequency = cursor.getInt(frequencyIndex); + final int fc = cursor.getInt(fcIndex); if (DBG_SAVE_RESTORE) { - Log.d(TAG, "--- Load user history: " + word1 + ", " + word2); + Log.d(TAG, "--- Load user history: " + word1 + ", " + word2 + "," + + mLocale + "," + this); } // Safeguard against adding really long words. Stack may overflow due // to recursive lookup if (null == word1) { - super.addWord(word2, null /* shortcut */, frequency); + super.addWord(word2, null /* shortcut */, fc); } else if (word1.length() < BinaryDictionary.MAX_WORD_LENGTH && word2.length() < BinaryDictionary.MAX_WORD_LENGTH) { super.setBigramAndGetFrequency( - word1, word2, new ForgettingCurveParams(frequency, now, last)); + word1, word2, new ForgettingCurveParams(fc, now, last)); } synchronized(mPendingWritesLock) { - mBigramList.addBigram(word1, word2); + mBigramList.addBigram(word1, word2, (byte)fc); } cursor.moveToNext(); } @@ -259,7 +260,8 @@ public class UserHistoryDictionary extends ExpandableDictionary { try { SQLiteDatabase db = sOpenHelper.getReadableDatabase(); Cursor c = qb.query(db, - new String[] { MAIN_COLUMN_WORD1, MAIN_COLUMN_WORD2, FREQ_COLUMN_FREQUENCY }, + new String[] { + MAIN_COLUMN_WORD1, MAIN_COLUMN_WORD2, COLUMN_FORGETTING_CURVE_VALUE }, selection, selectionArgs, null, null, null); return c; } catch (android.database.sqlite.SQLiteCantOpenDatabaseException e) { @@ -290,7 +292,7 @@ public class UserHistoryDictionary extends ExpandableDictionary { db.execSQL("CREATE TABLE " + FREQ_TABLE_NAME + " (" + FREQ_COLUMN_ID + " INTEGER PRIMARY KEY," + FREQ_COLUMN_PAIR_ID + " INTEGER," - + FREQ_COLUMN_FREQUENCY + " INTEGER," + + COLUMN_FORGETTING_CURVE_VALUE + " INTEGER," + "FOREIGN KEY(" + FREQ_COLUMN_PAIR_ID + ") REFERENCES " + MAIN_TABLE_NAME + "(" + MAIN_COLUMN_ID + ")" + " ON DELETE CASCADE" + ");"); @@ -378,10 +380,40 @@ public class UserHistoryDictionary extends ExpandableDictionary { // Write all the entries to the db for (String word1 : mBigramList.keySet()) { - for (String word2 : mBigramList.getBigrams(word1)) { + final HashMap<String, Byte> word1Bigrams = mBigramList.getBigrams(word1); + for (String word2 : word1Bigrams.keySet()) { + // Get new frequency. Do not insert shortcuts/bigrams which freq is "-1". + final int freq; // -1, or 0~255 + if (word1 == null) { + freq = FREQUENCY_FOR_TYPED; + } else { + final NextWord nw = mUserHistoryDictionary.getBigramWord(word1, word2); + if (nw != null) { + final ForgettingCurveParams fcp = nw.getFcParams(); + final byte prevFc = word1Bigrams.get(word2); + final byte fc = (byte)fcp.getFc(); + final boolean isValid = fcp.isValid(); + if (prevFc > 0 && prevFc == fc) { + // No need to update since we found no changes for this entry. + // Just skip to the next entry. + if (DBG_SAVE_RESTORE) { + Log.d(TAG, "Skip update user history: " + word1 + "," + word2 + + "," + prevFc); + } + continue; + } else if (UserHistoryForgettingCurveUtils. + needsToSave(fc, isValid, addLevel0Bigram)) { + freq = fc; + } else { + freq = -1; + } + } else { + freq = -1; + } + } // TODO: this process of making a text search for each pair each time // is terribly inefficient. Optimize this. - // find pair id + // Find pair id Cursor c = null; try { if (null != word1) { @@ -399,40 +431,22 @@ public class UserHistoryDictionary extends ExpandableDictionary { final int pairId; if (c.moveToFirst()) { - // existing pair + // Delete existing pair pairId = c.getInt(c.getColumnIndex(MAIN_COLUMN_ID)); db.delete(FREQ_TABLE_NAME, FREQ_COLUMN_PAIR_ID + "=?", new String[] { Integer.toString(pairId) }); } else { - // new pair + // Create new pair Long pairIdLong = db.insert(MAIN_TABLE_NAME, null, getContentValues(word1, word2, mLocale)); pairId = pairIdLong.intValue(); } - // insert new frequency - final int freq; - if (word1 == null) { - freq = FREQUENCY_FOR_TYPED; - } else { - final NextWord nw = mUserHistoryDictionary.getBigramWord(word1, word2); - if (nw != null) { - final ForgettingCurveParams fcp = nw.getFcParams(); - final int tempFreq = fcp.getFc(); - final boolean isValid = fcp.isValid(); - if (UserHistoryForgettingCurveUtils.needsToSave( - (byte)tempFreq, isValid, addLevel0Bigram)) { - freq = tempFreq; - } else { - freq = -1; - } - } else { - freq = -1; - } - } if (freq > 0) { if (DBG_SAVE_RESTORE) { - Log.d(TAG, "--- Save user history: " + word1 + ", " + word2); + Log.d(TAG, "--- Save user history: " + word1 + ", " + word2 + + mLocale + "," + this); } + // Insert new frequency db.insert(FREQ_TABLE_NAME, null, getFrequencyContentValues(pairId, freq)); } @@ -461,7 +475,7 @@ public class UserHistoryDictionary extends ExpandableDictionary { private static ContentValues getFrequencyContentValues(int pairId, int frequency) { ContentValues values = new ContentValues(2); values.put(FREQ_COLUMN_PAIR_ID, pairId); - values.put(FREQ_COLUMN_FREQUENCY, frequency); + values.put(COLUMN_FORGETTING_CURVE_VALUE, frequency); return values; } } diff --git a/java/src/com/android/inputmethod/latin/UserHistoryDictionaryBigramList.java b/java/src/com/android/inputmethod/latin/UserHistoryDictionaryBigramList.java index 409f921ff..96400dd48 100644 --- a/java/src/com/android/inputmethod/latin/UserHistoryDictionaryBigramList.java +++ b/java/src/com/android/inputmethod/latin/UserHistoryDictionaryBigramList.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin; import android.util.Log; import java.util.HashMap; -import java.util.HashSet; import java.util.Set; /** @@ -28,10 +27,11 @@ import java.util.Set; * bigrams when we write to the SQL DB. */ public class UserHistoryDictionaryBigramList { + public static final byte FORGETTING_CURVE_INITIAL_VALUE = 0; private static final String TAG = UserHistoryDictionaryBigramList.class.getSimpleName(); - private static final HashSet<String> EMPTY_STRING_SET = new HashSet<String>(); - private final HashMap<String, HashSet<String>> mBigramMap = - new HashMap<String, HashSet<String>>(); + private static final HashMap<String, Byte> EMPTY_BIGRAM_MAP = new HashMap<String, Byte>(); + private final HashMap<String, HashMap<String, Byte>> mBigramMap = + new HashMap<String, HashMap<String, Byte>>(); private int mSize = 0; public void evictAll() { @@ -40,19 +40,23 @@ public class UserHistoryDictionaryBigramList { } public void addBigram(String word1, String word2) { + addBigram(word1, word2, FORGETTING_CURVE_INITIAL_VALUE); + } + + public void addBigram(String word1, String word2, byte fcValue) { if (UserHistoryDictionary.DBG_SAVE_RESTORE) { Log.d(TAG, "--- add bigram: " + word1 + ", " + word2); } - final HashSet<String> set; + final HashMap<String, Byte> map; if (mBigramMap.containsKey(word1)) { - set = mBigramMap.get(word1); + map = mBigramMap.get(word1); } else { - set = new HashSet<String>(); - mBigramMap.put(word1, set); + map = new HashMap<String, Byte>(); + mBigramMap.put(word1, map); } - if (!set.contains(word2)) { + if (!map.containsKey(word2)) { ++mSize; - set.add(word2); + map.put(word2, fcValue); } } @@ -68,20 +72,20 @@ public class UserHistoryDictionaryBigramList { return mBigramMap.keySet(); } - public HashSet<String> getBigrams(String word1) { + public HashMap<String, Byte> getBigrams(String word1) { if (!mBigramMap.containsKey(word1)) { - return EMPTY_STRING_SET; + return EMPTY_BIGRAM_MAP; } else { return mBigramMap.get(word1); } } public boolean removeBigram(String word1, String word2) { - final HashSet<String> set = getBigrams(word1); + final HashMap<String, Byte> set = getBigrams(word1); if (set.isEmpty()) { return false; } - if (set.contains(word2)) { + if (set.containsKey(word2)) { set.remove(word2); --mSize; return true; diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 0e3bf8011..8128779a4 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -99,11 +99,13 @@ public class AndroidSpellCheckerService extends SpellCheckerService // List of the supported languages and their associated script. We won't check // words written in another script than the selected script, because we know we // don't have those in our dictionary so we will underline everything and we - // will never have any suggestions, so it makes no sense checking them. + // will never have any suggestions, so it makes no sense checking them, and this + // is done in {@link #shouldFilterOut}. Also, the script is used to choose which + // proximity to pass to the dictionary descent algorithm. + // IMPORTANT: this only contains languages - do not write countries in there. + // Only the language is searched from the map. mLanguageToScript = new TreeMap<String, Integer>(); mLanguageToScript.put("en", SCRIPT_LATIN); - mLanguageToScript.put("en_US", SCRIPT_LATIN); - mLanguageToScript.put("en_GB", SCRIPT_LATIN); mLanguageToScript.put("fr", SCRIPT_LATIN); mLanguageToScript.put("de", SCRIPT_LATIN); mLanguageToScript.put("nl", SCRIPT_LATIN); @@ -111,7 +113,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService mLanguageToScript.put("es", SCRIPT_LATIN); mLanguageToScript.put("it", SCRIPT_LATIN); mLanguageToScript.put("hr", SCRIPT_LATIN); - mLanguageToScript.put("pt_BR", SCRIPT_LATIN); + mLanguageToScript.put("pt", SCRIPT_LATIN); mLanguageToScript.put("ru", SCRIPT_CYRILLIC); // TODO: Make a persian proximity, and activate the Farsi subtype. // mLanguageToScript.put("fa", SCRIPT_PERSIAN); @@ -152,7 +154,13 @@ public class AndroidSpellCheckerService extends SpellCheckerService private void startUsingContactsDictionaryLocked() { if (null == mContactsDictionary) { - mContactsDictionary = new SynchronouslyLoadedContactsDictionary(this); + if (LatinIME.USE_BINARY_CONTACTS_DICTIONARY) { + // TODO: use the right locale for each session + mContactsDictionary = + new SynchronouslyLoadedContactsBinaryDictionary(this, Locale.getDefault()); + } else { + mContactsDictionary = new SynchronouslyLoadedContactsDictionary(this); + } } final Iterator<WeakReference<DictionaryCollection>> iterator = mDictionaryCollectionsList.iterator(); @@ -430,7 +438,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService // TODO: revert to the concrete type when USE_BINARY_CONTACTS_DICTIONARY is no // longer needed if (LatinIME.USE_BINARY_CONTACTS_DICTIONARY) { - mContactsDictionary = new SynchronouslyLoadedContactsBinaryDictionary(this); + // TODO: use the right locale. We can't do it right now because the + // spell checker is reusing the contacts dictionary across sessions + // without regard for their locale, so we need to fix that first. + mContactsDictionary = new SynchronouslyLoadedContactsBinaryDictionary(this, + Locale.getDefault()); } else { mContactsDictionary = new SynchronouslyLoadedContactsDictionary(this); } |