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

Commit 03bfd358 authored by Amit Kumar's avatar Amit Kumar
Browse files

Fix #40 - Swiping the launcher screen right jumps over one screen

parent cda6a8a9
Loading
Loading
Loading
Loading
Loading
+15 −31
Original line number Original line Diff line number Diff line
@@ -39,7 +39,6 @@ public class HorizontalPager extends ViewGroup {
    private boolean firstLayout = true;
    private boolean firstLayout = true;


    private int currentPage;
    private int currentPage;
    private int nextPage = INVALID_SCREEN;


    private Scroller mScroller;
    private Scroller mScroller;
    private VelocityTracker mVelocityTracker;
    private VelocityTracker mVelocityTracker;
@@ -131,12 +130,17 @@ public class HorizontalPager extends ViewGroup {


    @Override
    @Override
    public void computeScroll() {
    public void computeScroll() {
        if (mScroller.computeScrollOffset()) {
        if (!mScroller.isFinished() && mScroller.computeScrollOffset()) {
            scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
            int oldX = getScrollX();
            postInvalidate();
            int oldY = getScrollY();
        } else if (nextPage != INVALID_SCREEN) {
            int x = mScroller.getCurrX();
            currentPage = nextPage;
            int y = mScroller.getCurrY();
            nextPage = INVALID_SCREEN;

            if (oldX != x || oldY != y) {
                scrollTo(x, y);
            }
            postInvalidateOnAnimation();
            return;
        }
        }
    }
    }


@@ -209,11 +213,7 @@ public class HorizontalPager extends ViewGroup {
            return false;
            return false;
        }
        }
        int focusableScreen;
        int focusableScreen;
        if (nextPage != INVALID_SCREEN) {
            focusableScreen = nextPage;
        } else {
        focusableScreen = currentPage;
        focusableScreen = currentPage;
        }
        getChildAt(focusableScreen).requestFocus(direction, previouslyFocusedRect);
        getChildAt(focusableScreen).requestFocus(direction, previouslyFocusedRect);
        return false;
        return false;
    }
    }
@@ -454,7 +454,6 @@ public class HorizontalPager extends ViewGroup {
        } else if (getScrollX() > startX + getWidth() / 8) {
        } else if (getScrollX() > startX + getWidth() / 8) {
            whichPage = Math.min(getChildCount() - 1, whichPage + 1);
            whichPage = Math.min(getChildCount() - 1, whichPage + 1);
        }
        }

        snapToPage(whichPage);
        snapToPage(whichPage);
    }
    }


@@ -462,8 +461,7 @@ public class HorizontalPager extends ViewGroup {
        enableChildrenCache();
        enableChildrenCache();


        boolean changingPages = whichPage != currentPage;
        boolean changingPages = whichPage != currentPage;

        currentPage = whichPage;
        nextPage = whichPage;


        View focusedChild = getFocusedChild();
        View focusedChild = getFocusedChild();
        if (focusedChild != null && changingPages && focusedChild == getChildAt(currentPage)) {
        if (focusedChild != null && changingPages && focusedChild == getChildAt(currentPage)) {
@@ -472,7 +470,6 @@ public class HorizontalPager extends ViewGroup {


        final int newX = getScrollXForPage(whichPage);
        final int newX = getScrollXForPage(whichPage);
        final int delta = newX - getScrollX();
        final int delta = newX - getScrollX();
        //mScroller.startScroll(getScrollX(), 0, delta, 0, Math.abs(delta) * 2);
        mScroller.startScroll(getScrollX(), 0, delta, 0, duration);
        mScroller.startScroll(getScrollX(), 0, delta, 0, duration);
        invalidate();
        invalidate();
    }
    }
@@ -497,27 +494,14 @@ public class HorizontalPager extends ViewGroup {
        }
        }
    }
    }


    public void scrollLeft() {
        if (nextPage == INVALID_SCREEN && currentPage > 0 && mScroller.isFinished()) {
            snapToPage(currentPage - 1);
        }
    }

    public void scrollLeft(int duration) {
    public void scrollLeft(int duration) {
        if (nextPage == INVALID_SCREEN && currentPage > 0 && mScroller.isFinished()) {
        if (currentPage > 0 && mScroller.isFinished()) {
            snapToPage(currentPage - 1, duration);
            snapToPage(currentPage - 1, duration);
        }
        }
    }
    }


    public void scrollRight() {
        if (nextPage == INVALID_SCREEN && currentPage < getChildCount() - 1
                && mScroller.isFinished()) {
            snapToPage(currentPage + 1);
        }
    }

    public void scrollRight(int duration) {
    public void scrollRight(int duration) {
        if (nextPage == INVALID_SCREEN && currentPage < getChildCount() - 1
        if (currentPage < getChildCount() - 1
                && mScroller.isFinished()) {
                && mScroller.isFinished()) {
            snapToPage(currentPage + 1, duration);
            snapToPage(currentPage + 1, duration);
        }
        }