summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/SettingsActivity.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-06-11 16:18:39 -0700
committerSunny Goyal <sunnygoyal@google.com>2015-06-12 11:16:20 -0700
commit7779d62308b87ca26e3be47df836893f6f7693ec (patch)
tree15927028a921ac04a931ecf3edb119a39054cef5 /src/com/android/launcher3/SettingsActivity.java
parent2d0fc8dccd49a630a1e4a18e6b6b773d7c7bde71 (diff)
downloadandroid_packages_apps_Trebuchet-7779d62308b87ca26e3be47df836893f6f7693ec.tar.gz
android_packages_apps_Trebuchet-7779d62308b87ca26e3be47df836893f6f7693ec.tar.bz2
android_packages_apps_Trebuchet-7779d62308b87ca26e3be47df836893f6f7693ec.zip
Using content provider to update launcher settings
> Removing cross process preference file > Removed broadcast listener management for settings changes > Defining content provider method to get/set laucnehr preferences Change-Id: Ida36eac0ab17c1d48fedc9404817a53a89b36c4f
Diffstat (limited to 'src/com/android/launcher3/SettingsActivity.java')
-rw-r--r--src/com/android/launcher3/SettingsActivity.java41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java
index 27763f545..dab71c862 100644
--- a/src/com/android/launcher3/SettingsActivity.java
+++ b/src/com/android/launcher3/SettingsActivity.java
@@ -17,12 +17,11 @@
package com.android.launcher3;
import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
+import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceFragment;
-import android.preference.PreferenceScreen;
+import android.preference.SwitchPreference;
/**
* Settings activity for Launcher. Currently implements the following setting: Allow rotation
@@ -41,26 +40,36 @@ public class SettingsActivity extends Activity {
/**
* This fragment shows the launcher preferences.
*/
- @SuppressWarnings("WeakerAccess")
- public static class LauncherSettingsFragment extends PreferenceFragment {
+ public static class LauncherSettingsFragment extends PreferenceFragment
+ implements OnPreferenceChangeListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
- getPreferenceManager().setSharedPreferencesName(LauncherFiles.ROTATION_PREF_FILE);
addPreferencesFromResource(R.xml.launcher_preferences);
+
+ SwitchPreference pref = (SwitchPreference) findPreference(
+ Utilities.ALLOW_ROTATION_PREFERENCE_KEY);
+ pref.setPersistent(false);
+
+ Bundle extras = new Bundle();
+ extras.putBoolean(LauncherSettings.Settings.EXTRA_DEFAULT_VALUE, false);
+ Bundle value = getActivity().getContentResolver().call(
+ LauncherSettings.Settings.CONTENT_URI,
+ LauncherSettings.Settings.METHOD_GET_BOOLEAN,
+ Utilities.ALLOW_ROTATION_PREFERENCE_KEY, extras);
+ pref.setChecked(value.getBoolean(LauncherSettings.Settings.EXTRA_VALUE));
+
+ pref.setOnPreferenceChangeListener(this);
}
@Override
- public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
- Preference preference) {
- boolean allowRotation = getPreferenceManager().getSharedPreferences().getBoolean(
- Utilities.ALLOW_ROTATION_PREFERENCE_KEY, false);
- Intent rotationSetting = new Intent(Utilities.SCREEN_ROTATION_SETTING_INTENT);
- String launchBroadcastPermission = getResources().getString(
- R.string.receive_update_orientation_broadcasts_permission);
- rotationSetting.putExtra(Utilities.SCREEN_ROTATION_SETTING_EXTRA, allowRotation);
- getActivity().sendBroadcast(rotationSetting, launchBroadcastPermission);
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ Bundle extras = new Bundle();
+ extras.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, (Boolean) newValue);
+ getActivity().getContentResolver().call(
+ LauncherSettings.Settings.CONTENT_URI,
+ LauncherSettings.Settings.METHOD_SET_BOOLEAN,
+ preference.getKey(), extras);
return true;
}
}