am 2fa21f58
: Add input method subtype selector and IME settings dialog
* commit '2fa21f5854e1565deb139e0bf22719fecc5340bc': Add input method subtype selector and IME settings dialog
This commit is contained in:
commit
4eb52e6e08
2 changed files with 62 additions and 20 deletions
|
@ -123,6 +123,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
private AlertDialog mOptionsDialog;
|
private AlertDialog mOptionsDialog;
|
||||||
|
|
||||||
private InputMethodManager mImm;
|
private InputMethodManager mImm;
|
||||||
|
private Resources mResources;
|
||||||
|
private SharedPreferences mPrefs;
|
||||||
|
private String mInputMethodId;
|
||||||
private KeyboardSwitcher mKeyboardSwitcher;
|
private KeyboardSwitcher mKeyboardSwitcher;
|
||||||
private SubtypeSwitcher mSubtypeSwitcher;
|
private SubtypeSwitcher mSubtypeSwitcher;
|
||||||
private VoiceIMEConnector mVoiceConnector;
|
private VoiceIMEConnector mVoiceConnector;
|
||||||
|
@ -132,9 +135,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
private ContactsDictionary mContactsDictionary;
|
private ContactsDictionary mContactsDictionary;
|
||||||
private AutoDictionary mAutoDictionary;
|
private AutoDictionary mAutoDictionary;
|
||||||
|
|
||||||
private Resources mResources;
|
|
||||||
private SharedPreferences mPrefs;
|
|
||||||
|
|
||||||
// These variables are initialized according to the {@link EditorInfo#inputType}.
|
// These variables are initialized according to the {@link EditorInfo#inputType}.
|
||||||
private boolean mAutoSpace;
|
private boolean mAutoSpace;
|
||||||
private boolean mInputTypeNoAutoCorrect;
|
private boolean mInputTypeNoAutoCorrect;
|
||||||
|
@ -156,6 +156,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
private boolean mPopupOn;
|
private boolean mPopupOn;
|
||||||
private boolean mAutoCap;
|
private boolean mAutoCap;
|
||||||
private boolean mQuickFixes;
|
private boolean mQuickFixes;
|
||||||
|
private boolean mConfigEnableShowSubtypeSettings;
|
||||||
private boolean mConfigSwipeDownDismissKeyboardEnabled;
|
private boolean mConfigSwipeDownDismissKeyboardEnabled;
|
||||||
private int mConfigDelayBeforeFadeoutLanguageOnSpacebar;
|
private int mConfigDelayBeforeFadeoutLanguageOnSpacebar;
|
||||||
private int mConfigDurationOfFadeoutLanguageOnSpacebar;
|
private int mConfigDurationOfFadeoutLanguageOnSpacebar;
|
||||||
|
@ -350,6 +351,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
mImm = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
|
mImm = ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE));
|
||||||
|
mInputMethodId = Utils.getInputMethodId(mImm, getApplicationInfo().packageName);
|
||||||
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
|
||||||
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
||||||
|
|
||||||
|
@ -365,6 +367,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
mReCorrectionEnabled = res.getBoolean(R.bool.default_recorrection_enabled);
|
mReCorrectionEnabled = res.getBoolean(R.bool.default_recorrection_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mConfigEnableShowSubtypeSettings = res.getBoolean(
|
||||||
|
R.bool.config_enable_show_subtype_settings);
|
||||||
mConfigSwipeDownDismissKeyboardEnabled = res.getBoolean(
|
mConfigSwipeDownDismissKeyboardEnabled = res.getBoolean(
|
||||||
R.bool.config_swipe_down_dismiss_keyboard_enabled);
|
R.bool.config_swipe_down_dismiss_keyboard_enabled);
|
||||||
mConfigDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger(
|
mConfigDelayBeforeFadeoutLanguageOnSpacebar = res.getInteger(
|
||||||
|
@ -462,6 +466,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
commitTyped(ic);
|
commitTyped(ic);
|
||||||
if (ic != null) ic.finishComposingText(); // For voice input
|
if (ic != null) ic.finishComposingText(); // For voice input
|
||||||
mOrientation = conf.orientation;
|
mOrientation = conf.orientation;
|
||||||
|
if (isShowingOptionDialog())
|
||||||
|
mOptionsDialog.dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
mConfigurationChanging = true;
|
mConfigurationChanging = true;
|
||||||
|
@ -1044,7 +1050,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
|
|
||||||
private void onSettingsKeyPressed() {
|
private void onSettingsKeyPressed() {
|
||||||
if (!isShowingOptionDialog()) {
|
if (!isShowingOptionDialog()) {
|
||||||
if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
|
if (!mConfigEnableShowSubtypeSettings) {
|
||||||
|
showSubtypeSelectorAndSettings();
|
||||||
|
} else if (Utils.hasMultipleEnabledIMEsOrSubtypes(mImm)) {
|
||||||
showOptionsMenu();
|
showOptionsMenu();
|
||||||
} else {
|
} else {
|
||||||
launchSettings();
|
launchSettings();
|
||||||
|
@ -2183,7 +2191,48 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
return mSuggestPuncs.contains(String.valueOf((char)code));
|
return mSuggestPuncs.contains(String.valueOf((char)code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showSubtypeSelectorAndSettings() {
|
||||||
|
showOptionsMenuInternal(new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface di, int position) {
|
||||||
|
di.dismiss();
|
||||||
|
switch (position) {
|
||||||
|
case POS_SETTINGS:
|
||||||
|
launchSettings();
|
||||||
|
break;
|
||||||
|
case POS_METHOD:
|
||||||
|
Intent intent = new Intent(
|
||||||
|
android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
|
||||||
|
| Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
intent.putExtra(android.provider.Settings.EXTRA_INPUT_METHOD_ID,
|
||||||
|
mInputMethodId);
|
||||||
|
startActivity(intent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void showOptionsMenu() {
|
private void showOptionsMenu() {
|
||||||
|
showOptionsMenuInternal(new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface di, int position) {
|
||||||
|
di.dismiss();
|
||||||
|
switch (position) {
|
||||||
|
case POS_SETTINGS:
|
||||||
|
launchSettings();
|
||||||
|
break;
|
||||||
|
case POS_METHOD:
|
||||||
|
mImm.showInputMethodPicker();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showOptionsMenuInternal(DialogInterface.OnClickListener listener) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||||
builder.setCancelable(true);
|
builder.setCancelable(true);
|
||||||
builder.setIcon(R.drawable.ic_dialog_keyboard);
|
builder.setIcon(R.drawable.ic_dialog_keyboard);
|
||||||
|
@ -2191,22 +2240,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
CharSequence itemSettings = getString(R.string.english_ime_settings);
|
CharSequence itemSettings = getString(R.string.english_ime_settings);
|
||||||
CharSequence itemInputMethod = getString(R.string.selectInputMethod);
|
CharSequence itemInputMethod = getString(R.string.selectInputMethod);
|
||||||
builder.setItems(new CharSequence[] {
|
builder.setItems(new CharSequence[] {
|
||||||
itemInputMethod, itemSettings},
|
itemInputMethod, itemSettings}, listener);
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface di, int position) {
|
|
||||||
di.dismiss();
|
|
||||||
switch (position) {
|
|
||||||
case POS_SETTINGS:
|
|
||||||
launchSettings();
|
|
||||||
break;
|
|
||||||
case POS_METHOD:
|
|
||||||
mImm.showInputMethodPicker();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setTitle(mResources.getString(R.string.english_ime_input_options));
|
builder.setTitle(mResources.getString(R.string.english_ime_input_options));
|
||||||
mOptionsDialog = builder.create();
|
mOptionsDialog = builder.create();
|
||||||
Window window = mOptionsDialog.getWindow();
|
Window window = mOptionsDialog.getWindow();
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.os.HandlerThread;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -97,6 +98,13 @@ public class Utils {
|
||||||
|| imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
|
|| imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getInputMethodId(InputMethodManager imm, String packageName) {
|
||||||
|
for (final InputMethodInfo imi : imm.getEnabledInputMethodList()) {
|
||||||
|
if (imi.getPackageName().equals(packageName))
|
||||||
|
return imi.getId();
|
||||||
|
}
|
||||||
|
throw new RuntimeException("Can not find input method id for " + packageName);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions) {
|
public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions) {
|
||||||
// Safety net for auto correction.
|
// Safety net for auto correction.
|
||||||
|
|
Loading…
Reference in a new issue