From bf9d8348d89be257ccc3db75333bfd4cdf0a9b7e Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sun, 17 Jul 2011 21:18:47 -0700 Subject: Support select input method dialog on pre-HC platform Bug: 4971680 Change-Id: I641b336da54813e13409bd7874aa22e51f790729 --- java/src/com/android/inputmethod/deprecated/VoiceProxy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index 85993ea4d..c82c570ee 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -129,7 +129,7 @@ public class VoiceProxy implements VoiceInput.UiListener { mHandler = h; mMinimumVoiceRecognitionViewHeightPixel = Utils.dipToPixel( Utils.getDipScale(service), RECOGNITIONVIEW_MINIMUM_HEIGHT_DIP); - mImm = InputMethodManagerCompatWrapper.getInstance(service); + mImm = InputMethodManagerCompatWrapper.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); if (VOICE_INSTALLED) { mVoiceInput = new VoiceInput(service, this); -- cgit v1.2.3-83-g751a From 795a712ecf1847251c2da02351e0812a2b5d4bb9 Mon Sep 17 00:00:00 2001 From: satok Date: Thu, 21 Jul 2011 14:57:28 +0900 Subject: Guard unused voice functions Bug: 4985273 Change-Id: I9491b4af24e636cba6362cdde44568d14f7b2b85 --- .../android/inputmethod/deprecated/VoiceProxy.java | 125 +++++++++++---------- .../com/android/inputmethod/latin/LatinIME.java | 21 ++-- .../com/android/inputmethod/latin/Settings.java | 15 +-- 3 files changed, 82 insertions(+), 79 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index c82c570ee..28646214b 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -17,11 +17,11 @@ package com.android.inputmethod.deprecated; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.deprecated.voice.FieldContext; import com.android.inputmethod.deprecated.voice.Hints; import com.android.inputmethod.deprecated.voice.SettingsUtil; import com.android.inputmethod.deprecated.voice.VoiceInput; -import com.android.inputmethod.deprecated.voice.VoiceInputLogger; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.EditingUtils; import com.android.inputmethod.latin.LatinIME; @@ -71,7 +71,8 @@ import java.util.Map; public class VoiceProxy implements VoiceInput.UiListener { private static final VoiceProxy sInstance = new VoiceProxy(); - public static final boolean VOICE_INSTALLED = true; + public static final boolean VOICE_INSTALLED = + !InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED; private static final boolean ENABLE_VOICE_BUTTON = true; private static final String PREF_VOICE_MODE = "voice_mode"; // Whether or not the user has used voice input before (and thus, whether to show the @@ -125,24 +126,23 @@ public class VoiceProxy implements VoiceInput.UiListener { } private void initInternal(LatinIME service, SharedPreferences prefs, UIHandler h) { + if (!VOICE_INSTALLED) { + return; + } mService = service; mHandler = h; mMinimumVoiceRecognitionViewHeightPixel = Utils.dipToPixel( Utils.getDipScale(service), RECOGNITIONVIEW_MINIMUM_HEIGHT_DIP); mImm = InputMethodManagerCompatWrapper.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); - if (VOICE_INSTALLED) { - mVoiceInput = new VoiceInput(service, this); - mHints = new Hints(service, prefs, new Hints.Display() { - @Override - public void showHint(int viewResource) { - View view = LayoutInflater.from(mService).inflate(viewResource, null); -// mService.setCandidatesView(view); -// mService.setCandidatesViewShown(true); - mIsShowingHint = true; - } - }); - } + mVoiceInput = new VoiceInput(service, this); + mHints = new Hints(service, prefs, new Hints.Display() { + @Override + public void showHint(int viewResource) { + View view = LayoutInflater.from(mService).inflate(viewResource, null); + mIsShowingHint = true; + } + }); } private VoiceProxy() { @@ -170,6 +170,9 @@ public class VoiceProxy implements VoiceInput.UiListener { public void flushAndLogAllTextModificationCounters(int index, CharSequence suggestion, String wordSeparators) { + if (!VOICE_INSTALLED) { + return; + } if (mAfterVoiceInput && mShowingVoiceSuggestions) { mVoiceInput.flushAllTextModificationCounters(); // send this intent AFTER logging any prior aggregated edits. @@ -308,6 +311,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void hideVoiceWindow(boolean configurationChanging) { + if (!VOICE_INSTALLED) { + return; + } if (!configurationChanging) { if (mAfterVoiceInput) mVoiceInput.logInputEnded(); @@ -324,6 +330,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void setCursorAndSelection(int newSelEnd, int newSelStart) { + if (!VOICE_INSTALLED) { + return; + } if (mAfterVoiceInput) { mVoiceInput.setCursorPos(newSelEnd); mVoiceInput.setSelectionSpan(newSelEnd - newSelStart); @@ -366,6 +375,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } private void revertVoiceInput() { + if (!VOICE_INSTALLED) { + return; + } InputConnection ic = mService.getCurrentInputConnection(); if (ic != null) ic.commitText("", 1); mService.updateSuggestions(); @@ -393,6 +405,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void rememberReplacedWord(CharSequence suggestion,String wordSeparators) { + if (!VOICE_INSTALLED) { + return; + } if (mShowingVoiceSuggestions) { // Retain the replaced word in the alternatives array. String wordToBeReplaced = EditingUtils.getWordAtCursor( @@ -419,6 +434,9 @@ public class VoiceProxy implements VoiceInput.UiListener { * @return true if an alternative was found, false otherwise. */ public boolean applyVoiceAlternatives(EditingUtils.SelectedWord touching) { + if (!VOICE_INSTALLED) { + return false; + } // Search for result in spoken word alternatives String selectedWord = touching.mWord.toString().trim(); if (!mWordToSuggestions.containsKey(selectedWord)) { @@ -448,6 +466,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleBackspace() { + if (!VOICE_INSTALLED) { + return; + } if (mAfterVoiceInput) { // Don't log delete if the user is pressing delete at // the beginning of the text box (hence not deleting anything) @@ -462,6 +483,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleCharacter() { + if (!VOICE_INSTALLED) { + return; + } commitVoiceInput(); if (mAfterVoiceInput) { // Assume input length is 1. This assumption fails for smiley face insertions. @@ -470,6 +494,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleSeparator() { + if (!VOICE_INSTALLED) { + return; + } commitVoiceInput(); if (mAfterVoiceInput){ // Assume input length is 1. This assumption fails for smiley face insertions. @@ -485,6 +512,9 @@ public class VoiceProxy implements VoiceInput.UiListener { public void handleVoiceResults(boolean capitalizeFirstWord) { + if (!VOICE_INSTALLED) { + return; + } mAfterVoiceInput = true; mImmediatelyAfterVoiceInput = true; @@ -660,6 +690,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void loadSettings(EditorInfo attribute, SharedPreferences sp) { + if (!VOICE_INSTALLED) { + return; + } mHasUsedVoiceInput = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT, false); mHasUsedVoiceInputUnsupportedLocale = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false); @@ -683,6 +716,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void onStartInputView(IBinder keyboardViewToken) { + if (!VOICE_INSTALLED) { + return; + } // If keyboardViewToken is null, keyboardView is not attached but voiceView is attached. IBinder windowToken = keyboardViewToken != null ? keyboardViewToken : mVoiceInput.getView().getWindowToken(); @@ -699,12 +735,18 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void onAttachedToWindow() { + if (!VOICE_INSTALLED) { + return; + } // After onAttachedToWindow, we can show the voice warning dialog. See startListening() // above. VoiceInputWrapper.getInstance().setVoiceInput(mVoiceInput, mSubtypeSwitcher); } public void onConfigurationChanged(Configuration configuration) { + if (!VOICE_INSTALLED) { + return; + } if (mRecognizing) { switchToRecognitionStatusView(configuration); } @@ -712,6 +754,9 @@ public class VoiceProxy implements VoiceInput.UiListener { @Override public void onCancelVoice() { + if (!VOICE_INSTALLED) { + return; + } if (mRecognizing) { if (mSubtypeSwitcher.isVoiceMode()) { // If voice mode is being canceled within LatinIME (i.e. time-out or user @@ -733,6 +778,9 @@ public class VoiceProxy implements VoiceInput.UiListener { @Override public void onVoiceResults(List candidates, Map> alternatives) { + if (!VOICE_INSTALLED) { + return; + } if (!mRecognizing) { return; } @@ -748,59 +796,22 @@ public class VoiceProxy implements VoiceInput.UiListener { switcher.getEnabledLanguages()); } - private class VoiceResults { + // TODO: make this private (proguard issue) + public static class VoiceResults { List candidates; Map> alternatives; } - public static class VoiceLoggerWrapper { - private static final VoiceLoggerWrapper sLoggerWrapperInstance = new VoiceLoggerWrapper(); - private VoiceInputLogger mLogger; - - public static VoiceLoggerWrapper getInstance(Context context) { - if (sLoggerWrapperInstance.mLogger == null) { - // Not thread safe, but it's ok. - sLoggerWrapperInstance.mLogger = VoiceInputLogger.getLogger(context); - } - return sLoggerWrapperInstance; - } - - // private for the singleton - private VoiceLoggerWrapper() { - } - - public void settingsWarningDialogCancel() { - mLogger.settingsWarningDialogCancel(); - } - - public void settingsWarningDialogOk() { - mLogger.settingsWarningDialogOk(); - } - - public void settingsWarningDialogShown() { - mLogger.settingsWarningDialogShown(); - } - - public void settingsWarningDialogDismissed() { - mLogger.settingsWarningDialogDismissed(); - } - - public void voiceInputSettingEnabled(boolean enabled) { - if (enabled) { - mLogger.voiceInputSettingEnabled(); - } else { - mLogger.voiceInputSettingDisabled(); - } - } - } - public static class VoiceInputWrapper { private static final VoiceInputWrapper sInputWrapperInstance = new VoiceInputWrapper(); private VoiceInput mVoiceInput; public static VoiceInputWrapper getInstance() { return sInputWrapperInstance; } - public void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) { + private void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) { + if (!VOICE_INSTALLED) { + return; + } if (mVoiceInput == null && voiceInput != null) { mVoiceInput = voiceInput; } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5d8fd3411..e5d2f7578 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -542,12 +542,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar TextEntryState.reset(); - // Most such things we decide below in initializeInputAttributesAndGetMode, but we need to - // know now whether this is a password text field, because we need to know now whether we - // want to enable the voice button. - final VoiceProxy voiceIme = mVoiceProxy; - voiceIme.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(attribute.inputType) - || InputTypeCompatUtils.isVisiblePasswordInputType(attribute.inputType)); + if (attribute != null) { + // Most such things we decide below in initializeInputAttributesAndGetMode, but we need + // to know now whether this is a password text field, because we need to know now + // whether we want to enable the voice button. + mVoiceProxy.resetVoiceStates( + InputTypeCompatUtils.isPasswordInputType(attribute.inputType) + || InputTypeCompatUtils.isVisiblePasswordInputType( + attribute.inputType)); + } initializeInputAttributes(attribute); @@ -573,8 +576,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (mSubtypeSwitcher.isKeyboardMode()) { switcher.loadKeyboard(attribute, - mSubtypeSwitcher.isShortcutImeEnabled() && voiceIme.isVoiceButtonEnabled(), - voiceIme.isVoiceButtonOnPrimary()); + mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceProxy.isVoiceButtonEnabled(), + mVoiceProxy.isVoiceButtonOnPrimary()); switcher.updateShiftState(); } @@ -592,7 +595,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // If we just entered a text field, maybe it has some old text that requires correction mRecorrection.checkRecorrectionOnStart(); - voiceIme.onStartInputView(inputView.getWindowToken()); + mVoiceProxy.onStartInputView(inputView.getWindowToken()); if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); } diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 54f0a1b4d..e665ee2f5 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -304,8 +304,6 @@ public class Settings extends InputMethodSettingsActivity private AlertDialog mDialog; - private VoiceProxy.VoiceLoggerWrapper mVoiceLogger; - private boolean mOkClicked = false; private String mVoiceModeOff; @@ -349,7 +347,6 @@ public class Settings extends InputMethodSettingsActivity mVoiceModeOff = getString(R.string.voice_mode_off); mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff) .equals(mVoiceModeOff)); - mVoiceLogger = VoiceProxy.VoiceLoggerWrapper.getInstance(context); mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD); mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS); @@ -447,6 +444,7 @@ public class Settings extends InputMethodSettingsActivity } } + @SuppressWarnings("unused") @Override public void onResume() { super.onResume(); @@ -541,6 +539,7 @@ public class Settings extends InputMethodSettingsActivity [mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]); } + @Override protected Dialog onCreateDialog(int id) { switch (id) { case VOICE_INPUT_CONFIRM_DIALOG: @@ -549,12 +548,9 @@ public class Settings extends InputMethodSettingsActivity public void onClick(DialogInterface dialog, int whichButton) { if (whichButton == DialogInterface.BUTTON_NEGATIVE) { mVoicePreference.setValue(mVoiceModeOff); - mVoiceLogger.settingsWarningDialogCancel(); } else if (whichButton == DialogInterface.BUTTON_POSITIVE) { mOkClicked = true; - mVoiceLogger.settingsWarningDialogOk(); } - updateVoicePreference(); } }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivityInternal()) @@ -583,7 +579,6 @@ public class Settings extends InputMethodSettingsActivity AlertDialog dialog = builder.create(); mDialog = dialog; dialog.setOnDismissListener(this); - mVoiceLogger.settingsWarningDialogShown(); return dialog; default: Log.e(TAG, "unknown dialog " + id); @@ -593,16 +588,10 @@ public class Settings extends InputMethodSettingsActivity @Override public void onDismiss(DialogInterface dialog) { - mVoiceLogger.settingsWarningDialogDismissed(); if (!mOkClicked) { // This assumes that onPreferenceClick gets called first, and this if the user // agreed after the warning, we set the mOkClicked value to true. mVoicePreference.setValue(mVoiceModeOff); } } - - private void updateVoicePreference() { - boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff); - mVoiceLogger.voiceInputSettingEnabled(isChecked); - } } -- cgit v1.2.3-83-g751a From 055265684bdc049db54c3ec2a7fa5404ff36a608 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 21 Jul 2011 02:18:35 -0700 Subject: Revert "Guard unused voice functions" This reverts commit 795a712ecf1847251c2da02351e0812a2b5d4bb9. Bug: 4985273 --- .../android/inputmethod/deprecated/VoiceProxy.java | 125 ++++++++++----------- .../com/android/inputmethod/latin/LatinIME.java | 21 ++-- .../com/android/inputmethod/latin/Settings.java | 15 ++- 3 files changed, 79 insertions(+), 82 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index 28646214b..c82c570ee 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -17,11 +17,11 @@ package com.android.inputmethod.deprecated; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; -import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.deprecated.voice.FieldContext; import com.android.inputmethod.deprecated.voice.Hints; import com.android.inputmethod.deprecated.voice.SettingsUtil; import com.android.inputmethod.deprecated.voice.VoiceInput; +import com.android.inputmethod.deprecated.voice.VoiceInputLogger; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.EditingUtils; import com.android.inputmethod.latin.LatinIME; @@ -71,8 +71,7 @@ import java.util.Map; public class VoiceProxy implements VoiceInput.UiListener { private static final VoiceProxy sInstance = new VoiceProxy(); - public static final boolean VOICE_INSTALLED = - !InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED; + public static final boolean VOICE_INSTALLED = true; private static final boolean ENABLE_VOICE_BUTTON = true; private static final String PREF_VOICE_MODE = "voice_mode"; // Whether or not the user has used voice input before (and thus, whether to show the @@ -126,23 +125,24 @@ public class VoiceProxy implements VoiceInput.UiListener { } private void initInternal(LatinIME service, SharedPreferences prefs, UIHandler h) { - if (!VOICE_INSTALLED) { - return; - } mService = service; mHandler = h; mMinimumVoiceRecognitionViewHeightPixel = Utils.dipToPixel( Utils.getDipScale(service), RECOGNITIONVIEW_MINIMUM_HEIGHT_DIP); mImm = InputMethodManagerCompatWrapper.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); - mVoiceInput = new VoiceInput(service, this); - mHints = new Hints(service, prefs, new Hints.Display() { - @Override - public void showHint(int viewResource) { - View view = LayoutInflater.from(mService).inflate(viewResource, null); - mIsShowingHint = true; - } - }); + if (VOICE_INSTALLED) { + mVoiceInput = new VoiceInput(service, this); + mHints = new Hints(service, prefs, new Hints.Display() { + @Override + public void showHint(int viewResource) { + View view = LayoutInflater.from(mService).inflate(viewResource, null); +// mService.setCandidatesView(view); +// mService.setCandidatesViewShown(true); + mIsShowingHint = true; + } + }); + } } private VoiceProxy() { @@ -170,9 +170,6 @@ public class VoiceProxy implements VoiceInput.UiListener { public void flushAndLogAllTextModificationCounters(int index, CharSequence suggestion, String wordSeparators) { - if (!VOICE_INSTALLED) { - return; - } if (mAfterVoiceInput && mShowingVoiceSuggestions) { mVoiceInput.flushAllTextModificationCounters(); // send this intent AFTER logging any prior aggregated edits. @@ -311,9 +308,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void hideVoiceWindow(boolean configurationChanging) { - if (!VOICE_INSTALLED) { - return; - } if (!configurationChanging) { if (mAfterVoiceInput) mVoiceInput.logInputEnded(); @@ -330,9 +324,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void setCursorAndSelection(int newSelEnd, int newSelStart) { - if (!VOICE_INSTALLED) { - return; - } if (mAfterVoiceInput) { mVoiceInput.setCursorPos(newSelEnd); mVoiceInput.setSelectionSpan(newSelEnd - newSelStart); @@ -375,9 +366,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } private void revertVoiceInput() { - if (!VOICE_INSTALLED) { - return; - } InputConnection ic = mService.getCurrentInputConnection(); if (ic != null) ic.commitText("", 1); mService.updateSuggestions(); @@ -405,9 +393,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void rememberReplacedWord(CharSequence suggestion,String wordSeparators) { - if (!VOICE_INSTALLED) { - return; - } if (mShowingVoiceSuggestions) { // Retain the replaced word in the alternatives array. String wordToBeReplaced = EditingUtils.getWordAtCursor( @@ -434,9 +419,6 @@ public class VoiceProxy implements VoiceInput.UiListener { * @return true if an alternative was found, false otherwise. */ public boolean applyVoiceAlternatives(EditingUtils.SelectedWord touching) { - if (!VOICE_INSTALLED) { - return false; - } // Search for result in spoken word alternatives String selectedWord = touching.mWord.toString().trim(); if (!mWordToSuggestions.containsKey(selectedWord)) { @@ -466,9 +448,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleBackspace() { - if (!VOICE_INSTALLED) { - return; - } if (mAfterVoiceInput) { // Don't log delete if the user is pressing delete at // the beginning of the text box (hence not deleting anything) @@ -483,9 +462,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleCharacter() { - if (!VOICE_INSTALLED) { - return; - } commitVoiceInput(); if (mAfterVoiceInput) { // Assume input length is 1. This assumption fails for smiley face insertions. @@ -494,9 +470,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleSeparator() { - if (!VOICE_INSTALLED) { - return; - } commitVoiceInput(); if (mAfterVoiceInput){ // Assume input length is 1. This assumption fails for smiley face insertions. @@ -512,9 +485,6 @@ public class VoiceProxy implements VoiceInput.UiListener { public void handleVoiceResults(boolean capitalizeFirstWord) { - if (!VOICE_INSTALLED) { - return; - } mAfterVoiceInput = true; mImmediatelyAfterVoiceInput = true; @@ -690,9 +660,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void loadSettings(EditorInfo attribute, SharedPreferences sp) { - if (!VOICE_INSTALLED) { - return; - } mHasUsedVoiceInput = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT, false); mHasUsedVoiceInputUnsupportedLocale = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false); @@ -716,9 +683,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void onStartInputView(IBinder keyboardViewToken) { - if (!VOICE_INSTALLED) { - return; - } // If keyboardViewToken is null, keyboardView is not attached but voiceView is attached. IBinder windowToken = keyboardViewToken != null ? keyboardViewToken : mVoiceInput.getView().getWindowToken(); @@ -735,18 +699,12 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void onAttachedToWindow() { - if (!VOICE_INSTALLED) { - return; - } // After onAttachedToWindow, we can show the voice warning dialog. See startListening() // above. VoiceInputWrapper.getInstance().setVoiceInput(mVoiceInput, mSubtypeSwitcher); } public void onConfigurationChanged(Configuration configuration) { - if (!VOICE_INSTALLED) { - return; - } if (mRecognizing) { switchToRecognitionStatusView(configuration); } @@ -754,9 +712,6 @@ public class VoiceProxy implements VoiceInput.UiListener { @Override public void onCancelVoice() { - if (!VOICE_INSTALLED) { - return; - } if (mRecognizing) { if (mSubtypeSwitcher.isVoiceMode()) { // If voice mode is being canceled within LatinIME (i.e. time-out or user @@ -778,9 +733,6 @@ public class VoiceProxy implements VoiceInput.UiListener { @Override public void onVoiceResults(List candidates, Map> alternatives) { - if (!VOICE_INSTALLED) { - return; - } if (!mRecognizing) { return; } @@ -796,22 +748,59 @@ public class VoiceProxy implements VoiceInput.UiListener { switcher.getEnabledLanguages()); } - // TODO: make this private (proguard issue) - public static class VoiceResults { + private class VoiceResults { List candidates; Map> alternatives; } + public static class VoiceLoggerWrapper { + private static final VoiceLoggerWrapper sLoggerWrapperInstance = new VoiceLoggerWrapper(); + private VoiceInputLogger mLogger; + + public static VoiceLoggerWrapper getInstance(Context context) { + if (sLoggerWrapperInstance.mLogger == null) { + // Not thread safe, but it's ok. + sLoggerWrapperInstance.mLogger = VoiceInputLogger.getLogger(context); + } + return sLoggerWrapperInstance; + } + + // private for the singleton + private VoiceLoggerWrapper() { + } + + public void settingsWarningDialogCancel() { + mLogger.settingsWarningDialogCancel(); + } + + public void settingsWarningDialogOk() { + mLogger.settingsWarningDialogOk(); + } + + public void settingsWarningDialogShown() { + mLogger.settingsWarningDialogShown(); + } + + public void settingsWarningDialogDismissed() { + mLogger.settingsWarningDialogDismissed(); + } + + public void voiceInputSettingEnabled(boolean enabled) { + if (enabled) { + mLogger.voiceInputSettingEnabled(); + } else { + mLogger.voiceInputSettingDisabled(); + } + } + } + public static class VoiceInputWrapper { private static final VoiceInputWrapper sInputWrapperInstance = new VoiceInputWrapper(); private VoiceInput mVoiceInput; public static VoiceInputWrapper getInstance() { return sInputWrapperInstance; } - private void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) { - if (!VOICE_INSTALLED) { - return; - } + public void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) { if (mVoiceInput == null && voiceInput != null) { mVoiceInput = voiceInput; } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index e5d2f7578..5d8fd3411 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -542,15 +542,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar TextEntryState.reset(); - if (attribute != null) { - // Most such things we decide below in initializeInputAttributesAndGetMode, but we need - // to know now whether this is a password text field, because we need to know now - // whether we want to enable the voice button. - mVoiceProxy.resetVoiceStates( - InputTypeCompatUtils.isPasswordInputType(attribute.inputType) - || InputTypeCompatUtils.isVisiblePasswordInputType( - attribute.inputType)); - } + // Most such things we decide below in initializeInputAttributesAndGetMode, but we need to + // know now whether this is a password text field, because we need to know now whether we + // want to enable the voice button. + final VoiceProxy voiceIme = mVoiceProxy; + voiceIme.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(attribute.inputType) + || InputTypeCompatUtils.isVisiblePasswordInputType(attribute.inputType)); initializeInputAttributes(attribute); @@ -576,8 +573,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (mSubtypeSwitcher.isKeyboardMode()) { switcher.loadKeyboard(attribute, - mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceProxy.isVoiceButtonEnabled(), - mVoiceProxy.isVoiceButtonOnPrimary()); + mSubtypeSwitcher.isShortcutImeEnabled() && voiceIme.isVoiceButtonEnabled(), + voiceIme.isVoiceButtonOnPrimary()); switcher.updateShiftState(); } @@ -595,7 +592,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // If we just entered a text field, maybe it has some old text that requires correction mRecorrection.checkRecorrectionOnStart(); - mVoiceProxy.onStartInputView(inputView.getWindowToken()); + voiceIme.onStartInputView(inputView.getWindowToken()); if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); } diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index e665ee2f5..54f0a1b4d 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -304,6 +304,8 @@ public class Settings extends InputMethodSettingsActivity private AlertDialog mDialog; + private VoiceProxy.VoiceLoggerWrapper mVoiceLogger; + private boolean mOkClicked = false; private String mVoiceModeOff; @@ -347,6 +349,7 @@ public class Settings extends InputMethodSettingsActivity mVoiceModeOff = getString(R.string.voice_mode_off); mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff) .equals(mVoiceModeOff)); + mVoiceLogger = VoiceProxy.VoiceLoggerWrapper.getInstance(context); mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD); mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS); @@ -444,7 +447,6 @@ public class Settings extends InputMethodSettingsActivity } } - @SuppressWarnings("unused") @Override public void onResume() { super.onResume(); @@ -539,7 +541,6 @@ public class Settings extends InputMethodSettingsActivity [mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]); } - @Override protected Dialog onCreateDialog(int id) { switch (id) { case VOICE_INPUT_CONFIRM_DIALOG: @@ -548,9 +549,12 @@ public class Settings extends InputMethodSettingsActivity public void onClick(DialogInterface dialog, int whichButton) { if (whichButton == DialogInterface.BUTTON_NEGATIVE) { mVoicePreference.setValue(mVoiceModeOff); + mVoiceLogger.settingsWarningDialogCancel(); } else if (whichButton == DialogInterface.BUTTON_POSITIVE) { mOkClicked = true; + mVoiceLogger.settingsWarningDialogOk(); } + updateVoicePreference(); } }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivityInternal()) @@ -579,6 +583,7 @@ public class Settings extends InputMethodSettingsActivity AlertDialog dialog = builder.create(); mDialog = dialog; dialog.setOnDismissListener(this); + mVoiceLogger.settingsWarningDialogShown(); return dialog; default: Log.e(TAG, "unknown dialog " + id); @@ -588,10 +593,16 @@ public class Settings extends InputMethodSettingsActivity @Override public void onDismiss(DialogInterface dialog) { + mVoiceLogger.settingsWarningDialogDismissed(); if (!mOkClicked) { // This assumes that onPreferenceClick gets called first, and this if the user // agreed after the warning, we set the mOkClicked value to true. mVoicePreference.setValue(mVoiceModeOff); } } + + private void updateVoicePreference() { + boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff); + mVoiceLogger.voiceInputSettingEnabled(isChecked); + } } -- cgit v1.2.3-83-g751a From 255486a5d067469e074f3649b3d2747e7a08aaa2 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 21 Jul 2011 14:57:28 +0900 Subject: Disable VoiceInputLogger inside LatinIME Bug: 4985273 Change-Id: I6c70e50a58be0973f78c6a1abc1fb4eac5449c0b --- .../android/inputmethod/deprecated/VoiceProxy.java | 129 ++++++++++++--------- .../inputmethod/keyboard/KeyboardSwitcher.java | 6 +- .../com/android/inputmethod/latin/LatinIME.java | 8 +- .../com/android/inputmethod/latin/Settings.java | 62 ++++++---- 4 files changed, 114 insertions(+), 91 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index c82c570ee..b8a8169bc 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -17,11 +17,11 @@ package com.android.inputmethod.deprecated; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.deprecated.voice.FieldContext; import com.android.inputmethod.deprecated.voice.Hints; import com.android.inputmethod.deprecated.voice.SettingsUtil; import com.android.inputmethod.deprecated.voice.VoiceInput; -import com.android.inputmethod.deprecated.voice.VoiceInputLogger; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.EditingUtils; import com.android.inputmethod.latin.LatinIME; @@ -71,7 +71,8 @@ import java.util.Map; public class VoiceProxy implements VoiceInput.UiListener { private static final VoiceProxy sInstance = new VoiceProxy(); - public static final boolean VOICE_INSTALLED = true; + public static final boolean VOICE_INSTALLED = + !InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED; private static final boolean ENABLE_VOICE_BUTTON = true; private static final String PREF_VOICE_MODE = "voice_mode"; // Whether or not the user has used voice input before (and thus, whether to show the @@ -125,24 +126,23 @@ public class VoiceProxy implements VoiceInput.UiListener { } private void initInternal(LatinIME service, SharedPreferences prefs, UIHandler h) { + if (!VOICE_INSTALLED) { + return; + } mService = service; mHandler = h; mMinimumVoiceRecognitionViewHeightPixel = Utils.dipToPixel( Utils.getDipScale(service), RECOGNITIONVIEW_MINIMUM_HEIGHT_DIP); mImm = InputMethodManagerCompatWrapper.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance(); - if (VOICE_INSTALLED) { - mVoiceInput = new VoiceInput(service, this); - mHints = new Hints(service, prefs, new Hints.Display() { - @Override - public void showHint(int viewResource) { - View view = LayoutInflater.from(mService).inflate(viewResource, null); -// mService.setCandidatesView(view); -// mService.setCandidatesViewShown(true); - mIsShowingHint = true; - } - }); - } + mVoiceInput = new VoiceInput(service, this); + mHints = new Hints(service, prefs, new Hints.Display() { + @Override + public void showHint(int viewResource) { + View view = LayoutInflater.from(mService).inflate(viewResource, null); + mIsShowingHint = true; + } + }); } private VoiceProxy() { @@ -170,6 +170,9 @@ public class VoiceProxy implements VoiceInput.UiListener { public void flushAndLogAllTextModificationCounters(int index, CharSequence suggestion, String wordSeparators) { + if (!VOICE_INSTALLED) { + return; + } if (mAfterVoiceInput && mShowingVoiceSuggestions) { mVoiceInput.flushAllTextModificationCounters(); // send this intent AFTER logging any prior aggregated edits. @@ -308,6 +311,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void hideVoiceWindow(boolean configurationChanging) { + if (!VOICE_INSTALLED) { + return; + } if (!configurationChanging) { if (mAfterVoiceInput) mVoiceInput.logInputEnded(); @@ -324,6 +330,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void setCursorAndSelection(int newSelEnd, int newSelStart) { + if (!VOICE_INSTALLED) { + return; + } if (mAfterVoiceInput) { mVoiceInput.setCursorPos(newSelEnd); mVoiceInput.setSelectionSpan(newSelEnd - newSelStart); @@ -366,6 +375,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } private void revertVoiceInput() { + if (!VOICE_INSTALLED) { + return; + } InputConnection ic = mService.getCurrentInputConnection(); if (ic != null) ic.commitText("", 1); mService.updateSuggestions(); @@ -393,6 +405,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void rememberReplacedWord(CharSequence suggestion,String wordSeparators) { + if (!VOICE_INSTALLED) { + return; + } if (mShowingVoiceSuggestions) { // Retain the replaced word in the alternatives array. String wordToBeReplaced = EditingUtils.getWordAtCursor( @@ -419,6 +434,9 @@ public class VoiceProxy implements VoiceInput.UiListener { * @return true if an alternative was found, false otherwise. */ public boolean applyVoiceAlternatives(EditingUtils.SelectedWord touching) { + if (!VOICE_INSTALLED) { + return false; + } // Search for result in spoken word alternatives String selectedWord = touching.mWord.toString().trim(); if (!mWordToSuggestions.containsKey(selectedWord)) { @@ -448,6 +466,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleBackspace() { + if (!VOICE_INSTALLED) { + return; + } if (mAfterVoiceInput) { // Don't log delete if the user is pressing delete at // the beginning of the text box (hence not deleting anything) @@ -462,6 +483,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleCharacter() { + if (!VOICE_INSTALLED) { + return; + } commitVoiceInput(); if (mAfterVoiceInput) { // Assume input length is 1. This assumption fails for smiley face insertions. @@ -470,6 +494,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleSeparator() { + if (!VOICE_INSTALLED) { + return; + } commitVoiceInput(); if (mAfterVoiceInput){ // Assume input length is 1. This assumption fails for smiley face insertions. @@ -485,6 +512,9 @@ public class VoiceProxy implements VoiceInput.UiListener { public void handleVoiceResults(boolean capitalizeFirstWord) { + if (!VOICE_INSTALLED) { + return; + } mAfterVoiceInput = true; mImmediatelyAfterVoiceInput = true; @@ -659,7 +689,14 @@ public class VoiceProxy implements VoiceInput.UiListener { && SpeechRecognizer.isRecognitionAvailable(mService); } + public static boolean isRecognitionAvailable(Context context) { + return SpeechRecognizer.isRecognitionAvailable(context); + } + public void loadSettings(EditorInfo attribute, SharedPreferences sp) { + if (!VOICE_INSTALLED) { + return; + } mHasUsedVoiceInput = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT, false); mHasUsedVoiceInputUnsupportedLocale = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false); @@ -683,6 +720,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void onStartInputView(IBinder keyboardViewToken) { + if (!VOICE_INSTALLED) { + return; + } // If keyboardViewToken is null, keyboardView is not attached but voiceView is attached. IBinder windowToken = keyboardViewToken != null ? keyboardViewToken : mVoiceInput.getView().getWindowToken(); @@ -699,12 +739,18 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void onAttachedToWindow() { + if (!VOICE_INSTALLED) { + return; + } // After onAttachedToWindow, we can show the voice warning dialog. See startListening() // above. VoiceInputWrapper.getInstance().setVoiceInput(mVoiceInput, mSubtypeSwitcher); } public void onConfigurationChanged(Configuration configuration) { + if (!VOICE_INSTALLED) { + return; + } if (mRecognizing) { switchToRecognitionStatusView(configuration); } @@ -712,6 +758,9 @@ public class VoiceProxy implements VoiceInput.UiListener { @Override public void onCancelVoice() { + if (!VOICE_INSTALLED) { + return; + } if (mRecognizing) { if (mSubtypeSwitcher.isVoiceMode()) { // If voice mode is being canceled within LatinIME (i.e. time-out or user @@ -733,6 +782,9 @@ public class VoiceProxy implements VoiceInput.UiListener { @Override public void onVoiceResults(List candidates, Map> alternatives) { + if (!VOICE_INSTALLED) { + return; + } if (!mRecognizing) { return; } @@ -748,59 +800,22 @@ public class VoiceProxy implements VoiceInput.UiListener { switcher.getEnabledLanguages()); } - private class VoiceResults { + // TODO: make this private (proguard issue) + public static class VoiceResults { List candidates; Map> alternatives; } - public static class VoiceLoggerWrapper { - private static final VoiceLoggerWrapper sLoggerWrapperInstance = new VoiceLoggerWrapper(); - private VoiceInputLogger mLogger; - - public static VoiceLoggerWrapper getInstance(Context context) { - if (sLoggerWrapperInstance.mLogger == null) { - // Not thread safe, but it's ok. - sLoggerWrapperInstance.mLogger = VoiceInputLogger.getLogger(context); - } - return sLoggerWrapperInstance; - } - - // private for the singleton - private VoiceLoggerWrapper() { - } - - public void settingsWarningDialogCancel() { - mLogger.settingsWarningDialogCancel(); - } - - public void settingsWarningDialogOk() { - mLogger.settingsWarningDialogOk(); - } - - public void settingsWarningDialogShown() { - mLogger.settingsWarningDialogShown(); - } - - public void settingsWarningDialogDismissed() { - mLogger.settingsWarningDialogDismissed(); - } - - public void voiceInputSettingEnabled(boolean enabled) { - if (enabled) { - mLogger.voiceInputSettingEnabled(); - } else { - mLogger.voiceInputSettingDisabled(); - } - } - } - public static class VoiceInputWrapper { private static final VoiceInputWrapper sInputWrapperInstance = new VoiceInputWrapper(); private VoiceInput mVoiceInput; public static VoiceInputWrapper getInstance() { return sInputWrapperInstance; } - public void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) { + private void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) { + if (!VOICE_INSTALLED) { + return; + } if (mVoiceInput == null && voiceInput != null) { mVoiceInput = voiceInput; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 37c501468..52ecfe236 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -148,11 +148,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha } } - public void loadKeyboard(EditorInfo attribute, boolean voiceKeyEnabled, - boolean voiceButtonOnPrimary) { + public void loadKeyboard(EditorInfo attribute, Settings.Values settings) { mSwitchState = SWITCH_STATE_ALPHA; try { - loadKeyboardInternal(attribute, voiceKeyEnabled, voiceButtonOnPrimary, false); + loadKeyboardInternal(attribute, settings.isVoiceButtonEnabled(attribute), + settings.isVoiceButtonOnPrimary(), false); } catch (RuntimeException e) { // Get KeyboardId to record which keyboard has been failed to load. final KeyboardId id = getKeyboardId(attribute, false); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 64f7e6011..1b9983a6e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -573,9 +573,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar LanguageSwitcherProxy.loadSettings(); if (mSubtypeSwitcher.isKeyboardMode()) { - switcher.loadKeyboard(attribute, - mSubtypeSwitcher.isShortcutImeEnabled() && voiceIme.isVoiceButtonEnabled(), - voiceIme.isVoiceButtonOnPrimary()); + switcher.loadKeyboard(attribute, mSettingsValues); switcher.updateShiftState(); } @@ -1894,9 +1892,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar setInputView(mKeyboardSwitcher.onCreateInputView()); } // Reload keyboard because the current language has been changed. - mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), - mSubtypeSwitcher.isShortcutImeEnabled() && mVoiceProxy.isVoiceButtonEnabled(), - mVoiceProxy.isVoiceButtonOnPrimary()); + mKeyboardSwitcher.loadKeyboard(getCurrentInputEditorInfo(), mSettingsValues); initSuggest(); loadSettings(); mKeyboardSwitcher.updateShiftState(); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 54f0a1b4d..b6171d276 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -16,13 +16,6 @@ package com.android.inputmethod.latin; -import com.android.inputmethod.compat.CompatUtils; -import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; -import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; -import com.android.inputmethod.deprecated.VoiceProxy; -import com.android.inputmethod.compat.VibratorCompatWrapper; -import com.android.inputmethodcommon.InputMethodSettingsActivity; - import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; @@ -40,12 +33,20 @@ import android.preference.Preference; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; -import android.speech.SpeechRecognizer; import android.text.TextUtils; import android.text.method.LinkMovementMethod; import android.util.Log; +import android.view.inputmethod.EditorInfo; import android.widget.TextView; +import com.android.inputmethod.compat.CompatUtils; +import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; +import com.android.inputmethod.compat.InputTypeCompatUtils; +import com.android.inputmethod.compat.VibratorCompatWrapper; +import com.android.inputmethod.deprecated.VoiceProxy; +import com.android.inputmethodcommon.InputMethodSettingsActivity; + import java.util.Arrays; import java.util.Locale; @@ -119,6 +120,9 @@ public class Settings extends InputMethodSettingsActivity public final boolean mBigramPredictionEnabled; public final boolean mUseContactsDict; + private final boolean mVoiceButtonEnabled; + private final boolean mVoiceButtonOnPrimary; + public Values(final SharedPreferences prefs, final Context context, final String localeStr) { final Resources res = context.getResources(); @@ -179,6 +183,12 @@ public class Settings extends InputMethodSettingsActivity mUseContactsDict = prefs.getBoolean(Settings.PREF_KEY_USE_CONTACTS_DICT, true); + final String voiceMode = prefs.getString(PREF_VOICE_SETTINGS_KEY, null); + mVoiceButtonEnabled = voiceMode != null && !voiceMode.equals( + res.getString(R.string.voice_mode_off)); + mVoiceButtonOnPrimary = voiceMode != null && voiceMode.equals( + res.getString(R.string.voice_mode_main)); + Utils.setSystemLocale(res, savedLocale); } @@ -287,6 +297,17 @@ public class Settings extends InputMethodSettingsActivity } return builder.setIsPunctuationSuggestions().build(); } + + public boolean isVoiceButtonEnabled(EditorInfo attribute) { + final boolean shortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); + final int inputType = (attribute != null) ? attribute.inputType : 0; + return shortcutImeEnabled && mVoiceButtonEnabled + && !InputTypeCompatUtils.isPasswordInputType(inputType); + } + + public boolean isVoiceButtonOnPrimary() { + return mVoiceButtonOnPrimary; + } } private PreferenceScreen mInputLanguageSelection; @@ -304,8 +325,6 @@ public class Settings extends InputMethodSettingsActivity private AlertDialog mDialog; - private VoiceProxy.VoiceLoggerWrapper mVoiceLogger; - private boolean mOkClicked = false; private String mVoiceModeOff; @@ -349,7 +368,6 @@ public class Settings extends InputMethodSettingsActivity mVoiceModeOff = getString(R.string.voice_mode_off); mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff) .equals(mVoiceModeOff)); - mVoiceLogger = VoiceProxy.VoiceLoggerWrapper.getInstance(context); mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD); mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS); @@ -447,14 +465,17 @@ public class Settings extends InputMethodSettingsActivity } } + @SuppressWarnings("unused") @Override public void onResume() { super.onResume(); - if (!VoiceProxy.VOICE_INSTALLED - || !SpeechRecognizer.isRecognitionAvailable(getActivityInternal())) { - getPreferenceScreen().removePreference(mVoicePreference); - } else { + final boolean isShortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); + if (isShortcutImeEnabled + || (VoiceProxy.VOICE_INSTALLED + && VoiceProxy.isRecognitionAvailable(getActivityInternal()))) { updateVoiceModeSummary(); + } else { + getPreferenceScreen().removePreference(mVoicePreference); } updateSettingsKeySummary(); updateShowCorrectionSuggestionsSummary(); @@ -541,6 +562,7 @@ public class Settings extends InputMethodSettingsActivity [mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]); } + @Override protected Dialog onCreateDialog(int id) { switch (id) { case VOICE_INPUT_CONFIRM_DIALOG: @@ -549,12 +571,9 @@ public class Settings extends InputMethodSettingsActivity public void onClick(DialogInterface dialog, int whichButton) { if (whichButton == DialogInterface.BUTTON_NEGATIVE) { mVoicePreference.setValue(mVoiceModeOff); - mVoiceLogger.settingsWarningDialogCancel(); } else if (whichButton == DialogInterface.BUTTON_POSITIVE) { mOkClicked = true; - mVoiceLogger.settingsWarningDialogOk(); } - updateVoicePreference(); } }; AlertDialog.Builder builder = new AlertDialog.Builder(getActivityInternal()) @@ -583,7 +602,6 @@ public class Settings extends InputMethodSettingsActivity AlertDialog dialog = builder.create(); mDialog = dialog; dialog.setOnDismissListener(this); - mVoiceLogger.settingsWarningDialogShown(); return dialog; default: Log.e(TAG, "unknown dialog " + id); @@ -593,16 +611,10 @@ public class Settings extends InputMethodSettingsActivity @Override public void onDismiss(DialogInterface dialog) { - mVoiceLogger.settingsWarningDialogDismissed(); if (!mOkClicked) { // This assumes that onPreferenceClick gets called first, and this if the user // agreed after the warning, we set the mOkClicked value to true. mVoicePreference.setValue(mVoiceModeOff); } } - - private void updateVoicePreference() { - boolean isChecked = !mVoicePreference.getValue().equals(mVoiceModeOff); - mVoiceLogger.voiceInputSettingEnabled(isChecked); - } } -- cgit v1.2.3-83-g751a From f640a97566134e84af39c8766d4d83c0bde7a79f Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 22 Jul 2011 12:52:12 -0700 Subject: Fix NPE Bug: 5067161 Change-Id: I466d40fc1bffa01efc1205a47b3330ae6f30bc66 --- .../android/inputmethod/deprecated/VoiceProxy.java | 65 +++++++++++++++------- 1 file changed, 44 insertions(+), 21 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index b8a8169bc..9397483ce 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -158,7 +158,10 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void flushVoiceInputLogs(boolean configurationChanged) { - if (VOICE_INSTALLED && !configurationChanged) { + if (!VOICE_INSTALLED) { + return; + } + if (!configurationChanged) { if (mAfterVoiceInput) { mVoiceInput.flushAllTextModificationCounters(); mVoiceInput.logInputEnded(); @@ -301,6 +304,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void showPunctuationHintIfNecessary() { + if (!VOICE_INSTALLED) { + return; + } InputConnection ic = mService.getCurrentInputConnection(); if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) { if (mHints.showPunctuationHintIfNecessary(ic)) { @@ -375,9 +381,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } private void revertVoiceInput() { - if (!VOICE_INSTALLED) { - return; - } InputConnection ic = mService.getCurrentInputConnection(); if (ic != null) ic.commitText("", 1); mService.updateSuggestions(); @@ -394,7 +397,10 @@ public class VoiceProxy implements VoiceInput.UiListener { } public boolean logAndRevertVoiceInput() { - if (VOICE_INSTALLED && mVoiceInputHighlighted) { + if (!VOICE_INSTALLED) { + return false; + } + if (mVoiceInputHighlighted) { mVoiceInput.incrementTextModificationDeleteCount( mVoiceResults.candidates.get(0).toString().length()); revertVoiceInput(); @@ -505,7 +511,10 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void handleClose() { - if (VOICE_INSTALLED & mRecognizing) { + if (!VOICE_INSTALLED) { + return; + } + if (mRecognizing) { mVoiceInput.cancel(); } } @@ -553,6 +562,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void switchToRecognitionStatusView(final Configuration configuration) { + if (!VOICE_INSTALLED) { + return; + } mHandler.post(new Runnable() { @Override public void run() { @@ -597,6 +609,9 @@ public class VoiceProxy implements VoiceInput.UiListener { } private void switchToLastInputMethod() { + if (!VOICE_INSTALLED) { + return; + } final IBinder token = mService.getWindow().getWindow().getAttributes().token; new AsyncTask() { @Override @@ -662,14 +677,15 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void startListening(final boolean swipe, IBinder token) { + if (!VOICE_INSTALLED) { + return; + } // TODO: remove swipe which is no longer used. - if (VOICE_INSTALLED) { - if (needsToShowWarningDialog()) { - // Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel. - showVoiceWarningDialog(swipe, token); - } else { - reallyStartListening(swipe); - } + if (needsToShowWarningDialog()) { + // Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel. + showVoiceWarningDialog(swipe, token); + } else { + reallyStartListening(swipe); } } @@ -704,17 +720,18 @@ public class VoiceProxy implements VoiceInput.UiListener { mLocaleSupportedForVoiceInput = SubtypeSwitcher.getInstance().isVoiceSupported( SubtypeSwitcher.getInstance().getInputLocaleStr()); - if (VOICE_INSTALLED) { - final String voiceMode = sp.getString(PREF_VOICE_MODE, - mService.getString(R.string.voice_mode_main)); - mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off)) - && shouldShowVoiceButton(makeFieldContext(), attribute); - mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main)); - } + final String voiceMode = sp.getString(PREF_VOICE_MODE, + mService.getString(R.string.voice_mode_main)); + mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off)) + && shouldShowVoiceButton(makeFieldContext(), attribute); + mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main)); } public void destroy() { - if (VOICE_INSTALLED && mVoiceInput != null) { + if (!VOICE_INSTALLED) { + return; + } + if (mVoiceInput != null) { mVoiceInput.destroy(); } } @@ -826,10 +843,16 @@ public class VoiceProxy implements VoiceInput.UiListener { } public void cancel() { + if (!VOICE_INSTALLED) { + return; + } if (mVoiceInput != null) mVoiceInput.cancel(); } public void reset() { + if (!VOICE_INSTALLED) { + return; + } if (mVoiceInput != null) mVoiceInput.reset(); } } -- cgit v1.2.3-83-g751a From 6d468c513f49a1d64e5da2c9fbe625710c75e20a Mon Sep 17 00:00:00 2001 From: satok Date: Wed, 7 Sep 2011 12:36:07 +0900 Subject: Fix NPE in settings Bug: 5246032 Change-Id: I452dab9bf863fb8cba142467f338088ee8b30283 --- java/src/com/android/inputmethod/deprecated/VoiceProxy.java | 4 ++-- java/src/com/android/inputmethod/latin/Settings.java | 4 ++-- java/src/com/android/inputmethod/latin/SubtypeSwitcher.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index 9397483ce..a4dfa10d2 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -717,8 +717,8 @@ public class VoiceProxy implements VoiceInput.UiListener { mHasUsedVoiceInputUnsupportedLocale = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false); - mLocaleSupportedForVoiceInput = SubtypeSwitcher.getInstance().isVoiceSupported( - SubtypeSwitcher.getInstance().getInputLocaleStr()); + mLocaleSupportedForVoiceInput = SubtypeSwitcher.isVoiceSupported( + mService, SubtypeSwitcher.getInstance().getInputLocaleStr()); final String voiceMode = sp.getString(PREF_VOICE_MODE, mService.getString(R.string.voice_mode_main)); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index e99bb7016..e0eae180d 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -580,8 +580,8 @@ public class Settings extends InputMethodSettingsActivity // Get the current list of supported locales and check the current locale against // that list, to decide whether to put a warning that voice input will not work in // the current language as part of the pop-up confirmation dialog. - boolean localeSupported = SubtypeSwitcher.getInstance().isVoiceSupported( - Locale.getDefault().toString()); + boolean localeSupported = SubtypeSwitcher.isVoiceSupported( + this, Locale.getDefault().toString()); final CharSequence message; if (localeSupported) { diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 56f14de57..f9dda6a40 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -539,14 +539,14 @@ public class SubtypeSwitcher { } - public boolean isVoiceSupported(String locale) { + public static boolean isVoiceSupported(Context context, String locale) { // Get the current list of supported locales and check the current locale against that // list. We cache this value so as not to check it every time the user starts a voice // input. Because this method is called by onStartInputView, this should mean that as // long as the locale doesn't change while the user is keeping the IME open, the // value should never be stale. String supportedLocalesString = VoiceProxy.getSupportedLocalesString( - mService.getContentResolver()); + context.getContentResolver()); List voiceInputSupportedLocales = Arrays.asList( supportedLocalesString.split("\\s+")); return voiceInputSupportedLocales.contains(locale); -- cgit v1.2.3-83-g751a From 62c7e25e11f021f6640f9170e53b7e86ed537fd8 Mon Sep 17 00:00:00 2001 From: satok Date: Fri, 30 Sep 2011 20:17:32 +0900 Subject: Move SharedPreferencesCompat to com.android.inputmethod.compat Change-Id: Ied336339b8eb3643f14517c251b07c09398f61fe --- .../compat/SharedPreferencesCompat.java | 53 ++++++++++++++++++++++ .../android/inputmethod/deprecated/VoiceProxy.java | 2 +- .../languageswitcher/InputLanguageSelection.java | 2 +- .../languageswitcher/LanguageSwitcher.java | 2 +- .../inputmethod/deprecated/voice/Hints.java | 2 +- .../inputmethod/latin/SharedPreferencesCompat.java | 53 ---------------------- 6 files changed, 57 insertions(+), 57 deletions(-) create mode 100644 java/src/com/android/inputmethod/compat/SharedPreferencesCompat.java delete mode 100644 java/src/com/android/inputmethod/latin/SharedPreferencesCompat.java (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/compat/SharedPreferencesCompat.java b/java/src/com/android/inputmethod/compat/SharedPreferencesCompat.java new file mode 100644 index 000000000..38736f3a1 --- /dev/null +++ b/java/src/com/android/inputmethod/compat/SharedPreferencesCompat.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2010 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.SharedPreferences; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +/** + * Reflection utils to call SharedPreferences$Editor.apply when possible, + * falling back to commit when apply isn't available. + */ +public class SharedPreferencesCompat { + private static final Method sApplyMethod = findApplyMethod(); + + private static Method findApplyMethod() { + try { + return SharedPreferences.Editor.class.getMethod("apply"); + } catch (NoSuchMethodException unused) { + // fall through + } + return null; + } + + public static void apply(SharedPreferences.Editor editor) { + if (sApplyMethod != null) { + try { + sApplyMethod.invoke(editor); + return; + } catch (InvocationTargetException unused) { + // fall through + } catch (IllegalAccessException unused) { + // fall through + } + } + editor.commit(); + } +} diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index a4dfa10d2..3f8c2ef8f 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -18,6 +18,7 @@ package com.android.inputmethod.deprecated; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; +import com.android.inputmethod.compat.SharedPreferencesCompat; import com.android.inputmethod.deprecated.voice.FieldContext; import com.android.inputmethod.deprecated.voice.Hints; import com.android.inputmethod.deprecated.voice.SettingsUtil; @@ -28,7 +29,6 @@ import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME.UIHandler; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SharedPreferencesCompat; import com.android.inputmethod.latin.SubtypeSwitcher; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.Utils; diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java index b6e0ec9cf..dbe7aec6a 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java @@ -16,12 +16,12 @@ package com.android.inputmethod.deprecated.languageswitcher; +import com.android.inputmethod.compat.SharedPreferencesCompat; import com.android.inputmethod.keyboard.internal.KeyboardBuilder; import com.android.inputmethod.latin.DictionaryFactory; import com.android.inputmethod.latin.LocaleUtils; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.Settings; -import com.android.inputmethod.latin.SharedPreferencesCompat; import com.android.inputmethod.latin.Utils; import org.xmlpull.v1.XmlPullParserException; diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java index 8070942d0..7e2627c81 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java @@ -16,11 +16,11 @@ package com.android.inputmethod.deprecated.languageswitcher; +import com.android.inputmethod.compat.SharedPreferencesCompat; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LocaleUtils; import com.android.inputmethod.latin.Settings; -import com.android.inputmethod.latin.SharedPreferencesCompat; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; diff --git a/java/src/com/android/inputmethod/deprecated/voice/Hints.java b/java/src/com/android/inputmethod/deprecated/voice/Hints.java index 06b234381..17a19bf23 100644 --- a/java/src/com/android/inputmethod/deprecated/voice/Hints.java +++ b/java/src/com/android/inputmethod/deprecated/voice/Hints.java @@ -16,8 +16,8 @@ package com.android.inputmethod.deprecated.voice; +import com.android.inputmethod.compat.SharedPreferencesCompat; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SharedPreferencesCompat; import android.content.ContentResolver; import android.content.Context; diff --git a/java/src/com/android/inputmethod/latin/SharedPreferencesCompat.java b/java/src/com/android/inputmethod/latin/SharedPreferencesCompat.java deleted file mode 100644 index 1d36c0b98..000000000 --- a/java/src/com/android/inputmethod/latin/SharedPreferencesCompat.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2010 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.SharedPreferences; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -/** - * Reflection utils to call SharedPreferences$Editor.apply when possible, - * falling back to commit when apply isn't available. - */ -public class SharedPreferencesCompat { - private static final Method sApplyMethod = findApplyMethod(); - - private static Method findApplyMethod() { - try { - return SharedPreferences.Editor.class.getMethod("apply"); - } catch (NoSuchMethodException unused) { - // fall through - } - return null; - } - - public static void apply(SharedPreferences.Editor editor) { - if (sApplyMethod != null) { - try { - sApplyMethod.invoke(editor); - return; - } catch (InvocationTargetException unused) { - // fall through - } catch (IllegalAccessException unused) { - // fall through - } - } - editor.commit(); - } -} -- cgit v1.2.3-83-g751a From e7eac906c0a14b644d457beeb73a407fa1b63673 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Mon, 21 Nov 2011 14:58:32 -0800 Subject: Pending onStartInputView only if the EditorInfo is identical Bug: 5604372 Change-Id: I2a88cf15b07eebd29e43e460f6ec758432181b01 --- .../accessibility/AccessibilityUtils.java | 12 ++-- .../android/inputmethod/deprecated/VoiceProxy.java | 10 +-- .../inputmethod/deprecated/voice/FieldContext.java | 4 +- .../android/inputmethod/keyboard/KeyboardId.java | 12 ++-- .../com/android/inputmethod/latin/LatinIME.java | 83 +++++++++++----------- .../com/android/inputmethod/latin/Settings.java | 4 +- 6 files changed, 64 insertions(+), 61 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java index 4a2542dec..dcebb1c04 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibilityUtils.java @@ -116,8 +116,8 @@ public class AccessibilityUtils { * @return {@code true} if the device should not speak text (eg. * non-control) characters */ - public boolean shouldObscureInput(EditorInfo attribute) { - if (attribute == null) + public boolean shouldObscureInput(EditorInfo editorInfo) { + if (editorInfo == null) return false; // Always speak if the user is listening through headphones. @@ -125,7 +125,7 @@ public class AccessibilityUtils { return false; // 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 * 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. */ - public void onStartInputViewInternal(EditorInfo attribute, boolean restarting) { - if (shouldObscureInput(attribute)) { + public void onStartInputViewInternal(EditorInfo editorInfo, boolean restarting) { + if (shouldObscureInput(editorInfo)) { final CharSequence text = mContext.getText(R.string.spoken_use_headphones); speak(text); } diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index 3f8c2ef8f..a013ebca9 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -695,12 +695,12 @@ public class VoiceProxy implements VoiceInput.UiListener { && !mVoiceInput.isBlacklistedField(fieldContext); } - private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo attribute) { + private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo editorInfo) { @SuppressWarnings("deprecation") final boolean noMic = Utils.inPrivateImeOptions(null, - LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, attribute) + LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo) || Utils.inPrivateImeOptions(mService.getPackageName(), - LatinIME.IME_OPTION_NO_MICROPHONE, attribute); + LatinIME.IME_OPTION_NO_MICROPHONE, editorInfo); return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !noMic && SpeechRecognizer.isRecognitionAvailable(mService); } @@ -709,7 +709,7 @@ public class VoiceProxy implements VoiceInput.UiListener { return SpeechRecognizer.isRecognitionAvailable(context); } - public void loadSettings(EditorInfo attribute, SharedPreferences sp) { + public void loadSettings(EditorInfo editorInfo, SharedPreferences sp) { if (!VOICE_INSTALLED) { return; } @@ -723,7 +723,7 @@ public class VoiceProxy implements VoiceInput.UiListener { final String voiceMode = sp.getString(PREF_VOICE_MODE, mService.getString(R.string.voice_mode_main)); 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)); } diff --git a/java/src/com/android/inputmethod/deprecated/voice/FieldContext.java b/java/src/com/android/inputmethod/deprecated/voice/FieldContext.java index 3c79cc218..fd2cf3d25 100644 --- a/java/src/com/android/inputmethod/deprecated/voice/FieldContext.java +++ b/java/src/com/android/inputmethod/deprecated/voice/FieldContext.java @@ -43,10 +43,10 @@ public class FieldContext { Bundle mFieldInfo; - public FieldContext(InputConnection conn, EditorInfo info, + public FieldContext(InputConnection conn, EditorInfo editorInfo, String selectedLanguage, String[] enabledLanguages) { mFieldInfo = new Bundle(); - addEditorInfoToBundle(info, mFieldInfo); + addEditorInfoToBundle(editorInfo, mFieldInfo); addInputConnectionToBundle(conn, mFieldInfo); addLanguageInfoToBundle(selectedLanguage, enabledLanguages, mFieldInfo); if (DBG) Log.i("FieldContext", "Bundle = " + mFieldInfo.toString()); diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardId.java b/java/src/com/android/inputmethod/keyboard/KeyboardId.java index cf0637124..840857778 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardId.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardId.java @@ -58,15 +58,15 @@ public class KeyboardId { public final int mImeAction; public final String mXmlName; - public final EditorInfo mAttribute; + public final EditorInfo mEditorInfo; private final int mHashCode; 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) { - final int inputType = (attribute != null) ? attribute.inputType : 0; - final int imeOptions = (attribute != null) ? attribute.imeOptions : 0; + final int inputType = (editorInfo != null) ? editorInfo.inputType : 0; + final int imeOptions = (editorInfo != null) ? editorInfo.imeOptions : 0; this.mLocale = locale; this.mOrientation = orientation; this.mWidth = width; @@ -89,7 +89,7 @@ public class KeyboardId { EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION); this.mXmlName = xmlName; - this.mAttribute = attribute; + this.mEditorInfo = editorInfo; this.mHashCode = Arrays.hashCode(new Object[] { locale, @@ -109,7 +109,7 @@ public class KeyboardId { } 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); } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 049b316b1..dc5ec2d86 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -409,6 +409,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private boolean mHasPendingStartInput; private boolean mHasPendingFinishInputView; private boolean mHasPendingFinishInput; + private EditorInfo mAppliedEditorInfo; public void startOrientationChanging() { removeMessages(MSG_PENDING_IMS_CALLBACK); @@ -424,18 +425,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mHasPendingStartInput = false; } - private void executePendingImsCallback(LatinIME latinIme, EditorInfo attribute, + private void executePendingImsCallback(LatinIME latinIme, EditorInfo editorInfo, boolean restarting) { if (mHasPendingFinishInputView) latinIme.onFinishInputViewInternal(mHasPendingFinishInput); if (mHasPendingFinishInput) latinIme.onFinishInputInternal(); if (mHasPendingStartInput) - latinIme.onStartInputInternal(attribute, restarting); + latinIme.onStartInputInternal(editorInfo, restarting); resetPendingImsCallback(); } - public void onStartInput(EditorInfo attribute, boolean restarting) { + public void onStartInput(EditorInfo editorInfo, boolean restarting) { if (hasMessages(MSG_PENDING_IMS_CALLBACK)) { // Typically this is the second onStartInput after orientation changed. mHasPendingStartInput = true; @@ -446,27 +447,28 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mPendingSuccesiveImsCallback = true; } final LatinIME latinIme = getOuterInstance(); - executePendingImsCallback(latinIme, attribute, restarting); - latinIme.onStartInputInternal(attribute, restarting); + executePendingImsCallback(latinIme, editorInfo, restarting); + latinIme.onStartInputInternal(editorInfo, restarting); } } - public void onStartInputView(EditorInfo attribute, boolean restarting) { - if (hasMessages(MSG_PENDING_IMS_CALLBACK)) { - // Typically this is the second onStartInputView after orientation changed. - resetPendingImsCallback(); - } else { - if (mPendingSuccesiveImsCallback) { - // This is the first onStartInputView after orientation changed. - mPendingSuccesiveImsCallback = false; - resetPendingImsCallback(); - sendMessageDelayed(obtainMessage(MSG_PENDING_IMS_CALLBACK), - PENDING_IMS_CALLBACK_DURATION); - } - final LatinIME latinIme = getOuterInstance(); - executePendingImsCallback(latinIme, attribute, restarting); - latinIme.onStartInputViewInternal(attribute, restarting); - } + public void onStartInputView(EditorInfo editorInfo, boolean restarting) { + if (hasMessages(MSG_PENDING_IMS_CALLBACK) && editorInfo == mAppliedEditorInfo) { + // Typically this is the second onStartInputView after orientation changed. + resetPendingImsCallback(); + } else { + if (mPendingSuccesiveImsCallback) { + // This is the first onStartInputView after orientation changed. + mPendingSuccesiveImsCallback = false; + resetPendingImsCallback(); + sendMessageDelayed(obtainMessage(MSG_PENDING_IMS_CALLBACK), + PENDING_IMS_CALLBACK_DURATION); + } + final LatinIME latinIme = getOuterInstance(); + executePendingImsCallback(latinIme, editorInfo, restarting); + latinIme.onStartInputViewInternal(editorInfo, restarting); + mAppliedEditorInfo = editorInfo; + } } public void onFinishInputView(boolean finishingInput) { @@ -476,6 +478,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } else { final LatinIME latinIme = getOuterInstance(); latinIme.onFinishInputViewInternal(finishingInput); + mAppliedEditorInfo = null; } } @@ -703,13 +706,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } @Override - public void onStartInput(EditorInfo attribute, boolean restarting) { - mHandler.onStartInput(attribute, restarting); + public void onStartInput(EditorInfo editorInfo, boolean restarting) { + mHandler.onStartInput(editorInfo, restarting); } @Override - public void onStartInputView(EditorInfo attribute, boolean restarting) { - mHandler.onStartInputView(attribute, restarting); + public void onStartInputView(EditorInfo editorInfo, boolean restarting) { + mHandler.onStartInputView(editorInfo, restarting); } @Override @@ -722,19 +725,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mHandler.onFinishInput(); } - private void onStartInputInternal(EditorInfo attribute, boolean restarting) { - super.onStartInput(attribute, restarting); + private void onStartInputInternal(EditorInfo editorInfo, boolean restarting) { + super.onStartInput(editorInfo, restarting); } - private void onStartInputViewInternal(EditorInfo attribute, boolean restarting) { - super.onStartInputView(attribute, restarting); + private void onStartInputViewInternal(EditorInfo editorInfo, boolean restarting) { + super.onStartInputView(editorInfo, restarting); final KeyboardSwitcher switcher = mKeyboardSwitcher; LatinKeyboardView inputView = switcher.getKeyboardView(); 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", - attribute.inputType, attribute.imeOptions))); + editorInfo.inputType, editorInfo.imeOptions))); } // In landscape mode, this method gets called without the input view being created. if (inputView == null) { @@ -744,7 +747,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Forward this event to the accessibility utilities, if enabled. final AccessibilityUtils accessUtils = AccessibilityUtils.getInstance(); if (accessUtils.isTouchExplorationEnabled()) { - accessUtils.onStartInputViewInternal(attribute, restarting); + accessUtils.onStartInputViewInternal(editorInfo, restarting); } 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 // want to enable the voice button. 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) || InputTypeCompatUtils.isVisiblePasswordInputType(inputType)); // The EditorInfo might have a flag that affects fullscreen mode. // Note: This call should be done by InputMethodService? updateFullscreenMode(); - initializeInputAttributes(attribute); + initializeInputAttributes(editorInfo); inputView.closing(); mEnteredText = null; @@ -778,12 +781,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) { mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); } - mVoiceProxy.loadSettings(attribute, mPrefs); + mVoiceProxy.loadSettings(editorInfo, mPrefs); // This will work only when the subtype is not supported. LanguageSwitcherProxy.loadSettings(); if (mSubtypeSwitcher.isKeyboardMode()) { - switcher.loadKeyboard(attribute, mSettingsValues); + switcher.loadKeyboard(editorInfo, mSettingsValues); } if (mSuggestionsView != null) @@ -803,10 +806,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); } - private void initializeInputAttributes(EditorInfo attribute) { - if (attribute == null) + private void initializeInputAttributes(EditorInfo editorInfo) { + if (editorInfo == null) return; - final int inputType = attribute.inputType; + final int inputType = editorInfo.inputType; if (inputType == InputType.TYPE_NULL) { // TODO: We should honor TYPE_NULL specification. 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; if (inputClass == 0) { Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x imeOptions=0x%08x", - inputType, attribute.imeOptions)); + inputType, editorInfo.imeOptions)); } mInsertSpaceOnPickSuggestionManually = false; diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index e5a041f11..7d6efa584 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -301,9 +301,9 @@ public class Settings extends InputMethodSettingsActivity return mShowSettingsKey; } - public boolean isVoiceKeyEnabled(EditorInfo attribute) { + public boolean isVoiceKeyEnabled(EditorInfo editorInfo) { 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 && !InputTypeCompatUtils.isPasswordInputType(inputType); } -- cgit v1.2.3-83-g751a From 433ca6a46db30a321715da0f457974916668dff5 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 31 Jan 2012 16:59:32 +0900 Subject: Cleanup redundant methods of KeyboardSwitcher Change-Id: I2ebeb8852177f6c6e30578d0bb3f372f488dc6c1 --- .../android/inputmethod/deprecated/VoiceProxy.java | 40 ++++++++++++---------- .../inputmethod/keyboard/KeyboardSwitcher.java | 17 --------- .../com/android/inputmethod/latin/LatinIME.java | 16 ++++++--- 3 files changed, 32 insertions(+), 41 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index a013ebca9..f632b0e02 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -16,23 +16,6 @@ package com.android.inputmethod.deprecated; -import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; -import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; -import com.android.inputmethod.compat.SharedPreferencesCompat; -import com.android.inputmethod.deprecated.voice.FieldContext; -import com.android.inputmethod.deprecated.voice.Hints; -import com.android.inputmethod.deprecated.voice.SettingsUtil; -import com.android.inputmethod.deprecated.voice.VoiceInput; -import com.android.inputmethod.keyboard.KeyboardSwitcher; -import com.android.inputmethod.latin.EditingUtils; -import com.android.inputmethod.latin.LatinIME; -import com.android.inputmethod.latin.LatinIME.UIHandler; -import com.android.inputmethod.latin.LatinImeLogger; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.SuggestedWords; -import com.android.inputmethod.latin.Utils; - import android.app.AlertDialog; import android.content.ContentResolver; import android.content.Context; @@ -63,6 +46,24 @@ import android.view.inputmethod.ExtractedTextRequest; import android.view.inputmethod.InputConnection; import android.widget.TextView; +import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; +import com.android.inputmethod.compat.SharedPreferencesCompat; +import com.android.inputmethod.deprecated.voice.FieldContext; +import com.android.inputmethod.deprecated.voice.Hints; +import com.android.inputmethod.deprecated.voice.SettingsUtil; +import com.android.inputmethod.deprecated.voice.VoiceInput; +import com.android.inputmethod.keyboard.KeyboardSwitcher; +import com.android.inputmethod.keyboard.LatinKeyboardView; +import com.android.inputmethod.latin.EditingUtils; +import com.android.inputmethod.latin.LatinIME; +import com.android.inputmethod.latin.LatinIME.UIHandler; +import com.android.inputmethod.latin.LatinImeLogger; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.SubtypeSwitcher; +import com.android.inputmethod.latin.SuggestedWords; +import com.android.inputmethod.latin.Utils; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -747,8 +748,9 @@ public class VoiceProxy implements VoiceInput.UiListener { // keep showing the warning. if (mSubtypeSwitcher.isVoiceMode() && windowToken != null) { // Close keyboard view if it is been shown. - if (KeyboardSwitcher.getInstance().isInputViewShown()) - KeyboardSwitcher.getInstance().getKeyboardView().purgeKeyboardAndClosing(); + final LatinKeyboardView keyboardView = KeyboardSwitcher.getInstance().getKeyboardView(); + if (keyboardView != null && keyboardView.isShown()) + keyboardView.purgeKeyboardAndClosing(); startListening(false, windowToken); } // If we have no token, onAttachedToWindow will take care of showing dialog and start diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 17ad45df0..40bbc205f 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -179,23 +179,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions, mInputMethodService.mHandler.startDisplayLanguageOnSpacebar(localeChanged); } - // TODO: Remove this method. - public boolean isAlphabetMode() { - final Keyboard keyboard = getKeyboard(); - return keyboard != null && keyboard.mId.isAlphabetKeyboard(); - } - - // TODO: Remove this method. - public boolean isInputViewShown() { - return mCurrentInputView != null && mCurrentInputView.isShown(); - } - - // TODO: Remove this method. - public boolean isShiftedOrShiftLocked() { - final Keyboard keyboard = getKeyboard(); - return keyboard != null && keyboard.isShiftedOrShiftLocked(); - } - public Keyboard getKeyboard() { if (mKeyboardView != null) { return mKeyboardView.getKeyboard(); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 0d6395d97..1e7171406 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -291,8 +291,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar latinIme.updateBigramPredictions(); break; case MSG_VOICE_RESULTS: + final Keyboard keyboard = switcher.getKeyboard(); latinIme.mVoiceProxy.handleVoiceResults(latinIme.preferCapitalization() - || (switcher.isAlphabetMode() && switcher.isShiftedOrShiftLocked())); + || (keyboard != null && keyboard.isShiftedOrShiftLocked())); break; case MSG_FADEOUT_LANGUAGE_ON_SPACEBAR: setSpacebarTextFadeFactor(inputView, @@ -987,8 +988,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void setSuggestionStripShownInternal(boolean shown, boolean needsInputViewShown) { // TODO: Modify this if we support suggestions with hard keyboard if (onEvaluateInputViewShown() && mSuggestionsContainer != null) { + final LatinKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView(); + final boolean inputViewShown = (keyboardView != null) ? keyboardView.isShown() : false; final boolean shouldShowSuggestions = shown - && (needsInputViewShown ? mKeyboardSwitcher.isInputViewShown() : true); + && (needsInputViewShown ? inputViewShown : true); if (isFullscreenMode()) { mSuggestionsContainer.setVisibility( shouldShowSuggestions ? View.VISIBLE : View.GONE); @@ -1020,7 +1023,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final int extraHeight = extractHeight + backingHeight + suggestionsHeight; int touchY = extraHeight; // Need to set touchable region only if input view is being shown - if (mKeyboardSwitcher.isInputViewShown()) { + final LatinKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView(); + if (keyboardView != null && keyboardView.isShown()) { if (mSuggestionsContainer.getVisibility() == View.VISIBLE) { touchY -= suggestionsHeight; } @@ -1081,9 +1085,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case KeyEvent.KEYCODE_DPAD_UP: case KeyEvent.KEYCODE_DPAD_LEFT: case KeyEvent.KEYCODE_DPAD_RIGHT: + final LatinKeyboardView keyboardView = mKeyboardSwitcher.getKeyboardView(); + final Keyboard keyboard = mKeyboardSwitcher.getKeyboard(); // Enable shift key and DPAD to do selections - if (mKeyboardSwitcher.isInputViewShown() - && mKeyboardSwitcher.isShiftedOrShiftLocked()) { + if ((keyboardView != null && keyboardView.isShown()) + && (keyboard != null && keyboard.isShiftedOrShiftLocked())) { KeyEvent newEvent = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(), event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(), -- cgit v1.2.3-83-g751a From 66bb563535dbe3672f99f75bd71763a551444867 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 21 Feb 2012 23:17:54 -0800 Subject: Give LastComposedWord knowledge of the separator (A2) This stores the separator that was used to commit the word in the LastComposedWord. It may be NOT_A_SEPARATOR if there was no separator (for example, the cursor moved causing a commit, or there was a manual pick). This is necessary to implement feature request #5968922. Change-Id: I5fcf19a78ec66d68d4df89418eaef13952588207 --- .../android/inputmethod/deprecated/VoiceProxy.java | 3 ++- .../inputmethod/latin/LastComposedWord.java | 9 ++++++-- .../com/android/inputmethod/latin/LatinIME.java | 25 +++++++++++++--------- java/src/com/android/inputmethod/latin/Utils.java | 6 ++++-- .../android/inputmethod/latin/WordComposer.java | 5 +++-- 5 files changed, 31 insertions(+), 17 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index f632b0e02..5c4e9af68 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -56,6 +56,7 @@ import com.android.inputmethod.deprecated.voice.VoiceInput; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.keyboard.LatinKeyboardView; import com.android.inputmethod.latin.EditingUtils; +import com.android.inputmethod.latin.LastComposedWord; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME.UIHandler; import com.android.inputmethod.latin.LatinImeLogger; @@ -553,7 +554,7 @@ public class VoiceProxy implements VoiceInput.UiListener { mHints.registerVoiceResult(bestResult); if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text - mService.commitTyped(ic); + mService.commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR); EditingUtils.appendText(ic, bestResult); if (ic != null) ic.endBatchEdit(); diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java index 37be03c3e..f0b91b104 100644 --- a/java/src/com/android/inputmethod/latin/LastComposedWord.java +++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java @@ -40,26 +40,31 @@ public class LastComposedWord { // an auto-correction. public static final int COMMIT_TYPE_CANCEL_AUTO_CORRECT = 3; + public static final int NOT_A_SEPARATOR = -1; + public final ArrayList mCodes; public final int[] mXCoordinates; public final int[] mYCoordinates; public final String mTypedWord; public final String mCommittedWord; + public final int mSeparatorCode; private boolean mActive; public static final LastComposedWord NOT_A_COMPOSED_WORD = - new LastComposedWord(null, null, null, "", ""); + new LastComposedWord(null, null, null, "", "", NOT_A_SEPARATOR); // Warning: this is using the passed objects as is and fully expects them to be // immutable. Do not fiddle with their contents after you passed them to this constructor. public LastComposedWord(final ArrayList codes, final int[] xCoordinates, - final int[] yCoordinates, final String typedWord, final String committedWord) { + final int[] yCoordinates, final String typedWord, final String committedWord, + final int separatorCode) { mCodes = codes; mXCoordinates = xCoordinates; mYCoordinates = yCoordinates; mTypedWord = typedWord; mCommittedWord = committedWord; + mSeparatorCode = separatorCode; mActive = true; } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a40bcdfe2..b7c8b70e1 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -658,7 +658,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mDisplayOrientation = conf.orientation; mHandler.startOrientationChanging(); final InputConnection ic = getCurrentInputConnection(); - commitTyped(ic); + commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR); if (ic != null) ic.finishComposingText(); // For voice input if (isShowingOptionDialog()) mOptionsDialog.dismiss(); @@ -1126,12 +1126,13 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; } - public void commitTyped(final InputConnection ic) { + public void commitTyped(final InputConnection ic, final int separatorCode) { if (!mWordComposer.isComposingWord()) return; final CharSequence typedWord = mWordComposer.getTypedWord(); if (typedWord.length() > 0) { mLastComposedWord = mWordComposer.commitWord( - LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString()); + LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(), + separatorCode); if (ic != null) { ic.commitText(typedWord, 1); } @@ -1353,7 +1354,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; ic.beginBatchEdit(); - commitTyped(ic); + commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR); text = specificTldProcessingOnTextInput(ic, text); if (SPACE_STATE_PHANTOM == mSpaceState) { sendKeyCodePoint(Keyboard.CODE_SPACE); @@ -1646,7 +1647,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar commitCurrentAutoCorrection(primaryCode, ic); didAutoCorrect = true; } else { - commitTyped(ic); + commitTyped(ic, primaryCode); } } @@ -1703,7 +1704,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } private void handleClose() { - commitTyped(getCurrentInputConnection()); + commitTyped(getCurrentInputConnection(), LastComposedWord.NOT_A_SEPARATOR); mVoiceProxy.handleClose(); requestHideSelf(0); LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); @@ -1914,7 +1915,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } Utils.Stats.onAutoCorrection(typedWord, autoCorrection.toString(), separatorCodePoint); mExpectingUpdateSelection = true; - commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD); + commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD, + separatorCodePoint); // Add the word to the user unigram dictionary if it's not a known word addToUserUnigramAndBigramDictionaries(autoCorrection, UserUnigramDictionary.FREQUENCY_FOR_TYPED); @@ -1969,7 +1971,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(), suggestion.toString(), index, suggestions.mWords); mExpectingUpdateSelection = true; - commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK); + commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, + LastComposedWord.NOT_A_SEPARATOR); // Add the word to the auto dictionary if it's not a known word if (index == 0) { addToUserUnigramAndBigramDictionaries(suggestion, @@ -2019,7 +2022,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar /** * Commits the chosen word to the text field and saves it for later retrieval. */ - private void commitChosenWord(final CharSequence bestWord, final int commitType) { + private void commitChosenWord(final CharSequence bestWord, final int commitType, + final int separatorCode) { final InputConnection ic = getCurrentInputConnection(); if (ic != null) { mVoiceProxy.rememberReplacedWord(bestWord, mSettingsValues.mWordSeparators); @@ -2035,7 +2039,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // what user typed. Note: currently this is done much later in // LastComposedWord#canCancelAutoCorrect by string equality of the remembered // strings. - mLastComposedWord = mWordComposer.commitWord(commitType, bestWord.toString()); + mLastComposedWord = mWordComposer.commitWord(commitType, bestWord.toString(), + separatorCode); } private static final WordComposer sEmptyWordComposer = new WordComposer(); diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 3975dddeb..6d63e95f6 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -264,6 +264,7 @@ public class Utils { int ret = in % BUFSIZE; return ret < 0 ? ret + BUFSIZE : ret; } + // TODO: accept code points public void push(char c, int x, int y) { if (!mEnabled) return; if (mUsabilityStudy) { @@ -777,9 +778,10 @@ public class Utils { LatinImeLogger.logOnInputChar(); } - public static void onSeparator(final char code, final int x, + public static void onSeparator(final int code, final int x, final int y) { - RingCharBuffer.getInstance().push(code, x, y); + // TODO: accept code points + RingCharBuffer.getInstance().push((char)code, x, y); LatinImeLogger.logOnInputSeparator(); } diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index 1f9371538..0fa28e49e 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -308,7 +308,8 @@ public class WordComposer { } // `type' should be one of the LastComposedWord.COMMIT_TYPE_* constants above. - public LastComposedWord commitWord(final int type, final String committedWord) { + public LastComposedWord commitWord(final int type, final String committedWord, + final int separatorCode) { // Note: currently, we come here whenever we commit a word. If it's any *other* kind than // DECIDED_WORD, we should deactivate the last composed word so that we don't attempt to // cancel later. @@ -327,7 +328,7 @@ public class WordComposer { mXCoordinates = new int[N]; mYCoordinates = new int[N]; final LastComposedWord lastComposedWord = new LastComposedWord(codes, - xCoordinates, yCoordinates, mTypedWord.toString(), committedWord); + xCoordinates, yCoordinates, mTypedWord.toString(), committedWord, separatorCode); if (type != LastComposedWord.COMMIT_TYPE_DECIDED_WORD) { lastComposedWord.deactivate(); } -- cgit v1.2.3-83-g751a From 7293b65841f59a5d3c77df7faa0fcd388f572dce Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 2 Mar 2012 18:49:24 +0900 Subject: Remove a useless method Change-Id: Ic00520b18f74838fe1002a679952f62bc7226c15 --- .../android/inputmethod/deprecated/VoiceProxy.java | 38 ---------------------- 1 file changed, 38 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index 5c4e9af68..700709d50 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -435,44 +435,6 @@ public class VoiceProxy implements VoiceInput.UiListener { } } - /** - * Tries to apply any voice alternatives for the word if this was a spoken word and - * there are voice alternatives. - * @param touching The word that the cursor is touching, with position information - * @return true if an alternative was found, false otherwise. - */ - public boolean applyVoiceAlternatives(EditingUtils.SelectedWord touching) { - if (!VOICE_INSTALLED) { - return false; - } - // Search for result in spoken word alternatives - String selectedWord = touching.mWord.toString().trim(); - if (!mWordToSuggestions.containsKey(selectedWord)) { - selectedWord = selectedWord.toLowerCase(); - } - if (mWordToSuggestions.containsKey(selectedWord)) { - mShowingVoiceSuggestions = true; - List suggestions = mWordToSuggestions.get(selectedWord); - SuggestedWords.Builder builder = new SuggestedWords.Builder(); - // If the first letter of touching is capitalized, make all the suggestions - // start with a capital letter. - if (Character.isUpperCase(touching.mWord.charAt(0))) { - for (CharSequence word : suggestions) { - String str = word.toString(); - word = Character.toUpperCase(str.charAt(0)) + str.substring(1); - builder.addWord(word); - } - } else { - builder.addWords(suggestions, null); - } - builder.setTypedWordValid(true).setHasMinimalSuggestion(true); - mService.setSuggestions(builder.build()); -// mService.setCandidatesViewShown(true); - return true; - } - return false; - } - public void handleBackspace() { if (!VOICE_INSTALLED) { return; -- cgit v1.2.3-83-g751a From 3cd1a00ecacf01f3005e794f01be46648707c741 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 6 Mar 2012 18:43:18 +0900 Subject: Resolve a todo This exports some voiceproxy complexity to voiceproxy rather than keeping it in latinime Change-Id: I0b3523e77af4104cc3ed28417956059c734c8bfe --- .../com/android/inputmethod/deprecated/VoiceProxy.java | 17 +++++++++++++---- java/src/com/android/inputmethod/latin/LatinIME.java | 11 ++++------- 2 files changed, 17 insertions(+), 11 deletions(-) (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index 700709d50..c1c6d31cd 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -92,6 +92,7 @@ public class VoiceProxy implements VoiceInput.UiListener { private static final boolean DEBUG = LatinImeLogger.sDBG; private boolean mAfterVoiceInput; + private boolean mConfigurationChanging; private boolean mHasUsedVoiceInput; private boolean mHasUsedVoiceInputUnsupportedLocale; private boolean mImmediatelyAfterVoiceInput; @@ -159,11 +160,11 @@ public class VoiceProxy implements VoiceInput.UiListener { mPasswordText = isPasswordText; } - public void flushVoiceInputLogs(boolean configurationChanged) { + public void flushVoiceInputLogs() { if (!VOICE_INSTALLED) { return; } - if (!configurationChanged) { + if (!mConfigurationChanging) { if (mAfterVoiceInput) { mVoiceInput.flushAllTextModificationCounters(); mVoiceInput.logInputEnded(); @@ -318,11 +319,11 @@ public class VoiceProxy implements VoiceInput.UiListener { mImmediatelyAfterVoiceInput = false; } - public void hideVoiceWindow(boolean configurationChanging) { + public void hideVoiceWindow() { if (!VOICE_INSTALLED) { return; } - if (!configurationChanging) { + if (!mConfigurationChanging) { if (mAfterVoiceInput) mVoiceInput.logInputEnded(); if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) { @@ -842,4 +843,12 @@ public class VoiceProxy implements VoiceInput.UiListener { SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES, DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES); } + + public void startChangingConfiguration() { + mConfigurationChanging = true; + } + + public void finishChangingConfiguration() { + mConfigurationChanging = false; + } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 2bcd947f1..6b9ee9bf0 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -223,9 +223,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private VibratorCompatWrapper mVibrator; - // TODO: Move this flag to VoiceProxy - private boolean mConfigurationChanging; - // Member variables for remembering the current device orientation. private int mDisplayOrientation; @@ -664,10 +661,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mOptionsDialog.dismiss(); } - mConfigurationChanging = true; + mVoiceProxy.startChangingConfiguration(); super.onConfigurationChanged(conf); mVoiceProxy.onConfigurationChanged(conf); - mConfigurationChanging = false; + mVoiceProxy.finishChangingConfiguration(); // This will work only when the subtype is not supported. LanguageSwitcherProxy.onConfigurationChanged(conf); @@ -830,7 +827,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar LatinImeLogger.commit(); - mVoiceProxy.flushVoiceInputLogs(mConfigurationChanging); + mVoiceProxy.flushVoiceInputLogs(); KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.closing(); @@ -960,7 +957,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mOptionsDialog.dismiss(); mOptionsDialog = null; } - mVoiceProxy.hideVoiceWindow(mConfigurationChanging); + mVoiceProxy.hideVoiceWindow(); super.hideWindow(); } -- cgit v1.2.3-83-g751a From cc8c8b99bd0463f5977dea82f5e2379ea1dd4e73 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 8 Mar 2012 17:07:02 +0900 Subject: Split Utils class to StringUtils, SubtypeUtils, and JniUtils Change-Id: I09e91675fe7d573dad8c933ad513b21d7e409144 --- .../compat/InputMethodManagerCompatWrapper.java | 7 +- .../android/inputmethod/deprecated/VoiceProxy.java | 6 +- .../languageswitcher/InputLanguageSelection.java | 24 +- .../deprecated/voice/RecognitionView.java | 10 +- java/src/com/android/inputmethod/keyboard/Key.java | 10 +- .../android/inputmethod/keyboard/KeyboardSet.java | 52 ++- .../android/inputmethod/keyboard/KeyboardView.java | 4 +- .../inputmethod/keyboard/LatinKeyboardView.java | 13 +- .../inputmethod/keyboard/MoreKeysKeyboard.java | 4 +- .../inputmethod/keyboard/ProximityInfo.java | 4 +- .../keyboard/internal/KeySpecParser.java | 12 +- .../inputmethod/latin/BinaryDictionary.java | 2 +- .../inputmethod/latin/DictionaryFactory.java | 14 +- .../com/android/inputmethod/latin/JniUtils.java | 41 +++ .../com/android/inputmethod/latin/LatinIME.java | 23 +- .../com/android/inputmethod/latin/Settings.java | 2 +- .../android/inputmethod/latin/SettingsValues.java | 4 +- .../com/android/inputmethod/latin/StringUtils.java | 198 ++++++++++ .../android/inputmethod/latin/SubtypeSwitcher.java | 2 +- .../android/inputmethod/latin/SubtypeUtils.java | 135 +++++++ .../src/com/android/inputmethod/latin/Suggest.java | 50 ++- java/src/com/android/inputmethod/latin/Utils.java | 398 +-------------------- .../spellcheck/AndroidSpellCheckerService.java | 10 +- 23 files changed, 551 insertions(+), 474 deletions(-) create mode 100644 java/src/com/android/inputmethod/latin/JniUtils.java create mode 100644 java/src/com/android/inputmethod/latin/StringUtils.java create mode 100644 java/src/com/android/inputmethod/latin/SubtypeUtils.java (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java index 9dd0a599d..bf5f20158 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodManagerCompatWrapper.java @@ -32,7 +32,7 @@ import android.view.inputmethod.InputMethodManager; import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.SubtypeUtils; import java.lang.reflect.Method; import java.util.ArrayList; @@ -163,7 +163,7 @@ public class InputMethodManagerCompatWrapper { private InputMethodInfoCompatWrapper getLatinImeInputMethodInfo() { if (TextUtils.isEmpty(mLatinImePackageName)) return null; - return Utils.getInputMethodInfo(mLatinImePackageName); + return SubtypeUtils.getInputMethodInfo(mLatinImePackageName); } private static InputMethodSubtypeCompatWrapper getLastResortSubtype(String mode) { @@ -260,7 +260,8 @@ public class InputMethodManagerCompatWrapper { // The code below are based on {@link InputMethodManager#showInputMethodMenuInternal}. - final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo(mLatinImePackageName); + final InputMethodInfoCompatWrapper myImi = SubtypeUtils.getInputMethodInfo( + mLatinImePackageName); final List myImsList = getEnabledInputMethodSubtypeList( myImi, true); final InputMethodSubtypeCompatWrapper currentIms = getCurrentInputMethodSubtype(); diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java index c1c6d31cd..87d1c118b 100644 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java @@ -61,8 +61,8 @@ import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinIME.UIHandler; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.Utils; import java.util.ArrayList; @@ -662,9 +662,9 @@ public class VoiceProxy implements VoiceInput.UiListener { private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo editorInfo) { @SuppressWarnings("deprecation") - final boolean noMic = Utils.inPrivateImeOptions(null, + final boolean noMic = StringUtils.inPrivateImeOptions(null, LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo) - || Utils.inPrivateImeOptions(mService.getPackageName(), + || StringUtils.inPrivateImeOptions(mService.getPackageName(), LatinIME.IME_OPTION_NO_MICROPHONE, editorInfo); return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !noMic && SpeechRecognizer.isRecognitionAvailable(mService); diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java index e75e14861..421ee6529 100644 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java +++ b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java @@ -16,16 +16,6 @@ package com.android.inputmethod.deprecated.languageswitcher; -import com.android.inputmethod.compat.SharedPreferencesCompat; -import com.android.inputmethod.keyboard.KeyboardSet; -import com.android.inputmethod.latin.DictionaryFactory; -import com.android.inputmethod.latin.LocaleUtils; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Settings; -import com.android.inputmethod.latin.Utils; - -import org.xmlpull.v1.XmlPullParserException; - import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Resources; @@ -37,6 +27,16 @@ import android.preference.PreferenceManager; import android.text.TextUtils; import android.util.Pair; +import com.android.inputmethod.compat.SharedPreferencesCompat; +import com.android.inputmethod.keyboard.KeyboardSet; +import com.android.inputmethod.latin.DictionaryFactory; +import com.android.inputmethod.latin.LocaleUtils; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.Settings; +import com.android.inputmethod.latin.StringUtils; + +import org.xmlpull.v1.XmlPullParserException; + import java.io.IOException; import java.text.Collator; import java.util.ArrayList; @@ -237,12 +237,12 @@ public class InputLanguageSelection extends PreferenceActivity { if (finalSize == 0) { preprocess[finalSize++] = - new LocaleEntry(Utils.getFullDisplayName(l, false), l); + new LocaleEntry(StringUtils.getFullDisplayName(l, false), l); } else { if (s.equals("zz_ZZ")) { // ignore this locale } else { - final String displayName = Utils.getFullDisplayName(l, false); + final String displayName = StringUtils.getFullDisplayName(l, false); preprocess[finalSize++] = new LocaleEntry(displayName, l); } } diff --git a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java b/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java index 71d15dc3d..ff8b1abce 100644 --- a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java +++ b/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java @@ -16,10 +16,6 @@ package com.android.inputmethod.deprecated.voice; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.Utils; - import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; @@ -39,6 +35,10 @@ import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; +import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.StringUtils; +import com.android.inputmethod.latin.SubtypeSwitcher; + import java.io.ByteArrayOutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -222,7 +222,7 @@ public class RecognitionView { Locale locale = SubtypeSwitcher.getInstance().getInputLocale(); mLanguage.setVisibility(View.VISIBLE); - mLanguage.setText(Utils.getFullDisplayName(locale, true)); + mLanguage.setText(StringUtils.getFullDisplayName(locale, true)); mPopupLayout.setBackgroundDrawable(mListeningBorder); break; diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java index f3923834b..6b4de184f 100644 --- a/java/src/com/android/inputmethod/keyboard/Key.java +++ b/java/src/com/android/inputmethod/keyboard/Key.java @@ -30,7 +30,7 @@ import com.android.inputmethod.keyboard.internal.KeyStyles; import com.android.inputmethod.keyboard.internal.KeyStyles.KeyStyle; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.XmlParseUtils; import org.xmlpull.v1.XmlPullParser; @@ -293,7 +293,7 @@ public class Key { // Choose the first letter of the label as primary code if not specified. if (code == Keyboard.CODE_UNSPECIFIED && TextUtils.isEmpty(outputText) && !TextUtils.isEmpty(mLabel)) { - if (Utils.codePointCount(mLabel) == 1) { + if (StringUtils.codePointCount(mLabel) == 1) { // Use the first letter of the hint label if shiftedLetterActivated flag is // specified. if (hasShiftedLetterHint() && isShiftedLetterActivated() @@ -309,7 +309,7 @@ public class Key { mCode = Keyboard.CODE_OUTPUT_TEXT; } } else if (code == Keyboard.CODE_UNSPECIFIED && outputText != null) { - if (Utils.codePointCount(outputText) == 1) { + if (StringUtils.codePointCount(outputText) == 1) { mCode = outputText.codePointAt(0); outputText = null; } else { @@ -336,7 +336,7 @@ public class Key { if (!Keyboard.isLetterCode(code) || preserveCase) return code; final String text = new String(new int[] { code } , 0, 1); final String casedText = adjustCaseOfStringForKeyboardId(text, preserveCase, id); - return Utils.codePointCount(casedText) == 1 + return StringUtils.codePointCount(casedText) == 1 ? casedText.codePointAt(0) : Keyboard.CODE_UNSPECIFIED; } @@ -484,7 +484,7 @@ public class Key { } public int selectTextSize(int letter, int largeLetter, int label, int hintLabel) { - if (Utils.codePointCount(mLabel) > 1 + if (StringUtils.codePointCount(mLabel) > 1 && (mLabelFlags & (LABEL_FLAGS_FOLLOW_KEY_LETTER_RATIO | LABEL_FLAGS_FOLLOW_KEY_HINT_LABEL_RATIO)) == 0) { return label; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index 731aaf7c5..5ac6d03a8 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -21,16 +21,18 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; +import android.text.InputType; import android.util.Log; import android.util.Xml; import android.view.inputmethod.EditorInfo; import com.android.inputmethod.compat.EditorInfoCompatUtils; +import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.LocaleUtils; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.XmlParseUtils; import org.xmlpull.v1.XmlPullParser; @@ -215,9 +217,9 @@ public class KeyboardSet { mEditorInfo = editorInfo; final Params params = mParams; - params.mMode = Utils.getKeyboardMode(editorInfo); + params.mMode = getKeyboardMode(editorInfo); params.mEditorInfo = (editorInfo != null) ? editorInfo : EMPTY_EDITOR_INFO; - params.mNoSettingsKey = Utils.inPrivateImeOptions( + params.mNoSettingsKey = StringUtils.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_NO_SETTINGS_KEY, mEditorInfo); } @@ -230,7 +232,7 @@ public class KeyboardSet { // TODO: Use InputMethodSubtype object as argument. public Builder setSubtype(Locale inputLocale, boolean asciiCapable, boolean touchPositionCorrectionEnabled) { - final boolean deprecatedForceAscii = Utils.inPrivateImeOptions( + final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo); final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii( mParams.mEditorInfo.imeOptions) @@ -243,9 +245,9 @@ public class KeyboardSet { public Builder setOptions(boolean voiceKeyEnabled, boolean voiceKeyOnMain, boolean languageSwitchKeyEnabled) { @SuppressWarnings("deprecation") - final boolean deprecatedNoMicrophone = Utils.inPrivateImeOptions( + final boolean deprecatedNoMicrophone = StringUtils.inPrivateImeOptions( null, LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, mEditorInfo); - final boolean noMicrophone = Utils.inPrivateImeOptions( + final boolean noMicrophone = StringUtils.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_NO_MICROPHONE, mEditorInfo) || deprecatedNoMicrophone; mParams.mVoiceKeyEnabled = voiceKeyEnabled && !noMicrophone; @@ -337,6 +339,44 @@ public class KeyboardSet { a.recycle(); } } + + private static int getKeyboardMode(EditorInfo editorInfo) { + if (editorInfo == null) + return KeyboardId.MODE_TEXT; + + final int inputType = editorInfo.inputType; + final int variation = inputType & InputType.TYPE_MASK_VARIATION; + + switch (inputType & InputType.TYPE_MASK_CLASS) { + case InputType.TYPE_CLASS_NUMBER: + return KeyboardId.MODE_NUMBER; + case InputType.TYPE_CLASS_DATETIME: + switch (variation) { + case InputType.TYPE_DATETIME_VARIATION_DATE: + return KeyboardId.MODE_DATE; + case InputType.TYPE_DATETIME_VARIATION_TIME: + return KeyboardId.MODE_TIME; + default: // InputType.TYPE_DATETIME_VARIATION_NORMAL + return KeyboardId.MODE_DATETIME; + } + case InputType.TYPE_CLASS_PHONE: + return KeyboardId.MODE_PHONE; + case InputType.TYPE_CLASS_TEXT: + if (InputTypeCompatUtils.isEmailVariation(variation)) { + return KeyboardId.MODE_EMAIL; + } else if (variation == InputType.TYPE_TEXT_VARIATION_URI) { + return KeyboardId.MODE_URL; + } else if (variation == InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE) { + return KeyboardId.MODE_IM; + } else if (variation == InputType.TYPE_TEXT_VARIATION_FILTER) { + return KeyboardId.MODE_TEXT; + } else { + return KeyboardId.MODE_TEXT; + } + default: + return KeyboardId.MODE_TEXT; + } + } } public static String parseKeyboardLocale(Resources res, int resId) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index 78e0ee230..decd73d45 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -41,7 +41,7 @@ import com.android.inputmethod.compat.FrameLayoutCompatUtils; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; import java.util.HashMap; @@ -853,7 +853,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { if (key.mLabel != null) { // TODO Should take care of temporaryShiftLabel here. previewText.setCompoundDrawables(null, null, null, null); - if (Utils.codePointCount(key.mLabel) > 1) { + if (StringUtils.codePointCount(key.mLabel) > 1) { previewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, params.mKeyLetterSize); previewText.setTypeface(Typeface.DEFAULT_BOLD); } else { diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index afc4932e9..0a0307500 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -46,6 +46,8 @@ import com.android.inputmethod.latin.LatinIME; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.StaticInnerHandlerWrapper; +import com.android.inputmethod.latin.StringUtils; +import com.android.inputmethod.latin.SubtypeUtils; import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.Utils.UsabilityStudyLogUtils; @@ -779,12 +781,13 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke // Whether space key needs to show the "..." popup hint for special purposes if (mIsSpacebarTriggeringPopupByLongPress - && Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { + && SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes( + true /* include aux subtypes */)) { drawKeyPopupHint(key, canvas, paint, params); } } else if (key.mCode == Keyboard.CODE_LANGUAGE_SWITCH) { super.onDrawKeyTopVisuals(key, canvas, paint, params); - if (Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { + if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { drawKeyPopupHint(key, canvas, paint, params); } } else { @@ -810,7 +813,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke paint.setTextAlign(Align.CENTER); paint.setTypeface(Typeface.DEFAULT); // Estimate appropriate language name text size to fit in maxTextWidth. - String language = Utils.getFullDisplayName(locale, true); + String language = StringUtils.getFullDisplayName(locale, true); int textWidth = getTextWidth(paint, language, origTextSize); // Assuming text width and text size are proportional to each other. float textSize = origTextSize * Math.min(width / textWidth, 1.0f); @@ -822,7 +825,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke final boolean useShortName; if (useMiddleName) { - language = Utils.getMiddleDisplayLanguage(locale); + language = StringUtils.getMiddleDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize); textSize = origTextSize * Math.min(width / textWidth, 1.0f); useShortName = (textSize / origTextSize < MINIMUM_SCALE_OF_LANGUAGE_NAME) @@ -832,7 +835,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke } if (useShortName) { - language = Utils.getShortDisplayLanguage(locale); + language = StringUtils.getShortDisplayLanguage(locale); textWidth = getTextWidth(paint, language, origTextSize); textSize = origTextSize * Math.min(width / textWidth, 1.0f); } diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java index 9f735cff7..904a81de4 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java @@ -22,7 +22,7 @@ import android.graphics.drawable.Drawable; import com.android.inputmethod.keyboard.internal.KeySpecParser; import com.android.inputmethod.keyboard.internal.KeyboardIconsSet; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; public class MoreKeysKeyboard extends Keyboard { private final int mDefaultKeyCoordX; @@ -301,7 +301,7 @@ public class MoreKeysKeyboard extends Keyboard { for (String moreKeySpec : parentKey.mMoreKeys) { final String label = KeySpecParser.getLabel(moreKeySpec); // If the label is single letter, minKeyWidth is enough to hold the label. - if (label != null && Utils.codePointCount(label) > 1) { + if (label != null && StringUtils.codePointCount(label) > 1) { if (paint == null) { paint = new Paint(); paint.setAntiAlias(true); diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index f96f71e8a..582509324 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -19,7 +19,7 @@ package com.android.inputmethod.keyboard; import android.graphics.Rect; import com.android.inputmethod.keyboard.Keyboard.Params.TouchPositionCorrection; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.JniUtils; import com.android.inputmethod.latin.spellcheck.SpellCheckerProximityInfo; import java.util.Arrays; @@ -81,7 +81,7 @@ public class ProximityInfo { private long mNativeProximityInfo; static { - Utils.loadNativeLibrary(); + JniUtils.loadNativeLibrary(); } private native long setProximityInfoNative(int maxProximityCharsSize, int displayWidth, diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index e3fea3dce..0aba813b2 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -22,7 +22,7 @@ import android.text.TextUtils; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.LatinImeLogger; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Utils; +import com.android.inputmethod.latin.StringUtils; import java.util.ArrayList; import java.util.Arrays; @@ -150,7 +150,7 @@ public class KeySpecParser { } final String outputText = getOutputTextInternal(moreKeySpec); if (outputText != null) { - if (Utils.codePointCount(outputText) == 1) { + if (StringUtils.codePointCount(outputText) == 1) { // If output text is one code point, it should be treated as a code. // See {@link #getCode(Resources, String)}. return null; @@ -165,7 +165,7 @@ public class KeySpecParser { throw new KeySpecParserError("Empty label: " + moreKeySpec); } // Code is automatically generated for one letter label. See {@link getCode()}. - return (Utils.codePointCount(label) == 1) ? null : label; + return (StringUtils.codePointCount(label) == 1) ? null : label; } public static int getCode(Resources res, String moreKeySpec) { @@ -184,14 +184,14 @@ public class KeySpecParser { if (outputText != null) { // If output text is one code point, it should be treated as a code. // See {@link #getOutputText(String)}. - if (Utils.codePointCount(outputText) == 1) { + if (StringUtils.codePointCount(outputText) == 1) { return outputText.codePointAt(0); } return Keyboard.CODE_OUTPUT_TEXT; } final String label = getLabel(moreKeySpec); // Code is automatically generated for one letter label. - if (Utils.codePointCount(label) == 1) { + if (StringUtils.codePointCount(label) == 1) { return label.codePointAt(0); } return Keyboard.CODE_OUTPUT_TEXT; @@ -393,7 +393,7 @@ public class KeySpecParser { if (size == 0) { return null; } - if (Utils.codePointCount(text) == 1) { + if (StringUtils.codePointCount(text) == 1) { return text.codePointAt(0) == COMMA ? null : new String[] { text }; } diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 90ced6028..31ff4e7b4 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -104,7 +104,7 @@ public class BinaryDictionary extends Dictionary { } static { - Utils.loadNativeLibrary(); + JniUtils.loadNativeLibrary(); } private native long openNative(String sourceDir, long dictOffset, long dictSize, diff --git a/java/src/com/android/inputmethod/latin/DictionaryFactory.java b/java/src/com/android/inputmethod/latin/DictionaryFactory.java index 1607f86a8..7a81f7bd5 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryFactory.java +++ b/java/src/com/android/inputmethod/latin/DictionaryFactory.java @@ -164,7 +164,7 @@ public class DictionaryFactory { final Resources res = context.getResources(); final Locale saveLocale = LocaleUtils.setSystemLocale(res, locale); - final int resourceId = Utils.getMainDictionaryResourceId(res); + final int resourceId = getMainDictionaryResourceId(res); final AssetFileDescriptor afd = res.openRawResourceFd(resourceId); final boolean hasDictionary = isFullDictionary(afd); try { @@ -182,7 +182,7 @@ public class DictionaryFactory { final Resources res = context.getResources(); final Locale saveLocale = LocaleUtils.setSystemLocale(res, locale); - final int resourceId = Utils.getMainDictionaryResourceId(res); + final int resourceId = getMainDictionaryResourceId(res); final AssetFileDescriptor afd = res.openRawResourceFd(resourceId); final Long size = (afd != null && afd.getLength() > PLACEHOLDER_LENGTH) ? afd.getLength() @@ -209,4 +209,14 @@ public class DictionaryFactory { protected static boolean isFullDictionary(final AssetFileDescriptor afd) { return (afd != null && afd.getLength() > PLACEHOLDER_LENGTH); } + + /** + * 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); + } } diff --git a/java/src/com/android/inputmethod/latin/JniUtils.java b/java/src/com/android/inputmethod/latin/JniUtils.java new file mode 100644 index 000000000..4808b867a --- /dev/null +++ b/java/src/com/android/inputmethod/latin/JniUtils.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2012 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.util.Log; + +import com.android.inputmethod.latin.define.JniLibName; + +public class JniUtils { + private static final String TAG = JniUtils.class.getSimpleName(); + + private JniUtils() { + // This utility class is not publicly instantiable. + } + + public static void loadNativeLibrary() { + try { + System.loadLibrary(JniLibName.JNI_LIB_NAME); + } catch (UnsatisfiedLinkError ule) { + Log.e(TAG, "Could not load native library " + JniLibName.JNI_LIB_NAME); + if (LatinImeLogger.sDBG) { + throw new RuntimeException( + "Could not load native library " + JniLibName.JNI_LIB_NAME); + } + } + } +} diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 1858db949..c16a34fac 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -44,8 +44,8 @@ import android.view.HapticFeedbackConstants; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; -import android.view.ViewParent; import android.view.ViewGroup.LayoutParams; +import android.view.ViewParent; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.ExtractedText; @@ -576,7 +576,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar oldContactsDictionary = null; } - int mainDicResId = Utils.getMainDictionaryResourceId(res); + int mainDicResId = DictionaryFactory.getMainDictionaryResourceId(res); mSuggest = new Suggest(this, mainDicResId, keyboardLocale); if (mSettingsValues.mAutoCorrectEnabled) { mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); @@ -636,7 +636,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar /* package private */ void resetSuggestMainDict() { final String localeStr = mSubtypeSwitcher.getInputLocaleStr(); final Locale keyboardLocale = LocaleUtils.constructLocaleFromString(localeStr); - int mainDicResId = Utils.getMainDictionaryResourceId(mResources); + int mainDicResId = DictionaryFactory.getMainDictionaryResourceId(mResources); mSuggest.resetMainDict(this, mainDicResId, keyboardLocale); } @@ -745,12 +745,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar + String.format("inputType=0x%08x imeOptions=0x%08x", editorInfo.inputType, editorInfo.imeOptions)); } - if (Utils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) { + if (StringUtils.inPrivateImeOptions(null, IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use " + getPackageName() + "." + IME_OPTION_NO_MICROPHONE + " instead"); } - if (Utils.inPrivateImeOptions(getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) { + if (StringUtils.inPrivateImeOptions(getPackageName(), IME_OPTION_FORCE_ASCII, editorInfo)) { Log.w(TAG, "Deprecated private IME option specified: " + editorInfo.privateImeOptions); Log.w(TAG, "Use EditorInfo.IME_FLAG_FORCE_ASCII flag instead"); @@ -1207,7 +1207,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (ic == null) return false; final CharSequence lastThree = ic.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 - && Utils.canBeFollowedByPeriod(lastThree.charAt(0)) + && StringUtils.canBeFollowedByPeriod(lastThree.charAt(0)) && lastThree.charAt(1) == Keyboard.CODE_SPACE && lastThree.charAt(2) == Keyboard.CODE_SPACE && mHandler.isAcceptingDoubleSpaces()) { @@ -1247,7 +1247,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (isShowingOptionDialog()) return; if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) { showSubtypeSelectorAndSettings(); - } else if (Utils.hasMultipleEnabledIMEsOrSubtypes(false /* exclude aux subtypes */)) { + } else if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes( + false /* exclude aux subtypes */)) { showOptionsMenu(); } else { launchSettings(); @@ -1263,7 +1264,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (isShowingOptionDialog()) return false; switch (requestCode) { case CODE_SHOW_INPUT_METHOD_PICKER: - if (Utils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { + if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes(true /* include aux subtypes */)) { mImm.showInputMethodPicker(); return true; } @@ -1295,7 +1296,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final IBinder token = getWindow().getWindow().getAttributes().token; if (mShouldSwitchToLastSubtype) { final InputMethodSubtypeCompatWrapper lastSubtype = mImm.getLastInputMethodSubtype(); - final boolean lastSubtypeBelongsToThisIme = Utils.checkIfSubtypeBelongsToThisIme( + final boolean lastSubtypeBelongsToThisIme = SubtypeUtils.checkIfSubtypeBelongsToThisIme( this, lastSubtype); if ((includesOtherImes || lastSubtypeBelongsToThisIme) && mImm.switchToLastInputMethod(token)) { @@ -1884,7 +1885,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar builder.addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions); } } - if (Utils.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) { + if (Suggest.shouldBlockAutoCorrectionBySafetyNet(builder, mSuggest)) { builder.setShouldBlockAutoCorrectionBySafetyNet(); } showSuggestions(builder.build(), typedWord); @@ -2486,7 +2487,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar switch (position) { case 0: Intent intent = CompatUtils.getInputLanguageSelectionIntent( - Utils.getInputMethodId(getPackageName()), + SubtypeUtils.getInputMethodId(getPackageName()), Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_CLEAR_TOP); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 305cef22d..72391f31e 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -343,7 +343,7 @@ public class Settings extends InputMethodSettingsActivity @Override public boolean onPreferenceClick(Preference pref) { if (pref == mInputLanguageSelection) { - final String imeId = Utils.getInputMethodId( + final String imeId = SubtypeUtils.getInputMethodId( getActivityInternal().getApplicationInfo().packageName); startActivity(CompatUtils.getInputLanguageSelectionIntent(imeId, 0)); return true; diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 69e45f619..abd1dc692 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -326,9 +326,9 @@ public class SettingsValues { return false; } if (mIncludesOtherImesInLanguageSwitchList) { - return Utils.hasMultipleEnabledIMEsOrSubtypes(/* include aux subtypes */false); + return SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes(/* include aux subtypes */false); } else { - return Utils.hasMultipleEnabledSubtypesInThisIme( + return SubtypeUtils.hasMultipleEnabledSubtypesInThisIme( context, /* include aux subtypes */false); } } diff --git a/java/src/com/android/inputmethod/latin/StringUtils.java b/java/src/com/android/inputmethod/latin/StringUtils.java new file mode 100644 index 000000000..81c3b4edf --- /dev/null +++ b/java/src/com/android/inputmethod/latin/StringUtils.java @@ -0,0 +1,198 @@ +/* + * Copyright (C) 2012 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.text.TextUtils; +import android.view.inputmethod.EditorInfo; + +import com.android.inputmethod.keyboard.Keyboard; + +import java.util.ArrayList; +import java.util.Locale; + +public class StringUtils { + private StringUtils() { + // This utility class is not publicly instantiable. + } + + public static boolean canBeFollowedByPeriod(final int codePoint) { + // TODO: Check again whether there really ain't a better way to check this. + // TODO: This should probably be language-dependant... + return Character.isLetterOrDigit(codePoint) + || codePoint == Keyboard.CODE_SINGLE_QUOTE + || codePoint == Keyboard.CODE_DOUBLE_QUOTE + || codePoint == Keyboard.CODE_CLOSING_PARENTHESIS + || codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET + || codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET + || codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET; + } + + public static int codePointCount(String text) { + if (TextUtils.isEmpty(text)) return 0; + return text.codePointCount(0, text.length()); + } + + 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 editorInfo) { + if (editorInfo == null) + return false; + return containsInCsv(packageName != null ? packageName + "." + key : key, + editorInfo.privateImeOptions); + } + + /** + * Returns true if a and b are equal ignoring the case of the character. + * @param a first character to check + * @param b second character to check + * @return {@code true} if a and b are equal, {@code false} otherwise. + */ + public static boolean equalsIgnoreCase(char a, char b) { + // Some language, such as Turkish, need testing both cases. + return a == b + || Character.toLowerCase(a) == Character.toLowerCase(b) + || Character.toUpperCase(a) == Character.toUpperCase(b); + } + + /** + * Returns true if a and b are equal ignoring the case of the characters, including if they are + * both null. + * @param a first CharSequence to check + * @param b second CharSequence to check + * @return {@code true} if a and b are equal, {@code false} otherwise. + */ + public static boolean equalsIgnoreCase(CharSequence a, CharSequence b) { + if (a == b) + return true; // including both a and b are null. + if (a == null || b == null) + return false; + final int length = a.length(); + if (length != b.length()) + return false; + for (int i = 0; i < length; i++) { + if (!equalsIgnoreCase(a.charAt(i), b.charAt(i))) + return false; + } + return true; + } + + /** + * Returns true if a and b are equal ignoring the case of the characters, including if a is null + * and b is zero length. + * @param a CharSequence to check + * @param b character array to check + * @param offset start offset of array b + * @param length length of characters in array b + * @return {@code true} if a and b are equal, {@code false} otherwise. + * @throws IndexOutOfBoundsException + * if {@code offset < 0 || length < 0 || offset + length > data.length}. + * @throws NullPointerException if {@code b == null}. + */ + public static boolean equalsIgnoreCase(CharSequence a, char[] b, int offset, int length) { + if (offset < 0 || length < 0 || length > b.length - offset) + throw new IndexOutOfBoundsException("array.length=" + b.length + " offset=" + offset + + " length=" + length); + if (a == null) + return length == 0; // including a is null and b is zero length. + if (a.length() != length) + return false; + for (int i = 0; i < length; i++) { + if (!equalsIgnoreCase(a.charAt(i), b[offset + i])) + return false; + } + return true; + } + + /** + * Remove duplicates from an array of strings. + * + * This method will always keep the first occurence of all strings at their position + * in the array, removing the subsequent ones. + */ + public static void removeDupes(final ArrayList suggestions) { + if (suggestions.size() < 2) return; + int i = 1; + // Don't cache suggestions.size(), since we may be removing items + while (i < suggestions.size()) { + final CharSequence cur = suggestions.get(i); + // Compare each suggestion with each previous suggestion + for (int j = 0; j < i; j++) { + CharSequence previous = suggestions.get(j); + if (TextUtils.equals(cur, previous)) { + removeFromSuggestions(suggestions, i); + i--; + break; + } + } + i++; + } + } + + private static void removeFromSuggestions(final ArrayList suggestions, + final int index) { + final CharSequence garbage = suggestions.remove(index); + if (garbage instanceof StringBuilder) { + StringBuilderPool.recycle((StringBuilder)garbage); + } + } + + public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { + if (returnsNameInThisLocale) { + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); + } else { + return toTitleCase(locale.getDisplayName(), locale); + } + } + + public static String getDisplayLanguage(Locale locale) { + return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); + } + + public static String getMiddleDisplayLanguage(Locale locale) { + return toTitleCase((LocaleUtils.constructLocaleFromString( + locale.getLanguage()).getDisplayLanguage(locale)), locale); + } + + public static String getShortDisplayLanguage(Locale locale) { + return toTitleCase(locale.getLanguage(), locale); + } + + public static String toTitleCase(String s, Locale locale) { + if (s.length() <= 1) { + // TODO: is this really correct? Shouldn't this be s.toUpperCase()? + return s; + } + // TODO: fix the bugs below + // - This does not work for Greek, because it returns upper case instead of title case. + // - It does not work for Serbian, because it fails to account for the "lj" character, + // which should be "Lj" in title case and "LJ" in upper case. + // - It does not work for Dutch, because it fails to account for the "ij" digraph, which + // are two different characters but both should be capitalized as "IJ" as if they were + // a single letter. + // - It also does not work with unicode surrogate code points. + return s.toUpperCase(locale).charAt(0) + s.substring(1); + } +} diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index f5778167a..ffbbf9bb8 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -512,7 +512,7 @@ public class SubtypeSwitcher { } public String getInputLanguageName() { - return Utils.getDisplayLanguage(getInputLocale()); + return StringUtils.getDisplayLanguage(getInputLocale()); } ///////////////////////////// diff --git a/java/src/com/android/inputmethod/latin/SubtypeUtils.java b/java/src/com/android/inputmethod/latin/SubtypeUtils.java new file mode 100644 index 000000000..cb2bcf43f --- /dev/null +++ b/java/src/com/android/inputmethod/latin/SubtypeUtils.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2012 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.Context; + +import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; +import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; +import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; + +import java.util.Collections; +import java.util.List; + +public class SubtypeUtils { + private SubtypeUtils() { + // This utility class is not publicly instantiable. + } + + // TODO: Cache my InputMethodInfo and/or InputMethodSubtype list. + public static boolean checkIfSubtypeBelongsToThisIme(Context context, + InputMethodSubtypeCompatWrapper ims) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) return false; + + final InputMethodInfoCompatWrapper myImi = getInputMethodInfo(context.getPackageName()); + final List subtypes = + imm.getEnabledInputMethodSubtypeList(myImi, true); + for (final InputMethodSubtypeCompatWrapper subtype : subtypes) { + if (subtype.equals(ims)) { + return true; + } + } + return false; + } + + public static boolean hasMultipleEnabledIMEsOrSubtypes( + final boolean shouldIncludeAuxiliarySubtypes) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) return false; + + final List enabledImis = imm.getEnabledInputMethodList(); + return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis); + } + + public static boolean hasMultipleEnabledSubtypesInThisIme(Context context, + final boolean shouldIncludeAuxiliarySubtypes) { + final InputMethodInfoCompatWrapper myImi = getInputMethodInfo(context.getPackageName()); + final List imiList = Collections.singletonList(myImi); + return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList); + } + + private static boolean hasMultipleEnabledSubtypes(final boolean shouldIncludeAuxiliarySubtypes, + List imiList) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) return false; + + // Number of the filtered IMEs + int filteredImisCount = 0; + + for (InputMethodInfoCompatWrapper imi : imiList) { + // We can return true immediately after we find two or more filtered IMEs. + if (filteredImisCount > 1) return true; + final List subtypes = + imm.getEnabledInputMethodSubtypeList(imi, true); + // IMEs that have no subtypes should be counted. + if (subtypes.isEmpty()) { + ++filteredImisCount; + continue; + } + + int auxCount = 0; + for (InputMethodSubtypeCompatWrapper subtype : subtypes) { + if (subtype.isAuxiliary()) { + ++auxCount; + } + } + final int nonAuxCount = subtypes.size() - auxCount; + + // IMEs that have one or more non-auxiliary subtypes should be counted. + // If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary + // subtypes should be counted as well. + if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) { + ++filteredImisCount; + continue; + } + } + + if (filteredImisCount > 1) { + return true; + } + final List subtypes = + imm.getEnabledInputMethodSubtypeList(null, true); + int keyboardCount = 0; + // imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's + // both explicitly and implicitly enabled input method subtype. + // (The current IME should be LatinIME.) + for (InputMethodSubtypeCompatWrapper subtype : subtypes) { + if (SubtypeSwitcher.KEYBOARD_MODE.equals(subtype.getMode())) { + ++keyboardCount; + } + } + return keyboardCount > 1; + } + + public static String getInputMethodId(String packageName) { + return getInputMethodInfo(packageName).getId(); + } + + public static InputMethodInfoCompatWrapper getInputMethodInfo(String packageName) { + final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); + if (imm == null) { + throw new RuntimeException("Input method manager not found"); + } + + for (final InputMethodInfoCompatWrapper imi : imm.getEnabledInputMethodList()) { + if (imi.getPackageName().equals(packageName)) + return imi; + } + throw new RuntimeException("Can not find input method id for " + packageName); + } +} diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 298ead665..671fb905d 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -108,6 +108,8 @@ public class Suggest implements Dictionary.WordCallback { private boolean mIsAllUpperCase; private int mTrailingSingleQuotesCount; + private static final int MINIMUM_SAFETY_NET_CHAR_LENGTH = 4; + public Suggest(final Context context, final int dictionaryResId, final Locale locale) { initAsynchronously(context, dictionaryResId, locale); } @@ -383,7 +385,7 @@ public class Suggest implements Dictionary.WordCallback { if (typedWord != null) { mSuggestions.add(0, typedWord.toString()); } - Utils.removeDupes(mSuggestions); + StringUtils.removeDupes(mSuggestions); if (DBG) { double normalizedScore = mAutoCorrection.getNormalizedScore(); @@ -434,7 +436,7 @@ public class Suggest implements Dictionary.WordCallback { int pos = 0; // Check if it's the same word, only caps are different - if (Utils.equalsIgnoreCase(mConsideredWord, word, offset, length)) { + if (StringUtils.equalsIgnoreCase(mConsideredWord, word, offset, length)) { // TODO: remove this surrounding if clause and move this logic to // getSuggestedWordBuilder. if (suggestions.size() > 0) { @@ -443,7 +445,7 @@ public class Suggest implements Dictionary.WordCallback { // frequency to determine the insertion position. This does not ensure strictly // correct ordering, but ensures the top score is on top which is enough for // removing duplicates correctly. - if (Utils.equalsIgnoreCase(currentHighestWord, word, offset, length) + if (StringUtils.equalsIgnoreCase(currentHighestWord, word, offset, length) && score <= sortedScores[0]) { pos = 1; } @@ -558,4 +560,46 @@ public class Suggest implements Dictionary.WordCallback { } mMainDict = null; } + + // TODO: Resolve the inconsistencies between the native auto correction algorithms and + // this safety net + public static boolean shouldBlockAutoCorrectionBySafetyNet( + SuggestedWords.Builder suggestedWordsBuilder, Suggest suggest) { + // Safety net for auto correction. + // Actually if we hit this safety net, it's actually a bug. + if (suggestedWordsBuilder.size() <= 1 || suggestedWordsBuilder.isTypedWordValid()) { + return false; + } + // If user selected aggressive auto correction mode, there is no need to use the safety + // net. + if (suggest.isAggressiveAutoCorrectionMode()) { + return false; + } + final CharSequence typedWord = suggestedWordsBuilder.getWord(0); + // If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH, + // we should not use net because relatively edit distance can be big. + if (typedWord.length() < Suggest.MINIMUM_SAFETY_NET_CHAR_LENGTH) { + return false; + } + final CharSequence suggestionWord = suggestedWordsBuilder.getWord(1); + final int typedWordLength = typedWord.length(); + final int maxEditDistanceOfNativeDictionary = + (typedWordLength < 5 ? 2 : typedWordLength / 2) + 1; + final int distance = BinaryDictionary.editDistance( + typedWord.toString(), suggestionWord.toString()); + if (DBG) { + Log.d(TAG, "Autocorrected edit distance = " + distance + + ", " + maxEditDistanceOfNativeDictionary); + } + if (distance > maxEditDistanceOfNativeDictionary) { + if (DBG) { + Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); + Log.e(TAG, "(Error) The edit distance of this correction exceeds limit. " + + "Turning off auto-correction."); + } + return true; + } else { + return false; + } + } } diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index a8679e07a..f8dd5ae42 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -19,7 +19,6 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.content.res.Resources; import android.inputmethodservice.InputMethodService; import android.net.Uri; import android.os.AsyncTask; @@ -27,19 +26,9 @@ import android.os.Environment; import android.os.Handler; import android.os.HandlerThread; import android.os.Process; -import android.text.InputType; import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; -import android.view.inputmethod.EditorInfo; - -import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; -import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; -import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; -import com.android.inputmethod.compat.InputTypeCompatUtils; -import com.android.inputmethod.keyboard.Keyboard; -import com.android.inputmethod.keyboard.KeyboardId; -import com.android.inputmethod.latin.define.JniLibName; import java.io.BufferedReader; import java.io.File; @@ -51,20 +40,11 @@ import java.io.IOException; import java.io.PrintWriter; import java.nio.channels.FileChannel; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Collections; import java.util.Date; -import java.util.List; -import java.util.Locale; public class Utils { - private static final String TAG = Utils.class.getSimpleName(); - private static final int MINIMUM_SAFETY_NET_CHAR_LENGTH = 4; - private static boolean DBG = LatinImeLogger.sDBG; - private static boolean DBG_EDIT_DISTANCE = false; - private Utils() { - // Intentional empty constructor for utility class. + // This utility class is not publicly instantiable. } /** @@ -118,166 +98,6 @@ public class Utils { } } - // TODO: Move InputMethodSubtype related utility methods to its own utility class. - // TODO: Cache my InputMethodInfo and/or InputMethodSubtype list. - public static boolean checkIfSubtypeBelongsToThisIme(Context context, - InputMethodSubtypeCompatWrapper ims) { - final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); - if (imm == null) return false; - - final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo( - context.getPackageName()); - final List subtypes = - imm.getEnabledInputMethodSubtypeList(myImi, true); - for (final InputMethodSubtypeCompatWrapper subtype : subtypes) { - if (subtype.equals(ims)) { - return true; - } - } - return false; - } - - public static boolean hasMultipleEnabledIMEsOrSubtypes( - final boolean shouldIncludeAuxiliarySubtypes) { - final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); - if (imm == null) return false; - - final List enabledImis = imm.getEnabledInputMethodList(); - return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, enabledImis); - } - - public static boolean hasMultipleEnabledSubtypesInThisIme(Context context, - final boolean shouldIncludeAuxiliarySubtypes) { - final InputMethodInfoCompatWrapper myImi = Utils.getInputMethodInfo( - context.getPackageName()); - final List imiList = Collections.singletonList(myImi); - return Utils.hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList); - } - - private static boolean hasMultipleEnabledSubtypes(final boolean shouldIncludeAuxiliarySubtypes, - List imiList) { - final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); - if (imm == null) return false; - - // Number of the filtered IMEs - int filteredImisCount = 0; - - for (InputMethodInfoCompatWrapper imi : imiList) { - // We can return true immediately after we find two or more filtered IMEs. - if (filteredImisCount > 1) return true; - final List subtypes = - imm.getEnabledInputMethodSubtypeList(imi, true); - // IMEs that have no subtypes should be counted. - if (subtypes.isEmpty()) { - ++filteredImisCount; - continue; - } - - int auxCount = 0; - for (InputMethodSubtypeCompatWrapper subtype : subtypes) { - if (subtype.isAuxiliary()) { - ++auxCount; - } - } - final int nonAuxCount = subtypes.size() - auxCount; - - // IMEs that have one or more non-auxiliary subtypes should be counted. - // If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary - // subtypes should be counted as well. - if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) { - ++filteredImisCount; - continue; - } - } - - if (filteredImisCount > 1) { - return true; - } - final List subtypes = - imm.getEnabledInputMethodSubtypeList(null, true); - int keyboardCount = 0; - // imm.getEnabledInputMethodSubtypeList(null, true) will return the current IME's - // both explicitly and implicitly enabled input method subtype. - // (The current IME should be LatinIME.) - for (InputMethodSubtypeCompatWrapper subtype : subtypes) { - if (SubtypeSwitcher.KEYBOARD_MODE.equals(subtype.getMode())) { - ++keyboardCount; - } - } - return keyboardCount > 1; - } - - public static String getInputMethodId(String packageName) { - return getInputMethodInfo(packageName).getId(); - } - - public static InputMethodInfoCompatWrapper getInputMethodInfo(String packageName) { - final InputMethodManagerCompatWrapper imm = InputMethodManagerCompatWrapper.getInstance(); - if (imm == null) { - throw new RuntimeException("Input method manager not found"); - } - - for (final InputMethodInfoCompatWrapper imi : imm.getEnabledInputMethodList()) { - if (imi.getPackageName().equals(packageName)) - return imi; - } - throw new RuntimeException("Can not find input method id for " + packageName); - } - - // TODO: Resolve the inconsistencies between the native auto correction algorithms and - // this safety net - public static boolean shouldBlockAutoCorrectionBySafetyNet( - SuggestedWords.Builder suggestedWordsBuilder, Suggest suggest) { - // Safety net for auto correction. - // Actually if we hit this safety net, it's actually a bug. - if (suggestedWordsBuilder.size() <= 1 || suggestedWordsBuilder.isTypedWordValid()) { - return false; - } - // If user selected aggressive auto correction mode, there is no need to use the safety - // net. - if (suggest.isAggressiveAutoCorrectionMode()) { - return false; - } - final CharSequence typedWord = suggestedWordsBuilder.getWord(0); - // If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH, - // we should not use net because relatively edit distance can be big. - if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) { - return false; - } - final CharSequence suggestionWord = suggestedWordsBuilder.getWord(1); - final int typedWordLength = typedWord.length(); - final int maxEditDistanceOfNativeDictionary = - (typedWordLength < 5 ? 2 : typedWordLength / 2) + 1; - final int distance = BinaryDictionary.editDistance( - typedWord.toString(), suggestionWord.toString()); - if (DBG) { - Log.d(TAG, "Autocorrected edit distance = " + distance - + ", " + maxEditDistanceOfNativeDictionary); - } - if (distance > maxEditDistanceOfNativeDictionary) { - if (DBG) { - Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); - Log.e(TAG, "(Error) The edit distance of this correction exceeds limit. " - + "Turning off auto-correction."); - } - return true; - } else { - return false; - } - } - - public static boolean canBeFollowedByPeriod(final int codePoint) { - // TODO: Check again whether there really ain't a better way to check this. - // TODO: This should probably be language-dependant... - return Character.isLetterOrDigit(codePoint) - || codePoint == Keyboard.CODE_SINGLE_QUOTE - || codePoint == Keyboard.CODE_DOUBLE_QUOTE - || codePoint == Keyboard.CODE_CLOSING_PARENTHESIS - || codePoint == Keyboard.CODE_CLOSING_SQUARE_BRACKET - || codePoint == Keyboard.CODE_CLOSING_CURLY_BRACKET - || codePoint == Keyboard.CODE_CLOSING_ANGLE_BRACKET; - } - /* package */ static class RingCharBuffer { private static RingCharBuffer sRingCharBuffer = new RingCharBuffer(); private static final char PLACEHOLDER_DELIMITER_CHAR = '\uFFFC'; @@ -600,147 +420,6 @@ public class Utils { } } - // TODO: Move this method to KeyboardSet class. - public static int getKeyboardMode(EditorInfo editorInfo) { - if (editorInfo == null) - return KeyboardId.MODE_TEXT; - - final int inputType = editorInfo.inputType; - final int variation = inputType & InputType.TYPE_MASK_VARIATION; - - switch (inputType & InputType.TYPE_MASK_CLASS) { - case InputType.TYPE_CLASS_NUMBER: - return KeyboardId.MODE_NUMBER; - case InputType.TYPE_CLASS_DATETIME: - switch (variation) { - case InputType.TYPE_DATETIME_VARIATION_DATE: - return KeyboardId.MODE_DATE; - case InputType.TYPE_DATETIME_VARIATION_TIME: - return KeyboardId.MODE_TIME; - default: // InputType.TYPE_DATETIME_VARIATION_NORMAL - return KeyboardId.MODE_DATETIME; - } - case InputType.TYPE_CLASS_PHONE: - return KeyboardId.MODE_PHONE; - case InputType.TYPE_CLASS_TEXT: - if (InputTypeCompatUtils.isEmailVariation(variation)) { - return KeyboardId.MODE_EMAIL; - } else if (variation == InputType.TYPE_TEXT_VARIATION_URI) { - return KeyboardId.MODE_URL; - } else if (variation == InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE) { - return KeyboardId.MODE_IM; - } else if (variation == InputType.TYPE_TEXT_VARIATION_FILTER) { - return KeyboardId.MODE_TEXT; - } else { - return KeyboardId.MODE_TEXT; - } - default: - return KeyboardId.MODE_TEXT; - } - } - - 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 editorInfo) { - if (editorInfo == null) - return false; - return containsInCsv(packageName != null ? packageName + "." + key : key, - editorInfo.privateImeOptions); - } - - /** - * 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); - } - - public static void loadNativeLibrary() { - try { - System.loadLibrary(JniLibName.JNI_LIB_NAME); - } catch (UnsatisfiedLinkError ule) { - Log.e(TAG, "Could not load native library " + JniLibName.JNI_LIB_NAME); - if (LatinImeLogger.sDBG) { - throw new RuntimeException( - "Could not load native library " + JniLibName.JNI_LIB_NAME); - } - } - } - - /** - * Returns true if a and b are equal ignoring the case of the character. - * @param a first character to check - * @param b second character to check - * @return {@code true} if a and b are equal, {@code false} otherwise. - */ - public static boolean equalsIgnoreCase(char a, char b) { - // Some language, such as Turkish, need testing both cases. - return a == b - || Character.toLowerCase(a) == Character.toLowerCase(b) - || Character.toUpperCase(a) == Character.toUpperCase(b); - } - - /** - * Returns true if a and b are equal ignoring the case of the characters, including if they are - * both null. - * @param a first CharSequence to check - * @param b second CharSequence to check - * @return {@code true} if a and b are equal, {@code false} otherwise. - */ - public static boolean equalsIgnoreCase(CharSequence a, CharSequence b) { - if (a == b) - return true; // including both a and b are null. - if (a == null || b == null) - return false; - final int length = a.length(); - if (length != b.length()) - return false; - for (int i = 0; i < length; i++) { - if (!equalsIgnoreCase(a.charAt(i), b.charAt(i))) - return false; - } - return true; - } - - /** - * Returns true if a and b are equal ignoring the case of the characters, including if a is null - * and b is zero length. - * @param a CharSequence to check - * @param b character array to check - * @param offset start offset of array b - * @param length length of characters in array b - * @return {@code true} if a and b are equal, {@code false} otherwise. - * @throws IndexOutOfBoundsException - * if {@code offset < 0 || length < 0 || offset + length > data.length}. - * @throws NullPointerException if {@code b == null}. - */ - public static boolean equalsIgnoreCase(CharSequence a, char[] b, int offset, int length) { - if (offset < 0 || length < 0 || length > b.length - offset) - throw new IndexOutOfBoundsException("array.length=" + b.length + " offset=" + offset - + " length=" + length); - if (a == null) - return length == 0; // including a is null and b is zero length. - if (a.length() != length) - return false; - for (int i = 0; i < length; i++) { - if (!equalsIgnoreCase(a.charAt(i), b[offset + i])) - return false; - } - return true; - } - public static float getDipScale(Context context) { final float scale = context.getResources().getDisplayMetrics().density; return scale; @@ -751,76 +430,6 @@ public class Utils { return (int) (dip * scale + 0.5); } - /** - * Remove duplicates from an array of strings. - * - * This method will always keep the first occurence of all strings at their position - * in the array, removing the subsequent ones. - */ - public static void removeDupes(final ArrayList suggestions) { - if (suggestions.size() < 2) return; - int i = 1; - // Don't cache suggestions.size(), since we may be removing items - while (i < suggestions.size()) { - final CharSequence cur = suggestions.get(i); - // Compare each suggestion with each previous suggestion - for (int j = 0; j < i; j++) { - CharSequence previous = suggestions.get(j); - if (TextUtils.equals(cur, previous)) { - removeFromSuggestions(suggestions, i); - i--; - break; - } - } - i++; - } - } - - private static void removeFromSuggestions(final ArrayList suggestions, - final int index) { - final CharSequence garbage = suggestions.remove(index); - if (garbage instanceof StringBuilder) { - StringBuilderPool.recycle((StringBuilder)garbage); - } - } - - public static String getFullDisplayName(Locale locale, boolean returnsNameInThisLocale) { - if (returnsNameInThisLocale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); - } else { - return toTitleCase(locale.getDisplayName(), locale); - } - } - - public static String getDisplayLanguage(Locale locale) { - return toTitleCase(SubtypeLocale.getFullDisplayName(locale), locale); - } - - public static String getMiddleDisplayLanguage(Locale locale) { - return toTitleCase((LocaleUtils.constructLocaleFromString( - locale.getLanguage()).getDisplayLanguage(locale)), locale); - } - - public static String getShortDisplayLanguage(Locale locale) { - return toTitleCase(locale.getLanguage(), locale); - } - - public static String toTitleCase(String s, Locale locale) { - if (s.length() <= 1) { - // TODO: is this really correct? Shouldn't this be s.toUpperCase()? - return s; - } - // TODO: fix the bugs below - // - This does not work for Greek, because it returns upper case instead of title case. - // - It does not work for Serbian, because it fails to account for the "lj" character, - // which should be "Lj" in title case and "LJ" in upper case. - // - It does not work for Dutch, because it fails to account for the "ij" digraph, which - // are two different characters but both should be capitalized as "IJ" as if they were - // a single letter. - // - It also does not work with unicode surrogate code points. - return s.toUpperCase(locale).charAt(0) + s.substring(1); - } - public static class Stats { public static void onNonSeparator(final char code, final int x, final int y) { @@ -845,9 +454,4 @@ public class Utils { LatinImeLogger.logOnAutoCorrectionCancelled(); } } - - public static int codePointCount(String text) { - if (TextUtils.isEmpty(text)) return 0; - return text.codePointCount(0, text.length()); - } } diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 755c75b2e..35a5c0f52 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -37,9 +37,9 @@ import com.android.inputmethod.latin.DictionaryFactory; import com.android.inputmethod.latin.Flag; import com.android.inputmethod.latin.LocaleUtils; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.StringUtils; import com.android.inputmethod.latin.SynchronouslyLoadedContactsDictionary; import com.android.inputmethod.latin.SynchronouslyLoadedUserDictionary; -import com.android.inputmethod.latin.Utils; import com.android.inputmethod.latin.WhitelistDictionary; import com.android.inputmethod.latin.WordComposer; @@ -47,11 +47,11 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.Locale; import java.util.Map; import java.util.TreeMap; -import java.util.HashSet; /** * Service for spell checking, using LatinIME's dictionaries and mechanisms. @@ -316,7 +316,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService } } Collections.reverse(mSuggestions); - Utils.removeDupes(mSuggestions); + StringUtils.removeDupes(mSuggestions); if (CAPITALIZE_ALL == capitalizeType) { for (int i = 0; i < mSuggestions.size(); ++i) { // get(i) returns a CharSequence which is actually a String so .toString() @@ -326,7 +326,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService } else if (CAPITALIZE_FIRST == capitalizeType) { for (int i = 0; i < mSuggestions.size(); ++i) { // Likewise - mSuggestions.set(i, Utils.toTitleCase(mSuggestions.get(i).toString(), + mSuggestions.set(i, StringUtils.toTitleCase(mSuggestions.get(i).toString(), locale)); } } @@ -396,7 +396,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService final ProximityInfo proximityInfo = ProximityInfo.createSpellCheckerProximityInfo( SpellCheckerProximityInfo.getProximityForScript(script)); final Resources resources = getResources(); - final int fallbackResourceId = Utils.getMainDictionaryResourceId(resources); + final int fallbackResourceId = DictionaryFactory.getMainDictionaryResourceId(resources); final DictionaryCollection dictionaryCollection = DictionaryFactory.createDictionaryFromManager(this, locale, fallbackResourceId, USE_FULL_EDIT_DISTANCE_FLAG_ARRAY); -- cgit v1.2.3-83-g751a From 911b8f9d19c1c4903eeef29b43176cfeaa0e5d0c Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 30 Mar 2012 16:08:11 +0900 Subject: Remove the "deprecated" classes bug: 6129704 Change-Id: Ib27f2774444e1f084b19be3fe6f56d25dffa7084 --- java/res/values/attrs.xml | 6 - java/res/values/strings.xml | 72 -- java/res/xml-ar/keyboard_set.xml | 3 +- java/res/xml-be/keyboard_set.xml | 3 +- java/res/xml-bg/keyboard_set.xml | 3 +- java/res/xml-cs/keyboard_set.xml | 3 +- java/res/xml-da/keyboard_set.xml | 3 +- java/res/xml-de-rZZ/keyboard_set.xml | 3 +- java/res/xml-de/keyboard_set.xml | 3 +- java/res/xml-el/keyboard_set.xml | 3 +- java/res/xml-es/keyboard_set.xml | 3 +- java/res/xml-et/keyboard_set.xml | 3 +- java/res/xml-fa/keyboard_set.xml | 3 +- java/res/xml-fi/keyboard_set.xml | 3 +- java/res/xml-fr-rCA/keyboard_set.xml | 3 +- java/res/xml-fr-rCH/keyboard_set.xml | 3 +- java/res/xml-fr/keyboard_set.xml | 3 +- java/res/xml-hi/keyboard_set.xml | 3 +- java/res/xml-hr/keyboard_set.xml | 3 +- java/res/xml-hu/keyboard_set.xml | 3 +- java/res/xml-is/keyboard_set.xml | 3 +- java/res/xml-iw/keyboard_set.xml | 3 +- java/res/xml-ka/keyboard_set.xml | 3 +- java/res/xml-ky/keyboard_set.xml | 3 +- java/res/xml-mk/keyboard_set.xml | 3 +- java/res/xml-nb/keyboard_set.xml | 3 +- java/res/xml-pl/keyboard_set.xml | 3 +- java/res/xml-pt/keyboard_set.xml | 3 +- java/res/xml-ro/keyboard_set.xml | 3 +- java/res/xml-ru/keyboard_set.xml | 3 +- java/res/xml-sk/keyboard_set.xml | 3 +- java/res/xml-sl/keyboard_set.xml | 3 +- java/res/xml-sr/keyboard_set.xml | 3 +- java/res/xml-sv/keyboard_set.xml | 3 +- java/res/xml-th/keyboard_set.xml | 3 +- java/res/xml-tr/keyboard_set.xml | 3 +- java/res/xml-uk/keyboard_set.xml | 3 +- java/res/xml-vi/keyboard_set.xml | 3 +- java/res/xml/keyboard_set.xml | 3 +- .../compat/InputMethodManagerCompatWrapper.java | 119 +-- .../compat/InputMethodServiceCompatWrapper.java | 4 - .../deprecated/LanguageSwitcherProxy.java | 90 --- .../android/inputmethod/deprecated/VoiceProxy.java | 854 --------------------- .../compat/VoiceInputLoggerCompatUtils.java | 36 - .../languageswitcher/InputLanguageSelection.java | 255 ------ .../languageswitcher/LanguageSwitcher.java | 234 ------ .../inputmethod/deprecated/voice/FieldContext.java | 104 --- .../inputmethod/deprecated/voice/Hints.java | 188 ----- .../deprecated/voice/RecognitionView.java | 355 --------- .../inputmethod/deprecated/voice/SettingsUtil.java | 110 --- .../deprecated/voice/SoundIndicator.java | 155 ---- .../inputmethod/deprecated/voice/VoiceInput.java | 692 ----------------- .../deprecated/voice/VoiceInputLogger.java | 266 ------- .../deprecated/voice/WaveformImage.java | 92 --- .../inputmethod/deprecated/voice/Whitelist.java | 68 -- .../android/inputmethod/keyboard/KeyboardSet.java | 26 - .../inputmethod/keyboard/LatinKeyboardView.java | 7 - .../com/android/inputmethod/latin/LatinIME.java | 106 +-- .../com/android/inputmethod/latin/Settings.java | 88 +-- .../android/inputmethod/latin/SubtypeSwitcher.java | 75 +- 60 files changed, 44 insertions(+), 4069 deletions(-) delete mode 100644 java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java delete mode 100644 java/src/com/android/inputmethod/deprecated/VoiceProxy.java delete mode 100644 java/src/com/android/inputmethod/deprecated/compat/VoiceInputLoggerCompatUtils.java delete mode 100644 java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java delete mode 100644 java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java delete mode 100644 java/src/com/android/inputmethod/deprecated/voice/FieldContext.java delete mode 100644 java/src/com/android/inputmethod/deprecated/voice/Hints.java delete mode 100644 java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java delete mode 100644 java/src/com/android/inputmethod/deprecated/voice/SettingsUtil.java delete mode 100644 java/src/com/android/inputmethod/deprecated/voice/SoundIndicator.java delete mode 100644 java/src/com/android/inputmethod/deprecated/voice/VoiceInput.java delete mode 100644 java/src/com/android/inputmethod/deprecated/voice/VoiceInputLogger.java delete mode 100644 java/src/com/android/inputmethod/deprecated/voice/WaveformImage.java delete mode 100644 java/src/com/android/inputmethod/deprecated/voice/Whitelist.java (limited to 'java/src/com/android/inputmethod/deprecated/VoiceProxy.java') diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml index 3d4e776a7..86f2abe72 100644 --- a/java/res/values/attrs.xml +++ b/java/res/values/attrs.xml @@ -403,12 +403,6 @@ - - - - - - diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index e1ac387fa..4f038e1a5 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -207,75 +207,6 @@ Phone symbols mode - - - - Voice input - - - Voice input is not currently supported for your language, but does work in English. - - - Voice input uses Google\'s speech recognition. The Mobile Privacy Policy applies. - - - To turn off voice input, go to input method settings. - - - To use voice input, press the microphone button. - - - Speak now - - - Working - - - - - - Error. Please try again. - - - Couldn\'t connect - - - Error, too much speech. - - - Audio problem - - - Server error - - - No speech heard - - - No matches found - - - Voice search not installed - - - Hint: Swipe across keyboard to speak - - - Hint: Next time, try speaking punctuation like \"period\", \"comma\", or \"question mark\". - - - Cancel - - - OK - Voice input key @@ -294,9 +225,6 @@ Voice input is disabled - - Select input method - Configure input methods diff --git a/java/res/xml-ar/keyboard_set.xml b/java/res/xml-ar/keyboard_set.xml index c37d128d7..88d320144 100644 --- a/java/res/xml-ar/keyboard_set.xml +++ b/java/res/xml-ar/keyboard_set.xml @@ -19,8 +19,7 @@ --> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin"> getEnabledInputMethodSubtypeList( InputMethodInfoCompatWrapper imi, boolean allowsImplicitlySelectedSubtypes) { - if (!SUBTYPE_SUPPORTED) { - String[] languages = mLanguageSwitcherProxy.getEnabledLanguages( - allowsImplicitlySelectedSubtypes); - List subtypeList = - new ArrayList(); - for (String lang: languages) { - subtypeList.add(new InputMethodSubtypeCompatWrapper(0, 0, lang, KEYBOARD_MODE, "")); - } - return subtypeList; - } Object retval = CompatUtils.invoke(mImm, null, METHOD_getEnabledInputMethodSubtypeList, (imi != null ? imi.getInputMethodInfo() : null), allowsImplicitlySelectedSubtypes); if (retval == null || !(retval instanceof List) || ((List)retval).isEmpty()) { @@ -228,16 +199,10 @@ public class InputMethodManagerCompatWrapper { } public boolean switchToLastInputMethod(IBinder token) { - if (SubtypeSwitcher.getInstance().isDummyVoiceMode()) { - return true; - } return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToLastInputMethod, token); } public boolean switchToNextInputMethod(IBinder token, boolean onlyCurrentIme) { - if (SubtypeSwitcher.getInstance().isDummyVoiceMode()) { - return true; - } return (Boolean)CompatUtils.invoke(mImm, false, METHOD_switchToNextInputMethod, token, onlyCurrentIme); } @@ -253,88 +218,6 @@ public class InputMethodManagerCompatWrapper { public void showInputMethodPicker() { if (mImm == null) return; - if (SUBTYPE_SUPPORTED) { - mImm.showInputMethodPicker(); - return; - } - - // The code below are based on {@link InputMethodManager#showInputMethodMenuInternal}. - - final InputMethodInfoCompatWrapper myImi = SubtypeUtils.getInputMethodInfo( - mLatinImePackageName); - final List myImsList = getEnabledInputMethodSubtypeList( - myImi, true); - final InputMethodSubtypeCompatWrapper currentIms = getCurrentInputMethodSubtype(); - final List imiList = getEnabledInputMethodList(); - imiList.remove(myImi); - final PackageManager pm = mPackageManager; - Collections.sort(imiList, new Comparator() { - @Override - public int compare(InputMethodInfoCompatWrapper imi1, - InputMethodInfoCompatWrapper imi2) { - final CharSequence imiId1 = imi1.loadLabel(pm) + "/" + imi1.getId(); - final CharSequence imiId2 = imi2.loadLabel(pm) + "/" + imi2.getId(); - return imiId1.toString().compareTo(imiId2.toString()); - } - }); - - final int myImsCount = myImsList.size(); - final int imiCount = imiList.size(); - final CharSequence[] items = new CharSequence[myImsCount + imiCount]; - - int checkedItem = 0; - int index = 0; - final CharSequence myImiLabel = myImi.loadLabel(mPackageManager); - for (int i = 0; i < myImsCount; i++) { - InputMethodSubtypeCompatWrapper ims = myImsList.get(i); - if (currentIms.equals(ims)) - checkedItem = index; - final CharSequence title = TextUtils.concat( - ims.getDisplayName(mService, mLatinImePackageName, mApplicationInfo), - " (" + myImiLabel, ")"); - items[index] = title; - index++; - } - - for (int i = 0; i < imiCount; i++) { - final InputMethodInfoCompatWrapper imi = imiList.get(i); - final CharSequence title = imi.loadLabel(mPackageManager); - items[index] = title; - index++; - } - - final InputMethodServiceCompatWrapper service = mService; - final OnClickListener buttonListener = new OnClickListener() { - @Override - public void onClick(DialogInterface di, int whichButton) { - final Intent intent = new Intent("android.settings.INPUT_METHOD_SETTINGS"); - intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED - | Intent.FLAG_ACTIVITY_CLEAR_TOP); - service.startActivity(intent); - } - }; - final IBinder token = service.getWindow().getWindow().getAttributes().token; - final OnClickListener selectionListener = new OnClickListener() { - @Override - public void onClick(DialogInterface di, int which) { - di.dismiss(); - if (which < myImsCount) { - final int imsIndex = which; - final InputMethodSubtypeCompatWrapper ims = myImsList.get(imsIndex); - service.notifyOnCurrentInputMethodSubtypeChanged(ims); - } else { - final int imiIndex = which - myImsCount; - final InputMethodInfoCompatWrapper imi = imiList.get(imiIndex); - setInputMethodAndSubtype(token, imi.getId(), null); - } - } - }; - - final AlertDialog.Builder builder = new AlertDialog.Builder(mService) - .setTitle(mService.getString(R.string.selectInputMethod)) - .setNeutralButton(R.string.configure_input_method, buttonListener) - .setSingleChoiceItems(items, checkedItem, selectionListener); - mService.showOptionDialogInternal(builder.create()); + mImm.showInputMethodPicker(); } } diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java index 8e2ee0f7a..7c15be300 100644 --- a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java +++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatWrapper.java @@ -23,7 +23,6 @@ import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.InputMethodSubtype; -import com.android.inputmethod.deprecated.LanguageSwitcherProxy; import com.android.inputmethod.keyboard.KeyboardSwitcher; import com.android.inputmethod.latin.SubtypeSwitcher; @@ -87,9 +86,6 @@ public class InputMethodServiceCompatWrapper extends InputMethodService { if (subtype != null) { if (!InputMethodManagerCompatWrapper.FORCE_ENABLE_VOICE_EVEN_WITH_NO_VOICE_SUBTYPES && !subtype.isDummy()) return; - if (!InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) { - LanguageSwitcherProxy.getInstance().setLocale(subtype.getLocale()); - } SubtypeSwitcher.getInstance().updateSubtype(subtype); } } diff --git a/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java b/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java deleted file mode 100644 index 290e6b554..000000000 --- a/java/src/com/android/inputmethod/deprecated/LanguageSwitcherProxy.java +++ /dev/null @@ -1,90 +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.deprecated; - -import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; -import com.android.inputmethod.deprecated.languageswitcher.LanguageSwitcher; -import com.android.inputmethod.latin.LatinIME; -import com.android.inputmethod.latin.Settings; - -import android.content.SharedPreferences; -import android.content.res.Configuration; - -import java.util.Locale; - -// This class is used only when the IME doesn't use method.xml for language switching. -public class LanguageSwitcherProxy implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final LanguageSwitcherProxy sInstance = new LanguageSwitcherProxy(); - private LatinIME mService; - private LanguageSwitcher mLanguageSwitcher; - private SharedPreferences mPrefs; - - public static LanguageSwitcherProxy getInstance() { - if (InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) return null; - return sInstance; - } - - public static void init(LatinIME service, SharedPreferences prefs) { - if (InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) return; - final Configuration conf = service.getResources().getConfiguration(); - sInstance.mLanguageSwitcher = new LanguageSwitcher(service); - sInstance.mLanguageSwitcher.loadLocales(prefs, conf.locale); - sInstance.mPrefs = prefs; - sInstance.mService = service; - prefs.registerOnSharedPreferenceChangeListener(sInstance); - } - - public static void onConfigurationChanged(Configuration conf) { - if (InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) return; - sInstance.mLanguageSwitcher.onConfigurationChanged(conf, sInstance.mPrefs); - } - - public static void loadSettings() { - if (InputMethodManagerCompatWrapper.SUBTYPE_SUPPORTED) return; - sInstance.mLanguageSwitcher.loadLocales(sInstance.mPrefs, null); - } - - public int getLocaleCount() { - return mLanguageSwitcher.getLocaleCount(); - } - - public String[] getEnabledLanguages(boolean allowImplicitlySelectedLanguages) { - return mLanguageSwitcher.getEnabledLanguages(allowImplicitlySelectedLanguages); - } - - public Locale getInputLocale() { - return mLanguageSwitcher.getInputLocale(); - } - - public void setLocale(String localeStr) { - mLanguageSwitcher.setLocale(localeStr); - mLanguageSwitcher.persist(mPrefs); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - // PREF_SELECTED_LANGUAGES: enabled input subtypes - // PREF_INPUT_LANGUAGE: current input subtype - if (key.equals(Settings.PREF_SELECTED_LANGUAGES) - || key.equals(Settings.PREF_INPUT_LANGUAGE)) { - mLanguageSwitcher.loadLocales(prefs, null); - if (mService != null) { - mService.onRefreshKeyboard(); - } - } - } -} diff --git a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java b/java/src/com/android/inputmethod/deprecated/VoiceProxy.java deleted file mode 100644 index 87d1c118b..000000000 --- a/java/src/com/android/inputmethod/deprecated/VoiceProxy.java +++ /dev/null @@ -1,854 +0,0 @@ -/* - * Copyright (C) 2010 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.deprecated; - -import android.app.AlertDialog; -import android.content.ContentResolver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.IBinder; -import android.preference.PreferenceManager; -import android.provider.Browser; -import android.speech.SpeechRecognizer; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.TextUtils; -import android.text.method.LinkMovementMethod; -import android.text.style.URLSpan; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.view.ViewParent; -import android.view.Window; -import android.view.WindowManager; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.ExtractedTextRequest; -import android.view.inputmethod.InputConnection; -import android.widget.TextView; - -import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; -import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; -import com.android.inputmethod.compat.SharedPreferencesCompat; -import com.android.inputmethod.deprecated.voice.FieldContext; -import com.android.inputmethod.deprecated.voice.Hints; -import com.android.inputmethod.deprecated.voice.SettingsUtil; -import com.android.inputmethod.deprecated.voice.VoiceInput; -import com.android.inputmethod.keyboard.KeyboardSwitcher; -import com.android.inputmethod.keyboard.LatinKeyboardView; -import com.android.inputmethod.latin.EditingUtils; -import com.android.inputmethod.latin.LastComposedWord; -import com.android.inputmethod.latin.LatinIME; -import com.android.inputmethod.latin.LatinIME.UIHandler; -import com.android.inputmethod.latin.LatinImeLogger; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.StringUtils; -import com.android.inputmethod.latin.SubtypeSwitcher; -import com.android.inputmethod.latin.Utils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class VoiceProxy implements VoiceInput.UiListener { - private static final VoiceProxy sInstance = new VoiceProxy(); - - public static final boolean VOICE_INSTALLED = - !InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED; - private static final boolean ENABLE_VOICE_BUTTON = true; - private static final String PREF_VOICE_MODE = "voice_mode"; - // Whether or not the user has used voice input before (and thus, whether to show the - // first-run warning dialog or not). - private static final String PREF_HAS_USED_VOICE_INPUT = "has_used_voice_input"; - // Whether or not the user has used voice input from an unsupported locale UI before. - // For example, the user has a Chinese UI but activates voice input. - private static final String PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE = - "has_used_voice_input_unsupported_locale"; - private static final int RECOGNITIONVIEW_HEIGHT_THRESHOLD_RATIO = 6; - // TODO: Adjusted on phones for now - private static final int RECOGNITIONVIEW_MINIMUM_HEIGHT_DIP = 244; - - private static final String TAG = VoiceProxy.class.getSimpleName(); - private static final boolean DEBUG = LatinImeLogger.sDBG; - - private boolean mAfterVoiceInput; - private boolean mConfigurationChanging; - private boolean mHasUsedVoiceInput; - private boolean mHasUsedVoiceInputUnsupportedLocale; - private boolean mImmediatelyAfterVoiceInput; - private boolean mIsShowingHint; - private boolean mLocaleSupportedForVoiceInput; - private boolean mPasswordText; - private boolean mRecognizing; - private boolean mShowingVoiceSuggestions; - private boolean mVoiceButtonEnabled; - private boolean mVoiceButtonOnPrimary; - private boolean mVoiceInputHighlighted; - - private int mMinimumVoiceRecognitionViewHeightPixel; - private InputMethodManagerCompatWrapper mImm; - private LatinIME mService; - private AlertDialog mVoiceWarningDialog; - private VoiceInput mVoiceInput; - private final VoiceResults mVoiceResults = new VoiceResults(); - private Hints mHints; - private UIHandler mHandler; - private SubtypeSwitcher mSubtypeSwitcher; - - // For each word, a list of potential replacements, usually from voice. - private final Map> mWordToSuggestions = - new HashMap>(); - - public static VoiceProxy init(LatinIME context, SharedPreferences prefs, UIHandler h) { - sInstance.initInternal(context, prefs, h); - return sInstance; - } - - public static VoiceProxy getInstance() { - return sInstance; - } - - private void initInternal(LatinIME service, SharedPreferences prefs, UIHandler h) { - if (!VOICE_INSTALLED) { - return; - } - mService = service; - mHandler = h; - mMinimumVoiceRecognitionViewHeightPixel = Utils.dipToPixel( - Utils.getDipScale(service), RECOGNITIONVIEW_MINIMUM_HEIGHT_DIP); - mImm = InputMethodManagerCompatWrapper.getInstance(); - mSubtypeSwitcher = SubtypeSwitcher.getInstance(); - mVoiceInput = new VoiceInput(service, this); - mHints = new Hints(service, prefs, new Hints.Display() { - @Override - public void showHint(int viewResource) { - View view = LayoutInflater.from(mService).inflate(viewResource, null); - mIsShowingHint = true; - } - }); - } - - private VoiceProxy() { - // Intentional empty constructor for singleton. - } - - public void resetVoiceStates(boolean isPasswordText) { - mAfterVoiceInput = false; - mImmediatelyAfterVoiceInput = false; - mShowingVoiceSuggestions = false; - mVoiceInputHighlighted = false; - mPasswordText = isPasswordText; - } - - public void flushVoiceInputLogs() { - if (!VOICE_INSTALLED) { - return; - } - if (!mConfigurationChanging) { - if (mAfterVoiceInput) { - mVoiceInput.flushAllTextModificationCounters(); - mVoiceInput.logInputEnded(); - } - mVoiceInput.flushLogs(); - mVoiceInput.cancel(); - } - } - - public void flushAndLogAllTextModificationCounters(int index, CharSequence suggestion, - String wordSeparators) { - if (!VOICE_INSTALLED) { - return; - } - if (mAfterVoiceInput && mShowingVoiceSuggestions) { - mVoiceInput.flushAllTextModificationCounters(); - // send this intent AFTER logging any prior aggregated edits. - mVoiceInput.logTextModifiedByChooseSuggestion(suggestion.toString(), index, - wordSeparators, mService.getCurrentInputConnection()); - } - } - - private void showVoiceWarningDialog(final boolean swipe, IBinder token) { - if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) { - return; - } - AlertDialog.Builder builder = new UrlLinkAlertDialogBuilder(mService); - builder.setCancelable(true); - builder.setIcon(R.drawable.ic_mic_dialog); - builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - mVoiceInput.logKeyboardWarningDialogOk(); - reallyStartListening(swipe); - } - }); - builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - mVoiceInput.logKeyboardWarningDialogCancel(); - switchToLastInputMethod(); - } - }); - // When the dialog is dismissed by user's cancellation, switch back to the last input method - builder.setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface arg0) { - mVoiceInput.logKeyboardWarningDialogCancel(); - switchToLastInputMethod(); - } - }); - - final CharSequence message; - if (mLocaleSupportedForVoiceInput) { - message = TextUtils.concat( - mService.getText(R.string.voice_warning_may_not_understand), "\n\n", - mService.getText(R.string.voice_warning_how_to_turn_off)); - } else { - message = TextUtils.concat( - mService.getText(R.string.voice_warning_locale_not_supported), "\n\n", - mService.getText(R.string.voice_warning_may_not_understand), "\n\n", - mService.getText(R.string.voice_warning_how_to_turn_off)); - } - builder.setMessage(message); - builder.setTitle(R.string.voice_warning_title); - mVoiceWarningDialog = builder.create(); - final Window window = mVoiceWarningDialog.getWindow(); - final WindowManager.LayoutParams lp = window.getAttributes(); - lp.token = token; - lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG; - window.setAttributes(lp); - window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); - mVoiceInput.logKeyboardWarningDialogShown(); - mVoiceWarningDialog.show(); - } - - private static class UrlLinkAlertDialogBuilder extends AlertDialog.Builder { - private AlertDialog mAlertDialog; - - public UrlLinkAlertDialogBuilder(Context context) { - super(context); - } - - @Override - public AlertDialog.Builder setMessage(CharSequence message) { - return super.setMessage(replaceURLSpan(message)); - } - - private Spanned replaceURLSpan(CharSequence message) { - // Replace all spans with the custom span - final SpannableStringBuilder ssb = new SpannableStringBuilder(message); - for (URLSpan span : ssb.getSpans(0, ssb.length(), URLSpan.class)) { - int spanStart = ssb.getSpanStart(span); - int spanEnd = ssb.getSpanEnd(span); - int spanFlags = ssb.getSpanFlags(span); - ssb.removeSpan(span); - ssb.setSpan(new ClickableSpan(span.getURL()), spanStart, spanEnd, spanFlags); - } - return ssb; - } - - @Override - public AlertDialog create() { - final AlertDialog dialog = super.create(); - - dialog.setOnShowListener(new DialogInterface.OnShowListener() { - @Override - public void onShow(DialogInterface dialogInterface) { - // Make URL in the dialog message click-able. - TextView textView = (TextView) mAlertDialog.findViewById(android.R.id.message); - if (textView != null) { - textView.setMovementMethod(LinkMovementMethod.getInstance()); - } - } - }); - mAlertDialog = dialog; - return dialog; - } - - class ClickableSpan extends URLSpan { - public ClickableSpan(String url) { - super(url); - } - - @Override - public void onClick(View widget) { - Uri uri = Uri.parse(getURL()); - Context context = widget.getContext(); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - // Add this flag to start an activity from service - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); - // Dismiss the warning dialog and go back to the previous IME. - // TODO: If we can find a way to bring the new activity to front while keeping - // the warning dialog, we don't need to dismiss it here. - mAlertDialog.cancel(); - context.startActivity(intent); - } - } - } - - public void showPunctuationHintIfNecessary() { - if (!VOICE_INSTALLED) { - return; - } - InputConnection ic = mService.getCurrentInputConnection(); - if (!mImmediatelyAfterVoiceInput && mAfterVoiceInput && ic != null) { - if (mHints.showPunctuationHintIfNecessary(ic)) { - mVoiceInput.logPunctuationHintDisplayed(); - } - } - mImmediatelyAfterVoiceInput = false; - } - - public void hideVoiceWindow() { - if (!VOICE_INSTALLED) { - return; - } - if (!mConfigurationChanging) { - if (mAfterVoiceInput) - mVoiceInput.logInputEnded(); - if (mVoiceWarningDialog != null && mVoiceWarningDialog.isShowing()) { - mVoiceInput.logKeyboardWarningDialogDismissed(); - mVoiceWarningDialog.dismiss(); - mVoiceWarningDialog = null; - } - if (VOICE_INSTALLED & mRecognizing) { - mVoiceInput.cancel(); - } - } - mWordToSuggestions.clear(); - } - - public void setCursorAndSelection(int newSelEnd, int newSelStart) { - if (!VOICE_INSTALLED) { - return; - } - if (mAfterVoiceInput) { - mVoiceInput.setCursorPos(newSelEnd); - mVoiceInput.setSelectionSpan(newSelEnd - newSelStart); - } - } - - public void setVoiceInputHighlighted(boolean b) { - mVoiceInputHighlighted = b; - } - - public void setShowingVoiceSuggestions(boolean b) { - mShowingVoiceSuggestions = b; - } - - public boolean isVoiceButtonEnabled() { - return mVoiceButtonEnabled; - } - - public boolean isVoiceButtonOnPrimary() { - return mVoiceButtonOnPrimary; - } - - public boolean isVoiceInputHighlighted() { - return mVoiceInputHighlighted; - } - - public boolean isRecognizing() { - return mRecognizing; - } - - public boolean needsToShowWarningDialog() { - return !mHasUsedVoiceInput - || (!mLocaleSupportedForVoiceInput && !mHasUsedVoiceInputUnsupportedLocale); - } - - public boolean getAndResetIsShowingHint() { - boolean ret = mIsShowingHint; - mIsShowingHint = false; - return ret; - } - - private void revertVoiceInput() { - InputConnection ic = mService.getCurrentInputConnection(); - if (ic != null) ic.commitText("", 1); - mService.updateSuggestions(); - mVoiceInputHighlighted = false; - } - - public void commitVoiceInput() { - if (VOICE_INSTALLED && mVoiceInputHighlighted) { - InputConnection ic = mService.getCurrentInputConnection(); - if (ic != null) ic.finishComposingText(); - mService.updateSuggestions(); - mVoiceInputHighlighted = false; - } - } - - public boolean logAndRevertVoiceInput() { - if (!VOICE_INSTALLED) { - return false; - } - if (mVoiceInputHighlighted) { - mVoiceInput.incrementTextModificationDeleteCount( - mVoiceResults.candidates.get(0).toString().length()); - revertVoiceInput(); - return true; - } else { - return false; - } - } - - public void rememberReplacedWord(CharSequence suggestion,String wordSeparators) { - if (!VOICE_INSTALLED) { - return; - } - if (mShowingVoiceSuggestions) { - // Retain the replaced word in the alternatives array. - String wordToBeReplaced = EditingUtils.getWordAtCursor( - mService.getCurrentInputConnection(), wordSeparators); - if (!mWordToSuggestions.containsKey(wordToBeReplaced)) { - wordToBeReplaced = wordToBeReplaced.toLowerCase(); - } - if (mWordToSuggestions.containsKey(wordToBeReplaced)) { - List suggestions = mWordToSuggestions.get(wordToBeReplaced); - if (suggestions.contains(suggestion)) { - suggestions.remove(suggestion); - } - suggestions.add(wordToBeReplaced); - mWordToSuggestions.remove(wordToBeReplaced); - mWordToSuggestions.put(suggestion.toString(), suggestions); - } - } - } - - public void handleBackspace() { - if (!VOICE_INSTALLED) { - return; - } - if (mAfterVoiceInput) { - // Don't log delete if the user is pressing delete at - // the beginning of the text box (hence not deleting anything) - if (mVoiceInput.getCursorPos() > 0) { - // If anything was selected before the delete was pressed, increment the - // delete count by the length of the selection - int deleteLen = mVoiceInput.getSelectionSpan() > 0 ? - mVoiceInput.getSelectionSpan() : 1; - mVoiceInput.incrementTextModificationDeleteCount(deleteLen); - } - } - } - - public void handleCharacter() { - if (!VOICE_INSTALLED) { - return; - } - commitVoiceInput(); - if (mAfterVoiceInput) { - // Assume input length is 1. This assumption fails for smiley face insertions. - mVoiceInput.incrementTextModificationInsertCount(1); - } - } - - public void handleSeparator() { - if (!VOICE_INSTALLED) { - return; - } - commitVoiceInput(); - if (mAfterVoiceInput){ - // Assume input length is 1. This assumption fails for smiley face insertions. - mVoiceInput.incrementTextModificationInsertPunctuationCount(1); - } - } - - public void handleClose() { - if (!VOICE_INSTALLED) { - return; - } - if (mRecognizing) { - mVoiceInput.cancel(); - } - } - - - public void handleVoiceResults(boolean capitalizeFirstWord) { - if (!VOICE_INSTALLED) { - return; - } - mAfterVoiceInput = true; - mImmediatelyAfterVoiceInput = true; - - InputConnection ic = mService.getCurrentInputConnection(); - if (!mService.isFullscreenMode()) { - // Start listening for updates to the text from typing, etc. - if (ic != null) { - ExtractedTextRequest req = new ExtractedTextRequest(); - ic.getExtractedText(req, InputConnection.GET_EXTRACTED_TEXT_MONITOR); - } - } - mService.vibrate(); - - final List nBest = new ArrayList(); - for (String c : mVoiceResults.candidates) { - if (capitalizeFirstWord) { - c = Character.toUpperCase(c.charAt(0)) + c.substring(1, c.length()); - } - nBest.add(c); - } - if (nBest.size() == 0) { - return; - } - String bestResult = nBest.get(0).toString(); - mVoiceInput.logVoiceInputDelivered(bestResult.length()); - mHints.registerVoiceResult(bestResult); - - if (ic != null) ic.beginBatchEdit(); // To avoid extra updates on committing older text - mService.commitTyped(ic, LastComposedWord.NOT_A_SEPARATOR); - EditingUtils.appendText(ic, bestResult); - if (ic != null) ic.endBatchEdit(); - - mVoiceInputHighlighted = true; - mWordToSuggestions.putAll(mVoiceResults.alternatives); - onCancelVoice(); - } - - public void switchToRecognitionStatusView(final Configuration configuration) { - if (!VOICE_INSTALLED) { - return; - } - mHandler.post(new Runnable() { - @Override - public void run() { -// mService.setCandidatesViewShown(false); - mRecognizing = true; - mVoiceInput.newView(); - View v = mVoiceInput.getView(); - - ViewParent p = v.getParent(); - if (p != null && p instanceof ViewGroup) { - ((ViewGroup) p).removeView(v); - } - - View keyboardView = KeyboardSwitcher.getInstance().getKeyboardView(); - - // The full height of the keyboard is difficult to calculate - // as the dimension is expressed in "mm" and not in "pixel" - // As we add mm, we don't know how the rounding is going to work - // thus we may end up with few pixels extra (or less). - if (keyboardView != null) { - View popupLayout = v.findViewById(R.id.popup_layout); - final int displayHeight = - mService.getResources().getDisplayMetrics().heightPixels; - final int currentHeight = popupLayout.getLayoutParams().height; - final int keyboardHeight = keyboardView.getHeight(); - if (mMinimumVoiceRecognitionViewHeightPixel > keyboardHeight - || mMinimumVoiceRecognitionViewHeightPixel > currentHeight) { - popupLayout.getLayoutParams().height = - mMinimumVoiceRecognitionViewHeightPixel; - } else if (keyboardHeight > currentHeight || keyboardHeight - > (displayHeight / RECOGNITIONVIEW_HEIGHT_THRESHOLD_RATIO)) { - popupLayout.getLayoutParams().height = keyboardHeight; - } - } - mService.setInputView(v); - mService.updateInputViewShown(); - - if (configuration != null) { - mVoiceInput.onConfigurationChanged(configuration); - } - }}); - } - - private void switchToLastInputMethod() { - if (!VOICE_INSTALLED) { - return; - } - final IBinder token = mService.getWindow().getWindow().getAttributes().token; - new AsyncTask() { - @Override - protected Boolean doInBackground(Void... params) { - return mImm.switchToLastInputMethod(token); - } - - @Override - protected void onPostExecute(Boolean result) { - // Calls in this method need to be done in the same thread as the thread which - // called switchToLastInputMethod() - if (!result) { - if (DEBUG) { - Log.d(TAG, "Couldn't switch back to last IME."); - } - // Because the current IME and subtype failed to switch to any other IME and - // subtype by switchToLastInputMethod, the current IME and subtype should keep - // being LatinIME and voice subtype in the next time. And for re-showing voice - // mode, the state of voice input should be reset and the voice view should be - // hidden. - mVoiceInput.reset(); - mService.requestHideSelf(0); - } else { - // Notify an event that the current subtype was changed. This event will be - // handled if "onCurrentInputMethodSubtypeChanged" can't be implemented - // when the API level is 10 or previous. - mService.notifyOnCurrentInputMethodSubtypeChanged(null); - } - } - }.execute(); - } - - private void reallyStartListening(boolean swipe) { - if (!VOICE_INSTALLED) { - return; - } - if (!mHasUsedVoiceInput) { - // The user has started a voice input, so remember that in the - // future (so we don't show the warning dialog after the first run). - SharedPreferences.Editor editor = - PreferenceManager.getDefaultSharedPreferences(mService).edit(); - editor.putBoolean(PREF_HAS_USED_VOICE_INPUT, true); - SharedPreferencesCompat.apply(editor); - mHasUsedVoiceInput = true; - } - - if (!mLocaleSupportedForVoiceInput && !mHasUsedVoiceInputUnsupportedLocale) { - // The user has started a voice input from an unsupported locale, so remember that - // in the future (so we don't show the warning dialog the next time they do this). - SharedPreferences.Editor editor = - PreferenceManager.getDefaultSharedPreferences(mService).edit(); - editor.putBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, true); - SharedPreferencesCompat.apply(editor); - mHasUsedVoiceInputUnsupportedLocale = true; - } - - // Clear N-best suggestions - mService.clearSuggestions(); - - FieldContext context = makeFieldContext(); - mVoiceInput.startListening(context, swipe); - switchToRecognitionStatusView(null); - } - - public void startListening(final boolean swipe, IBinder token) { - if (!VOICE_INSTALLED) { - return; - } - // TODO: remove swipe which is no longer used. - if (needsToShowWarningDialog()) { - // Calls reallyStartListening if user clicks OK, does nothing if user clicks Cancel. - showVoiceWarningDialog(swipe, token); - } else { - reallyStartListening(swipe); - } - } - - private boolean fieldCanDoVoice(FieldContext fieldContext) { - return !mPasswordText - && mVoiceInput != null - && !mVoiceInput.isBlacklistedField(fieldContext); - } - - private boolean shouldShowVoiceButton(FieldContext fieldContext, EditorInfo editorInfo) { - @SuppressWarnings("deprecation") - final boolean noMic = StringUtils.inPrivateImeOptions(null, - LatinIME.IME_OPTION_NO_MICROPHONE_COMPAT, editorInfo) - || StringUtils.inPrivateImeOptions(mService.getPackageName(), - LatinIME.IME_OPTION_NO_MICROPHONE, editorInfo); - return ENABLE_VOICE_BUTTON && fieldCanDoVoice(fieldContext) && !noMic - && SpeechRecognizer.isRecognitionAvailable(mService); - } - - public static boolean isRecognitionAvailable(Context context) { - return SpeechRecognizer.isRecognitionAvailable(context); - } - - public void loadSettings(EditorInfo editorInfo, SharedPreferences sp) { - if (!VOICE_INSTALLED) { - return; - } - mHasUsedVoiceInput = sp.getBoolean(PREF_HAS_USED_VOICE_INPUT, false); - mHasUsedVoiceInputUnsupportedLocale = - sp.getBoolean(PREF_HAS_USED_VOICE_INPUT_UNSUPPORTED_LOCALE, false); - - mLocaleSupportedForVoiceInput = SubtypeSwitcher.isVoiceSupported( - mService, SubtypeSwitcher.getInstance().getInputLocaleStr()); - - final String voiceMode = sp.getString(PREF_VOICE_MODE, - mService.getString(R.string.voice_mode_main)); - mVoiceButtonEnabled = !voiceMode.equals(mService.getString(R.string.voice_mode_off)) - && shouldShowVoiceButton(makeFieldContext(), editorInfo); - mVoiceButtonOnPrimary = voiceMode.equals(mService.getString(R.string.voice_mode_main)); - } - - public void destroy() { - if (!VOICE_INSTALLED) { - return; - } - if (mVoiceInput != null) { - mVoiceInput.destroy(); - } - } - - public void onStartInputView(IBinder keyboardViewToken) { - if (!VOICE_INSTALLED) { - return; - } - // If keyboardViewToken is null, keyboardView is not attached but voiceView is attached. - IBinder windowToken = keyboardViewToken != null ? keyboardViewToken - : mVoiceInput.getView().getWindowToken(); - // If IME is in voice mode, but still needs to show the voice warning dialog, - // keep showing the warning. - if (mSubtypeSwitcher.isVoiceMode() && windowToken != null) { - // Close keyboard view if it is been shown. - final LatinKeyboardView keyboardView = KeyboardSwitcher.getInstance().getKeyboardView(); - if (keyboardView != null && keyboardView.isShown()) - keyboardView.purgeKeyboardAndClosing(); - startListening(false, windowToken); - } - // If we have no token, onAttachedToWindow will take care of showing dialog and start - // listening. - } - - public void onAttachedToWindow() { - if (!VOICE_INSTALLED) { - return; - } - // After onAttachedToWindow, we can show the voice warning dialog. See startListening() - // above. - VoiceInputWrapper.getInstance().setVoiceInput(mVoiceInput, mSubtypeSwitcher); - } - - public void onConfigurationChanged(Configuration configuration) { - if (!VOICE_INSTALLED) { - return; - } - if (mRecognizing) { - switchToRecognitionStatusView(configuration); - } - } - - @Override - public void onCancelVoice() { - if (!VOICE_INSTALLED) { - return; - } - if (mRecognizing) { - if (mSubtypeSwitcher.isVoiceMode()) { - // If voice mode is being canceled within LatinIME (i.e. time-out or user - // cancellation etc.), onCancelVoice() will be called first. LatinIME thinks it's - // still in voice mode. LatinIME needs to call switchToLastInputMethod(). - // Note that onCancelVoice() will be called again from SubtypeSwitcher. - switchToLastInputMethod(); - } else if (mSubtypeSwitcher.isKeyboardMode()) { - // If voice mode is being canceled out of LatinIME (i.e. by user's IME switching or - // as a result of switchToLastInputMethod() etc.), - // onCurrentInputMethodSubtypeChanged() will be called first. LatinIME will know - // that it's in keyboard mode and SubtypeSwitcher will call onCancelVoice(). - mRecognizing = false; - mService.switchToKeyboardView(); - } - } - } - - @Override - public void onVoiceResults(List candidates, - Map> alternatives) { - if (!VOICE_INSTALLED) { - return; - } - if (!mRecognizing) { - return; - } - mVoiceResults.candidates = candidates; - mVoiceResults.alternatives = alternatives; - mHandler.updateVoiceResults(); - } - - private FieldContext makeFieldContext() { - SubtypeSwitcher switcher = SubtypeSwitcher.getInstance(); - return new FieldContext(mService.getCurrentInputConnection(), - mService.getCurrentInputEditorInfo(), switcher.getInputLocaleStr(), - switcher.getEnabledLanguages()); - } - - // TODO: make this private (proguard issue) - public static class VoiceResults { - List candidates; - Map> alternatives; - } - - public static class VoiceInputWrapper { - private static final VoiceInputWrapper sInputWrapperInstance = new VoiceInputWrapper(); - private VoiceInput mVoiceInput; - public static VoiceInputWrapper getInstance() { - return sInputWrapperInstance; - } - private void setVoiceInput(VoiceInput voiceInput, SubtypeSwitcher switcher) { - if (!VOICE_INSTALLED) { - return; - } - if (mVoiceInput == null && voiceInput != null) { - mVoiceInput = voiceInput; - } - switcher.setVoiceInputWrapper(this); - } - - private VoiceInputWrapper() { - } - - public void cancel() { - if (!VOICE_INSTALLED) { - return; - } - if (mVoiceInput != null) mVoiceInput.cancel(); - } - - public void reset() { - if (!VOICE_INSTALLED) { - return; - } - if (mVoiceInput != null) mVoiceInput.reset(); - } - } - - // A list of locales which are supported by default for voice input, unless we get a - // different list from Gservices. - private static final String DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES = - "en " + - "en_US " + - "en_GB " + - "en_AU " + - "en_CA " + - "en_IE " + - "en_IN " + - "en_NZ " + - "en_SG " + - "en_ZA "; - - public static String getSupportedLocalesString (ContentResolver resolver) { - return SettingsUtil.getSettingsString( - resolver, - SettingsUtil.LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES, - DEFAULT_VOICE_INPUT_SUPPORTED_LOCALES); - } - - public void startChangingConfiguration() { - mConfigurationChanging = true; - } - - public void finishChangingConfiguration() { - mConfigurationChanging = false; - } -} diff --git a/java/src/com/android/inputmethod/deprecated/compat/VoiceInputLoggerCompatUtils.java b/java/src/com/android/inputmethod/deprecated/compat/VoiceInputLoggerCompatUtils.java deleted file mode 100644 index 488390fbc..000000000 --- a/java/src/com/android/inputmethod/deprecated/compat/VoiceInputLoggerCompatUtils.java +++ /dev/null @@ -1,36 +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.deprecated.compat; - -import com.android.common.userhappiness.UserHappinessSignals; -import com.android.inputmethod.compat.CompatUtils; - -import java.lang.reflect.Method; - -public class VoiceInputLoggerCompatUtils { - public static final String EXTRA_TEXT_REPLACED_LENGTH = "length"; - public static final String EXTRA_BEFORE_N_BEST_CHOOSE = "before"; - public static final String EXTRA_AFTER_N_BEST_CHOOSE = "after"; - private static final Method METHOD_UserHappinessSignals_setHasVoiceLoggingInfo = - CompatUtils.getMethod(UserHappinessSignals.class, "setHasVoiceLoggingInfo", - boolean.class); - - public static void setHasVoiceLoggingInfoCompat(boolean hasLoggingInfo) { - CompatUtils.invoke(null, null, METHOD_UserHappinessSignals_setHasVoiceLoggingInfo, - hasLoggingInfo); - } -} diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java deleted file mode 100644 index 421ee6529..000000000 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/InputLanguageSelection.java +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (C) 2008-2009 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.deprecated.languageswitcher; - -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import android.content.res.Resources; -import android.os.Bundle; -import android.preference.CheckBoxPreference; -import android.preference.PreferenceActivity; -import android.preference.PreferenceGroup; -import android.preference.PreferenceManager; -import android.text.TextUtils; -import android.util.Pair; - -import com.android.inputmethod.compat.SharedPreferencesCompat; -import com.android.inputmethod.keyboard.KeyboardSet; -import com.android.inputmethod.latin.DictionaryFactory; -import com.android.inputmethod.latin.LocaleUtils; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.Settings; -import com.android.inputmethod.latin.StringUtils; - -import org.xmlpull.v1.XmlPullParserException; - -import java.io.IOException; -import java.text.Collator; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map.Entry; -import java.util.TreeMap; - -public class InputLanguageSelection extends PreferenceActivity { - - private SharedPreferences mPrefs; - private String mSelectedLanguages; - private HashMap mLocaleMap = - new HashMap(); - - private static class LocaleEntry implements Comparable { - private static Collator sCollator = Collator.getInstance(); - - private String mLabel; - public final Locale mLocale; - - public LocaleEntry(String label, Locale locale) { - this.mLabel = label; - this.mLocale = locale; - } - - @Override - public String toString() { - return this.mLabel; - } - - @Override - public int compareTo(Object o) { - return sCollator.compare(this.mLabel, ((LocaleEntry) o).mLabel); - } - } - - @Override - protected void onCreate(Bundle icicle) { - super.onCreate(icicle); - addPreferencesFromResource(R.xml.language_prefs); - // Get the settings preferences - mPrefs = PreferenceManager.getDefaultSharedPreferences(this); - mSelectedLanguages = mPrefs.getString(Settings.PREF_SELECTED_LANGUAGES, ""); - String[] languageList = mSelectedLanguages.split(","); - ArrayList availableLanguages = getUniqueLocales(); - PreferenceGroup parent = getPreferenceScreen(); - final HashMap dictionaryIdLocaleMap = new HashMap(); - final TreeMap localeHasDictionaryMap = - new TreeMap(); - for (int i = 0; i < availableLanguages.size(); i++) { - LocaleEntry loc = availableLanguages.get(i); - Locale locale = loc.mLocale; - final Pair hasDictionaryOrLayout = hasDictionaryOrLayout(locale); - final Long dictionaryId = hasDictionaryOrLayout.first; - final boolean hasLayout = hasDictionaryOrLayout.second; - final boolean hasDictionary = dictionaryId != null; - // Add this locale to the supported list if: - // 1) this locale has a layout/ 2) this locale has a dictionary - // If some locales have no layout but have a same dictionary, the shortest locale - // will be added to the supported list. - if (!hasLayout && !hasDictionary) { - continue; - } - if (hasLayout) { - localeHasDictionaryMap.put(loc, hasDictionary); - } - if (!hasDictionary) { - continue; - } - if (dictionaryIdLocaleMap.containsKey(dictionaryId)) { - final String newLocale = locale.toString(); - final String oldLocale = - dictionaryIdLocaleMap.get(dictionaryId).mLocale.toString(); - // Check if this locale is more appropriate to be the candidate of the input locale. - if (oldLocale.length() <= newLocale.length() && !hasLayout) { - // Don't add this new locale to the map if: - // 1) the new locale's name is longer than the existing one, and - // 2) the new locale doesn't have its layout - continue; - } - } - dictionaryIdLocaleMap.put(dictionaryId, loc); - } - - for (LocaleEntry localeEntry : dictionaryIdLocaleMap.values()) { - if (!localeHasDictionaryMap.containsKey(localeEntry)) { - localeHasDictionaryMap.put(localeEntry, true); - } - } - - for (Entry entry : localeHasDictionaryMap.entrySet()) { - final LocaleEntry localeEntry = entry.getKey(); - final Locale locale = localeEntry.mLocale; - final Boolean hasDictionary = entry.getValue(); - CheckBoxPreference pref = new CheckBoxPreference(this); - pref.setTitle(localeEntry.mLabel); - boolean checked = isLocaleIn(locale, languageList); - pref.setChecked(checked); - if (hasDictionary) { - pref.setSummary(R.string.has_dictionary); - } - mLocaleMap.put(pref, locale); - parent.addPreference(pref); - } - } - - private boolean isLocaleIn(Locale locale, String[] list) { - String lang = get5Code(locale); - for (int i = 0; i < list.length; i++) { - if (lang.equalsIgnoreCase(list[i])) return true; - } - return false; - } - - private Pair hasDictionaryOrLayout(Locale locale) { - if (locale == null) return new Pair(null, false); - final Resources res = getResources(); - final Locale saveLocale = LocaleUtils.setSystemLocale(res, locale); - final Long dictionaryId = DictionaryFactory.getDictionaryId(this, locale); - boolean hasLayout = false; - - try { - final String localeStr = locale.toString(); - final String[] layoutCountryCodes = KeyboardSet.parseKeyboardLocale( - getResources(), R.xml.keyboard_set).split(",", -1); - if (!TextUtils.isEmpty(localeStr) && layoutCountryCodes.length > 0) { - for (String s : layoutCountryCodes) { - if (s.equals(localeStr)) { - hasLayout = true; - break; - } - } - } - } catch (XmlPullParserException e) { - } catch (IOException e) { - } - LocaleUtils.setSystemLocale(res, saveLocale); - return new Pair(dictionaryId, hasLayout); - } - - private String get5Code(Locale locale) { - String country = locale.getCountry(); - return locale.getLanguage() - + (TextUtils.isEmpty(country) ? "" : "_" + country); - } - - @Override - protected void onResume() { - super.onResume(); - } - - @Override - protected void onPause() { - super.onPause(); - // Save the selected languages - String checkedLanguages = ""; - PreferenceGroup parent = getPreferenceScreen(); - int count = parent.getPreferenceCount(); - for (int i = 0; i < count; i++) { - CheckBoxPreference pref = (CheckBoxPreference) parent.getPreference(i); - if (pref.isChecked()) { - checkedLanguages += get5Code(mLocaleMap.get(pref)) + ","; - } - } - if (checkedLanguages.length() < 1) checkedLanguages = null; // Save null - Editor editor = mPrefs.edit(); - editor.putString(Settings.PREF_SELECTED_LANGUAGES, checkedLanguages); - SharedPreferencesCompat.apply(editor); - } - - public ArrayList getUniqueLocales() { - String[] locales = getAssets().getLocales(); - Arrays.sort(locales); - ArrayList uniqueLocales = new ArrayList(); - - final int origSize = locales.length; - LocaleEntry[] preprocess = new LocaleEntry[origSize]; - int finalSize = 0; - for (int i = 0 ; i < origSize; i++ ) { - String s = locales[i]; - int len = s.length(); - String language = ""; - String country = ""; - if (len == 5) { - language = s.substring(0, 2); - country = s.substring(3, 5); - } else if (len < 5) { - language = s; - } - Locale l = new Locale(language, country); - - // Exclude languages that are not relevant to LatinIME - if (TextUtils.isEmpty(language)) { - continue; - } - - if (finalSize == 0) { - preprocess[finalSize++] = - new LocaleEntry(StringUtils.getFullDisplayName(l, false), l); - } else { - if (s.equals("zz_ZZ")) { - // ignore this locale - } else { - final String displayName = StringUtils.getFullDisplayName(l, false); - preprocess[finalSize++] = new LocaleEntry(displayName, l); - } - } - } - for (int i = 0; i < finalSize ; i++) { - uniqueLocales.add(preprocess[i]); - } - return uniqueLocales; - } -} diff --git a/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java b/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java deleted file mode 100644 index 7e2627c81..000000000 --- a/java/src/com/android/inputmethod/deprecated/languageswitcher/LanguageSwitcher.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright (C) 2010 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.deprecated.languageswitcher; - -import com.android.inputmethod.compat.SharedPreferencesCompat; -import com.android.inputmethod.latin.LatinIME; -import com.android.inputmethod.latin.LatinImeLogger; -import com.android.inputmethod.latin.LocaleUtils; -import com.android.inputmethod.latin.Settings; - -import android.content.SharedPreferences; -import android.content.SharedPreferences.Editor; -import android.content.res.Configuration; -import android.text.TextUtils; -import android.util.Log; - -import java.util.ArrayList; -import java.util.Locale; - -/** - * Keeps track of list of selected input languages and the current - * input language that the user has selected. - */ -public class LanguageSwitcher { - private static final String TAG = LanguageSwitcher.class.getSimpleName(); - - @SuppressWarnings("unused") - private static final String KEYBOARD_MODE = "keyboard"; - private static final String[] EMPTY_STIRNG_ARRAY = new String[0]; - - private final ArrayList mLocales = new ArrayList(); - private final LatinIME mIme; - private String[] mSelectedLanguageArray = EMPTY_STIRNG_ARRAY; - private String mSelectedLanguages; - private int mCurrentIndex = 0; - private String mDefaultInputLanguage; - private Locale mDefaultInputLocale; - private Locale mSystemLocale; - - public LanguageSwitcher(LatinIME ime) { - mIme = ime; - } - - public int getLocaleCount() { - return mLocales.size(); - } - - public void onConfigurationChanged(Configuration conf, SharedPreferences prefs) { - final Locale newLocale = conf.locale; - if (!getSystemLocale().toString().equals(newLocale.toString())) { - loadLocales(prefs, newLocale); - } - } - - /** - * Loads the currently selected input languages from shared preferences. - * @param sp shared preference for getting the current input language and enabled languages - * @param systemLocale the current system locale, stored for changing the current input language - * based on the system current system locale. - * @return whether there was any change - */ - public boolean loadLocales(SharedPreferences sp, Locale systemLocale) { - if (LatinImeLogger.sDBG) { - Log.d(TAG, "load locales"); - } - if (systemLocale != null) { - setSystemLocale(systemLocale); - } - String selectedLanguages = sp.getString(Settings.PREF_SELECTED_LANGUAGES, null); - String currentLanguage = sp.getString(Settings.PREF_INPUT_LANGUAGE, null); - if (TextUtils.isEmpty(selectedLanguages)) { - mSelectedLanguageArray = EMPTY_STIRNG_ARRAY; - mSelectedLanguages = null; - loadDefaults(); - if (mLocales.size() == 0) { - return false; - } - mLocales.clear(); - return true; - } - if (selectedLanguages.equals(mSelectedLanguages)) { - return false; - } - mSelectedLanguageArray = selectedLanguages.split(","); - mSelectedLanguages = selectedLanguages; // Cache it for comparison later - constructLocales(); - mCurrentIndex = 0; - if (currentLanguage != null) { - // Find the index - mCurrentIndex = 0; - for (int i = 0; i < mLocales.size(); i++) { - if (mSelectedLanguageArray[i].equals(currentLanguage)) { - mCurrentIndex = i; - break; - } - } - // If we didn't find the index, use the first one - } - return true; - } - - private void loadDefaults() { - if (LatinImeLogger.sDBG) { - Log.d(TAG, "load default locales:"); - } - mDefaultInputLocale = mIme.getResources().getConfiguration().locale; - String country = mDefaultInputLocale.getCountry(); - mDefaultInputLanguage = mDefaultInputLocale.getLanguage() + - (TextUtils.isEmpty(country) ? "" : "_" + country); - } - - private void constructLocales() { - mLocales.clear(); - for (final String lang : mSelectedLanguageArray) { - final Locale locale = LocaleUtils.constructLocaleFromString(lang); - mLocales.add(locale); - } - } - - /** - * Returns the currently selected input language code, or the display language code if - * no specific locale was selected for input. - */ - public String getInputLanguage() { - if (getLocaleCount() == 0) return mDefaultInputLanguage; - - return mSelectedLanguageArray[mCurrentIndex]; - } - - /** - * Returns the list of enabled language codes. - */ - public String[] getEnabledLanguages(boolean allowImplicitlySelectedLanguages) { - if (mSelectedLanguageArray.length == 0 && allowImplicitlySelectedLanguages) { - return new String[] { mDefaultInputLanguage }; - } - return mSelectedLanguageArray; - } - - /** - * Returns the currently selected input locale, or the display locale if no specific - * locale was selected for input. - */ - public Locale getInputLocale() { - if (getLocaleCount() == 0) return mDefaultInputLocale; - - return mLocales.get(mCurrentIndex); - } - - private int nextLocaleIndex() { - final int size = mLocales.size(); - return (mCurrentIndex + 1) % size; - } - - private int prevLocaleIndex() { - final int size = mLocales.size(); - return (mCurrentIndex - 1 + size) % size; - } - - /** - * Returns the next input locale in the list. Wraps around to the beginning of the - * list if we're at the end of the list. - */ - public Locale getNextInputLocale() { - if (getLocaleCount() == 0) return mDefaultInputLocale; - return mLocales.get(nextLocaleIndex()); - } - - /** - * Sets the system locale (display UI) used for comparing with the input language. - * @param locale the locale of the system - */ - private void setSystemLocale(Locale locale) { - mSystemLocale = locale; - } - - /** - * Returns the system locale. - * @return the system locale - */ - private Locale getSystemLocale() { - return mSystemLocale; - } - - /** - * Returns the previous input locale in the list. Wraps around to the end of the - * list if we're at the beginning of the list. - */ - public Locale getPrevInputLocale() { - if (getLocaleCount() == 0) return mDefaultInputLocale; - return mLocales.get(prevLocaleIndex()); - } - - public void reset() { - mCurrentIndex = 0; - } - - public void next() { - mCurrentIndex = nextLocaleIndex(); - } - - public void prev() { - mCurrentIndex = prevLocaleIndex(); - } - - public void setLocale(String localeStr) { - final int N = mLocales.size(); - for (int i = 0; i < N; ++i) { - if (mLocales.get(i).toString().equals(localeStr)) { - mCurrentIndex = i; - } - } - } - - public void persist(SharedPreferences prefs) { - Editor editor = prefs.edit(); - editor.putString(Settings.PREF_INPUT_LANGUAGE, getInputLanguage()); - SharedPreferencesCompat.apply(editor); - } -} diff --git a/java/src/com/android/inputmethod/deprecated/voice/FieldContext.java b/java/src/com/android/inputmethod/deprecated/voice/FieldContext.java deleted file mode 100644 index fd2cf3d25..000000000 --- a/java/src/com/android/inputmethod/deprecated/voice/FieldContext.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2009 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.deprecated.voice; - -import android.os.Bundle; -import android.util.Log; -import android.view.inputmethod.EditorInfo; -import android.view.inputmethod.ExtractedText; -import android.view.inputmethod.ExtractedTextRequest; -import android.view.inputmethod.InputConnection; - -/** - * Represents information about a given text field, which can be passed - * to the speech recognizer as context information. - */ -public class FieldContext { - private static final boolean DBG = false; - - static final String LABEL = "label"; - static final String HINT = "hint"; - static final String PACKAGE_NAME = "packageName"; - static final String FIELD_ID = "fieldId"; - static final String FIELD_NAME = "fieldName"; - static final String SINGLE_LINE = "singleLine"; - static final String INPUT_TYPE = "inputType"; - static final String IME_OPTIONS = "imeOptions"; - static final String SELECTED_LANGUAGE = "selectedLanguage"; - static final String ENABLED_LANGUAGES = "enabledLanguages"; - - Bundle mFieldInfo; - - public FieldContext(InputConnection conn, EditorInfo editorInfo, - String selectedLanguage, String[] enabledLanguages) { - mFieldInfo = new Bundle(); - addEditorInfoToBundle(editorInfo, mFieldInfo); - addInputConnectionToBundle(conn, mFieldInfo); - addLanguageInfoToBundle(selectedLanguage, enabledLanguages, mFieldInfo); - if (DBG) Log.i("FieldContext", "Bundle = " + mFieldInfo.toString()); - } - - private static String safeToString(Object o) { - if (o == null) { - return ""; - } - return o.toString(); - } - - private static void addEditorInfoToBundle(EditorInfo info, Bundle bundle) { - if (info == null) { - return; - } - - bundle.putString(LABEL, safeToString(info.label)); - bundle.putString(HINT, safeToString(info.hintText)); - bundle.putString(PACKAGE_NAME, safeToString(info.packageName)); - bundle.putInt(FIELD_ID, info.fieldId); - bundle.putString(FIELD_NAME, safeToString(info.fieldName)); - bundle.putInt(INPUT_TYPE, info.inputType); - bundle.putInt(IME_OPTIONS, info.imeOptions); - } - - @SuppressWarnings("static-access") - private static void addInputConnectionToBundle( - InputConnection conn, Bundle bundle) { - if (conn == null) { - return; - } - - ExtractedText et = conn.getExtractedText(new ExtractedTextRequest(), 0); - if (et == null) { - return; - } - bundle.putBoolean(SINGLE_LINE, (et.flags & et.FLAG_SINGLE_LINE) > 0); - } - - private static void addLanguageInfoToBundle( - String selectedLanguage, String[] enabledLanguages, Bundle bundle) { - bundle.putString(SELECTED_LANGUAGE, selectedLanguage); - bundle.putStringArray(ENABLED_LANGUAGES, enabledLanguages); - } - - public Bundle getBundle() { - return mFieldInfo; - } - - @Override - public String toString() { - return mFieldInfo.toString(); - } -} diff --git a/java/src/com/android/inputmethod/deprecated/voice/Hints.java b/java/src/com/android/inputmethod/deprecated/voice/Hints.java deleted file mode 100644 index 17a19bf23..000000000 --- a/java/src/com/android/inputmethod/deprecated/voice/Hints.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright (C) 2009 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.deprecated.voice; - -import com.android.inputmethod.compat.SharedPreferencesCompat; -import com.android.inputmethod.latin.R; - -import android.content.ContentResolver; -import android.content.Context; -import android.content.SharedPreferences; -import android.view.inputmethod.InputConnection; - -import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; - -/** - * Logic to determine when to display hints on usage to the user. - */ -public class Hints { - public interface Display { - public void showHint(int viewResource); - } - - private static final String PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN = - "voice_hint_num_unique_days_shown"; - private static final String PREF_VOICE_HINT_LAST_TIME_SHOWN = - "voice_hint_last_time_shown"; - private static final String PREF_VOICE_INPUT_LAST_TIME_USED = - "voice_input_last_time_used"; - private static final String PREF_VOICE_PUNCTUATION_HINT_VIEW_COUNT = - "voice_punctuation_hint_view_count"; - private static final int DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW = 7; - private static final int DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS = 7; - - private final Context mContext; - private final SharedPreferences mPrefs; - private final Display mDisplay; - private boolean mVoiceResultContainedPunctuation; - private int mSwipeHintMaxDaysToShow; - private int mPunctuationHintMaxDisplays; - - // Only show punctuation hint if voice result did not contain punctuation. - static final Map SPEAKABLE_PUNCTUATION - = new HashMap(); - static { - SPEAKABLE_PUNCTUATION.put(",", "comma"); - SPEAKABLE_PUNCTUATION.put(".", "period"); - SPEAKABLE_PUNCTUATION.put("?", "question mark"); - } - - public Hints(Context context, SharedPreferences prefs, Display display) { - mContext = context; - mPrefs = prefs; - mDisplay = display; - - ContentResolver cr = mContext.getContentResolver(); - mSwipeHintMaxDaysToShow = SettingsUtil.getSettingsInt( - cr, - SettingsUtil.LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS, - DEFAULT_SWIPE_HINT_MAX_DAYS_TO_SHOW); - mPunctuationHintMaxDisplays = SettingsUtil.getSettingsInt( - cr, - SettingsUtil.LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS, - DEFAULT_PUNCTUATION_HINT_MAX_DISPLAYS); - } - - public boolean showSwipeHintIfNecessary(boolean fieldRecommended) { - if (fieldRecommended && shouldShowSwipeHint()) { - showHint(R.layout.voice_swipe_hint); - return true; - } - - return false; - } - - public boolean showPunctuationHintIfNecessary(InputConnection ic) { - if (!mVoiceResultContainedPunctuation - && ic != null - && getAndIncrementPref(PREF_VOICE_PUNCTUATION_HINT_VIEW_COUNT) - < mPunctuationHintMaxDisplays) { - CharSequence charBeforeCursor = ic.getTextBeforeCursor(1, 0); - if (SPEAKABLE_PUNCTUATION.containsKey(charBeforeCursor)) { - showHint(R.layout.voice_punctuation_hint); - return true; - } - } - - return false; - } - - public void registerVoiceResult(String text) { - // Update the current time as the last time voice input was used. - SharedPreferences.Editor editor = mPrefs.edit(); - editor.putLong(PREF_VOICE_INPUT_LAST_TIME_USED, System.currentTimeMillis()); - SharedPreferencesCompat.apply(editor); - - mVoiceResultContainedPunctuation = false; - for (CharSequence s : SPEAKABLE_PUNCTUATION.keySet()) { - if (text.indexOf(s.toString()) >= 0) { - mVoiceResultContainedPunctuation = true; - break; - } - } - } - - private boolean shouldShowSwipeHint() { - final SharedPreferences prefs = mPrefs; - - int numUniqueDaysShown = prefs.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0); - - // If we've already shown the hint for enough days, we'll return false. - if (numUniqueDaysShown < mSwipeHintMaxDaysToShow) { - - long lastTimeVoiceWasUsed = prefs.getLong(PREF_VOICE_INPUT_LAST_TIME_USED, 0); - - // If the user has used voice today, we'll return false. (We don't show the hint on - // any day that the user has already used voice.) - if (!isFromToday(lastTimeVoiceWasUsed)) { - return true; - } - } - - return false; - } - - /** - * Determines whether the provided time is from some time today (i.e., this day, month, - * and year). - */ - private boolean isFromToday(long timeInMillis) { - if (timeInMillis == 0) return false; - - Calendar today = Calendar.getInstance(); - today.setTimeInMillis(System.currentTimeMillis()); - - Calendar timestamp = Calendar.getInstance(); - timestamp.setTimeInMillis(timeInMillis); - - return (today.get(Calendar.YEAR) == timestamp.get(Calendar.YEAR) && - today.get(Calendar.DAY_OF_MONTH) == timestamp.get(Calendar.DAY_OF_MONTH) && - today.get(Calendar.MONTH) == timestamp.get(Calendar.MONTH)); - } - - private void showHint(int hintViewResource) { - final SharedPreferences prefs = mPrefs; - - int numUniqueDaysShown = prefs.getInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, 0); - long lastTimeHintWasShown = prefs.getLong(PREF_VOICE_HINT_LAST_TIME_SHOWN, 0); - - // If this is the first time the hint is being shown today, increase the saved values - // to represent that. We don't need to increase the last time the hint was shown unless - // it is a different day from the current value. - if (!isFromToday(lastTimeHintWasShown)) { - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt(PREF_VOICE_HINT_NUM_UNIQUE_DAYS_SHOWN, numUniqueDaysShown + 1); - editor.putLong(PREF_VOICE_HINT_LAST_TIME_SHOWN, System.currentTimeMillis()); - SharedPreferencesCompat.apply(editor); - } - - if (mDisplay != null) { - mDisplay.showHint(hintViewResource); - } - } - - private int getAndIncrementPref(String pref) { - final SharedPreferences prefs = mPrefs; - int value = prefs.getInt(pref, 0); - SharedPreferences.Editor editor = prefs.edit(); - editor.putInt(pref, value + 1); - SharedPreferencesCompat.apply(editor); - return value; - } -} diff --git a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java b/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java deleted file mode 100644 index ff8b1abce..000000000 --- a/java/src/com/android/inputmethod/deprecated/voice/RecognitionView.java +++ /dev/null @@ -1,355 +0,0 @@ -/* - * Copyright (C) 2009 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.deprecated.voice; - -import android.content.Context; -import android.content.res.Resources; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.CornerPathEffect; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.PathEffect; -import android.graphics.drawable.Drawable; -import android.os.Handler; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.ImageView; -import android.widget.ProgressBar; -import android.widget.TextView; - -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.StringUtils; -import com.android.inputmethod.latin.SubtypeSwitcher; - -import java.io.ByteArrayOutputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.ShortBuffer; -import java.util.Locale; - -/** - * The user interface for the "Speak now" and "working" states. - * Displays a recognition dialog (with waveform, voice meter, etc.), - * plays beeps, shows errors, etc. - */ -public class RecognitionView { - private static final String TAG = "RecognitionView"; - - private Handler mUiHandler; // Reference to UI thread - private View mView; - private Context mContext; - - private TextView mText; - private ImageView mImage; - private View mProgress; - private SoundIndicator mSoundIndicator; - private TextView mLanguage; - private Button mButton; - - private Drawable mInitializing; - private Drawable mError; - - private static final int INIT = 0; - private static final int LISTENING = 1; - private static final int WORKING = 2; - private static final int READY = 3; - - private int mState = INIT; - - private final View mPopupLayout; - - private final Drawable mListeningBorder; - private final Drawable mWorkingBorder; - private final Drawable mErrorBorder; - - public RecognitionView(Context context, OnClickListener clickListener) { - mUiHandler = new Handler(); - - LayoutInflater inflater = (LayoutInflater) context.getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - - mView = inflater.inflate(R.layout.recognition_status, null); - - mPopupLayout= mView.findViewById(R.id.popup_layout); - - // Pre-load volume level images - Resources r = context.getResources(); - - mListeningBorder = r.getDrawable(R.drawable.vs_dialog_red); - mWorkingBorder = r.getDrawable(R.drawable.vs_dialog_blue); - mErrorBorder = r.getDrawable(R.drawable.vs_dialog_yellow); - - mInitializing = r.getDrawable(R.drawable.mic_slash); - mError = r.getDrawable(R.drawable.caution); - - mImage = (ImageView) mView.findViewById(R.id.image); - mProgress = mView.findViewById(R.id.progress); - mSoundIndicator = (SoundIndicator) mView.findViewById(R.id.sound_indicator); - - mButton = (Button) mView.findViewById(R.id.button); - mButton.setOnClickListener(clickListener); - mText = (TextView) mView.findViewById(R.id.text); - mLanguage = (TextView) mView.findViewById(R.id.language); - - mContext = context; - } - - public View getView() { - return mView; - } - - public void restoreState() { - mUiHandler.post(new Runnable() { - @Override - public void run() { - // Restart the spinner - if (mState == WORKING) { - ((ProgressBar) mProgress).setIndeterminate(false); - ((ProgressBar) mProgress).setIndeterminate(true); - } - } - }); - } - - public void showInitializing() { - mUiHandler.post(new Runnable() { - @Override - public void run() { - mState = INIT; - prepareDialog(mContext.getText(R.string.voice_initializing), mInitializing, - mContext.getText(R.string.cancel)); - } - }); - } - - public void showListening() { - Log.d(TAG, "#showListening"); - mUiHandler.post(new Runnable() { - @Override - public void run() { - mState = LISTENING; - prepareDialog(mContext.getText(R.string.voice_listening), null, - mContext.getText(R.string.cancel)); - } - }); - } - - public void updateVoiceMeter(float rmsdB) { - mSoundIndicator.setRmsdB(rmsdB); - } - - public void showError(final String message) { - mUiHandler.post(new Runnable() { - @Override - public void run() { - mState = READY; - prepareDialog(message, mError, mContext.getText(R.string.ok)); - } - }); - } - - public void showWorking( - final ByteArrayOutputStream waveBuffer, - final int speechStartPosition, - final int speechEndPosition) { - mUiHandler.post(new Runnable() { - @Override - public void run() { - mState = WORKING; - prepareDialog(mContext.getText(R.string.voice_working), null, mContext - .getText(R.string.cancel)); - final ShortBuffer buf = ByteBuffer.wrap(waveBuffer.toByteArray()).order( - ByteOrder.nativeOrder()).asShortBuffer(); - buf.position(0); - waveBuffer.reset(); - showWave(buf, speechStartPosition / 2, speechEndPosition / 2); - } - }); - } - - private void prepareDialog(CharSequence text, Drawable image, - CharSequence btnTxt) { - - /* - * The mic of INIT and of LISTENING has to be displayed in the same position. To accomplish - * that, some text visibility are not set as GONE but as INVISIBLE. - */ - switch (mState) { - case INIT: - mText.setVisibility(View.INVISIBLE); - - mProgress.setVisibility(View.GONE); - - mImage.setVisibility(View.VISIBLE); - mImage.setImageResource(R.drawable.mic_slash); - - mSoundIndicator.setVisibility(View.GONE); - mSoundIndicator.stop(); - - mLanguage.setVisibility(View.INVISIBLE); - - mPopupLayout.setBackgroundDrawable(mListeningBorder); - break; - case LISTENING: - mText.setVisibility(View.VISIBLE); - mText.setText(text); - - mProgress.setVisibility(View.GONE); - - mImage.setVisibility(View.GONE); - - mSoundIndicator.setVisibility(View.VISIBLE); - mSoundIndicator.start(); - - Locale locale = SubtypeSwitcher.getInstance().getInputLocale(); - - mLanguage.setVisibility(View.VISIBLE); - mLanguage.setText(StringUtils.getFullDisplayName(locale, true)); - - mPopupLayout.setBackgroundDrawable(mListeningBorder); - break; - case WORKING: - - mText.setVisibility(View.VISIBLE); - mText.setText(text); - - mProgress.setVisibility(View.VISIBLE); - - mImage.setVisibility(View.VISIBLE); - - mSoundIndicator.setVisibility(View.GONE); - mSoundIndicator.stop(); - - mLanguage.setVisibility(View.GONE); - - mPopupLayout.setBackgroundDrawable(mWorkingBorder); - break; - case READY: - mText.setVisibility(View.VISIBLE); - mText.setText(text); - - mProgress.setVisibility(View.GONE); - - mImage.setVisibility(View.VISIBLE); - mImage.setImageResource(R.drawable.caution); - - mSoundIndicator.setVisibility(View.GONE); - mSoundIndicator.stop(); - - mLanguage.setVisibility(View.GONE); - - mPopupLayout.setBackgroundDrawable(mErrorBorder); - break; - default: - Log.w(TAG, "Unknown state " + mState); - } - mPopupLayout.requestLayout(); - mButton.setText(btnTxt); - } - - /** - * @return an average abs of the specified buffer. - */ - private static int getAverageAbs(ShortBuffer buffer, int start, int i, int npw) { - int from = start + i * npw; - int end = from + npw; - int total = 0; - for (int x = from; x < end; x++) { - total += Math.abs(buffer.get(x)); - } - return total / npw; - } - - - /** - * Shows waveform of input audio. - * - * Copied from version in VoiceSearch's RecognitionActivity. - * - * TODO: adjust stroke width based on the size of data. - * TODO: use dip rather than pixels. - */ - private void showWave(ShortBuffer waveBuffer, int startPosition, int endPosition) { - final int w = ((View) mImage.getParent()).getWidth(); - final int h = ((View) mImage.getParent()).getHeight(); - if (w <= 0 || h <= 0) { - // view is not visible this time. Skip drawing. - return; - } - final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); - final Canvas c = new Canvas(b); - final Paint paint = new Paint(); - paint.setColor(0xFFFFFFFF); // 0xAARRGGBB - paint.setAntiAlias(true); - paint.setStyle(Paint.Style.STROKE); - paint.setAlpha(80); - - final PathEffect effect = new CornerPathEffect(3); - paint.setPathEffect(effect); - - final int numSamples = waveBuffer.remaining(); - int endIndex; - if (endPosition == 0) { - endIndex = numSamples; - } else { - endIndex = Math.min(endPosition, numSamples); - } - - int startIndex = startPosition - 2000; // include 250ms before speech - if (startIndex < 0) { - startIndex = 0; - } - final int numSamplePerWave = 200; // 8KHz 25ms = 200 samples - final float scale = 10.0f / 65536.0f; - - final int count = (endIndex - startIndex) / numSamplePerWave; - final float deltaX = 1.0f * w / count; - int yMax = h / 2; - Path path = new Path(); - c.translate(0, yMax); - float x = 0; - path.moveTo(x, 0); - for (int i = 0; i < count; i++) { - final int avabs = getAverageAbs(waveBuffer, startIndex, i , numSamplePerWave); - int sign = ( (i & 01) == 0) ? -1 : 1; - final float y = Math.min(yMax, avabs * h * scale) * sign; - path.lineTo(x, y); - x += deltaX; - path.lineTo(x, y); - } - if (deltaX > 4) { - paint.setStrokeWidth(2); - } else { - paint.setStrokeWidth(Math.max(0, (int) (deltaX -.05))); - } - c.drawPath(path, paint); - mImage.setImageBitmap(b); - } - - public void finish() { - mUiHandler.post(new Runnable() { - @Override - public void run() { - mSoundIndicator.stop(); - } - }); - } -} diff --git a/java/src/com/android/inputmethod/deprecated/voice/SettingsUtil.java b/java/src/com/android/inputmethod/deprecated/voice/SettingsUtil.java deleted file mode 100644 index 855a09a1d..000000000 --- a/java/src/com/android/inputmethod/deprecated/voice/SettingsUtil.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright (C) 2009 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.deprecated.voice; - -import android.content.ContentResolver; -import android.provider.Settings; - -/** - * Utility for retrieving settings from Settings.Secure. - */ -public class SettingsUtil { - /** - * A whitespace-separated list of supported locales for voice input from the keyboard. - */ - public static final String LATIN_IME_VOICE_INPUT_SUPPORTED_LOCALES = - "latin_ime_voice_input_supported_locales"; - - /** - * A whitespace-separated list of recommended app packages for voice input from the - * keyboard. - */ - public static final String LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES = - "latin_ime_voice_input_recommended_packages"; - - /** - * The maximum number of unique days to show the swipe hint for voice input. - */ - public static final String LATIN_IME_VOICE_INPUT_SWIPE_HINT_MAX_DAYS = - "latin_ime_voice_input_swipe_hint_max_days"; - - /** - * The maximum number of times to show the punctuation hint for voice input. - */ - public static final String LATIN_IME_VOICE_INPUT_PUNCTUATION_HINT_MAX_DISPLAYS = - "latin_ime_voice_input_punctuation_hint_max_displays"; - - /** - * Endpointer parameters for voice input from the keyboard. - */ - public static final String LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS = - "latin_ime_speech_minimum_length_millis"; - public static final String LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS = - "latin_ime_speech_input_complete_silence_length_millis"; - public static final String LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS = - "latin_ime_speech_input_possibly_complete_silence_length_millis"; - - /** - * Min and max volume levels that can be displayed on the "speak now" screen. - */ - public static final String LATIN_IME_MIN_MICROPHONE_LEVEL = - "latin_ime_min_microphone_level"; - public static final String LATIN_IME_MAX_MICROPHONE_LEVEL = - "latin_ime_max_microphone_level"; - - /** - * The number of sentence-level alternates to request of the server. - */ - public static final String LATIN_IME_MAX_VOICE_RESULTS = "latin_ime_max_voice_results"; - - /** - * Get a string-valued setting. - * - * @param cr The content resolver to use - * @param key The setting to look up - * @param defaultValue The default value to use if none can be found - * @return The value of the setting, or defaultValue if it couldn't be found - */ - public static String getSettingsString(ContentResolver cr, String key, String defaultValue) { - String result = Settings.Secure.getString(cr, key); - return (result == null) ? defaultValue : result; - } - - /** - * Get an int-valued setting. - * - * @param cr The content resolver to use - * @param key The setting to look up - * @param defaultValue The default value to use if the setting couldn't be found or parsed - * @return The value of the setting, or defaultValue if it couldn't be found or parsed - */ - public static int getSettingsInt(ContentResolver cr, String key, int defaultValue) { - return Settings.Secure.getInt(cr, key, defaultValue); - } - - /** - * Get a float-valued setting. - * - * @param cr The content resolver to use - * @param key The setting to look up - * @param defaultValue The default value to use if the setting couldn't be found or parsed - * @return The value of the setting, or defaultValue if it couldn't be found or parsed - */ - public static float getSettingsFloat(ContentResolver cr, String key, float defaultValue) { - return Settings.Secure.getFloat(cr, key, defaultValue); - } -} diff --git a/java/src/com/android/inputmethod/deprecated/voice/SoundIndicator.java b/java/src/com/android/inputmethod/deprecated/voice/SoundIndicator.java deleted file mode 100644 index 25b314085..000000000 --- a/java/src/com/android/inputmethod/deprecated/voice/SoundIndicator.java +++ /dev/null @@ -1,155 +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.deprecated.voice; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Bitmap.Config; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffXfermode; -import android.graphics.Rect; -import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; -import android.os.Handler; -import android.util.AttributeSet; -import android.widget.ImageView; - -import com.android.inputmethod.latin.R; - -/** - * A widget which shows the volume of audio using a microphone icon - */ -public class SoundIndicator extends ImageView { - @SuppressWarnings("unused") - private static final String TAG = "SoundIndicator"; - - private static final float UP_SMOOTHING_FACTOR = 0.9f; - private static final float DOWN_SMOOTHING_FACTOR = 0.4f; - - private static final float AUDIO_METER_MIN_DB = 7.0f; - private static final float AUDIO_METER_DB_RANGE = 20.0f; - - private static final long FRAME_DELAY = 50; - - private Bitmap mDrawingBuffer; - private Canvas mBufferCanvas; - private Bitmap mEdgeBitmap; - private float mLevel = 0.0f; - private Drawable mFrontDrawable; - private Paint mClearPaint; - private Paint mMultPaint; - private int mEdgeBitmapOffset; - - private Handler mHandler; - - private Runnable mDrawFrame = new Runnable() { - public void run() { - invalidate(); - mHandler.postDelayed(mDrawFrame, FRAME_DELAY); - } - }; - - public SoundIndicator(Context context) { - this(context, null); - } - - public SoundIndicator(Context context, AttributeSet attrs) { - super(context, attrs); - - mFrontDrawable = getDrawable(); - BitmapDrawable edgeDrawable = - (BitmapDrawable) context.getResources().getDrawable(R.drawable.vs_popup_mic_edge); - mEdgeBitmap = edgeDrawable.getBitmap(); - mEdgeBitmapOffset = mEdgeBitmap.getHeight() / 2; - - mDrawingBuffer = - Bitmap.createBitmap(mFrontDrawable.getIntrinsicWidth(), - mFrontDrawable.getIntrinsicHeight(), Config.ARGB_8888); - - mBufferCanvas = new Canvas(mDrawingBuffer); - - // Initialize Paints. - mClearPaint = new Paint(); - mClearPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); - - mMultPaint = new Paint(); - mMultPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY)); - - mHandler = new Handler(); - } - - @Override - public void onDraw(Canvas canvas) { - //super.onDraw(canvas); - - float w = getWidth(); - float h = getHeight(); - - // Clear the buffer canvas - mBufferCanvas.drawRect(0, 0, w, h, mClearPaint); - - // Set its clip so we don't draw the front image all the way to the top - Rect clip = new Rect(0, - (int) ((1.0 - mLevel) * (h + mEdgeBitmapOffset)) - mEdgeBitmapOffset, - (int) w, - (int) h); - - mBufferCanvas.save(); - mBufferCanvas.clipRect(clip); - - // Draw the front image - mFrontDrawable.setBounds(new Rect(0, 0, (int) w, (int) h)); - mFrontDrawable.draw(mBufferCanvas); - - mBufferCanvas.restore(); - - // Draw the edge image on top of the buffer image with a multiply mode - mBufferCanvas.drawBitmap(mEdgeBitmap, 0, clip.top, mMultPaint); - - // Draw the buffer image (on top of the background image) - canvas.drawBitmap(mDrawingBuffer, 0, 0, null); - } - - /** - * Sets the sound level - * - * @param rmsdB The level of the sound, in dB. - */ - public void setRmsdB(float rmsdB) { - float level = ((rmsdB - AUDIO_METER_MIN_DB) / AUDIO_METER_DB_RANGE); - - level = Math.min(Math.max(0.0f, level), 1.0f); - - // We smooth towards the new level - if (level > mLevel) { - mLevel = (level - mLevel) * UP_SMOOTHING_FACTOR + mLevel; - } else { - mLevel = (level - mLevel) * DOWN_SMOOTHING_FACTOR + mLevel; - } - invalidate(); - } - - public void start() { - mHandler.post(mDrawFrame); - } - - public void stop() { - mHandler.removeCallbacks(mDrawFrame); - } -} diff --git a/java/src/com/android/inputmethod/deprecated/voice/VoiceInput.java b/java/src/com/android/inputmethod/deprecated/voice/VoiceInput.java deleted file mode 100644 index 8969a2168..000000000 --- a/java/src/com/android/inputmethod/deprecated/voice/VoiceInput.java +++ /dev/null @@ -1,692 +0,0 @@ -/* - * Copyright (C) 2009 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.deprecated.voice; - -import com.android.inputmethod.latin.EditingUtils; -import com.android.inputmethod.latin.LatinImeLogger; -import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.StaticInnerHandlerWrapper; - -import android.content.ContentResolver; -import android.content.Context; -import android.content.Intent; -import android.content.res.Configuration; -import android.os.Build; -import android.os.Bundle; -import android.os.Message; -import android.os.Parcelable; -import android.speech.RecognitionListener; -import android.speech.RecognizerIntent; -import android.speech.SpeechRecognizer; -import android.util.Log; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.inputmethod.InputConnection; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * Speech recognition input, including both user interface and a background - * process to stream audio to the network recognizer. This class supplies a - * View (getView()), which it updates as recognition occurs. The user of this - * class is responsible for making the view visible to the user, as well as - * handling various events returned through UiListener. - */ -public class VoiceInput implements OnClickListener { - private static final String TAG = "VoiceInput"; - private static final String EXTRA_RECOGNITION_CONTEXT = - "android.speech.extras.RECOGNITION_CONTEXT"; - private static final String EXTRA_CALLING_PACKAGE = "calling_package"; - private static final String EXTRA_ALTERNATES = "android.speech.extra.ALTERNATES"; - private static final int MAX_ALT_LIST_LENGTH = 6; - private static boolean DBG = LatinImeLogger.sDBG; - - private static final String DEFAULT_RECOMMENDED_PACKAGES = - "com.android.mms " + - "com.google.android.gm " + - "com.google.android.talk " + - "com.google.android.apps.googlevoice " + - "com.android.email " + - "com.android.browser "; - - // WARNING! Before enabling this, fix the problem with calling getExtractedText() in - // landscape view. It causes Extracted text updates to be rejected due to a token mismatch - public static boolean ENABLE_WORD_CORRECTIONS = true; - - // Dummy word suggestion which means "delete current word" - public static final String DELETE_SYMBOL = " \u00D7 "; // times symbol - - private Whitelist mRecommendedList; - private Whitelist mBlacklist; - - private VoiceInputLogger mLogger; - - // Names of a few extras defined in VoiceSearch's RecognitionController - // Note, the version of voicesearch that shipped in Froyo returns the raw - // RecognitionClientAlternates protocol buffer under the key "alternates", - // so a VS market update must be installed on Froyo devices in order to see - // alternatives. - private static final String ALTERNATES_BUNDLE = "alternates_bundle"; - - // This is copied from the VoiceSearch app. - @SuppressWarnings("unused") - private static final class AlternatesBundleKeys { - public static final String ALTERNATES = "alternates"; - public static final String CONFIDENCE = "confidence"; - public static final String LENGTH = "length"; - public static final String MAX_SPAN_LENGTH = "max_span_length"; - public static final String SPANS = "spans"; - public static final String SPAN_KEY_DELIMITER = ":"; - public static final String START = "start"; - public static final String TEXT = "text"; - } - - // Names of a few intent extras defined in VoiceSearch's RecognitionService. - // These let us tweak the endpointer parameters. - private static final String EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS = - "android.speech.extras.SPEECH_INPUT_MINIMUM_LENGTH_MILLIS"; - private static final String EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS = - "android.speech.extras.SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS"; - private static final String EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS = - "android.speech.extras.SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS"; - - // The usual endpointer default value for input complete silence length is 0.5 seconds, - // but that's used for things like voice search. For dictation-like voice input like this, - // we go with a more liberal value of 1 second. This value will only be used if a value - // is not provided from Gservices. - private static final String INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS = "1000"; - - // Used to record part of that state for logging purposes. - public static final int DEFAULT = 0; - public static final int LISTENING = 1; - public static final int WORKING = 2; - public static final int ERROR = 3; - - private int mAfterVoiceInputDeleteCount = 0; - private int mAfterVoiceInputInsertCount = 0; - private int mAfterVoiceInputInsertPunctuationCount = 0; - private int mAfterVoiceInputCursorPos = 0; - private int mAfterVoiceInputSelectionSpan = 0; - - private int mState = DEFAULT; - - private final static int MSG_RESET = 1; - - private final UIHandler mHandler = new UIHandler(this); - - private static class UIHandler extends StaticInnerHandlerWrapper { - public UIHandler(VoiceInput outerInstance) { - super(outerInstance); - } - - @Override - public void handleMessage(Message msg) { - if (msg.what == MSG_RESET) { - final VoiceInput voiceInput = getOuterInstance(); - voiceInput.mState = DEFAULT; - voiceInput.mRecognitionView.finish(); - voiceInput.mUiListener.onCancelVoice(); - } - } - }; - - /** - * Events relating to the recognition UI. You must implement these. - */ - public interface UiListener { - - /** - * @param recognitionResults a set of transcripts for what the user - * spoke, sorted by likelihood. - */ - public void onVoiceResults( - List recognitionResults, - Map> alternatives); - - /** - * Called when the user cancels speech recognition. - */ - public void onCancelVoice(); - } - - private SpeechRecognizer mSpeechRecognizer; - private RecognitionListener mRecognitionListener; - private RecognitionView mRecognitionView; - private UiListener mUiListener; - private Context mContext; - - /** - * @param context the service or activity in which we're running. - * @param uiHandler object to receive events from VoiceInput. - */ - public VoiceInput(Context context, UiListener uiHandler) { - mLogger = VoiceInputLogger.getLogger(context); - mRecognitionListener = new ImeRecognitionListener(); - mSpeechRecognizer = SpeechRecognizer.createSpeechRecognizer(context); - mSpeechRecognizer.setRecognitionListener(mRecognitionListener); - mUiListener = uiHandler; - mContext = context; - newView(); - - String recommendedPackages = SettingsUtil.getSettingsString( - context.getContentResolver(), - SettingsUtil.LATIN_IME_VOICE_INPUT_RECOMMENDED_PACKAGES, - DEFAULT_RECOMMENDED_PACKAGES); - - mRecommendedList = new Whitelist(); - for (String recommendedPackage : recommendedPackages.split("\\s+")) { - mRecommendedList.addApp(recommendedPackage); - } - - mBlacklist = new Whitelist(); - mBlacklist.addApp("com.google.android.setupwizard"); - } - - public void setCursorPos(int pos) { - mAfterVoiceInputCursorPos = pos; - } - - public int getCursorPos() { - return mAfterVoiceInputCursorPos; - } - - public void setSelectionSpan(int span) { - mAfterVoiceInputSelectionSpan = span; - } - - public int getSelectionSpan() { - return mAfterVoiceInputSelectionSpan; - } - - public void incrementTextModificationDeleteCount(int count){ - mAfterVoiceInputDeleteCount += count; - // Send up intents for other text modification types - if (mAfterVoiceInputInsertCount > 0) { - logTextModifiedByTypingInsertion(mAfterVoiceInputInsertCount); - mAfterVoiceInputInsertCount = 0; - } - if (mAfterVoiceInputInsertPunctuationCount > 0) { - logTextModifiedByTypingInsertionPunctuation(mAfterVoiceInputInsertPunctuationCount); - mAfterVoiceInputInsertPunctuationCount = 0; - } - - } - - public void incrementTextModificationInsertCount(int count){ - mAfterVoiceInputInsertCount += count; - if (mAfterVoiceInputSelectionSpan > 0) { - // If text was highlighted before inserting the char, count this as - // a delete. - mAfterVoiceInputDeleteCount += mAfterVoiceInputSelectionSpan; - } - // Send up intents for other text modification types - if (mAfterVoiceInputDeleteCount > 0) { - logTextModifiedByTypingDeletion(mAfterVoiceInputDeleteCount); - mAfterVoiceInputDeleteCount = 0; - } - if (mAfterVoiceInputInsertPunctuationCount > 0) { - logTextModifiedByTypingInsertionPunctuation(mAfterVoiceInputInsertPunctuationCount); - mAfterVoiceInputInsertPunctuationCount = 0; - } - } - - public void incrementTextModificationInsertPunctuationCount(int count){ - mAfterVoiceInputInsertPunctuationCount += count; - if (mAfterVoiceInputSelectionSpan > 0) { - // If text was highlighted before inserting the char, count this as - // a delete. - mAfterVoiceInputDeleteCount += mAfterVoiceInputSelectionSpan; - } - // Send up intents for aggregated non-punctuation insertions - if (mAfterVoiceInputDeleteCount > 0) { - logTextModifiedByTypingDeletion(mAfterVoiceInputDeleteCount); - mAfterVoiceInputDeleteCount = 0; - } - if (mAfterVoiceInputInsertCount > 0) { - logTextModifiedByTypingInsertion(mAfterVoiceInputInsertCount); - mAfterVoiceInputInsertCount = 0; - } - } - - public void flushAllTextModificationCounters() { - if (mAfterVoiceInputInsertCount > 0) { - logTextModifiedByTypingInsertion(mAfterVoiceInputInsertCount); - mAfterVoiceInputInsertCount = 0; - } - if (mAfterVoiceInputDeleteCount > 0) { - logTextModifiedByTypingDeletion(mAfterVoiceInputDeleteCount); - mAfterVoiceInputDeleteCount = 0; - } - if (mAfterVoiceInputInsertPunctuationCount > 0) { - logTextModifiedByTypingInsertionPunctuation(mAfterVoiceInputInsertPunctuationCount); - mAfterVoiceInputInsertPunctuationCount = 0; - } - } - - /** - * The configuration of the IME changed and may have caused the views to be layed out - * again. Restore the state of the recognition view. - */ - public void onConfigurationChanged(Configuration configuration) { - mRecognitionView.restoreState(); - mRecognitionView.getView().dispatchConfigurationChanged(configuration); - } - - /** - * @return true if field is blacklisted for voice - */ - public boolean isBlacklistedField(FieldContext context) { - return mBlacklist.matches(context); - } - - /** - * Used to decide whether to show voice input hints for this field, etc. - * - * @return true if field is recommended for voice - */ - public boolean isRecommendedField(FieldContext context) { - return mRecommendedList.matches(context); - } - - /** - * Start listening for speech from the user. This will grab the microphone - * and start updating the view provided by getView(). It is the caller's - * responsibility to ensure that the view is visible to the user at this stage. - * - * @param context the same FieldContext supplied to voiceIsEnabled() - * @param swipe whether this voice input was started by swipe, for logging purposes - */ - public void startListening(FieldContext context, boolean swipe) { - if (DBG) { - Log.d(TAG, "startListening: " + context); - } - - if (mState != DEFAULT) { - Log.w(TAG, "startListening in the wrong status " + mState); - } - - // If everything works ok, the voice input should be already in the correct state. As this - // class can be called by third-party, we call reset just to be on the safe side. - reset(); - - Locale locale = Locale.getDefault(); - String localeString = locale.getLanguage() + "-" + locale.getCountry(); - - mLogger.start(localeString, swipe); - - mState = LISTENING; - - mRecognitionView.showInitializing(); - startListeningAfterInitialization(context); - } - - /** - * Called only when the recognition manager's initialization completed - * - * @param context context with which {@link #startListening(FieldContext, boolean)} was executed - */ - private void startListeningAfterInitialization(FieldContext context) { - Intent intent = makeIntent(); - intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, ""); - intent.putExtra(EXTRA_RECOGNITION_CONTEXT, context.getBundle()); - intent.putExtra(EXTRA_CALLING_PACKAGE, "VoiceIME"); - intent.putExtra(EXTRA_ALTERNATES, true); - intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, - SettingsUtil.getSettingsInt( - mContext.getContentResolver(), - SettingsUtil.LATIN_IME_MAX_VOICE_RESULTS, - 1)); - // Get endpointer params from Gservices. - // TODO: Consider caching these values for improved performance on slower devices. - final ContentResolver cr = mContext.getContentResolver(); - putEndpointerExtra( - cr, - intent, - SettingsUtil.LATIN_IME_SPEECH_MINIMUM_LENGTH_MILLIS, - EXTRA_SPEECH_MINIMUM_LENGTH_MILLIS, - null /* rely on endpointer default */); - putEndpointerExtra( - cr, - intent, - SettingsUtil.LATIN_IME_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, - EXTRA_SPEECH_INPUT_COMPLETE_SILENCE_LENGTH_MILLIS, - INPUT_COMPLETE_SILENCE_LENGTH_DEFAULT_VALUE_MILLIS - /* our default value is different from the endpointer's */); - putEndpointerExtra( - cr, - intent, - SettingsUtil. - LATIN_IME_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, - EXTRA_SPEECH_INPUT_POSSIBLY_COMPLETE_SILENCE_LENGTH_MILLIS, - null /* rely on endpointer default */); - - mSpeechRecognizer.startListening(intent); - } - - /** - * Gets the value of the provided Gservices key, attempts to parse it into a long, - * and if successful, puts the long value as an extra in the provided intent. - */ - private void putEndpointerExtra(ContentResolver cr, Intent i, - String gservicesKey, String intentExtraKey, String defaultValue) { - long l = -1; - String s = SettingsUtil.getSettingsString(cr, gservicesKey, defaultValue); - if (s != null) { - try { - l = Long.valueOf(s); - } catch (NumberFormatException e) { - Log.e(TAG, "could not parse value for " + gservicesKey + ": " + s); - } - } - - if (l != -1) i.putExtra(intentExtraKey, l); - } - - public void destroy() { - mSpeechRecognizer.destroy(); - } - - /** - * Creates a new instance of the view that is returned by {@link #getView()} - * Clients should use this when a previously returned view is stuck in a - * layout that is being thrown away and a new one is need to show to the - * user. - */ - public void newView() { - mRecognitionView = new RecognitionView(mContext, this); - } - - /** - * @return a view that shows the recognition flow--e.g., "Speak now" and - * "working" dialogs. - */ - public View getView() { - return mRecognitionView.getView(); - } - - /** - * Handle the cancel button. - */ - @Override - public void onClick(View view) { - switch(view.getId()) { - case R.id.button: - cancel(); - break; - } - } - - public void logTextModifiedByTypingInsertion(int length) { - mLogger.textModifiedByTypingInsertion(length); - } - - public void logTextModifiedByTypingInsertionPunctuation(int length) { - mLogger.textModifiedByTypingInsertionPunctuation(length); - } - - public void logTextModifiedByTypingDeletion(int length) { - mLogger.textModifiedByTypingDeletion(length); - } - - public void logTextModifiedByChooseSuggestion(String suggestion, int index, - String wordSeparators, InputConnection ic) { - String wordToBeReplaced = EditingUtils.getWordAtCursor(ic, wordSeparators); - // If we enable phrase-based alternatives, only send up the first word - // in suggestion and wordToBeReplaced. - mLogger.textModifiedByChooseSuggestion(suggestion.length(), wordToBeReplaced.length(), - index, wordToBeReplaced, suggestion); - } - - public void logKeyboardWarningDialogShown() { - mLogger.keyboardWarningDialogShown(); - } - - public void logKeyboardWarningDialogDismissed() { - mLogger.keyboardWarningDialogDismissed(); - } - - public void logKeyboardWarningDialogOk() { - mLogger.keyboardWarningDialogOk(); - } - - public void logKeyboardWarningDialogCancel() { - mLogger.keyboardWarningDialogCancel(); - } - - public void logSwipeHintDisplayed() { - mLogger.swipeHintDisplayed(); - } - - public void logPunctuationHintDisplayed() { - mLogger.punctuationHintDisplayed(); - } - - public void logVoiceInputDelivered(int length) { - mLogger.voiceInputDelivered(length); - } - - public void logInputEnded() { - mLogger.inputEnded(); - } - - public void flushLogs() { - mLogger.flush(); - } - - private static Intent makeIntent() { - Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); - - // On Cupcake, use VoiceIMEHelper since VoiceSearch doesn't support. - // On Donut, always use VoiceSearch, since VoiceIMEHelper and - // VoiceSearch may conflict. - if (Build.VERSION.RELEASE.equals("1.5")) { - intent = intent.setClassName( - "com.google.android.voiceservice", - "com.google.android.voiceservice.IMERecognitionService"); - } else { - intent = intent.setClassName( - "com.google.android.voicesearch", - "com.google.android.voicesearch.RecognitionService"); - } - - return intent; - } - - /** - * Reset the current voice recognition. - */ - public void reset() { - if (mState != DEFAULT) { - mState = DEFAULT; - - // Remove all pending tasks (e.g., timers to cancel voice input) - mHandler.removeMessages(MSG_RESET); - - mSpeechRecognizer.cancel(); - mRecognitionView.finish(); - } - } - - /** - * Cancel in-progress speech recognition. - */ - public void cancel() { - switch (mState) { - case LISTENING: - mLogger.cancelDuringListening(); - break; - case WORKING: - mLogger.cancelDuringWorking(); - break; - case ERROR: - mLogger.cancelDuringError(); - break; - } - - reset(); - mUiListener.onCancelVoice(); - } - - private int getErrorStringId(int errorType, boolean endpointed) { - switch (errorType) { - // We use CLIENT_ERROR to signify that voice search is not available on the device. - case SpeechRecognizer.ERROR_CLIENT: - return R.string.voice_not_installed; - case SpeechRecognizer.ERROR_NETWORK: - return R.string.voice_network_error; - case SpeechRecognizer.ERROR_NETWORK_TIMEOUT: - return endpointed ? - R.string.voice_network_error : R.string.voice_too_much_speech; - case SpeechRecognizer.ERROR_AUDIO: - return R.string.voice_audio_error; - case SpeechRecognizer.ERROR_SERVER: - return R.string.voice_server_error; - case SpeechRecognizer.ERROR_SPEECH_TIMEOUT: - return R.string.voice_speech_timeout; - case SpeechRecognizer.ERROR_NO_MATCH: - return R.string.voice_no_match; - default: return R.string.voice_error; - } - } - - private void onError(int errorType, boolean endpointed) { - Log.i(TAG, "error " + errorType); - mLogger.error(errorType); - onError(mContext.getString(getErrorStringId(errorType, endpointed))); - } - - private void onError(String error) { - mState = ERROR; - mRecognitionView.showError(error); - // Wait a couple seconds and then automatically dismiss message. - mHandler.sendMessageDelayed(Message.obtain(mHandler, MSG_RESET), 2000); - } - - private class ImeRecognitionListener implements RecognitionListener { - // Waveform data - final ByteArrayOutputStream mWaveBuffer = new ByteArrayOutputStream(); - int mSpeechStart; - private boolean mEndpointed = false; - - @Override - public void onReadyForSpeech(Bundle noiseParams) { - mRecognitionView.showListening(); - } - - @Override - public void onBeginningOfSpeech() { - mEndpointed = false; - mSpeechStart = mWaveBuffer.size(); - } - - @Override - public void onRmsChanged(float rmsdB) { - mRecognitionView.updateVoiceMeter(rmsdB); - } - - @Override - public void onBufferReceived(byte[] buf) { - try { - mWaveBuffer.write(buf); - } catch (IOException e) { - // ignore. - } - } - - @Override - public void onEndOfSpeech() { - mEndpointed = true; - mState = WORKING; - mRecognitionView.showWorking(mWaveBuffer, mSpeechStart, mWaveBuffer.size()); - } - - @Override - public void onError(int errorType) { - mState = ERROR; - VoiceInput.this.onError(errorType, mEndpointed); - } - - @Override - public void onResults(Bundle resultsBundle) { - List results = resultsBundle - .getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION); - // VS Market update is needed for IME froyo clients to access the alternatesBundle - // TODO: verify this. - Bundle alternatesBundle = resultsBundle.getBundle(ALTERNATES_BUNDLE); - mState = DEFAULT; - - final Map> alternatives = - new HashMap>(); - - if (ENABLE_WORD_CORRECTIONS && alternatesBundle != null && results.size() > 0) { - // Use the top recognition result to map each alternative's start:length to a word. - String[] words = results.get(0).split(" "); - Bundle spansBundle = alternatesBundle.getBundle(AlternatesBundleKeys.SPANS); - for (String key : spansBundle.keySet()) { - // Get the word for which these alternates correspond to. - Bundle spanBundle = spansBundle.getBundle(key); - int start = spanBundle.getInt(AlternatesBundleKeys.START); - int length = spanBundle.getInt(AlternatesBundleKeys.LENGTH); - // Only keep single-word based alternatives. - if (length == 1 && start < words.length) { - // Get the alternatives associated with the span. - // If a word appears twice in a recognition result, - // concatenate the alternatives for the word. - List altList = alternatives.get(words[start]); - if (altList == null) { - altList = new ArrayList(); - alternatives.put(words[start], altList); - } - Parcelable[] alternatesArr = spanBundle - .getParcelableArray(AlternatesBundleKeys.ALTERNATES); - for (int j = 0; j < alternatesArr.length && - altList.size() < MAX_ALT_LIST_LENGTH; j++) { - Bundle alternateBundle = (Bundle) alternatesArr[j]; - String alternate = alternateBundle.getString(AlternatesBundleKeys.TEXT); - // Don't allow duplicates in the alternates list. - if (!altList.contains(alternate)) { - altList.add(alternate); - } - } - } - } - } - - if (results.size() > 5) { - results = results.subList(0, 5); - } - mUiListener.onVoiceResults(results, alternatives); - mRecognitionView.finish(); - } - - @Override - public void onPartialResults(final Bundle partialResults) { - // currently - do nothing - } - - @Override - public void onEvent(int eventType, Bundle params) { - // do nothing - reserved for events that might be added in the future - } - } -} diff --git a/java/src/com/android/inputmethod/deprecated/voice/VoiceInputLogger.java b/java/src/com/android/inputmethod/deprecated/voice/VoiceInputLogger.java deleted file mode 100644 index 22e8207bf..000000000 --- a/java/src/com/android/inputmethod/deprecated/voice/VoiceInputLogger.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (C) 2008 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.deprecated.voice; - -import com.android.common.speech.LoggingEvents; -import com.android.inputmethod.deprecated.compat.VoiceInputLoggerCompatUtils; - -import android.content.Context; -import android.content.Intent; - -/** - * Provides the logging facility for voice input events. This fires broadcasts back to - * the voice search app which then logs on our behalf. - * - * Note that debug console logging does not occur in this class. If you want to - * see console output of these logging events, there is a boolean switch to turn - * on on the VoiceSearch side. - */ -public class VoiceInputLogger { - @SuppressWarnings("unused") - private static final String TAG = VoiceInputLogger.class.getSimpleName(); - - private static VoiceInputLogger sVoiceInputLogger; - - private final Context mContext; - - // The base intent used to form all broadcast intents to the logger - // in VoiceSearch. - private final Intent mBaseIntent; - - // This flag is used to indicate when there are voice events that - // need to be flushed. - private boolean mHasLoggingInfo = false; - - /** - * Returns the singleton of the logger. - * - * @param contextHint a hint context used when creating the logger instance. - * Ignored if the singleton instance already exists. - */ - public static synchronized VoiceInputLogger getLogger(Context contextHint) { - if (sVoiceInputLogger == null) { - sVoiceInputLogger = new VoiceInputLogger(contextHint); - } - return sVoiceInputLogger; - } - - public VoiceInputLogger(Context context) { - mContext = context; - - mBaseIntent = new Intent(LoggingEvents.ACTION_LOG_EVENT); - mBaseIntent.putExtra(LoggingEvents.EXTRA_APP_NAME, LoggingEvents.VoiceIme.APP_NAME); - } - - private Intent newLoggingBroadcast(int event) { - Intent i = new Intent(mBaseIntent); - i.putExtra(LoggingEvents.EXTRA_EVENT, event); - return i; - } - - public void flush() { - if (hasLoggingInfo()) { - Intent i = new Intent(mBaseIntent); - i.putExtra(LoggingEvents.EXTRA_FLUSH, true); - mContext.sendBroadcast(i); - setHasLoggingInfo(false); - } - } - - public void keyboardWarningDialogShown() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.KEYBOARD_WARNING_DIALOG_SHOWN)); - } - - public void keyboardWarningDialogDismissed() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.KEYBOARD_WARNING_DIALOG_DISMISSED)); - } - - public void keyboardWarningDialogOk() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.KEYBOARD_WARNING_DIALOG_OK)); - } - - public void keyboardWarningDialogCancel() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.KEYBOARD_WARNING_DIALOG_CANCEL)); - } - - public void settingsWarningDialogShown() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.SETTINGS_WARNING_DIALOG_SHOWN)); - } - - public void settingsWarningDialogDismissed() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.SETTINGS_WARNING_DIALOG_DISMISSED)); - } - - public void settingsWarningDialogOk() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.SETTINGS_WARNING_DIALOG_OK)); - } - - public void settingsWarningDialogCancel() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.SETTINGS_WARNING_DIALOG_CANCEL)); - } - - public void swipeHintDisplayed() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast(LoggingEvents.VoiceIme.SWIPE_HINT_DISPLAYED)); - } - - public void cancelDuringListening() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast(LoggingEvents.VoiceIme.CANCEL_DURING_LISTENING)); - } - - public void cancelDuringWorking() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast(LoggingEvents.VoiceIme.CANCEL_DURING_WORKING)); - } - - public void cancelDuringError() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast(LoggingEvents.VoiceIme.CANCEL_DURING_ERROR)); - } - - public void punctuationHintDisplayed() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.PUNCTUATION_HINT_DISPLAYED)); - } - - public void error(int code) { - setHasLoggingInfo(true); - Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.ERROR); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_ERROR_CODE, code); - mContext.sendBroadcast(i); - } - - public void start(String locale, boolean swipe) { - setHasLoggingInfo(true); - Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.START); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_START_LOCALE, locale); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_START_SWIPE, swipe); - i.putExtra(LoggingEvents.EXTRA_TIMESTAMP, System.currentTimeMillis()); - mContext.sendBroadcast(i); - } - - public void voiceInputDelivered(int length) { - setHasLoggingInfo(true); - Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.VOICE_INPUT_DELIVERED); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length); - mContext.sendBroadcast(i); - } - - public void textModifiedByTypingInsertion(int length) { - setHasLoggingInfo(true); - Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_TYPE, - LoggingEvents.VoiceIme.TEXT_MODIFIED_TYPE_TYPING_INSERTION); - mContext.sendBroadcast(i); - } - - public void textModifiedByTypingInsertionPunctuation(int length) { - setHasLoggingInfo(true); - Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_TYPE, - LoggingEvents.VoiceIme.TEXT_MODIFIED_TYPE_TYPING_INSERTION_PUNCTUATION); - mContext.sendBroadcast(i); - } - - public void textModifiedByTypingDeletion(int length) { - setHasLoggingInfo(true); - Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, length); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_TYPE, - LoggingEvents.VoiceIme.TEXT_MODIFIED_TYPE_TYPING_DELETION); - - mContext.sendBroadcast(i); - } - - - public void textModifiedByChooseSuggestion(int suggestionLength, int replacedPhraseLength, - int index, String before, String after) { - setHasLoggingInfo(true); - Intent i = newLoggingBroadcast(LoggingEvents.VoiceIme.TEXT_MODIFIED); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_LENGTH, suggestionLength); - i.putExtra(VoiceInputLoggerCompatUtils.EXTRA_TEXT_REPLACED_LENGTH, replacedPhraseLength); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_TEXT_MODIFIED_TYPE, - LoggingEvents.VoiceIme.TEXT_MODIFIED_TYPE_CHOOSE_SUGGESTION); - i.putExtra(LoggingEvents.VoiceIme.EXTRA_N_BEST_CHOOSE_INDEX, index); - i.putExtra(VoiceInputLoggerCompatUtils.EXTRA_BEFORE_N_BEST_CHOOSE, before); - i.putExtra(VoiceInputLoggerCompatUtils.EXTRA_AFTER_N_BEST_CHOOSE, after); - mContext.sendBroadcast(i); - } - - public void inputEnded() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast(LoggingEvents.VoiceIme.INPUT_ENDED)); - } - - public void voiceInputSettingEnabled() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.VOICE_INPUT_SETTING_ENABLED)); - } - - public void voiceInputSettingDisabled() { - setHasLoggingInfo(true); - mContext.sendBroadcast(newLoggingBroadcast( - LoggingEvents.VoiceIme.VOICE_INPUT_SETTING_DISABLED)); - } - - private void setHasLoggingInfo(boolean hasLoggingInfo) { - mHasLoggingInfo = hasLoggingInfo; - // If applications that call UserHappinessSignals.userAcceptedImeText - // make that call after VoiceInputLogger.flush() calls this method with false, we - // will lose those happiness signals. For example, consider the gmail sequence: - // 1. compose message - // 2. speak message into message field - // 3. type subject into subject field - // 4. press send - // We will NOT get the signal that the user accepted the voice inputted message text - // because when the user tapped on the subject field, the ime's flush will be triggered - // and the hasLoggingInfo will be then set to false. So by the time the user hits send - // we have essentially forgotten about any voice input. - // However the following (more common) use case is properly logged - // 1. compose message - // 2. type subject in subject field - // 3. speak message in message field - // 4. press send - VoiceInputLoggerCompatUtils.setHasVoiceLoggingInfoCompat(hasLoggingInfo); - } - - private boolean hasLoggingInfo(){ - return mHasLoggingInfo; - } - -} diff --git a/java/src/com/android/inputmethod/deprecated/voice/WaveformImage.java b/java/src/com/android/inputmethod/deprecated/voice/WaveformImage.java deleted file mode 100644 index 8ed279f42..000000000 --- a/java/src/com/android/inputmethod/deprecated/voice/WaveformImage.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2008-2009 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.deprecated.voice; - -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Paint; - -import java.io.ByteArrayOutputStream; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.ShortBuffer; - -/** - * Utility class to draw a waveform into a bitmap, given a byte array - * that represents the waveform as a sequence of 16-bit integers. - * Adapted from RecognitionActivity.java. - */ -public class WaveformImage { - private static final int SAMPLING_RATE = 8000; - - private WaveformImage() { - // Intentional empty constructor. - } - - public static Bitmap drawWaveform( - ByteArrayOutputStream waveBuffer, int w, int h, int start, int end) { - final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); - final Canvas c = new Canvas(b); - final Paint paint = new Paint(); - paint.setColor(0xFFFFFFFF); // 0xRRGGBBAA - paint.setAntiAlias(true); - paint.setStrokeWidth(0); - - final ShortBuffer buf = ByteBuffer - .wrap(waveBuffer.toByteArray()) - .order(ByteOrder.nativeOrder()) - .asShortBuffer(); - buf.position(0); - - final int numSamples = waveBuffer.size() / 2; - final int delay = (SAMPLING_RATE * 100 / 1000); - int endIndex = end / 2 + delay; - if (end == 0 || endIndex >= numSamples) { - endIndex = numSamples; - } - int index = start / 2 - delay; - if (index < 0) { - index = 0; - } - final int size = endIndex - index; - int numSamplePerPixel = 32; - int delta = size / (numSamplePerPixel * w); - if (delta == 0) { - numSamplePerPixel = size / w; - delta = 1; - } - - final float scale = 3.5f / 65536.0f; - // do one less column to make sure we won't read past - // the buffer. - try { - for (int i = 0; i < w - 1 ; i++) { - final float x = i; - for (int j = 0; j < numSamplePerPixel; j++) { - final short s = buf.get(index); - final float y = (h / 2) - (s * h * scale); - c.drawPoint(x, y, paint); - index += delta; - } - } - } catch (IndexOutOfBoundsException e) { - // this can happen, but we don't care - } - - return b; - } -} diff --git a/java/src/com/android/inputmethod/deprecated/voice/Whitelist.java b/java/src/com/android/inputmethod/deprecated/voice/Whitelist.java deleted file mode 100644 index 6c5f52ae2..000000000 --- a/java/src/com/android/inputmethod/deprecated/voice/Whitelist.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2009 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.deprecated.voice; - -import android.os.Bundle; - -import java.util.ArrayList; -import java.util.List; - -/** - * A set of text fields where speech has been explicitly enabled. - */ -public class Whitelist { - private List mConditions; - - public Whitelist() { - mConditions = new ArrayList(); - } - - public Whitelist(List conditions) { - this.mConditions = conditions; - } - - public void addApp(String app) { - Bundle bundle = new Bundle(); - bundle.putString("packageName", app); - mConditions.add(bundle); - } - - /** - * @return true if the field is a member of the whitelist. - */ - public boolean matches(FieldContext context) { - for (Bundle condition : mConditions) { - if (matches(condition, context.getBundle())) { - return true; - } - } - return false; - } - - /** - * @return true of all values in condition are matched by a value - * in target. - */ - private boolean matches(Bundle condition, Bundle target) { - for (String key : condition.keySet()) { - if (!condition.getString(key).equals(target.getString(key))) { - return false; - } - } - return true; - } -} diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index 1bf2fc04e..c17fe8628 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -390,30 +390,4 @@ public class KeyboardSet { } } } - - // TODO: Should be removed. This is no longer required if {@link InputMethodSubtype} is - // supported. - public static String parseKeyboardLocale(Resources res, int resId) - throws XmlPullParserException, IOException { - final XmlPullParser parser = res.getXml(resId); - if (parser == null) - return ""; - int event; - while ((event = parser.next()) != XmlPullParser.END_DOCUMENT) { - if (event == XmlPullParser.START_TAG) { - final String tag = parser.getName(); - if (TAG_KEYBOARD_SET.equals(tag)) { - final TypedArray keyboardSetAttr = res.obtainAttributes( - Xml.asAttributeSet(parser), R.styleable.KeyboardSet); - final String locale = keyboardSetAttr.getString( - R.styleable.KeyboardSet_keyboardLocale); - keyboardSetAttr.recycle(); - return locale; - } else { - throw new XmlParseUtils.IllegalStartTag(parser, TAG_KEYBOARD_SET); - } - } - } - return ""; - } } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 7194cced3..62bcf6ca8 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -39,7 +39,6 @@ import android.widget.PopupWindow; import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy; -import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.keyboard.PointerTracker.DrawingProxy; import com.android.inputmethod.keyboard.PointerTracker.TimerProxy; import com.android.inputmethod.keyboard.internal.KeySpecParser; @@ -828,12 +827,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke } } - @Override - protected void onAttachedToWindow() { - // Token is available from here. - VoiceProxy.getInstance().onAttachedToWindow(); - } - /** * Receives hover events from the input framework. This method overrides * View.dispatchHoverEvent(MotionEvent) on SDK version ICS or higher. On diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 8b32be937..f5909a692 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -60,8 +60,6 @@ import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; import com.android.inputmethod.compat.InputTypeCompatUtils; import com.android.inputmethod.compat.SuggestionSpanUtils; -import com.android.inputmethod.deprecated.LanguageSwitcherProxy; -import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardId; @@ -193,7 +191,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private SharedPreferences mPrefs; /* package for tests */ final KeyboardSwitcher mKeyboardSwitcher; private final SubtypeSwitcher mSubtypeSwitcher; - private VoiceProxy mVoiceProxy; private boolean mShouldSwitchToLastSubtype = true; private UserDictionary mUserDictionary; @@ -234,7 +231,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public static class UIHandler extends StaticInnerHandlerWrapper { private static final int MSG_UPDATE_SHIFT_STATE = 1; - private static final int MSG_VOICE_RESULTS = 2; private static final int MSG_SPACE_TYPED = 4; private static final int MSG_SET_BIGRAM_PREDICTIONS = 5; private static final int MSG_PENDING_IMS_CALLBACK = 6; @@ -272,11 +268,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar case MSG_SET_BIGRAM_PREDICTIONS: latinIme.updateBigramPredictions(); break; - case MSG_VOICE_RESULTS: - final Keyboard keyboard = switcher.getKeyboard(); - latinIme.mVoiceProxy.handleVoiceResults(latinIme.preferCapitalization() - || (keyboard != null && keyboard.isShiftedOrShiftLocked())); - break; } } @@ -311,10 +302,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar removeMessages(MSG_SET_BIGRAM_PREDICTIONS); } - public void updateVoiceResults() { - sendMessage(obtainMessage(MSG_VOICE_RESULTS)); - } - public void startDoubleSpacesTimer() { removeMessages(MSG_SPACE_TYPED); sendMessageDelayed(obtainMessage(MSG_SPACE_TYPED), mDoubleSpacesTurnIntoPeriodTimeout); @@ -436,7 +423,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.init(this, prefs); } - LanguageSwitcherProxy.init(this, prefs); InputMethodManagerCompatWrapper.init(this); SubtypeSwitcher.init(this); KeyboardSwitcher.init(this, prefs); @@ -476,7 +462,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); registerReceiver(mReceiver, filter); - mVoiceProxy = VoiceProxy.init(this, prefs, mHandler); final IntentFilter packageFilter = new IntentFilter(); packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED); @@ -577,7 +562,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } unregisterReceiver(mReceiver); unregisterReceiver(mDictionaryPackInstallReceiver); - mVoiceProxy.destroy(); LatinImeLogger.commit(); LatinImeLogger.onDestroy(); super.onDestroy(); @@ -596,14 +580,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (isShowingOptionDialog()) mOptionsDialog.dismiss(); } - - mVoiceProxy.startChangingConfiguration(); super.onConfigurationChanged(conf); - mVoiceProxy.onConfigurationChanged(conf); - mVoiceProxy.finishChangingConfiguration(); - - // This will work only when the subtype is not supported. - LanguageSwitcherProxy.onConfigurationChanged(conf); } @Override @@ -698,13 +675,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSubtypeSwitcher.updateParametersOnStartInputView(); - // Most such things we decide below in initializeInputAttributesAndGetMode, but we need to - // know now whether this is a password text field, because we need to know now whether we - // want to enable the voice button. - final int inputType = editorInfo.inputType; - mVoiceProxy.resetVoiceStates(InputTypeCompatUtils.isPasswordInputType(inputType) - || InputTypeCompatUtils.isVisiblePasswordInputType(inputType)); - // The EditorInfo might have a flag that affects fullscreen mode. // Note: This call should be done by InputMethodService? updateFullscreenMode(); @@ -726,9 +696,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (mSuggest != null && mSettingsValues.mAutoCorrectEnabled) { mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); } - mVoiceProxy.loadSettings(editorInfo, mPrefs); - // This will work only when the subtype is not supported. - LanguageSwitcherProxy.loadSettings(); if (mSubtypeSwitcher.isKeyboardMode()) { switcher.loadKeyboard(editorInfo, mSettingsValues); @@ -746,8 +713,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mSettingsValues.mKeyPreviewPopupDismissDelay); inputView.setProximityCorrectionEnabled(true); - mVoiceProxy.onStartInputView(inputView.getWindowToken()); - if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); } @@ -763,8 +728,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar LatinImeLogger.commit(); - mVoiceProxy.flushVoiceInputLogs(); - KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.closing(); if (mUserHistoryDictionary != null) mUserHistoryDictionary.flushPendingWrites(); @@ -779,12 +742,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mHandler.cancelUpdateSuggestions(); } - @Override - public void onUpdateExtractedText(int token, ExtractedText text) { - super.onUpdateExtractedText(token, text); - mVoiceProxy.showPunctuationHintIfNecessary(); - } - @Override public void onUpdateSelection(int oldSelStart, int oldSelEnd, int newSelStart, int newSelEnd, @@ -816,8 +773,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar + ", ce=" + composingSpanEnd); } - mVoiceProxy.setCursorAndSelection(newSelEnd, newSelStart); - // TODO: refactor the following code to be less contrived. // "newSelStart != composingSpanEnd" || "newSelEnd != composingSpanEnd" means // that the cursor is not at the end of the composing span, or there is a selection. @@ -905,7 +860,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mOptionsDialog.dismiss(); mOptionsDialog = null; } - mVoiceProxy.hideVoiceWindow(); super.hideWindow(); } @@ -1094,7 +1048,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (ic != null) { ic.finishComposingText(); } - mVoiceProxy.setVoiceInputHighlighted(false); } private void resetComposingState(final boolean alsoResetLastComposedWord) { @@ -1184,14 +1137,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void onSettingsKeyPressed() { if (isShowingOptionDialog()) return; - if (InputMethodServiceCompatWrapper.CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) { - showSubtypeSelectorAndSettings(); - } else if (SubtypeUtils.hasMultipleEnabledIMEsOrSubtypes( - false /* exclude aux subtypes */)) { - showOptionsMenu(); - } else { - launchSettings(); - } + showSubtypeSelectorAndSettings(); } // Virtual codes representing custom requests. These are used in onCustomRequest() below. @@ -1351,7 +1297,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void onTextInput(CharSequence text) { - mVoiceProxy.commitVoiceInput(); final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; ic.beginBatchEdit(); @@ -1396,7 +1341,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } private void handleBackspace(final int spaceState) { - if (mVoiceProxy.logAndRevertVoiceInput()) return; final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; ic.beginBatchEdit(); @@ -1406,8 +1350,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // "ic" may not be null. private void handleBackspaceWhileInBatchEdit(final int spaceState, final InputConnection ic) { - mVoiceProxy.handleBackspace(); - // In many cases, we may have to put the keyboard in auto-shift state again. mHandler.postUpdateShiftState(); @@ -1506,7 +1448,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void handleCharacter(final int primaryCode, final int x, final int y, final int spaceState) { - mVoiceProxy.handleCharacter(); final InputConnection ic = getCurrentInputConnection(); if (null != ic) ic.beginBatchEdit(); // TODO: if ic is null, does it make any sense to call this? @@ -1582,8 +1523,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Returns true if we did an autocorrection, false otherwise. private boolean handleSeparator(final int primaryCode, final int x, final int y, final int spaceState) { - mVoiceProxy.handleSeparator(); - // Should dismiss the "Touch again to save" message when handling separator if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) { mHandler.cancelUpdateBigramPredictions(); @@ -1669,7 +1608,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void handleClose() { commitTyped(getCurrentInputConnection(), LastComposedWord.NOT_A_SEPARATOR); - mVoiceProxy.handleClose(); requestHideSelf(0); LatinKeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) @@ -1749,8 +1687,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar public void updateSuggestions() { // Check if we have a suggestion engine attached. - if ((mSuggest == null || !isSuggestionsRequested()) - && !mVoiceProxy.isVoiceInputHighlighted()) { + if ((mSuggest == null || !isSuggestionsRequested())) { if (mWordComposer.isComposingWord()) { Log.w(TAG, "Called updateSuggestions but suggestions were not requested!"); mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); @@ -1859,8 +1796,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void pickSuggestionManually(final int index, final CharSequence suggestion) { final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); - mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion, - mSettingsValues.mWordSeparators); if (SPACE_STATE_PHANTOM == mSpaceState && suggestion.length() > 0) { int firstChar = Character.codePointAt(suggestion, 0); @@ -1953,7 +1888,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final int separatorCode) { final InputConnection ic = getCurrentInputConnection(); if (ic != null) { - mVoiceProxy.rememberReplacedWord(bestWord, mSettingsValues.mWordSeparators); if (mSettingsValues.mEnableSuggestionSpanInsertion) { final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); ic.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan( @@ -2206,11 +2140,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Notify that language or mode have been changed and toggleLanguage will update KeyboardID // according to new language or mode. public void onRefreshKeyboard() { - if (!CAN_HANDLE_ON_CURRENT_INPUT_METHOD_SUBTYPE_CHANGED) { - // Before Honeycomb, Voice IME is in LatinIME and it changes the current input view, - // so that we need to re-create the keyboard input view here. - setInputView(mKeyboardSwitcher.onCreateInputView()); - } // When the device locale is changed in SetupWizard etc., this method may get called via // onConfigurationChanged before SoftInputWindow is shown. if (mKeyboardSwitcher.getKeyboardView() != null) { @@ -2269,11 +2198,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } }; - // TODO: remove this method when VoiceProxy has been removed - public void vibrate() { - mFeedbackManager.vibrate(mKeyboardSwitcher.getKeyboardView()); - } - private void updateCorrectionMode() { // TODO: cleanup messy flags final boolean shouldAutoCorrect = mSettingsValues.mAutoCorrectEnabled @@ -2341,32 +2265,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar showOptionDialogInternal(builder.create()); } - private void showOptionsMenu() { - final CharSequence title = getString(R.string.english_ime_input_options); - final CharSequence[] items = new CharSequence[] { - getString(R.string.selectInputMethod), - getString(R.string.english_ime_settings), - }; - final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface di, int position) { - di.dismiss(); - switch (position) { - case 0: - mImm.showInputMethodPicker(); - break; - case 1: - launchSettings(); - break; - } - } - }; - final AlertDialog.Builder builder = new AlertDialog.Builder(this) - .setItems(items, listener) - .setTitle(title); - showOptionDialogInternal(builder.create()); - } - @Override protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) { super.dump(fd, fout, args); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 110264892..650dcdc68 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -45,15 +45,13 @@ import android.widget.TextView; import com.android.inputmethod.compat.CompatUtils; import com.android.inputmethod.compat.InputMethodServiceCompatWrapper; import com.android.inputmethod.compat.VibratorCompatWrapper; -import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethodcommon.InputMethodSettingsActivity; import java.util.Locale; public class Settings extends InputMethodSettingsActivity - implements SharedPreferences.OnSharedPreferenceChangeListener, - DialogInterface.OnDismissListener, OnPreferenceClickListener { + implements SharedPreferences.OnSharedPreferenceChangeListener, OnPreferenceClickListener { private static final String TAG = Settings.class.getSimpleName(); public static final boolean ENABLE_EXPERIMENTAL_SETTINGS = false; @@ -92,9 +90,6 @@ public class Settings extends InputMethodSettingsActivity public static final String PREF_SELECTED_LANGUAGES = "selected_languages"; public static final String PREF_DEBUG_SETTINGS = "debug_settings"; - // Dialog ids - private static final int VOICE_INPUT_CONFIRM_DIALOG = 0; - private PreferenceScreen mInputLanguageSelection; private PreferenceScreen mKeypressVibrationDurationSettingsPref; private PreferenceScreen mKeypressSoundVolumeSettingsPref; @@ -113,7 +108,6 @@ public class Settings extends InputMethodSettingsActivity private TextView mKeypressVibrationDurationSettingsTextView; private TextView mKeypressSoundVolumeSettingsTextView; - private boolean mOkClicked = false; private String mVoiceModeOff; private void ensureConsistencyOfAutoCorrectionSettings() { @@ -291,9 +285,7 @@ public class Settings extends InputMethodSettingsActivity public void onResume() { super.onResume(); final boolean isShortcutImeEnabled = SubtypeSwitcher.getInstance().isShortcutImeEnabled(); - if (isShortcutImeEnabled - || (VoiceProxy.VOICE_INSTALLED - && VoiceProxy.isRecognitionAvailable(getActivityInternal()))) { + if (isShortcutImeEnabled) { updateVoiceModeSummary(); } else { getPreferenceScreen().removePreference(mVoicePreference); @@ -312,13 +304,7 @@ public class Settings extends InputMethodSettingsActivity @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { (new BackupManager(getActivityInternal())).dataChanged(); - // If turning on voice input, show dialog - if (key.equals(PREF_VOICE_MODE) && !mVoiceOn) { - if (!prefs.getString(PREF_VOICE_MODE, mVoiceModeOff) - .equals(mVoiceModeOff)) { - showVoiceConfirmation(); - } - } else if (key.equals(PREF_POPUP_ON)) { + if (key.equals(PREF_POPUP_ON)) { final ListPreference popupDismissDelay = (ListPreference)findPreference(PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY); if (null != popupDismissDelay) { @@ -363,80 +349,12 @@ public class Settings extends InputMethodSettingsActivity lp.setSummary(lp.getEntries()[lp.findIndexOfValue(lp.getValue())]); } - private void showVoiceConfirmation() { - mOkClicked = false; - getActivityInternal().showDialog(VOICE_INPUT_CONFIRM_DIALOG); - // Make URL in the dialog message clickable - if (mDialog != null) { - TextView textView = (TextView) mDialog.findViewById(android.R.id.message); - if (textView != null) { - textView.setMovementMethod(LinkMovementMethod.getInstance()); - } - } - } - private void updateVoiceModeSummary() { mVoicePreference.setSummary( getResources().getStringArray(R.array.voice_input_modes_summary) [mVoicePreference.findIndexOfValue(mVoicePreference.getValue())]); } - @Override - protected Dialog onCreateDialog(int id) { - switch (id) { - case VOICE_INPUT_CONFIRM_DIALOG: - DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int whichButton) { - if (whichButton == DialogInterface.BUTTON_NEGATIVE) { - mVoicePreference.setValue(mVoiceModeOff); - } else if (whichButton == DialogInterface.BUTTON_POSITIVE) { - mOkClicked = true; - } - } - }; - AlertDialog.Builder builder = new AlertDialog.Builder(getActivityInternal()) - .setTitle(R.string.voice_warning_title) - .setPositiveButton(android.R.string.ok, listener) - .setNegativeButton(android.R.string.cancel, listener); - - // Get the current list of supported locales and check the current locale against - // that list, to decide whether to put a warning that voice input will not work in - // the current language as part of the pop-up confirmation dialog. - boolean localeSupported = SubtypeSwitcher.isVoiceSupported( - this, Locale.getDefault().toString()); - - final CharSequence message; - if (localeSupported) { - message = TextUtils.concat( - getText(R.string.voice_warning_may_not_understand), "\n\n", - getText(R.string.voice_hint_dialog_message)); - } else { - message = TextUtils.concat( - getText(R.string.voice_warning_locale_not_supported), "\n\n", - getText(R.string.voice_warning_may_not_understand), "\n\n", - getText(R.string.voice_hint_dialog_message)); - } - builder.setMessage(message); - AlertDialog dialog = builder.create(); - mDialog = dialog; - dialog.setOnDismissListener(this); - return dialog; - default: - Log.e(TAG, "unknown dialog " + id); - return null; - } - } - - @Override - public void onDismiss(DialogInterface dialog) { - if (!mOkClicked) { - // This assumes that onPreferenceClick gets called first, and this if the user - // agreed after the warning, we set the mOkClicked value to true. - mVoicePreference.setValue(mVoiceModeOff); - } - } - private void refreshEnablingsOfKeypressSoundAndVibrationSettings( SharedPreferences sp, Resources res) { if (mKeypressVibrationDurationSettingsPref != null) { diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 3524c72f6..de2e8be3d 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -33,7 +33,6 @@ import android.util.Log; import com.android.inputmethod.compat.InputMethodInfoCompatWrapper; import com.android.inputmethod.compat.InputMethodManagerCompatWrapper; import com.android.inputmethod.compat.InputMethodSubtypeCompatWrapper; -import com.android.inputmethod.deprecated.VoiceProxy; import com.android.inputmethod.keyboard.KeyboardSwitcher; import java.util.ArrayList; @@ -76,7 +75,6 @@ public class SubtypeSwitcher { private Locale mSystemLocale; private Locale mInputLocale; private String mInputLocaleStr; - private VoiceProxy.VoiceInputWrapper mVoiceInputWrapper; /*-----------------------------------------------------------*/ private boolean mIsNetworkConnected; @@ -108,7 +106,6 @@ public class SubtypeSwitcher { mInputLocaleStr = null; mCurrentSubtype = null; mAllEnabledSubtypesOfCurrentInputMethod = null; - mVoiceInputWrapper = null; final NetworkInfo info = mConnectivityManager.getActiveNetworkInfo(); mIsNetworkConnected = (info != null && info.isConnected()); @@ -234,34 +231,12 @@ public class SubtypeSwitcher { } mCurrentSubtype = newSubtype; - // If the old mode is voice input, we need to reset or cancel its status. - // We cancel its status when we change mode, while we reset otherwise. if (isKeyboardMode()) { - if (modeChanged) { - if (VOICE_MODE.equals(oldMode) && mVoiceInputWrapper != null) { - mVoiceInputWrapper.cancel(); - } - } if (modeChanged || languageChanged) { updateShortcutIME(); mService.onRefreshKeyboard(); } - } else if (isVoiceMode() && mVoiceInputWrapper != null) { - if (VOICE_MODE.equals(oldMode)) { - mVoiceInputWrapper.reset(); - } - // If needsToShowWarningDialog is true, voice input need to show warning before - // show recognition view. - if (languageChanged || modeChanged - || VoiceProxy.getInstance().needsToShowWarningDialog()) { - triggerVoiceIME(); - } } else { - if (VOICE_MODE.equals(oldMode) && mVoiceInputWrapper != null) { - // We need to reset the voice input to release the resources and to reset its status - // as it is not the current input mode. - mVoiceInputWrapper.reset(); - } final String packageName = mService.getPackageName(); int version = -1; try { @@ -270,7 +245,7 @@ public class SubtypeSwitcher { } catch (NameNotFoundException e) { } Log.w(TAG, "Unknown subtype mode: " + newMode + "," + version + ", " + packageName - + ", " + mVoiceInputWrapper + ". IME is already changed to other IME."); + + ". IME is already changed to other IME."); if (newSubtype != null) { Log.w(TAG, "Subtype mode:" + newSubtype.getMode()); Log.w(TAG, "Subtype locale:" + newSubtype.getLocale()); @@ -477,40 +452,6 @@ public class SubtypeSwitcher { return KEYBOARD_MODE.equals(getCurrentSubtypeMode()); } - - /////////////////////////// - // Voice Input functions // - /////////////////////////// - - public boolean setVoiceInputWrapper(VoiceProxy.VoiceInputWrapper vi) { - if (mVoiceInputWrapper == null && vi != null) { - mVoiceInputWrapper = vi; - if (isVoiceMode()) { - if (DBG) { - Log.d(TAG, "Set and call voice input.: " + getInputLocaleStr()); - } - triggerVoiceIME(); - return true; - } - } - return false; - } - - public boolean isVoiceMode() { - return null == mCurrentSubtype ? false : VOICE_MODE.equals(getCurrentSubtypeMode()); - } - - public boolean isDummyVoiceMode() { - return mCurrentSubtype != null && mCurrentSubtype.getOriginalObject() == null - && VOICE_MODE.equals(getCurrentSubtypeMode()); - } - - private void triggerVoiceIME() { - if (!mService.isInputViewShown()) return; - VoiceProxy.getInstance().startListening(false, - KeyboardSwitcher.getInstance().getKeyboardView().getWindowToken()); - } - public String getInputLanguageName() { return StringUtils.getDisplayLanguage(getInputLocale()); } @@ -537,18 +478,4 @@ public class SubtypeSwitcher { public String getCurrentSubtypeMode() { return null != mCurrentSubtype ? mCurrentSubtype.getMode() : KEYBOARD_MODE; } - - - public static boolean isVoiceSupported(Context context, String locale) { - // Get the current list of supported locales and check the current locale against that - // list. We cache this value so as not to check it every time the user starts a voice - // input. Because this method is called by onStartInputView, this should mean that as - // long as the locale doesn't change while the user is keeping the IME open, the - // value should never be stale. - String supportedLocalesString = VoiceProxy.getSupportedLocalesString( - context.getContentResolver()); - List voiceInputSupportedLocales = Arrays.asList( - supportedLocalesString.split("\\s+")); - return voiceInputSupportedLocales.contains(locale); - } } -- cgit v1.2.3-83-g751a