diff options
Diffstat (limited to 'java/src')
6 files changed, 63 insertions, 35 deletions
diff --git a/java/src/com/android/inputmethod/latin/Constants.java b/java/src/com/android/inputmethod/latin/Constants.java index 202ac87ef..b4971312e 100644 --- a/java/src/com/android/inputmethod/latin/Constants.java +++ b/java/src/com/android/inputmethod/latin/Constants.java @@ -133,6 +133,8 @@ public final class Constants { * {@link android.text.TextUtils#CAP_MODE_WORDS}, and * {@link android.text.TextUtils#CAP_MODE_SENTENCES}. */ + // TODO: Straighten this out. It's bizarre to have to use android.text.TextUtils.CAP_MODE_* + // except for OFF that is in Constants.TextUtils. public static final int CAP_MODE_OFF = 0; private TextUtils() { diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index ab9b2e598..e9988bf5b 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1270,28 +1270,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Called from the KeyboardSwitcher which needs to know auto caps state to display // the right layout. - // TODO[IL]: Move this to InputLogic. + // TODO[IL]: Remove this, pass the input logic to the keyboard switcher instead? public int getCurrentAutoCapsState() { - final SettingsValues currentSettingsValues = mSettings.getCurrent(); - if (!currentSettingsValues.mAutoCap) return Constants.TextUtils.CAP_MODE_OFF; - - final EditorInfo ei = getCurrentInputEditorInfo(); - if (ei == null) return Constants.TextUtils.CAP_MODE_OFF; - final int inputType = ei.inputType; - // Warning: this depends on mSpaceState, which may not be the most current value. If - // mSpaceState gets updated later, whoever called this may need to be told about it. - return mInputLogic.mConnection.getCursorCapsMode(inputType, currentSettingsValues, - SpaceState.PHANTOM == mInputLogic.mSpaceState); + return mInputLogic.getCurrentAutoCapsState(null /* optionalSettingsValues */); } + // Called from the KeyboardSwitcher which needs to know recaps state to display + // the right layout. + // TODO[IL]: Remove this, pass the input logic to the keyboard switcher instead? public int getCurrentRecapitalizeState() { - if (!mInputLogic.mRecapitalizeStatus.isActive() - || !mInputLogic.mRecapitalizeStatus.isSetAt(mInputLogic.mLastSelectionStart, - mInputLogic.mLastSelectionEnd)) { - // Not recapitalizing at the moment - return RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; - } - return mInputLogic.mRecapitalizeStatus.getCurrentMode(); + return mInputLogic.getCurrentRecapitalizeState(); } // Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is @@ -1311,8 +1299,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mUserDictionary.addWordToUserDictionary(wordToEdit); } - // TODO[IL]: Rework the route through which this is called. - public void onSettingsKeyPressed() { + public void displaySettingsDialog() { if (isShowingOptionDialog()) return; showSubtypeSelectorAndSettings(); } @@ -1336,8 +1323,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // TODO: Revise the language switch key behavior to make it much smarter and more reasonable. - // TODO[IL]: Move a part of this to InputLogic and straighten out the interface for this. - public void handleLanguageSwitchKey() { + public void switchToNextSubtype() { final IBinder token = getWindow().getWindow().getAttributes().token; if (mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList) { mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */); @@ -1436,7 +1422,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } mInputLogic.mConnection.endBatchEdit(); mInputLogic.mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime( - mInputLogic.getActualCapsMode(mKeyboardSwitcher), + mInputLogic.getActualCapsMode(currentSettingsValues, mKeyboardSwitcher), // Prev word is 1st word before cursor mInputLogic.getNthPreviousWordForSuggestion(currentSettingsValues, 1 /* nthPreviousWord */)); @@ -1600,7 +1586,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private int mAutoCommitSequenceNumber = 1; @Override public void onUpdateBatchInput(final InputPointers batchPointers) { - if (mSettings.getCurrent().mPhraseGestureEnabled) { + final SettingsValues settingsValues = mSettings.getCurrent(); + if (settingsValues.mPhraseGestureEnabled) { final SuggestedWordInfo candidate = mInputLogic.mSuggestedWords.getAutoCommitCandidate(); // If these suggested words have been generated with out of date input pointers, then @@ -1616,7 +1603,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mKeyboardSwitcher.updateShiftState(); mInputLogic.mWordComposer. setCapitalizedModeAndPreviousWordAtStartComposingTime( - mInputLogic.getActualCapsMode(mKeyboardSwitcher), commitParts[0]); + mInputLogic.getActualCapsMode(settingsValues, mKeyboardSwitcher), + commitParts[0]); ++mAutoCommitSequenceNumber; } } @@ -2386,7 +2374,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final CharSequence[] items = new CharSequence[] { // TODO: Should use new string "Select active input modes". getString(R.string.language_selection_title), - getString(ApplicationUtils.getAcitivityTitleResId(this, SettingsActivity.class)), + getString(ApplicationUtils.getActivityTitleResId(this, SettingsActivity.class)), }; final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { @Override diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 2f9221071..5a70d6428 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -373,7 +373,7 @@ public final class InputLogic { // We pass 1 to getPreviousWordForSuggestion because we were not composing a word // yet, so the word we want is the 1st word before the cursor. mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime( - getActualCapsMode(keyboardSwitcher), + getActualCapsMode(settingsValues, keyboardSwitcher), getNthPreviousWordForSuggestion(settingsValues, 1 /* nthPreviousWord */)); } mConnection.setComposingText(getTextWithUnderline( @@ -644,7 +644,7 @@ public final class InputLogic { * Handle a press on the language switch key (the "globe key") */ private void handleLanguageSwitchKey() { - mLatinIME.handleLanguageSwitchKey(); + mLatinIME.switchToNextSubtype(); } /** @@ -907,14 +907,15 @@ public final class InputLogic { /** * Factor in auto-caps and manual caps and compute the current caps mode. + * @param settingsValues the current settings values. * @param keyboardSwitcher the keyboard switcher. Caps mode depends on its mode. * @return the actual caps mode the keyboard is in right now. */ - // TODO: Make this private - public int getActualCapsMode(final KeyboardSwitcher keyboardSwitcher) { + public int getActualCapsMode(final SettingsValues settingsValues, + final KeyboardSwitcher keyboardSwitcher) { final int keyboardShiftMode = keyboardSwitcher.getKeyboardShiftMode(); if (keyboardShiftMode != WordComposer.CAPS_MODE_AUTO_SHIFTED) return keyboardShiftMode; - final int auto = mLatinIME.getCurrentAutoCapsState(); + final int auto = getCurrentAutoCapsState(settingsValues); if (0 != (auto & TextUtils.CAP_MODE_CHARACTERS)) { return WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED; } @@ -925,6 +926,43 @@ public final class InputLogic { } /** + * Gets the current auto-caps state, factoring in the space state. + * + * This method tries its best to do this in the most efficient possible manner. It avoids + * getting text from the editor if possible at all. + * This is called from the KeyboardSwitcher (through a trampoline in LatinIME) because it + * needs to know auto caps state to display the right layout. + * + * @param optionalSettingsValues settings values, or null if we should just get the current ones + * from the singleton. + * @return a caps mode from TextUtils.CAP_MODE_* or Constants.TextUtils.CAP_MODE_OFF. + */ + public int getCurrentAutoCapsState(final SettingsValues optionalSettingsValues) { + // If we are in a batch edit, we need to use the same settings values as the outside + // code, that will pass it to us. Otherwise, we can just take the current values. + final SettingsValues settingsValues = null != optionalSettingsValues + ? optionalSettingsValues : Settings.getInstance().getCurrent(); + if (!settingsValues.mAutoCap) return Constants.TextUtils.CAP_MODE_OFF; + + final EditorInfo ei = getCurrentInputEditorInfo(); + if (ei == null) return Constants.TextUtils.CAP_MODE_OFF; + final int inputType = ei.inputType; + // Warning: this depends on mSpaceState, which may not be the most current value. If + // mSpaceState gets updated later, whoever called this may need to be told about it. + return mConnection.getCursorCapsMode(inputType, settingsValues, + SpaceState.PHANTOM == mSpaceState); + } + + public int getCurrentRecapitalizeState() { + if (!mRecapitalizeStatus.isActive() + || !mRecapitalizeStatus.isSetAt(mLastSelectionStart, mLastSelectionEnd)) { + // Not recapitalizing at the moment + return RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; + } + return mRecapitalizeStatus.getCurrentMode(); + } + + /** * @return the editor info for the current editor */ private EditorInfo getCurrentInputEditorInfo() { @@ -961,7 +999,7 @@ public final class InputLogic { * Handle a press on the settings key. */ private void onSettingsKeyPressed() { - mLatinIME.onSettingsKeyPressed(); + mLatinIME.displaySettingsDialog(); } /** diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java index d7a3e95b3..e1182e4ff 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsFragment.java @@ -98,7 +98,7 @@ public final class SettingsFragment extends InputMethodSettingsFragment final PreferenceScreen preferenceScreen = getPreferenceScreen(); if (preferenceScreen != null) { preferenceScreen.setTitle( - ApplicationUtils.getAcitivityTitleResId(getActivity(), SettingsActivity.class)); + ApplicationUtils.getActivityTitleResId(getActivity(), SettingsActivity.class)); } final Resources res = getResources(); diff --git a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java index 999ca775b..186dafd29 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/SpellCheckerSettingsFragment.java @@ -39,7 +39,7 @@ public final class SpellCheckerSettingsFragment extends PreferenceFragment { addPreferencesFromResource(R.xml.spell_checker_settings); final PreferenceScreen preferenceScreen = getPreferenceScreen(); if (preferenceScreen != null) { - preferenceScreen.setTitle(ApplicationUtils.getAcitivityTitleResId( + preferenceScreen.setTitle(ApplicationUtils.getActivityTitleResId( getActivity(), SpellCheckerSettingsActivity.class)); } } diff --git a/java/src/com/android/inputmethod/latin/utils/ApplicationUtils.java b/java/src/com/android/inputmethod/latin/utils/ApplicationUtils.java index e521ec807..7a4150def 100644 --- a/java/src/com/android/inputmethod/latin/utils/ApplicationUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/ApplicationUtils.java @@ -31,7 +31,7 @@ public final class ApplicationUtils { // This utility class is not publicly instantiable. } - public static int getAcitivityTitleResId(final Context context, + public static int getActivityTitleResId(final Context context, final Class<? extends Activity> cls) { final ComponentName cn = new ComponentName(context, cls); try { |