Pending onStartInputView only if the EditorInfo is identical

Bug: 5604372
Change-Id: I2a88cf15b07eebd29e43e460f6ec758432181b01
This commit is contained in:
Tadashi G. Takaoka 2011-11-21 14:58:32 -08:00
parent 19cbdfc92f
commit e7eac906c0
6 changed files with 64 additions and 61 deletions

View file

@ -116,8 +116,8 @@ public class AccessibilityUtils {
* @return {@code true} if the device should not speak text (eg. * @return {@code true} if the device should not speak text (eg.
* non-control) characters * non-control) characters
*/ */
public boolean shouldObscureInput(EditorInfo attribute) { public boolean shouldObscureInput(EditorInfo editorInfo) {
if (attribute == null) if (editorInfo == null)
return false; return false;
// Always speak if the user is listening through headphones. // Always speak if the user is listening through headphones.
@ -125,7 +125,7 @@ public class AccessibilityUtils {
return false; return false;
// Don't speak if the IME is connected to a password field. // Don't speak if the IME is connected to a password field.
return InputTypeCompatUtils.isPasswordInputType(attribute.inputType); return InputTypeCompatUtils.isPasswordInputType(editorInfo.inputType);
} }
/** /**
@ -159,11 +159,11 @@ public class AccessibilityUtils {
* Handles speaking the "connect a headset to hear passwords" notification * Handles speaking the "connect a headset to hear passwords" notification
* when connecting to a password field. * when connecting to a password field.
* *
* @param attribute The input connection's editor info attribute. * @param editorInfo The input connection's editor info attribute.
* @param restarting Whether the connection is being restarted. * @param restarting Whether the connection is being restarted.
*/ */
public void onStartInputViewInternal(EditorInfo attribute, boolean restarting) { public void onStartInputViewInternal(EditorInfo editorInfo, boolean restarting) {
if (shouldObscureInput(attribute)) { if (shouldObscureInput(editorInfo)) {
final CharSequence text = mContext.getText(R.string.spoken_use_headphones); final CharSequence text = mContext.getText(R.string.spoken_use_headphones);
speak(text); speak(text);
} }

View file

@ -695,12 +695,12 @@ public class VoiceProxy implements VoiceInput.UiListener {
&& !mVoiceInput.isBlacklistedField(fieldContext); && !mVoiceInput.isBlacklistedField(fieldContext);
} }
private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo attribute) { private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo editorInfo) {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
final boolean noMic = Utils.inPrivateImeOptions(null, final boolean noMic = Utils.inPrivateImeOptions(null,
LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, attribute) LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)
|| Utils.inPrivateImeOptions(mService.getPackageName(), || Utils.inPrivateImeOptions(mService.getPackageName(),
LatinIME.IME_OPTION_NO_MICROPHONE, attribute); LatinIME.IME_OPTION_NO_MICROPHONE, editorInfo);
return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !noMic return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !noMic
&& SpeechRecognizer.isRecognitionAvailable(mService); && SpeechRecognizer.isRecognitionAvailable(mService);
} }
@ -709,7 +709,7 @@ public class VoiceProxy implements VoiceInput.UiListener {
return SpeechRecognizer.isRecognitionAvailable(context); return SpeechRecognizer.isRecognitionAvailable(context);
} }
public void loadSettings(EditorInfo attribute, SharedPreferences sp) { public void loadSettings(EditorInfo editorInfo, SharedPreferences sp) {
if (!VOICE_INSTALLED) { if (!VOICE_INSTALLED) {
return; return;
} }
@ -723,7 +723,7 @@ public class VoiceProxy implements VoiceInput.UiListener {
final String voiceMode = sp.getString(PREF_VOICE_MODE, final String voiceMode = sp.getString(PREF_VOICE_MODE,
mService.getString(R.string.voice_mode_main)); mService.getString(R.string.voice_mode_main));
mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off)) mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off))
&& shouldShowVoiceButton(makeFieldContext(), attribute); && shouldShowVoiceButton(makeFieldContext(), editorInfo);
mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main)); mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main));
} }

View file

