am 75c60bf3: Merge "Change auto caps mode argument to int type" into jb-dev

* commit '75c60bf3a5dfd8f5f529011a20d9e3e73e91d04e':
  Change auto caps mode argument to int type
main
Tadashi G. Takaoka 2012-05-18 14:21:49 -07:00 committed by Android Git Automerger
commit 628a5745e1
8 changed files with 73 additions and 47 deletions

View File

@ -20,6 +20,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.ResearchLogger; import com.android.inputmethod.latin.ResearchLogger;
import com.android.inputmethod.latin.define.ProductionFlag; import com.android.inputmethod.latin.define.ProductionFlag;
@ -30,8 +31,8 @@ import com.android.inputmethod.latin.define.ProductionFlag;
* *
* The input events are {@link #onLoadKeyboard(String)}, {@link #onSaveKeyboardState()}, * The input events are {@link #onLoadKeyboard(String)}, {@link #onSaveKeyboardState()},
* {@link #onPressKey(int)}, {@link #onReleaseKey(int, boolean)}, * {@link #onPressKey(int)}, {@link #onReleaseKey(int, boolean)},
* {@link #onCodeInput(int, boolean, boolean)}, {@link #onCancelInput(boolean)}, * {@link #onCodeInput(int, boolean, int)}, {@link #onCancelInput(boolean)},
* {@link #onUpdateShiftState(boolean)}, {@link #onLongPressTimeout(int)}. * {@link #onUpdateShiftState(int)}, {@link #onLongPressTimeout(int)}.
* *
* The actions are {@link SwitchActions}'s methods. * The actions are {@link SwitchActions}'s methods.
*/ */
@ -50,7 +51,7 @@ public class KeyboardState {
public void setSymbolsShiftedKeyboard(); public void setSymbolsShiftedKeyboard();
/** /**
* Request to call back {@link KeyboardState#onUpdateShiftState(boolean)}. * Request to call back {@link KeyboardState#onUpdateShiftState(int)}.
*/ */
public void requestUpdatingShiftState(); public void requestUpdatingShiftState();
@ -371,14 +372,14 @@ public class KeyboardState {
} }
} }
public void onUpdateShiftState(boolean autoCaps) { public void onUpdateShiftState(int autoCaps) {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this); Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + " " + this);
} }
updateAlphabetShiftState(autoCaps); updateAlphabetShiftState(autoCaps);
} }
private void updateAlphabetShiftState(boolean autoCaps) { private void updateAlphabetShiftState(int autoCaps) {
if (!mIsAlphabetMode) return; if (!mIsAlphabetMode) return;
if (!mShiftKeyState.isReleasing()) { if (!mShiftKeyState.isReleasing()) {
// Ignore update shift state event while the shift key is being pressed (including // Ignore update shift state event while the shift key is being pressed (including
@ -386,7 +387,7 @@ public class KeyboardState {
return; return;
} }
if (!mAlphabetShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) { if (!mAlphabetShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) {
if (mShiftKeyState.isReleasing() && autoCaps) { if (mShiftKeyState.isReleasing() && autoCaps != Constants.TextUtils.CAP_MODE_OFF) {
// Only when shift key is releasing, automatic temporary upper case will be set. // Only when shift key is releasing, automatic temporary upper case will be set.
setShifted(AUTOMATIC_SHIFT); setShifted(AUTOMATIC_SHIFT);
} else { } else {
@ -521,7 +522,7 @@ public class KeyboardState {
return false; return false;
} }
public void onCodeInput(int code, boolean isSinglePointer, boolean autoCaps) { public void onCodeInput(int code, boolean isSinglePointer, int autoCaps) {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onCodeInput: code=" + Keyboard.printableCode(code) Log.d(TAG, "onCodeInput: code=" + Keyboard.printableCode(code)
+ " single=" + isSinglePointer + " single=" + isSinglePointer

View File

@ -106,6 +106,21 @@ public final class Constants {
} }
} }
public static class TextUtils {
/**
* Capitalization mode for {@link android.text.TextUtils#getCapsMode}: don't capitalize
* characters. This value may be used with
* {@link android.text.TextUtils#CAP_MODE_CHARACTERS},
* {@link android.text.TextUtils#CAP_MODE_WORDS}, and
* {@link android.text.TextUtils#CAP_MODE_SENTENCES}.
*/
public static final int CAP_MODE_OFF = 0;
private TextUtils() {
// This utility class is not publicly instantiable.
}
}
private Constants() { private Constants() {
// This utility class is not publicly instantiable. // This utility class is not publicly instantiable.
} }

View File

@ -1032,26 +1032,28 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
updateSuggestions(); updateSuggestions();
} }
public boolean getCurrentAutoCapsState() { public int getCurrentAutoCapsState() {
if (!mSettingsValues.mAutoCap) return false; if (!mSettingsValues.mAutoCap) return Constants.TextUtils.CAP_MODE_OFF;
final EditorInfo ei = getCurrentInputEditorInfo(); final EditorInfo ei = getCurrentInputEditorInfo();
if (ei == null) return false; if (ei == null) return Constants.TextUtils.CAP_MODE_OFF;
final int inputType = ei.inputType; final int inputType = ei.inputType;
if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) return true; if ((inputType & InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS) != 0) {
return TextUtils.CAP_MODE_CHARACTERS;
}
final boolean noNeedToCheckCapsMode = (inputType & (InputType.TYPE_TEXT_FLAG_CAP_SENTENCES final boolean noNeedToCheckCapsMode = (inputType & (InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
| InputType.TYPE_TEXT_FLAG_CAP_WORDS)) == 0; | InputType.TYPE_TEXT_FLAG_CAP_WORDS)) == 0;
if (noNeedToCheckCapsMode) return false; if (noNeedToCheckCapsMode) return Constants.TextUtils.CAP_MODE_OFF;
final InputConnection ic = getCurrentInputConnection(); final InputConnection ic = getCurrentInputConnection();
if (ic == null) return false; if (ic == null) return Constants.TextUtils.CAP_MODE_OFF;
// TODO: This blocking IPC call is heavy. Consider doing this without using IPC calls. // TODO: This blocking IPC call is heavy. Consider doing this without using IPC calls.
// Note: getCursorCapsMode() returns the current capitalization mode that is any // Note: getCursorCapsMode() returns the current capitalization mode that is any
// combination of CAP_MODE_CHARACTERS, CAP_MODE_WORDS, and CAP_MODE_SENTENCES. 0 means none // combination of CAP_MODE_CHARACTERS, CAP_MODE_WORDS, and CAP_MODE_SENTENCES. 0 means none
// of them. // of them.
return ic.getCursorCapsMode(inputType) != 0; return ic.getCursorCapsMode(inputType);
} }
// "ic" may be null // "ic" may be null
@ -1522,7 +1524,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (ic != null) { if (ic != null) {
// If it's the first letter, make note of auto-caps state // If it's the first letter, make note of auto-caps state
if (mWordComposer.size() == 1) { if (mWordComposer.size() == 1) {
mWordComposer.setAutoCapitalized(getCurrentAutoCapsState()); mWordComposer.setAutoCapitalized(
getCurrentAutoCapsState() != Constants.TextUtils.CAP_MODE_OFF);
} }
ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1); ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1);
} }

