summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-08-19 12:43:27 -0700
committerSunny Goyal <sunnygoyal@google.com>2015-08-19 12:59:29 -0700
commit4b17147c28488c20b01aea18297fd6a327bad213 (patch)
tree42536f7440a140239fc2458954a96d5ff8802581
parent5f195074b7a29da69482dbcd92dc3263d3ac50ce (diff)
downloadandroid_packages_apps_Trebuchet-4b17147c28488c20b01aea18297fd6a327bad213.tar.gz
android_packages_apps_Trebuchet-4b17147c28488c20b01aea18297fd6a327bad213.tar.bz2
android_packages_apps_Trebuchet-4b17147c28488c20b01aea18297fd6a327bad213.zip
Updating logic for setting wallpaper desired size
> Only setting desired size on wallpaper change for pre kitkat > Removing wallpaper change receiver from manifest > Removing multi-process wallpaper shared prefs for kitkat+ Bug: 23353784 Change-Id: Iba72d32871ee50b75807e2284a73a691bcddc472
-rw-r--r--AndroidManifest.xml7
-rw-r--r--WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java29
-rw-r--r--src/com/android/launcher3/LauncherAppState.java17
-rw-r--r--src/com/android/launcher3/WallpaperChangedReceiver.java29
-rw-r--r--src/com/android/launcher3/Workspace.java13
-rw-r--r--src/com/android/launcher3/util/WallpaperUtils.java81
6 files changed, 74 insertions, 102 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ce6fb2174..ef210d4bb 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -178,13 +178,6 @@
>
</service>
- <receiver
- android:name="com.android.launcher3.WallpaperChangedReceiver">
- <intent-filter>
- <action android:name="android.intent.action.WALLPAPER_CHANGED" />
- </intent-filter>
- </receiver>
-
<!-- Intent received used to install shortcuts from other applications -->
<receiver
android:name="com.android.launcher3.InstallShortcutReceiver"
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
index 4727d0653..eb473804f 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
@@ -19,10 +19,7 @@ package com.android.launcher3;
import android.annotation.TargetApi;
import android.app.ActionBar;
import android.app.Activity;
-import android.app.WallpaperManager;
-import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
@@ -58,9 +55,6 @@ import java.util.WeakHashMap;
public class WallpaperCropActivity extends BaseActivity implements Handler.Callback {
private static final String LOGTAG = "Launcher3.CropActivity";
- protected static final String WALLPAPER_WIDTH_KEY = WallpaperUtils.WALLPAPER_WIDTH_KEY;
- protected static final String WALLPAPER_HEIGHT_KEY = WallpaperUtils.WALLPAPER_HEIGHT_KEY;
-
/**
* The maximum bitmap size we allow to be returned through the intent.
* Intents have a maximum of 1MB in total size. However, the Bitmap seems to
@@ -69,7 +63,6 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
* array instead of a Bitmap instance to avoid overhead.
*/
public static final int MAX_BMAP_IN_INTENT = 750000;
- public static final float WALLPAPER_SCREENS_SPAN = WallpaperUtils.WALLPAPER_SCREENS_SPAN;
private static final int MSG_LOAD_IMAGE = 1;
@@ -302,7 +295,7 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
final Point bounds = cropTask.getImageBounds();
Runnable onEndCrop = new Runnable() {
public void run() {
- updateWallpaperDimensions(bounds.x, bounds.y);
+ WallpaperUtils.saveWallpaperDimensions(bounds.x, bounds.y, WallpaperCropActivity.this);
if (finishActivityWhenDone) {
setResult(Activity.RESULT_OK);
finish();
@@ -328,7 +321,7 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
public void run() {
// Passing 0, 0 will cause launcher to revert to using the
// default wallpaper size
- updateWallpaperDimensions(0, 0);
+ WallpaperUtils.saveWallpaperDimensions(0, 0, WallpaperCropActivity.this);
if (finishActivityWhenDone) {
setResult(Activity.RESULT_OK);
finish();
@@ -420,7 +413,7 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
Runnable onEndCrop = new Runnable() {
public void run() {
- updateWallpaperDimensions(outWidth, outHeight);
+ WallpaperUtils.saveWallpaperDimensions(outWidth, outHeight, WallpaperCropActivity.this);
if (finishActivityWhenDone) {
setResult(Activity.RESULT_OK);
finish();
@@ -435,22 +428,6 @@ public class WallpaperCropActivity extends BaseActivity implements Handler.Callb
cropTask.execute();
}
- protected void updateWallpaperDimensions(int width, int height) {
- String spKey = LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY;
- SharedPreferences sp = getContext().getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
- SharedPreferences.Editor editor = sp.edit();
- if (width != 0 && height != 0) {
- editor.putInt(WALLPAPER_WIDTH_KEY, width);
- editor.putInt(WALLPAPER_HEIGHT_KEY, height);
- } else {
- editor.remove(WALLPAPER_WIDTH_KEY);
- editor.remove(WALLPAPER_HEIGHT_KEY);
- }
- editor.commit();
- WallpaperUtils.suggestWallpaperDimension(getResources(),
- sp, getWindowManager(), WallpaperManager.getInstance(getContext()), true);
- }
-
static class LoadRequest {
BitmapSource src;
boolean touchEnabled;
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index f2d58ffdc..5a7fadb5b 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -17,6 +17,7 @@
package com.android.launcher3;
import android.app.SearchManager;
+import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -37,7 +38,7 @@ public class LauncherAppState {
private final IconCache mIconCache;
private final WidgetPreviewLoader mWidgetCache;
- private boolean mWallpaperChangedSinceLastCheck;
+ @Thunk boolean mWallpaperChangedSinceLastCheck;
private static WeakReference<LauncherProvider> sLauncherProvider;
private static Context sContext;
@@ -100,6 +101,16 @@ public class LauncherAppState {
sContext.registerReceiver(mModel, filter);
UserManagerCompat.getInstance(sContext).enableAndResetCache();
+
+ if (!Utilities.ATLEAST_KITKAT) {
+ sContext.registerReceiver(new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ mWallpaperChangedSinceLastCheck = true;
+ }
+ }, new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED));
+ }
}
/**
@@ -156,10 +167,6 @@ public class LauncherAppState {
public WidgetPreviewLoader getWidgetCache() {
return mWidgetCache;
}
-
- public void onWallpaperChanged() {
- mWallpaperChangedSinceLastCheck = true;
- }
public boolean hasWallpaperChangedSinceLastCheck() {
boolean result = mWallpaperChangedSinceLastCheck;
diff --git a/src/com/android/launcher3/WallpaperChangedReceiver.java b/src/com/android/launcher3/WallpaperChangedReceiver.java
deleted file mode 100644
index 2d5612f12..000000000
--- a/src/com/android/launcher3/WallpaperChangedReceiver.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-public class WallpaperChangedReceiver extends BroadcastReceiver {
- public void onReceive(Context context, Intent data) {
- LauncherAppState.setApplicationContext(context.getApplicationContext());
- LauncherAppState appState = LauncherAppState.getInstance();
- appState.onWallpaperChanged();
- }
-}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 387fd1f3d..f299a45eb 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -28,7 +28,6 @@ import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Context;
-import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
@@ -1308,12 +1307,12 @@ public class Workspace extends PagedView
protected void setWallpaperDimension() {
new AsyncTask<Void, Void, Void>() {
public Void doInBackground(Void ... args) {
- String spKey = LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY;
- SharedPreferences sp =
- mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
- WallpaperUtils.suggestWallpaperDimension(mLauncher.getResources(),
- sp, mLauncher.getWindowManager(), mWallpaperManager,
- mLauncher.overrideWallpaperDimensions());
+ if (Utilities.ATLEAST_KITKAT) {
+ WallpaperUtils.suggestWallpaperDimension(mLauncher);
+ } else {
+ WallpaperUtils.suggestWallpaperDimensionPreK(mLauncher,
+ mLauncher.overrideWallpaperDimensions());
+ }
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
diff --git a/src/com/android/launcher3/util/WallpaperUtils.java b/src/com/android/launcher3/util/WallpaperUtils.java
index b9fccbcfd..a5251e190 100644
--- a/src/com/android/launcher3/util/WallpaperUtils.java
+++ b/src/com/android/launcher3/util/WallpaperUtils.java
@@ -17,13 +17,16 @@
package com.android.launcher3.util;
import android.annotation.TargetApi;
+import android.app.Activity;
import android.app.WallpaperManager;
+import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Point;
import android.os.Build;
import android.view.WindowManager;
+import com.android.launcher3.LauncherFiles;
import com.android.launcher3.Utilities;
/**
@@ -35,28 +38,59 @@ public final class WallpaperUtils {
public static final String WALLPAPER_HEIGHT_KEY = "wallpaper.height";
public static final float WALLPAPER_SCREENS_SPAN = 2f;
- public static void suggestWallpaperDimension(Resources res,
- final SharedPreferences sharedPrefs,
- WindowManager windowManager,
- final WallpaperManager wallpaperManager, boolean fallBackToDefaults) {
- final Point defaultWallpaperSize = WallpaperUtils.getDefaultWallpaperSize(res, windowManager);
- // If we have saved a wallpaper width/height, use that instead
+ public static void saveWallpaperDimensions(int width, int height, Activity activity) {
+ if (Utilities.ATLEAST_KITKAT) {
+ // From Kitkat onwards, ImageWallpaper does not care about the
+ // desired width and desired height of the wallpaper.
+ return;
+ }
+ String spKey = LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY;
+ SharedPreferences sp = activity.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
+ SharedPreferences.Editor editor = sp.edit();
+ if (width != 0 && height != 0) {
+ editor.putInt(WALLPAPER_WIDTH_KEY, width);
+ editor.putInt(WALLPAPER_HEIGHT_KEY, height);
+ } else {
+ editor.remove(WALLPAPER_WIDTH_KEY);
+ editor.remove(WALLPAPER_HEIGHT_KEY);
+ }
+ editor.commit();
+ suggestWallpaperDimensionPreK(activity, true);
+ }
+
+ public static void suggestWallpaperDimensionPreK(
+ Activity activity, boolean fallBackToDefaults) {
+ final Point defaultWallpaperSize = getDefaultWallpaperSize(
+ activity.getResources(), activity.getWindowManager());
- int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, -1);
- int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, -1);
+ SharedPreferences sp = activity.getSharedPreferences(
+ LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY, Context.MODE_MULTI_PROCESS);
+ // If we have saved a wallpaper width/height, use that instead
+ int width = sp.getInt(WALLPAPER_WIDTH_KEY, -1);
+ int height = sp.getInt(WALLPAPER_HEIGHT_KEY, -1);
- if (savedWidth == -1 || savedHeight == -1) {
+ if (width == -1 || height == -1) {
if (!fallBackToDefaults) {
return;
} else {
- savedWidth = defaultWallpaperSize.x;
- savedHeight = defaultWallpaperSize.y;
+ width = defaultWallpaperSize.x;
+ height = defaultWallpaperSize.y;
}
}
- if (savedWidth != wallpaperManager.getDesiredMinimumWidth() ||
- savedHeight != wallpaperManager.getDesiredMinimumHeight()) {
- wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight);
+ WallpaperManager wm = WallpaperManager.getInstance(activity);
+ if (width != wm.getDesiredMinimumWidth() || height != wm.getDesiredMinimumHeight()) {
+ wm.suggestDesiredDimensions(width, height);
+ }
+ }
+
+ public static void suggestWallpaperDimension(Activity activity) {
+ // Only live wallpapers care about desired size. Update the size to what launcher expects.
+ final Point size = getDefaultWallpaperSize(
+ activity.getResources(), activity.getWindowManager());
+ WallpaperManager wm = WallpaperManager.getInstance(activity);
+ if (size.x != wm.getDesiredMinimumWidth() || size.y != wm.getDesiredMinimumHeight()) {
+ wm.suggestDesiredDimensions(size.x, size.y);
}
}
@@ -64,7 +98,7 @@ public final class WallpaperUtils {
* As a ratio of screen height, the total distance we want the parallax effect to span
* horizontally
*/
- public static float wallpaperTravelToScreenWidthRatio(int width, int height) {
+ private static float wallpaperTravelToScreenWidthRatio(int width, int height) {
float aspectRatio = width / (float) height;
// At an aspect ratio of 16/10, the wallpaper parallax effect should span 1.5 * screen width
@@ -94,19 +128,10 @@ public final class WallpaperUtils {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static Point getDefaultWallpaperSize(Resources res, WindowManager windowManager) {
if (sDefaultWallpaperSize == null) {
- Point minDims = new Point();
- Point maxDims = new Point();
- windowManager.getDefaultDisplay().getCurrentSizeRange(minDims, maxDims);
-
- int maxDim = Math.max(maxDims.x, maxDims.y);
- int minDim = Math.max(minDims.x, minDims.y);
-
- if (Utilities.ATLEAST_JB_MR1) {
- Point realSize = new Point();
- windowManager.getDefaultDisplay().getRealSize(realSize);
- maxDim = Math.max(realSize.x, realSize.y);
- minDim = Math.min(realSize.x, realSize.y);
- }
+ Point realSize = new Point();
+ windowManager.getDefaultDisplay().getRealSize(realSize);
+ int maxDim = Math.max(realSize.x, realSize.y);
+ int minDim = Math.min(realSize.x, realSize.y);
// We need to ensure that there is enough extra space in the wallpaper
// for the intended parallax effects