summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-03-17 17:04:15 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-03-17 17:04:37 -0700
commit6f866095c0177a794050e578f148b640f4e0a0ab (patch)
treee55c59ad95fdde0ca1b7295efd0911df33fc1007
parent1bc8fc3de2113b7be9df304309a42276d642a8c4 (diff)
downloadandroid_packages_apps_Trebuchet-6f866095c0177a794050e578f148b640f4e0a0ab.tar.gz
android_packages_apps_Trebuchet-6f866095c0177a794050e578f148b640f4e0a0ab.tar.bz2
android_packages_apps_Trebuchet-6f866095c0177a794050e578f148b640f4e0a0ab.zip
Removing dependency on wallpaper size settings from launcher
> Moving wallpaper desired width calculation to xml Bug: 14470153 Change-Id: I8803af158861507a40e5d55e9aa6d515be47eefa
-rw-r--r--src/com/android/launcher3/InvariantDeviceProfile.java42
-rw-r--r--src/com/android/launcher3/Launcher.java14
-rw-r--r--src/com/android/launcher3/LauncherCallbacks.java1
-rw-r--r--src/com/android/launcher3/Utilities.java3
-rw-r--r--src/com/android/launcher3/Workspace.java18
5 files changed, 56 insertions, 22 deletions
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index d60132270..0742df9b4 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -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;
+ }
+
} \ No newline at end of file
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 245b39909..5939878a9 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -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;
@@ -2750,7 +2749,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) {
@@ -4502,17 +4501,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.
*/
diff --git a/src/com/android/launcher3/LauncherCallbacks.java b/src/com/android/launcher3/LauncherCallbacks.java
index fc7ff709f..635d413ba 100644
--- a/src/com/android/launcher3/LauncherCallbacks.java
+++ b/src/com/android/launcher3/LauncherCallbacks.java
@@ -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();
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index ee25e8164..3969d308b 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -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;
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 44a17cce8..1a41e53d7 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -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) {