Merge "Added CompatUtils for starting a language selector"

main
satok 2011-03-17 20:36:42 -07:00 committed by Android (Google) Code Review
commit da4236fb51
3 changed files with 61 additions and 15 deletions

View File

@ -0,0 +1,51 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.inputmethod.compat;
import android.content.Intent;
import android.text.TextUtils;
public class CompatUtils {
private static final String EXTRA_INPUT_METHOD_ID = "input_method_id";
// TODO: Can these be constants instead of literal String constants?
private static final String INPUT_METHOD_SUBTYPE_SETTINGS =
"android.settings.INPUT_METHOD_SUBTYPE_SETTINGS";
private static final String INPUT_LANGUAGE_SELECTION =
"com.android.inputmethod.latin.INPUT_LANGUAGE_SELECTION";
public static Intent getInputLanguageSelectionIntent(String inputMethodId,
int flagsForSubtypeSettings) {
final String action;
Intent intent;
if (android.os.Build.VERSION.SDK_INT
>= /* android.os.Build.VERSION_CODES.HONEYCOMB */ 11) {
// Refer to android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS
action = INPUT_METHOD_SUBTYPE_SETTINGS;
intent = new Intent(action);
if (!TextUtils.isEmpty(inputMethodId)) {
intent.putExtra(EXTRA_INPUT_METHOD_ID, inputMethodId);
}
if (flagsForSubtypeSettings > 0) {
intent.setFlags(flagsForSubtypeSettings);
}
} else {
action = INPUT_LANGUAGE_SELECTION;
intent = new Intent(action);
}
return intent;
}
}

View File

@ -16,6 +16,7 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.deprecated.VoiceConnector; import com.android.inputmethod.deprecated.VoiceConnector;
import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardActionListener; import com.android.inputmethod.keyboard.KeyboardActionListener;
@ -2215,13 +2216,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
di.dismiss(); di.dismiss();
switch (position) { switch (position) {
case 0: case 0:
Intent intent = new Intent( Intent intent = CompatUtils.getInputLanguageSelectionIntent(
android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS); mInputMethodId, Intent.FLAG_ACTIVITY_NEW_TASK
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
| Intent.FLAG_ACTIVITY_CLEAR_TOP); | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(android.provider.Settings.EXTRA_INPUT_METHOD_ID,
mInputMethodId);
startActivity(intent); startActivity(intent);
break; break;
case 1: case 1:

View File

@ -16,11 +16,13 @@
package com.android.inputmethod.latin; package com.android.inputmethod.latin;
import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.deprecated.VoiceConnector; import com.android.inputmethod.deprecated.VoiceConnector;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.backup.BackupManager; import android.app.backup.BackupManager;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -38,6 +40,7 @@ import android.text.AutoText;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.util.Log; import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView; import android.widget.TextView;
import java.util.Locale; import java.util.Locale;
@ -221,16 +224,10 @@ public class Settings extends PreferenceActivity
@Override @Override
public boolean onPreferenceClick(Preference pref) { public boolean onPreferenceClick(Preference pref) {
if (pref == mInputLanguageSelection) { if (pref == mInputLanguageSelection) {
final String action; startActivity(CompatUtils.getInputLanguageSelectionIntent(
if (android.os.Build.VERSION.SDK_INT Utils.getInputMethodId(
>= /* android.os.Build.VERSION_CODES.HONEYCOMB */ 11) { (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE),
// Refer to android.provider.Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS getApplicationInfo().packageName), 0));
// TODO: Can this be a constant instead of literal String constant?
action = "android.settings.INPUT_METHOD_SUBTYPE_SETTINGS";
} else {
action = "com.android.inputmethod.latin.INPUT_LANGUAGE_SELECTION";
}
startActivity(new Intent(action));
return true; return true;
} }
return false; return false;