aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-12-19 20:36:32 +0900
committerJean Chalard <jchalard@google.com>2013-12-20 11:24:42 +0900
commit48ba1f25ffb40780fb97093ee9a8ce118a801740 (patch)
treee11b6e4fa174dd27730a44a66022a43e7db309fe /java/src
parentcdd8a1a69d0fdbf844ab390e22872e2b32f1d664 (diff)
downloadlatinime-48ba1f25ffb40780fb97093ee9a8ce118a801740.tar.gz
latinime-48ba1f25ffb40780fb97093ee9a8ce118a801740.tar.xz
latinime-48ba1f25ffb40780fb97093ee9a8ce118a801740.zip
[IL14] Move getCurrent*Caps* to InputLogic
Bug: 8636060 Change-Id: I6338dcee0f7a80f2181ba0369f71350cb21d231a
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/Constants.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java35
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java48
3 files changed, 57 insertions, 28 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..e03687668 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
@@ -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;
}
}
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index 2f9221071..54d789859 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() {