am 963abf4b: Merge "Remove unused public methods from KeyboardState and KeyboardSwitcher"

* commit '963abf4bcc0e1676f3d183216c222d8d88059197':
  Remove unused public methods from KeyboardState and KeyboardSwitcher
main
Tadashi G. Takaoka 2011-12-09 11:00:53 -08:00 committed by Android Git Automerger
commit 2db1bc4eb8
3 changed files with 42 additions and 75 deletions

View File

@ -274,18 +274,25 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
voiceKeyEnabled, hasShortcutKey); voiceKeyEnabled, hasShortcutKey);
} }
public int getKeyboardMode() {
return mCurrentId != null ? mCurrentId.mMode : KeyboardId.MODE_TEXT;
}
public boolean isAlphabetMode() { public boolean isAlphabetMode() {
return mState.isAlphabetMode(); final Keyboard keyboard = getLatinKeyboard();
return keyboard != null && keyboard.mId.isAlphabetKeyboard();
} }
public boolean isInputViewShown() { public boolean isInputViewShown() {
return mCurrentInputView != null && mCurrentInputView.isShown(); return mCurrentInputView != null && mCurrentInputView.isShown();
} }
public boolean isShiftedOrShiftLocked() {
final Keyboard keyboard = getLatinKeyboard();
return keyboard != null && keyboard.isShiftedOrShiftLocked();
}
public boolean isManualTemporaryUpperCase() {
final Keyboard keyboard = getLatinKeyboard();
return keyboard != null && keyboard.isManualTemporaryUpperCase();
}
public boolean isKeyboardAvailable() { public boolean isKeyboardAvailable() {
if (mKeyboardView != null) if (mKeyboardView != null)
return mKeyboardView.getKeyboard() != null; return mKeyboardView.getKeyboard() != null;
@ -301,14 +308,6 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions,
return null; return null;
} }
public boolean isShiftedOrShiftLocked() {
return mState.isShiftedOrShiftLocked();
}
public boolean isManualTemporaryUpperCase() {
return mState.isManualTemporaryUpperCase();
}
// Implements {@link KeyboardState.SwitchActions}. // Implements {@link KeyboardState.SwitchActions}.
@Override @Override
public void setShifted(int shiftMode) { public void setShifted(int shiftMode) {

View File

@ -26,11 +26,13 @@ import com.android.inputmethod.keyboard.Keyboard;
* Keyboard state machine. * Keyboard state machine.
* *
* This class contains all keyboard state transition logic. * This class contains all keyboard state transition logic.
*
* The input events are {@link #onLoadKeyboard(String, boolean)}, {@link #onSaveKeyboardState()}, * The input events are {@link #onLoadKeyboard(String, boolean)}, {@link #onSaveKeyboardState()},
* {@link #onPressShift(boolean)}, {@link #onReleaseShift(boolean)}, {@link #onPressSymbol()}, * {@link #onPressShift(boolean)}, {@link #onReleaseShift(boolean)}, {@link #onPressSymbol()},
* {@link #onReleaseSymbol()}, {@link #onOtherKeyPressed()}, {@link #onCodeInput(int, boolean)}, * {@link #onReleaseSymbol()}, {@link #onOtherKeyPressed()}, {@link #onCodeInput(int, boolean)},
* {@link #onCancelInput(boolean)}, {@link #onUpdateShiftState(boolean)}, {@link #onToggleShift()}, * {@link #onCancelInput(boolean)}, {@link #onUpdateShiftState(boolean)}, {@link #onToggleShift()},
* {@link #onToggleCapsLock()}, and {@link #onToggleAlphabetAndSymbols()}. * {@link #onToggleCapsLock()}, and {@link #onToggleAlphabetAndSymbols()}.
*
* The actions are {@link SwitchActions}'s methods. * The actions are {@link SwitchActions}'s methods.
*/ */
public class KeyboardState { public class KeyboardState {
@ -39,12 +41,16 @@ public class KeyboardState {
public interface SwitchActions { public interface SwitchActions {
public void setAlphabetKeyboard(); public void setAlphabetKeyboard();
public static final int UNSHIFT = 0; public static final int UNSHIFT = 0;
public static final int MANUAL_SHIFT = 1; public static final int MANUAL_SHIFT = 1;
public static final int AUTOMATIC_SHIFT = 2; public static final int AUTOMATIC_SHIFT = 2;
public void setShifted(int shiftMode); public void setShifted(int shiftMode);
public void setShiftLocked(boolean shiftLocked); public void setShiftLocked(boolean shiftLocked);
public void setSymbolsKeyboard(); public void setSymbolsKeyboard();
public void setSymbolsShiftedKeyboard(); public void setSymbolsShiftedKeyboard();
} }
@ -103,8 +109,9 @@ public class KeyboardState {
final SavedKeyboardState state = mSavedKeyboardState; final SavedKeyboardState state = mSavedKeyboardState;
state.mIsAlphabetMode = mIsAlphabetMode; state.mIsAlphabetMode = mIsAlphabetMode;
if (mIsAlphabetMode) { if (mIsAlphabetMode) {
state.mIsShiftLocked = isShiftLocked(); state.mIsShiftLocked = mKeyboardShiftState.isShiftLocked();
state.mIsShifted = !state.mIsShiftLocked && isShiftedOrShiftLocked(); state.mIsShifted = !state.mIsShiftLocked
&& mKeyboardShiftState.isShiftedOrShiftLocked();
} else { } else {
state.mIsShiftLocked = false; state.mIsShiftLocked = false;
state.mIsShifted = mIsSymbolShifted; state.mIsShifted = mIsSymbolShifted;
@ -144,34 +151,11 @@ public class KeyboardState {
} }
} }
public boolean isAlphabetMode() { // TODO: Remove this method.
return mIsAlphabetMode;
}
public boolean isShiftLocked() { public boolean isShiftLocked() {
return mKeyboardShiftState.isShiftLocked(); return mKeyboardShiftState.isShiftLocked();
} }
public boolean isShiftLockShifted() {
return mKeyboardShiftState.isShiftLockShifted();
}
public boolean isShiftedOrShiftLocked() {
return mKeyboardShiftState.isShiftedOrShiftLocked();
}
public boolean isAutomaticTemporaryUpperCase() {
return mKeyboardShiftState.isAutomaticTemporaryUpperCase();
}
public boolean isManualTemporaryUpperCase() {
return mKeyboardShiftState.isManualTemporaryUpperCase();
}
public boolean isManualTemporaryUpperCaseFromAuto() {
return mKeyboardShiftState.isManualTemporaryUpperCaseFromAuto();
}
private void setShifted(int shiftMode) { private void setShifted(int shiftMode) {
if (DEBUG_STATE) { if (DEBUG_STATE) {
Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode)); Log.d(TAG, "setShifted: shiftMode=" + shiftModeToString(shiftMode));
@ -185,7 +169,7 @@ public class KeyboardState {
// state when shift key is pressed to go to normal mode. // state when shift key is pressed to go to normal mode.
// On the other hand, on distinct multi touch panel device, turning off the shift // On the other hand, on distinct multi touch panel device, turning off the shift
// locked state with shift key pressing is handled by onReleaseShift(). // locked state with shift key pressing is handled by onReleaseShift().
if (!mHasDistinctMultitouch && !shifted && isShiftLocked()) { if (!mHasDistinctMultitouch && !shifted && mKeyboardShiftState.isShiftLocked()) {
mKeyboardShiftState.setShiftLocked(false); mKeyboardShiftState.setShiftLocked(false);
} }
mKeyboardShiftState.setShifted(shifted); mKeyboardShiftState.setShifted(shifted);
@ -233,7 +217,7 @@ public class KeyboardState {
if (DEBUG_STATE) { if (DEBUG_STATE) {
Log.d(TAG, "setSymbolsKeyboard"); Log.d(TAG, "setSymbolsKeyboard");
} }
mPrevMainKeyboardWasShiftLocked = isShiftLocked(); mPrevMainKeyboardWasShiftLocked = mKeyboardShiftState.isShiftLocked();
mSwitchActions.setSymbolsKeyboard(); mSwitchActions.setSymbolsKeyboard();
mIsAlphabetMode = false; mIsAlphabetMode = false;
mIsSymbolShifted = false; mIsSymbolShifted = false;
@ -284,7 +268,7 @@ public class KeyboardState {
Log.d(TAG, "onUpdateShiftState: " + this + " autoCaps=" + autoCaps); Log.d(TAG, "onUpdateShiftState: " + this + " autoCaps=" + autoCaps);
} }
if (mIsAlphabetMode) { if (mIsAlphabetMode) {
if (!isShiftLocked() && !mShiftKeyState.isIgnoring()) { if (!mKeyboardShiftState.isShiftLocked() && !mShiftKeyState.isIgnoring()) {
if (mShiftKeyState.isReleasing() && autoCaps) { if (mShiftKeyState.isReleasing() && autoCaps) {
// 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(SwitchActions.AUTOMATIC_SHIFT); setShifted(SwitchActions.AUTOMATIC_SHIFT);
@ -305,17 +289,17 @@ public class KeyboardState {
Log.d(TAG, "onPressShift: " + this + " sliding=" + withSliding); Log.d(TAG, "onPressShift: " + this + " sliding=" + withSliding);
} }
if (mIsAlphabetMode) { if (mIsAlphabetMode) {
if (isShiftLocked()) { if (mKeyboardShiftState.isShiftLocked()) {
// Shift key is pressed while caps lock state, we will treat this state as shifted // Shift key is pressed while caps lock state, we will treat this state as shifted
// caps lock state and mark as if shift key pressed while normal state. // caps lock state and mark as if shift key pressed while normal state.
setShifted(SwitchActions.MANUAL_SHIFT); setShifted(SwitchActions.MANUAL_SHIFT);
mShiftKeyState.onPress(); mShiftKeyState.onPress();
} else if (isAutomaticTemporaryUpperCase()) { } else if (mKeyboardShiftState.isAutomaticTemporaryUpperCase()) {
// Shift key is pressed while automatic temporary upper case, we have to move to // Shift key is pressed while automatic temporary upper case, we have to move to
// manual temporary upper case. // manual temporary upper case.
setShifted(SwitchActions.MANUAL_SHIFT); setShifted(SwitchActions.MANUAL_SHIFT);
mShiftKeyState.onPress(); mShiftKeyState.onPress();
} else if (isShiftedOrShiftLocked()) { } else if (mKeyboardShiftState.isShiftedOrShiftLocked()) {
// In manual upper case state, we just record shift key has been pressing while // In manual upper case state, we just record shift key has been pressing while
// shifted state. // shifted state.
mShiftKeyState.onPressOnShifted(); mShiftKeyState.onPressOnShifted();
@ -337,22 +321,23 @@ public class KeyboardState {
Log.d(TAG, "onReleaseShift: " + this + " sliding=" + withSliding); Log.d(TAG, "onReleaseShift: " + this + " sliding=" + withSliding);
} }
if (mIsAlphabetMode) { if (mIsAlphabetMode) {
final boolean isShiftLocked = isShiftLocked(); final boolean isShiftLocked = mKeyboardShiftState.isShiftLocked();
if (mShiftKeyState.isMomentary()) { if (mShiftKeyState.isMomentary()) {
// After chording input while normal state. // After chording input while normal state.
setShifted(SwitchActions.UNSHIFT); setShifted(SwitchActions.UNSHIFT);
} else if (isShiftLocked && !isShiftLockShifted() && (mShiftKeyState.isPressing() } else if (isShiftLocked && !mKeyboardShiftState.isShiftLockShifted()
|| mShiftKeyState.isPressingOnShifted()) && !withSliding) { && (mShiftKeyState.isPressing() || mShiftKeyState.isPressingOnShifted())
&& !withSliding) {
// Shift has been long pressed, ignore this release. // Shift has been long pressed, ignore this release.
} else if (isShiftLocked && !mShiftKeyState.isIgnoring() && !withSliding) { } else if (isShiftLocked && !mShiftKeyState.isIgnoring() && !withSliding) {
// Shift has been pressed without chording while caps lock state. // Shift has been pressed without chording while caps lock state.
setShiftLocked(false); setShiftLocked(false);
} else if (isShiftedOrShiftLocked() && mShiftKeyState.isPressingOnShifted() } else if (mKeyboardShiftState.isShiftedOrShiftLocked()
&& !withSliding) { && mShiftKeyState.isPressingOnShifted() && !withSliding) {
// Shift has been pressed without chording while shifted state. // Shift has been pressed without chording while shifted state.
setShifted(SwitchActions.UNSHIFT); setShifted(SwitchActions.UNSHIFT);
} else if (isManualTemporaryUpperCaseFromAuto() && mShiftKeyState.isPressing() } else if (mKeyboardShiftState.isManualTemporaryUpperCaseFromAuto()
&& !withSliding) { && mShiftKeyState.isPressing() && !withSliding) {
// Shift has been pressed without chording while manual temporary upper case // Shift has been pressed without chording while manual temporary upper case
// transited from automatic temporary upper case. // transited from automatic temporary upper case.
setShifted(SwitchActions.UNSHIFT); setShifted(SwitchActions.UNSHIFT);
@ -468,7 +453,7 @@ public class KeyboardState {
Log.d(TAG, "onToggleShift: " + this); Log.d(TAG, "onToggleShift: " + this);
} }
if (mIsAlphabetMode) { if (mIsAlphabetMode) {
setShifted(isShiftedOrShiftLocked() setShifted(mKeyboardShiftState.isShiftedOrShiftLocked()
? SwitchActions.UNSHIFT : SwitchActions.MANUAL_SHIFT); ? SwitchActions.UNSHIFT : SwitchActions.MANUAL_SHIFT);
} else { } else {
toggleShiftInSymbols(); toggleShiftInSymbols();
@ -480,7 +465,7 @@ public class KeyboardState {
Log.d(TAG, "onToggleCapsLock: " + this); Log.d(TAG, "onToggleCapsLock: " + this);
} }
if (mIsAlphabetMode) { if (mIsAlphabetMode) {
if (isShiftLocked()) { if (mKeyboardShiftState.isShiftLocked()) {
setShiftLocked(false); setShiftLocked(false);
// Shift key is long pressed while caps lock state, we will toggle back to normal // Shift key is long pressed while caps lock state, we will toggle back to normal
// state. And mark as if shift key is released. // state. And mark as if shift key is released.
@ -506,6 +491,7 @@ public class KeyboardState {
default: return null; default: return null;
} }
} }
private static String switchStateToString(int switchState) { private static String switchStateToString(int switchState) {
switch (switchState) { switch (switchState) {
case SWITCH_STATE_ALPHA: return "ALPHA"; case SWITCH_STATE_ALPHA: return "ALPHA";

View File

@ -78,7 +78,6 @@ import java.util.Locale;
public class LatinIME extends InputMethodServiceCompatWrapper implements KeyboardActionListener, public class LatinIME extends InputMethodServiceCompatWrapper implements KeyboardActionListener,
SuggestionsView.Listener { SuggestionsView.Listener {
private static final String TAG = LatinIME.class.getSimpleName(); private static final String TAG = LatinIME.class.getSimpleName();
private static final boolean PERF_DEBUG = false;
private static final boolean TRACE = false; private static final boolean TRACE = false;
private static boolean DEBUG; private static boolean DEBUG;
@ -1577,7 +1576,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
switcher.updateShiftState(); switcher.updateShiftState();
if (LatinIME.PERF_DEBUG) measureCps();
TextEntryState.typedCharacter((char) code, mSettingsValues.isWordSeparator(code), x, y); TextEntryState.typedCharacter((char) code, mSettingsValues.isWordSeparator(code), x, y);
if (null != ic) ic.endBatchEdit(); if (null != ic) ic.endBatchEdit();
} }
@ -2478,7 +2476,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final Printer p = new PrintWriterPrinter(fout); final Printer p = new PrintWriterPrinter(fout);
p.println("LatinIME state :"); p.println("LatinIME state :");
p.println(" Keyboard mode = " + mKeyboardSwitcher.getKeyboardMode()); final Keyboard keyboard = mKeyboardSwitcher.getLatinKeyboard();
final int keyboardMode = keyboard != null ? keyboard.mId.mMode : -1;
p.println(" Keyboard mode = " + keyboardMode);
p.println(" mComposingStringBuilder=" + mComposingStringBuilder.toString()); p.println(" mComposingStringBuilder=" + mComposingStringBuilder.toString());
p.println(" mIsSuggestionsRequested=" + mIsSettingsSuggestionStripOn); p.println(" mIsSuggestionsRequested=" + mIsSettingsSuggestionStripOn);
p.println(" mCorrectionMode=" + mCorrectionMode); p.println(" mCorrectionMode=" + mCorrectionMode);
@ -2491,22 +2491,4 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
p.println(" mVibrateOn=" + mSettingsValues.mVibrateOn); p.println(" mVibrateOn=" + mSettingsValues.mVibrateOn);
p.println(" mKeyPreviewPopupOn=" + mSettingsValues.mKeyPreviewPopupOn); p.println(" mKeyPreviewPopupOn=" + mSettingsValues.mKeyPreviewPopupOn);
} }
// Characters per second measurement
private long mLastCpsTime;
private static final int CPS_BUFFER_SIZE = 16;
private long[] mCpsIntervals = new long[CPS_BUFFER_SIZE];
private int mCpsIndex;
private void measureCps() {
long now = System.currentTimeMillis();
if (mLastCpsTime == 0) mLastCpsTime = now - 100; // Initial
mCpsIntervals[mCpsIndex] = now - mLastCpsTime;
mLastCpsTime = now;
mCpsIndex = (mCpsIndex + 1) % CPS_BUFFER_SIZE;
long total = 0;
for (int i = 0; i < CPS_BUFFER_SIZE; i++) total += mCpsIntervals[i];
System.out.println("CPS = " + ((CPS_BUFFER_SIZE * 1000f) / total));
}
} }