KeyboardSwitcherpublic class KeyboardSwitcher extends Object
Fields Summary |
---|
public static final int | MODE_TEXT | public static final int | MODE_SYMBOLS | public static final int | MODE_PHONE | public static final int | MODE_URL | public static final int | MODE_EMAIL | public static final int | MODE_IM | public static final int | MODE_TEXT_QWERTY | public static final int | MODE_TEXT_ALPHA | public static final int | MODE_TEXT_COUNT | public static final int | KEYBOARDMODE_NORMAL | public static final int | KEYBOARDMODE_URL | public static final int | KEYBOARDMODE_EMAIL | public static final int | KEYBOARDMODE_IM | LatinKeyboardView | mInputView | LatinIME | mContext | private LatinKeyboard | mPhoneKeyboard | private LatinKeyboard | mPhoneSymbolsKeyboard | private LatinKeyboard | mSymbolsKeyboard | private LatinKeyboard | mSymbolsShiftedKeyboard | private LatinKeyboard | mQwertyKeyboard | private LatinKeyboard | mAlphaKeyboard | private LatinKeyboard | mUrlKeyboard | private LatinKeyboard | mEmailKeyboard | private LatinKeyboard | mIMKeyboard | List | mKeyboards | private int | mMode | private int | mImeOptions | private int | mTextMode | private int | mLastDisplayWidth |
Constructors Summary |
---|
KeyboardSwitcher(LatinIME context)
mContext = context;
|
Methods Summary |
---|
int | getKeyboardMode()
return mMode;
| int | getTextMode()
return mTextMode;
| int | getTextModeCount()
return MODE_TEXT_COUNT;
| boolean | isAlphabetMode()
Keyboard current = mInputView.getKeyboard();
if (current == mQwertyKeyboard
|| current == mAlphaKeyboard
|| current == mUrlKeyboard
|| current == mIMKeyboard
|| current == mEmailKeyboard) {
return true;
}
return false;
| boolean | isTextMode()
return mMode == MODE_TEXT;
| void | makeKeyboards()
// Configuration change is coming after the keyboard gets recreated. So don't rely on that.
// If keyboards have already been made, check if we have a screen width change and
// create the keyboard layouts again at the correct orientation
if (mKeyboards != null) {
int displayWidth = mContext.getMaxWidth();
if (displayWidth == mLastDisplayWidth) return;
mLastDisplayWidth = displayWidth;
}
// Delayed creation when keyboard mode is set.
mQwertyKeyboard = null;
mAlphaKeyboard = null;
mUrlKeyboard = null;
mEmailKeyboard = null;
mIMKeyboard = null;
mPhoneKeyboard = null;
mPhoneSymbolsKeyboard = null;
mSymbolsKeyboard = null;
mSymbolsShiftedKeyboard = null;
| void | setInputView(LatinKeyboardView inputView)
mInputView = inputView;
| void | setKeyboardMode(int mode, int imeOptions)
mMode = mode;
mImeOptions = imeOptions;
LatinKeyboard keyboard = (LatinKeyboard) mInputView.getKeyboard();
mInputView.setPreviewEnabled(true);
switch (mode) {
case MODE_TEXT:
if (mTextMode == MODE_TEXT_QWERTY) {
if (mQwertyKeyboard == null) {
mQwertyKeyboard = new LatinKeyboard(mContext, R.xml.kbd_qwerty,
KEYBOARDMODE_NORMAL);
mQwertyKeyboard.enableShiftLock();
}
keyboard = mQwertyKeyboard;
} else if (mTextMode == MODE_TEXT_ALPHA) {
if (mAlphaKeyboard == null) {
mAlphaKeyboard = new LatinKeyboard(mContext, R.xml.kbd_alpha,
KEYBOARDMODE_NORMAL);
mAlphaKeyboard.enableShiftLock();
}
keyboard = mAlphaKeyboard;
}
break;
case MODE_SYMBOLS:
if (mSymbolsKeyboard == null) {
mSymbolsKeyboard = new LatinKeyboard(mContext, R.xml.kbd_symbols);
}
if (mSymbolsShiftedKeyboard == null) {
mSymbolsShiftedKeyboard = new LatinKeyboard(mContext, R.xml.kbd_symbols_shift);
}
keyboard = mSymbolsKeyboard;
break;
case MODE_PHONE:
if (mPhoneKeyboard == null) {
mPhoneKeyboard = new LatinKeyboard(mContext, R.xml.kbd_phone);
}
mInputView.setPhoneKeyboard(mPhoneKeyboard);
if (mPhoneSymbolsKeyboard == null) {
mPhoneSymbolsKeyboard = new LatinKeyboard(mContext, R.xml.kbd_phone_symbols);
}
keyboard = mPhoneKeyboard;
mInputView.setPreviewEnabled(false);
break;
case MODE_URL:
if (mUrlKeyboard == null) {
mUrlKeyboard = new LatinKeyboard(mContext, R.xml.kbd_qwerty, KEYBOARDMODE_URL);
mUrlKeyboard.enableShiftLock();
}
keyboard = mUrlKeyboard;
break;
case MODE_EMAIL:
if (mEmailKeyboard == null) {
mEmailKeyboard = new LatinKeyboard(mContext, R.xml.kbd_qwerty, KEYBOARDMODE_EMAIL);
mEmailKeyboard.enableShiftLock();
}
keyboard = mEmailKeyboard;
break;
case MODE_IM:
if (mIMKeyboard == null) {
mIMKeyboard = new LatinKeyboard(mContext, R.xml.kbd_qwerty, KEYBOARDMODE_IM);
mIMKeyboard.enableShiftLock();
}
keyboard = mIMKeyboard;
break;
}
mInputView.setKeyboard(keyboard);
keyboard.setShifted(false);
keyboard.setShiftLocked(keyboard.isShiftLocked());
keyboard.setImeOptions(mContext.getResources(), mMode, imeOptions);
| void | setTextMode(int position)
if (position < MODE_TEXT_COUNT && position >= 0) {
mTextMode = position;
}
if (isTextMode()) {
setKeyboardMode(MODE_TEXT, mImeOptions);
}
| void | toggleShift()
Keyboard currentKeyboard = mInputView.getKeyboard();
if (currentKeyboard == mSymbolsKeyboard) {
mSymbolsKeyboard.setShifted(true);
mInputView.setKeyboard(mSymbolsShiftedKeyboard);
mSymbolsShiftedKeyboard.setShifted(true);
mSymbolsShiftedKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions);
} else if (currentKeyboard == mSymbolsShiftedKeyboard) {
mSymbolsShiftedKeyboard.setShifted(false);
mInputView.setKeyboard(mSymbolsKeyboard);
mSymbolsKeyboard.setShifted(false);
mSymbolsKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions);
}
| void | toggleSymbols()
Keyboard current = mInputView.getKeyboard();
if (mSymbolsKeyboard == null) {
mSymbolsKeyboard = new LatinKeyboard(mContext, R.xml.kbd_symbols);
}
if (mSymbolsShiftedKeyboard == null) {
mSymbolsShiftedKeyboard = new LatinKeyboard(mContext, R.xml.kbd_symbols_shift);
}
if (current == mSymbolsKeyboard || current == mSymbolsShiftedKeyboard) {
setKeyboardMode(mMode, mImeOptions); // Could be qwerty, alpha, url, email or im
return;
} else if (current == mPhoneKeyboard) {
current = mPhoneSymbolsKeyboard;
mPhoneSymbolsKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions);
} else if (current == mPhoneSymbolsKeyboard) {
current = mPhoneKeyboard;
mPhoneKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions);
} else {
current = mSymbolsKeyboard;
mSymbolsKeyboard.setImeOptions(mContext.getResources(), mMode, mImeOptions);
}
mInputView.setKeyboard(current);
if (current == mSymbolsKeyboard) {
current.setShifted(false);
}
|
|