diff options
Diffstat (limited to 'src')
33 files changed, 447 insertions, 264 deletions
diff --git a/src/com/android/settings/AppWidgetLoader.java b/src/com/android/settings/AppWidgetLoader.java index 9155e60..985ef8b 100644 --- a/src/com/android/settings/AppWidgetLoader.java +++ b/src/com/android/settings/AppWidgetLoader.java @@ -176,7 +176,8 @@ public class AppWidgetLoader<Item extends AppWidgetLoader.LabelledItem> { * Create list entries for installed {@link AppWidgetProviderInfo} widgets. */ void putInstalledAppWidgets(List<Item> items, int categoryFilter) { - List<AppWidgetProviderInfo> installed = mAppWidgetManager.getInstalledProviders(); + List<AppWidgetProviderInfo> installed = + mAppWidgetManager.getInstalledProviders(categoryFilter); putAppWidgetItems(installed, null, items, categoryFilter, false); } } diff --git a/src/com/android/settings/ChooseLockGeneric.java b/src/com/android/settings/ChooseLockGeneric.java index f191079..f67213c 100644 --- a/src/com/android/settings/ChooseLockGeneric.java +++ b/src/com/android/settings/ChooseLockGeneric.java @@ -383,9 +383,7 @@ public class ChooseLockGeneric extends PreferenceActivity { startActivity(intent); } } else if (quality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) { - boolean showTutorial = !mChooseLockSettingsHelper.utils().isPatternEverChosen(); - Intent intent = new Intent(); - intent.setClass(getActivity(), ChooseLockPatternSize.class); + Intent intent = new Intent(getActivity(), ChooseLockPatternSize.class); intent.putExtra("key_lock_method", "pattern"); intent.putExtra(CONFIRM_CREDENTIALS, false); intent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, diff --git a/src/com/android/settings/ChooseLockPatternSize.java b/src/com/android/settings/ChooseLockPatternSize.java index f6f25c2..cc5834b 100644 --- a/src/com/android/settings/ChooseLockPatternSize.java +++ b/src/com/android/settings/ChooseLockPatternSize.java @@ -62,12 +62,8 @@ public class ChooseLockPatternSize extends PreferenceActivity { final boolean isFallback = getActivity().getIntent() .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false); - boolean showTutorial = !mChooseLockSettingsHelper.utils().isPatternEverChosen(); - Intent intent = new Intent(); - intent.setClass(getActivity(), showTutorial - ? ChooseLockPatternTutorial.class - : ChooseLockPattern.class); + Intent intent = new Intent(getActivity(), ChooseLockPatternSize.class); intent.putExtra("pattern_size", patternSize); intent.putExtra("key_lock_method", "pattern"); intent.putExtra("confirm_credentials", false); diff --git a/src/com/android/settings/ChooseLockPatternTutorial.java b/src/com/android/settings/ChooseLockPatternTutorial.java deleted file mode 100644 index 66e40c1..0000000 --- a/src/com/android/settings/ChooseLockPatternTutorial.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2008 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.settings; - -import java.util.ArrayList; - -import com.android.internal.widget.LockPatternUtils; -import com.android.internal.widget.LockPatternView; - -import android.app.Fragment; -import android.content.Intent; -import android.os.Bundle; -import android.preference.PreferenceActivity; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -public class ChooseLockPatternTutorial extends PreferenceActivity { - - // required constructor for fragments - public ChooseLockPatternTutorial() { - - } - - @Override - public Intent getIntent() { - Intent modIntent = new Intent(super.getIntent()); - modIntent.putExtra(EXTRA_SHOW_FRAGMENT, ChooseLockPatternTutorialFragment.class.getName()); - modIntent.putExtra(EXTRA_NO_HEADERS, true); - return modIntent; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - CharSequence msg = getText(R.string.lockpassword_choose_your_pattern_header); - showBreadCrumbs(msg, msg); - } - - public static class ChooseLockPatternTutorialFragment extends Fragment - implements View.OnClickListener { - private View mNextButton; - private View mSkipButton; - private LockPatternView mPatternView; - - private byte mPatternSize = LockPatternUtils.PATTERN_SIZE_DEFAULT; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - // Don't show the tutorial if the user has seen it before. - LockPatternUtils lockPatternUtils = new LockPatternUtils(getActivity()); - if (savedInstanceState == null && lockPatternUtils.isPatternEverChosen()) { - mPatternSize = getActivity().getIntent().getByteExtra("pattern_size", LockPatternUtils.PATTERN_SIZE_DEFAULT); - Intent intent = new Intent(getActivity(), ChooseLockPattern.class); - intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); - intent.putExtra("confirm_credentials", false); - final boolean isFallback = getActivity().getIntent() - .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false); - intent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, - isFallback); - intent.putExtra("pattern_size", mPatternSize); - startActivity(intent); - getActivity().finish(); - } - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.choose_lock_pattern_tutorial, null); - mNextButton = view.findViewById(R.id.next_button); - mNextButton.setOnClickListener(this); - mSkipButton = view.findViewById(R.id.skip_button); - mSkipButton.setOnClickListener(this); - - mPatternSize = getActivity().getIntent().getByteExtra("pattern_size", LockPatternUtils.PATTERN_SIZE_DEFAULT); - - // Set up LockPatternView to be a non-interactive demo animation - LockPatternView.Cell.updateSize(mPatternSize); - ArrayList<LockPatternView.Cell> demoPattern = new ArrayList<LockPatternView.Cell>(); - demoPattern.add(LockPatternView.Cell.of(0,0, mPatternSize)); - demoPattern.add(LockPatternView.Cell.of(0,1, mPatternSize)); - demoPattern.add(LockPatternView.Cell.of(1,1, mPatternSize)); - demoPattern.add(LockPatternView.Cell.of(2,1, mPatternSize)); - mPatternView = (LockPatternView) view.findViewById(R.id.lockPattern); - mPatternView.setLockPatternSize(mPatternSize); - mPatternView.setPattern(LockPatternView.DisplayMode.Animate, demoPattern); - mPatternView.disableInput(); - - return view; - } - - public void onClick(View v) { - if (v == mSkipButton) { - // Canceling, so finish all - getActivity().setResult(ChooseLockPattern.RESULT_FINISHED); - getActivity().finish(); - } else if (v == mNextButton) { - final boolean isFallback = getActivity().getIntent() - .getBooleanExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, false); - Intent intent = new Intent(getActivity(), ChooseLockPattern.class); - intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); - intent.putExtra(LockPatternUtils.LOCKSCREEN_BIOMETRIC_WEAK_FALLBACK, - isFallback); - intent.putExtra("pattern_size", mPatternSize); - startActivity(intent); - getActivity().overridePendingTransition(0, 0); // no animation - getActivity().finish(); - } - } - } -} diff --git a/src/com/android/settings/CryptKeeper.java b/src/com/android/settings/CryptKeeper.java index f07d6fa..94c793d 100644 --- a/src/com/android/settings/CryptKeeper.java +++ b/src/com/android/settings/CryptKeeper.java @@ -55,6 +55,7 @@ import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; +import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.telephony.ITelephony; import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; @@ -229,6 +230,16 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList }; private AudioManager mAudioManager; + /** The status bar where back/home/recent buttons are shown. */ + private StatusBarManager mStatusBar; + + /** All the widgets to disable in the status bar */ + final private static int sWidgetsToDisable = StatusBarManager.DISABLE_EXPAND + | StatusBarManager.DISABLE_NOTIFICATION_ICONS + | StatusBarManager.DISABLE_NOTIFICATION_ALERTS + | StatusBarManager.DISABLE_SYSTEM_INFO + | StatusBarManager.DISABLE_HOME + | StatusBarManager.DISABLE_RECENT; /** @return whether or not this Activity was started for debugging the UI only. */ private boolean isDebugView() { @@ -269,6 +280,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList */ @Override public void onBackPressed() { + // In the rare case that something pressed back even though we were disabled. if (mIgnoreBack) return; super.onBackPressed(); @@ -299,13 +311,8 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // Disable the status bar, but do NOT disable back because the user needs a way to go // from keyboard settings and back to the password screen. - StatusBarManager sbm = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); - sbm.disable(StatusBarManager.DISABLE_EXPAND - | StatusBarManager.DISABLE_NOTIFICATION_ICONS - | StatusBarManager.DISABLE_NOTIFICATION_ALERTS - | StatusBarManager.DISABLE_SYSTEM_INFO - | StatusBarManager.DISABLE_HOME - | StatusBarManager.DISABLE_RECENT); + mStatusBar = (StatusBarManager) getSystemService(Context.STATUS_BAR_SERVICE); + mStatusBar.disable(sWidgetsToDisable); setAirplaneModeIfNecessary(); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); @@ -403,7 +410,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList ((ProgressBar) findViewById(R.id.progress_bar)).setIndeterminate(true); // Ignore all back presses from now, both hard and soft keys. - mIgnoreBack = true; + setBackFunctionality(false); // Start the first run of progress manually. This method sets up messages to occur at // repeated intervals. updateProgress(); @@ -469,7 +476,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList if (mCooldown <= 0) { // Re-enable the password entry and back presses. mPasswordEntry.setEnabled(true); - mIgnoreBack = false; + setBackFunctionality(true); status.setText(R.string.enter_password); } else { CharSequence template = getText(R.string.crypt_keeper_cooldown); @@ -481,6 +488,19 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList } } + /** + * Sets the back status: enabled or disabled according to the parameter. + * @param isEnabled true if back is enabled, false otherwise. + */ + private final void setBackFunctionality(boolean isEnabled) { + mIgnoreBack = !isEnabled; + if (isEnabled) { + mStatusBar.disable(sWidgetsToDisable); + } else { + mStatusBar.disable(sWidgetsToDisable | StatusBarManager.DISABLE_BACK); + } + } + private void passwordEntryInit() { mPasswordEntry = (EditText) findViewById(R.id.passwordEntry); mPasswordEntry.setOnEditorActionListener(this); @@ -610,7 +630,7 @@ public class CryptKeeper extends Activity implements TextView.OnEditorActionList // Disable the password entry and back keypress while checking the password. These // we either be re-enabled if the password was wrong or after the cooldown period. mPasswordEntry.setEnabled(false); - mIgnoreBack = true; + setBackFunctionality(false); Log.d(TAG, "Attempting to send command to decrypt"); new DecryptTask().execute(password); diff --git a/src/com/android/settings/DataUsageSummary.java b/src/com/android/settings/DataUsageSummary.java index 0a03a31..0f76179 100644 --- a/src/com/android/settings/DataUsageSummary.java +++ b/src/com/android/settings/DataUsageSummary.java @@ -492,11 +492,7 @@ public class DataUsageSummary extends Fragment { final MenuItem help = menu.findItem(R.id.data_usage_menu_help); String helpUrl; if (!TextUtils.isEmpty(helpUrl = getResources().getString(R.string.help_url_data_usage))) { - Intent helpIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl)); - helpIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); - help.setIntent(helpIntent); - help.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); + HelpUtils.prepareHelpMenuItem(context, help, helpUrl); } else { help.setVisible(false); } diff --git a/src/com/android/settings/DateTimeSettings.java b/src/com/android/settings/DateTimeSettings.java index 53f25a2..65a34f4 100644 --- a/src/com/android/settings/DateTimeSettings.java +++ b/src/com/android/settings/DateTimeSettings.java @@ -17,6 +17,7 @@ package com.android.settings; import android.app.Activity; +import android.app.AlarmManager; import android.app.DatePickerDialog; import android.app.Dialog; import android.app.TimePickerDialog; @@ -184,18 +185,18 @@ public class DateTimeSettings extends SettingsPreferenceFragment @Override public void onDateSet(DatePicker view, int year, int month, int day) { - setDate(year, month, day); final Activity activity = getActivity(); if (activity != null) { + setDate(activity, year, month, day); updateTimeAndDateDisplay(activity); } } @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { - setTime(hourOfDay, minute); final Activity activity = getActivity(); if (activity != null) { + setTime(activity, hourOfDay, minute); updateTimeAndDateDisplay(activity); } @@ -337,7 +338,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment } } - /* package */ static void setDate(int year, int month, int day) { + /* package */ static void setDate(Context context, int year, int month, int day) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, year); @@ -346,11 +347,11 @@ public class DateTimeSettings extends SettingsPreferenceFragment long when = c.getTimeInMillis(); if (when / 1000 < Integer.MAX_VALUE) { - SystemClock.setCurrentTimeMillis(when); + ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).setTime(when); } } - /* package */ static void setTime(int hourOfDay, int minute) { + /* package */ static void setTime(Context context, int hourOfDay, int minute) { Calendar c = Calendar.getInstance(); c.set(Calendar.HOUR_OF_DAY, hourOfDay); @@ -360,7 +361,7 @@ public class DateTimeSettings extends SettingsPreferenceFragment long when = c.getTimeInMillis(); if (when / 1000 < Integer.MAX_VALUE) { - SystemClock.setCurrentTimeMillis(when); + ((AlarmManager) context.getSystemService(Context.ALARM_SERVICE)).setTime(when); } } diff --git a/src/com/android/settings/DateTimeSettingsSetupWizard.java b/src/com/android/settings/DateTimeSettingsSetupWizard.java index 87b1cae..05e0d4e 100644 --- a/src/com/android/settings/DateTimeSettingsSetupWizard.java +++ b/src/com/android/settings/DateTimeSettingsSetupWizard.java @@ -188,9 +188,9 @@ public class DateTimeSettingsSetupWizard extends Activity Settings.Global.putInt(getContentResolver(), Settings.Global.AUTO_TIME, mAutoDateTimeButton.isChecked() ? 1 : 0); if (!mAutoDateTimeButton.isChecked()) { - DateTimeSettings.setDate(mDatePicker.getYear(), mDatePicker.getMonth(), + DateTimeSettings.setDate(this, mDatePicker.getYear(), mDatePicker.getMonth(), mDatePicker.getDayOfMonth()); - DateTimeSettings.setTime( + DateTimeSettings.setTime(this, mTimePicker.getCurrentHour(), mTimePicker.getCurrentMinute()); } } diff --git a/src/com/android/settings/DevelopmentSettings.java b/src/com/android/settings/DevelopmentSettings.java index fd0e62f..5ebc287 100644 --- a/src/com/android/settings/DevelopmentSettings.java +++ b/src/com/android/settings/DevelopmentSettings.java @@ -50,6 +50,7 @@ import android.os.ServiceManager; import android.os.StrictMode; import android.os.SystemProperties; import android.os.Trace; +import android.os.UserHandle; import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.MultiCheckPreference; @@ -238,6 +239,11 @@ public class DevelopmentSettings extends PreferenceFragment mPassword = (PreferenceScreen) findPreference(LOCAL_BACKUP_PASSWORD); mAllPrefs.add(mPassword); + if (!android.os.Process.myUserHandle().equals(UserHandle.OWNER)) { + disableForUser(mEnableAdb); + disableForUser(mPassword); + } + mDebugAppPref = findPreference(DEBUG_APP_KEY); mAllPrefs.add(mDebugAppPref); mWaitForDebugger = findAndInitCheckboxPref(WAIT_FOR_DEBUGGER_KEY); @@ -320,6 +326,13 @@ public class DevelopmentSettings extends PreferenceFragment mAllPrefs.add(mDevelopmentTools); } + private void disableForUser(Preference pref) { + if (pref != null) { + pref.setEnabled(false); + mDisabledPrefs.add(pref); + } + } + private CheckBoxPreference findAndInitCheckboxPref(String key) { CheckBoxPreference pref = (CheckBoxPreference) findPreference(key); if (pref == null) { diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java index 4bf6ce9..c3683f0 100644 --- a/src/com/android/settings/DeviceInfoSettings.java +++ b/src/com/android/settings/DeviceInfoSettings.java @@ -225,8 +225,8 @@ public class DeviceInfoSettings extends SettingsPreferenceFragment { if (mDevHitToast != null) { mDevHitToast.cancel(); } - mDevHitToast = Toast.makeText(getActivity(), getResources().getString( - R.string.show_dev_countdown, mDevHitCountdown), + mDevHitToast = Toast.makeText(getActivity(), getResources().getQuantityString( + R.plurals.show_dev_countdown, mDevHitCountdown, mDevHitCountdown), Toast.LENGTH_SHORT); mDevHitToast.show(); } diff --git a/src/com/android/settings/HelpUtils.java b/src/com/android/settings/HelpUtils.java new file mode 100644 index 0000000..6cd5eb6 --- /dev/null +++ b/src/com/android/settings/HelpUtils.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2012 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.settings; + +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager.NameNotFoundException; +import android.net.Uri; +import android.text.TextUtils; +import android.util.Log; +import android.view.MenuItem; + +import java.util.Locale; + +/** + * Functions to easily prepare contextual help menu option items with an intent that opens up the + * browser to a particular URL, while taking into account the preferred language and app version. + */ +public class HelpUtils { + private final static String TAG = HelpUtils.class.getName(); + + /** + * Help URL query parameter key for the preferred language. + */ + private final static String PARAM_LANGUAGE_CODE = "hl"; + + /** + * Help URL query parameter key for the app version. + */ + private final static String PARAM_VERSION = "version"; + + /** + * Cached version code to prevent repeated calls to the package manager. + */ + private static String sCachedVersionCode = null; + + /** Static helper that is not instantiable*/ + private HelpUtils() { } + + /** + * Prepares the help menu item by doing the following. + * - If the string corresponding to the helpUrlResourceId is empty or null, then the help menu + * item is made invisible. + * - Otherwise, this makes the help menu item visible and sets the intent for the help menu + * item to view the URL. + * + * @return returns whether the help menu item has been made visible. + */ + public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem, + int helpUrlResourceId) { + String helpUrlString = context.getResources().getString(helpUrlResourceId); + return prepareHelpMenuItem(context, helpMenuItem, helpUrlString); + } + + /** + * Prepares the help menu item by doing the following. + * - If the helpUrlString is empty or null, the help menu item is made invisible. + * - Otherwise, this makes the help menu item visible and sets the intent for the help menu + * item to view the URL. + * + * @return returns whether the help menu item has been made visible. + */ + public static boolean prepareHelpMenuItem(Context context, MenuItem helpMenuItem, + String helpUrlString) { + if (TextUtils.isEmpty(helpUrlString)) { + // The help url string is empty or null, so set the help menu item to be invisible. + helpMenuItem.setVisible(false); + + // return that the help menu item is not visible (i.e. false) + return false; + } else { + // The help url string exists, so first add in some extra query parameters. + final Uri fullUri = uriWithAddedParameters(context, Uri.parse(helpUrlString)); + + // Then, create an intent that will be fired when the user + // selects this help menu item. + Intent intent = new Intent(Intent.ACTION_VIEW, fullUri); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK + | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + + // Set the intent to the help menu item, show the help menu item in the overflow + // menu, and make it visible. + helpMenuItem.setIntent(intent); + helpMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); + helpMenuItem.setVisible(true); + + // return that the help menu item is visible (i.e., true) + return true; + } + } + + /** + * Adds two query parameters into the Uri, namely the language code and the version code + * of the app's package as gotten via the context. + * @return the uri with added query parameters + */ + private static Uri uriWithAddedParameters(Context context, Uri baseUri) { + Uri.Builder builder = baseUri.buildUpon(); + + // Add in the preferred language + builder.appendQueryParameter(PARAM_LANGUAGE_CODE, Locale.getDefault().toString()); + + // Add in the package version code + if (sCachedVersionCode == null) { + // There is no cached version code, so try to get it from the package manager. + try { + // cache the version code + PackageInfo info = context.getPackageManager().getPackageInfo( + context.getPackageName(), 0); + sCachedVersionCode = Integer.toString(info.versionCode); + + // append the version code to the uri + builder.appendQueryParameter(PARAM_VERSION, sCachedVersionCode); + } catch (NameNotFoundException e) { + // Cannot find the package name, so don't add in the version parameter + // This shouldn't happen. + Log.wtf(TAG, "Invalid package name for context", e); + } + } else { + builder.appendQueryParameter(PARAM_VERSION, sCachedVersionCode); + } + + // Build the full uri and return it + return builder.build(); + } +} diff --git a/src/com/android/settings/LocalePicker.java b/src/com/android/settings/LocalePicker.java index 9bfa07e..8ea99a1 100644 --- a/src/com/android/settings/LocalePicker.java +++ b/src/com/android/settings/LocalePicker.java @@ -19,6 +19,10 @@ package com.android.settings; import android.app.Dialog; import android.os.Bundle; import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ListView; import com.android.settings.SettingsPreferenceFragment.SettingsDialogFragment; @@ -50,6 +54,15 @@ public class LocalePicker extends com.android.internal.app.LocalePicker } @Override + public View onCreateView( + LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = super.onCreateView(inflater, container, savedInstanceState); + final ListView list = (ListView) view.findViewById(android.R.id.list); + Utils.forcePrepareCustomPreferencesList(container, view, list, false); + return view; + } + + @Override public void onLocaleSelected(final Locale locale) { if (Utils.hasMultipleUsers(getActivity())) { mTargetLocale = locale; diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java index 80f8468..935097d 100644 --- a/src/com/android/settings/Settings.java +++ b/src/com/android/settings/Settings.java @@ -399,7 +399,11 @@ public class Settings extends PreferenceActivity VpnSettings.class.getName().equals(fragmentName) || SecuritySettings.class.getName().equals(fragmentName) || InstalledAppDetails.class.getName().equals(fragmentName) || - ChooseLockGenericFragment.class.getName().equals(fragmentName)) { + ChooseLockGenericFragment.class.getName().equals(fragmentName) || + TetherSettings.class.getName().equals(fragmentName) || + ApnSettings.class.getName().equals(fragmentName) || + LocationSettings.class.getName().equals(fragmentName) || + ZonePicker.class.getName().equals(fragmentName)) { intent.putExtra(EXTRA_CLEAR_UI_OPTIONS, true); } @@ -872,4 +876,5 @@ public class Settings extends PreferenceActivity public static class ApnEditorActivity extends Settings { /* empty */ } public static class ProfilesSettingsActivity extends Settings { /* empty */ } public static class QuietHoursSettingsActivity extends Settings { /* empty */ } + public static class DreamSettingsActivity extends Settings { /* empty */ } } diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java index c0440c8..b418826 100644 --- a/src/com/android/settings/SettingsPreferenceFragment.java +++ b/src/com/android/settings/SettingsPreferenceFragment.java @@ -84,13 +84,9 @@ public class SettingsPreferenceFragment extends PreferenceFragment implements Di @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { - if (mHelpUrl != null) { - Intent helpIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(mHelpUrl)); - helpIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); + if (mHelpUrl != null && getActivity() != null) { MenuItem helpItem = menu.add(0, MENU_HELP, 0, R.string.help_label); - helpItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); - helpItem.setIntent(helpIntent); + HelpUtils.prepareHelpMenuItem(getActivity(), helpItem, mHelpUrl); } } diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index dcd37d1..3bc244c 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -312,7 +312,7 @@ public class Utils { } // Did not find a matching activity, so remove the preference - if (target.remove(header)) System.err.println("Removed " + header.id); + target.remove(header); return false; } @@ -436,13 +436,20 @@ public class Utils { return statusString; } + public static void forcePrepareCustomPreferencesList( + ViewGroup parent, View child, ListView list, boolean ignoreSidePadding) { + list.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); + list.setClipToPadding(false); + prepareCustomPreferencesList(parent, child, list, ignoreSidePadding); + } + /** * Prepare a custom preferences layout, moving padding to {@link ListView} * when outside scrollbars are requested. Usually used to display * {@link ListView} and {@link TabWidget} with correct padding. */ public static void prepareCustomPreferencesList( - ViewGroup parent, View child, ListView list, boolean ignoreSidePadding) { + ViewGroup parent, View child, View list, boolean ignoreSidePadding) { final boolean movePadding = list.getScrollBarStyle() == View.SCROLLBARS_OUTSIDE_OVERLAY; if (movePadding && parent instanceof PreferenceFrameLayout) { ((PreferenceFrameLayout.LayoutParams) child.getLayoutParams()).removeBorders = true; diff --git a/src/com/android/settings/ZonePicker.java b/src/com/android/settings/ZonePicker.java index 652f3b7..1502ad1 100644 --- a/src/com/android/settings/ZonePicker.java +++ b/src/com/android/settings/ZonePicker.java @@ -23,10 +23,12 @@ import android.content.Context; import android.content.res.XmlResourceParser; import android.os.Bundle; import android.util.Log; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import android.widget.ListView; import android.widget.SimpleAdapter; @@ -81,7 +83,7 @@ public class ZonePicker extends ListFragment { public static SimpleAdapter constructTimezoneAdapter(Context context, boolean sortedByName) { return constructTimezoneAdapter(context, sortedByName, - android.R.layout.simple_list_item_2); + R.layout.date_time_setup_custom_list_item_2); } /** @@ -155,6 +157,15 @@ public class ZonePicker extends ListFragment { } @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + final View view = super.onCreateView(inflater, container, savedInstanceState); + final ListView list = (ListView) view.findViewById(android.R.id.list); + Utils.forcePrepareCustomPreferencesList(container, view, list, false); + return view; + } + + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.add(0, MENU_ALPHABETICAL, 0, R.string.zone_list_menu_sort_alphabetically) .setIcon(android.R.drawable.ic_menu_sort_alphabetically); diff --git a/src/com/android/settings/accounts/AccountSyncSettings.java b/src/com/android/settings/accounts/AccountSyncSettings.java index 196908e..c346017 100644 --- a/src/com/android/settings/accounts/AccountSyncSettings.java +++ b/src/com/android/settings/accounts/AccountSyncSettings.java @@ -47,9 +47,11 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.ListView; import android.widget.TextView; import com.android.settings.R; +import com.android.settings.Utils; import com.google.android.collect.Lists; import com.google.android.collect.Maps; @@ -149,7 +151,10 @@ public class AccountSyncSettings extends AccountPreferenceBase { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.account_sync_screen, container, false); - + + final ListView list = (ListView) view.findViewById(android.R.id.list); + Utils.prepareCustomPreferencesList(container, view, list, false); + initializeUi(view); return view; diff --git a/src/com/android/settings/accounts/ManageAccountsSettings.java b/src/com/android/settings/accounts/ManageAccountsSettings.java index a27fbbd..46aa566 100644 --- a/src/com/android/settings/accounts/ManageAccountsSettings.java +++ b/src/com/android/settings/accounts/ManageAccountsSettings.java @@ -46,12 +46,14 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; +import android.widget.ListView; import android.widget.Switch; import android.widget.TextView; import com.android.settings.AccountPreference; import com.android.settings.R; import com.android.settings.Settings; +import com.android.settings.Utils; import java.util.ArrayList; import java.util.Date; @@ -101,6 +103,8 @@ public class ManageAccountsSettings extends AccountPreferenceBase public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.manage_accounts_screen, container, false); + final ListView list = (ListView) view.findViewById(android.R.id.list); + Utils.prepareCustomPreferencesList(container, view, list, false); return view; } diff --git a/src/com/android/settings/applications/InstalledAppDetails.java b/src/com/android/settings/applications/InstalledAppDetails.java index 7241fdc..75c9485 100644 --- a/src/com/android/settings/applications/InstalledAppDetails.java +++ b/src/com/android/settings/applications/InstalledAppDetails.java @@ -424,9 +424,12 @@ public class InstalledAppDetails extends Fragment } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = mRootView = inflater.inflate(R.layout.installed_app_details, null); - + public View onCreateView( + LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.installed_app_details, container, false); + Utils.prepareCustomPreferencesList(container, view, view, false); + + mRootView = view; mComputingStr = getActivity().getText(R.string.computing_size); // Set default values on sizes @@ -536,7 +539,9 @@ public class InstalledAppDetails extends Fragment // Utility method to set applicaiton label and icon. private void setAppLabelAndIcon(PackageInfo pkgInfo) { - View appSnippet = mRootView.findViewById(R.id.app_snippet); + final View appSnippet = mRootView.findViewById(R.id.app_snippet); + appSnippet.setPadding(0, appSnippet.getPaddingTop(), 0, appSnippet.getPaddingBottom()); + ImageView icon = (ImageView) appSnippet.findViewById(R.id.app_icon); mState.ensureIcon(mAppEntry); icon.setImageDrawable(mAppEntry.icon); diff --git a/src/com/android/settings/applications/ManageApplications.java b/src/com/android/settings/applications/ManageApplications.java index 95222c3..64b9269 100644 --- a/src/com/android/settings/applications/ManageApplications.java +++ b/src/com/android/settings/applications/ManageApplications.java @@ -768,9 +768,6 @@ public class ManageApplications extends Fragment implements holder.entry = entry; if (entry.label != null) { holder.appName.setText(entry.label); - holder.appName.setTextColor(mContext.getResources().getColorStateList( - entry.info.enabled ? android.R.color.primary_text_dark - : android.R.color.secondary_text_dark)); } mState.ensureIcon(entry); if (entry.icon != null) { diff --git a/src/com/android/settings/applications/RunningServiceDetails.java b/src/com/android/settings/applications/RunningServiceDetails.java index 02fbecc..73547f1 100644 --- a/src/com/android/settings/applications/RunningServiceDetails.java +++ b/src/com/android/settings/applications/RunningServiceDetails.java @@ -1,7 +1,5 @@ package com.android.settings.applications; -import com.android.settings.R; - import android.app.Activity; import android.app.ActivityManager; import android.app.AlertDialog; @@ -18,9 +16,9 @@ import android.content.Intent; import android.content.IntentSender; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ProviderInfo; import android.content.pm.ServiceInfo; -import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.os.Bundle; import android.os.Debug; @@ -35,6 +33,9 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; +import com.android.settings.R; +import com.android.settings.Utils; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -507,12 +508,14 @@ public class RunningServiceDetails extends Fragment } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = mRootView = inflater.inflate(R.layout.running_service_details, null); - + public View onCreateView( + LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.running_service_details, container, false); + Utils.prepareCustomPreferencesList(container, view, view, false); + + mRootView = view; mAllDetails = (ViewGroup)view.findViewById(R.id.all_details); mSnippet = (ViewGroup)view.findViewById(R.id.snippet); - mSnippet.setPadding(0, mSnippet.getPaddingTop(), 0, mSnippet.getPaddingBottom()); mSnippetViewHolder = new RunningProcessesView.ViewHolder(mSnippet); // We want to retrieve the data right now, so any active managed diff --git a/src/com/android/settings/bluetooth/DockService.java b/src/com/android/settings/bluetooth/DockService.java index ab0e7c7..c9a18a3 100644 --- a/src/com/android/settings/bluetooth/DockService.java +++ b/src/com/android/settings/bluetooth/DockService.java @@ -120,6 +120,8 @@ public final class DockService extends Service implements ServiceListener { private int mPendingTurnOnStartId = INVALID_STARTID; private int mPendingTurnOffStartId = INVALID_STARTID; + private CheckBox mAudioMediaCheckbox; + @Override public void onCreate() { if (DEBUG) Log.d(TAG, "onCreate"); @@ -499,6 +501,8 @@ public final class DockService extends Service implements ServiceListener { View view; LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); + mAudioMediaCheckbox = null; + if (device != null) { // Device in a new dock. boolean firstTime = @@ -528,14 +532,14 @@ public final class DockService extends Service implements ServiceListener { ab.setTitle(getString(R.string.bluetooth_dock_settings_title)); view = inflater.inflate(R.layout.dock_audio_media_enable_dialog, null); - CheckBox audioMediaCheckbox = + mAudioMediaCheckbox = (CheckBox) view.findViewById(R.id.dock_audio_media_enable_cb); boolean checked = Settings.Global.getInt(getContentResolver(), Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, 0) == 1; - audioMediaCheckbox.setChecked(checked); - audioMediaCheckbox.setOnCheckedChangeListener(mCheckedChangeListener); + mAudioMediaCheckbox.setChecked(checked); + mAudioMediaCheckbox.setOnCheckedChangeListener(mCheckedChangeListener); } float pixelScaleFactor = getResources().getDisplayMetrics().density; @@ -601,19 +605,24 @@ public final class DockService extends Service implements ServiceListener { private final DialogInterface.OnClickListener mClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { - if (which == DialogInterface.BUTTON_POSITIVE - && mDevice != null) { - if (!LocalBluetoothPreferences - .hasDockAutoConnectSetting( - DockService.this, - mDevice.getAddress())) { - LocalBluetoothPreferences - .saveDockAutoConnectSetting( + if (which == DialogInterface.BUTTON_POSITIVE) { + if (mDevice != null) { + if (!LocalBluetoothPreferences + .hasDockAutoConnectSetting( DockService.this, - mDevice.getAddress(), true); + mDevice.getAddress())) { + LocalBluetoothPreferences + .saveDockAutoConnectSetting( + DockService.this, + mDevice.getAddress(), true); + } + + applyBtSettings(mDevice, mStartIdAssociatedWithDialog); + } else if (mAudioMediaCheckbox != null) { + Settings.Global.putInt(getContentResolver(), + Settings.Global.DOCK_AUDIO_MEDIA_ENABLED, + mAudioMediaCheckbox.isChecked() ? 1 : 0); } - - applyBtSettings(mDevice, mStartIdAssociatedWithDialog); } } }; diff --git a/src/com/android/settings/bluetooth/RequestPermissionActivity.java b/src/com/android/settings/bluetooth/RequestPermissionActivity.java index 08c10fb..9f266a5 100644 --- a/src/com/android/settings/bluetooth/RequestPermissionActivity.java +++ b/src/com/android/settings/bluetooth/RequestPermissionActivity.java @@ -149,8 +149,6 @@ public class RequestPermissionActivity extends Activity implements private void createDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setIcon(android.R.drawable.ic_dialog_info); - builder.setTitle(getString(R.string.bluetooth_permission_request)); if (mNeededToEnableBluetooth) { // RequestPermissionHelperActivity has gotten confirmation from user @@ -167,8 +165,8 @@ public class RequestPermissionActivity extends Activity implements builder.setMessage( getString(R.string.bluetooth_ask_discovery, mTimeout)); } - builder.setPositiveButton(getString(R.string.yes), this); - builder.setNegativeButton(getString(R.string.no), this); + builder.setPositiveButton(getString(R.string.allow), this); + builder.setNegativeButton(getString(R.string.deny), this); } mDialog = builder.create(); diff --git a/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java b/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java index 5c4b828..f108513 100644 --- a/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java +++ b/src/com/android/settings/bluetooth/RequestPermissionHelperActivity.java @@ -72,26 +72,20 @@ public class RequestPermissionHelperActivity extends AlertActivity implements void createDialog() { final AlertController.AlertParams p = mAlertParams; - p.mIconId = android.R.drawable.ic_dialog_info; - p.mTitle = getString(R.string.bluetooth_permission_request); - - View view = getLayoutInflater().inflate(R.layout.bluetooth_discoverable, null); - p.mView = view; - TextView tv = (TextView) view.findViewById(R.id.message); if (mEnableOnly) { - tv.setText(getString(R.string.bluetooth_ask_enablement)); + p.mMessage = getString(R.string.bluetooth_ask_enablement); } else { if (mTimeout == BluetoothDiscoverableEnabler.DISCOVERABLE_TIMEOUT_NEVER) { - tv.setText(getString(R.string.bluetooth_ask_enablement_and_lasting_discovery)); + p.mMessage = getString(R.string.bluetooth_ask_enablement_and_lasting_discovery); } else { - tv.setText(getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout)); + p.mMessage = getString(R.string.bluetooth_ask_enablement_and_discovery, mTimeout); } } - p.mPositiveButtonText = getString(R.string.yes); + p.mPositiveButtonText = getString(R.string.allow); p.mPositiveButtonListener = this; - p.mNegativeButtonText = getString(R.string.no); + p.mNegativeButtonText = getString(R.string.deny); p.mNegativeButtonListener = this; setupAlert(); diff --git a/src/com/android/settings/deviceinfo/Status.java b/src/com/android/settings/deviceinfo/Status.java index 8017af3..5297245 100644 --- a/src/com/android/settings/deviceinfo/Status.java +++ b/src/com/android/settings/deviceinfo/Status.java @@ -26,7 +26,6 @@ import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; -import android.os.BatteryManager; import android.os.Build; import android.os.Bundle; import android.os.Handler; @@ -37,6 +36,7 @@ import android.os.UserHandle; import android.preference.Preference; import android.preference.PreferenceActivity; import android.preference.PreferenceScreen; +import android.telephony.CellBroadcastMessage; import android.telephony.PhoneNumberUtils; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; @@ -47,7 +47,6 @@ import com.android.internal.telephony.Phone; import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.PhoneFactory; import com.android.internal.telephony.PhoneStateIntentReceiver; -import com.android.internal.telephony.TelephonyProperties; import com.android.settings.R; import com.android.settings.Utils; @@ -60,6 +59,7 @@ import java.lang.ref.WeakReference; * # Roaming * # Device Id (IMEI in GSM and MEID in CDMA) * # Network type + * # Operator info (area info cell broadcast for Brazil) * # Signal Strength * # Battery Strength : TODO * # Uptime @@ -74,6 +74,7 @@ public class Status extends PreferenceActivity { private static final String KEY_OPERATOR_NAME = "operator_name"; private static final String KEY_ROAMING_STATE = "roaming_state"; private static final String KEY_NETWORK_TYPE = "network_type"; + private static final String KEY_LATEST_AREA_INFO = "latest_area_info"; private static final String KEY_PHONE_NUMBER = "number"; private static final String KEY_IMEI_SV = "imei_sv"; private static final String KEY_IMEI = "imei"; @@ -95,6 +96,7 @@ public class Status extends PreferenceActivity { KEY_OPERATOR_NAME, KEY_ROAMING_STATE, KEY_NETWORK_TYPE, + KEY_LATEST_AREA_INFO, KEY_PHONE_NUMBER, KEY_IMEI, KEY_IMEI_SV, @@ -105,6 +107,16 @@ public class Status extends PreferenceActivity { KEY_ICC_ID }; + static final String CB_AREA_INFO_RECEIVED_ACTION = + "android.cellbroadcastreceiver.CB_AREA_INFO_RECEIVED"; + + static final String GET_LATEST_CB_AREA_INFO_ACTION = + "android.cellbroadcastreceiver.GET_LATEST_CB_AREA_INFO"; + + // Require the sender to have this permission to prevent third-party spoofing. + static final String CB_AREA_INFO_SENDER_PERMISSION = + "android.permission.RECEIVE_EMERGENCY_BROADCAST"; + private static final int EVENT_SIGNAL_STRENGTH_CHANGED = 200; private static final int EVENT_SERVICE_STATE_CHANGED = 300; @@ -116,6 +128,7 @@ public class Status extends PreferenceActivity { private Resources mRes; private Preference mSignalStrength; private Preference mUptime; + private boolean mShowLatestAreaInfo; private String sUnknown; @@ -176,10 +189,27 @@ public class Status extends PreferenceActivity { } }; + private BroadcastReceiver mAreaInfoReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (CB_AREA_INFO_RECEIVED_ACTION.equals(action)) { + Bundle extras = intent.getExtras(); + if (extras == null) { + return; + } + CellBroadcastMessage cbMessage = (CellBroadcastMessage) extras.get("message"); + if (cbMessage != null && cbMessage.getServiceCategory() == 50) { + String latestAreaInfo = cbMessage.getMessageBody(); + updateAreaInfo(latestAreaInfo); + } + } + } + }; + @Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); - Preference removablePref; mHandler = new MyHandler(this); @@ -237,6 +267,11 @@ public class Status extends PreferenceActivity { removePreferenceFromScreen(KEY_MEID_NUMBER); removePreferenceFromScreen(KEY_MIN_NUMBER); removePreferenceFromScreen(KEY_ICC_ID); + + // only show area info when SIM country is Brazil + if ("br".equals(mTelephonyManager.getSimCountryIso())) { + mShowLatestAreaInfo = true; + } } String rawNumber = mPhone.getLine1Number(); // may be null or empty @@ -250,6 +285,10 @@ public class Status extends PreferenceActivity { mPhoneStateReceiver = new PhoneStateIntentReceiver(this, mHandler); mPhoneStateReceiver.notifySignalStrength(EVENT_SIGNAL_STRENGTH_CHANGED); mPhoneStateReceiver.notifyServiceState(EVENT_SERVICE_STATE_CHANGED); + + if (!mShowLatestAreaInfo) { + removePreferenceFromScreen(KEY_LATEST_AREA_INFO); + } } setWimaxStatus(); @@ -275,9 +314,16 @@ public class Status extends PreferenceActivity { updateSignalStrength(); updateServiceState(mPhone.getServiceState()); updateDataState(); - mTelephonyManager.listen(mPhoneStateListener, - PhoneStateListener.LISTEN_DATA_CONNECTION_STATE); + PhoneStateListener.LISTEN_DATA_CONNECTION_STATE); + if (mShowLatestAreaInfo) { + registerReceiver(mAreaInfoReceiver, new IntentFilter(CB_AREA_INFO_RECEIVED_ACTION), + CB_AREA_INFO_SENDER_PERMISSION, null); + // Ask CellBroadcastReceiver to broadcast the latest area info received + Intent getLatestIntent = new Intent(GET_LATEST_CB_AREA_INFO_ACTION); + sendBroadcastAsUser(getLatestIntent, UserHandle.ALL, + CB_AREA_INFO_SENDER_PERMISSION); + } } registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); mHandler.sendEmptyMessage(EVENT_UPDATE_STATS); @@ -291,6 +337,9 @@ public class Status extends PreferenceActivity { mPhoneStateReceiver.unregisterIntent(); mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); } + if (mShowLatestAreaInfo) { + unregisterReceiver(mAreaInfoReceiver); + } unregisterReceiver(mBatteryInfoReceiver); mHandler.removeMessages(EVENT_UPDATE_STATS); } @@ -385,6 +434,12 @@ public class Status extends PreferenceActivity { setSummaryText(KEY_OPERATOR_NAME, serviceState.getOperatorAlphaLong()); } + private void updateAreaInfo(String areaInfo) { + if (areaInfo != null) { + setSummaryText(KEY_LATEST_AREA_INFO, areaInfo); + } + } + void updateSignalStrength() { // TODO PhoneStateIntentReceiver is deprecated and PhoneStateListener // should probably used instead. diff --git a/src/com/android/settings/fuelgauge/PowerUsageDetail.java b/src/com/android/settings/fuelgauge/PowerUsageDetail.java index 4f98163..8ecc659 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageDetail.java +++ b/src/com/android/settings/fuelgauge/PowerUsageDetail.java @@ -16,6 +16,8 @@ package com.android.settings.fuelgauge; +import static com.android.settings.Utils.prepareCustomPreferencesList; + import android.app.Activity; import android.app.ActivityManager; import android.app.ApplicationErrorReport; @@ -34,10 +36,10 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; import android.os.Process; -import android.os.UserHandle; import android.preference.PreferenceActivity; import android.provider.Settings; import android.text.TextUtils; +import android.text.format.Formatter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -141,8 +143,12 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = mRootView = inflater.inflate(R.layout.power_usage_details, null); + public View onCreateView( + LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(R.layout.power_usage_details, container, false); + prepareCustomPreferencesList(container, view, view, false); + + mRootView = view; createDetails(); return view; } @@ -310,10 +316,12 @@ public class PowerUsageDetail extends Fragment implements Button.OnClickListener switch (mTypes[i]) { case R.string.usage_type_data_recv: case R.string.usage_type_data_send: - value = Utils.formatBytes(getActivity(), mValues[i]); + final long bytes = (long) (mValues[i]); + value = Formatter.formatFileSize(getActivity(), bytes); break; case R.string.usage_type_no_coverage: - value = String.format("%d%%", (int) Math.floor(mValues[i])); + final int percentage = (int) Math.floor(mValues[i]); + value = getActivity().getString(R.string.percentage, percentage); break; case R.string.usage_type_gps: mUsesGps = true; diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java index 4a79d9d..0a6e2ab 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -52,6 +52,7 @@ import android.view.MenuItem; import com.android.internal.app.IBatteryStats; import com.android.internal.os.BatteryStatsImpl; import com.android.internal.os.PowerProfile; +import com.android.settings.HelpUtils; import com.android.settings.R; import com.android.settings.fuelgauge.PowerUsageDetail.DrainType; import com.android.settings.users.UserUtils; @@ -339,11 +340,7 @@ public class PowerUsageSummary extends PreferenceFragment implements Runnable { String helpUrl; if (!TextUtils.isEmpty(helpUrl = getResources().getString(R.string.help_url_battery))) { final MenuItem help = menu.add(0, MENU_HELP, 0, R.string.help_label); - Intent helpIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl)); - helpIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK - | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); - help.setIntent(helpIntent); - help.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); + HelpUtils.prepareHelpMenuItem(getActivity(), help, helpUrl); } } diff --git a/src/com/android/settings/fuelgauge/Utils.java b/src/com/android/settings/fuelgauge/Utils.java index 2ffc9de..5c99a86 100644 --- a/src/com/android/settings/fuelgauge/Utils.java +++ b/src/com/android/settings/fuelgauge/Utils.java @@ -64,21 +64,4 @@ public class Utils { } return sb.toString(); } - - /** - * Formats data size in KB, MB, from the given bytes. - * @param context the application context - * @param bytes data size in bytes - * @return the formatted size such as 4.52 MB or 245 KB or 332 bytes - */ - public static String formatBytes(Context context, double bytes) { - // TODO: I18N - if (bytes > 1000 * 1000) { - return String.format("%.2f MB", ((int) (bytes / 1000)) / 1000f); - } else if (bytes > 1024) { - return String.format("%.2f KB", ((int) (bytes / 10)) / 100f); - } else { - return String.format("%d bytes", (int) bytes); - } - } } diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java index e52ab7a..1bf68ce 100644 --- a/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java +++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordActivity.java @@ -21,6 +21,9 @@ import com.android.settings.R; import android.app.Activity; import android.content.Intent; import android.os.Bundle; +import android.os.Message; +import android.os.Messenger; +import android.os.RemoteException; import android.view.View; public class UserDictionaryAddWordActivity extends Activity { @@ -30,6 +33,10 @@ public class UserDictionaryAddWordActivity extends Activity { public static final String MODE_EDIT_ACTION = "com.android.settings.USER_DICTIONARY_EDIT"; public static final String MODE_INSERT_ACTION = "com.android.settings.USER_DICTIONARY_INSERT"; + /* package */ static final int CODE_WORD_ADDED = 0; + /* package */ static final int CODE_CANCEL = 1; + /* package */ static final int CODE_ALREADY_PRESENT = 2; + private UserDictionaryAddWordContents mContents; @Override @@ -67,12 +74,31 @@ public class UserDictionaryAddWordActivity extends Activity { mContents.saveStateIntoBundle(outState); } + private void reportBackToCaller(final int resultCode, final Bundle result) { + final Intent senderIntent = getIntent(); + final Object listener = senderIntent.getExtras().get("listener"); + if (!(listener instanceof Messenger)) return; // This will work if listener is null too. + final Messenger messenger = (Messenger)listener; + + final Message m = Message.obtain(); + m.obj = result; + m.what = resultCode; + try { + messenger.send(m); + } catch (RemoteException e) { + // Couldn't report back, but there is nothing we can do to fix it + } + } + public void onClickCancel(final View v) { + reportBackToCaller(CODE_CANCEL, null); finish(); } public void onClickConfirm(final View v) { - mContents.apply(this); + final Bundle parameters = new Bundle(); + final int resultCode = mContents.apply(this, parameters); + reportBackToCaller(resultCode, parameters); finish(); } } diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java index e46b19c..3251216 100644 --- a/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java +++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordContents.java @@ -43,6 +43,8 @@ public class UserDictionaryAddWordContents { public static final String EXTRA_WORD = "word"; public static final String EXTRA_SHORTCUT = "shortcut"; public static final String EXTRA_LOCALE = "locale"; + public static final String EXTRA_ORIGINAL_WORD = "originalWord"; + public static final String EXTRA_ORIGINAL_SHORTCUT = "originalShortcut"; public static final int MODE_EDIT = 0; public static final int MODE_INSERT = 1; @@ -82,9 +84,13 @@ public class UserDictionaryAddWordContents { /* package */ void saveStateIntoBundle(final Bundle outState) { outState.putString(EXTRA_WORD, mWordEditText.getText().toString()); + outState.putString(EXTRA_ORIGINAL_WORD, mOldWord); if (null != mShortcutEditText) { outState.putString(EXTRA_SHORTCUT, mShortcutEditText.getText().toString()); } + if (null != mOldShortcut) { + outState.putString(EXTRA_ORIGINAL_SHORTCUT, mOldShortcut); + } outState.putString(EXTRA_LOCALE, mLocale); } @@ -97,7 +103,8 @@ public class UserDictionaryAddWordContents { // If we are in add mode, nothing was added, so we don't need to do anything. } - /* package */ void apply(final Context context) { + /* package */ int apply(final Context context, final Bundle outParameters) { + if (null != outParameters) saveStateIntoBundle(outParameters); final ContentResolver resolver = context.getContentResolver(); if (MODE_EDIT == mMode && !TextUtils.isEmpty(mOldWord)) { // Mode edit: remove the old entry. @@ -117,13 +124,13 @@ public class UserDictionaryAddWordContents { } if (TextUtils.isEmpty(newWord)) { // If the word is somehow empty, don't insert it. - return; + return UserDictionaryAddWordActivity.CODE_CANCEL; } // If there is no shortcut, and the word already exists in the database, then we // should not insert, because either A. the word exists with no shortcut, in which // case the exact same thing we want to insert is already there, or B. the word // exists with at least one shortcut, in which case it has priority on our word. - if (hasWord(newWord, context)) return; + if (hasWord(newWord, context)) return UserDictionaryAddWordActivity.CODE_ALREADY_PRESENT; // Disallow duplicates. If the same word with no shortcut is defined, remove it; if // the same word with the same shortcut is defined, remove it; but we don't mind if @@ -139,6 +146,8 @@ public class UserDictionaryAddWordContents { UserDictionary.Words.addWord(context, newWord.toString(), FREQUENCY_FOR_USER_DICTIONARY_ADDS, newShortcut, TextUtils.isEmpty(mLocale) ? null : Utils.createLocaleFromString(mLocale)); + + return UserDictionaryAddWordActivity.CODE_WORD_ADDED; } private static final String[] HAS_WORD_PROJECTION = { UserDictionary.Words.WORD }; diff --git a/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java b/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java index 97ffa19..e33333b 100644 --- a/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java +++ b/src/com/android/settings/inputmethod/UserDictionaryAddWordFragment.java @@ -116,7 +116,7 @@ public class UserDictionaryAddWordFragment extends Fragment super.onPause(); // We are being hidden: commit changes to the user dictionary, unless we were deleting it if (!mIsDeleting) { - mContents.apply(getActivity()); + mContents.apply(getActivity(), null); } } diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java index 632dfe5..dbaaf37 100644 --- a/src/com/android/settings/users/UserSettings.java +++ b/src/com/android/settings/users/UserSettings.java @@ -26,6 +26,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.UserInfo; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.drawable.BitmapDrawable; @@ -477,6 +478,7 @@ public class UserSettings extends SettingsPreferenceFragment } private void loadIconsAsync(List<Integer> missingIcons) { + final Resources resources = getResources(); new AsyncTask<List<Integer>, Void, Void>() { @Override protected void onPostExecute(Void result) { @@ -485,17 +487,16 @@ public class UserSettings extends SettingsPreferenceFragment @Override protected Void doInBackground(List<Integer>... values) { - if (getActivity() == null) return null; for (int userId : values[0]) { Bitmap bitmap = mUserManager.getUserIcon(userId); - Drawable d = new BitmapDrawable(getResources(), bitmap); + Drawable d = new BitmapDrawable(resources, bitmap); mUserIcons.append(userId, d); } return null; } }.execute(missingIcons); - } + private void assignProfilePhoto(final UserInfo user) { if (!Utils.copyMeProfilePhoto(getActivity(), user)) { assignDefaultPhoto(user); diff --git a/src/com/android/settings/wifi/AccessPoint.java b/src/com/android/settings/wifi/AccessPoint.java index 5a7a768..f6581a5 100644 --- a/src/com/android/settings/wifi/AccessPoint.java +++ b/src/com/android/settings/wifi/AccessPoint.java @@ -224,17 +224,19 @@ class AccessPoint extends Preference { } AccessPoint other = (AccessPoint) preference; // Active one goes first. - if (mInfo != other.mInfo) { - return (mInfo != null) ? -1 : 1; - } + if (mInfo != null && other.mInfo == null) return -1; + if (mInfo == null && other.mInfo != null) return 1; + // Reachable one goes before unreachable one. - if ((mRssi ^ other.mRssi) < 0) { - return (mRssi != Integer.MAX_VALUE) ? -1 : 1; - } + if (mRssi != Integer.MAX_VALUE && other.mRssi == Integer.MAX_VALUE) return -1; + if (mRssi == Integer.MAX_VALUE && other.mRssi != Integer.MAX_VALUE) return 1; + // Configured one goes before unconfigured one. - if ((networkId ^ other.networkId) < 0) { - return (networkId != -1) ? -1 : 1; - } + if (networkId != WifiConfiguration.INVALID_NETWORK_ID + && other.networkId == WifiConfiguration.INVALID_NETWORK_ID) return -1; + if (networkId == WifiConfiguration.INVALID_NETWORK_ID + && other.networkId != WifiConfiguration.INVALID_NETWORK_ID) return 1; + // Sort by signal strength. int difference = WifiManager.compareSignalLevel(other.mRssi, mRssi); if (difference != 0) { @@ -244,6 +246,22 @@ class AccessPoint extends Preference { return ssid.compareToIgnoreCase(other.ssid); } + @Override + public boolean equals(Object other) { + if (!(other instanceof AccessPoint)) return false; + return (this.compareTo((AccessPoint) other) == 0); + } + + @Override + public int hashCode() { + int result = 0; + if (mInfo != null) result += 13 * mInfo.hashCode(); + result += 19 * mRssi; + result += 23 * networkId; + result += 29 * ssid.hashCode(); + return result; + } + boolean update(ScanResult result) { if (ssid.equals(result.SSID) && security == getSecurity(result)) { if (WifiManager.compareSignalLevel(result.level, mRssi) > 0) { |