diff options
Diffstat (limited to 'java')
8 files changed, 48 insertions, 72 deletions
diff --git a/java/AndroidManifest.xml b/java/AndroidManifest.xml index 97f2d891a..654157912 100644 --- a/java/AndroidManifest.xml +++ b/java/AndroidManifest.xml @@ -139,12 +139,6 @@ </intent-filter> </receiver> - <receiver android:name="SuggestionSpanPickedNotificationReceiver" android:enabled="true"> - <intent-filter> - <action android:name="android.text.style.SUGGESTION_PICKED" /> - </intent-filter> - </receiver> - <receiver android:name="com.android.inputmethod.dictionarypack.EventHandler"> <intent-filter> <action android:name="android.intent.action.DOWNLOAD_COMPLETE" /> diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index c38ea0037..4d2925d30 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -26,7 +26,6 @@ import android.text.style.SuggestionSpan; import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; -import com.android.inputmethod.latin.SuggestionSpanPickedNotificationReceiver; import com.android.inputmethod.latin.common.LocaleUtils; import com.android.inputmethod.latin.define.DebugFlags; @@ -65,8 +64,7 @@ public final class SuggestionSpanUtils { final Spannable spannable = new SpannableString(text); // TODO: Set locale if it is feasible. final SuggestionSpan suggestionSpan = new SuggestionSpan(context, null /* locale */, - new String[] {} /* suggestions */, OBJ_FLAG_AUTO_CORRECTION, - SuggestionSpanPickedNotificationReceiver.class); + new String[] {} /* suggestions */, OBJ_FLAG_AUTO_CORRECTION, null); spannable.setSpan(suggestionSpan, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING); return spannable; @@ -96,8 +94,7 @@ public final class SuggestionSpanUtils { } // TODO: Set locale if it is feasible. final SuggestionSpan suggestionSpan = new SuggestionSpan(context, null /* locale */, - suggestionsList.toArray(new String[suggestionsList.size()]), 0 /* flags */, - SuggestionSpanPickedNotificationReceiver.class); + suggestionsList.toArray(new String[suggestionsList.size()]), 0 /* flags */, null); final Spannable spannable = new SpannableString(pickedWord); spannable.setSpan(suggestionSpan, 0, pickedWord.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannable; diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java index 9ea1950f5..8a700d564 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitator.java @@ -170,7 +170,9 @@ public interface DictionaryFacilitator { int getMaxFrequencyOfExactMatches(final String word); void clearUserHistoryDictionary(); - + + String dump(final Context context); + void dumpDictionaryForDebug(final String dictName); ArrayList<Pair<String, DictionaryStats>> getStatsOfEnabledSubDicts(); diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorImpl.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorImpl.java index 763cfa26d..05eec9d61 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorImpl.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorImpl.java @@ -807,4 +807,9 @@ public class DictionaryFacilitatorImpl implements DictionaryFacilitator { } return statsOfEnabledSubDicts; } + + @Override + public String dump(final Context context) { + return ""; + } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index f38b3330f..65a8d667e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1845,6 +1845,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen p.println(" Keyboard mode = " + keyboardMode); final SettingsValues settingsValues = mSettings.getCurrent(); p.println(settingsValues.dump()); + p.println(mDictionaryFacilitator.dump(this /* context */)); // TODO: Dump all settings values } diff --git a/java/src/com/android/inputmethod/latin/NgramContext.java b/java/src/com/android/inputmethod/latin/NgramContext.java index 53bec6e59..c9351586e 100644 --- a/java/src/com/android/inputmethod/latin/NgramContext.java +++ b/java/src/com/android/inputmethod/latin/NgramContext.java @@ -146,6 +146,32 @@ public class NgramContext { : TextUtils.join(CONTEXT_SEPARATOR, terms); } + /** + * Extracts the previous words context. + * + * @return a String array with the previous words. + */ + public String[] extractPrevWordsContextArray() { + final ArrayList<String> prevTermList = new ArrayList<>(); + for (int i = mPrevWordsInfo.length - 1; i >= 0; --i) { + if (mPrevWordsInfo[i] != null && mPrevWordsInfo[i].isValid()) { + final NgramContext.WordInfo wordInfo = mPrevWordsInfo[i]; + if (wordInfo.mIsBeginningOfSentence) { + prevTermList.add(BEGINNING_OF_SENTENCE_TAG); + } else { + final String term = wordInfo.mWord.toString(); + if (!term.isEmpty()) { + prevTermList.add(term); + } + } + } + } + final String[] contextStringArray = prevTermList.size() == 0 ? + new String[] { BEGINNING_OF_SENTENCE_TAG } + : prevTermList.toArray(new String[prevTermList.size()]); + return contextStringArray; + } + public boolean isValid() { return mPrevWordsCount > 0 && mPrevWordsInfo[0].isValid(); } diff --git a/java/src/com/android/inputmethod/latin/SuggestionSpanPickedNotificationReceiver.java b/java/src/com/android/inputmethod/latin/SuggestionSpanPickedNotificationReceiver.java deleted file mode 100644 index 08785f3d9..000000000 --- a/java/src/com/android/inputmethod/latin/SuggestionSpanPickedNotificationReceiver.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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. - */ - -package com.android.inputmethod.latin; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.text.style.SuggestionSpan; -import android.util.Log; - -import com.android.inputmethod.latin.define.DebugFlags; - -public final class SuggestionSpanPickedNotificationReceiver extends BroadcastReceiver { - private static final boolean DBG = DebugFlags.DEBUG_ENABLED; - private static final String TAG = - SuggestionSpanPickedNotificationReceiver.class.getSimpleName(); - - @Override - public void onReceive(Context context, Intent intent) { - if (SuggestionSpan.ACTION_SUGGESTION_PICKED.equals(intent.getAction())) { - if (DBG) { - final String before = intent.getStringExtra( - SuggestionSpan.SUGGESTION_SPAN_PICKED_BEFORE); - final String after = intent.getStringExtra( - SuggestionSpan.SUGGESTION_SPAN_PICKED_AFTER); - Log.d(TAG, "Received notification picked: " + before + "," + after); - } - } - } -} diff --git a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java index 3ed6a021e..fd567f49d 100644 --- a/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/DictionaryInfoUtils.java @@ -340,7 +340,7 @@ public class DictionaryInfoUtils { return getDictionaryFileHeaderOrNull(file, 0, file.length()); } - private static DictionaryHeader getDictionaryFileHeaderOrNull(final File file, + public static DictionaryHeader getDictionaryFileHeaderOrNull(final File file, final long offset, final long length) { try { final DictionaryHeader header = @@ -357,23 +357,17 @@ public class DictionaryInfoUtils { * Returns information of the dictionary. * * @param fileAddress the asset dictionary file address. + * @param locale Locale for this file. * @return information of the specified dictionary. */ @Nullable private static DictionaryInfo createDictionaryInfoFromFileAddress( - final AssetFileAddress fileAddress) { - // TODO: Read the header and update the version number for the new dictionaries. - // This will make sure that the dictionary version is updated in the database. - final DictionaryHeader header = getDictionaryFileHeaderOrNull( - new File(fileAddress.mFilename), fileAddress.mOffset, fileAddress.mLength); - if (header == null) { - return null; - } - final String id = header.mIdString; - final Locale locale = LocaleUtils.constructLocaleFromString(header.mLocaleString); - final String description = header.getDescription(); - final String version = header.mVersionString; - return new DictionaryInfo(id, locale, description, fileAddress, Integer.parseInt(version)); + final AssetFileAddress fileAddress, Locale locale) { + final String id = getMainDictId(locale); + final int version = DictionaryHeaderUtils.getContentVersion(fileAddress); + final String description = SubtypeLocaleUtils + .getSubtypeLocaleDisplayName(locale.toString()); + return new DictionaryInfo(id, locale, description, fileAddress, version); } private static void addOrUpdateDictInfo(final ArrayList<DictionaryInfo> dictList, @@ -410,7 +404,7 @@ public class DictionaryInfoUtils { final Locale locale = LocaleUtils.constructLocaleFromString(localeString); final AssetFileAddress fileAddress = AssetFileAddress.makeFromFile(dict); final DictionaryInfo dictionaryInfo = - createDictionaryInfoFromFileAddress(fileAddress); + createDictionaryInfoFromFileAddress(fileAddress, locale); // Protect against cases of a less-specific dictionary being found, like an // en dictionary being used for an en_US locale. In this case, the en dictionary // should be used for en_US but discounted for listing purposes. @@ -435,7 +429,8 @@ public class DictionaryInfoUtils { } final AssetFileAddress fileAddress = BinaryDictionaryGetter.loadFallbackResource(context, resourceId); - final DictionaryInfo dictionaryInfo = createDictionaryInfoFromFileAddress(fileAddress); + final DictionaryInfo dictionaryInfo = createDictionaryInfoFromFileAddress(fileAddress, + locale); // Protect against cases of a less-specific dictionary being found, like an // en dictionary being used for an en_US locale. In this case, the en dictionary // should be used for en_US but discounted for listing purposes. |