Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a92e0dfa authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Unifying the workspace translation logic

Change-Id: I82430734c222d43222763fc6edcadac33dc3e076
parent 05e4ba0d
Loading
Loading
Loading
Loading
+40 −12
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.os.IBinder;
import android.os.Parcelable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Property;
import android.util.SparseArray;
import android.view.MotionEvent;
import android.view.View;
@@ -1386,16 +1387,50 @@ public class Workspace extends PagedView
        // 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(getPageIndicator(), transX, alpha);
        setTranslationAndAlpha(getChildAt(getCurrentPage()), transX, alpha);
        setTranslationAndAlpha(mLauncher.getHotseat(), transX, alpha);
        setWorkspaceTranslation(TRANSLATION_X, transX, alpha);
        setHotseatTranslation(TRANSLATION_X, transX, alpha);
    }

    /**
     * Moves the workspace UI in the provided direction.
     * @param direction either {@link #TRANSLATION_X} or {@link #TRANSLATION_Y}
     * @param translation the amound of shift.
     * @param alpha the alpha for the workspace page
     */
    public void setWorkspaceTranslation(
            Property<View, Float> direction, float translation, float alpha) {
        View currentChild = getChildAt(getCurrentPage());
        if (currentChild != null) {
            direction.set(currentChild, translation);
            currentChild.setAlpha(alpha);
        }

        // When the animation finishes, reset all pages, just in case we missed a page.
        if (transX == 0) {
        if (Float.compare(translation, 0) == 0) {
            for (int i = getChildCount() - 1; i >= 0; i--) {
                setTranslationAndAlpha(getChildAt(i), 0, alpha);
                View child = getChildAt(i);
                direction.set(child, translation);
                child.setAlpha(alpha);
            }
        }
    }

    /**
     * Moves the Hotseat UI in the provided direction.
     * @param direction either {@link #TRANSLATION_X} or {@link #TRANSLATION_Y}
     * @param translation the amound of shift.
     * @param alpha the alpha for the hotseat page
     */
    public void setHotseatTranslation(
            Property<View, Float> direction, float translation, float alpha) {
        View pageIndicator = getPageIndicator();
        if (pageIndicator != null) {
            direction.set(pageIndicator, translation);
            pageIndicator.setAlpha(alpha);
        }

        direction.set(mLauncher.getHotseat(), translation);
        mLauncher.getHotseat().setAlpha(alpha);
    }

    @Override
@@ -1410,13 +1445,6 @@ public class Workspace extends PagedView
        return super.getPageShiftMatrix();
    }

    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);
+15 −19
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import com.android.launcher3.Hotseat;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.PagedView;
import com.android.launcher3.Workspace;
import com.android.launcher3.util.TouchController;

/**
@@ -41,10 +42,10 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
    private static final float FINAL_ALPHA = .6f;

    private AllAppsContainerView mAppsView;
    private Workspace mWorkspace;
    private Hotseat mHotseat;
    private Drawable mHotseatBackground;
    private float mHotseatAlpha;
    private View mWorkspaceCurPage;

    private final Launcher mLauncher;
    private final VerticalPullDetector mDetector;
@@ -69,8 +70,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        init();
        if (mLauncher.getWorkspace().isInOverviewMode() ||
                mLauncher.isWidgetsViewVisible()) {
        if (mWorkspace.isInOverviewMode() || mLauncher.isWidgetsViewVisible()) {
            return false;
        }
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
@@ -91,6 +91,7 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
        }
        mAppsView = mLauncher.getAppsView();
        mHotseat = mLauncher.getHotseat();
        mWorkspace = mLauncher.getWorkspace();

        if (mHotseatBackground == null) {
            mHotseatBackground = mHotseat.getBackground();
@@ -110,9 +111,6 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
     * @param start {@code true} if start of new drag.
     */
    public void preparePull(boolean start) {
        // TODO: create a method inside workspace to fetch this easily.
        mWorkspaceCurPage = mLauncher.getWorkspace().getChildAt(
                mLauncher.getWorkspace().getNextPage());
        mHotseat.setVisibility(View.VISIBLE);
        mHotseat.bringToFront();
        if (start) {
@@ -130,10 +128,13 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
                    setProgress(mTranslation);
                }
            } else {
                mLauncher.getWorkspace().onLauncherTransitionPrepare(mLauncher, false, false);
                mWorkspaceCurPage.setVisibility(View.VISIBLE);
                ((CellLayout) mWorkspaceCurPage).getShortcutsAndWidgets().setVisibility(View.VISIBLE);
                ((CellLayout) mWorkspaceCurPage).getShortcutsAndWidgets().setAlpha(1f);
                // TODO: get rid of this workaround to override state change by workspace transition
                mWorkspace.onLauncherTransitionPrepare(mLauncher, false, false);
                View child = ((CellLayout) mWorkspace.getChildAt(mWorkspace.getNextPage()))
                        .getShortcutsAndWidgets();
                child.setVisibility(View.VISIBLE);
                child.setAlpha(1f);

                mAppsView.setSearchBarVisible(false);
                setLightStatusBar(false);
            }
@@ -175,8 +176,10 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
        mAppsView.getRevealView().setAlpha(Math.min(FINAL_ALPHA, Math.max(mHotseatAlpha, alpha)));
        mAppsView.getContentView().setAlpha(alpha);
        mAppsView.setTranslationY(progress);
        setTransAndAlpha(mWorkspaceCurPage, -mTranslation + progress, mAccelInterpolator.getInterpolation(workspaceHotseatAlpha));
        setTransAndAlpha(mHotseat, -mTranslation + progress, workspaceHotseatAlpha);
        mWorkspace.setWorkspaceTranslation(View.TRANSLATION_Y, -mTranslation + progress,
                mAccelInterpolator.getInterpolation(workspaceHotseatAlpha));
        mWorkspace.setHotseatTranslation(
                View.TRANSLATION_Y, -mTranslation + progress, workspaceHotseatAlpha);
    }

    public float getProgress() {
@@ -187,13 +190,6 @@ public class AllAppsTransitionController implements TouchController, VerticalPul
        return ((mTranslation - progress)/mTranslation);
    }

    private void setTransAndAlpha(View v, float transY, float alpha) {
        if (v != null) {
            v.setTranslationY(transY);
            v.setAlpha(alpha);
        }
    }

    @Override
    public void onScrollEnd(float velocity, boolean fling) {
        if (mAppsView == null) {