diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 66c9bfd2163..4729785db31 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -457,7 +457,7 @@ + android:targetActivity="Settings"> @@ -470,7 +470,7 @@ + android:targetActivity="Settings"> @@ -480,11 +480,6 @@ - - - - + - - + diff --git a/res/values/strings.xml b/res/values/strings.xml index d51001838c2..2d1a599a4a7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -999,14 +999,6 @@ Advanced - - Regulatory domain - - Set the number of channels to use - - There was a problem setting the regulatory domain. - - %1$d channels Wi-Fi sleep policy diff --git a/res/xml/application_settings.xml b/res/xml/application_settings.xml index 6cd0b620732..76fa0bcd50a 100644 --- a/res/xml/application_settings.xml +++ b/res/xml/application_settings.xml @@ -44,25 +44,24 @@ + android:fragment="com.android.settings.applications.ManageApplications" + android:title="@string/manageapplications_settings_title" + android:summary="@string/manageapplications_settings_summary"> - + - + - - > getEnabledInputMethodsAndSubtypeList( + ContentResolver resolver) { + final String enabledInputMethodsStr = Settings.Secure.getString( + resolver, Settings.Secure.ENABLED_INPUT_METHODS); + HashMap> imsList + = new HashMap>(); + if (DEBUG) { + Log.d(TAG, "--- Load enabled input methods: " + enabledInputMethodsStr); + } + + if (TextUtils.isEmpty(enabledInputMethodsStr)) { + return imsList; + } + sStringInputMethodSplitter.setString(enabledInputMethodsStr); + while (sStringInputMethodSplitter.hasNext()) { + String nextImsStr = sStringInputMethodSplitter.next(); + sStringInputMethodSubtypeSplitter.setString(nextImsStr); + if (sStringInputMethodSubtypeSplitter.hasNext()) { + HashSet subtypeHashes = new HashSet(); + // The first element is ime id. + String imeId = sStringInputMethodSubtypeSplitter.next(); + while (sStringInputMethodSubtypeSplitter.hasNext()) { + subtypeHashes.add(sStringInputMethodSubtypeSplitter.next()); + } + imsList.put(imeId, subtypeHashes); + } + } + return imsList; + } public static void saveInputMethodSubtypeList( SettingsPreferenceFragment context, ContentResolver resolver, List inputMethodProperties, boolean hasHardKeyboard, String lastTickedInputMethodId) { - String lastInputMethodId = Settings.Secure.getString(resolver, + String currentInputMethodId = Settings.Secure.getString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD); StringBuilder builder = new StringBuilder(); StringBuilder disabledSysImes = new StringBuilder(); + InputMethodInfo firstEnabledIMI = null; + int firstSubtypeHashCode = NOT_A_SUBTYPE_ID; - int firstEnabled = -1; - int N = inputMethodProperties.size(); - for (int i = 0; i < N; ++i) { - final InputMethodInfo property = inputMethodProperties.get(i); + final boolean onlyOneIME = inputMethodProperties.size() == 1; + for (InputMethodInfo property : inputMethodProperties) { final String id = property.getId(); CheckBoxPreference pref = (CheckBoxPreference) context.findPreference(id); - boolean currentInputMethod = id.equals(lastInputMethodId); + boolean isCurrentInputMethod = id.equals(currentInputMethodId); boolean systemIme = isSystemIme(property); // TODO: Append subtypes by using the separator ";" - if (((N == 1 || systemIme) && !hasHardKeyboard) + if (((onlyOneIME || systemIme) && !hasHardKeyboard) || (pref != null && pref.isChecked())) { - if (builder.length() > 0) builder.append(':'); + if (builder.length() > 0) builder.append(INPUT_METHOD_SEPARATER); builder.append(id); - if (firstEnabled < 0) { - firstEnabled = i; + if (firstEnabledIMI == null) { + firstEnabledIMI = property; } - } else if (currentInputMethod) { - lastInputMethodId = lastTickedInputMethodId; + for (InputMethodSubtype subtype : property.getSubtypes()) { + CheckBoxPreference subtypePref = (CheckBoxPreference) context.findPreference( + id + subtype.hashCode()); + if (subtypePref != null && subtypePref.isChecked()) { + builder.append(INPUT_METHOD_SUBTYPE_SEPARATER).append(subtype.hashCode()); + if (firstSubtypeHashCode == NOT_A_SUBTYPE_ID) { + firstSubtypeHashCode = subtype.hashCode(); + } + } + } + } else if (isCurrentInputMethod) { + // We are processing the current input method, but found that it's not enabled. + // This means that the current input method has been uninstalled. + // If currentInputMethod is already uninstalled, selects last ticked IME + currentInputMethodId = lastTickedInputMethodId; } // If it's a disabled system ime, add it to the disabled list so that it // doesn't get enabled automatically on any changes to the package list if (pref != null && !pref.isChecked() && systemIme && hasHardKeyboard) { - if (disabledSysImes.length() > 0) disabledSysImes.append(":"); + if (disabledSysImes.length() > 0) disabledSysImes.append(INPUT_METHOD_SEPARATER); disabledSysImes.append(id); } } // If the last input method is unset, set it as the first enabled one. - if (TextUtils.isEmpty(lastInputMethodId)) { - if (firstEnabled >= 0) { - lastInputMethodId = inputMethodProperties.get(firstEnabled).getId(); + if (TextUtils.isEmpty(currentInputMethodId)) { + if (firstEnabledIMI != null) { + currentInputMethodId = firstEnabledIMI.getId(); } else { - lastInputMethodId = null; + currentInputMethodId = null; } } + if (DEBUG) { + Log.d(TAG, "--- Save enabled inputmethod settings. :" + builder.toString()); + Log.d(TAG, "--- Save disable system inputmethod settings. :" + + disabledSysImes.toString()); + Log.d(TAG, "--- Save default inputmethod settings. :" + currentInputMethodId); + } + + // redefines SelectedSubtype when all subtypes are unchecked or there is no subtype + // selected. + if (firstSubtypeHashCode == NOT_A_SUBTYPE_ID || !isInputMethodSubtypeSelected(resolver)) { + if (DEBUG) { + Log.d(TAG, "--- Set inputmethod subtype because it's not defined." + + firstSubtypeHashCode); + } + putSelectedInputMethodSubtype(resolver, firstSubtypeHashCode); + } + Settings.Secure.putString(resolver, Settings.Secure.ENABLED_INPUT_METHODS, builder.toString()); Settings.Secure.putString(resolver, Settings.Secure.DISABLED_SYSTEM_INPUT_METHODS, disabledSysImes.toString()); Settings.Secure.putString(resolver, Settings.Secure.DEFAULT_INPUT_METHOD, - lastInputMethodId != null ? lastInputMethodId : ""); + currentInputMethodId != null ? currentInputMethodId : ""); } public static void loadInputMethodSubtypeList( SettingsPreferenceFragment context, ContentResolver resolver, List inputMethodProperties) { - final HashSet enabled = new HashSet(); - String enabledStr = Settings.Secure.getString(resolver, - Settings.Secure.ENABLED_INPUT_METHODS); - if (enabledStr != null) { - final TextUtils.SimpleStringSplitter splitter = sStringColonSplitter; - splitter.setString(enabledStr); - while (splitter.hasNext()) { - enabled.add(splitter.next()); - } - } + HashMap> enabledSubtypes = + getEnabledInputMethodsAndSubtypeList(resolver); - // Update the statuses of the Check Boxes. - int N = inputMethodProperties.size(); - // TODO: Use iterator. - for (int i = 0; i < N; ++i) { - final String id = inputMethodProperties.get(i).getId(); - CheckBoxPreference pref = (CheckBoxPreference) context.findPreference( - inputMethodProperties.get(i).getId()); + for (InputMethodInfo property : inputMethodProperties) { + final String id = property.getId(); + CheckBoxPreference pref = (CheckBoxPreference) context.findPreference(id); if (pref != null) { - boolean isEnabled = enabled.contains(id); + boolean isEnabled = enabledSubtypes.containsKey(id); pref.setChecked(isEnabled); setSubtypesPreferenceEnabled(context, inputMethodProperties, id, isEnabled); + updateSubtypesPreferenceChecked(context, inputMethodProperties, enabledSubtypes); } } } @@ -121,17 +197,41 @@ public class InputMethodAndSubtypeUtil { public static void setSubtypesPreferenceEnabled(SettingsPreferenceFragment context, List inputMethodProperties, String id, boolean enabled) { PreferenceScreen preferenceScreen = context.getPreferenceScreen(); - final int N = inputMethodProperties.size(); - // TODO: Use iterator. - for (int i = 0; i < N; i++) { - InputMethodInfo imi = inputMethodProperties.get(i); + for (InputMethodInfo imi : inputMethodProperties) { if (id.equals(imi.getId())) { - for (InputMethodSubtype subtype: imi.getSubtypes()) { - preferenceScreen.findPreference(id + subtype.hashCode()).setEnabled(enabled); + for (InputMethodSubtype subtype : imi.getSubtypes()) { + CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen.findPreference( + id + subtype.hashCode()); + if (pref != null) { + pref.setEnabled(enabled); + } } } } } + + public static void updateSubtypesPreferenceChecked(SettingsPreferenceFragment context, + List inputMethodProperties, + HashMap> enabledSubtypes) { + PreferenceScreen preferenceScreen = context.getPreferenceScreen(); + for (InputMethodInfo imi : inputMethodProperties) { + String id = imi.getId(); + HashSet enabledSubtypesSet = enabledSubtypes.get(id); + for (InputMethodSubtype subtype : imi.getSubtypes()) { + String hashCode = String.valueOf(subtype.hashCode()); + if (DEBUG) { + Log.d(TAG, "--- Set checked state: " + "id" + ", " + hashCode + ", " + + enabledSubtypesSet.contains(hashCode)); + } + CheckBoxPreference pref = (CheckBoxPreference) preferenceScreen.findPreference( + id + hashCode); + if (pref != null) { + pref.setChecked(enabledSubtypesSet.contains(hashCode)); + } + } + } + } + public static boolean isSystemIme(InputMethodInfo property) { return (property.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0; diff --git a/src/com/android/settings/wifi/AdvancedSettings.java b/src/com/android/settings/wifi/AdvancedSettings.java index c88073d75db..0d33a10d496 100644 --- a/src/com/android/settings/wifi/AdvancedSettings.java +++ b/src/com/android/settings/wifi/AdvancedSettings.java @@ -35,12 +35,8 @@ public class AdvancedSettings extends SettingsPreferenceFragment private static final String KEY_MAC_ADDRESS = "mac_address"; private static final String KEY_CURRENT_IP_ADDRESS = "current_ip_address"; - private static final String KEY_NUM_CHANNELS = "num_channels"; private static final String KEY_SLEEP_POLICY = "sleep_policy"; - //Tracks ro.debuggable (1 on userdebug builds) - private static int DEBUGGABLE; - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -50,77 +46,16 @@ public class AdvancedSettings extends SettingsPreferenceFragment @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - - DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0); - - /** - * Remove user control of regulatory domain - * channel count settings in non userdebug builds - */ - if (DEBUGGABLE == 1) { - /* - * Fix the Run-time IllegalStateException that ListPreference requires an entries - * array and an entryValues array, this exception occurs when user open/close the - * slider in the Regulatory domain dialog. - */ - initNumChannelsPreference(); - } else { - Preference chanPref = findPreference(KEY_NUM_CHANNELS); - if (chanPref != null) { - getPreferenceScreen().removePreference(chanPref); - } - } } - + @Override public void onResume() { super.onResume(); - /** - * Remove user control of regulatory domain - * channel count settings in non userdebug builds - */ - if (DEBUGGABLE == 1) { - initNumChannelsPreference(); - } initSleepPolicyPreference(); refreshWifiInfo(); } - private void initNumChannelsPreference() { - ListPreference pref = (ListPreference) findPreference(KEY_NUM_CHANNELS); - pref.setOnPreferenceChangeListener(this); - - WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE); - /* - * Generate the list of valid channel counts to show in the ListPreference. - * The values are numerical, so the only text to be localized is the - * "channel_word" resource. - */ - int[] validChannelCounts = wifiManager.getValidChannelCounts(); - if (validChannelCounts == null) { - Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error, - Toast.LENGTH_SHORT).show(); - pref.setEnabled(false); - return; - } - String[] entries = new String[validChannelCounts.length]; - String[] entryValues = new String[validChannelCounts.length]; - - for (int i = 0; i < validChannelCounts.length; i++) { - entryValues[i] = String.valueOf(validChannelCounts[i]); - entries[i] = getActivity().getString(R.string.wifi_setting_num_channels_channel_phrase, - validChannelCounts[i]); - } - pref.setEntries(entries); - pref.setEntryValues(entryValues); - pref.setEnabled(true); - int numChannels = wifiManager.getNumAllowedChannels(); - if (numChannels >= 0) { - pref.setValue(String.valueOf(numChannels)); - } - } - private void initSleepPolicyPreference() { ListPreference pref = (ListPreference) findPreference(KEY_SLEEP_POLICY); pref.setOnPreferenceChangeListener(this); @@ -133,21 +68,7 @@ public class AdvancedSettings extends SettingsPreferenceFragment String key = preference.getKey(); if (key == null) return true; - if (key.equals(KEY_NUM_CHANNELS)) { - try { - int numChannels = Integer.parseInt((String) newValue); - WifiManager wifiManager = (WifiManager) getSystemService(Activity.WIFI_SERVICE); - if (!wifiManager.setNumAllowedChannels(numChannels, true)) { - Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error, - Toast.LENGTH_SHORT).show(); - } - } catch (NumberFormatException e) { - Toast.makeText(getActivity(), R.string.wifi_setting_num_channels_error, - Toast.LENGTH_SHORT).show(); - return false; - } - - } else if (key.equals(KEY_SLEEP_POLICY)) { + if (key.equals(KEY_SLEEP_POLICY)) { try { Settings.System.putInt(getContentResolver(), Settings.System.WIFI_SLEEP_POLICY, Integer.parseInt(((String) newValue))); @@ -157,7 +78,7 @@ public class AdvancedSettings extends SettingsPreferenceFragment return false; } } - + return true; } @@ -167,7 +88,7 @@ public class AdvancedSettings extends SettingsPreferenceFragment Preference wifiMacAddressPref = findPreference(KEY_MAC_ADDRESS); String macAddress = wifiInfo == null ? null : wifiInfo.getMacAddress(); - wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress + wifiMacAddressPref.setSummary(!TextUtils.isEmpty(macAddress) ? macAddress : getActivity().getString(R.string.status_unavailable)); Preference wifiIpAddressPref = findPreference(KEY_CURRENT_IP_ADDRESS);