Move KeyboardShiftState to KeyboardState
Bug: 5708602 Change-Id: Idfe69978972bb674e0f360ef5e324739e2652d25
This commit is contained in:
parent
4f7f61730c
commit
c1859b8fd2
4 changed files with 120 additions and 118 deletions
|
@ -21,7 +21,6 @@ import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
|
import com.android.inputmethod.keyboard.internal.KeyboardIconsSet;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardParams;
|
import com.android.inputmethod.keyboard.internal.KeyboardParams;
|
||||||
import com.android.inputmethod.keyboard.internal.KeyboardShiftState;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -112,11 +111,17 @@ public class Keyboard {
|
||||||
public final KeyboardIconsSet mIconsSet;
|
public final KeyboardIconsSet mIconsSet;
|
||||||
|
|
||||||
private final Map<Integer, Key> mKeyCache = new HashMap<Integer, Key>();
|
private final Map<Integer, Key> mKeyCache = new HashMap<Integer, Key>();
|
||||||
// TODO: Move this state to KeyboardSwitcher
|
|
||||||
/* package for debug */ final KeyboardShiftState mShiftState = new KeyboardShiftState();
|
|
||||||
|
|
||||||
private final ProximityInfo mProximityInfo;
|
private final ProximityInfo mProximityInfo;
|
||||||
|
|
||||||
|
// TODO: Remove these variables.
|
||||||
|
private static final int UNSHIFT = 0;
|
||||||
|
private static final int MANUAL_SHIFT = 1;
|
||||||
|
private static final int AUTOMATIC_SHIFT = 2;
|
||||||
|
private int mShiftMode;
|
||||||
|
private boolean mShifted;
|
||||||
|
private boolean mShiftLocked;
|
||||||
|
|
||||||
public Keyboard(KeyboardParams params) {
|
public Keyboard(KeyboardParams params) {
|
||||||
mId = params.mId;
|
mId = params.mId;
|
||||||
mThemeId = params.mThemeId;
|
mThemeId = params.mThemeId;
|
||||||
|
@ -163,10 +168,12 @@ public class Keyboard {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this method.
|
||||||
public boolean hasShiftLockKey() {
|
public boolean hasShiftLockKey() {
|
||||||
return !mShiftLockKeys.isEmpty();
|
return !mShiftLockKeys.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this method.
|
||||||
public void setShiftLocked(boolean newShiftLockState) {
|
public void setShiftLocked(boolean newShiftLockState) {
|
||||||
for (final Key key : mShiftLockKeys) {
|
for (final Key key : mShiftLockKeys) {
|
||||||
// To represent "shift locked" state. The highlight is handled by background image that
|
// To represent "shift locked" state. The highlight is handled by background image that
|
||||||
|
@ -174,47 +181,47 @@ public class Keyboard {
|
||||||
key.setHighlightOn(newShiftLockState);
|
key.setHighlightOn(newShiftLockState);
|
||||||
key.setIcon(newShiftLockState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key));
|
key.setIcon(newShiftLockState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key));
|
||||||
}
|
}
|
||||||
mShiftState.setShiftLocked(newShiftLockState);
|
mShiftLocked = newShiftLockState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Move this method to KeyboardId.
|
||||||
public boolean isShiftLocked() {
|
public boolean isShiftLocked() {
|
||||||
return mShiftState.isShiftLocked();
|
return mShiftLocked;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isShiftLockShifted() {
|
|
||||||
return mShiftState.isShiftLockShifted();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this method.
|
||||||
public void setShifted(boolean newShiftState) {
|
public void setShifted(boolean newShiftState) {
|
||||||
if (!mShiftState.isShiftLocked()) {
|
mShiftMode = (newShiftState ? MANUAL_SHIFT : UNSHIFT);
|
||||||
|
setShiftedInternal(newShiftState);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this method
|
||||||
|
private void setShiftedInternal(boolean newShiftState) {
|
||||||
|
if (!mShiftLocked) {
|
||||||
for (final Key key : mShiftKeys) {
|
for (final Key key : mShiftKeys) {
|
||||||
key.setIcon(newShiftState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key));
|
key.setIcon(newShiftState ? mShiftedIcons.get(key) : mUnshiftedIcons.get(key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mShiftState.setShifted(newShiftState);
|
mShifted = newShiftState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Move this method to KeyboardId.
|
||||||
public boolean isShiftedOrShiftLocked() {
|
public boolean isShiftedOrShiftLocked() {
|
||||||
return mShiftState.isShiftedOrShiftLocked();
|
return mShifted || mShiftLocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this method
|
||||||
public void setAutomaticTemporaryUpperCase() {
|
public void setAutomaticTemporaryUpperCase() {
|
||||||
setShifted(true);
|
mShiftMode = AUTOMATIC_SHIFT;
|
||||||
mShiftState.setAutomaticTemporaryUpperCase();
|
setShiftedInternal(true);
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isAutomaticTemporaryUpperCase() {
|
|
||||||
return mId.isAlphabetKeyboard() && mShiftState.isAutomaticTemporaryUpperCase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Move this method to KeyboardId.
|
||||||
public boolean isManualTemporaryUpperCase() {
|
public boolean isManualTemporaryUpperCase() {
|
||||||
return mId.isAlphabetKeyboard() && mShiftState.isManualTemporaryUpperCase();
|
return mShiftMode == MANUAL_SHIFT;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isManualTemporaryUpperCaseFromAuto() {
|
|
||||||
return mId.isAlphabetKeyboard() && mShiftState.isManualTemporaryUpperCaseFromAuto();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Remove this method.
|
||||||
public CharSequence adjustLabelCase(CharSequence label) {
|
public CharSequence adjustLabelCase(CharSequence label) {
|
||||||
if (isShiftedOrShiftLocked() && !TextUtils.isEmpty(label) && label.length() < 3
|
if (isShiftedOrShiftLocked() && !TextUtils.isEmpty(label) && label.length() < 3
|
||||||
&& Character.isLowerCase(label.charAt(0))) {
|
&& Character.isLowerCase(label.charAt(0))) {
|
||||||
|
|
|
@ -118,8 +118,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
}
|
}
|
||||||
mIsAlphabetMode = isAlphabetMode();
|
mIsAlphabetMode = isAlphabetMode();
|
||||||
if (mIsAlphabetMode) {
|
if (mIsAlphabetMode) {
|
||||||
mIsShiftLocked = isShiftLocked();
|
mIsShiftLocked = mState.isShiftLocked();
|
||||||
mIsShifted = !mIsShiftLocked && isShiftedOrShiftLocked();
|
mIsShifted = !mIsShiftLocked && mState.isShiftedOrShiftLocked();
|
||||||
} else {
|
} else {
|
||||||
mIsShiftLocked = false;
|
mIsShiftLocked = false;
|
||||||
mIsShifted = mCurrentId.equals(mSymbolsShiftedKeyboardId);
|
mIsShifted = mCurrentId.equals(mSymbolsShiftedKeyboardId);
|
||||||
|
@ -143,8 +143,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
if (mIsAlphabetMode) {
|
if (mIsAlphabetMode) {
|
||||||
final boolean isAlphabetMode = isAlphabetMode();
|
final boolean isAlphabetMode = isAlphabetMode();
|
||||||
final boolean isShiftLocked = isAlphabetMode && isShiftLocked();
|
final boolean isShiftLocked = isAlphabetMode && mState.isShiftLocked();
|
||||||
final boolean isShifted = !isShiftLocked && isShiftedOrShiftLocked();
|
final boolean isShifted = !isShiftLocked && mState.isShiftedOrShiftLocked();
|
||||||
if (mIsShiftLocked != isShiftLocked) {
|
if (mIsShiftLocked != isShiftLocked) {
|
||||||
toggleCapsLock();
|
toggleCapsLock();
|
||||||
} else if (mIsShifted != isShifted) {
|
} else if (mIsShifted != isShifted) {
|
||||||
|
@ -252,10 +252,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
// sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked()
|
// sticky shift key). To show or dismiss the indicator, we need to call setShiftLocked()
|
||||||
// that takes care of the current keyboard having such ALT key or not.
|
// that takes care of the current keyboard having such ALT key or not.
|
||||||
keyboard.setShiftLocked(keyboard.hasShiftLockKey());
|
keyboard.setShiftLocked(keyboard.hasShiftLockKey());
|
||||||
|
mState.setShiftLocked(keyboard.hasShiftLockKey());
|
||||||
} else if (mCurrentId.equals(mSymbolsKeyboardId)) {
|
} else if (mCurrentId.equals(mSymbolsKeyboardId)) {
|
||||||
// Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the
|
// Symbol keyboard has an ALT key that has a caps lock style indicator. To disable the
|
||||||
// indicator, we need to call setShiftLocked(false).
|
// indicator, we need to call setShiftLocked(false).
|
||||||
keyboard.setShiftLocked(false);
|
keyboard.setShiftLocked(false);
|
||||||
|
mState.setShiftLocked(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,52 +376,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShiftedOrShiftLocked() {
|
public boolean isShiftedOrShiftLocked() {
|
||||||
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
return mState.isShiftedOrShiftLocked();
|
||||||
if (latinKeyboard != null)
|
|
||||||
return latinKeyboard.isShiftedOrShiftLocked();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isShiftLocked() {
|
|
||||||
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
||||||
if (latinKeyboard != null)
|
|
||||||
return latinKeyboard.isShiftLocked();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isShiftLockShifted() {
|
|
||||||
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
||||||
if (latinKeyboard != null)
|
|
||||||
return latinKeyboard.isShiftLockShifted();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isAutomaticTemporaryUpperCase() {
|
|
||||||
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
||||||
if (latinKeyboard != null)
|
|
||||||
return latinKeyboard.isAutomaticTemporaryUpperCase();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isManualTemporaryUpperCase() {
|
public boolean isManualTemporaryUpperCase() {
|
||||||
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
return mState.isManualTemporaryUpperCase();
|
||||||
if (latinKeyboard != null)
|
|
||||||
return latinKeyboard.isManualTemporaryUpperCase();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isManualTemporaryUpperCaseFromAuto() {
|
private void setShifted(int shiftMode) {
|
||||||
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
|
||||||
if (latinKeyboard != null)
|
|
||||||
return latinKeyboard.isManualTemporaryUpperCaseFromAuto();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setShift(int shiftMode) {
|
|
||||||
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
||||||
if (latinKeyboard == null)
|
if (latinKeyboard == null)
|
||||||
return;
|
return;
|
||||||
if (shiftMode == AUTOMATIC_SHIFT) {
|
if (shiftMode == AUTOMATIC_SHIFT) {
|
||||||
|
mState.setAutomaticTemporaryUpperCase();
|
||||||
latinKeyboard.setAutomaticTemporaryUpperCase();
|
latinKeyboard.setAutomaticTemporaryUpperCase();
|
||||||
} else {
|
} else {
|
||||||
final boolean shifted = (shiftMode == MANUAL_SHIFT);
|
final boolean shifted = (shiftMode == MANUAL_SHIFT);
|
||||||
|
@ -428,8 +397,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
// 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 (!hasDistinctMultitouch() && !shifted && latinKeyboard.isShiftLocked()) {
|
if (!hasDistinctMultitouch() && !shifted && latinKeyboard.isShiftLocked()) {
|
||||||
|
mState.setShiftLocked(false);
|
||||||
latinKeyboard.setShiftLocked(false);
|
latinKeyboard.setShiftLocked(false);
|
||||||
}
|
}
|
||||||
|
mState.setShifted(shifted);
|
||||||
latinKeyboard.setShifted(shifted);
|
latinKeyboard.setShifted(shifted);
|
||||||
}
|
}
|
||||||
mKeyboardView.invalidateAllKeys();
|
mKeyboardView.invalidateAllKeys();
|
||||||
|
@ -437,10 +408,11 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
private void setShiftLocked(boolean shiftLocked) {
|
private void setShiftLocked(boolean shiftLocked) {
|
||||||
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
LatinKeyboard latinKeyboard = getLatinKeyboard();
|
||||||
if (latinKeyboard != null) {
|
if (latinKeyboard == null)
|
||||||
latinKeyboard.setShiftLocked(shiftLocked);
|
return;
|
||||||
mKeyboardView.invalidateAllKeys();
|
mState.setShiftLocked(shiftLocked);
|
||||||
}
|
latinKeyboard.setShiftLocked(shiftLocked);
|
||||||
|
mKeyboardView.invalidateAllKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -449,12 +421,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
public void toggleShift() {
|
public void toggleShift() {
|
||||||
mInputMethodService.mHandler.cancelUpdateShiftState();
|
mInputMethodService.mHandler.cancelUpdateShiftState();
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "toggleShift:"
|
Log.d(TAG, "toggleShift: " + mState);
|
||||||
+ " keyboard=" + getLatinKeyboard().mShiftState
|
|
||||||
+ " state=" + mState);
|
|
||||||
}
|
}
|
||||||
if (isAlphabetMode()) {
|
if (isAlphabetMode()) {
|
||||||
setShift(isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT);
|
setShifted(mState.isShiftedOrShiftLocked() ? UNSHIFT : MANUAL_SHIFT);
|
||||||
} else {
|
} else {
|
||||||
toggleShiftInSymbol();
|
toggleShiftInSymbol();
|
||||||
}
|
}
|
||||||
|
@ -463,12 +433,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
public void toggleCapsLock() {
|
public void toggleCapsLock() {
|
||||||
mInputMethodService.mHandler.cancelUpdateShiftState();
|
mInputMethodService.mHandler.cancelUpdateShiftState();
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "toggleCapsLock:"
|
Log.d(TAG, "toggleCapsLock: " + mState);
|
||||||
+ " keyboard=" + getLatinKeyboard().mShiftState
|
|
||||||
+ " state=" + mState);
|
|
||||||
}
|
}
|
||||||
if (isAlphabetMode()) {
|
if (isAlphabetMode()) {
|
||||||
if (isShiftLocked()) {
|
if (mState.isShiftLocked()) {
|
||||||
// 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.
|
||||||
setShiftLocked(false);
|
setShiftLocked(false);
|
||||||
|
@ -481,12 +449,10 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
public void changeKeyboardMode() {
|
public void changeKeyboardMode() {
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "changeKeyboardMode:"
|
Log.d(TAG, "changeKeyboardMode: " + mState);
|
||||||
+ " keyboard=" + getLatinKeyboard().mShiftState
|
|
||||||
+ " state=" + mState);
|
|
||||||
}
|
}
|
||||||
toggleKeyboardMode();
|
toggleKeyboardMode();
|
||||||
if (isShiftLocked() && isAlphabetMode()) {
|
if (mState.isShiftLocked() && isAlphabetMode()) {
|
||||||
setShiftLocked(true);
|
setShiftLocked(true);
|
||||||
}
|
}
|
||||||
updateShiftState();
|
updateShiftState();
|
||||||
|
@ -502,23 +468,19 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
* Update keyboard shift state triggered by connected EditText status change.
|
* Update keyboard shift state triggered by connected EditText status change.
|
||||||
*/
|
*/
|
||||||
public void updateShiftState() {
|
public void updateShiftState() {
|
||||||
final boolean isAlphabetMode = isAlphabetMode();
|
|
||||||
final boolean isShiftLocked = isShiftLocked();
|
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "updateShiftState:"
|
Log.d(TAG, "updateShiftState: " + mState
|
||||||
+ " autoCaps=" + mInputMethodService.getCurrentAutoCapsState()
|
+ " autoCaps=" + mInputMethodService.getCurrentAutoCapsState());
|
||||||
+ " keyboard=" + getLatinKeyboard().mShiftState
|
|
||||||
+ " isAlphabetMode=" + isAlphabetMode
|
|
||||||
+ " isShiftLocked=" + isShiftLocked
|
|
||||||
+ " state=" + mState);
|
|
||||||
}
|
}
|
||||||
|
final boolean isAlphabetMode = isAlphabetMode();
|
||||||
|
final boolean isShiftLocked = mState.isShiftLocked();
|
||||||
if (isAlphabetMode) {
|
if (isAlphabetMode) {
|
||||||
if (!isShiftLocked && !mState.isShiftKeyIgnoring()) {
|
if (!isShiftLocked && !mState.isShiftKeyIgnoring()) {
|
||||||
if (mState.isShiftKeyReleasing() && mInputMethodService.getCurrentAutoCapsState()) {
|
if (mState.isShiftKeyReleasing() && mInputMethodService.getCurrentAutoCapsState()) {
|
||||||
// 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.
|
||||||
setShift(AUTOMATIC_SHIFT);
|
setShifted(AUTOMATIC_SHIFT);
|
||||||
} else {
|
} else {
|
||||||
setShift(mState.isShiftKeyMomentary() ? MANUAL_SHIFT : UNSHIFT);
|
setShifted(mState.isShiftKeyMomentary() ? MANUAL_SHIFT : UNSHIFT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -529,23 +491,21 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
if (!isKeyboardAvailable())
|
if (!isKeyboardAvailable())
|
||||||
return;
|
return;
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "onPressShift:"
|
Log.d(TAG, "onPressShift: " + mState + " sliding=" + withSliding);
|
||||||
+ " keyboard=" + getLatinKeyboard().mShiftState
|
|
||||||
+ " state=" + mState + " sliding=" + withSliding);
|
|
||||||
}
|
}
|
||||||
final boolean isAlphabetMode = isAlphabetMode();
|
final boolean isAlphabetMode = isAlphabetMode();
|
||||||
final boolean isShiftLocked = isShiftLocked();
|
final boolean isShiftLocked = mState.isShiftLocked();
|
||||||
final boolean isAutomaticTemporaryUpperCase = isAutomaticTemporaryUpperCase();
|
final boolean isAutomaticTemporaryUpperCase = mState.isAutomaticTemporaryUpperCase();
|
||||||
final boolean isShiftedOrShiftLocked = isShiftedOrShiftLocked();
|
final boolean isShiftedOrShiftLocked = mState.isShiftedOrShiftLocked();
|
||||||
if (isAlphabetMode) {
|
if (isAlphabetMode) {
|
||||||
if (isShiftLocked) {
|
if (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.
|
||||||
setShift(MANUAL_SHIFT);
|
setShifted(MANUAL_SHIFT);
|
||||||
} else if (isAutomaticTemporaryUpperCase) {
|
} else if (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.
|
||||||
setShift(MANUAL_SHIFT);
|
setShifted(MANUAL_SHIFT);
|
||||||
} else if (isShiftedOrShiftLocked) {
|
} else if (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.
|
||||||
|
@ -566,15 +526,14 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
if (!isKeyboardAvailable())
|
if (!isKeyboardAvailable())
|
||||||
return;
|
return;
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "onReleaseShift:"
|
Log.d(TAG, "onReleaseShift: " + mState + " sliding=" + withSliding);
|
||||||
+ " keyboard=" + getLatinKeyboard().mShiftState
|
|
||||||
+ " state=" + mState + " sliding=" + withSliding);
|
|
||||||
}
|
}
|
||||||
final boolean isAlphabetMode = isAlphabetMode();
|
final boolean isAlphabetMode = isAlphabetMode();
|
||||||
final boolean isShiftLocked = isShiftLocked();
|
final boolean isShiftLocked = mState.isShiftLocked();
|
||||||
final boolean isShiftLockShifted = isShiftLockShifted();
|
final boolean isShiftLockShifted = mState.isShiftLockShifted();
|
||||||
final boolean isShiftedOrShiftLocked = isShiftedOrShiftLocked();
|
final boolean isShiftedOrShiftLocked = mState.isShiftedOrShiftLocked();
|
||||||
final boolean isManualTemporaryUpperCaseFromAuto = isManualTemporaryUpperCaseFromAuto();
|
final boolean isManualTemporaryUpperCaseFromAuto =
|
||||||
|
mState.isManualTemporaryUpperCaseFromAuto();
|
||||||
if (isAlphabetMode) {
|
if (isAlphabetMode) {
|
||||||
if (mState.isShiftKeyMomentary()) {
|
if (mState.isShiftKeyMomentary()) {
|
||||||
// After chording input while normal state.
|
// After chording input while normal state.
|
||||||
|
@ -611,9 +570,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
public void onPressSymbol() {
|
public void onPressSymbol() {
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "onPressSymbol:"
|
Log.d(TAG, "onPressSymbol: " + mState);
|
||||||
+ " keyboard=" + getLatinKeyboard().mShiftState
|
|
||||||
+ " state=" + mState);
|
|
||||||
}
|
}
|
||||||
changeKeyboardMode();
|
changeKeyboardMode();
|
||||||
mState.onPressSymbol();
|
mState.onPressSymbol();
|
||||||
|
@ -622,10 +579,8 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
public void onReleaseSymbol() {
|
public void onReleaseSymbol() {
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "onReleaseSymbol:"
|
Log.d(TAG, "onReleaseSymbol: " + mState);
|
||||||
+ " keyboard=" + getLatinKeyboard().mShiftState
|
}
|
||||||
+ " state=" + mState);
|
|
||||||
}
|
|
||||||
// Snap back to the previous keyboard mode if the user chords the mode change key and
|
// Snap 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.
|
||||||
if (mSwitchState == SWITCH_STATE_CHORDING_ALPHA) {
|
if (mSwitchState == SWITCH_STATE_CHORDING_ALPHA) {
|
||||||
|
@ -636,9 +591,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
public void onOtherKeyPressed() {
|
public void onOtherKeyPressed() {
|
||||||
if (DEBUG_STATE) {
|
if (DEBUG_STATE) {
|
||||||
Log.d(TAG, "onOtherKeyPressed:"
|
Log.d(TAG, "onOtherKeyPressed: " + mState);
|
||||||
+ " keyboard=" + getLatinKeyboard().mShiftState
|
|
||||||
+ " state=" + mState);
|
|
||||||
}
|
}
|
||||||
mState.onOtherKeyPressed();
|
mState.onOtherKeyPressed();
|
||||||
}
|
}
|
||||||
|
@ -658,7 +611,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
|
|
||||||
private void toggleKeyboardMode() {
|
private void toggleKeyboardMode() {
|
||||||
if (mCurrentId.equals(mMainKeyboardId)) {
|
if (mCurrentId.equals(mMainKeyboardId)) {
|
||||||
mPrevMainKeyboardWasShiftLocked = isShiftLocked();
|
mPrevMainKeyboardWasShiftLocked = mState.isShiftLocked();
|
||||||
setKeyboard(getKeyboard(mSymbolsKeyboardId));
|
setKeyboard(getKeyboard(mSymbolsKeyboardId));
|
||||||
} else {
|
} else {
|
||||||
setKeyboard(getKeyboard(mMainKeyboardId));
|
setKeyboard(getKeyboard(mMainKeyboardId));
|
||||||
|
|
|
@ -20,7 +20,7 @@ import android.util.Log;
|
||||||
|
|
||||||
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
||||||
|
|
||||||
public class KeyboardShiftState {
|
/* package */ class KeyboardShiftState {
|
||||||
private static final String TAG = KeyboardShiftState.class.getSimpleName();
|
private static final String TAG = KeyboardShiftState.class.getSimpleName();
|
||||||
private static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE;
|
private static final boolean DEBUG = KeyboardSwitcher.DEBUG_STATE;
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@ package com.android.inputmethod.keyboard.internal;
|
||||||
|
|
||||||
// TODO: Add unit tests
|
// TODO: Add unit tests
|
||||||
public class KeyboardState {
|
public class KeyboardState {
|
||||||
|
private KeyboardShiftState mKeyboardShiftState = new KeyboardShiftState();
|
||||||
|
|
||||||
// TODO: Combine these key state objects with auto mode switch state.
|
// TODO: Combine these key state objects with auto mode switch state.
|
||||||
private ShiftKeyState mShiftKeyState = new ShiftKeyState("Shift");
|
private ShiftKeyState mShiftKeyState = new ShiftKeyState("Shift");
|
||||||
private ModifierKeyState mSymbolKeyState = new ModifierKeyState("Symbol");
|
private ModifierKeyState mSymbolKeyState = new ModifierKeyState("Symbol");
|
||||||
|
@ -25,6 +27,45 @@ public class KeyboardState {
|
||||||
public KeyboardState() {
|
public KeyboardState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Get rid of this method
|
||||||
|
public void setShifted(boolean shifted) {
|
||||||
|
mKeyboardShiftState.setShifted(shifted);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Get rid of this method
|
||||||
|
public void setShiftLocked(boolean shiftLocked) {
|
||||||
|
mKeyboardShiftState.setShiftLocked(shiftLocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Get rid of this method
|
||||||
|
public void setAutomaticTemporaryUpperCase() {
|
||||||
|
mKeyboardShiftState.setAutomaticTemporaryUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Get rid of this method
|
// TODO: Get rid of this method
|
||||||
public boolean isShiftKeyIgnoring() {
|
public boolean isShiftKeyIgnoring() {
|
||||||
return mShiftKeyState.isIgnoring();
|
return mShiftKeyState.isIgnoring();
|
||||||
|
@ -107,7 +148,8 @@ public class KeyboardState {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[shift=" + mShiftKeyState
|
return "[keyboard=" + mKeyboardShiftState
|
||||||
|
+ " shift=" + mShiftKeyState
|
||||||
+ " symbol=" + mSymbolKeyState + "]";
|
+ " symbol=" + mSymbolKeyState + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue