Merge "Refactoring getPreferenceKey method" into ub-launcher3-burnaby-polish

This commit is contained in:
Sunny Goyal
2015-10-20 17:17:08 +00:00
committed by Android (Google) Code Review
11 changed files with 33 additions and 65 deletions

View File

@@ -92,8 +92,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
if (packageNames.isEmpty()) {
return;
}
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
SharedPreferences sp = Utilities.getPrefs(context);
synchronized(sLock) {
Set<String> strings = sp.getStringSet(APPS_PENDING_INSTALL, null);
if (DBG) {
@@ -176,9 +175,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
LauncherAppState app = LauncherAppState.getInstance();
boolean launcherNotLoaded = app.getModel().getCallback() == null;
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
addToInstallQueue(sp, info);
addToInstallQueue(Utilities.getPrefs(context), info);
if (!mUseInstallQueue && !launcherNotLoaded) {
flushInstallQueue(context);
}
@@ -192,8 +189,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
flushInstallQueue(context);
}
static void flushInstallQueue(Context context) {
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
SharedPreferences sp = Utilities.getPrefs(context);
ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp, context);
if (!installQueue.isEmpty()) {
Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();

View File

@@ -426,8 +426,7 @@ public class Launcher extends Activity
app.getInvariantDeviceProfile().landscapeProfile
: app.getInvariantDeviceProfile().portraitProfile;
mSharedPrefs = getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Context.MODE_PRIVATE);
mSharedPrefs = Utilities.getPrefs(this);
mIsSafeModeEnabled = getPackageManager().isSafeMode();
mModel = app.setLauncher(this);
mIconCache = app.getIconCache();
@@ -3636,12 +3635,10 @@ public class Launcher extends Activity
opts.putAll(mLauncherCallbacks.getAdditionalSearchWidgetOptions());
}
SharedPreferences sp = getSharedPreferences(
LauncherAppState.getSharedPreferencesKey(), MODE_PRIVATE);
int widgetId = sp.getInt(QSB_WIDGET_ID, -1);
int widgetId = mSharedPrefs.getInt(QSB_WIDGET_ID, -1);
AppWidgetProviderInfo widgetInfo = mAppWidgetManager.getAppWidgetInfo(widgetId);
if (!searchProvider.provider.flattenToString().equals(
sp.getString(QSB_WIDGET_PROVIDER, null))
mSharedPrefs.getString(QSB_WIDGET_PROVIDER, null))
|| (widgetInfo == null)
|| !widgetInfo.provider.equals(searchProvider.provider)) {
// A valid widget is not already bound.
@@ -3659,7 +3656,7 @@ public class Launcher extends Activity
widgetId = -1;
}
sp.edit()
mSharedPrefs.edit()
.putInt(QSB_WIDGET_ID, widgetId)
.putString(QSB_WIDGET_PROVIDER, searchProvider.provider.flattenToString())
.commit();

View File

@@ -153,14 +153,10 @@ public class LauncherAppState {
return sLauncherProvider.get();
}
public static String getSharedPreferencesKey() {
return LauncherFiles.SHARED_PREFERENCES_KEY;
}
public WidgetPreviewLoader getWidgetCache() {
return mWidgetCache;
}
public void onWallpaperChanged() {
mWallpaperChangedSinceLastCheck = true;
}

View File

