summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWinson <winsonc@google.com>2016-07-28 12:24:55 -0700
committerWinson <winsonc@google.com>2016-07-28 16:05:47 -0700
commitd96fa1336921cc8c8bb4d773b2229b62df86e6ea (patch)
treef31e96efba08fe614975265a22d950b97d351f27 /src
parent71538da6e2e70af15684cc270a6e67c9b5a010dc (diff)
downloadandroid_packages_apps_Trebuchet-d96fa1336921cc8c8bb4d773b2229b62df86e6ea.tar.gz
android_packages_apps_Trebuchet-d96fa1336921cc8c8bb4d773b2229b62df86e6ea.tar.bz2
android_packages_apps_Trebuchet-d96fa1336921cc8c8bb4d773b2229b62df86e6ea.zip
Fixing RTL wallpaper scrolling.
- Ensure that we map the scroll offsets to the full wallpaper offset range - Default to either edge of the wallpaper (depending on RTL) to match the default system wallpaper behavior (ag/1265418) Bug: 28795125 Bug: 29398681 Change-Id: I36c316095057912d2dda0beb43bd1e6aaeac3fdc
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/util/WallpaperOffsetInterpolator.java87
1 files changed, 45 insertions, 42 deletions
diff --git a/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java b/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java
index 1fbd0dc13..1568beb76 100644
--- a/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java
+++ b/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java
@@ -18,7 +18,7 @@ public class WallpaperOffsetInterpolator implements Choreographer.FrameCallback
private static final int ANIMATION_DURATION = 250;
// Don't use all the wallpaper for parallax until you have at least this many pages
- private static final int MIN_PARALLAX_PAGE_SPAN = 3;
+ private static final int MIN_PARALLAX_PAGE_SPAN = 4;
private final Choreographer mChoreographer;
private final Interpolator mInterpolator;
@@ -90,57 +90,60 @@ public class WallpaperOffsetInterpolator implements Choreographer.FrameCallback
return false;
}
+ /**
+ * TODO: do different behavior if it's a live wallpaper?
+ */
public float wallpaperOffsetForScroll(int scroll) {
- // TODO: do different behavior if it's a live wallpaper?
- // Don't use up all the wallpaper parallax until you have at least
- // MIN_PARALLAX_PAGE_SPAN pages
+ // To match the default wallpaper behavior in the system, we default to either the left
+ // or right edge on initialization
int numScrollingPages = getNumScreensExcludingEmptyAndCustom();
- int parallaxPageSpan;
- if (mWallpaperIsLiveWallpaper) {
- parallaxPageSpan = numScrollingPages - 1;
- } else {
- parallaxPageSpan = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages - 1);
+ if (numScrollingPages <= 1) {
+ return mIsRtl ? 1f : 0f;
}
- mNumPagesForWallpaperParallax = parallaxPageSpan;
- if (mWorkspace.getChildCount() <= 1) {
- if (mIsRtl) {
- return 1 - 1.0f/mNumPagesForWallpaperParallax;
- }
- return 0;
+ // Distribute the wallpaper parallax over a minimum of MIN_PARALLAX_PAGE_SPAN workspace
+ // screens, not including the custom screen, and empty screens (if > MIN_PARALLAX_PAGE_SPAN)
+ if (mWallpaperIsLiveWallpaper) {
+ mNumPagesForWallpaperParallax = numScrollingPages;
+ } else {
+ mNumPagesForWallpaperParallax = Math.max(MIN_PARALLAX_PAGE_SPAN, numScrollingPages);
}
- // Exclude the leftmost page
- int emptyExtraPages = numEmptyScreensToIgnore();
- int firstIndex = mWorkspace.numCustomPages();
- // Exclude the last extra empty screen (if we have > MIN_PARALLAX_PAGE_SPAN pages)
- int lastIndex = mWorkspace.getChildCount() - 1 - emptyExtraPages;
+ // Offset by the custom screen
+ int leftPageIndex;
+ int rightPageIndex;
if (mIsRtl) {
- int temp = firstIndex;
- firstIndex = lastIndex;
- lastIndex = temp;
+ rightPageIndex = mWorkspace.numCustomPages();
+ leftPageIndex = rightPageIndex + numScrollingPages - 1;
+ } else {
+ leftPageIndex = mWorkspace.numCustomPages();
+ rightPageIndex = leftPageIndex + numScrollingPages - 1;
}
- int firstPageScrollX = mWorkspace.getScrollForPage(firstIndex);
- int scrollRange = mWorkspace.getScrollForPage(lastIndex) - firstPageScrollX;
+ // Calculate the scroll range
+ int leftPageScrollX = mWorkspace.getScrollForPage(leftPageIndex);
+ int rightPageScrollX = mWorkspace.getScrollForPage(rightPageIndex);
+ int scrollRange = rightPageScrollX - leftPageScrollX;
if (scrollRange == 0) {
- return 0;
- } else {
- // Sometimes the left parameter of the pages is animated during a layout transition;
- // this parameter offsets it to keep the wallpaper from animating as well
- int adjustedScroll =
- scroll - firstPageScrollX - mWorkspace.getLayoutTransitionOffsetForPage(0);
- float offset = Math.min(1, adjustedScroll / (float) scrollRange);
- offset = Math.max(0, offset);
-
- // On RTL devices, push the wallpaper offset to the right if we don't have enough
- // pages (ie if numScrollingPages < MIN_PARALLAX_PAGE_SPAN)
- if (!mWallpaperIsLiveWallpaper && numScrollingPages < MIN_PARALLAX_PAGE_SPAN
- && mIsRtl) {
- return offset * (parallaxPageSpan - numScrollingPages + 1) / parallaxPageSpan;
- }
- return offset * (numScrollingPages - 1) / parallaxPageSpan;
+ return 0f;
+ }
+
+ // Sometimes the left parameter of the pages is animated during a layout transition;
+ // this parameter offsets it to keep the wallpaper from animating as well
+ int adjustedScroll = scroll - leftPageScrollX -
+ mWorkspace.getLayoutTransitionOffsetForPage(0);
+ float offset = Utilities.boundToRange((float) adjustedScroll / scrollRange, 0f, 1f);
+
+ // The offset is now distributed 0..1 between the left and right pages that we care about,
+ // so we just map that between the pages that we are using for parallax
+ float rtlOffset = 0;
+ if (mIsRtl) {
+ // In RTL, the pages are right aligned, so adjust the offset from the end
+ rtlOffset = (float) ((mNumPagesForWallpaperParallax - 1) - (numScrollingPages - 1)) /
+ (mNumPagesForWallpaperParallax - 1);
}
+ return rtlOffset + offset *
+ ((float) (numScrollingPages - 1) / (mNumPagesForWallpaperParallax - 1));
}
private float wallpaperOffsetForCurrentScroll() {
@@ -182,7 +185,7 @@ public class WallpaperOffsetInterpolator implements Choreographer.FrameCallback
private void setWallpaperOffsetSteps() {
// Set wallpaper offset steps (1 / (number of screens - 1))
- float xOffset = 1.0f / mNumPagesForWallpaperParallax;
+ float xOffset = 1.0f / (mNumPagesForWallpaperParallax - 1);
if (xOffset != mLastSetWallpaperOffsetSteps) {
mWallpaperManager.setWallpaperOffsetSteps(xOffset, 1.0f);
mLastSetWallpaperOffsetSteps = xOffset;