Merge "Fixing some RTL issues with scrollable folder" into ub-launcher3-burnaby
This commit is contained in:
commit
85e3d4cc5e
|
@ -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,42 +651,17 @@ 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;
|
||||
}
|
||||
} else if (currentPage < (mPagedView.getPageCount() - 1) &&
|
||||
(x > (getWidth() - cellWidth * ICON_OVERSCROLL_WIDTH_FACTOR))) {
|
||||
// Show scroll hint on the right
|
||||
if (mScrollHintDir != DragController.SCROLL_RIGHT) {
|
||||
mPagedView.showScrollHint(SCROLL_HINT_FRACTION);
|
||||
mScrollHintDir = DragController.SCROLL_RIGHT;
|
||||
}
|
||||
|
||||
// Set alarm for when the hint is complete
|
||||
if (!mOnScrollHintAlarm.alarmPending() || mCurrentScrollDir != DragController.SCROLL_RIGHT) {
|
||||
mCurrentScrollDir = DragController.SCROLL_RIGHT;
|
||||
mOnScrollHintAlarm.cancelAlarm();
|
||||
mOnScrollHintAlarm.setOnAlarmListener(new OnScrollHintListener(d));
|
||||
mOnScrollHintAlarm.setAlarm(SCROLL_HINT_DURATION);
|
||||
|
||||
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) {
|
||||
|
@ -701,6 +671,25 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
|
|||
}
|
||||
}
|
||||
|
||||
private void showScrollHint(int direction, DragObject d) {
|
||||
// Show scroll hint on the right
|
||||
if (mScrollHintDir != direction) {
|
||||
mPagedView.showScrollHint(direction);
|
||||
mScrollHintDir = direction;
|
||||
}
|
||||
|
||||
// Set alarm for when the hint is complete
|
||||
if (!mOnScrollHintAlarm.alarmPending() || mCurrentScrollDir != direction) {
|
||||
mCurrentScrollDir = direction;
|
||||
mOnScrollHintAlarm.cancelAlarm();
|
||||
mOnScrollHintAlarm.setOnAlarmListener(new OnScrollHintListener(d));
|
||||
mOnScrollHintAlarm.setAlarm(SCROLL_HINT_DURATION);
|
||||
|
||||
mReorderAlarm.cancelAlarm();
|
||||
mTargetRank = mEmptyCellRank;
|
||||
}
|
||||
}
|
||||
|
||||
OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
|
||||
public void onAlarm(Alarm alarm) {
|
||||
completeDragExit();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue