Merge "Adding a utility method for getting device prefs" into ub-launcher3-dorval-polish

This commit is contained in:
TreeHugger Robot
2017-06-08 21:32:51 +00:00
committed by Android (Google) Code Review
4 changed files with 16 additions and 23 deletions
+5
View File
@@ -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();
@@ -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;
@@ -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();
@@ -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