am c235a3be: Add debug logging

* commit 'c235a3be9dc6bdc9af869f98136462b860928839':
  Add debug logging
main
Tadashi G. Takaoka 2014-11-02 14:08:36 +00:00 committed by Android Git Automerger
commit 7e7da4863f
2 changed files with 121 additions and 76 deletions

View File

@ -39,6 +39,8 @@ import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.define.ProductionFlags; import com.android.inputmethod.latin.define.ProductionFlags;
import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsValues; import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.utils.CapsModeUtils;
import com.android.inputmethod.latin.utils.RecapitalizeStatus;
import com.android.inputmethod.latin.utils.ResourceUtils; import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.ScriptUtils; import com.android.inputmethod.latin.utils.ScriptUtils;
@ -204,36 +206,54 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetKeyboard() { public void setAlphabetKeyboard() {
if (DEBUG_ACTION) {
Log.d(TAG, "setAlphabetKeyboard");
}
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET)); setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET));
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetManualShiftedKeyboard() { public void setAlphabetManualShiftedKeyboard() {
if (DEBUG_ACTION) {
Log.d(TAG, "setAlphabetManualShiftedKeyboard");
}
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED)); setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED));
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetAutomaticShiftedKeyboard() { public void setAlphabetAutomaticShiftedKeyboard() {
if (DEBUG_ACTION) {
Log.d(TAG, "setAlphabetAutomaticShiftedKeyboard");
}
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED)); setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED));
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetShiftLockedKeyboard() { public void setAlphabetShiftLockedKeyboard() {
if (DEBUG_ACTION) {
Log.d(TAG, "setAlphabetShiftLockedKeyboard");
}
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED)); setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED));
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setAlphabetShiftLockShiftedKeyboard() { public void setAlphabetShiftLockShiftedKeyboard() {
if (DEBUG_ACTION) {
Log.d(TAG, "setAlphabetShiftLockShiftedKeyboard");
}
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED)); setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED));
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setSymbolsKeyboard() { public void setSymbolsKeyboard() {
if (DEBUG_ACTION) {
Log.d(TAG, "setSymbolsKeyboard");
}
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS)); setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS));
} }
@ -247,6 +267,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setEmojiKeyboard() { public void setEmojiKeyboard() {
if (DEBUG_ACTION) {
Log.d(TAG, "setEmojiKeyboard");
}
final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET); final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET);
mMainKeyboardFrame.setVisibility(View.GONE); mMainKeyboardFrame.setVisibility(View.GONE);
mEmojiPalettesView.startEmojiPalettes( mEmojiPalettesView.startEmojiPalettes(
@ -269,19 +292,29 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setSymbolsShiftedKeyboard() { public void setSymbolsShiftedKeyboard() {
if (DEBUG_ACTION) {
Log.d(TAG, "setSymbolsShiftedKeyboard");
}
setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS_SHIFTED)); setKeyboard(mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_SYMBOLS_SHIFTED));
} }
// Future method for requesting an updating to the shift state. // Future method for requesting an updating to the shift state.
@Override @Override
public void requestUpdatingShiftState(final int currentAutoCapsState, public void requestUpdatingShiftState(final int autoCapsFlags, final int recapitalizeMode) {
final int currentRecapitalizeState) { if (DEBUG_ACTION) {
mState.onUpdateShiftState(currentAutoCapsState, currentRecapitalizeState); Log.d(TAG, "requestUpdatingShiftState: "
+ " autoCapsFlags=" + CapsModeUtils.flagsToString(autoCapsFlags)
+ " recapitalizeMode=" + RecapitalizeStatus.modeToString(recapitalizeMode));
}
mState.onUpdateShiftState(autoCapsFlags, recapitalizeMode);
} }
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void startDoubleTapShiftKeyTimer() { public void startDoubleTapShiftKeyTimer() {
if (DEBUG_TIMER_ACTION) {
Log.d(TAG, "startDoubleTapShiftKeyTimer");
}
final MainKeyboardView keyboardView = getMainKeyboardView(); final MainKeyboardView keyboardView = getMainKeyboardView();
if (keyboardView != null) { if (keyboardView != null) {
keyboardView.startDoubleTapShiftKeyTimer(); keyboardView.startDoubleTapShiftKeyTimer();
@ -291,6 +324,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void cancelDoubleTapShiftKeyTimer() { public void cancelDoubleTapShiftKeyTimer() {
if (DEBUG_TIMER_ACTION) {
Log.d(TAG, "setAlphabetKeyboard");
}
final MainKeyboardView keyboardView = getMainKeyboardView(); final MainKeyboardView keyboardView = getMainKeyboardView();
if (keyboardView != null) { if (keyboardView != null) {
keyboardView.cancelDoubleTapShiftKeyTimer(); keyboardView.cancelDoubleTapShiftKeyTimer();
@ -300,6 +336,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public boolean isInDoubleTapShiftKeyTimeout() { public boolean isInDoubleTapShiftKeyTimeout() {
if (DEBUG_TIMER_ACTION) {
Log.d(TAG, "isInDoubleTapShiftKeyTimeout");
}
final MainKeyboardView keyboardView = getMainKeyboardView(); final MainKeyboardView keyboardView = getMainKeyboardView();
return keyboardView != null && keyboardView.isInDoubleTapShiftKeyTimeout(); return keyboardView != null && keyboardView.isInDoubleTapShiftKeyTimeout();
} }

View File

@ -21,6 +21,7 @@ import android.util.Log;
import com.android.inputmethod.event.Event; import com.android.inputmethod.event.Event;
import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.utils.CapsModeUtils;
import com.android.inputmethod.latin.utils.RecapitalizeStatus; import com.android.inputmethod.latin.utils.RecapitalizeStatus;
/** /**
@ -38,9 +39,11 @@ import com.android.inputmethod.latin.utils.RecapitalizeStatus;
public final class KeyboardState { public final class KeyboardState {
private static final String TAG = KeyboardState.class.getSimpleName(); private static final String TAG = KeyboardState.class.getSimpleName();
private static final boolean DEBUG_EVENT = false; private static final boolean DEBUG_EVENT = false;
private static final boolean DEBUG_ACTION = false; private static final boolean DEBUG_INTERNAL_ACTION = false;
public interface SwitchActions { public interface SwitchActions {
public static final boolean DEBUG_ACTION = false;
public void setAlphabetKeyboard(); public void setAlphabetKeyboard();
public void setAlphabetManualShiftedKeyboard(); public void setAlphabetManualShiftedKeyboard();
public void setAlphabetAutomaticShiftedKeyboard(); public void setAlphabetAutomaticShiftedKeyboard();
@ -53,8 +56,9 @@ public final class KeyboardState {
/** /**
* Request to call back {@link KeyboardState#onUpdateShiftState(int, int)}. * Request to call back {@link KeyboardState#onUpdateShiftState(int, int)}.
*/ */
public void requestUpdatingShiftState(final int currentAutoCapsState, public void requestUpdatingShiftState(final int autoCapsFlags, final int recapitalizeMode);
final int currentRecapitalizeState);
public static final boolean DEBUG_TIMER_ACTION = false;
public void startDoubleTapShiftKeyTimer(); public void startDoubleTapShiftKeyTimer();
public boolean isInDoubleTapShiftKeyTimeout(); public boolean isInDoubleTapShiftKeyTimeout();
@ -119,10 +123,9 @@ public final class KeyboardState {
mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
} }
public void onLoadKeyboard(final int currentAutoCapsState, public void onLoadKeyboard(final int autoCapsFlags, final int recapitalizeMode) {
final int currentRecapitalizeState) {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onLoadKeyboard: " + this); Log.d(TAG, "onLoadKeyboard: " + stateToString(autoCapsFlags, recapitalizeMode));
} }
// Reset alphabet shift state. // Reset alphabet shift state.
mAlphabetShiftState.setShiftLocked(false); mAlphabetShiftState.setShiftLocked(false);
@ -130,7 +133,7 @@ public final class KeyboardState {
mPrevSymbolsKeyboardWasShifted = false; mPrevSymbolsKeyboardWasShifted = false;
mShiftKeyState.onRelease(); mShiftKeyState.onRelease();
mSymbolKeyState.onRelease(); mSymbolKeyState.onRelease();
onRestoreKeyboardState(currentAutoCapsState, currentRecapitalizeState); onRestoreKeyboardState(autoCapsFlags, recapitalizeMode);
} }
private static final int UNSHIFT = 0; private static final int UNSHIFT = 0;
@ -156,14 +159,14 @@ public final class KeyboardState {
} }
} }
private void onRestoreKeyboardState(final int currentAutoCapsState, private void onRestoreKeyboardState(final int autoCapsFlags, final int recapitalizeMode) {
final int currentRecapitalizeState) {
final SavedKeyboardState state = mSavedKeyboardState; final SavedKeyboardState state = mSavedKeyboardState;
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onRestoreKeyboardState: saved=" + state + " " + this); Log.d(TAG, "onRestoreKeyboardState: saved=" + state
+ " " + stateToString(autoCapsFlags, recapitalizeMode));
} }
if (!state.mIsValid || state.mIsAlphabetMode) { if (!state.mIsValid || state.mIsAlphabetMode) {
setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
} else if (state.mIsEmojiMode) { } else if (state.mIsEmojiMode) {
setEmojiKeyboard(); setEmojiKeyboard();
} else { } else {
@ -188,7 +191,7 @@ public final class KeyboardState {
} }
private void setShifted(final int shiftMode) { private void setShifted(final int shiftMode) {
if (DEBUG_ACTION) { if (DEBUG_INTERNAL_ACTION) {
Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode) + " " + this); Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode) + " " + this);
} }
if (!mIsAlphabetMode) return; if (!mIsAlphabetMode) return;
@ -227,7 +230,7 @@ public final class KeyboardState {
} }
private void setShiftLocked(final boolean shiftLocked) { private void setShiftLocked(final boolean shiftLocked) {
if (DEBUG_ACTION) { if (DEBUG_INTERNAL_ACTION) {
Log.d(TAG, "setShiftLocked: shiftLocked=" + shiftLocked + " " + this); Log.d(TAG, "setShiftLocked: shiftLocked=" + shiftLocked + " " + this);
} }
if (!mIsAlphabetMode) return; if (!mIsAlphabetMode) return;
@ -241,10 +244,10 @@ public final class KeyboardState {
mAlphabetShiftState.setShiftLocked(shiftLocked); mAlphabetShiftState.setShiftLocked(shiftLocked);
} }
private void toggleAlphabetAndSymbols(final int currentAutoCapsState, private void toggleAlphabetAndSymbols(final int autoCapsFlags, final int recapitalizeMode) {
final int currentRecapitalizeState) { if (DEBUG_INTERNAL_ACTION) {
if (DEBUG_ACTION) { Log.d(TAG, "toggleAlphabetAndSymbols: "
Log.d(TAG, "toggleAlphabetAndSymbols: " + this); + stateToString(autoCapsFlags, recapitalizeMode));
} }
if (mIsAlphabetMode) { if (mIsAlphabetMode) {
mPrevMainKeyboardWasShiftLocked = mAlphabetShiftState.isShiftLocked(); mPrevMainKeyboardWasShiftLocked = mAlphabetShiftState.isShiftLocked();
@ -256,7 +259,7 @@ public final class KeyboardState {
mPrevSymbolsKeyboardWasShifted = false; mPrevSymbolsKeyboardWasShifted = false;
} else { } else {
mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted; mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted;
setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
if (mPrevMainKeyboardWasShiftLocked) { if (mPrevMainKeyboardWasShiftLocked) {
setShiftLocked(true); setShiftLocked(true);
} }
@ -266,15 +269,15 @@ public final class KeyboardState {
// TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout // TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout
// when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal(). // when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal().
private void resetKeyboardStateToAlphabet(final int currentAutoCapsState, private void resetKeyboardStateToAlphabet(final int autoCapsFlags, final int recapitalizeMode) {
final int currentRecapitalizeState) { if (DEBUG_INTERNAL_ACTION) {
if (DEBUG_ACTION) { Log.d(TAG, "resetKeyboardStateToAlphabet: "
Log.d(TAG, "resetKeyboardStateToAlphabet: " + this); + stateToString(autoCapsFlags, recapitalizeMode));
} }
if (mIsAlphabetMode) return; if (mIsAlphabetMode) return;
mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted; mPrevSymbolsKeyboardWasShifted = mIsSymbolShifted;
setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
if (mPrevMainKeyboardWasShiftLocked) { if (mPrevMainKeyboardWasShiftLocked) {
setShiftLocked(true); setShiftLocked(true);
} }
@ -289,10 +292,9 @@ public final class KeyboardState {
} }
} }
private void setAlphabetKeyboard(final int currentAutoCapsState, private void setAlphabetKeyboard(final int autoCapsFlags, final int recapitalizeMode) {
final int currentRecapitalizeState) { if (DEBUG_INTERNAL_ACTION) {
if (DEBUG_ACTION) { Log.d(TAG, "setAlphabetKeyboard: " + stateToString(autoCapsFlags, recapitalizeMode));
Log.d(TAG, "setAlphabetKeyboard");
} }
mSwitchActions.setAlphabetKeyboard(); mSwitchActions.setAlphabetKeyboard();
@ -301,11 +303,11 @@ public final class KeyboardState {
mIsSymbolShifted = false; mIsSymbolShifted = false;
mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE; mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
mSwitchState = SWITCH_STATE_ALPHA; mSwitchState = SWITCH_STATE_ALPHA;
mSwitchActions.requestUpdatingShiftState(currentAutoCapsState, currentRecapitalizeState); mSwitchActions.requestUpdatingShiftState(autoCapsFlags, recapitalizeMode);
} }
private void setSymbolsKeyboard() { private void setSymbolsKeyboard() {
if (DEBUG_ACTION) { if (DEBUG_INTERNAL_ACTION) {
Log.d(TAG, "setSymbolsKeyboard"); Log.d(TAG, "setSymbolsKeyboard");
} }
mSwitchActions.setSymbolsKeyboard(); mSwitchActions.setSymbolsKeyboard();
@ -318,7 +320,7 @@ public final class KeyboardState {
} }
private void setSymbolsShiftedKeyboard() { private void setSymbolsShiftedKeyboard() {
if (DEBUG_ACTION) { if (DEBUG_INTERNAL_ACTION) {
Log.d(TAG, "setSymbolsShiftedKeyboard"); Log.d(TAG, "setSymbolsShiftedKeyboard");
} }
mSwitchActions.setSymbolsShiftedKeyboard(); mSwitchActions.setSymbolsShiftedKeyboard();
@ -331,7 +333,7 @@ public final class KeyboardState {
} }
private void setEmojiKeyboard() { private void setEmojiKeyboard() {
if (DEBUG_ACTION) { if (DEBUG_INTERNAL_ACTION) {
Log.d(TAG, "setEmojiKeyboard"); Log.d(TAG, "setEmojiKeyboard");
} }
mIsAlphabetMode = false; mIsAlphabetMode = false;
@ -343,11 +345,12 @@ public final class KeyboardState {
mSwitchActions.setEmojiKeyboard(); mSwitchActions.setEmojiKeyboard();
} }
public void onPressKey(final int code, final boolean isSinglePointer, public void onPressKey(final int code, final boolean isSinglePointer, final int autoCapsFlags,
final int currentAutoCapsState, final int currentRecapitalizeState) { final int recapitalizeMode) {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onPressKey: code=" + Constants.printableCode(code) + " single=" Log.d(TAG, "onPressKey: code=" + Constants.printableCode(code)
+ isSinglePointer + " autoCaps=" + currentAutoCapsState + " " + this); + " single=" + isSinglePointer
+ " " + stateToString(autoCapsFlags, recapitalizeMode));
} }
if (code != Constants.CODE_SHIFT) { if (code != Constants.CODE_SHIFT) {
// Because the double tap shift key timer is to detect two consecutive shift key press, // Because the double tap shift key timer is to detect two consecutive shift key press,
@ -359,7 +362,7 @@ public final class KeyboardState {
} else if (code == Constants.CODE_CAPSLOCK) { } else if (code == Constants.CODE_CAPSLOCK) {
// Nothing to do here. See {@link #onReleaseKey(int,boolean)}. // Nothing to do here. See {@link #onReleaseKey(int,boolean)}.
} else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) { } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
onPressSymbol(currentAutoCapsState, currentRecapitalizeState); onPressSymbol(autoCapsFlags, recapitalizeMode);
} else { } else {
mShiftKeyState.onOtherKeyPressed(); mShiftKeyState.onOtherKeyPressed();
mSymbolKeyState.onOtherKeyPressed(); mSymbolKeyState.onOtherKeyPressed();
@ -372,7 +375,7 @@ public final class KeyboardState {
// off because, for example, we may be in the #1 state within the manual temporary // off because, for example, we may be in the #1 state within the manual temporary
// shifted mode. // shifted mode.
if (!isSinglePointer && mIsAlphabetMode if (!isSinglePointer && mIsAlphabetMode
&& currentAutoCapsState != TextUtils.CAP_MODE_CHARACTERS) { && autoCapsFlags != TextUtils.CAP_MODE_CHARACTERS) {
final boolean needsToResetAutoCaps = mAlphabetShiftState.isAutomaticShifted() final boolean needsToResetAutoCaps = mAlphabetShiftState.isAutomaticShifted()
|| (mAlphabetShiftState.isManualShifted() && mShiftKeyState.isReleasing()); || (mAlphabetShiftState.isManualShifted() && mShiftKeyState.isReleasing());
if (needsToResetAutoCaps) { if (needsToResetAutoCaps) {
@ -382,34 +385,35 @@ public final class KeyboardState {
} }
} }
public void onReleaseKey(final int code, final boolean withSliding, public void onReleaseKey(final int code, final boolean withSliding, final int autoCapsFlags,
final int currentAutoCapsState, final int currentRecapitalizeState) { final int recapitalizeMode) {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onReleaseKey: code=" + Constants.printableCode(code) Log.d(TAG, "onReleaseKey: code=" + Constants.printableCode(code)
+ " sliding=" + withSliding + " " + this); + " sliding=" + withSliding
+ " " + stateToString(autoCapsFlags, recapitalizeMode));
} }
if (code == Constants.CODE_SHIFT) { if (code == Constants.CODE_SHIFT) {
onReleaseShift(withSliding, currentAutoCapsState, currentRecapitalizeState); onReleaseShift(withSliding, autoCapsFlags, recapitalizeMode);
} else if (code == Constants.CODE_CAPSLOCK) { } else if (code == Constants.CODE_CAPSLOCK) {
setShiftLocked(!mAlphabetShiftState.isShiftLocked()); setShiftLocked(!mAlphabetShiftState.isShiftLocked());
} else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) { } else if (code == Constants.CODE_SWITCH_ALPHA_SYMBOL) {
onReleaseSymbol(withSliding, currentAutoCapsState, currentRecapitalizeState); onReleaseSymbol(withSliding, autoCapsFlags, recapitalizeMode);
} }
} }
private void onPressSymbol(final int currentAutoCapsState, private void onPressSymbol(final int autoCapsFlags,
final int currentRecapitalizeState) { final int recapitalizeMode) {
toggleAlphabetAndSymbols(currentAutoCapsState, currentRecapitalizeState); toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode);
mSymbolKeyState.onPress(); mSymbolKeyState.onPress();
mSwitchState = SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL; mSwitchState = SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL;
} }
private void onReleaseSymbol(final boolean withSliding, final int currentAutoCapsState, private void onReleaseSymbol(final boolean withSliding, final int autoCapsFlags,
final int currentRecapitalizeState) { final int recapitalizeMode) {
if (mSymbolKeyState.isChording()) { if (mSymbolKeyState.isChording()) {
// Switch back to the previous keyboard mode if the user chords the mode change key and // Switch back to the previous keyboard mode if the user chords the mode change key and
// another key, then releases the mode change key. // another key, then releases the mode change key.
toggleAlphabetAndSymbols(currentAutoCapsState, currentRecapitalizeState); toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode);
} else if (!withSliding) { } else if (!withSliding) {
// If the mode change key is being released without sliding, we should forget the // If the mode change key is being released without sliding, we should forget the
// previous symbols keyboard shift state and simply switch back to symbols layout // previous symbols keyboard shift state and simply switch back to symbols layout
@ -419,23 +423,23 @@ public final class KeyboardState {
mSymbolKeyState.onRelease(); mSymbolKeyState.onRelease();
} }
public void onUpdateShiftState(final int autoCaps, final int recapitalizeMode) { public void onUpdateShiftState(final int autoCapsFlags, final int recapitalizeMode) {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onUpdateShiftState: autoCaps=" + autoCaps + ", recapitalizeMode=" Log.d(TAG, "onUpdateShiftState: " + stateToString(autoCapsFlags, recapitalizeMode));
+ recapitalizeMode + " " + this);
} }
mRecapitalizeMode = recapitalizeMode; mRecapitalizeMode = recapitalizeMode;
updateAlphabetShiftState(autoCaps, recapitalizeMode); updateAlphabetShiftState(autoCapsFlags, recapitalizeMode);
} }
// TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout // TODO: Remove this method. Come up with a more comprehensive way to reset the keyboard layout
// when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal(). // when a keyboard layout set doesn't get reloaded in LatinIME.onStartInputViewInternal().
public void onResetKeyboardStateToAlphabet(final int currentAutoCapsState, public void onResetKeyboardStateToAlphabet(final int autoCapsFlags,
final int currentRecapitalizeState) { final int recapitalizeMode) {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onResetKeyboardStateToAlphabet: " + this); Log.d(TAG, "onResetKeyboardStateToAlphabet: "
+ stateToString(autoCapsFlags, recapitalizeMode));
} }
resetKeyboardStateToAlphabet(currentAutoCapsState, currentRecapitalizeState); resetKeyboardStateToAlphabet(autoCapsFlags, recapitalizeMode);
} }
private void updateShiftStateForRecapitalize(final int recapitalizeMode) { private void updateShiftStateForRecapitalize(final int recapitalizeMode) {
@ -453,7 +457,7 @@ public final class KeyboardState {
} }
} }
private void updateAlphabetShiftState(final int autoCaps, final int recapitalizeMode) { private void updateAlphabetShiftState(final int autoCapsFlags, final int recapitalizeMode) {
if (!mIsAlphabetMode) return; if (!mIsAlphabetMode) return;
if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != recapitalizeMode) { if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != recapitalizeMode) {
// We are recapitalizing. Match the keyboard to the current recapitalize state. // We are recapitalizing. Match the keyboard to the current recapitalize state.
@ -466,7 +470,7 @@ public final class KeyboardState {
return; return;
} }
if (!mAlphabetShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) { if (!mAlphabetShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) {
if (mShiftKeyState.isReleasing() && autoCaps != Constants.TextUtils.CAP_MODE_OFF) { if (mShiftKeyState.isReleasing() && autoCapsFlags != 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 {
@ -526,8 +530,8 @@ public final class KeyboardState {
} }
} }
private void onReleaseShift(final boolean withSliding, final int currentAutoCapsState, private void onReleaseShift(final boolean withSliding, final int autoCapsFlags,
final int currentRecapitalizeState) { final int recapitalizeMode) {
if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) { if (RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE != mRecapitalizeMode) {
// We are recapitalizing. We should match the keyboard state to the recapitalize // We are recapitalizing. We should match the keyboard state to the recapitalize
// state in priority. // state in priority.
@ -550,8 +554,7 @@ public final class KeyboardState {
// After chording input, automatic shift state may have been changed depending on // After chording input, automatic shift state may have been changed depending on
// what characters were input. // what characters were input.
mShiftKeyState.onRelease(); mShiftKeyState.onRelease();
mSwitchActions.requestUpdatingShiftState(currentAutoCapsState, mSwitchActions.requestUpdatingShiftState(autoCapsFlags, recapitalizeMode);
currentRecapitalizeState);
return; return;
} else if (mAlphabetShiftState.isShiftLockShifted() && withSliding) { } else if (mAlphabetShiftState.isShiftLockShifted() && withSliding) {
// In shift locked state, shift has been pressed and slid out to other key. // In shift locked state, shift has been pressed and slid out to other key.
@ -588,21 +591,20 @@ public final class KeyboardState {
mShiftKeyState.onRelease(); mShiftKeyState.onRelease();
} }
public void onFinishSlidingInput(final int currentAutoCapsState, public void onFinishSlidingInput(final int autoCapsFlags, final int recapitalizeMode) {
final int currentRecapitalizeState) {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onFinishSlidingInput: " + this); Log.d(TAG, "onFinishSlidingInput: " + stateToString(autoCapsFlags, recapitalizeMode));
} }
// Switch back to the previous keyboard mode if the user cancels sliding input. // Switch back to the previous keyboard mode if the user cancels sliding input.
switch (mSwitchState) { switch (mSwitchState) {
case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL: case SWITCH_STATE_MOMENTARY_ALPHA_AND_SYMBOL:
toggleAlphabetAndSymbols(currentAutoCapsState, currentRecapitalizeState); toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode);
break; break;
case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE: case SWITCH_STATE_MOMENTARY_SYMBOL_AND_MORE:
toggleShiftInSymbols(); toggleShiftInSymbols();
break; break;
case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT: case SWITCH_STATE_MOMENTARY_ALPHA_SHIFT:
setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
break; break;
} }
} }
@ -611,12 +613,11 @@ public final class KeyboardState {
return c == Constants.CODE_SPACE || c == Constants.CODE_ENTER; return c == Constants.CODE_SPACE || c == Constants.CODE_ENTER;
} }
public void onEvent(final Event event, final int currentAutoCapsState, public void onEvent(final Event event, final int autoCapsFlags, final int recapitalizeMode) {
final int currentRecapitalizeState) {
final int code = event.isFunctionalKeyEvent() ? event.mKeyCode : event.mCodePoint; final int code = event.isFunctionalKeyEvent() ? event.mKeyCode : event.mCodePoint;
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
Log.d(TAG, "onEvent: code=" + Constants.printableCode(code) Log.d(TAG, "onEvent: code=" + Constants.printableCode(code)
+ " autoCaps=" + currentAutoCapsState + " " + this); + " " + stateToString(autoCapsFlags, recapitalizeMode));
} }
switch (mSwitchState) { switch (mSwitchState) {
@ -652,7 +653,7 @@ public final class KeyboardState {
// Switch back to alpha keyboard mode if user types one or more non-space/enter // Switch back to alpha keyboard mode if user types one or more non-space/enter
// characters followed by a space/enter. // characters followed by a space/enter.
if (isSpaceOrEnter(code)) { if (isSpaceOrEnter(code)) {
toggleAlphabetAndSymbols(currentAutoCapsState, currentRecapitalizeState); toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode);
mPrevSymbolsKeyboardWasShifted = false; mPrevSymbolsKeyboardWasShifted = false;
} }
break; break;
@ -660,11 +661,11 @@ public final class KeyboardState {
// If the code is a letter, update keyboard shift state. // If the code is a letter, update keyboard shift state.
if (Constants.isLetterCode(code)) { if (Constants.isLetterCode(code)) {
updateAlphabetShiftState(currentAutoCapsState, currentRecapitalizeState); updateAlphabetShiftState(autoCapsFlags, recapitalizeMode);
} else if (code == Constants.CODE_EMOJI) { } else if (code == Constants.CODE_EMOJI) {
setEmojiKeyboard(); setEmojiKeyboard();
} else if (code == Constants.CODE_ALPHA_FROM_EMOJI) { } else if (code == Constants.CODE_ALPHA_FROM_EMOJI) {
setAlphabetKeyboard(currentAutoCapsState, currentRecapitalizeState); setAlphabetKeyboard(autoCapsFlags, recapitalizeMode);
} }
} }
@ -697,4 +698,9 @@ public final class KeyboardState {
+ " symbol=" + mSymbolKeyState + " symbol=" + mSymbolKeyState
+ " switch=" + switchStateToString(mSwitchState) + "]"; + " switch=" + switchStateToString(mSwitchState) + "]";
} }
private String stateToString(final int autoCapsFlags, final int recapitalizeMode) {
return this + " autoCapsFlags=" + CapsModeUtils.flagsToString(autoCapsFlags)
+ " recapitalizeMode=" + RecapitalizeStatus.modeToString(recapitalizeMode);
}
} }