Update suggested wallpaper dimensions in onResume

If another launcher runs in between, it might
change the suggested dimensions. This fixes that
case.

Bug: 11667475
This commit is contained in:
Michael Jurka
2013-11-13 17:59:46 +01:00
parent 87f445c8b2
commit a6a0547fa6
5 changed files with 100 additions and 38 deletions

View File

@@ -160,6 +160,13 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<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 --> <!-- Intent received used to install shortcuts from other applications -->
<receiver <receiver
android:name="com.android.launcher3.InstallShortcutReceiver" android:name="com.android.launcher3.InstallShortcutReceiver"

View File

@@ -39,6 +39,7 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks {
private boolean mIsScreenLarge; private boolean mIsScreenLarge;
private float mScreenDensity; private float mScreenDensity;
private int mLongPressTimeout = 300; private int mLongPressTimeout = 300;
private boolean mWallpaperChangedSinceLastCheck;
private static WeakReference<LauncherProvider> sLauncherProvider; private static WeakReference<LauncherProvider> sLauncherProvider;
private static Context sContext; private static Context sContext;
@@ -217,6 +218,16 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks {
return mLongPressTimeout; return mLongPressTimeout;
} }
public void onWallpaperChanged() {
mWallpaperChangedSinceLastCheck = true;
}
public boolean hasWallpaperChangedSinceLastCheck() {
boolean result = mWallpaperChangedSinceLastCheck;
mWallpaperChangedSinceLastCheck = false;
return result;
}
@Override @Override
public void onAvailableSizeChanged(DeviceProfile grid) { public void onAvailableSizeChanged(DeviceProfile grid) {
Utilities.setIconSize(grid.iconSizePx); Utilities.setIconSize(grid.iconSizePx);

View File

@@ -0,0 +1,28 @@
/*
* 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 appState = LauncherAppState.getInstance();
appState.onWallpaperChanged();
}
}

View File

@@ -71,6 +71,8 @@ public class WallpaperCropActivity extends Activity {
public static final int MAX_BMAP_IN_INTENT = 750000; public static final int MAX_BMAP_IN_INTENT = 750000;
private static final float WALLPAPER_SCREENS_SPAN = 2f; private static final float WALLPAPER_SCREENS_SPAN = 2f;
protected static Point sDefaultWallpaperSize;
protected CropView mCropView; protected CropView mCropView;
protected Uri mUri; protected Uri mUri;
@@ -204,32 +206,34 @@ public class WallpaperCropActivity extends Activity {
} }
static protected Point getDefaultWallpaperSize(Resources res, WindowManager windowManager) { static protected Point getDefaultWallpaperSize(Resources res, WindowManager windowManager) {
Point minDims = new Point(); if (sDefaultWallpaperSize == null) {
Point maxDims = new Point(); Point minDims = new Point();
windowManager.getDefaultDisplay().getCurrentSizeRange(minDims, maxDims); Point maxDims = new Point();
windowManager.getDefaultDisplay().getCurrentSizeRange(minDims, maxDims);
int maxDim = Math.max(maxDims.x, maxDims.y); int maxDim = Math.max(maxDims.x, maxDims.y);
int minDim = Math.max(minDims.x, minDims.y); int minDim = Math.max(minDims.x, minDims.y);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
Point realSize = new Point(); Point realSize = new Point();
windowManager.getDefaultDisplay().getRealSize(realSize); windowManager.getDefaultDisplay().getRealSize(realSize);
maxDim = Math.max(realSize.x, realSize.y); maxDim = Math.max(realSize.x, realSize.y);
minDim = Math.min(realSize.x, realSize.y); 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
final int defaultWidth, defaultHeight;
if (isScreenLarge(res)) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
defaultHeight = maxDim;
}
sDefaultWallpaperSize = new Point(defaultWidth, defaultHeight);
} }
return sDefaultWallpaperSize;
// We need to ensure that there is enough extra space in the wallpaper
// for the intended
// parallax effects
final int defaultWidth, defaultHeight;
if (isScreenLarge(res)) {
defaultWidth = (int) (maxDim * wallpaperTravelToScreenWidthRatio(maxDim, minDim));
defaultHeight = maxDim;
} else {
defaultWidth = Math.max((int) (minDim * WALLPAPER_SCREENS_SPAN), maxDim);
defaultHeight = maxDim;
}
return new Point(defaultWidth, defaultHeight);
} }
public static int getRotationFromExif(String path) { public static int getRotationFromExif(String path) {
@@ -785,16 +789,13 @@ public class WallpaperCropActivity extends Activity {
WindowManager windowManager, WindowManager windowManager,
final WallpaperManager wallpaperManager) { final WallpaperManager wallpaperManager) {
final Point defaultWallpaperSize = getDefaultWallpaperSize(res, windowManager); final Point defaultWallpaperSize = getDefaultWallpaperSize(res, windowManager);
// If we have saved a wallpaper width/height, use that instead
new AsyncTask<Void, Void, Void>() { int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, defaultWallpaperSize.x);
public Void doInBackground(Void ... args) { int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, defaultWallpaperSize.y);
// If we have saved a wallpaper width/height, use that instead if (savedWidth != wallpaperManager.getDesiredMinimumWidth() ||
int savedWidth = sharedPrefs.getInt(WALLPAPER_WIDTH_KEY, defaultWallpaperSize.x); savedHeight != wallpaperManager.getDesiredMinimumHeight()) {
int savedHeight = sharedPrefs.getInt(WALLPAPER_HEIGHT_KEY, defaultWallpaperSize.y); wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight);
wallpaperManager.suggestDesiredDimensions(savedWidth, savedHeight); }
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
} }
protected static RectF getMaxCropRect( protected static RectF getMaxCropRect(

View File

@@ -43,6 +43,7 @@ import android.graphics.Rect;
import android.graphics.Region.Op; import android.graphics.Region.Op;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.os.IBinder; import android.os.IBinder;
import android.os.Parcelable; import android.os.Parcelable;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
@@ -437,6 +438,9 @@ public class Workspace extends SmoothPagedView
mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx); mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx);
mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity); mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);
// Set the wallpaper dimensions when Launcher starts up
setWallpaperDimension();
} }
private void setupLayoutTransition() { private void setupLayoutTransition() {
@@ -1232,10 +1236,16 @@ public class Workspace extends SmoothPagedView
} }
protected void setWallpaperDimension() { protected void setWallpaperDimension() {
String spKey = WallpaperCropActivity.getSharedPreferencesKey(); new AsyncTask<Void, Void, Void>() {
SharedPreferences sp = mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS); public Void doInBackground(Void ... args) {
WallpaperPickerActivity.suggestWallpaperDimension(mLauncher.getResources(), String spKey = WallpaperCropActivity.getSharedPreferencesKey();
sp, mLauncher.getWindowManager(), mWallpaperManager); SharedPreferences sp =
mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS);
WallpaperPickerActivity.suggestWallpaperDimension(mLauncher.getResources(),
sp, mLauncher.getWindowManager(), mWallpaperManager);
return null;
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
} }
protected void snapToPage(int whichPage, Runnable r) { protected void snapToPage(int whichPage, Runnable r) {
@@ -1693,6 +1703,12 @@ public class Workspace extends SmoothPagedView
AccessibilityManager am = (AccessibilityManager) AccessibilityManager am = (AccessibilityManager)
getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
sAccessibilityEnabled = am.isEnabled(); sAccessibilityEnabled = am.isEnabled();
// Update wallpaper dimensions if they were changed since last onResume
// (we also always set the wallpaper dimensions in the constructor)
if (LauncherAppState.getInstance().hasWallpaperChangedSinceLastCheck()) {
setWallpaperDimension();
}
} }
@Override @Override
@@ -4001,7 +4017,6 @@ public class Workspace extends SmoothPagedView
// hardware layers on children are enabled on startup, but should be disabled until // hardware layers on children are enabled on startup, but should be disabled until
// needed // needed
updateChildrenLayersEnabled(false); updateChildrenLayersEnabled(false);
setWallpaperDimension();
} }
/** /**