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_ANIMATING = 1;
|
||||||
static final int STATE_OPEN = 2;
|
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.
|
* 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];
|
float x = r[0];
|
||||||
int currentPage = mPagedView.getNextPage();
|
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
|
float cellOverlap = mPagedView.getCurrentCellLayout().getCellWidth()
|
||||||
if (!mOnScrollHintAlarm.alarmPending() || mCurrentScrollDir != DragController.SCROLL_LEFT) {
|
* ICON_OVERSCROLL_WIDTH_FACTOR;
|
||||||
mCurrentScrollDir = DragController.SCROLL_LEFT;
|
boolean isOutsideLeftEdge = x < cellOverlap;
|
||||||
mOnScrollHintAlarm.cancelAlarm();
|
boolean isOutsideRightEdge = x > (getWidth() - cellOverlap);
|
||||||
mOnScrollHintAlarm.setOnAlarmListener(new OnScrollHintListener(d));
|
|
||||||
mOnScrollHintAlarm.setAlarm(SCROLL_HINT_DURATION);
|
|
||||||
|
|
||||||
mReorderAlarm.cancelAlarm();
|
if (currentPage > 0 && (mPagedView.rtlLayout ? isOutsideRightEdge : isOutsideLeftEdge)) {
|
||||||
mTargetRank = mEmptyCellRank;
|
showScrollHint(DragController.SCROLL_LEFT, d);
|
||||||
}
|
} else if (currentPage < (mPagedView.getPageCount() - 1)
|
||||||
} else if (currentPage < (mPagedView.getPageCount() - 1) &&
|
&& (mPagedView.rtlLayout ? isOutsideLeftEdge : isOutsideRightEdge)) {
|
||||||
(x > (getWidth() - cellWidth * ICON_OVERSCROLL_WIDTH_FACTOR))) {
|
showScrollHint(DragController.SCROLL_RIGHT, d);
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
mOnScrollHintAlarm.cancelAlarm();
|
mOnScrollHintAlarm.cancelAlarm();
|
||||||
if (mScrollHintDir != DragController.SCROLL_NONE) {
|
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() {
|
OnAlarmListener mOnExitAlarmListener = new OnAlarmListener() {
|
||||||
public void onAlarm(Alarm alarm) {
|
public void onAlarm(Alarm alarm) {
|
||||||
completeDragExit();
|
completeDragExit();
|
||||||
|
|
|
@ -19,6 +19,7 @@ package com.android.launcher3;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.LayoutDirection;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
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_HIDE_DURATION = 130;
|
||||||
private static final int SORT_ANIM_SHOW_DURATION = 160;
|
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];
|
private static final int[] sTempPosArray = new int[2];
|
||||||
|
|
||||||
// TODO: Remove this restriction
|
// TODO: Remove this restriction
|
||||||
private static final int MAX_ITEMS_PER_PAGE = 4;
|
private static final int MAX_ITEMS_PER_PAGE = 4;
|
||||||
|
|
||||||
|
public final boolean rtlLayout;
|
||||||
|
|
||||||
private final LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
private final IconCache mIconCache;
|
private final IconCache mIconCache;
|
||||||
|
|
||||||
|
@ -94,6 +102,8 @@ public class FolderPagedView extends PagedView implements Folder.FolderContent {
|
||||||
|
|
||||||
mInflater = LayoutInflater.from(context);
|
mInflater = LayoutInflater.from(context);
|
||||||
mIconCache = app.getIconCache();
|
mIconCache = app.getIconCache();
|
||||||
|
|
||||||
|
rtlLayout = getResources().getConfiguration().getLayoutDirection() == LayoutDirection.RTL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -484,7 +494,7 @@ public class FolderPagedView extends PagedView implements Folder.FolderContent {
|
||||||
if (getPageCount() > 1) {
|
if (getPageCount() > 1) {
|
||||||
mPageIndicator.setVisibility(View.VISIBLE);
|
mPageIndicator.setVisibility(View.VISIBLE);
|
||||||
mSortButton.setVisibility(View.VISIBLE);
|
mSortButton.setVisibility(View.VISIBLE);
|
||||||
mFolder.mFolderName.setGravity(Gravity.START);
|
mFolder.mFolderName.setGravity(rtlLayout ? Gravity.RIGHT : Gravity.LEFT);
|
||||||
setEnableOverscroll(true);
|
setEnableOverscroll(true);
|
||||||
} else {
|
} else {
|
||||||
mPageIndicator.setVisibility(View.GONE);
|
mPageIndicator.setVisibility(View.GONE);
|
||||||
|
@ -611,7 +621,9 @@ public class FolderPagedView extends PagedView implements Folder.FolderContent {
|
||||||
/**
|
/**
|
||||||
* Scrolls the current view by a fraction
|
* 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 hint = (int) (fraction * getWidth());
|
||||||
int scroll = getScrollForPage(getNextPage()) + hint;
|
int scroll = getScrollForPage(getNextPage()) + hint;
|
||||||
int delta = scroll - mUnboundedScrollX;
|
int delta = scroll - mUnboundedScrollX;
|
||||||
|
@ -761,7 +773,7 @@ public class FolderPagedView extends PagedView implements Folder.FolderContent {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
v.animate()
|
v.animate()
|
||||||
.translationXBy(direction > 0 ? -v.getWidth() : v.getWidth())
|
.translationXBy((direction > 0 ^ rtlLayout) ? -v.getWidth() : v.getWidth())
|
||||||
.setDuration(REORDER_ANIMATION_DURATION)
|
.setDuration(REORDER_ANIMATION_DURATION)
|
||||||
.setStartDelay(0)
|
.setStartDelay(0)
|
||||||
.withEndAction(endAction);
|
.withEndAction(endAction);
|
||||||
|
|
Loading…
Reference in New Issue