@ -43,10 +43,10 @@ public class FieldContext {
Bundle mFieldInfo; Bundle mFieldInfo;
public FieldContext(InputConnection conn, EditorInfo info, public FieldContext(InputConnection conn, EditorInfo editorInfo,
String selectedLanguage, String[] enabledLanguages) { String selectedLanguage, String[] enabledLanguages) {
mFieldInfo = new Bundle(); mFieldInfo = new Bundle();
addEditorInfoToBundle(info, mFieldInfo); addEditorInfoToBundle(editorInfo, mFieldInfo);
addInputConnectionToBundle(conn, mFieldInfo); addInputConnectionToBundle(conn, mFieldInfo);
addLanguageInfoToBundle(selectedLanguage, enabledLanguages, mFieldInfo); addLanguageInfoToBundle(selectedLanguage, enabledLanguages, mFieldInfo);
if (DBG) Log.i("FieldContext", "Bundle = " + mFieldInfo.toString()); if (DBG) Log.i("FieldContext", "Bundle = " + mFieldInfo.toString());

View file

@ -58,15 +58,15 @@ public class KeyboardId {
public final int mImeAction; public final int mImeAction;
public final String mXmlName; public final String mXmlName;
public final EditorInfo mAttribute; public final EditorInfo mEditorInfo;
private final int mHashCode; private final int mHashCode;
public KeyboardId(String xmlName, int xmlId, Locale locale, int orientation, int width, public KeyboardId(String xmlName, int xmlId, Locale locale, int orientation, int width,
int mode, EditorInfo attribute, boolean hasSettingsKey, int f2KeyMode, int mode, EditorInfo editorInfo, boolean hasSettingsKey, int f2KeyMode,
boolean clobberSettingsKey, boolean shortcutKeyEnabled, boolean hasShortcutKey) { boolean clobberSettingsKey, boolean shortcutKeyEnabled, boolean hasShortcutKey) {
final int inputType = (attribute != null) ? attribute.inputType : 0; final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
final int imeOptions = (attribute != null) ? attribute.imeOptions : 0; final int imeOptions = (editorInfo != null) ? editorInfo.imeOptions : 0;
this.mLocale = locale; this.mLocale = locale;
this.mOrientation = orientation; this.mOrientation = orientation;
this.mWidth = width; this.mWidth = width;
@ -89,7 +89,7 @@ public class KeyboardId {
EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION); EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
this.mXmlName = xmlName; this.mXmlName = xmlName;
this.mAttribute = attribute; this.mEditorInfo = editorInfo;
this.mHashCode = Arrays.hashCode(new Object[] { this.mHashCode = Arrays.hashCode(new Object[] {
locale, locale,
@ -109,7 +109,7 @@ public class KeyboardId {
} }
public KeyboardId cloneWithNewXml(String xmlName, int xmlId) { public KeyboardId cloneWithNewXml(String xmlName, int xmlId) {
return new KeyboardId(xmlName, xmlId, mLocale, mOrientation, mWidth, mMode, mAttribute, return new KeyboardId(xmlName, xmlId, mLocale, mOrientation, mWidth, mMode, mEditorInfo,
false, F2KEY_MODE_NONE, false, false, false); false, F2KEY_MODE_NONE, false, false, false);
} }

View file

@ -409,6 +409,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
private boolean mHasPendingStartInput; private boolean mHasPendingStartInput;
private boolean mHasPendingFinishInputView; private boolean mHasPendingFinishInputView;
private boolean mHasPendingFinishInput; private boolean mHasPendingFinishInput;
private EditorInfo mAppliedEditorInfo;
public void startOrientationChanging() { public void startOrientationChanging() {
removeMessages(MSG_PENDING_IMS_CALLBACK); removeMessages(MSG_PENDING_IMS_CALLBACK);
@ -424,18 +425,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mHasPendingStartInput = false; mHasPendingStartInput = false;
} }
private void executePendingImsCallback(LatinIME latinIme, EditorInfo attribute, private void executePendingImsCallback(LatinIME latinIme, EditorInfo editorInfo,
boolean restarting) { boolean restarting) {
if (mHasPendingFinishInputView) if (mHasPendingFinishInputView)
latinIme.onFinishInputViewInternal(mHasPendingFinishInput); latinIme.onFinishInputViewInternal(mHasPendingFinishInput);
if (mHasPendingFinishInput) if (mHasPendingFinishInput)
latinIme.onFinishInputInternal(); latinIme.onFinishInputInternal();
if (mHasPendingStartInput) if (mHasPendingStartInput)
latinIme.onStartInputInternal(attribute, restarting); latinIme.onStartInputInternal(editorInfo, restarting);
resetPendingImsCallback(); resetPendingImsCallback();
} }
public void onStartInput(EditorInfo attribute, boolean restarting) { public void onStartInput(EditorInfo editorInfo, boolean restarting) {
if (hasMessages(MSG_PENDING_IMS_CALLBACK)) { if (hasMessages(MSG_PENDING_IMS_CALLBACK)) {
// Typically this is the second onStartInput after orientation changed. // Typically this is the second onStartInput after orientation changed.
mHasPendingStartInput = true; mHasPendingStartInput = true;
@ -446,13 +447,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mPendingSuccesiveImsCallback = true; mPendingSuccesiveImsCallback = true;
} }
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOuterInstance();
executePendingImsCallback(latinIme, attribute, restarting); executePendingImsCallback(latinIme, editorInfo, restarting);
latinIme.onStartInputInternal(attribute, restarting); latinIme.onStartInputInternal(editorInfo, restarting);
} }
} }
public void onStartInputView(EditorInfo attribute, boolean restarting) { public void onStartInputView(EditorInfo editorInfo, boolean restarting) {
if (hasMessages(MSG_PENDING_IMS_CALLBACK)) { if (hasMessages(MSG_PENDING_IMS_CALLBACK) && editorInfo == mAppliedEditorInfo) {
// Typically this is the second onStartInputView after orientation changed. // Typically this is the second onStartInputView after orientation changed.
resetPendingImsCallback(); resetPendingImsCallback();
} else { } else {
@ -464,8 +465,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
PENDING_IMS_CALLBACK_DURATION); PENDING_IMS_CALLBACK_DURATION);
} }
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOuterInstance();
executePendingImsCallback(latinIme, attribute, restarting); executePendingImsCallback(latinIme, editorInfo, restarting);
latinIme.onStartInputViewInternal(attribute, restarting); latinIme.onStartInputViewInternal(editorInfo, restarting);
mAppliedEditorInfo = editorInfo;
} }
} }
@ -476,6 +478,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} else { } else {
final LatinIME latinIme = getOuterInstance(); final LatinIME latinIme = getOuterInstance();
latinIme.onFinishInputViewInternal(finishingInput); latinIme.onFinishInputViewInternal(finishingInput);
mAppliedEditorInfo = null;
} }
} }
@ -703,13 +706,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
@Override @Override
public void onStartInput(EditorInfo attribute, boolean restarting) { public void onStartInput(EditorInfo editorInfo, boolean restarting) {
mHandler.onStartInput(attribute, restarting); mHandler.onStartInput(editorInfo, restarting);
} }
@Override @Override
public void onStartInputView(EditorInfo attribute, boolean restarting) { public void onStartInputView(EditorInfo editorInfo, boolean restarting) {
mHandler.onStartInputView(attribute, restarting); mHandler.onStartInputView(editorInfo, restarting);
} }
@Override @Override
@ -722,19 +725,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mHandler.onFinishInput(); mHandler.onFinishInput();
} }
private void onStartInputInternal(EditorInfo attribute, boolean restarting) { private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) {
super.onStartInput(attribute, restarting); super.onStartInput(editorInfo, restarting);
} }
private void onStartInputViewInternal(EditorInfo attribute, boolean restarting) { private void onStartInputViewInternal(EditorInfo editorInfo, boolean restarting) {
super.onStartInputView(attribute, restarting); super.onStartInputView(editorInfo, restarting);
final KeyboardSwitcher switcher = mKeyboardSwitcher; final KeyboardSwitcher switcher = mKeyboardSwitcher;
LatinKeyboardView inputView = switcher.getKeyboardView(); LatinKeyboardView inputView = switcher.getKeyboardView();
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "onStartInputView: attribute:" + ((attribute == null) ? "none" Log.d(TAG, "onStartInputView: editorInfo:" + ((editorInfo == null) ? "none"
: String.format("inputType=0x%08x imeOptions=0x%08x", : String.format("inputType=0x%08x imeOptions=0x%08x",
attribute.inputType, attribute.imeOptions))); editorInfo.inputType, editorInfo.imeOptions)));
} }
// In landscape mode, this method gets called without the input view being created. // In landscape mode, this method gets called without the input view being created.
if (inputView == null) { if (inputView == null) {
@ -744,7 +747,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// Forward this event to the accessibility utilities, if enabled. // Forward this event to the accessibility utilities, if enabled.
final AccessibilityUtils accessUtils = AccessibilityUtils.getInstance(); final AccessibilityUtils accessUtils = AccessibilityUtils.getInstance();
if (accessUtils.isTouchExplorationEnabled()) { if (accessUtils.isTouchExplorationEnabled()) {
accessUtils.onStartInputViewInternal(attribute, restarting); accessUtils.onStartInputViewInternal(editorInfo, restarting);
} }
mSubtypeSwitcher.updateParametersOnStartInputView(); mSubtypeSwitcher.updateParametersOnStartInputView();
@ -755,14 +758,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// know now whether this is a password text field, because we need to know now whether we // know now whether this is a password text field, because we need to know now whether we
// want to enable the voice button. // want to enable the voice button.
final VoiceProxy voiceIme = mVoiceProxy; final VoiceProxy voiceIme = mVoiceProxy;
final int inputType = (attribute != null) ? attribute.inputType : 0; final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
voiceIme.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(inputType) voiceIme.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(inputType)
|| InputTypeCompatUtils.isVisiblePasswordInputType(inputType)); || InputTypeCompatUtils.isVisiblePasswordInputType(inputType));
// The EditorInfo might have a flag that affects fullscreen mode. // The EditorInfo might have a flag that affects fullscreen mode.
// Note: This call should be done by InputMethodService? // Note: This call should be done by InputMethodService?
updateFullscreenMode(); updateFullscreenMode();
initializeInputAttributes(attribute); initializeInputAttributes(editorInfo);
inputView.closing(); inputView.closing();
mEnteredText = null; mEnteredText = null;
@ -778,12 +781,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) { if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) {
mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold);
} }
mVoiceProxy.loadSettings(attribute, mPrefs); mVoiceProxy.loadSettings(editorInfo, mPrefs);
// This will work only when the subtype is not supported. // This will work only when the subtype is not supported.
LanguageSwitcherProxy.loadSettings(); LanguageSwitcherProxy.loadSettings();
if (mSubtypeSwitcher.isKeyboardMode()) { if (mSubtypeSwitcher.isKeyboardMode()) {
switcher.loadKeyboard(attribute, mSettingsValues); switcher.loadKeyboard(editorInfo, mSettingsValues);
} }
if (mSuggestionsView != null) if (mSuggestionsView != null)
@ -803,10 +806,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); if (TRACE) Debug.startMethodTracing("/data/trace/latinime");
} }
private void initializeInputAttributes(EditorInfo attribute) { private void initializeInputAttributes(EditorInfo editorInfo) {
if (attribute == null) if (editorInfo == null)
return; return;
final int inputType = attribute.inputType; final int inputType = editorInfo.inputType;
if (inputType == InputType.TYPE_NULL) { if (inputType == InputType.TYPE_NULL) {
// TODO: We should honor TYPE_NULL specification. // TODO: We should honor TYPE_NULL specification.
Log.i(TAG, "InputType.TYPE_NULL is specified"); Log.i(TAG, "InputType.TYPE_NULL is specified");
@ -815,7 +818,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final int variation = inputType & InputType.TYPE_MASK_VARIATION; final int variation = inputType & InputType.TYPE_MASK_VARIATION;
if (inputClass == 0) { if (inputClass == 0) {
Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x imeOptions=0x%08x", Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x imeOptions=0x%08x",
inputType, attribute.imeOptions)); inputType, editorInfo.imeOptions));
} }
mInsertSpaceOnPickSuggestionManually = false; mInsertSpaceOnPickSuggestionManually = false;

View file

@ -301,9 +301,9 @@ public class Settings extends InputMethodSettingsActivity
return mShowSettingsKey; return mShowSettingsKey;
} }
public boolean isVoiceKeyEnabled(EditorInfo attribute) { public boolean isVoiceKeyEnabled(EditorInfo editorInfo) {
final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled();
final int inputType = (attribute != null) ? attribute.inputType : 0; final int inputType = (editorInfo != null) ? editorInfo.inputType : 0;
return shortcutImeEnabled && mVoiceKeyEnabled return shortcutImeEnabled && mVoiceKeyEnabled
&& !InputTypeCompatUtils.isPasswordInputType(inputType); && !InputTypeCompatUtils.isPasswordInputType(inputType);
} }