Merge "Fix privateImeOptions parsing"

This commit is contained in:
Tadashi G. Takaoka 2011-02-23 03:03:19 -08:00 committed by Android (Google) Code Review
commit 435711dee0
4 changed files with 53 additions and 21 deletions

View file

@ -106,7 +106,7 @@ public class InputLanguageSelection extends PreferenceActivity {
conf.locale = locale; conf.locale = locale;
res.updateConfiguration(conf, res.getDisplayMetrics()); res.updateConfiguration(conf, res.getDisplayMetrics());
int mainDicResId = LatinIME.getMainDictionaryResourceId(res); int mainDicResId = Utils.getMainDictionaryResourceId(res);
BinaryDictionary bd = BinaryDictionary.initDictionary(this, mainDicResId, Suggest.DIC_MAIN); BinaryDictionary bd = BinaryDictionary.initDictionary(this, mainDicResId, Suggest.DIC_MAIN);
// Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of // Is the dictionary larger than a placeholder? Arbitrarily chose a lower limit of

View file

@ -81,11 +81,27 @@ import java.util.Locale;
* Input method implementation for Qwerty'ish keyboard. * Input method implementation for Qwerty'ish keyboard.
*/ */
public class LatinIME extends InputMethodService implements KeyboardActionListener { public class LatinIME extends InputMethodService implements KeyboardActionListener {
private static final String TAG = "LatinIME"; private static final String TAG = LatinIME.class.getSimpleName();
private static final boolean PERF_DEBUG = false; private static final boolean PERF_DEBUG = false;
private static final boolean TRACE = false; private static final boolean TRACE = false;
private static boolean DEBUG = LatinImeLogger.sDBG; private static boolean DEBUG = LatinImeLogger.sDBG;
/**
* The private IME option used to indicate that no microphone should be
* shown for a given text field. For instance, this is specified by the
* search dialog when the dialog is already showing a voice search button.
*
* @deprecated Use {@link LatinIME#IME_OPTION_NO_MICROPHONE} with package name prefixed.
*/
public static final String IME_OPTION_NO_MICROPHONE_COMPAT = "nm";
/**
* The private IME option used to indicate that no microphone should be
* shown for a given text field. For instance, this is specified by the
* search dialog when the dialog is already showing a voice search button.
*/
public static final String IME_OPTION_NO_MICROPHONE = "noMicrophone";
private static final int DELAY_UPDATE_SUGGESTIONS = 180; private static final int DELAY_UPDATE_SUGGESTIONS = 180;
private static final int DELAY_UPDATE_OLD_SUGGESTIONS = 300; private static final int DELAY_UPDATE_OLD_SUGGESTIONS = 300;
private static final int DELAY_UPDATE_SHIFT_STATE = 300; private static final int DELAY_UPDATE_SHIFT_STATE = 300;
@ -345,7 +361,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
super.onCreate(); super.onCreate();
mImm = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)); mImm = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
mInputMethodId = Utils.getInputMethodId(mImm, getApplicationInfo().packageName); mInputMethodId = Utils.getInputMethodId(mImm, getPackageName());
mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mKeyboardSwitcher = KeyboardSwitcher.getInstance(); mKeyboardSwitcher = KeyboardSwitcher.getInstance();
@ -394,16 +410,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler); mVoiceConnector = VoiceIMEConnector.init(this, prefs, mHandler);
} }
/**
* Returns a main dictionary resource id
* @return main dictionary resource id
*/
public static int getMainDictionaryResourceId(Resources res) {
final String MAIN_DIC_NAME = "main";
String packageName = LatinIME.class.getPackage().getName();
return res.getIdentifier(MAIN_DIC_NAME, "raw", packageName);
}
private void initSuggest() { private void initSuggest() {
updateAutoTextEnabled(); updateAutoTextEnabled();
String locale = mSubtypeSwitcher.getInputLocaleStr(); String locale = mSubtypeSwitcher.getInputLocaleStr();
@ -416,7 +422,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mQuickFixes = isQuickFixesEnabled(prefs); mQuickFixes = isQuickFixesEnabled(prefs);
final Resources res = mResources; final Resources res = mResources;
int mainDicResId = getMainDictionaryResourceId(res); int mainDicResId = Utils.getMainDictionaryResourceId(res);
mSuggest = new Suggest(this, mainDicResId); mSuggest = new Suggest(this, mainDicResId);
loadAndSetAutoCorrectionThreshold(prefs); loadAndSetAutoCorrectionThreshold(prefs);

View file

@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.keyboard.KeyboardId;
import android.content.res.Resources;
import android.inputmethodservice.InputMethodService; import android.inputmethodservice.InputMethodService;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Handler; import android.os.Handler;
@ -526,4 +527,30 @@ public class Utils {
return variation return variation
== (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); == (InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
} }
public static boolean containsInCsv(String key, String csv) {
if (csv == null)
return false;
for (String option : csv.split(",")) {
if (option.equals(key))
return true;
}
return false;
}
public static boolean inPrivateImeOptions(String packageName, String key,
EditorInfo attribute) {
if (attribute == null)
return false;
return containsInCsv(packageName != null ? packageName + "." + key : key,
attribute.privateImeOptions);
}
/**
* Returns a main dictionary resource id
* @return main dictionary resource id
*/
public static int getMainDictionaryResourceId(Resources res) {
return res.getIdentifier("main", "raw", LatinIME.class.getPackage().getName());
}
} }

View file

@ -25,6 +25,7 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.SharedPreferencesCompat; import com.android.inputmethod.latin.SharedPreferencesCompat;
import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher;
import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.Utils;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
@ -74,10 +75,6 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
// For example, the user has a Chinese UI but activates voice input. // For example, the user has a Chinese UI but activates voice input.
private static final String PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE = private static final String PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE =
"has_used_voice_input_unsupported_locale"; "has_used_voice_input_unsupported_locale";
// The private IME option used to indicate that no microphone should be shown for a
// given text field. For instance this is specified by the search dialog when the
// dialog is already showing a voice search button.
private static final String IME_OPTION_NO_MICROPHONE = "nm";
private static final int RECOGNITIONVIEW_HEIGHT_THRESHOLD_RATIO = 6; private static final int RECOGNITIONVIEW_HEIGHT_THRESHOLD_RATIO = 6;
private static final String TAG = VoiceIMEConnector.class.getSimpleName(); private static final String TAG = VoiceIMEConnector.class.getSimpleName();
@ -627,9 +624,11 @@ public class VoiceIMEConnector implements VoiceInput.UiListener {
} }
private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo attribute) { private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo attribute) {
return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) final boolean noMic = Utils.inPrivateImeOptions(null,
&& !(attribute != null LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, attribute)
&& IME_OPTION_NO_MICROPHONE.equals(attribute.privateImeOptions)) || Utils.inPrivateImeOptions(mService.getPackageName(),
LatinIME.IME_OPTION_NO_MICROPHONE, attribute);
return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !noMic
&& SpeechRecognizer.isRecognitionAvailable(mService); && SpeechRecognizer.isRecognitionAvailable(mService);
} }