[packages/apps/Settings] Settings: set language according to SIM

Add a setting in Language settings to enable of disable this function

Issue: GRANITEFLY-745
Change-Id: Ibcdedc20bb629c5757f086fa88cf85cc3dfc5598
This commit is contained in:
Firefly
2015-06-03 16:31:10 +08:00
committed by djw
parent b3d3d0e43d
commit ea5265c077
5 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 Intel Mobile Communications GmbH
Copyright (C) 2007 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.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Auto set language by sim card settings ui -->
<string name="auto_language_title">自动确定语言</string>
<string name="auto_language_summaryOn">根据SIM卡国家码自动确定系统语言</string>
<string name="auto_language_summaryOff">根据SIM卡国家码自动确定系统语言</string>
</resources>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 Intel Mobile Communications GmbH
Copyright (C) 2007 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.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Auto set language by sim card settings ui -->
<string name="auto_language_title">自動確定語言</string>
<string name="auto_language_summaryOn">根據SIM卡國家碼自動確定系統語言</string>
<string name="auto_language_summaryOff">根據SIM卡國家碼自動確定系統語言</string>
</resources>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 Intel Mobile Communications GmbH
Copyright (C) 2007 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.
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Auto set language by sim card settings ui -->
<string name="auto_language_title">Automatic Language</string>
<string name="auto_language_summaryOn">Auto set language according to SIM card country code info</string>
<string name="auto_language_summaryOff">Auto set language according to SIM card country code info</string>
</resources>

View File

@ -19,6 +19,12 @@
android:key="language_keyboard_settings"
android:title="@string/language_keyboard_settings_title">
<CheckBoxPreference
android:key="auto_language"
android:summaryOff="@string/auto_language_summaryOff"
android:summaryOn="@string/auto_language_summaryOn"
android:title="@string/auto_language_title" />
<PreferenceScreen
android:key="phone_language"
android:title="@string/phone_language"

View File

@ -32,6 +32,8 @@ import android.hardware.input.InputManager;
import android.hardware.input.KeyboardLayout;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemProperties;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
@ -79,6 +81,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
InputMethodPreference.OnSavePreferenceListener {
private static final String KEY_SPELL_CHECKERS = "spellcheckers_settings";
private static final String KEY_PHONE_LANGUAGE = "phone_language";
private static final String KEY_AUTO_LANGUAGE = "auto_language";
private static final String KEY_CURRENT_INPUT_METHOD = "current_input_method";
private static final String KEY_INPUT_METHOD_SELECTOR = "input_method_selector";
private static final String KEY_USER_DICTIONARY_SETTINGS = "key_user_dictionary_settings";
@ -87,6 +90,7 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
private static final boolean SHOW_INPUT_METHOD_SWITCHER_SETTINGS = false;
private int mDefaultInputMethodSelectorVisibility = 0;
private CheckBoxPreference mAutoLanguagePref;
private ListPreference mShowInputMethodSelectorPref;
private PreferenceCategory mKeyboardSettingsCategory;
private PreferenceCategory mHardKeyboardCategory;
@ -109,6 +113,14 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
addPreferencesFromResource(R.xml.language_settings);
mAutoLanguagePref = (CheckBoxPreference) findPreference(KEY_AUTO_LANGUAGE);
if (!allowSetLanguageBySim()) {
getPreferenceScreen().removePreference(mAutoLanguagePref);
} else if (mAutoLanguagePref != null) {
mAutoLanguagePref.setChecked(isAutoLanguageBySim());
mAutoLanguagePref.setOnPreferenceChangeListener(this);
}
final Activity activity = getActivity();
mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mInputMethodSettingValues = InputMethodSettingValuesWrapper.getInstance(activity);
@ -257,6 +269,10 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
}
if (!mShowsOnlyFullImeAndKeyboardList) {
if (mAutoLanguagePref != null) {
mAutoLanguagePref.setChecked(isAutoLanguageBySim());
}
if (mLanguagePref != null) {
String localeName = getLocaleName(getActivity());
mLanguagePref.setSummary(localeName);
@ -372,6 +388,12 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
}
}
}
if (preference == mAutoLanguagePref) {
boolean autoEnabled = (Boolean) value;
Settings.Global.putInt(getContentResolver(), Settings.Global.AUTO_LANGUAGE_BY_SIM,
autoEnabled ? 1 : 0);
return true;
}
return false;
}
@ -616,6 +638,20 @@ public class InputMethodAndLanguageSettings extends SettingsPreferenceFragment
return false;
}
private boolean allowSetLanguageBySim() {
if (!SystemProperties.getBoolean("ro.config.set_language_by_sim", false)) {
return false;
}
return true;
}
private boolean isAutoLanguageBySim() {
final boolean autoEnabled = Settings.Global.getInt(getContentResolver(),
Settings.Global.AUTO_LANGUAGE_BY_SIM, 0) > 0;
return autoEnabled;
}
private class SettingsObserver extends ContentObserver {
private Context mContext;