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

Commit 3b0883fc authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing some RTL issues with scrollable folder

> folder name alingment
> scroll hint direction
> Fake animation direction for icons changing pages

Change-Id: Ia17ab2861a6d72c876806427e2de1682976b7671
parent 50062408
Loading
Loading
Loading
Loading
+28 −39
Original line number Diff line number Diff line
@@ -76,11 +76,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
    static final int STATE_ANIMATING = 1;
    static final int STATE_OPEN = 2;

    /**
     * Fraction of the width to scroll when showing the next page hint.
     */
    private static final float SCROLL_HINT_FRACTION = 0.07f;

    /**
     * Time for which the scroll hint is shown before automatically changing page.
     */
@@ -656,35 +651,36 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList

        float x = r[0];
        int currentPage = mPagedView.getNextPage();
        int cellWidth = mPagedView.getCurrentCellLayout().getCellWidth();
        if (currentPage > 0 && x < cellWidth * ICON_OVERSCROLL_WIDTH_FACTOR) {
            // Show scroll hint on the left
            if (mScrollHintDir != DragController.SCROLL_LEFT) {
                mPagedView.showScrollHint(-SCROLL_HINT_FRACTION);
                mScrollHintDir = DragController.SCROLL_LEFT;
            }

            // Set alarm for when the hint is complete
            if (!mOnScrollHintAlarm.alarmPending() || mCurrentScrollDir != DragController.SCROLL_LEFT) {
                mCurrentScrollDir = DragController.SCROLL_LEFT;
                mOnScrollHintAlarm.cancelAlarm();
                mOnScrollHintAlarm.setOnAlarmListener(new OnScrollHintListener(d));
                mOnScrollHintAlarm.setAlarm(SCROLL_HINT_DURATION);
        float cellOverlap = mPagedView.getCurrentCellLayout().getCellWidth()
                * ICON_OVERSCROLL_WIDTH_FACTOR;
        boolean isOutsideLeftEdge = x < cellOverlap;
        boolean isOutsideRightEdge = x > (getWidth() - cellOverlap);

                mReorderAlarm.cancelAlarm();
                mTargetRank = mEmptyCellRank;
        if (currentPage > 0 && (mPagedView.rtlLayout ? isOutsideRightEdge : isOutsideLeftEdge)) {
            showScrollHint(DragController.SCROLL_LEFT, d);
        } else if (currentPage < (mPagedView.getPageCount() - 1)
                && (mPagedView.rtlLayout ? isOutsideLeftEdge : isOutsideRightEdge)) {
            showScrollHint(DragController.SCROLL_RIGHT, d);
        } else {
            mOnScrollHintAlarm.cancelAlarm();
            if (mScrollHintDir != DragController.SCROLL_NONE) {
                mPagedView.clearScrollHint();
                mScrollHintDir = DragController.SCROLL_NONE;
            }
        }
        } else if (currentPage < (mPagedView.getPageCount() - 1) &&
                (x > (getWidth() - cellWidth * ICON_OVERSCROLL_WIDTH_FACTOR))) {
    }

    private void showScrollHint(int direction, DragObject d) {
        // Show scroll hint on the right
            if (mScrollHintDir != DragController.SCROLL_RIGHT) {
                mPagedView.showScrollHint(SCROLL_HINT_FRACTION);
                mScrollHintDir = DragController.SCROLL_RIGHT;
        if (mScrollHintDir != direction) {
            mPagedView.showScrollHint(direction);
            mScrollHintDir = direction;
        }

        // Set alarm for when the hint is complete
            if (!mOnScrollHintAlarm.alarmPending() || mCurrentScrollDir != DragController.SCROLL_RIGHT) {
                mCurrentScrollDir = DragController.SCROLL_RIGHT;
        if (!mOnScrollHintAlarm.alarmPending() || mCurrentScrollDir != direction) {
            mCurrentScrollDir = direction;
            mOnScrollHintAlarm.cancelAlarm();
            mOnScrollHintAlarm.setOnAlarmListener(new OnScrollHintListener(d));
            mOnScrollHintAlarm.setAlarm(SCROLL_HINT_DURATION);
@@ -692,13 +688,6 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
            mReorderAlarm.cancelAlarm();
            mTargetRank = mEmptyCellRank;
        }
        } else {
            mOnScrollHintAlarm.cancelAlarm();
            if (mScrollHintDir != DragController.SCROLL_NONE) {
                mPagedView.clearScrollHint();
                mScrollHintDir = DragController.SCROLL_NONE;
            }
        }
    }

    OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
+15 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.launcher3;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.LayoutDirection;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
@@ -53,11 +54,18 @@ public class FolderPagedView extends PagedView implements Folder.FolderContent {
    private static final int SORT_ANIM_HIDE_DURATION = 130;
    private static final int SORT_ANIM_SHOW_DURATION = 160;

    /**
     * Fraction of the width to scroll when showing the next page hint.
     */
    private static final float SCROLL_HINT_FRACTION = 0.07f;

    private static final int[] sTempPosArray = new int[2];

    // TODO: Remove this restriction
    private static final int MAX_ITEMS_PER_PAGE = 4;

    public final boolean rtlLayout;

    private final LayoutInflater mInflater;
    private final IconCache mIconCache;

@@ -94,6 +102,8 @@ public class FolderPagedView extends PagedView implements Folder.FolderContent {

        mInflater = LayoutInflater.from(context);
        mIconCache = app.getIconCache();

        rtlLayout = getResources().getConfiguration().getLayoutDirection() == LayoutDirection.RTL;
    }

    @Override
@@ -484,7 +494,7 @@ public class FolderPagedView extends PagedView implements Folder.FolderContent {
        if (getPageCount() > 1) {
            mPageIndicator.setVisibility(View.VISIBLE);
            mSortButton.setVisibility(View.VISIBLE);
            mFolder.mFolderName.setGravity(Gravity.START);
            mFolder.mFolderName.setGravity(rtlLayout ? Gravity.RIGHT : Gravity.LEFT);
            setEnableOverscroll(true);
        } else {
            mPageIndicator.setVisibility(View.GONE);
@@ -611,7 +621,9 @@ public class FolderPagedView extends PagedView implements Folder.FolderContent {
    /**
     * Scrolls the current view by a fraction
     */
    public void showScrollHint(float fraction) {
    public void showScrollHint(int direction) {
        float fraction = (direction == DragController.SCROLL_LEFT) ^ rtlLayout
                ? -SCROLL_HINT_FRACTION : SCROLL_HINT_FRACTION;
        int hint = (int) (fraction * getWidth());
        int scroll = getScrollForPage(getNextPage()) + hint;
        int delta = scroll - mUnboundedScrollX;
@@ -761,7 +773,7 @@ public class FolderPagedView extends PagedView implements Folder.FolderContent {
                        }
                    };
                    v.animate()
                        .translationXBy(direction > 0 ? -v.getWidth() : v.getWidth())
                        .translationXBy((direction > 0 ^ rtlLayout) ? -v.getWidth() : v.getWidth())
                        .setDuration(REORDER_ANIMATION_DURATION)
                        .setStartDelay(0)
                        .withEndAction(endAction);