Load keyboard only when subtype is keyboard mode
Bug: 3224990 Change-Id: I1ae1d86dce923464d4474fc7ce02f2ff22067603
This commit is contained in:
parent
dedb26f639
commit
8d7ecc70a6
3 changed files with 28 additions and 21 deletions
|
@ -296,7 +296,6 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
final SoftReference<LatinKeyboard> ref = mKeyboardCache.get(id);
|
final SoftReference<LatinKeyboard> ref = mKeyboardCache.get(id);
|
||||||
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
|
LatinKeyboard keyboard = (ref == null) ? null : ref.get();
|
||||||
if (keyboard == null) {
|
if (keyboard == null) {
|
||||||
final Resources res = mInputMethodService.getResources();
|
|
||||||
final Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(
|
final Locale savedLocale = mSubtypeSwitcher.changeSystemLocale(
|
||||||
mSubtypeSwitcher.getInputLocale());
|
mSubtypeSwitcher.getInputLocale());
|
||||||
|
|
||||||
|
@ -668,11 +667,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
return mInputView;
|
return mInputView;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadKeyboardView() {
|
public LatinKeyboardView onCreateInputView() {
|
||||||
loadKeyboardViewInternal(mLayoutId, true);
|
createInputViewInternal(mLayoutId, true);
|
||||||
|
return mInputView;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadKeyboardViewInternal(int newLayout, boolean forceReset) {
|
private void createInputViewInternal(int newLayout, boolean forceReset) {
|
||||||
if (mLayoutId != newLayout || mInputView == null || forceReset) {
|
if (mLayoutId != newLayout || mInputView == null || forceReset) {
|
||||||
if (mInputView != null) {
|
if (mInputView != null) {
|
||||||
mInputView.closing();
|
mInputView.closing();
|
||||||
|
@ -701,24 +701,31 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
|
||||||
mInputView.setOnKeyboardActionListener(mInputMethodService);
|
mInputView.setOnKeyboardActionListener(mInputMethodService);
|
||||||
mLayoutId = newLayout;
|
mLayoutId = newLayout;
|
||||||
}
|
}
|
||||||
// TODO: Not to post if this function was called from loadKeyboardView
|
}
|
||||||
|
|
||||||
|
private void postSetInputView() {
|
||||||
mInputMethodService.mHandler.post(new Runnable() {
|
mInputMethodService.mHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (mInputView != null) {
|
if (mInputView != null) {
|
||||||
mInputMethodService.setInputView(mInputView);
|
mInputMethodService.setInputView(mInputView);
|
||||||
}
|
}
|
||||||
mInputMethodService.updateInputViewShown();
|
mInputMethodService.updateInputViewShown();
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
if (PREF_KEYBOARD_LAYOUT.equals(key)) {
|
if (PREF_KEYBOARD_LAYOUT.equals(key)) {
|
||||||
final int layoutId = Integer.valueOf(
|
final int layoutId = Integer.valueOf(
|
||||||
sharedPreferences.getString(key, DEFAULT_LAYOUT_ID));
|
sharedPreferences.getString(key, DEFAULT_LAYOUT_ID));
|
||||||
loadKeyboardViewInternal(layoutId, false);
|
createInputViewInternal(layoutId, false);
|
||||||
|
postSetInputView();
|
||||||
} else if (LatinIMESettings.PREF_SETTINGS_KEY.equals(key)) {
|
} else if (LatinIMESettings.PREF_SETTINGS_KEY.equals(key)) {
|
||||||
mHasSettingsKey = getSettingsKeyMode(sharedPreferences, mInputMethodService);
|
mHasSettingsKey = getSettingsKeyMode(sharedPreferences, mInputMethodService);
|
||||||
loadKeyboardViewInternal(mLayoutId, true);
|
createInputViewInternal(mLayoutId, true);
|
||||||
|
postSetInputView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -464,7 +464,8 @@ public class LatinIME extends InputMethodService
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration conf) {
|
public void onConfigurationChanged(Configuration conf) {
|
||||||
mSubtypeSwitcher.onConfigurationChanged(conf);
|
mSubtypeSwitcher.onConfigurationChanged(conf);
|
||||||
onKeyboardLanguageChanged();
|
if (mSubtypeSwitcher.isKeyboardMode())
|
||||||
|
onKeyboardLanguageChanged();
|
||||||
updateAutoTextEnabled();
|
updateAutoTextEnabled();
|
||||||
|
|
||||||
// If orientation changed while predicting, commit the change
|
// If orientation changed while predicting, commit the change
|
||||||
|
@ -489,8 +490,7 @@ public class LatinIME extends InputMethodService
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateInputView() {
|
public View onCreateInputView() {
|
||||||
mKeyboardSwitcher.loadKeyboardView();
|
return mKeyboardSwitcher.onCreateInputView();
|
||||||
return mKeyboardSwitcher.getInputView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -524,7 +524,7 @@ public class LatinIME extends InputMethodService
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubtypeSwitcher.getInstance().updateParametersOnStartInputView();
|
mSubtypeSwitcher.updateParametersOnStartInputView();
|
||||||
|
|
||||||
if (mRefreshKeyboardRequired) {
|
if (mRefreshKeyboardRequired) {
|
||||||
mRefreshKeyboardRequired = false;
|
mRefreshKeyboardRequired = false;
|
||||||
|
@ -614,9 +614,12 @@ public class LatinIME extends InputMethodService
|
||||||
mJustAddedAutoSpace = false;
|
mJustAddedAutoSpace = false;
|
||||||
|
|
||||||
loadSettings(attribute);
|
loadSettings(attribute);
|
||||||
switcher.loadKeyboard(mode, attribute.imeOptions, mVoiceConnector.isVoiceButtonEnabled(),
|
if (mSubtypeSwitcher.isKeyboardMode()) {
|
||||||
mVoiceConnector.isVoiceButtonOnPrimary());
|
switcher.loadKeyboard(mode, attribute.imeOptions,
|
||||||
switcher.updateShiftState();
|
mVoiceConnector.isVoiceButtonEnabled(),
|
||||||
|
mVoiceConnector.isVoiceButtonOnPrimary());
|
||||||
|
switcher.updateShiftState();
|
||||||
|
}
|
||||||
|
|
||||||
setCandidatesViewShownInternal(isCandidateStripVisible(),
|
setCandidatesViewShownInternal(isCandidateStripVisible(),
|
||||||
false /* needsInputViewShown */ );
|
false /* needsInputViewShown */ );
|
||||||
|
|
|
@ -39,7 +39,7 @@ public class SubtypeSwitcher {
|
||||||
// We may or may not draw the current language on space bar regardless of this flag.
|
// We may or may not draw the current language on space bar regardless of this flag.
|
||||||
public static final boolean USE_SPACEBAR_LANGUAGE_SWITCHER = false;
|
public static final boolean USE_SPACEBAR_LANGUAGE_SWITCHER = false;
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
private static final String TAG = "InputMethodSubtypeSwitcher";
|
private static final String TAG = "SubtypeSwitcher";
|
||||||
|
|
||||||
private static final char LOCALE_SEPARATER = '_';
|
private static final char LOCALE_SEPARATER = '_';
|
||||||
private static final String KEYBOARD_MODE = "keyboard";
|
private static final String KEYBOARD_MODE = "keyboard";
|
||||||
|
@ -153,9 +153,9 @@ public class SubtypeSwitcher {
|
||||||
final String newLocale;
|
final String newLocale;
|
||||||
final String newMode;
|
final String newMode;
|
||||||
if (newSubtype == null) {
|
if (newSubtype == null) {
|
||||||
// Normally, newSubtype shouldn't be null. But just in case if newSubtype was null,
|
// Normally, newSubtype shouldn't be null. But just in case newSubtype was null,
|
||||||
// fallback to the default locale and mode.
|
// fallback to the default locale and mode.
|
||||||
Log.e(TAG, "Couldn't get the current subtype.");
|
Log.w(TAG, "Couldn't get the current subtype.");
|
||||||
newLocale = "en_US";
|
newLocale = "en_US";
|
||||||
newMode =KEYBOARD_MODE;
|
newMode =KEYBOARD_MODE;
|
||||||
} else {
|
} else {
|
||||||
|
@ -345,14 +345,11 @@ public class SubtypeSwitcher {
|
||||||
|
|
||||||
public boolean setVoiceInput(VoiceInput vi) {
|
public boolean setVoiceInput(VoiceInput vi) {
|
||||||
if (mVoiceInput == null && vi != null) {
|
if (mVoiceInput == null && vi != null) {
|
||||||
// TODO: Remove requirements to construct KeyboardSwitcher
|
|
||||||
// when IME was enabled with Voice mode
|
|
||||||
mVoiceInput = vi;
|
mVoiceInput = vi;
|
||||||
if (isVoiceMode()) {
|
if (isVoiceMode()) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "Set and call voice input.");
|
Log.d(TAG, "Set and call voice input.");
|
||||||
}
|
}
|
||||||
mService.onKeyboardLanguageChanged();
|
|
||||||
mService.onKey(LatinKeyboardView.KEYCODE_VOICE, null, 0, 0);
|
mService.onKey(LatinKeyboardView.KEYCODE_VOICE, null, 0, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue