diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-06-08 14:00:43 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-06-08 14:00:54 -0700 |
commit | 9d887a2c452f652624f0d28950c1b69cb37a8e23 (patch) | |
tree | 635a49f9f9b818f49ee4c69d0c02e9d1addfb3c7 /src | |
parent | 54ba601a99cd8cecc2750e305275c40ac2bfba8b (diff) | |
download | android_packages_apps_Trebuchet-9d887a2c452f652624f0d28950c1b69cb37a8e23.tar.gz android_packages_apps_Trebuchet-9d887a2c452f652624f0d28950c1b69cb37a8e23.tar.bz2 android_packages_apps_Trebuchet-9d887a2c452f652624f0d28950c1b69cb37a8e23.zip |
Adding a utility method for getting device prefs
Change-Id: I1e3c7df0a3f4e847b40d722d44890e441cc73509
Diffstat (limited to 'src')
4 files changed, 16 insertions, 23 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index ffda67c38..d48b9ab2c 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -551,6 +551,11 @@ public final class Utilities { LauncherFiles.SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE); } + public static SharedPreferences getDevicePrefs(Context context) { + return context.getSharedPreferences( + LauncherFiles.DEVICE_PREFERENCES_KEY, Context.MODE_PRIVATE); + } + public static boolean isPowerSaverOn(Context context) { PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); return powerManager.isPowerSaveMode(); diff --git a/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java b/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java index 34316644a..d61b5640a 100644 --- a/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java +++ b/src/com/android/launcher3/compat/WallpaperManagerCompatVL.java @@ -17,6 +17,8 @@ package com.android.launcher3.compat; import static android.app.WallpaperManager.FLAG_SYSTEM; +import static com.android.launcher3.Utilities.getDevicePrefs; + import android.app.IntentService; import android.app.WallpaperInfo; import android.app.WallpaperManager; @@ -24,7 +26,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; -import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.BitmapRegionDecoder; @@ -41,7 +42,6 @@ import android.util.Log; import android.util.Pair; import android.util.SparseIntArray; -import com.android.launcher3.LauncherFiles; import com.android.launcher3.Utilities; import java.io.IOException; @@ -63,7 +63,7 @@ public class WallpaperManagerCompatVL extends WallpaperManagerCompat { WallpaperManagerCompatVL(Context context) { mContext = context; - String colors = prefs(mContext).getString(KEY_COLORS, ""); + String colors = getDevicePrefs(mContext).getString(KEY_COLORS, ""); int wallpaperId = -1; if (colors.startsWith(VERSION_PREFIX)) { Pair<Integer, WallpaperColorsCompat> storedValue = parseValue(colors); @@ -106,18 +106,13 @@ public class WallpaperManagerCompatVL extends WallpaperManagerCompat { } private void handleResult(String result) { - prefs(mContext).edit().putString(KEY_COLORS, result).apply(); + getDevicePrefs(mContext).edit().putString(KEY_COLORS, result).apply(); mColorsCompat = parseValue(result).second; for (OnColorsChangedListenerCompat listener : mListeners) { listener.onColorsChanged(mColorsCompat, FLAG_SYSTEM); } } - private static SharedPreferences prefs(Context context) { - return context.getSharedPreferences( - LauncherFiles.DEVICE_PREFERENCES_KEY, Context.MODE_PRIVATE); - } - private static final int getWallpaperId(Context context) { if (!Utilities.ATLEAST_NOUGAT) { return -1; diff --git a/src/com/android/launcher3/graphics/IconShapeOverride.java b/src/com/android/launcher3/graphics/IconShapeOverride.java index a0727fb4b..e2d1d50e4 100644 --- a/src/com/android/launcher3/graphics/IconShapeOverride.java +++ b/src/com/android/launcher3/graphics/IconShapeOverride.java @@ -15,13 +15,14 @@ */ package com.android.launcher3.graphics; +import static com.android.launcher3.Utilities.getDevicePrefs; + import android.annotation.TargetApi; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Build; import android.os.SystemClock; @@ -34,7 +35,6 @@ import android.text.TextUtils; import android.util.Log; import com.android.launcher3.LauncherAppState; -import com.android.launcher3.LauncherFiles; import com.android.launcher3.LauncherModel; import com.android.launcher3.R; import com.android.launcher3.Utilities; @@ -101,7 +101,7 @@ public class IconShapeOverride { } catch (Exception e) { Log.e(TAG, "Unable to override icon shape", e); // revert value. - prefs(context).edit().remove(KEY_PREFERENCE).apply(); + getDevicePrefs(context).edit().remove(KEY_PREFERENCE).apply(); } } @@ -116,11 +116,7 @@ public class IconShapeOverride { } private static String getAppliedValue(Context context) { - return prefs(context).getString(KEY_PREFERENCE, ""); - } - - private static SharedPreferences prefs(Context context) { - return context.getSharedPreferences(LauncherFiles.DEVICE_PREFERENCES_KEY, 0); + return getDevicePrefs(context).getString(KEY_PREFERENCE, ""); } public static void handlePreferenceUi(ListPreference preference) { @@ -189,7 +185,7 @@ public class IconShapeOverride { @Override public void run() { // Synchronously write the preference. - prefs(mContext).edit().putString(KEY_PREFERENCE, mValue).commit(); + getDevicePrefs(mContext).edit().putString(KEY_PREFERENCE, mValue).commit(); // Clear the icon cache. LauncherAppState.getInstance(mContext).getIconCache().clear(); diff --git a/src/com/android/launcher3/provider/ImportDataTask.java b/src/com/android/launcher3/provider/ImportDataTask.java index 3e4cd0192..314f24417 100644 --- a/src/com/android/launcher3/provider/ImportDataTask.java +++ b/src/com/android/launcher3/provider/ImportDataTask.java @@ -16,6 +16,8 @@ package com.android.launcher3.provider; +import static com.android.launcher3.Utilities.getDevicePrefs; + import android.content.ContentProviderOperation; import android.content.ContentValues; import android.content.Context; @@ -36,7 +38,6 @@ import com.android.launcher3.AutoInstallsLayout.LayoutParserCallback; import com.android.launcher3.DefaultLayoutParser; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherAppWidgetInfo; -import com.android.launcher3.LauncherFiles; import com.android.launcher3.LauncherProvider; import com.android.launcher3.LauncherSettings; import com.android.launcher3.LauncherSettings.Favorites; @@ -377,10 +378,6 @@ public class ImportDataTask { return false; } - private static SharedPreferences getDevicePrefs(Context c) { - return c.getSharedPreferences(LauncherFiles.DEVICE_PREFERENCES_KEY, Context.MODE_PRIVATE); - } - private static final int getMyHotseatLayoutId(Context context) { return LauncherAppState.getIDP(context).numHotseatIcons <= 5 ? R.xml.dw_phone_hotseat |