am 2cd1136b: Merge "Remove the dialog to insert words to the dictionary."

* commit '2cd1136b8ebedc7cf939d7d7546ed753191f8677':
  Remove the dialog to insert words to the dictionary.
main
Jean Chalard 2013-04-12 05:36:50 -07:00 committed by Android Git Automerger
commit 41e59b6202
3 changed files with 63 additions and 22 deletions

View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2013 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.compat;
import android.content.Context;
import android.provider.UserDictionary.Words;
import java.lang.reflect.Method;
import java.util.Locale;
public final class UserDictionaryCompatUtils {
// UserDictionary.Words#addWord(Context, String, int, String, Locale) was introduced
// in API level 16 (Build.VERSION_CODES.JELLY_BEAN).
private static final Method METHOD_addWord = CompatUtils.getMethod(Words.class, "addWord",
Context.class, String.class, Integer.TYPE, String.class, Locale.class);
public static void addWord(final Context context, final String word, final int freq,
final String shortcut, final Locale locale) {
if (hasNewerAddWord()) {
CompatUtils.invoke(Words.class, null, METHOD_addWord, context, word, freq, shortcut,
locale);
} else {
// Fall back to the pre-JellyBean method.
final int localeType;
if (null == locale) {
localeType = Words.LOCALE_TYPE_ALL;
} else {
localeType = Words.LOCALE_TYPE_CURRENT;
}
Words.addWord(context, word, freq, localeType);
}
}
private static final boolean hasNewerAddWord() {
return null != METHOD_addWord;
}
}

View File

@ -1254,10 +1254,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
} else {
wordToEdit = word;
}
mPositionalInfoForUserDictPendingAddition =
new PositionalInfoForUserDictPendingAddition(
wordToEdit, mLastSelectionEnd, getCurrentInputEditorInfo(),
mLastComposedWord.mCapitalizedMode);
mUserDictionary.addWordToUserDictionary(wordToEdit);
}

View File

@ -20,7 +20,6 @@ import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
@ -28,7 +27,10 @@ import android.os.Build;
import android.provider.UserDictionary.Words;
import android.text.TextUtils;
import com.android.inputmethod.compat.UserDictionaryCompatUtils;
import java.util.Arrays;
import java.util.Locale;
/**
* An expandable dictionary that stores the words in the user dictionary provider into a binary
@ -61,10 +63,6 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
private static final String NAME = "userunigram";
// This is not exported by the framework so we pretty much have to write it here verbatim
private static final String ACTION_USER_DICTIONARY_INSERT =
"com.android.settings.USER_DICTIONARY_INSERT";
private ContentObserver mObserver;
final private String mLocale;
final private boolean mAlsoUseMoreRestrictiveLocales;
@ -211,23 +209,19 @@ public class UserBinaryDictionary extends ExpandableBinaryDictionary {
/**
* Adds a word to the user dictionary and makes it persistent.
*
* This will call upon the system interface to do the actual work through the intent readied by
* the system to this effect.
*
* @param word the word to add. If the word is capitalized, then the dictionary will
* recognize it as a capitalized word when searched.
*/
public synchronized void addWordToUserDictionary(final String word) {
// TODO: do something for the UI. With the following, any sufficiently long word will
// look like it will go to the user dictionary but it won't.
// Safeguard against adding long words. Can cause stack overflow.
if (word.length() >= MAX_WORD_LENGTH) return;
Intent intent = new Intent(ACTION_USER_DICTIONARY_INSERT);
intent.putExtra(Words.WORD, word);
intent.putExtra(Words.LOCALE, mLocale);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
// Update the user dictionary provider
final Locale locale;
if (USER_DICTIONARY_ALL_LANGUAGES == mLocale) {
locale = null;
} else {
locale = LocaleUtils.constructLocaleFromString(mLocale);
}
UserDictionaryCompatUtils.addWord(mContext, word,
HISTORICAL_DEFAULT_USER_DICTIONARY_FREQUENCY, null, locale);
}
private int scaleFrequencyFromDefaultToLatinIme(final int defaultFrequency) {