summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2010-08-18 13:59:28 -0700
committerAmith Yamasani <yamasani@google.com>2010-08-18 22:59:33 -0700
commitd79934731c8d33f6fc63b21c120b9ffba5d06f54 (patch)
tree2edb1cb461f5933faf26bdffc5522d9e00f9b808 /src
parent3a9cf0363618bfadeaa5df2460fa615922bd8c75 (diff)
downloadpackages_apps_Settings-d79934731c8d33f6fc63b21c120b9ffba5d06f54.tar.gz
packages_apps_Settings-d79934731c8d33f6fc63b21c120b9ffba5d06f54.tar.bz2
packages_apps_Settings-d79934731c8d33f6fc63b21c120b9ffba5d06f54.zip
Refactor settings top level activities to use fragments.
Added a base class SettingsPreferenceFragment from which the settings activities should be derived so that they can behave like fragments. It contains some commonly called utility methods and dialog conversion to DialogFragment. Some of the top-level activities can be launched directly without the left pane. Settings.java acts as a proxy activity that contains just that settings fragment without the left pane. There are still a lot of second and third level activities that need to be fragmentized. This is just the first pass to test the 2-pane layout.
Diffstat (limited to 'src')
-rw-r--r--src/com/android/settings/AccessibilitySettings.java38
-rw-r--r--src/com/android/settings/ApplicationSettings.java12
-rw-r--r--src/com/android/settings/DateTimeSettings.java40
-rw-r--r--src/com/android/settings/DateTimeSettingsActivity.java380
-rw-r--r--src/com/android/settings/DateTimeSettingsSetupWizard.java2
-rw-r--r--src/com/android/settings/DeviceInfoSettings.java21
-rw-r--r--src/com/android/settings/DisplaySettings.java16
-rw-r--r--src/com/android/settings/DockSettings.java25
-rw-r--r--src/com/android/settings/IconPreferenceScreen.java11
-rw-r--r--src/com/android/settings/LanguageSettings.java35
-rw-r--r--src/com/android/settings/PrivacySettings.java15
-rw-r--r--src/com/android/settings/SecuritySettings.java93
-rw-r--r--src/com/android/settings/Settings.java226
-rw-r--r--src/com/android/settings/SettingsPreferenceFragment.java137
-rw-r--r--src/com/android/settings/SoundSettings.java21
-rw-r--r--src/com/android/settings/VoiceInputOutputSettings.java5
-rw-r--r--src/com/android/settings/WirelessSettings.java40
-rw-r--r--src/com/android/settings/deviceinfo/Memory.java48
18 files changed, 934 insertions, 231 deletions
diff --git a/src/com/android/settings/AccessibilitySettings.java b/src/com/android/settings/AccessibilitySettings.java
index d78d2d8ef..8892e966d 100644
--- a/src/com/android/settings/AccessibilitySettings.java
+++ b/src/com/android/settings/AccessibilitySettings.java
@@ -22,14 +22,13 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ServiceInfo;
+import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemProperties;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
@@ -47,7 +46,7 @@ import java.util.Map;
/**
* Activity with the accessibility settings.
*/
-public class AccessibilitySettings extends PreferenceActivity {
+public class AccessibilitySettings extends SettingsPreferenceFragment {
private static final String DEFAULT_SCREENREADER_MARKET_LINK =
"market://search?q=pname:com.google.android.marvin.talkback";
@@ -77,7 +76,7 @@ public class AccessibilitySettings extends PreferenceActivity {
private PreferenceGroup mAccessibilityServicesCategory;
@Override
- protected void onCreate(Bundle icicle) {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.accessibility_settings);
@@ -92,7 +91,7 @@ public class AccessibilitySettings extends PreferenceActivity {
}
@Override
- protected void onResume() {
+ public void onResume() {
super.onResume();
final HashSet<String> enabled = new HashSet<String>();
@@ -155,7 +154,7 @@ public class AccessibilitySettings extends PreferenceActivity {
}
@Override
- protected void onPause() {
+ public void onPause() {
super.onPause();
persistEnabledAccessibilityServices();
@@ -214,10 +213,12 @@ public class AccessibilitySettings extends PreferenceActivity {
setAccessibilityServicePreferencesState(true);
} else {
final CheckBoxPreference checkBoxPreference = preference;
- AlertDialog dialog = (new AlertDialog.Builder(this))
+ // TODO: DialogFragment?
+ AlertDialog dialog = (new AlertDialog.Builder(getActivity()))
.setTitle(android.R.string.dialog_alert_title)
.setIcon(android.R.drawable.ic_dialog_alert)
- .setMessage(getString(R.string.accessibility_service_disable_warning))
+ .setMessage(getResources().
+ getString(R.string.accessibility_service_disable_warning))
.setCancelable(true)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@@ -246,12 +247,14 @@ public class AccessibilitySettings extends PreferenceActivity {
private void handleEnableAccessibilityServiceStateChange(CheckBoxPreference preference) {
if (preference.isChecked()) {
final CheckBoxPreference checkBoxPreference = preference;
- AlertDialog dialog = (new AlertDialog.Builder(this))
+ // TODO: DialogFragment?
+ AlertDialog dialog = (new AlertDialog.Builder(getActivity()))
.setTitle(android.R.string.dialog_alert_title)
.setIcon(android.R.drawable.ic_dialog_alert)
- .setMessage(getString(R.string.accessibility_service_security_warning,
- mAccessibilityServices.get(preference.getKey())
- .applicationInfo.loadLabel(getPackageManager())))
+ .setMessage(getResources().
+ getString(R.string.accessibility_service_security_warning,
+ mAccessibilityServices.get(preference.getKey())
+ .applicationInfo.loadLabel(getActivity().getPackageManager())))
.setCancelable(true)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@@ -318,9 +321,9 @@ public class AccessibilitySettings extends PreferenceActivity {
mAccessibilityServices.put(key, serviceInfo);
- CheckBoxPreference preference = new CheckBoxPreference(this);
+ CheckBoxPreference preference = new CheckBoxPreference(getActivity());
preference.setKey(key);
- preference.setTitle(serviceInfo.loadLabel(getPackageManager()));
+ preference.setTitle(serviceInfo.loadLabel(getActivity().getPackageManager()));
mAccessibilityServicesCategory.addPreference(preference);
}
}
@@ -332,13 +335,14 @@ public class AccessibilitySettings extends PreferenceActivity {
*/
private void displayNoAppsAlert() {
try {
- PackageManager pm = getPackageManager();
+ PackageManager pm = getActivity().getPackageManager();
ApplicationInfo info = pm.getApplicationInfo("com.android.vending", 0);
} catch (NameNotFoundException e) {
// This is a no-op if the user does not have Android Market
return;
}
- AlertDialog.Builder noAppsAlert = new AlertDialog.Builder(this);
+ // TODO: DialogFragment?
+ AlertDialog.Builder noAppsAlert = new AlertDialog.Builder(getActivity());
noAppsAlert.setTitle(R.string.accessibility_service_no_apps_title);
noAppsAlert.setMessage(R.string.accessibility_service_no_apps_message);
@@ -351,7 +355,7 @@ public class AccessibilitySettings extends PreferenceActivity {
Uri marketUri = Uri.parse(screenreaderMarketLink);
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
startActivity(marketIntent);
- finish();
+ getFragmentManager().popBackStack();
}
});
diff --git a/src/com/android/settings/ApplicationSettings.java b/src/com/android/settings/ApplicationSettings.java
index a919ae849..ed7c7a085 100644
--- a/src/com/android/settings/ApplicationSettings.java
+++ b/src/com/android/settings/ApplicationSettings.java
@@ -23,12 +23,11 @@ import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.preference.Preference.OnPreferenceChangeListener;
import android.provider.Settings;
-public class ApplicationSettings extends PreferenceActivity implements
+public class ApplicationSettings extends SettingsPreferenceFragment implements
DialogInterface.OnClickListener {
private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
@@ -51,7 +50,7 @@ public class ApplicationSettings extends PreferenceActivity implements
private DialogInterface mWarnInstallApps;
@Override
- protected void onCreate(Bundle icicle) {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.application_settings);
@@ -102,7 +101,7 @@ public class ApplicationSettings extends PreferenceActivity implements
}
@Override
- protected void onDestroy() {
+ public void onDestroy() {
super.onDestroy();
if (mWarnInstallApps != null) {
mWarnInstallApps.dismiss();
@@ -157,8 +156,9 @@ public class ApplicationSettings extends PreferenceActivity implements
}
private void warnAppInstallation() {
- mWarnInstallApps = new AlertDialog.Builder(this)
- .setTitle(getString(R.string.error_title))
+ // TODO: DialogFragment?
+ mWarnInstallApps = new AlertDialog.Builder(getActivity()).setTitle(
+ getResources().getString(R.string.error_title))
.setIcon(com.android.internal.R.drawable.ic_dialog_alert)
.setMessage(getResources().getString(R.string.install_all_warning))
.setPositiveButton(android.R.string.yes, this)
diff --git a/src/com/android/settings/DateTimeSettings.java b/src/com/android/settings/DateTimeSettings.java
index 5b38651ce..0a929bae7 100644
--- a/src/com/android/settings/DateTimeSettings.java
+++ b/src/com/android/settings/DateTimeSettings.java
@@ -16,8 +16,8 @@
package com.android.settings;
-import android.app.Dialog;
import android.app.DatePickerDialog;
+import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -30,7 +30,6 @@ import android.os.SystemClock;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
@@ -43,7 +42,7 @@ import java.util.Date;
import java.util.TimeZone;
public class DateTimeSettings
- extends PreferenceActivity
+ extends SettingsPreferenceFragment
implements OnSharedPreferenceChangeListener,
TimePickerDialog.OnTimeSetListener , DatePickerDialog.OnDateSetListener {
@@ -65,7 +64,7 @@ public class DateTimeSettings
private ListPreference mDateFormat;
@Override
- protected void onCreate(Bundle icicle) {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.date_time_prefs);
@@ -97,8 +96,8 @@ public class DateTimeSettings
}
for (int i = 0; i < formattedDates.length; i++) {
String formatted =
- DateFormat.getDateFormatForSetting(this, dateFormats[i]).
- format(mDummyDate.getTime());
+ DateFormat.getDateFormatForSetting(getActivity(), dateFormats[i])
+ .format(mDummyDate.getTime());
if (dateFormats[i].length() == 0) {
formattedDates[i] = getResources().
@@ -119,7 +118,7 @@ public class DateTimeSettings
@Override
- protected void onResume() {
+ public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
@@ -131,23 +130,23 @@ public class DateTimeSettings
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
- registerReceiver(mIntentReceiver, filter, null, null);
+ getActivity().registerReceiver(mIntentReceiver, filter, null, null);
updateTimeAndDateDisplay();
}
@Override
- protected void onPause() {
+ public void onPause() {
super.onPause();
- unregisterReceiver(mIntentReceiver);
+ getActivity().unregisterReceiver(mIntentReceiver);
getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
}
private void updateTimeAndDateDisplay() {
- java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(this);
+ java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(getActivity());
Date now = Calendar.getInstance().getTime();
Date dummyDate = mDummyDate.getTime();
- mTimePref.setSummary(DateFormat.getTimeFormat(this).format(now));
+ mTimePref.setSummary(DateFormat.getTimeFormat(getActivity()).format(now));
mTimeZone.setSummary(getTimeZoneText());
mDatePref.setSummary(shortDateFormat.format(now));
mDateFormat.setSummary(shortDateFormat.format(dummyDate));
@@ -210,7 +209,7 @@ public class DateTimeSettings
case DIALOG_DATEPICKER: {
final Calendar calendar = Calendar.getInstance();
d = new DatePickerDialog(
- this,
+ getActivity(),
this,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
@@ -221,11 +220,11 @@ public class DateTimeSettings
case DIALOG_TIMEPICKER: {
final Calendar calendar = Calendar.getInstance();
d = new TimePickerDialog(
- this,
+ getActivity(),
this,
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
- DateFormat.is24HourFormat(this));
+ DateFormat.is24HourFormat(getActivity()));
d.setTitle(getResources().getString(R.string.date_time_changeTime_text));
break;
}
@@ -237,6 +236,7 @@ public class DateTimeSettings
return d;
}
+ /*
@Override
public void onPrepareDialog(int id, Dialog d) {
switch (id) {
@@ -261,7 +261,7 @@ public class DateTimeSettings
break;
}
}
-
+ */
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if (preference == mDatePref) {
@@ -276,27 +276,27 @@ public class DateTimeSettings
timeUpdated();
} else if (preference == mTimeZone) {
Intent intent = new Intent();
- intent.setClass(this, ZoneList.class);
+ intent.setClass(getActivity(), ZoneList.class);
startActivityForResult(intent, 0);
}
return false;
}
@Override
- protected void onActivityResult(int requestCode, int resultCode,
+ public void onActivityResult(int requestCode, int resultCode,
Intent data) {
updateTimeAndDateDisplay();
}
private void timeUpdated() {
Intent timeChanged = new Intent(Intent.ACTION_TIME_CHANGED);
- sendBroadcast(timeChanged);
+ getActivity().sendBroadcast(timeChanged);
}
/* Get & Set values from the system settings */
private boolean is24Hour() {
- return DateFormat.is24HourFormat(this);
+ return DateFormat.is24HourFormat(getActivity());
}
private void set24Hour(boolean is24Hour) {
diff --git a/src/com/android/settings/DateTimeSettingsActivity.java b/src/com/android/settings/DateTimeSettingsActivity.java
new file mode 100644
index 000000000..3f426b9e3
--- /dev/null
+++ b/src/com/android/settings/DateTimeSettingsActivity.java
@@ -0,0 +1,380 @@
+/*
+ * 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 android.app.Dialog;
+import android.app.DatePickerDialog;
+import android.app.TimePickerDialog;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.os.Bundle;
+import android.os.SystemClock;
+import android.preference.CheckBoxPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceScreen;
+import android.provider.Settings;
+import android.provider.Settings.SettingNotFoundException;
+import android.text.format.DateFormat;
+import android.widget.DatePicker;
+import android.widget.TimePicker;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+public class DateTimeSettingsActivity
+ extends PreferenceActivity
+ implements OnSharedPreferenceChangeListener,
+ TimePickerDialog.OnTimeSetListener , DatePickerDialog.OnDateSetListener {
+
+ private static final String HOURS_12 = "12";
+ private static final String HOURS_24 = "24";
+
+ private Calendar mDummyDate;
+ private static final String KEY_DATE_FORMAT = "date_format";
+ private static final String KEY_AUTO_TIME = "auto_time";
+
+ private static final int DIALOG_DATEPICKER = 0;
+ private static final int DIALOG_TIMEPICKER = 1;
+
+ private CheckBoxPreference mAutoPref;
+ private Preference mTimePref;
+ private Preference mTime24Pref;
+ private Preference mTimeZone;
+ private Preference mDatePref;
+ private ListPreference mDateFormat;
+
+ @Override
+ protected void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+
+ addPreferencesFromResource(R.xml.date_time_prefs);
+
+ initUI();
+ }
+
+ private void initUI() {
+ boolean autoEnabled = getAutoState();
+
+ mDummyDate = Calendar.getInstance();
+ mDummyDate.set(mDummyDate.get(Calendar.YEAR), 11, 31, 13, 0, 0);
+
+ mAutoPref = (CheckBoxPreference) findPreference(KEY_AUTO_TIME);
+ mAutoPref.setChecked(autoEnabled);
+ mTimePref = findPreference("time");
+ mTime24Pref = findPreference("24 hour");
+ mTimeZone = findPreference("timezone");
+ mDatePref = findPreference("date");
+ mDateFormat = (ListPreference) findPreference(KEY_DATE_FORMAT);
+
+ String [] dateFormats = getResources().getStringArray(R.array.date_format_values);
+ String [] formattedDates = new String[dateFormats.length];
+ String currentFormat = getDateFormat();
+ // Initialize if DATE_FORMAT is not set in the system settings
+ // This can happen after a factory reset (or data wipe)
+ if (currentFormat == null) {
+ currentFormat = "";
+ }
+ for (int i = 0; i < formattedDates.length; i++) {
+ String formatted =
+ DateFormat.getDateFormatForSetting(this, dateFormats[i]).
+ format(mDummyDate.getTime());
+
+ if (dateFormats[i].length() == 0) {
+ formattedDates[i] = getResources().
+ getString(R.string.normal_date_format, formatted);
+ } else {
+ formattedDates[i] = formatted;
+ }
+ }
+
+ mDateFormat.setEntries(formattedDates);
+ mDateFormat.setEntryValues(R.array.date_format_values);
+ mDateFormat.setValue(currentFormat);
+
+ mTimePref.setEnabled(!autoEnabled);
+ mDatePref.setEnabled(!autoEnabled);
+ mTimeZone.setEnabled(!autoEnabled);
+ }
+
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+
+ getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+
+ ((CheckBoxPreference)mTime24Pref).setChecked(is24Hour());
+
+ // Register for time ticks and other reasons for time change
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_TIME_TICK);
+ filter.addAction(Intent.ACTION_TIME_CHANGED);
+ filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
+ registerReceiver(mIntentReceiver, filter, null, null);
+
+ updateTimeAndDateDisplay();
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ unregisterReceiver(mIntentReceiver);
+ getPreferenceScreen().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
+ }
+
+ private void updateTimeAndDateDisplay() {
+ java.text.DateFormat shortDateFormat = DateFormat.getDateFormat(this);
+ Date now = Calendar.getInstance().getTime();
+ Date dummyDate = mDummyDate.getTime();
+ mTimePref.setSummary(DateFormat.getTimeFormat(this).format(now));
+ mTimeZone.setSummary(getTimeZoneText());
+ mDatePref.setSummary(shortDateFormat.format(now));
+ mDateFormat.setSummary(shortDateFormat.format(dummyDate));
+ }
+
+ public void onDateSet(DatePicker view, int year, int month, int day) {
+ Calendar c = Calendar.getInstance();
+
+ c.set(Calendar.YEAR, year);
+ c.set(Calendar.MONTH, month);
+ c.set(Calendar.DAY_OF_MONTH, day);
+ long when = c.getTimeInMillis();
+
+ if (when / 1000 < Integer.MAX_VALUE) {
+ SystemClock.setCurrentTimeMillis(when);
+ }
+ updateTimeAndDateDisplay();
+ }
+
+ public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
+ Calendar c = Calendar.getInstance();
+
+ c.set(Calendar.HOUR_OF_DAY, hourOfDay);
+ c.set(Calendar.MINUTE, minute);
+ long when = c.getTimeInMillis();
+
+ if (when / 1000 < Integer.MAX_VALUE) {
+ SystemClock.setCurrentTimeMillis(when);
+ }
+ updateTimeAndDateDisplay();
+
+ // We don't need to call timeUpdated() here because the TIME_CHANGED
+ // broadcast is sent by the AlarmManager as a side effect of setting the
+ // SystemClock time.
+ }
+
+ public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
+ if (key.equals(KEY_DATE_FORMAT)) {
+ String format = preferences.getString(key,
+ getResources().getString(R.string.default_date_format));
+ Settings.System.putString(getContentResolver(),
+ Settings.System.DATE_FORMAT, format);
+ updateTimeAndDateDisplay();
+ } else if (key.equals(KEY_AUTO_TIME)) {
+ boolean autoEnabled = preferences.getBoolean(key, true);
+ Settings.System.putInt(getContentResolver(),
+ Settings.System.AUTO_TIME,
+ autoEnabled ? 1 : 0);
+ mTimePref.setEnabled(!autoEnabled);
+ mDatePref.setEnabled(!autoEnabled);
+ mTimeZone.setEnabled(!autoEnabled);
+ }
+ }
+
+ @Override
+ public Dialog onCreateDialog(int id) {
+ Dialog d;
+
+ switch (id) {
+ case DIALOG_DATEPICKER: {
+ final Calendar calendar = Calendar.getInstance();
+ d = new DatePickerDialog(
+ this,
+ this,
+ calendar.get(Calendar.YEAR),
+ calendar.get(Calendar.MONTH),
+ calendar.get(Calendar.DAY_OF_MONTH));
+ d.setTitle(getResources().getString(R.string.date_time_changeDate_text));
+ break;
+ }
+ case DIALOG_TIMEPICKER: {
+ final Calendar calendar = Calendar.getInstance();
+ d = new TimePickerDialog(
+ this,
+ this,
+ calendar.get(Calendar.HOUR_OF_DAY),
+ calendar.get(Calendar.MINUTE),
+ DateFormat.is24HourFormat(this));
+ d.setTitle(getResources().getString(R.string.date_time_changeTime_text));
+ break;
+ }
+ default:
+ d = null;
+ break;
+ }
+
+ return d;
+ }
+
+ @Override
+ public void onPrepareDialog(int id, Dialog d) {
+ switch (id) {
+ case DIALOG_DATEPICKER: {
+ DatePickerDialog datePicker = (DatePickerDialog)d;
+ final Calendar calendar = Calendar.getInstance();
+ datePicker.updateDate(
+ calendar.get(Calendar.YEAR),
+ calendar.get(Calendar.MONTH),
+ calendar.get(Calendar.DAY_OF_MONTH));
+ break;
+ }
+ case DIALOG_TIMEPICKER: {
+ TimePickerDialog timePicker = (TimePickerDialog)d;
+ final Calendar calendar = Calendar.getInstance();
+ timePicker.updateTime(
+ calendar.get(Calendar.HOUR_OF_DAY),
+ calendar.get(Calendar.MINUTE));
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
+ if (preference == mDatePref) {
+ showDialog(DIALOG_DATEPICKER);
+ } else if (preference == mTimePref) {
+ // The 24-hour mode may have changed, so recreate the dialog
+ removeDialog(DIALOG_TIMEPICKER);
+ showDialog(DIALOG_TIMEPICKER);
+ } else if (preference == mTime24Pref) {
+ set24Hour(((CheckBoxPreference)mTime24Pref).isChecked());
+ updateTimeAndDateDisplay();
+ timeUpdated();
+ } else if (preference == mTimeZone) {
+ Intent intent = new Intent();
+ intent.setClass(this, ZoneList.class);
+ startActivityForResult(intent, 0);
+ }
+ return false;
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode,
+ Intent data) {
+ updateTimeAndDateDisplay();
+ }
+
+ private void timeUpdated() {
+ Intent timeChanged = new Intent(Intent.ACTION_TIME_CHANGED);
+ sendBroadcast(timeChanged);
+ }
+
+ /* Get & Set values from the system settings */
+
+ private boolean is24Hour() {
+ return DateFormat.is24HourFormat(this);
+ }
+
+ private void set24Hour(boolean is24Hour) {
+ Settings.System.putString(getContentResolver(),
+ Settings.System.TIME_12_24,
+ is24Hour? HOURS_24 : HOURS_12);
+ }
+
+ private String getDateFormat() {
+ return Settings.System.getString(getContentResolver(),
+ Settings.System.DATE_FORMAT);
+ }
+
+ private boolean getAutoState() {
+ try {
+ return Settings.System.getInt(getContentResolver(),
+ Settings.System.AUTO_TIME) > 0;
+ } catch (SettingNotFoundException snfe) {
+ return true;
+ }
+ }
+
+ private void setDateFormat(String format) {
+ if (format.length() == 0) {
+ format = null;
+ }
+
+ Settings.System.putString(getContentResolver(), Settings.System.DATE_FORMAT, format);
+ }
+
+ /* Helper routines to format timezone */
+
+ private String getTimeZoneText() {
+ TimeZone tz = java.util.Calendar.getInstance().getTimeZone();
+ boolean daylight = tz.inDaylightTime(new Date());
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(formatOffset(tz.getRawOffset() +
+ (daylight ? tz.getDSTSavings() : 0))).
+ append(", ").
+ append(tz.getDisplayName(daylight, TimeZone.LONG));
+
+ return sb.toString();
+ }
+
+ private char[] formatOffset(int off) {
+ off = off / 1000 / 60;
+
+ char[] buf = new char[9];
+ buf[0] = 'G';
+ buf[1] = 'M';
+ buf[2] = 'T';
+
+ if (off < 0) {
+ buf[3] = '-';
+ off = -off;
+ } else {
+ buf[3] = '+';
+ }
+
+ int hours = off / 60;
+ int minutes = off % 60;
+
+ buf[4] = (char) ('0' + hours / 10);
+ buf[5] = (char) ('0' + hours % 10);
+
+ buf[6] = ':';
+
+ buf[7] = (char) ('0' + minutes / 10);
+ buf[8] = (char) ('0' + minutes % 10);
+
+ return buf;
+ }
+
+ private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ updateTimeAndDateDisplay();
+ }
+ };
+}
diff --git a/src/com/android/settings/DateTimeSettingsSetupWizard.java b/src/com/android/settings/DateTimeSettingsSetupWizard.java
index a6a60c1b2..262a53637 100644
--- a/src/com/android/settings/DateTimeSettingsSetupWizard.java
+++ b/src/com/android/settings/DateTimeSettingsSetupWizard.java
@@ -21,7 +21,7 @@ import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
-public class DateTimeSettingsSetupWizard extends DateTimeSettings implements OnClickListener {
+public class DateTimeSettingsSetupWizard extends DateTimeSettingsActivity implements OnClickListener {
private View mNextButton;
@Override
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index a2c22ab9e..7f9433879 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -16,16 +16,15 @@
package com.android.settings;
+import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.SystemProperties;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.util.Log;
-import android.view.MotionEvent;
import java.io.BufferedReader;
import java.io.FileReader;
@@ -33,7 +32,7 @@ import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-public class DeviceInfoSettings extends PreferenceActivity {
+public class DeviceInfoSettings extends SettingsPreferenceFragment {
private static final String TAG = "DeviceInfoSettings";
private static final String KEY_CONTAINER = "container";
@@ -46,7 +45,7 @@ public class DeviceInfoSettings extends PreferenceActivity {
private static final String PROPERTY_URL_SAFETYLEGAL = "ro.url.safetylegal";
@Override
- protected void onCreate(Bundle icicle) {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.device_info_settings);
@@ -66,24 +65,24 @@ public class DeviceInfoSettings extends PreferenceActivity {
* Settings is a generic app and should not contain any device-specific
* info.
*/
-
+ final Activity act = getActivity();
// These are contained in the "container" preference group
PreferenceGroup parentPreference = (PreferenceGroup) findPreference(KEY_CONTAINER);
- Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_TERMS,
+ Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TERMS,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
- Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_LICENSE,
+ Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_LICENSE,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
- Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_COPYRIGHT,
+ Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_COPYRIGHT,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
- Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_TEAM,
+ Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_TEAM,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
// These are contained by the root preference screen
parentPreference = getPreferenceScreen();
- Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference,
+ Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference,
KEY_SYSTEM_UPDATE_SETTINGS,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
- Utils.updatePreferenceToSpecificActivityOrRemove(this, parentPreference, KEY_CONTRIBUTORS,
+ Utils.updatePreferenceToSpecificActivityOrRemove(act, parentPreference, KEY_CONTRIBUTORS,
Utils.UPDATE_PREFERENCE_FLAG_SET_TITLE_TO_MATCHING_ACTIVITY);
}
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index fbb07c13c..5945884af 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -18,8 +18,6 @@ package com.android.settings;
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
-import java.util.ArrayList;
-
import android.app.admin.DevicePolicyManager;
import android.content.ContentResolver;
import android.content.Context;
@@ -29,13 +27,14 @@ import android.os.ServiceManager;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.util.Log;
import android.view.IWindowManager;
-public class DisplaySettings extends PreferenceActivity implements
+import java.util.ArrayList;
+
+public class DisplaySettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String TAG = "DisplaySettings";
@@ -53,9 +52,9 @@ public class DisplaySettings extends PreferenceActivity implements
private IWindowManager mWindowManager;
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- ContentResolver resolver = getContentResolver();
+ ContentResolver resolver = getActivity().getContentResolver();
mWindowManager = IWindowManager.Stub.asInterface(ServiceManager.getService("window"));
addPreferencesFromResource(R.xml.display_settings);
@@ -75,7 +74,8 @@ public class DisplaySettings extends PreferenceActivity implements
private void disableUnusableTimeouts(ListPreference screenTimeoutPreference) {
final DevicePolicyManager dpm =
- (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
+ (DevicePolicyManager) getActivity().getSystemService(
+ Context.DEVICE_POLICY_SERVICE);
final long maxTimeout = dpm != null ? dpm.getMaximumTimeToLock(null) : 0;
if (maxTimeout == 0) {
return; // policy not enforced
@@ -109,7 +109,7 @@ public class DisplaySettings extends PreferenceActivity implements
}
@Override
- protected void onResume() {
+ public void onResume() {
super.onResume();
updateState(true);
diff --git a/src/com/android/settings/DockSettings.java b/src/com/android/settings/DockSettings.java
index 0d46ce9a9..b36864021 100644
--- a/src/com/android/settings/DockSettings.java
+++ b/src/com/android/settings/DockSettings.java
@@ -16,6 +16,8 @@
package com.android.settings;
+import com.android.settings.bluetooth.DockEventReceiver;
+
import android.app.AlertDialog;
import android.app.Dialog;
import android.bluetooth.BluetoothDevice;
@@ -27,13 +29,10 @@ import android.content.IntentFilter;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;
-import com.android.settings.bluetooth.DockEventReceiver;
-
-public class DockSettings extends PreferenceActivity {
+public class DockSettings extends SettingsPreferenceFragment {
private static final int DIALOG_NOT_DOCKED = 1;
private static final String KEY_AUDIO_SETTINGS = "dock_audio";
@@ -52,7 +51,7 @@ public class DockSettings extends PreferenceActivity {
};
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContentResolver resolver = getContentResolver();
addPreferencesFromResource(R.xml.dock_settings);
@@ -61,18 +60,18 @@ public class DockSettings extends PreferenceActivity {
}
@Override
- protected void onResume() {
+ public void onResume() {
super.onResume();
IntentFilter filter = new IntentFilter(Intent.ACTION_DOCK_EVENT);
- registerReceiver(mReceiver, filter);
+ getActivity().registerReceiver(mReceiver, filter);
}
@Override
- protected void onPause() {
+ public void onPause() {
super.onPause();
- unregisterReceiver(mReceiver);
+ getActivity().unregisterReceiver(mReceiver);
}
private void initDockSettings() {
@@ -120,7 +119,7 @@ public class DockSettings extends PreferenceActivity {
if (dockState != Intent.EXTRA_DOCK_STATE_UNDOCKED) {
// remove undocked dialog if currently showing.
try {
- dismissDialog(DIALOG_NOT_DOCKED);
+ removeDialog(DIALOG_NOT_DOCKED);
} catch (IllegalArgumentException iae) {
// Maybe it was already dismissed
}
@@ -139,8 +138,8 @@ public class DockSettings extends PreferenceActivity {
} else {
Intent i = new Intent(mDockIntent);
i.setAction(DockEventReceiver.ACTION_DOCK_SHOW_UI);
- i.setClass(this, DockEventReceiver.class);
- sendBroadcast(i);
+ i.setClass(getActivity(), DockEventReceiver.class);
+ getActivity().sendBroadcast(i);
}
} else if (preference == mDockSounds) {
Settings.System.putInt(getContentResolver(), Settings.System.DOCK_SOUNDS_ENABLED,
@@ -159,7 +158,7 @@ public class DockSettings extends PreferenceActivity {
}
private Dialog createUndockedMessage() {
- final AlertDialog.Builder ab = new AlertDialog.Builder(this);
+ final AlertDialog.Builder ab = new AlertDialog.Builder(getActivity());
ab.setTitle(R.string.dock_not_found_title);
ab.setMessage(R.string.dock_not_found_text);
ab.setPositiveButton(android.R.string.ok, null);
diff --git a/src/com/android/settings/IconPreferenceScreen.java b/src/com/android/settings/IconPreferenceScreen.java
index 31abf0a86..64fce29de 100644
--- a/src/com/android/settings/IconPreferenceScreen.java
+++ b/src/com/android/settings/IconPreferenceScreen.java
@@ -22,13 +22,16 @@ import android.graphics.drawable.Drawable;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
-import android.view.ViewGroup;
import android.widget.ImageView;
+import android.widget.TextView;
public class IconPreferenceScreen extends Preference {
private Drawable mIcon;
+ // Whether or not the text and icon should be highlighted (as selected)
+ private boolean mHighlight;
+
public IconPreferenceScreen(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@@ -48,6 +51,7 @@ public class IconPreferenceScreen extends Preference {
if (imageView != null && mIcon != null) {
imageView.setImageDrawable(mIcon);
}
+ TextView textView = (TextView) view.findViewById(android.R.id.title);
}
/**
@@ -71,4 +75,9 @@ public class IconPreferenceScreen extends Preference {
public Drawable getIcon() {
return mIcon;
}
+
+ public void setHighlighted(boolean highlight) {
+ mHighlight = highlight;
+ notifyChanged();
+ }
}
diff --git a/src/com/android/settings/LanguageSettings.java b/src/com/android/settings/LanguageSettings.java
index 6036ac31c..959329c1b 100644
--- a/src/com/android/settings/LanguageSettings.java
+++ b/src/com/android/settings/LanguageSettings.java
@@ -17,23 +17,18 @@
package com.android.settings;
import android.app.AlertDialog;
-import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.os.Bundle;
-import android.os.Environment;
-import android.os.SystemProperties;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.text.TextUtils;
-import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
@@ -41,7 +36,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
-public class LanguageSettings extends PreferenceActivity {
+public class LanguageSettings extends SettingsPreferenceFragment {
private static final String KEY_PHONE_LANGUAGE = "phone_language";
private static final String KEY_INPUT_METHOD = "input_method";
@@ -65,12 +60,12 @@ public class LanguageSettings extends PreferenceActivity {
}
@Override
- protected void onCreate(Bundle icicle) {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.language_settings);
- if (getAssets().getLocales().length == 1) {
+ if (getActivity().getAssets().getLocales().length == 1) {
getPreferenceScreen().
removePreference(findPreference("language_category"));
} else {
@@ -109,12 +104,12 @@ public class LanguageSettings extends PreferenceActivity {
InputMethodInfo property = mInputMethodProperties.get(i);
String prefKey = property.getId();
- CharSequence label = property.loadLabel(getPackageManager());
+ CharSequence label = property.loadLabel(getActivity().getPackageManager());
boolean systemIME = isSystemIme(property);
// Add a check box.
// Don't show the toggle if it's the only keyboard in the system, or it's a system IME.
if (mHaveHardKeyboard || (N > 1 && !systemIME)) {
- CheckBoxPreference chkbxPref = new CheckBoxPreference(this);
+ CheckBoxPreference chkbxPref = new CheckBoxPreference(getActivity());
chkbxPref.setKey(prefKey);
chkbxPref.setTitle(label);
textCategory.addPreference(chkbxPref);
@@ -123,7 +118,7 @@ public class LanguageSettings extends PreferenceActivity {
// If setting activity is available, add a setting screen entry.
if (null != property.getSettingsActivity()) {
- PreferenceScreen prefScreen = new PreferenceScreen(this, null);
+ PreferenceScreen prefScreen = new PreferenceScreen(getActivity(), null);
String settingsActivity = property.getSettingsActivity();
if (settingsActivity.lastIndexOf("/") < 0) {
settingsActivity = property.getPackageName() + "/" + settingsActivity;
@@ -131,7 +126,8 @@ public class LanguageSettings extends PreferenceActivity {
prefScreen.setKey(settingsActivity);
prefScreen.setTitle(label);
if (N == 1) {
- prefScreen.setSummary(getString(R.string.onscreen_keyboard_settings_summary));
+ prefScreen.setSummary(getResources().getString(
+ R.string.onscreen_keyboard_settings_summary));
} else {
CharSequence settingsLabel = getResources().getString(
R.string.input_methods_settings_label_format, label);
@@ -143,7 +139,7 @@ public class LanguageSettings extends PreferenceActivity {
}
@Override
- protected void onResume() {
+ public void onResume() {
super.onResume();
final HashSet<String> enabled = new HashSet<String>();
@@ -180,7 +176,7 @@ public class LanguageSettings extends PreferenceActivity {
}
@Override
- protected void onPause() {
+ public void onPause() {
super.onPause();
StringBuilder builder = new StringBuilder(256);
@@ -260,7 +256,8 @@ public class LanguageSettings extends PreferenceActivity {
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
if (mDialog == null) {
- mDialog = (new AlertDialog.Builder(this))
+ // TODO: DialogFragment?
+ mDialog = (new AlertDialog.Builder(getActivity()))
.setTitle(android.R.string.dialog_alert_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setCancelable(true)
@@ -284,9 +281,9 @@ public class LanguageSettings extends PreferenceActivity {
mDialog.dismiss();
}
}
- mDialog.setMessage(getString(R.string.ime_security_warning,
- selImi.getServiceInfo().applicationInfo.loadLabel(
- getPackageManager())));
+ mDialog.setMessage(getResources().getString(
+ R.string.ime_security_warning,
+ selImi.getServiceInfo().applicationInfo.loadLabel(getPackageManager())));
mDialog.show();
} else if (id.equals(mLastTickedInputMethodId)) {
mLastTickedInputMethodId = null;
@@ -316,7 +313,7 @@ public class LanguageSettings extends PreferenceActivity {
}
@Override
- protected void onDestroy() {
+ public void onDestroy() {
super.onDestroy();
if (mDialog != null) {
mDialog.dismiss();
diff --git a/src/com/android/settings/PrivacySettings.java b/src/com/android/settings/PrivacySettings.java
index 29deacf29..826c9cfe1 100644
--- a/src/com/android/settings/PrivacySettings.java
+++ b/src/com/android/settings/PrivacySettings.java
@@ -22,23 +22,18 @@ import android.app.backup.IBackupManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;
-import android.text.method.LinkMovementMethod;
-import android.widget.TextView;
/**
* Gesture lock pattern settings.
*/
-public class PrivacySettings extends PreferenceActivity implements
+public class PrivacySettings extends SettingsPreferenceFragment implements
DialogInterface.OnClickListener {
// Vendor specific
@@ -54,7 +49,7 @@ public class PrivacySettings extends PreferenceActivity implements
private int mDialogType;
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.privacy_settings);
final PreferenceScreen screen = getPreferenceScreen();
@@ -63,7 +58,8 @@ public class PrivacySettings extends PreferenceActivity implements
mAutoRestore = (CheckBoxPreference) screen.findPreference(AUTO_RESTORE);
// Vendor specific
- if (getPackageManager().resolveContentProvider(GSETTINGS_PROVIDER, 0) == null) {
+ if (getActivity().getPackageManager().
+ resolveContentProvider(GSETTINGS_PROVIDER, 0) == null) {
screen.removePreference(findPreference(BACKUP_CATEGORY));
}
updateToggles();
@@ -110,7 +106,8 @@ public class PrivacySettings extends PreferenceActivity implements
mDialogType = DIALOG_ERASE_BACKUP;
CharSequence msg = getResources().getText(R.string.backup_erase_dialog_message);
- mConfirmDialog = new AlertDialog.Builder(this).setMessage(msg)
+ // TODO: DialogFragment?
+ mConfirmDialog = new AlertDialog.Builder(getActivity()).setMessage(msg)
.setTitle(R.string.backup_erase_dialog_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.ok, this)
diff --git a/src/com/android/settings/SecuritySettings.java b/src/com/android/settings/SecuritySettings.java
index f86af91d5..e61844852 100644
--- a/src/com/android/settings/SecuritySettings.java
+++ b/src/com/android/settings/SecuritySettings.java
@@ -17,8 +17,7 @@
package com.android.settings;
-import java.util.Observable;
-import java.util.Observer;
+import com.android.internal.widget.LockPatternUtils;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -34,7 +33,6 @@ import android.os.Bundle;
import android.os.SystemProperties;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
@@ -46,12 +44,13 @@ import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
-import com.android.internal.widget.LockPatternUtils;
+import java.util.Observable;
+import java.util.Observer;
/**
* Gesture lock pattern settings.
*/
-public class SecuritySettings extends PreferenceActivity {
+public class SecuritySettings extends SettingsPreferenceFragment {
private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
// Lock Settings
@@ -102,14 +101,14 @@ public class SecuritySettings extends PreferenceActivity {
}
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- mLockPatternUtils = new LockPatternUtils(this);
+ mLockPatternUtils = new LockPatternUtils(getActivity());
mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
- mChooseLockSettingsHelper = new ChooseLockSettingsHelper(this);
+ mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
createPreferenceHierarchy();
@@ -172,22 +171,22 @@ public class SecuritySettings extends PreferenceActivity {
if (TelephonyManager.PHONE_TYPE_CDMA != activePhoneType)
{
PreferenceScreen simLockPreferences = getPreferenceManager()
- .createPreferenceScreen(this);
+ .createPreferenceScreen(getActivity());
simLockPreferences.setTitle(R.string.sim_lock_settings_category);
// Intent to launch SIM lock settings
simLockPreferences.setIntent(new Intent().setClassName(PACKAGE, ICC_LOCK_SETTINGS));
- PreferenceCategory simLockCat = new PreferenceCategory(this);
+ PreferenceCategory simLockCat = new PreferenceCategory(getActivity());
simLockCat.setTitle(R.string.sim_lock_settings_title);
root.addPreference(simLockCat);
simLockCat.addPreference(simLockPreferences);
}
// Passwords
- PreferenceCategory passwordsCat = new PreferenceCategory(this);
+ PreferenceCategory passwordsCat = new PreferenceCategory(getActivity());
passwordsCat.setTitle(R.string.security_passwords_title);
root.addPreference(passwordsCat);
- CheckBoxPreference showPassword = mShowPassword = new CheckBoxPreference(this);
+ CheckBoxPreference showPassword = mShowPassword = new CheckBoxPreference(getActivity());
showPassword.setKey("show_password");
showPassword.setTitle(R.string.show_password);
showPassword.setSummary(R.string.show_password_summary);
@@ -195,26 +194,26 @@ public class SecuritySettings extends PreferenceActivity {
passwordsCat.addPreference(showPassword);
// Device policies
- PreferenceCategory devicePoliciesCat = new PreferenceCategory(this);
+ PreferenceCategory devicePoliciesCat = new PreferenceCategory(getActivity());
devicePoliciesCat.setTitle(R.string.device_admin_title);
root.addPreference(devicePoliciesCat);
- Preference deviceAdminButton = new Preference(this);
+ Preference deviceAdminButton = new Preference(getActivity());
deviceAdminButton.setTitle(R.string.manage_device_admin);
deviceAdminButton.setSummary(R.string.manage_device_admin_summary);
Intent deviceAdminIntent = new Intent();
- deviceAdminIntent.setClass(this, DeviceAdminSettings.class);
+ deviceAdminIntent.setClass(getActivity(), DeviceAdminSettings.class);
deviceAdminButton.setIntent(deviceAdminIntent);
devicePoliciesCat.addPreference(deviceAdminButton);
// Credential storage
- PreferenceCategory credentialsCat = new PreferenceCategory(this);
+ PreferenceCategory credentialsCat = new PreferenceCategory(getActivity());
credentialsCat.setTitle(R.string.credentials_category);
root.addPreference(credentialsCat);
mCredentialStorage.createPreferences(credentialsCat, CredentialStorage.TYPE_KEYSTORE);
// File System Encryption
- PreferenceCategory encryptedfsCat = new PreferenceCategory(this);
+ PreferenceCategory encryptedfsCat = new PreferenceCategory(getActivity());
encryptedfsCat.setTitle(R.string.encrypted_fs_category);
//root.addPreference(encryptedfsCat);
mCredentialStorage.createPreferences(encryptedfsCat, CredentialStorage.TYPE_ENCRYPTEDFS);
@@ -222,7 +221,7 @@ public class SecuritySettings extends PreferenceActivity {
}
@Override
- protected void onResume() {
+ public void onResume() {
super.onResume();
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
@@ -246,7 +245,7 @@ public class SecuritySettings extends PreferenceActivity {
final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) {
- Intent intent = new Intent(this, ChooseLockGeneric.class);
+ Intent intent = new Intent(getActivity(), ChooseLockGeneric.class);
startActivityForResult(intent, SET_OR_CHANGE_LOCK_METHOD_REQUEST);
} else if (KEY_LOCK_ENABLED.equals(key)) {
lockPatternUtils.setLockPatternEnabled(isToggled(preference));
@@ -300,7 +299,7 @@ public class SecuritySettings extends PreferenceActivity {
* @see #confirmPatternThenDisableAndClear
*/
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
createPreferenceHierarchy();
}
@@ -342,7 +341,7 @@ public class SecuritySettings extends PreferenceActivity {
mState = mKeyStore.test();
updatePreferences(mState);
- Intent intent = getIntent();
+ Intent intent = getActivity().getIntent();
if (!mExternal && intent != null &&
Credentials.UNLOCK_ACTION.equals(intent.getAction())) {
mExternal = true;
@@ -351,7 +350,8 @@ public class SecuritySettings extends PreferenceActivity {
} else if (mState == KeyStore.LOCKED) {
showUnlockDialog();
} else {
- finish();
+ // TODO: Verify if this is the right way
+ SecuritySettings.this.getFragmentManager().popBackStack();
}
}
}
@@ -399,7 +399,7 @@ public class SecuritySettings extends PreferenceActivity {
public boolean onPreferenceClick(Preference preference) {
if (preference == mInstallButton) {
- Credentials.getInstance().installFromSdCard(SecuritySettings.this);
+ Credentials.getInstance().installFromSdCard(SecuritySettings.this.getActivity());
} else if (preference == mPasswordButton) {
showPasswordDialog();
} else if (preference == mResetButton) {
@@ -420,11 +420,12 @@ public class SecuritySettings extends PreferenceActivity {
if (button == DialogInterface.BUTTON_POSITIVE) {
Intent intent = new Intent("android.intent.action.MASTER_CLEAR");
intent.putExtra("enableEFS", mWillEnableEncryptedFS);
- sendBroadcast(intent);
+ getActivity().sendBroadcast(intent);
updatePreferences(mState);
} else if (button == DialogInterface.BUTTON_NEGATIVE) {
// Cancel action
- Toast.makeText(SecuritySettings.this, R.string.encrypted_fs_cancel_confirm,
+ Toast.makeText(SecuritySettings.this.getActivity(),
+ R.string.encrypted_fs_cancel_confirm,
Toast.LENGTH_SHORT).show();
updatePreferences(mState);
} else {
@@ -435,7 +436,10 @@ public class SecuritySettings extends PreferenceActivity {
}
public void onDismiss(DialogInterface dialog) {
- if (mSubmit && !isFinishing()) {
+ // TODO:
+ //if (mSubmit && !isFinishing()) {
+
+ if (mSubmit) {
mSubmit = false;
if (!checkPassword((Dialog) dialog)) {
((Dialog) dialog).show();
@@ -444,7 +448,8 @@ public class SecuritySettings extends PreferenceActivity {
}
updatePreferences(mState);
if (mExternal) {
- finish();
+ // TODO:
+ // finish();
}
}
@@ -519,25 +524,25 @@ public class SecuritySettings extends PreferenceActivity {
private void createPreferences(PreferenceCategory category, int type) {
switch(type) {
case TYPE_KEYSTORE:
- mAccessCheckBox = new CheckBoxPreference(SecuritySettings.this);
+ mAccessCheckBox = new CheckBoxPreference(SecuritySettings.this.getActivity());
mAccessCheckBox.setTitle(R.string.credentials_access);
mAccessCheckBox.setSummary(R.string.credentials_access_summary);
mAccessCheckBox.setOnPreferenceChangeListener(this);
category.addPreference(mAccessCheckBox);
- mInstallButton = new Preference(SecuritySettings.this);
+ mInstallButton = new Preference(SecuritySettings.this.getActivity());
mInstallButton.setTitle(R.string.credentials_install_certificates);
mInstallButton.setSummary(R.string.credentials_install_certificates_summary);
mInstallButton.setOnPreferenceClickListener(this);
category.addPreference(mInstallButton);
- mPasswordButton = new Preference(SecuritySettings.this);
+ mPasswordButton = new Preference(SecuritySettings.this.getActivity());
mPasswordButton.setTitle(R.string.credentials_set_password);
mPasswordButton.setSummary(R.string.credentials_set_password_summary);
mPasswordButton.setOnPreferenceClickListener(this);
category.addPreference(mPasswordButton);
- mResetButton = new Preference(SecuritySettings.this);
+ mResetButton = new Preference(SecuritySettings.this.getActivity());
mResetButton.setTitle(R.string.credentials_reset);
mResetButton.setSummary(R.string.credentials_reset_summary);
mResetButton.setOnPreferenceClickListener(this);
@@ -545,7 +550,8 @@ public class SecuritySettings extends PreferenceActivity {
break;
case TYPE_ENCRYPTEDFS:
- mEncryptedFSEnabled = new CheckBoxPreference(SecuritySettings.this);
+ mEncryptedFSEnabled = new CheckBoxPreference(SecuritySettings.this
+ .getActivity());
mEncryptedFSEnabled.setTitle(R.string.encrypted_fs_enable);
mEncryptedFSEnabled.setSummary(R.string.encrypted_fs_enable_summary);
mEncryptedFSEnabled.setOnPreferenceChangeListener(this);
@@ -568,20 +574,20 @@ public class SecuritySettings extends PreferenceActivity {
if (mState == state) {
return;
} else if (state == KeyStore.NO_ERROR) {
- Toast.makeText(SecuritySettings.this, R.string.credentials_enabled,
+ Toast.makeText(SecuritySettings.this.getActivity(), R.string.credentials_enabled,
Toast.LENGTH_SHORT).show();
} else if (state == KeyStore.UNINITIALIZED) {
- Toast.makeText(SecuritySettings.this, R.string.credentials_erased,
+ Toast.makeText(SecuritySettings.this.getActivity(), R.string.credentials_erased,
Toast.LENGTH_SHORT).show();
} else if (state == KeyStore.LOCKED) {
- Toast.makeText(SecuritySettings.this, R.string.credentials_disabled,
+ Toast.makeText(SecuritySettings.this.getActivity(), R.string.credentials_disabled,
Toast.LENGTH_SHORT).show();
}
mState = state;
}
private void showUnlockDialog() {
- View view = View.inflate(SecuritySettings.this,
+ View view = View.inflate(SecuritySettings.this.getActivity(),
R.layout.credentials_unlock_dialog, null);
// Show extra hint only when the action comes from outside.
@@ -589,7 +595,7 @@ public class SecuritySettings extends PreferenceActivity {
view.findViewById(R.id.hint).setVisibility(View.VISIBLE);
}
- Dialog dialog = new AlertDialog.Builder(SecuritySettings.this)
+ Dialog dialog = new AlertDialog.Builder(SecuritySettings.this.getActivity())
.setView(view)
.setTitle(R.string.credentials_unlock)
.setPositiveButton(android.R.string.ok, this)
@@ -601,7 +607,7 @@ public class SecuritySettings extends PreferenceActivity {
}
private void showPasswordDialog() {
- View view = View.inflate(SecuritySettings.this,
+ View view = View.inflate(SecuritySettings.this.getActivity(),
R.layout.credentials_password_dialog, null);
if (mState == KeyStore.UNINITIALIZED) {
@@ -611,7 +617,7 @@ public class SecuritySettings extends PreferenceActivity {
view.findViewById(R.id.old_password).setVisibility(View.VISIBLE);
}
- Dialog dialog = new AlertDialog.Builder(SecuritySettings.this)
+ Dialog dialog = new AlertDialog.Builder(SecuritySettings.this.getActivity())
.setView(view)
.setTitle(R.string.credentials_set_password)
.setPositiveButton(android.R.string.ok, this)
@@ -624,17 +630,18 @@ public class SecuritySettings extends PreferenceActivity {
private void showResetDialog() {
mShowingDialog = DLG_RESET;
- new AlertDialog.Builder(SecuritySettings.this)
+ new AlertDialog.Builder(SecuritySettings.this.getActivity())
.setTitle(android.R.string.dialog_alert_title)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(R.string.credentials_reset_hint)
- .setNeutralButton(getString(android.R.string.ok), this)
- .setNegativeButton(getString(android.R.string.cancel), this)
+ .setNeutralButton(getResources().getString(android.R.string.ok), this)
+ .setNegativeButton(getResources().getString(android.R.string.cancel), this)
.create().show();
}
private void showSwitchEncryptedFSDialog() {
- AlertDialog.Builder builder = new AlertDialog.Builder(SecuritySettings.this)
+ AlertDialog.Builder builder = new AlertDialog.Builder(SecuritySettings.this
+ .getActivity())
.setCancelable(false)
.setTitle(R.string.encrypted_fs_alert_dialog_title);
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index a2816f813..94e732997 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -16,47 +16,233 @@
package com.android.settings;
+import android.app.Activity;
+import android.app.Fragment;
+import android.app.Fragment.InstantiationException;
+import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
+import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
+import android.preference.PreferenceScreen;
+import android.text.TextUtils;
+import android.util.Log;
+import android.view.View;
-public class Settings extends PreferenceActivity {
+import java.util.ArrayList;
+
+/**
+ * Top-level settings activity to handle single pane and double pane UI layout.
+ */
+public class Settings extends Activity
+ implements PreferenceFragment.OnPreferenceStartFragmentCallback,
+ SettingsPreferenceFragment.OnStateListener {
+
+ private static final String TAG = "Settings";
private static final String KEY_PARENT = "parent";
private static final String KEY_CALL_SETTINGS = "call_settings";
private static final String KEY_SYNC_SETTINGS = "sync_settings";
private static final String KEY_SEARCH_SETTINGS = "search_settings";
private static final String KEY_DOCK_SETTINGS = "dock_settings";
-
+
private static final String KEY_OPERATOR_SETTINGS = "operator_settings";
private static final String KEY_MANUFACTURER_SETTINGS = "manufacturer_settings";
+ public static final String EXTRA_SHOW_FRAGMENT = ":settings:show_fragment";
+
+ public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";
+
+ // Temporary, until all top-level settings are converted to fragments
+ private static final String BACK_STACK_PREFS = ":settings:prefs";
+
+ private View mPrefsPane;
+ private View mMainPane;
+ private boolean mSinglePane;
+
+ private ArrayList<CharSequence> mTrail = new ArrayList<CharSequence>();
+
+ /*
+ @Override
+ protected void onResume() {
+ super.onResume();
+ findPreference(KEY_CALL_SETTINGS).setEnabled(!AirplaneModeEnabler.isAirplaneModeOn(this));
+ }
+ */
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
- addPreferencesFromResource(R.xml.settings);
+ setContentView(R.layout.settings_top_level);
+ mPrefsPane = findViewById(R.id.prefs);
+ mMainPane = findViewById(R.id.top_level);
+ mSinglePane = mMainPane == null;
+ if (mSinglePane) mMainPane = mPrefsPane;
- PreferenceGroup parent = (PreferenceGroup) findPreference(KEY_PARENT);
- Utils.updatePreferenceToSpecificActivityOrRemove(this, parent, KEY_SYNC_SETTINGS, 0);
- Utils.updatePreferenceToSpecificActivityOrRemove(this, parent, KEY_SEARCH_SETTINGS, 0);
+ final Intent intent = getIntent();
+ String initialFragment = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
+ Bundle initialArguments = intent.getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
- Preference dockSettings = parent.findPreference(KEY_DOCK_SETTINGS);
- if (getResources().getBoolean(R.bool.has_dock_settings) == false && dockSettings != null) {
- parent.removePreference(dockSettings);
+ if (mSinglePane) {
+ if (initialFragment != null) {
+ showFragment(initialFragment, initialArguments);
+ } else {
+ if (intent.getComponent().getClassName().equals(this.getClass().getName())) {
+ showFragment(TopLevelSettings.class.getName(), null);
+ } else {
+ showFragment(intent.getComponent().getClassName(), intent.getExtras());
+ }
+ }
+ } else {
+ if (!intent.getComponent().getClassName().equals(this.getClass().getName())) {
+ if (showFragment(intent.getComponent().getClassName(), intent.getExtras())) {
+ mMainPane.setVisibility(View.GONE);
+ }
+ }
+ Fragment topLevel = getFragmentManager().findFragmentById(R.id.top_level);
+ if (topLevel != null) {
+ ((TopLevelSettings) topLevel).selectFirst();
+ }
}
+ }
- Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(this, parent,
- KEY_OPERATOR_SETTINGS);
- Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(this, parent,
- KEY_MANUFACTURER_SETTINGS);
+ boolean showFragment(Preference preference) {
+ if (mSinglePane) {
+ startWithFragment(preference.getFragment(), preference.getExtras());
+ return false;
+ } else {
+ return showFragment(preference.getFragment(), preference.getExtras());
+ }
}
-
- @Override
- protected void onResume() {
- super.onResume();
- findPreference(KEY_CALL_SETTINGS).setEnabled(!AirplaneModeEnabler.isAirplaneModeOn(this));
+
+ private void startWithFragment(String fragmentName, Bundle args) {
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.setClass(this, getClass());
+ intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentName);
+ intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
+ startActivity(intent);
}
+ private boolean showFragment(String fragmentClass, Bundle extras) {
+ try {
+ Fragment f = Fragment.instantiate(this, fragmentClass, extras);
+ if (f instanceof SettingsPreferenceFragment) {
+ ((SettingsPreferenceFragment) f).setOnStateListener(this);
+ }
+ getFragmentManager().openTransaction().replace(R.id.prefs, f).commit();
+ return true;
+ } catch (InstantiationException exc) {
+ Log.d(TAG, "Couldn't instantiate fragment " + fragmentClass);
+ return false;
+ }
+ }
+
+ private void addToBreadCrumbs(Fragment fragment) {
+ final CharSequence title = ((PreferenceFragment) fragment)
+ .getPreferenceScreen().getTitle();
+ if (mSinglePane) mTrail.clear();
+ if (mTrail.size() == 0 || !TextUtils.equals(title, mTrail.get(mTrail.size() - 1))) {
+ mTrail.add(title);
+ updateTitle();
+ }
+ }
+
+ private void removeFromBreadCrumbs(Fragment fragment) {
+ if (mTrail.size() > 0) {
+ mTrail.remove(mTrail.size() - 1);
+ }
+ updateTitle();
+ }
+
+ private void updateTitle() {
+ String trail = "";
+ for (CharSequence trailPart : mTrail) {
+ if (trail.length() != 0)
+ trail += " | ";
+ trail = trail + trailPart;
+ }
+ setTitle(trail);
+ }
+
+ public void onCreated(SettingsPreferenceFragment fragment) {
+ Log.d(TAG, "Fragment created " + fragment);
+ addToBreadCrumbs(fragment);
+ }
+
+ public void onDestroyed(SettingsPreferenceFragment fragment) {
+ removeFromBreadCrumbs(fragment);
+ Log.d(TAG, "Fragment destroyed " + fragment);
+ }
+
+ public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
+ Fragment f = Fragment.instantiate(this, pref.getFragment(), pref.getExtras());
+ if (f instanceof SettingsPreferenceFragment) {
+ ((SettingsPreferenceFragment) f).setOnStateListener(this);
+ }
+ getFragmentManager().openTransaction().replace(R.id.prefs, f)
+ .addToBackStack(BACK_STACK_PREFS).commit();
+ return true;
+ }
+
+ public static class TopLevelSettings extends PreferenceFragment {
+
+ private IconPreferenceScreen mHighlightedPreference;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Load the preferences from an XML resource
+ addPreferencesFromResource(R.xml.settings);
+
+ updatePreferenceList();
+ }
+
+ private void updatePreferenceList() {
+ final Activity activity = getActivity();
+ PreferenceGroup parent = (PreferenceGroup) findPreference(KEY_PARENT);
+ Utils.updatePreferenceToSpecificActivityOrRemove(activity, parent,
+ KEY_SYNC_SETTINGS, 0);
+ Utils.updatePreferenceToSpecificActivityOrRemove(activity, parent,
+ KEY_SEARCH_SETTINGS, 0);
+
+ Preference dockSettings = parent.findPreference(KEY_DOCK_SETTINGS);
+ if (activity.getResources().getBoolean(R.bool.has_dock_settings) == false
+ && dockSettings != null) {
+ parent.removePreference(dockSettings);
+ }
+
+ Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(activity, parent,
+ KEY_OPERATOR_SETTINGS);
+ Utils.updatePreferenceToSpecificActivityFromMetaDataOrRemove(activity, parent,
+ KEY_MANUFACTURER_SETTINGS);
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
+ // If it is a fragment preference, replace the prefs pane in the 2 pane UI.
+ final String fragmentClass = preference.getFragment();
+ if (fragmentClass != null) {
+ boolean showed = ((Settings) getActivity()).showFragment(preference);
+ if (showed) {
+ highlight(preference);
+ }
+ return showed;
+ }
+ return false;
+ }
+
+ void highlight(Preference preference) {
+ if (mHighlightedPreference != null) {
+ mHighlightedPreference.setHighlighted(false);
+ }
+ mHighlightedPreference = (IconPreferenceScreen) preference;
+ mHighlightedPreference.setHighlighted(true);
+ }
+
+ void selectFirst() {
+ Preference first = getPreferenceScreen().getPreference(0);
+ onPreferenceTreeClick(getPreferenceScreen(), first);
+ }
+ }
}
diff --git a/src/com/android/settings/SettingsPreferenceFragment.java b/src/com/android/settings/SettingsPreferenceFragment.java
new file mode 100644
index 000000000..83511c9c8
--- /dev/null
+++ b/src/com/android/settings/SettingsPreferenceFragment.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2010 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.app.Dialog;
+import android.app.DialogFragment;
+import android.content.ContentResolver;
+import android.content.pm.PackageManager;
+import android.content.res.Resources;
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+import android.util.Log;
+
+/**
+ * Base class for Settings fragments, with some helper functions and dialog management.
+ */
+public class SettingsPreferenceFragment extends PreferenceFragment {
+
+ private static final String TAG = "SettingsPreferenceFragment";
+
+ private SettingsDialogFragment mDialogFragment;
+
+ private OnStateListener mOnStateListener;
+
+ interface OnStateListener {
+
+ void onCreated(SettingsPreferenceFragment fragment);
+
+ void onDestroyed(SettingsPreferenceFragment fragment);
+ }
+
+ public void setOnStateListener(OnStateListener listener) {
+ mOnStateListener = listener;
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ if (mOnStateListener != null) {
+ mOnStateListener.onCreated(this);
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (mOnStateListener != null) {
+ mOnStateListener.onDestroyed(this);
+ }
+ }
+
+ // Some helpers for functions used by the settings fragments when they were activities
+
+ /**
+ * Returns the ContentResolver from the owning Activity.
+ */
+ protected ContentResolver getContentResolver() {
+ return getActivity().getContentResolver();
+ }
+
+ /**
+ * Returns the specified system service from the owning Activity.
+ */
+ protected Object getSystemService(final String name) {
+ return getActivity().getSystemService(name);
+ }
+
+ /**
+ * Returns the Resources from the owning Activity.
+ */
+ protected Resources getResources() {
+ return getActivity().getResources();
+ }
+
+ /**
+ * Returns the PackageManager from the owning Activity.
+ */
+ protected PackageManager getPackageManager() {
+ return getActivity().getPackageManager();
+ }
+
+ // Dialog management
+
+ protected void showDialog(int dialogId) {
+ if (mDialogFragment != null) {
+ Log.e(TAG, "Old dialog fragment not null!");
+ }
+ mDialogFragment = new SettingsDialogFragment(this, dialogId);
+ mDialogFragment.show(getActivity(), Integer.toString(dialogId));
+ }
+
+ public Dialog onCreateDialog(int dialogId) {
+ return null;
+ }
+
+ protected void removeDialog(int dialogId) {
+ if (mDialogFragment != null && mDialogFragment.getDialogId() == dialogId
+ && mDialogFragment.isVisible()) {
+ mDialogFragment.dismiss();
+ }
+ mDialogFragment = null;
+ }
+
+ static class SettingsDialogFragment extends DialogFragment {
+ private int mDialogId;
+
+ private SettingsPreferenceFragment mFragment;
+
+ SettingsDialogFragment(SettingsPreferenceFragment fragment, int dialogId) {
+ mDialogId = dialogId;
+ mFragment = fragment;
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ return mFragment.onCreateDialog(mDialogId);
+ }
+
+ public int getDialogId() {
+ return mDialogId;
+ }
+ }
+}
diff --git a/src/com/android/settings/SoundSettings.java b/src/com/android/settings/SoundSettings.java
index a735268b1..c5dad8217 100644
--- a/src/com/android/settings/SoundSettings.java
+++ b/src/com/android/settings/SoundSettings.java
@@ -23,26 +23,21 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.Bundle;
-import android.os.RemoteException;
-import android.os.ServiceManager;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.telephony.TelephonyManager;
import android.util.Log;
-import android.view.IWindowManager;
-public class SoundSettings extends PreferenceActivity implements
+public class SoundSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
private static final String TAG = "SoundAndDisplaysSettings";
/** If there is no setting in the provider, use this. */
- private static final int FALLBACK_SCREEN_TIMEOUT_VALUE = 30000;
private static final int FALLBACK_EMERGENCY_TONE_VALUE = 0;
private static final String KEY_SILENT = "silent";
@@ -90,7 +85,7 @@ public class SoundSettings extends PreferenceActivity implements
private PreferenceGroup mSoundSettings;
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ContentResolver resolver = getContentResolver();
int activePhoneType = TelephonyManager.getDefault().getPhoneType();
@@ -137,8 +132,8 @@ public class SoundSettings extends PreferenceActivity implements
mSoundSettings = (PreferenceGroup) findPreference(KEY_SOUND_SETTINGS);
mNotificationPulse = (CheckBoxPreference)
mSoundSettings.findPreference(KEY_NOTIFICATION_PULSE);
- if (mNotificationPulse != null &&
- getResources().getBoolean(R.bool.has_intrusive_led) == false) {
+ if (mNotificationPulse != null
+ && getResources().getBoolean(R.bool.has_intrusive_led) == false) {
mSoundSettings.removePreference(mNotificationPulse);
} else {
try {
@@ -153,20 +148,20 @@ public class SoundSettings extends PreferenceActivity implements
}
@Override
- protected void onResume() {
+ public void onResume() {
super.onResume();
updateState(true);
IntentFilter filter = new IntentFilter(AudioManager.RINGER_MODE_CHANGED_ACTION);
- registerReceiver(mReceiver, filter);
+ getActivity().registerReceiver(mReceiver, filter);
}
@Override
- protected void onPause() {
+ public void onPause() {
super.onPause();
- unregisterReceiver(mReceiver);
+ getActivity().unregisterReceiver(mReceiver);
}
private String getPhoneVibrateSettingValue() {
diff --git a/src/com/android/settings/VoiceInputOutputSettings.java b/src/com/android/settings/VoiceInputOutputSettings.java
index 30beddad7..b07c69ee6 100644
--- a/src/com/android/settings/VoiceInputOutputSettings.java
+++ b/src/com/android/settings/VoiceInputOutputSettings.java
@@ -31,7 +31,6 @@ import android.content.res.XmlResourceParser;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceScreen;
@@ -49,7 +48,7 @@ import java.util.List;
/**
* Settings screen for voice input/output.
*/
-public class VoiceInputOutputSettings extends PreferenceActivity
+public class VoiceInputOutputSettings extends SettingsPreferenceFragment
implements OnPreferenceChangeListener {
private static final String TAG = "VoiceInputOutputSettings";
@@ -67,7 +66,7 @@ public class VoiceInputOutputSettings extends PreferenceActivity
private HashMap<String, ResolveInfo> mAvailableRecognizersMap;
@Override
- protected void onCreate(Bundle icicle) {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.voice_input_output_settings);
diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java
index 60ae20da0..6d1ce8d27 100644
--- a/src/com/android/settings/WirelessSettings.java
+++ b/src/com/android/settings/WirelessSettings.java
@@ -16,28 +16,26 @@
package com.android.settings;
+import com.android.internal.telephony.TelephonyIntents;
+import com.android.internal.telephony.TelephonyProperties;
+import com.android.settings.bluetooth.BluetoothEnabler;
+import com.android.settings.wifi.WifiEnabler;
+
+import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
-import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.provider.Settings;
-import android.util.Log;
-
-import com.android.internal.telephony.TelephonyIntents;
-import com.android.internal.telephony.TelephonyProperties;
-import com.android.settings.bluetooth.BluetoothEnabler;
-import com.android.settings.wifi.WifiEnabler;
-public class WirelessSettings extends PreferenceActivity {
+public class WirelessSettings extends SettingsPreferenceFragment {
private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth";
@@ -71,7 +69,7 @@ public class WirelessSettings extends PreferenceActivity {
return true;
}
// Let the intents be launched by the Preference manager
- return false;
+ return super.onPreferenceTreeClick(preferenceScreen, preference);
}
public static boolean isRadioAllowed(Context context, String type) {
@@ -85,21 +83,22 @@ public class WirelessSettings extends PreferenceActivity {
}
@Override
- protected void onCreate(Bundle savedInstanceState) {
+ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.wireless_settings);
+ final Activity activity = getActivity();
CheckBoxPreference airplane = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
CheckBoxPreference wifi = (CheckBoxPreference) findPreference(KEY_TOGGLE_WIFI);
CheckBoxPreference bt = (CheckBoxPreference) findPreference(KEY_TOGGLE_BLUETOOTH);
- mAirplaneModeEnabler = new AirplaneModeEnabler(this, airplane);
+ mAirplaneModeEnabler = new AirplaneModeEnabler(activity, airplane);
mAirplaneModePreference = (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE);
- mWifiEnabler = new WifiEnabler(this, wifi);
- mBtEnabler = new BluetoothEnabler(this, bt);
+ mWifiEnabler = new WifiEnabler(activity, wifi);
+ mBtEnabler = new BluetoothEnabler(activity, bt);
- String toggleable = Settings.System.getString(getContentResolver(),
+ String toggleable = Settings.System.getString(activity.getContentResolver(),
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
// Manually set dependencies for Wifi when not toggleable.
@@ -122,12 +121,13 @@ public class WirelessSettings extends PreferenceActivity {
// Enable Proxy selector settings if allowed.
Preference mGlobalProxy = findPreference(KEY_PROXY_SETTINGS);
- DevicePolicyManager mDPM = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
+ DevicePolicyManager mDPM = (DevicePolicyManager)
+ activity.getSystemService(Context.DEVICE_POLICY_SERVICE);
mGlobalProxy.setEnabled(mDPM.getGlobalProxyAdmin() == null);
// Disable Tethering if it's not allowed
ConnectivityManager cm =
- (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
+ (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
if (!cm.isTetheringSupported()) {
getPreferenceScreen().removePreference(findPreference(KEY_TETHER_SETTINGS));
} else {
@@ -166,7 +166,7 @@ public class WirelessSettings extends PreferenceActivity {
}
@Override
- protected void onResume() {
+ public void onResume() {
super.onResume();
mAirplaneModeEnabler.resume();
@@ -175,7 +175,7 @@ public class WirelessSettings extends PreferenceActivity {
}
@Override
- protected void onPause() {
+ public void onPause() {
super.onPause();
mAirplaneModeEnabler.pause();
@@ -184,7 +184,7 @@ public class WirelessSettings extends PreferenceActivity {
}
@Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_EXIT_ECM) {
Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
// Set Airplane mode based on the return value and checkbox state
diff --git a/src/com/android/settings/deviceinfo/Memory.java b/src/com/android/settings/deviceinfo/Memory.java
index b57484908..4e27837ed 100644
--- a/src/com/android/settings/deviceinfo/Memory.java
+++ b/src/com/android/settings/deviceinfo/Memory.java
@@ -16,6 +16,9 @@
package com.android.settings.deviceinfo;
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -26,35 +29,26 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.DialogInterface.OnCancelListener;
import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.os.Bundle;
-import android.os.Handler;
+import android.os.Environment;
import android.os.IBinder;
-import android.os.Message;
import android.os.RemoteException;
-import android.os.Environment;
-import android.os.storage.IMountService;
import android.os.ServiceManager;
import android.os.StatFs;
-import android.os.storage.StorageManager;
+import android.os.storage.IMountService;
import android.os.storage.StorageEventListener;
+import android.os.storage.StorageManager;
import android.preference.Preference;
-import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.text.format.Formatter;
import android.util.Log;
import android.widget.Toast;
-import com.android.settings.R;
-
import java.io.File;
-import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-public class Memory extends PreferenceActivity implements OnCancelListener {
+public class Memory extends SettingsPreferenceFragment implements OnCancelListener {
private static final String TAG = "Memory";
private static final boolean localLOGV = false;
@@ -82,7 +76,7 @@ public class Memory extends PreferenceActivity implements OnCancelListener {
private StorageManager mStorageManager = null;
@Override
- protected void onCreate(Bundle icicle) {
+ public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (mStorageManager == null) {
@@ -100,13 +94,13 @@ public class Memory extends PreferenceActivity implements OnCancelListener {
}
@Override
- protected void onResume() {
+ public void onResume() {
super.onResume();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_MEDIA_SCANNER_STARTED);
intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
intentFilter.addDataScheme("file");
- registerReceiver(mReceiver, intentFilter);
+ getActivity().registerReceiver(mReceiver, intentFilter);
updateMemoryStatus();
}
@@ -123,13 +117,13 @@ public class Memory extends PreferenceActivity implements OnCancelListener {
};
@Override
- protected void onPause() {
+ public void onPause() {
super.onPause();
- unregisterReceiver(mReceiver);
+ getActivity().unregisterReceiver(mReceiver);
}
@Override
- protected void onDestroy() {
+ public void onDestroy() {
if (mStorageManager != null && mStorageListener != null) {
mStorageManager.unregisterListener(mStorageListener);
}
@@ -160,7 +154,7 @@ public class Memory extends PreferenceActivity implements OnCancelListener {
return true;
} else if (preference == mSdFormat) {
Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setClass(this, com.android.settings.MediaFormat.class);
+ intent.setClass(getActivity(), com.android.settings.MediaFormat.class);
startActivity(intent);
return true;
}
@@ -176,10 +170,10 @@ public class Memory extends PreferenceActivity implements OnCancelListener {
};
@Override
- public Dialog onCreateDialog(int id, Bundle args) {
+ public Dialog onCreateDialog(int id) {
switch (id) {
case DLG_CONFIRM_UNMOUNT:
- return new AlertDialog.Builder(this)
+ return new AlertDialog.Builder(getActivity())
.setTitle(R.string.dlg_confirm_unmount_title)
.setPositiveButton(R.string.dlg_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
@@ -190,7 +184,7 @@ public class Memory extends PreferenceActivity implements OnCancelListener {
.setOnCancelListener(this)
.create();
case DLG_ERROR_UNMOUNT:
- return new AlertDialog.Builder(this )
+ return new AlertDialog.Builder(getActivity())
.setTitle(R.string.dlg_error_unmount_title)
.setNeutralButton(R.string.dlg_ok, null)
.setMessage(R.string.dlg_error_unmount_text)
@@ -202,7 +196,7 @@ public class Memory extends PreferenceActivity implements OnCancelListener {
private void doUnmount(boolean force) {
// Present a toast here
- Toast.makeText(this, R.string.unmount_inform_text, Toast.LENGTH_SHORT).show();
+ Toast.makeText(getActivity(), R.string.unmount_inform_text, Toast.LENGTH_SHORT).show();
IMountService mountService = getMountService();
String extStoragePath = Environment.getExternalStorageDirectory().toString();
try {
@@ -225,7 +219,6 @@ public class Memory extends PreferenceActivity implements OnCancelListener {
private boolean hasAppsAccessingStorage() throws RemoteException {
String extStoragePath = Environment.getExternalStorageDirectory().toString();
IMountService mountService = getMountService();
- boolean showPidDialog = false;
int stUsers[] = mountService.getStorageUsers(extStoragePath);
if (stUsers != null && stUsers.length > 0) {
return true;
@@ -325,11 +318,12 @@ public class Memory extends PreferenceActivity implements OnCancelListener {
}
private String formatSize(long size) {
- return Formatter.formatFileSize(this, size);
+ return Formatter.formatFileSize(getActivity(), size);
}
public void onCancel(DialogInterface dialog) {
- finish();
+ // TODO: Is this really required?
+ // finish();
}
}