Merge "[IL14] Move getCurrent*Caps* to InputLogic"

This commit is contained in:
Jean Chalard 2013-12-20 02:40:53 +00:00 committed by Android (Google) Code Review
commit 00a2f21eeb
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_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() {

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
// 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
@ -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[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 +1423,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 +1587,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 +1604,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;
}
}

View file

@ -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;
}
@ -924,6 +925,43 @@ public final class InputLogic {
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
*/