am 00a2f21e: Merge "[IL14] Move getCurrent*Caps* to InputLogic"

* commit '00a2f21eeb0296124b65581b83a7364c2befe3d9':
  [IL14]  Move getCurrent*Caps* to InputLogic
main
Jean Chalard 2013-12-19 20:12:10 -08:00 committed by Android Git Automerger
commit 1516b09c3b
3 changed files with 57 additions and 28 deletions

View File

@ -133,6 +133,8 @@ public final class Constants {
* {@link android.text.TextUtils#CAP_MODE_WORDS}, and * {@link android.text.TextUtils#CAP_MODE_WORDS}, and
* {@link android.text.TextUtils#CAP_MODE_SENTENCES}. * {@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; public static final int CAP_MODE_OFF = 0;
private TextUtils() { private TextUtils() {

View File

@ -1270,28 +1270,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Called from the KeyboardSwitcher which needs to know auto caps state to display // Called from the KeyboardSwitcher which needs to know auto caps state to display
// the right layout. // 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() { public int getCurrentAutoCapsState() {
final SettingsValues currentSettingsValues = mSettings.getCurrent(); return mInputLogic.getCurrentAutoCapsState(null /* optionalSettingsValues */);
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);
} }
// 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() { public int getCurrentRecapitalizeState() {
if (!mInputLogic.mRecapitalizeStatus.isActive() return mInputLogic.getCurrentRecapitalizeState();
|| !mInputLogic.mRecapitalizeStatus.isSetAt(mInputLogic.mLastSelectionStart,
mInputLogic.mLastSelectionEnd)) {
// Not recapitalizing at the moment
return RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
}
return mInputLogic.mRecapitalizeStatus.getCurrentMode();
} }
// Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is // Callback for the {@link SuggestionStripView}, to call when the "add to dictionary" hint is
@ -1336,8 +1324,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
// TODO: Revise the language switch key behavior to make it much smarter and more reasonable. // 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 switchToNextSubtype() {
public void handleLanguageSwitchKey() {
final IBinder token = getWindow().getWindow().getAttributes().token; final IBinder token = getWindow().getWindow().getAttributes().token;
if (mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList) { if (mSettings.getCurrent().mIncludesOtherImesInLanguageSwitchList) {
mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */); mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */);
@ -1436,7 +1423,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
mInputLogic.mConnection.endBatchEdit(); mInputLogic.mConnection.endBatchEdit();
mInputLogic.mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime( mInputLogic.mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
mInputLogic.getActualCapsMode(mKeyboardSwitcher), mInputLogic.getActualCapsMode(currentSettingsValues, mKeyboardSwitcher),
// Prev word is 1st word before cursor // Prev word is 1st word before cursor
mInputLogic.getNthPreviousWordForSuggestion(currentSettingsValues, mInputLogic.getNthPreviousWordForSuggestion(currentSettingsValues,
1 /* nthPreviousWord */)); 1 /* nthPreviousWord */));
@ -1600,7 +1587,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private int mAutoCommitSequenceNumber = 1; private int mAutoCommitSequenceNumber = 1;
@Override @Override
public void onUpdateBatchInput(final InputPointers batchPointers) { public void onUpdateBatchInput(final InputPointers batchPointers) {
if (mSettings.getCurrent().mPhraseGestureEnabled) { final SettingsValues settingsValues = mSettings.getCurrent();
if (settingsValues.mPhraseGestureEnabled) {
final SuggestedWordInfo candidate = final SuggestedWordInfo candidate =
mInputLogic.mSuggestedWords.getAutoCommitCandidate(); mInputLogic.mSuggestedWords.getAutoCommitCandidate();
// If these suggested words have been generated with out of date input pointers, then // If these suggested words have been generated with out of date input pointers, then
@ -1616,7 +1604,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mKeyboardSwitcher.updateShiftState(); mKeyboardSwitcher.updateShiftState();
mInputLogic.mWordComposer. mInputLogic.mWordComposer.
setCapitalizedModeAndPreviousWordAtStartComposingTime( setCapitalizedModeAndPreviousWordAtStartComposingTime(
mInputLogic.getActualCapsMode(mKeyboardSwitcher), commitParts[0]); mInputLogic.getActualCapsMode(settingsValues, mKeyboardSwitcher),
commitParts[0]);
++mAutoCommitSequenceNumber; ++mAutoCommitSequenceNumber;
} }
} }

View File

@ -373,7 +373,7 @@ public final class InputLogic {
// We pass 1 to getPreviousWordForSuggestion because we were not composing a word // 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. // yet, so the word we want is the 1st word before the cursor.
mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime( mWordComposer.setCapitalizedModeAndPreviousWordAtStartComposingTime(
getActualCapsMode(keyboardSwitcher), getActualCapsMode(settingsValues, keyboardSwitcher),
getNthPreviousWordForSuggestion(settingsValues, 1 /* nthPreviousWord */)); getNthPreviousWordForSuggestion(settingsValues, 1 /* nthPreviousWord */));
} }
mConnection.setComposingText(getTextWithUnderline( mConnection.setComposingText(getTextWithUnderline(
@ -644,7 +644,7 @@ public final class InputLogic {
* Handle a press on the language switch key (the "globe key") * Handle a press on the language switch key (the "globe key")
*/ */
private void handleLanguageSwitchKey() { 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. * 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. * @param keyboardSwitcher the keyboard switcher. Caps mode depends on its mode.
* @return the actual caps mode the keyboard is in right now. * @return the actual caps mode the keyboard is in right now.
*/ */
// TODO: Make this private public int getActualCapsMode(final SettingsValues settingsValues,
public int getActualCapsMode(final KeyboardSwitcher keyboardSwitcher) { final KeyboardSwitcher keyboardSwitcher) {
final int keyboardShiftMode = keyboardSwitcher.getKeyboardShiftMode(); final int keyboardShiftMode = keyboardSwitcher.getKeyboardShiftMode();
if (keyboardShiftMode != WordComposer.CAPS_MODE_AUTO_SHIFTED) return keyboardShiftMode; 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)) { if (0 != (auto & TextUtils.CAP_MODE_CHARACTERS)) {
return WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED; return WordComposer.CAPS_MODE_AUTO_SHIFT_LOCKED;
} }
@ -924,6 +925,43 @@ public final class InputLogic {
return WordComposer.CAPS_MODE_OFF; return WordComposer.CAPS_MODE_OFF;
} }
/**
* 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 * @return the editor info for the current editor
*/ */