Merge "Fix RTL changes in PagedTileLayout" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
30fdd9646c
@@ -54,7 +54,7 @@ public class FragmentHostManager {
|
|||||||
private final View mRootView;
|
private final View mRootView;
|
||||||
private final InterestingConfigChanges mConfigChanges = new InterestingConfigChanges(
|
private final InterestingConfigChanges mConfigChanges = new InterestingConfigChanges(
|
||||||
ActivityInfo.CONFIG_FONT_SCALE | ActivityInfo.CONFIG_LOCALE
|
ActivityInfo.CONFIG_FONT_SCALE | ActivityInfo.CONFIG_LOCALE
|
||||||
| ActivityInfo.CONFIG_LAYOUT_DIRECTION | ActivityInfo.CONFIG_ASSETS_PATHS);
|
| ActivityInfo.CONFIG_ASSETS_PATHS);
|
||||||
private final FragmentService mManager;
|
private final FragmentService mManager;
|
||||||
private final ExtensionFragmentManager mPlugins = new ExtensionFragmentManager();
|
private final ExtensionFragmentManager mPlugins = new ExtensionFragmentManager();
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
|
|
||||||
private static final boolean DEBUG = false;
|
private static final boolean DEBUG = false;
|
||||||
private static final String CURRENT_PAGE = "current_page";
|
private static final String CURRENT_PAGE = "current_page";
|
||||||
|
private static final int NO_PAGE = -1;
|
||||||
|
|
||||||
private static final String TAG = "PagedTileLayout";
|
private static final String TAG = "PagedTileLayout";
|
||||||
private static final int REVEAL_SCROLL_DURATION_MILLIS = 750;
|
private static final int REVEAL_SCROLL_DURATION_MILLIS = 750;
|
||||||
@@ -109,13 +110,14 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void saveInstanceState(Bundle outState) {
|
public void saveInstanceState(Bundle outState) {
|
||||||
outState.putInt(CURRENT_PAGE, getCurrentItem());
|
int resolvedPage = mPageToRestore != NO_PAGE ? mPageToRestore : getCurrentPageNumber();
|
||||||
|
outState.putInt(CURRENT_PAGE, resolvedPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restoreInstanceState(Bundle savedInstanceState) {
|
public void restoreInstanceState(Bundle savedInstanceState) {
|
||||||
// There's only 1 page at this point. We want to restore the correct page once the
|
// There's only 1 page at this point. We want to restore the correct page once the
|
||||||
// pages have been inflated
|
// pages have been inflated
|
||||||
mPageToRestore = savedInstanceState.getInt(CURRENT_PAGE, -1);
|
mPageToRestore = savedInstanceState.getInt(CURRENT_PAGE, NO_PAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -151,12 +153,15 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRtlPropertiesChanged(int layoutDirection) {
|
public void onRtlPropertiesChanged(int layoutDirection) {
|
||||||
|
// The configuration change will change the flag in the view (that's returned in
|
||||||
|
// isLayoutRtl). As we detect the change, we use the cached direction to store the page
|
||||||
|
// before setting it.
|
||||||
|
final int page = getPageNumberForDirection(mLayoutDirection == LAYOUT_DIRECTION_RTL);
|
||||||
super.onRtlPropertiesChanged(layoutDirection);
|
super.onRtlPropertiesChanged(layoutDirection);
|
||||||
if (mLayoutDirection != layoutDirection) {
|
if (mLayoutDirection != layoutDirection) {
|
||||||
mLayoutDirection = layoutDirection;
|
mLayoutDirection = layoutDirection;
|
||||||
setAdapter(mAdapter);
|
setAdapter(mAdapter);
|
||||||
setCurrentItem(0, false);
|
setCurrentItem(page, false);
|
||||||
mPageToRestore = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,8 +177,12 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
* Obtains the current page number respecting RTL
|
* Obtains the current page number respecting RTL
|
||||||
*/
|
*/
|
||||||
private int getCurrentPageNumber() {
|
private int getCurrentPageNumber() {
|
||||||
|
return getPageNumberForDirection(isLayoutRtl());
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getPageNumberForDirection(boolean isLayoutRTL) {
|
||||||
int page = getCurrentItem();
|
int page = getCurrentItem();
|
||||||
if (mLayoutDirection == LAYOUT_DIRECTION_RTL) {
|
if (isLayoutRTL) {
|
||||||
page = mPages.size() - 1 - page;
|
page = mPages.size() - 1 - page;
|
||||||
}
|
}
|
||||||
return page;
|
return page;
|
||||||
@@ -388,9 +397,9 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
mPageIndicator.setNumPages(mPages.size());
|
mPageIndicator.setNumPages(mPages.size());
|
||||||
setAdapter(mAdapter);
|
setAdapter(mAdapter);
|
||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
if (mPageToRestore != -1) {
|
if (mPageToRestore != NO_PAGE) {
|
||||||
setCurrentItem(mPageToRestore, false);
|
setCurrentItem(mPageToRestore, false);
|
||||||
mPageToRestore = -1;
|
mPageToRestore = NO_PAGE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,9 +488,27 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
maxHeight = height;
|
maxHeight = height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (mPages.get(0).getParent() == null) {
|
||||||
|
// Measure page 0 so we know how tall it is if it's not attached to the pager.
|
||||||
|
mPages.get(0).measure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
int height = mPages.get(0).getMeasuredHeight();
|
||||||
|
if (height > maxHeight) {
|
||||||
|
maxHeight = height;
|
||||||
|
}
|
||||||
|
}
|
||||||
setMeasuredDimension(getMeasuredWidth(), maxHeight + getPaddingBottom());
|
setMeasuredDimension(getMeasuredWidth(), maxHeight + getPaddingBottom());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
|
super.onLayout(changed, l, t, r, b);
|
||||||
|
if (mPages.get(0).getParent() == null) {
|
||||||
|
// Layout page 0, so we can get the bottom of the tiles. We only do this if the page
|
||||||
|
// is not attached.
|
||||||
|
mPages.get(0).layout(l, t, r, b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getColumnCount() {
|
public int getColumnCount() {
|
||||||
if (mPages.size() == 0) return 0;
|
if (mPages.size() == 0) return 0;
|
||||||
return mPages.get(0).mColumns;
|
return mPages.get(0).mColumns;
|
||||||
@@ -625,8 +652,7 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
if (mPageIndicator == null) return;
|
if (mPageIndicator == null) return;
|
||||||
if (mPageListener != null) {
|
if (mPageListener != null) {
|
||||||
int pageNumber = isLayoutRtl() ? mPages.size() - 1 - position : position;
|
int pageNumber = isLayoutRtl() ? mPages.size() - 1 - position : position;
|
||||||
mPageListener.onPageChanged(isLayoutRtl() ? position == mPages.size() - 1
|
mPageListener.onPageChanged(pageNumber == 0, pageNumber);
|
||||||
: position == 0, pageNumber);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,8 +671,8 @@ public class PagedTileLayout extends ViewPager implements QSTileLayout {
|
|||||||
mPageIndicator.setLocation(mPageIndicatorPosition);
|
mPageIndicator.setLocation(mPageIndicatorPosition);
|
||||||
if (mPageListener != null) {
|
if (mPageListener != null) {
|
||||||
int pageNumber = isLayoutRtl() ? mPages.size() - 1 - position : position;
|
int pageNumber = isLayoutRtl() ? mPages.size() - 1 - position : position;
|
||||||
mPageListener.onPageChanged(positionOffsetPixels == 0 &&
|
mPageListener.onPageChanged(
|
||||||
(isLayoutRtl() ? position == mPages.size() - 1 : position == 0),
|
positionOffsetPixels == 0 && pageNumber == 0,
|
||||||
// Send only valid page number on integer pages
|
// Send only valid page number on integer pages
|
||||||
positionOffsetPixels == 0 ? pageNumber : PageListener.INVALID_PAGE
|
positionOffsetPixels == 0 ? pageNumber : PageListener.INVALID_PAGE
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user