Adding overlay interaction support

> Sending unboundX to the overlay which is the total untranslated X and not just deltaX from last frame
> Handling overlay callback and translating workspace accordingly

Change-Id: I3bd8d9efac738e9ce131758f0e5ff1b9c1d6a8fc
This commit is contained in:
Sunny Goyal
2016-02-25 09:19:38 -08:00
parent 4ec7134a77
commit d6e208b035
5 changed files with 105 additions and 25 deletions
+72 -14
View File
@@ -55,6 +55,7 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.TextView;
@@ -275,8 +276,11 @@ public class Workspace extends PagedView
LauncherOverlay mLauncherOverlay;
boolean mScrollInteractionBegan;
boolean mStartedSendingScrollEvents;
boolean mShouldSendPageSettled;
int mLastOverlaySroll = 0;
float mLastOverlaySroll = 0;
// Total over scrollX in the overlay direction.
private int mUnboundedScrollX;
// Total over scrollX in the overlay direction.
private float mOverlayTranslation;
// Handles workspace state transitions
private WorkspaceStateTransitionAnimation mStateTransitionAnimation;
@@ -1232,11 +1236,6 @@ public class Workspace extends PagedView
stripEmptyScreens();
mStripScreensOnPageStopMoving = false;
}
if (mShouldSendPageSettled) {
mLauncherOverlay.onScrollSettled();
mShouldSendPageSettled = false;
}
}
protected void onScrollInteractionBegin() {
@@ -1255,6 +1254,27 @@ public class Workspace extends PagedView
public void setLauncherOverlay(LauncherOverlay overlay) {
mLauncherOverlay = overlay;
// A new overlay has been set. Reset event tracking
mStartedSendingScrollEvents = false;
onOverlayScrollChanged(0);
}
@Override
protected int getUnboundedScrollX() {
if (mLauncherOverlay != null) {
if ((mIsRtl && mUnboundedScrollX > mMaxScrollX) ||
(!mIsRtl && mUnboundedScrollX < 0)) {
return mUnboundedScrollX;
}
}
return super.getUnboundedScrollX();
}
@Override
public void scrollTo(int x, int y) {
mUnboundedScrollX = x;
super.scrollTo(x, y);
}
@Override
@@ -1272,15 +1292,10 @@ public class Workspace extends PagedView
if (!mStartedSendingScrollEvents && mScrollInteractionBegan) {
mStartedSendingScrollEvents = true;
mLauncherOverlay.onScrollInteractionBegin();
mShouldSendPageSettled = true;
}
int screenSize = getViewportWidth();
float f = (amount / screenSize);
int progress = (int) Math.abs((f * 100));
mLastOverlaySroll = progress;
mLauncherOverlay.onScrollChange(progress, mIsRtl);
mLastOverlaySroll = Math.abs(amount / getViewportWidth());
mLauncherOverlay.onScrollChange(mLastOverlaySroll, mIsRtl);
} else if (shouldOverScroll) {
dampedOverScroll(amount);
}
@@ -1290,6 +1305,49 @@ public class Workspace extends PagedView
}
}
private final Interpolator mAlphaInterpolator = new DecelerateInterpolator(3f);
/**
* The overlay scroll is being controlled locally, just update our overlay effect
*/
public void onOverlayScrollChanged(float scroll) {
float offset = 0f;
float slip = 0f;
scroll = Math.max(scroll - offset, 0);
scroll = Math.min(1, scroll / (1 - offset));
float alpha = 1 - mAlphaInterpolator.getInterpolation(scroll);
float transX = mLauncher.getDragLayer().getMeasuredWidth() * scroll;
transX *= 1 - slip;
if (mIsRtl) {
transX = -transX;
}
// TODO(adamcohen): figure out a final effect here. We may need to recommend
// different effects based on device performance. On at least one relatively high-end
// device I've tried, translating the launcher causes things to get quite laggy.
setTranslationAndAlpha(mLauncher.getSearchDropTargetBar(), transX, alpha);
setTranslationAndAlpha(getPageIndicator(), transX, alpha);
setTranslationAndAlpha(getChildAt(getCurrentPage()), transX, alpha);
setTranslationAndAlpha(mLauncher.getHotseat(), transX, alpha);
// When the animation finishes, reset all pages, just in case we missed a page.
if (transX == 0) {
for (int i = getChildCount() - 1; i >= 0; i--) {
setTranslationAndAlpha(getChildAt(i), 0, alpha);
}
}
}
private void setTranslationAndAlpha(View v, float transX, float alpha) {
if (v != null) {
v.setTranslationX(transX);
v.setAlpha(alpha);
}
}
@Override
protected void getEdgeVerticalPostion(int[] pos) {
View child = getChildAt(getPageCount() - 1);