diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2015-06-11 16:18:39 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2015-06-12 11:16:20 -0700 |
commit | 7779d62308b87ca26e3be47df836893f6f7693ec (patch) | |
tree | 15927028a921ac04a931ecf3edb119a39054cef5 /src/com | |
parent | 2d0fc8dccd49a630a1e4a18e6b6b773d7c7bde71 (diff) | |
download | android_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')
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 50 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherAppState.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherFiles.java | 5 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherProvider.java | 34 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherProviderChangeListener.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherSettings.java | 15 | ||||
-rw-r--r-- | src/com/android/launcher3/SettingsActivity.java | 41 | ||||
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 7 |
8 files changed, 97 insertions, 60 deletions
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 076a6e657..ba9a96e77 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -399,29 +399,8 @@ public class Launcher extends Activity } private Stats mStats; - FocusIndicatorView mFocusHandler; - - @Thunk boolean mRotationEnabled = false; - private boolean mScreenOrientationSettingReceiverRegistered = false; - - final private BroadcastReceiver mScreenOrientationSettingReceiver = - new BroadcastReceiver() { - @Thunk Runnable mUpdateOrientationRunnable = new Runnable() { - public void run() { - setOrientation(); - } - }; - - @Override - public void onReceive(Context context, Intent intent) { - mRotationEnabled = intent.getBooleanExtra( - Utilities.SCREEN_ROTATION_SETTING_EXTRA, false); - if (!waitUntilResume(mUpdateOrientationRunnable, true)) { - setOrientation(); - } - } - }; + private boolean mRotationEnabled = false; @Thunk void setOrientation() { if (mRotationEnabled) { @@ -432,6 +411,12 @@ public class Launcher extends Activity } } + private Runnable mUpdateOrientationRunnable = new Runnable() { + public void run() { + setOrientation(); + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { if (DEBUG_STRICT_MODE) { @@ -531,12 +516,6 @@ public class Launcher extends Activity // In case we are on a device with locked rotation, we should look at preferences to check // if the user has specifically allowed rotation. if (!mRotationEnabled) { - String updateOrientationBroadcastPermission = getResources().getString( - R.string.receive_update_orientation_broadcasts_permission); - registerReceiver(mScreenOrientationSettingReceiver, - new IntentFilter(Utilities.SCREEN_ROTATION_SETTING_INTENT), - updateOrientationBroadcastPermission, null); - mScreenOrientationSettingReceiverRegistered = true; mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext()); } @@ -563,6 +542,16 @@ public class Launcher extends Activity } } + @Override + public void onSettingsChanged(String settings, boolean value) { + if (Utilities.ALLOW_ROTATION_PREFERENCE_KEY.equals(settings)) { + mRotationEnabled = value; + if (!waitUntilResume(mUpdateOrientationRunnable, true)) { + mUpdateOrientationRunnable.run(); + } + } + } + private LauncherCallbacks mLauncherCallbacks; public void onPostCreate(Bundle savedInstanceState) { @@ -2031,11 +2020,6 @@ public class Launcher extends Activity public void onDestroy() { super.onDestroy(); - if (mScreenOrientationSettingReceiverRegistered) { - unregisterReceiver(mScreenOrientationSettingReceiver); - mScreenOrientationSettingReceiverRegistered = false; - } - // Remove all pending runnables mHandler.removeMessages(ADVANCE_MSG); mHandler.removeMessages(0); diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java index 76ad8c164..540bdf814 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -21,10 +21,8 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.res.Resources; import android.util.Log; -import android.view.ViewConfiguration; import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; import com.android.launcher3.compat.LauncherAppsCompat; import com.android.launcher3.compat.PackageInstallerCompat; @@ -48,6 +46,7 @@ public class LauncherAppState { private static LauncherAppState INSTANCE; private InvariantDeviceProfile mInvariantDeviceProfile; + private LauncherAccessibilityDelegate mAccessibilityDelegate; public static LauncherAppState getInstance() { diff --git a/src/com/android/launcher3/LauncherFiles.java b/src/com/android/launcher3/LauncherFiles.java index ec4e4f942..c08cd0bf5 100644 --- a/src/com/android/launcher3/LauncherFiles.java +++ b/src/com/android/launcher3/LauncherFiles.java @@ -26,8 +26,6 @@ public class LauncherFiles { public static final String WIDGET_PREVIEWS_DB = "widgetpreviews.db"; public static final String APP_ICONS_DB = "app_icons.db"; - public static final String ROTATION_PREF_FILE = "com.android.launcher3.rotation.prefs"; - public static final List<String> ALL_FILES = Collections.unmodifiableList(Arrays.asList( DEFAULT_WALLPAPER_THUMBNAIL, DEFAULT_WALLPAPER_THUMBNAIL_OLD, @@ -37,8 +35,7 @@ public class LauncherFiles { WALLPAPER_IMAGES_DB, WIDGET_PREVIEWS_DB, MANAGED_USER_PREFERENCES_KEY, - APP_ICONS_DB, - ROTATION_PREF_FILE)); + APP_ICONS_DB)); // TODO: Delete these files on upgrade public static final List<String> OBSOLETE_FILES = Collections.unmodifiableList(Arrays.asList( diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index b5901265c..cb808c22b 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -39,8 +39,10 @@ import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteQueryBuilder; import android.database.sqlite.SQLiteStatement; import android.net.Uri; +import android.os.Binder; import android.os.Build; import android.os.Bundle; +import android.os.Process; import android.os.StrictMode; import android.os.UserManager; import android.text.TextUtils; @@ -237,6 +239,38 @@ public class LauncherProvider extends ContentProvider { return count; } + @Override + public Bundle call(String method, String arg, Bundle extras) { + if (Binder.getCallingUid() != Process.myUid()) { + return null; + } + + switch (method) { + case LauncherSettings.Settings.METHOD_GET_BOOLEAN: { + Bundle result = new Bundle(); + result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, + getContext().getSharedPreferences( + LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE) + .getBoolean(arg, extras.getBoolean( + LauncherSettings.Settings.EXTRA_DEFAULT_VALUE))); + return result; + } + case LauncherSettings.Settings.METHOD_SET_BOOLEAN: { + boolean value = extras.getBoolean(LauncherSettings.Settings.EXTRA_VALUE); + getContext().getSharedPreferences( + LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE) + .edit().putBoolean(arg, value).apply(); + if (mListener != null) { + mListener.onSettingsChanged(arg, value); + } + Bundle result = new Bundle(); + result.putBoolean(LauncherSettings.Settings.EXTRA_VALUE, value); + return result; + } + } + return null; + } + private void notifyListeners() { // always notify the backup agent LauncherBackupAgentHelper.dataChanged(getContext()); diff --git a/src/com/android/launcher3/LauncherProviderChangeListener.java b/src/com/android/launcher3/LauncherProviderChangeListener.java index 0de96fbc4..5b5c6c5ab 100644 --- a/src/com/android/launcher3/LauncherProviderChangeListener.java +++ b/src/com/android/launcher3/LauncherProviderChangeListener.java @@ -8,4 +8,6 @@ package com.android.launcher3; public interface LauncherProviderChangeListener { public void onLauncherProviderChange(); + + public void onSettingsChanged(String settings, boolean value); } diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java index 90e60e450..afdb3dd00 100644 --- a/src/com/android/launcher3/LauncherSettings.java +++ b/src/com/android/launcher3/LauncherSettings.java @@ -305,4 +305,19 @@ public class LauncherSettings { */ static final String OPTIONS = "options"; } + + /** + * Launcher settings + */ + public static final class Settings { + + public static final Uri CONTENT_URI = Uri.parse("content://" + + ProviderConfig.AUTHORITY + "/settings"); + + public static final String METHOD_GET_BOOLEAN = "get_boolean_setting"; + public static final String METHOD_SET_BOOLEAN = "set_boolean_setting"; + + public static final String EXTRA_VALUE = "value"; + public static final String EXTRA_DEFAULT_VALUE = "default_value"; + } } 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; } } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 0cd980cb2..0f52cba2b 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -92,17 +92,14 @@ public final class Utilities { private static boolean sForceEnableRotation = isPropertyEnabled(FORCE_ENABLE_ROTATION_PROPERTY); public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation"; - public static final String SCREEN_ROTATION_SETTING_INTENT = - "come.android.launcher3.SCREEN_ORIENTATION_PREF_CHANGED"; - public static final String SCREEN_ROTATION_SETTING_EXTRA = "screenRotationPref"; public static boolean isPropertyEnabled(String propertyName) { return Log.isLoggable(propertyName, Log.VERBOSE); } public static boolean isAllowRotationPrefEnabled(Context context) { - SharedPreferences sharedPrefs = context.getSharedPreferences(LauncherFiles.ROTATION_PREF_FILE, - Context.MODE_MULTI_PROCESS); + SharedPreferences sharedPrefs = context.getSharedPreferences( + LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE); boolean allowRotationPref = sharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, false); return sForceEnableRotation || allowRotationPref; } |