@@ -73,9 +73,7 @@ class LauncherClings implements OnClickListener {
LauncherModel.LOADER_FLAG_CLEAR_WORKSPACE
| LauncherModel.LOADER_FLAG_MIGRATE_SHORTCUTS);
// Set the flag to skip the folder cling
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
SharedPreferences.Editor editor = Utilities.getPrefs(mLauncher).edit();
editor.putBoolean(Launcher.USER_HAS_MIGRATED, true);
editor.apply();
// Disable the migration cling
@@ -254,9 +252,7 @@ class LauncherClings implements OnClickListener {
}
public static void synchonouslyMarkFirstRunClingDismissed(Context ctx) {
SharedPreferences prefs = ctx.getSharedPreferences(
LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
SharedPreferences.Editor editor = Utilities.getPrefs(ctx).edit();
editor.putBoolean(WORKSPACE_CLING_DISMISSED_KEY, true);
editor.commit();
}

View File

@@ -257,17 +257,13 @@ public class LauncherProvider extends ContentProvider {
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)));
Utilities.getPrefs(getContext()).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();
Utilities.getPrefs(getContext()).edit().putBoolean(arg, value).apply();
if (mListener != null) {
mListener.onSettingsChanged(arg, value);
}
@@ -343,11 +339,7 @@ public class LauncherProvider extends ContentProvider {
}
public void clearFlagEmptyDbCreated() {
String spKey = LauncherAppState.getSharedPreferencesKey();
getContext().getSharedPreferences(spKey, Context.MODE_PRIVATE)
.edit()
.remove(EMPTY_DATABASE_CREATED)
.commit();
Utilities.getPrefs(getContext()).edit().remove(EMPTY_DATABASE_CREATED).commit();
}
/**
@@ -358,8 +350,7 @@ public class LauncherProvider extends ContentProvider {
* 4) The default configuration for the particular device
*/
synchronized public void loadDefaultFavoritesIfNecessary() {
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp = getContext().getSharedPreferences(spKey, Context.MODE_PRIVATE);
SharedPreferences sp = Utilities.getPrefs(getContext());
if (sp.getBoolean(EMPTY_DATABASE_CREATED, false)) {
Log.d(TAG, "loading default workspace");
@@ -635,15 +626,11 @@ public class LauncherProvider extends ContentProvider {
}
private void setFlagJustLoadedOldDb() {
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp = mContext.getSharedPreferences(spKey, Context.MODE_PRIVATE);
sp.edit().putBoolean(EMPTY_DATABASE_CREATED, false).commit();
Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, false).commit();
}
private void setFlagEmptyDbCreated() {
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp = mContext.getSharedPreferences(spKey, Context.MODE_PRIVATE);
sp.edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
}
@Override

View File

@@ -137,7 +137,7 @@ public final class Utilities {
public static boolean isAllowRotationPrefEnabled(Context context, boolean multiProcess) {
SharedPreferences sharedPrefs = context.getSharedPreferences(
LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE | (multiProcess ?
LauncherFiles.SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE | (multiProcess ?
Context.MODE_MULTI_PROCESS : 0));
boolean allowRotationPref = sharedPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY, false);
return sForceEnableRotation || allowRotationPref;
@@ -754,4 +754,9 @@ public final class Utilities {
public static int longCompare(long lhs, long rhs) {
return lhs < rhs ? -1 : (lhs == rhs ? 0 : 1);
}
public static SharedPreferences getPrefs(Context context) {
return context.getSharedPreferences(
LauncherFiles.SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE);
}
}

View File

@@ -25,7 +25,6 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.UserHandle;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.LongArrayMap;
@@ -104,8 +103,7 @@ public class UserManagerCompatVL extends UserManagerCompatV17 {
if (Utilities.ATLEAST_MARSHMALLOW) {
return mUserManager.getUserCreationTime(user.getUser());
}
SharedPreferences prefs = mContext.getSharedPreferences(
LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
SharedPreferences prefs = Utilities.getPrefs(mContext);
String key = USER_CREATION_TIME_KEY + getSerialNumberForUser(user);
if (!prefs.contains(key)) {
prefs.edit().putLong(key, System.currentTimeMillis()).apply();

View File

@@ -71,7 +71,7 @@ public class MigrateFromRestoreTask {
public MigrateFromRestoreTask(Context context) {
mContext = context;
SharedPreferences prefs = prefs(context);
SharedPreferences prefs = Utilities.getPrefs(context);
Point sourceSize = parsePoint(prefs.getString(KEY_MIGRATION_SOURCE_SIZE, ""));
mSrcX = sourceSize.x;
mSrcY = sourceSize.y;
@@ -745,23 +745,19 @@ public class MigrateFromRestoreTask {
public static void markForMigration(Context context, int srcX, int srcY,
HashSet<String> widgets) {
prefs(context).edit()
Utilities.getPrefs(context).edit()
.putString(KEY_MIGRATION_SOURCE_SIZE, srcX + "," + srcY)
.putStringSet(KEY_MIGRATION_WIDGET_MINSIZE, widgets)
.apply();
}
public static boolean shouldRunTask(Context context) {
return !TextUtils.isEmpty(prefs(context).getString(KEY_MIGRATION_SOURCE_SIZE, ""));
return !TextUtils.isEmpty(Utilities.getPrefs(context).getString(KEY_MIGRATION_SOURCE_SIZE, ""));
}
public static void clearFlags(Context context) {
prefs(context).edit().remove(KEY_MIGRATION_SOURCE_SIZE)
Utilities.getPrefs(context).edit().remove(KEY_MIGRATION_SOURCE_SIZE)
.remove(KEY_MIGRATION_WIDGET_MINSIZE).commit();
}
private static SharedPreferences prefs(Context context) {
return context.getSharedPreferences(LauncherAppState.getSharedPreferencesKey(),
Context.MODE_PRIVATE);
}
}

View File

@@ -1,13 +1,13 @@
package com.android.launcher3.testing;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.Utilities;
import com.android.launcher3.util.TestingUtils;
public class ToggleWeightWatcher extends Activity {
@@ -16,8 +16,7 @@ public class ToggleWeightWatcher extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp = getSharedPreferences(spKey, Context.MODE_PRIVATE);
SharedPreferences sp = Utilities.getPrefs(this);
boolean show = sp.getBoolean(TestingUtils.SHOW_WEIGHT_WATCHER, true);
show = !show;

View File

@@ -13,6 +13,7 @@ import com.android.launcher3.CustomAppWidget;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
import java.util.HashMap;
@@ -39,9 +40,7 @@ public class TestingUtils {
public static void addWeightWatcher(Launcher launcher) {
if (MEMORY_DUMP_ENABLED) {
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp = launcher.getSharedPreferences(spKey, Context.MODE_PRIVATE);
boolean show = sp.getBoolean(SHOW_WEIGHT_WATCHER, true);
boolean show = Utilities.getPrefs(launcher).getBoolean(SHOW_WEIGHT_WATCHER, true);
int id = launcher.getResources().getIdentifier("zzz_weight_watcher", "layout",
launcher.getPackageName());

View File

@@ -28,8 +28,7 @@ public class RotationPreferenceTest extends InstrumentationTestCase {
mDevice = UiDevice.getInstance(getInstrumentation());
mTargetContext = getInstrumentation().getTargetContext();
mTargetPackage = mTargetContext.getPackageName();
mPrefs = mTargetContext.getSharedPreferences(
LauncherAppState.getSharedPreferencesKey(), Context.MODE_PRIVATE);
mPrefs = Utilities.getPrefs(mTargetContext);
mOriginalRotationValue = mPrefs.getBoolean(Utilities.ALLOW_ROTATION_PREFERENCE_KEY, false);
}