Merge "Removing dependency on wallpaper size settings from launcher" into ub-launcher3-calgary

This commit is contained in:
Sunny Goyal
2016-03-21 18:32:41 +00:00
committed by Android (Google) Code Review
5 changed files with 56 additions and 22 deletions
@@ -83,6 +83,8 @@ public class InvariantDeviceProfile {
DeviceProfile landscapeProfile;
DeviceProfile portraitProfile;
public Point defaultWallpaperSize;
public InvariantDeviceProfile() {
}
@@ -166,6 +168,16 @@ public class InvariantDeviceProfile {
largeSide, smallSide, true /* isLandscape */);
portraitProfile = new DeviceProfile(context, this, smallestSize, largestSize,
smallSide, largeSide, false /* isLandscape */);
// We need to ensure that there is enough extra space in the wallpaper
// for the intended parallax effects
if (context.getResources().getConfiguration().smallestScreenWidthDp >= 720) {
defaultWallpaperSize = new Point(
(int) (largeSide * wallpaperTravelToScreenWidthRatio(largeSide, smallSide)),
largeSide);
} else {
defaultWallpaperSize = new Point(Math.max(smallSide * 2, largeSide), largeSide);
}
}
ArrayList<InvariantDeviceProfile> getPredefinedDeviceProfiles() {
@@ -299,4 +311,34 @@ public class InvariantDeviceProfile {
}
return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
}
/**
* As a ratio of screen height, the total distance we want the parallax effect to span
* horizontally
*/
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
// At an aspect ratio of 10/16, the wallpaper parallax effect should span 1.2 * screen width
// We will use these two data points to extrapolate how much the wallpaper parallax effect
// to span (ie travel) at any aspect ratio:
final float ASPECT_RATIO_LANDSCAPE = 16/10f;
final float ASPECT_RATIO_PORTRAIT = 10/16f;
final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE = 1.5f;
final float WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT = 1.2f;
// To find out the desired width at different aspect ratios, we use the following two
// formulas, where the coefficient on x is the aspect ratio (width/height):
// (16/10)x + y = 1.5
// (10/16)x + y = 1.2
// We solve for x and y and end up with a final formula:
final float x =
(WALLPAPER_WIDTH_TO_SCREEN_RATIO_LANDSCAPE - WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT) /
(ASPECT_RATIO_LANDSCAPE - ASPECT_RATIO_PORTRAIT);
final float y = WALLPAPER_WIDTH_TO_SCREEN_RATIO_PORTRAIT - x * ASPECT_RATIO_PORTRAIT;
return x * aspectRatio + y;
}
}
+1 -13
View File
@@ -120,7 +120,6 @@ import com.android.launcher3.util.ViewOnDrawExecutor;
import com.android.launcher3.widget.PendingAddWidgetInfo;
import com.android.launcher3.widget.WidgetHostViewLoader;
import com.android.launcher3.widget.WidgetsContainerView;
import com.android.wallpaperpicker.WallpaperUtils;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -2742,7 +2741,7 @@ public class Launcher extends Activity
int pageScroll = mWorkspace.getScrollForPage(mWorkspace.getPageNearestToCenterOfScreen());
float offset = mWorkspace.mWallpaperOffset.wallpaperOffsetForScroll(pageScroll);
startActivityForResult(new Intent(Intent.ACTION_SET_WALLPAPER).setPackage(getPackageName())
.putExtra(WallpaperUtils.EXTRA_WALLPAPER_OFFSET, offset),
.putExtra(Utilities.EXTRA_WALLPAPER_OFFSET, offset),
REQUEST_PICK_WALLPAPER);
if (mLauncherCallbacks != null) {
@@ -4494,17 +4493,6 @@ public class Launcher extends Activity
}
}
/**
* This method indicates whether or not we should suggest default wallpaper dimensions
* when our wallpaper cropper was not yet used to set a wallpaper.
*/
protected boolean overrideWallpaperDimensions() {
if (mLauncherCallbacks != null) {
return mLauncherCallbacks.overrideWallpaperDimensions();
}
return true;
}
/**
* To be overridden by subclasses to indicate that there is an activity to launch
* before showing the standard launcher experience.
@@ -105,6 +105,7 @@ public interface LauncherCallbacks {
public View getIntroScreen();
public boolean shouldMoveToDefaultScreenOnHomeIntent();
public boolean hasSettings();
@Deprecated
public boolean overrideWallpaperDimensions();
public boolean isLauncherPreinstalled();
public AllAppsSearchBarController getAllAppsSearchBarController();
+3
View File
@@ -119,6 +119,9 @@ public final class Utilities {
public static final boolean ATLEAST_JB_MR2 =
Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
// An intent extra to indicate the horizontal scroll of the wallpaper.
public static final String EXTRA_WALLPAPER_OFFSET = "com.android.launcher3.WALLPAPER_OFFSET";
// These values are same as that in {@link AsyncTask}.
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
+9 -9
View File
@@ -1382,17 +1382,17 @@ public class Workspace extends PagedView
}
protected void setWallpaperDimension() {
new AsyncTask<Void, Void, Void>() {
public Void doInBackground(Void ... args) {
if (Utilities.ATLEAST_KITKAT) {
WallpaperUtils.suggestWallpaperDimension(mLauncher);
} else {
WallpaperUtils.suggestWallpaperDimensionPreK(mLauncher,
mLauncher.overrideWallpaperDimensions());
Utilities.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
final Point size = LauncherAppState.getInstance()
.getInvariantDeviceProfile().defaultWallpaperSize;
if (size.x != mWallpaperManager.getDesiredMinimumWidth()
|| size.y != mWallpaperManager.getDesiredMinimumHeight()) {
mWallpaperManager.suggestDesiredDimensions(size.x, size.y);
}
return null;
}
}.executeOnExecutor(Utilities.THREAD_POOL_EXECUTOR);
});
}
protected void snapToPage(int whichPage, Runnable r) {