minor bugfix in the translator keyboard

This commit is contained in:
kr.angelov
2013-11-13 10:59:03 +00:00
parent ab1856046f
commit 5f60445d2c

View File

@@ -67,6 +67,7 @@ public class TranslatorInputMethodService extends InputMethodService
} }
private int mModeId; private int mModeId;
private EditorInfo mAttribute;
private static TranslatorInputMethodService mInstance; private static TranslatorInputMethodService mInstance;
static TranslatorInputMethodService getInstance() { static TranslatorInputMethodService getInstance() {
@@ -98,6 +99,7 @@ public class TranslatorInputMethodService extends InputMethodService
!attribute.extras.getBoolean("show_language_toggle", true)) { !attribute.extras.getBoolean("show_language_toggle", true)) {
mModeId = R.string.internalKeyboardMode; mModeId = R.string.internalKeyboardMode;
} }
mAttribute = attribute;
mLanguageKeyboard = new TranslatorKeyboard(this, res, mModeId); mLanguageKeyboard = new TranslatorKeyboard(this, res, mModeId);
mSymbolsKeyboard = new TranslatorKeyboard(this, R.xml.symbols, mModeId); mSymbolsKeyboard = new TranslatorKeyboard(this, R.xml.symbols, mModeId);
mSymbolsShiftedKeyboard = new TranslatorKeyboard(this, R.xml.symbols_shift, mModeId); mSymbolsShiftedKeyboard = new TranslatorKeyboard(this, R.xml.symbols_shift, mModeId);
@@ -169,7 +171,7 @@ public class TranslatorInputMethodService extends InputMethodService
mActionId = attribute.imeOptions & EditorInfo.IME_MASK_ACTION; mActionId = attribute.imeOptions & EditorInfo.IME_MASK_ACTION;
mCurKeyboard.setImeOptions(getResources(), attribute.imeOptions); mCurKeyboard.setImeOptions(getResources(), attribute.imeOptions);
mInstance = this; mInstance = this;
} }
@@ -191,8 +193,9 @@ public class TranslatorInputMethodService extends InputMethodService
if (mInputView != null) { if (mInputView != null) {
mInputView.closing(); mInputView.closing();
} }
mInstance = null; mInstance = null;
mAttribute = null;
} }
@Override @Override
@@ -504,11 +507,10 @@ public class TranslatorInputMethodService extends InputMethodService
} }
void handleChangeSourceLanguage(Language newSource) { void handleChangeSourceLanguage(Language newSource) {
mLanguageKeyboard = updateLanguageKeyboard(newSource);
new TranslatorKeyboard(this, newSource.getKeyboardResource(), mModeId);
mSymbolsKeyboard.updateLanguageKeyLabels(); mSymbolsKeyboard.updateLanguageKeyLabels();
mSymbolsShiftedKeyboard.updateLanguageKeyLabels(); mSymbolsShiftedKeyboard.updateLanguageKeyLabels();
mInputView.setKeyboard(mLanguageKeyboard); mInputView.setKeyboard(mCurKeyboard);
} }
void handleChangeTargetLanguage(Language newTarget) { void handleChangeTargetLanguage(Language newTarget) {
@@ -520,11 +522,22 @@ public class TranslatorInputMethodService extends InputMethodService
void handleSwitchLanguages() { void handleSwitchLanguages() {
Language newSource = mTranslator.getSourceLanguage(); Language newSource = mTranslator.getSourceLanguage();
mLanguageKeyboard = updateLanguageKeyboard(newSource);
new TranslatorKeyboard(this, newSource.getKeyboardResource(), mModeId); mSymbolsKeyboard.updateLanguageKeyLabels();
mInputView.setKeyboard(mLanguageKeyboard); mSymbolsShiftedKeyboard.updateLanguageKeyLabels();
mInputView.setKeyboard(mCurKeyboard);
} }
private void updateLanguageKeyboard(Language language) {
TranslatorKeyboard keyboard =
new TranslatorKeyboard(this, language.getKeyboardResource(), mModeId);
keyboard.setImeOptions(getResources(), mAttribute.imeOptions);
if (mCurKeyboard == mLanguageKeyboard) {
mCurKeyboard = keyboard;
}
mLanguageKeyboard = keyboard;
}
private void checkToggleCapsLock() { private void checkToggleCapsLock() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (mLastShiftTime + 800 > now) { if (mLastShiftTime + 800 > now) {