View File

@ -444,7 +444,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
} }
public static void keyboardState_onCodeInput( public static void keyboardState_onCodeInput(
final int code, final boolean isSinglePointer, final boolean autoCaps, final int code, final boolean isSinglePointer, final int autoCaps,
final KeyboardState keyboardState) { final KeyboardState keyboardState) {
if (UnsLogGroup.KEYBOARDSTATE_ONCODEINPUT_ENABLED) { if (UnsLogGroup.KEYBOARDSTATE_ONCODEINPUT_ENABLED) {
final String s = "onCodeInput: code=" + Keyboard.printableCode(code) final String s = "onCodeInput: code=" + Keyboard.printableCode(code)

View File

@ -206,8 +206,8 @@ public class KeyboardStateMultiTouchTests extends KeyboardStateTestsBase {
// Chording input in automatic upper case. // Chording input in automatic upper case.
public void testChordingAutomaticUpperCase() { public void testChordingAutomaticUpperCase() {
// Set auto caps mode on. // Set capitalize the first character of all words mode.
setAutoCapsMode(AUTO_CAPS); setAutoCapsMode(CAP_MODE_WORDS);
// Update shift state with auto caps enabled. // Update shift state with auto caps enabled.
pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED);

View File

@ -202,8 +202,8 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Automatic upper case test // Automatic upper case test
public void testAutomaticUpperCase() { public void testAutomaticUpperCase() {
// Set auto caps mode on. // Set capitalize the first character of all words mode.
setAutoCapsMode(AUTO_CAPS); setAutoCapsMode(CAP_MODE_WORDS);
// Load keyboard, should be in automatic shifted. // Load keyboard, should be in automatic shifted.
loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED);
@ -239,7 +239,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Long press shift key. // Long press shift key.
public void testLongPressShift() { public void testLongPressShift() {
// Set auto caps mode off. // Set auto caps mode off.
setAutoCapsMode(NO_AUTO_CAPS); setAutoCapsMode(CAP_MODE_OFF);
// Load keyboard, should be in alphabet. // Load keyboard, should be in alphabet.
loadKeyboard(ALPHABET_UNSHIFTED); loadKeyboard(ALPHABET_UNSHIFTED);
// Long press shift key, enter alphabet shift locked. // Long press shift key, enter alphabet shift locked.
@ -268,8 +268,8 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Press/release shift key, back to alphabet. // Press/release shift key, back to alphabet.
pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED); pressAndReleaseKey(CODE_SHIFT, ALPHABET_SHIFT_LOCK_SHIFTED, ALPHABET_UNSHIFTED);
// Set auto caps mode on. // Set capitalize the first character of all words mode.
setAutoCapsMode(AUTO_CAPS); setAutoCapsMode(CAP_MODE_WORDS);
// Load keyboard, should be in automatic shifted. // Load keyboard, should be in automatic shifted.
loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED);
// Long press shift key, enter alphabet shift locked. // Long press shift key, enter alphabet shift locked.
@ -303,8 +303,8 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Second shift key tap. // Second shift key tap.
secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED); secondPressAndReleaseKey(CODE_SHIFT, ALPHABET_UNSHIFTED, ALPHABET_UNSHIFTED);
// Set auto caps mode on. // Set capitalize the first character of all words mode.
setAutoCapsMode(AUTO_CAPS); setAutoCapsMode(CAP_MODE_WORDS);
// Load keyboard, should be in automatic shifted. // Load keyboard, should be in automatic shifted.
loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED);
@ -322,7 +322,7 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Update shift state. // Update shift state.
public void testUpdateShiftState() { public void testUpdateShiftState() {
// Set auto caps mode off. // Set auto caps mode off.
setAutoCapsMode(NO_AUTO_CAPS); setAutoCapsMode(CAP_MODE_OFF);
// Load keyboard, should be in alphabet. // Load keyboard, should be in alphabet.
loadKeyboard(ALPHABET_UNSHIFTED); loadKeyboard(ALPHABET_UNSHIFTED);
// Update shift state, remained in alphabet. // Update shift state, remained in alphabet.
@ -350,8 +350,8 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Update shift state, remained in symbols shifted. // Update shift state, remained in symbols shifted.
updateShiftState(SYMBOLS_SHIFTED); updateShiftState(SYMBOLS_SHIFTED);
// Set auto caps mode on. // Set capitalize the first character of all words mode.
setAutoCapsMode(AUTO_CAPS); setAutoCapsMode(CAP_MODE_WORDS);
// Load keyboard, should be in automatic shifted. // Load keyboard, should be in automatic shifted.
loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED);
// Update shift state, remained in automatic shifted. // Update shift state, remained in automatic shifted.
@ -592,11 +592,8 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Change focus to auto caps text field. // Change focus to auto caps text field.
public void testChangeFocusAutoCaps() { public void testChangeFocusAutoCaps() {
// Set auto caps mode on. // Set capitalize the first character of all words mode.
setAutoCapsMode(AUTO_CAPS); setAutoCapsMode(CAP_MODE_WORDS);
// Update shift state.
updateShiftState(ALPHABET_AUTOMATIC_SHIFTED);
// Change focus to new text field. // Change focus to new text field.
loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED); loadKeyboard(ALPHABET_AUTOMATIC_SHIFTED);
@ -735,8 +732,8 @@ public class KeyboardStateSingleTouchTests extends KeyboardStateTestsBase {
// Rapidly press/release letter key. // Rapidly press/release letter key.
secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED); secondPressAndReleaseKey('J', ALPHABET_MANUAL_SHIFTED, ALPHABET_UNSHIFTED);
// Set auto caps mode on. // Set capitalize the first character of all words mode.
setAutoCapsMode(AUTO_CAPS); setAutoCapsMode(CAP_MODE_WORDS);
// Press/release auto caps trigger letter to enter alphabet automatic shifted. // Press/release auto caps trigger letter to enter alphabet automatic shifted.
pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED); pressAndReleaseKey(CODE_AUTO_CAPS_TRIGGER, ALPHABET_UNSHIFTED, ALPHABET_AUTOMATIC_SHIFTED);
// Press/release shift key // Press/release shift key

View File

@ -29,12 +29,12 @@ public class KeyboardStateTestsBase extends AndroidTestCase
super.setUp(); super.setUp();
mSwitcher = new MockKeyboardSwitcher(); mSwitcher = new MockKeyboardSwitcher();
mSwitcher.setAutoCapsMode(NO_AUTO_CAPS); mSwitcher.setAutoCapsMode(CAP_MODE_OFF);
loadKeyboard(ALPHABET_UNSHIFTED); loadKeyboard(ALPHABET_UNSHIFTED);
} }
public void setAutoCapsMode(boolean autoCaps) { public void setAutoCapsMode(int autoCaps) {
mSwitcher.setAutoCapsMode(autoCaps); mSwitcher.setAutoCapsMode(autoCaps);
} }

View File

@ -16,6 +16,8 @@
package com.android.inputmethod.keyboard.internal; package com.android.inputmethod.keyboard.internal;
import android.text.TextUtils;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
public class MockKeyboardSwitcher implements KeyboardState.SwitchActions { public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
@ -26,8 +28,10 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
// Argument for {@link KeyboardState#onCodeInput}. // Argument for {@link KeyboardState#onCodeInput}.
public static final boolean SINGLE = true; public static final boolean SINGLE = true;
public static final boolean MULTI = false; public static final boolean MULTI = false;
public static final boolean NO_AUTO_CAPS = false; public static final int CAP_MODE_OFF =
public static final boolean AUTO_CAPS = true; com.android.inputmethod.latin.Constants.TextUtils.CAP_MODE_OFF;
public static final int CAP_MODE_WORDS = TextUtils.CAP_MODE_WORDS;
public static final int CAP_MODE_CHARACTERS = TextUtils.CAP_MODE_CHARACTERS;
public static final int CODE_SHIFT = Keyboard.CODE_SHIFT; public static final int CODE_SHIFT = Keyboard.CODE_SHIFT;
public static final int CODE_SYMBOL = Keyboard.CODE_SWITCH_ALPHA_SYMBOL; public static final int CODE_SYMBOL = Keyboard.CODE_SWITCH_ALPHA_SYMBOL;
@ -45,9 +49,9 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
private int mLayout = Constants.ALPHABET_UNSHIFTED; private int mLayout = Constants.ALPHABET_UNSHIFTED;
private boolean mAutoCapsMode = Constants.NO_AUTO_CAPS; private int mAutoCapsMode = Constants.CAP_MODE_OFF;
// Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS. // Following InputConnection's behavior. Simulating InputType.TYPE_TEXT_FLAG_CAP_WORDS.
private boolean mAutoCapsState = true; private int mAutoCapsState = Constants.CAP_MODE_OFF;
private boolean mIsInDoubleTapTimeout; private boolean mIsInDoubleTapTimeout;
private int mLongPressTimeoutCode; private int mLongPressTimeoutCode;
@ -71,8 +75,9 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
} }
} }
public void setAutoCapsMode(boolean autoCaps) { public void setAutoCapsMode(int autoCaps) {
mAutoCapsMode = autoCaps; mAutoCapsMode = autoCaps;
mAutoCapsState = autoCaps;
} }
public void expireDoubleTapTimeout() { public void expireDoubleTapTimeout() {
@ -116,7 +121,7 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
@Override @Override
public void requestUpdatingShiftState() { public void requestUpdatingShiftState() {
mState.onUpdateShiftState(mAutoCapsMode && mAutoCapsState); mState.onUpdateShiftState(mAutoCapsState);
} }
@Override @Override
@ -158,7 +163,7 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
} }
public void updateShiftState() { public void updateShiftState() {
mState.onUpdateShiftState(mAutoCapsMode && mAutoCapsState); mState.onUpdateShiftState(mAutoCapsState);
} }
public void loadKeyboard(String layoutSwitchBackSymbols) { public void loadKeyboard(String layoutSwitchBackSymbols) {
@ -181,10 +186,15 @@ public class MockKeyboardSwitcher implements KeyboardState.SwitchActions {
} }
public void onCodeInput(int code, boolean isSinglePointer) { public void onCodeInput(int code, boolean isSinglePointer) {
if (Keyboard.isLetterCode(code)) { if (mAutoCapsMode == Constants.CAP_MODE_WORDS) {
mAutoCapsState = (code == Constants.CODE_AUTO_CAPS_TRIGGER); if (Keyboard.isLetterCode(code)) {
mAutoCapsState = (code == Constants.CODE_AUTO_CAPS_TRIGGER)
? mAutoCapsMode : Constants.CAP_MODE_OFF;
}
} else {
mAutoCapsState = mAutoCapsMode;
} }
mState.onCodeInput(code, isSinglePointer, mAutoCapsMode && mAutoCapsState); mState.onCodeInput(code, isSinglePointer, mAutoCapsState);
} }
public void onCancelInput(boolean isSinglePointer) { public void onCancelInput(boolean isSinglePointer) {