Skip to content
Snippets Groups Projects
Commit 0d6b2ee5 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

TwoPaneLayout: replace mSlideOffset with isOpened

Change-Id: I5adf1b641a33350e493cbfbbd2daa7a63537acb2
parent 3cfe2dff
Branches
Tags
No related merge requests found
...@@ -104,7 +104,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -104,7 +104,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
* How far the panel is offset from its usual position. * How far the panel is offset from its usual position.
* range [0, 1] where 0 = open, 1 = closed. * range [0, 1] where 0 = open, 1 = closed.
*/ */
private float mSlideOffset = 1.f; private boolean isOpened = false;
private final List<PanelListener> mPanelListeners = new CopyOnWriteArrayList<>(); private final List<PanelListener> mPanelListeners = new CopyOnWriteArrayList<>();
...@@ -212,24 +212,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -212,24 +212,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
} }
void updateObscuredViewsVisibility(View panel) { void updateObscuredViewsVisibility(View panel) {
final boolean isLayoutRtl = isLayoutRtlSupport(); boolean visibility = !mCanSlide || !isOpened;
final int startBound = isLayoutRtl ? (getWidth() - getPaddingRight()) : getPaddingLeft();
final int endBound = isLayoutRtl ? getPaddingLeft() : (getWidth() - getPaddingRight());
final int topBound = getPaddingTop();
final int bottomBound = getHeight() - getPaddingBottom();
final int left;
final int right;
final int top;
final int bottom;
if (panel != null && panel.isOpaque()) {
left = panel.getLeft();
right = panel.getRight();
top = panel.getTop();
bottom = panel.getBottom();
} else {
left = right = top = bottom = 0;
}
for (int i = 0, childCount = getChildCount(); i < childCount; i++) { for (int i = 0, childCount = getChildCount(); i < childCount; i++) {
final View child = getChildAt(i); final View child = getChildAt(i);
...@@ -239,21 +222,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -239,21 +222,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
} else if (child.getVisibility() == GONE) { } else if (child.getVisibility() == GONE) {
continue; continue;
} }
child.setVisibility(visibility ? VISIBLE : INVISIBLE);
final int clampedChildLeft = Math.max(
(isLayoutRtl ? endBound : startBound), child.getLeft());
final int clampedChildTop = Math.max(topBound, child.getTop());
final int clampedChildRight = Math.min(
(isLayoutRtl ? startBound : endBound), child.getRight());
final int clampedChildBottom = Math.min(bottomBound, child.getBottom());
final int vis;
if (clampedChildLeft >= left && clampedChildTop >= top
&& clampedChildRight <= right && clampedChildBottom <= bottom) {
vis = INVISIBLE;
} else {
vis = VISIBLE;
}
child.setVisibility(vis);
} }
} }
...@@ -436,7 +405,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -436,7 +405,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
int childWidthSpec = MeasureSpec.makeMeasureSpec(splitView.width(), int childWidthSpec = MeasureSpec.makeMeasureSpec(splitView.width(),
MeasureSpec.AT_MOST); MeasureSpec.AT_MOST);
child.measure(childWidthSpec, childHeightSpec); child.measure(childWidthSpec, childHeightSpec);
if ((child.getMeasuredWidthAndState() & MEASURED_STATE_TOO_SMALL) == 1 || ( if ((child.getMeasuredWidthAndState() & MEASURED_STATE_TOO_SMALL) != 0 || (
getMinimumWidth(child) != 0 getMinimumWidth(child) != 0
&& splitView.width() < getMinimumWidth(child))) { && splitView.width() < getMinimumWidth(child))) {
childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin, childWidthSpec = MeasureSpec.makeMeasureSpec(widthAvailable - horizontalMargin,
...@@ -496,7 +465,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -496,7 +465,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
int nextXStart = xStart; int nextXStart = xStart;
if (mFirstLayout) { if (mFirstLayout) {
mSlideOffset = mCanSlide && mPreservedOpenState ? 0.f : 1.f; isOpened = mCanSlide && mPreservedOpenState;
} }
for (int i = 0; i < childCount; i++) { for (int i = 0; i < childCount; i++) {
...@@ -515,9 +484,8 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -515,9 +484,8 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
final int margin = lp.leftMargin + lp.rightMargin; final int margin = lp.leftMargin + lp.rightMargin;
final int range = Math.min(nextXStart, width - paddingEnd) - xStart - margin; final int range = Math.min(nextXStart, width - paddingEnd) - xStart - margin;
final int lpMargin = isLayoutRtl ? lp.rightMargin : lp.leftMargin; final int lpMargin = isLayoutRtl ? lp.rightMargin : lp.leftMargin;
final int pos = (int) (range * mSlideOffset); final int pos = (isOpened) ? 0 : range;
xStart += pos + lpMargin; xStart += pos + lpMargin;
mSlideOffset = (float) pos / range;
} else { } else {
xStart = nextXStart; xStart = nextXStart;
} }
...@@ -581,7 +549,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -581,7 +549,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
if (!mCanSlide) { if (!mCanSlide) {
mPreservedOpenState = false; mPreservedOpenState = false;
} }
if (mFirstLayout || slideTo(1.f)) { if (mFirstLayout || slideTo(false)) {
mPreservedOpenState = false; mPreservedOpenState = false;
return true; return true;
} }
...@@ -599,7 +567,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -599,7 +567,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
if (!mCanSlide) { if (!mCanSlide) {
mPreservedOpenState = true; mPreservedOpenState = true;
} }
if (mFirstLayout || slideTo(0.f)) { if (mFirstLayout || slideTo(true)) {
mPreservedOpenState = true; mPreservedOpenState = true;
return true; return true;
} }
...@@ -632,7 +600,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -632,7 +600,7 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
*/ */
@Override @Override
public boolean isOpen() { public boolean isOpen() {
return !mCanSlide || mSlideOffset == 0; return !mCanSlide || isOpened;
} }
/** /**
...@@ -673,21 +641,19 @@ public class TwoPaneLayout extends ViewGroup implements Openable { ...@@ -673,21 +641,19 @@ public class TwoPaneLayout extends ViewGroup implements Openable {
} }
/** /**
* Set mDraggingPane to the target X position within its range. * @param opened position to switch to
*
* @param slideOffset position to animate to
*/ */
boolean slideTo(float slideOffset) { boolean slideTo(boolean opened) {
if (!mCanSlide) { if (!mCanSlide) {
// Nothing to do. // Nothing to do.
return false; return false;
} }
View slideableView = mSlideableView; View slideableView = mSlideableView;
mSlideOffset = slideOffset; isOpened = opened;
mFirstLayout = true;
requestLayout(); requestLayout();
invalidate(); invalidate();
boolean opened = slideOffset == 0.f;
if (opened) if (opened)
dispatchOnPanelOpened(slideableView); dispatchOnPanelOpened(slideableView);
else else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment