Skip to content

Commit

Permalink
[layouts] Rename childFrame arguments to outRect in Lanes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasr committed Aug 12, 2014
1 parent e80f308 commit e5a41e7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.support.v7.widget.RecyclerView.Recycler;
import android.support.v7.widget.RecyclerView.State;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -129,8 +128,8 @@ void getDecoratedChildFrame(View child, Rect childFrame) {
protected void getChildLaneAndFrame(LaneInfo outInfo, View child, Direction direction,
Rect childFrame) {
getLaneForChild(outInfo, child, direction);
mLanes.getChildFrame(getDecoratedMeasuredWidth(child), getDecoratedMeasuredHeight(child),
outInfo, direction, childFrame);
mLanes.getChildFrame(childFrame, getDecoratedMeasuredWidth(child), getDecoratedMeasuredHeight(child),
outInfo, direction);
}

boolean isVertical() {
Expand Down
58 changes: 28 additions & 30 deletions layouts/src/main/java/org/lucasr/twowayview/widget/Lanes.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package org.lucasr.twowayview.widget;

import android.graphics.Rect;
import android.util.Log;
import android.view.View;

import org.lucasr.twowayview.TwoWayLayoutManager.Direction;
import org.lucasr.twowayview.TwoWayLayoutManager.Orientation;
Expand Down Expand Up @@ -156,25 +154,25 @@ public void getLane(int lane, Rect laneRect) {
laneRect.set(mLanes[lane]);
}

public int pushChildFrame(Rect childFrame, int lane, Direction direction) {
public int pushChildFrame(Rect outRect, int lane, Direction direction) {
final int margin;

final Rect laneRect = mLanes[lane];
if (mIsVertical) {
if (direction == Direction.END) {
margin = laneRect.bottom - childFrame.top;
laneRect.bottom = childFrame.bottom;
margin = laneRect.bottom - outRect.top;
laneRect.bottom = outRect.bottom;
} else {
margin = laneRect.top - childFrame.bottom;
laneRect.top = childFrame.top;
margin = laneRect.top - outRect.bottom;
laneRect.top = outRect.top;
}
} else {
if (direction == Direction.END) {
margin = laneRect.right - childFrame.left;
laneRect.right = childFrame.right;
margin = laneRect.right - outRect.left;
laneRect.right = outRect.right;
} else {
margin = laneRect.left - childFrame.right;
laneRect.left = childFrame.left;
margin = laneRect.left - outRect.right;
laneRect.left = outRect.left;
}
}

Expand All @@ -183,39 +181,39 @@ public int pushChildFrame(Rect childFrame, int lane, Direction direction) {
return margin;
}

public void pushChildFrame(Rect childFrame, int start, int end, Direction direction) {
public void pushChildFrame(Rect outRect, int start, int end, Direction direction) {
for (int i = start; i < end; i++) {
pushChildFrame(childFrame, i, direction);
pushChildFrame(outRect, i, direction);
}
}

public void popChildFrame(Rect childFrame, int lane, Direction direction) {
public void popChildFrame(Rect outRect, int lane, Direction direction) {
final Rect laneRect = mLanes[lane];
if (mIsVertical) {
if (direction == Direction.END) {
laneRect.top = childFrame.bottom;
laneRect.top = outRect.bottom;
} else {
laneRect.bottom = childFrame.top;
laneRect.bottom = outRect.top;
}
} else {
if (direction == Direction.END) {
laneRect.left = childFrame.right;
laneRect.left = outRect.right;
} else {
laneRect.right = childFrame.left;
laneRect.right = outRect.left;
}
}

invalidateEdges();
}

public void popChildFrame(Rect childFrame, int start, int end, Direction direction) {
public void popChildFrame(Rect outRect, int start, int end, Direction direction) {
for (int i = start; i < end; i++) {
popChildFrame(childFrame, i, direction);
popChildFrame(outRect, i, direction);
}
}

public void getChildFrame(int childWidth, int childHeight, LaneInfo laneInfo,
Direction direction, Rect childFrame) {
public void getChildFrame(Rect outRect, int childWidth, int childHeight, LaneInfo laneInfo,
Direction direction) {
final Rect startRect = mLanes[laneInfo.startLane];

// The anchor lane only applies when we're get child frame in the direction
Expand All @@ -226,17 +224,17 @@ public void getChildFrame(int childWidth, int childHeight, LaneInfo laneInfo,
final Rect anchorRect = mLanes[anchorLane];

if (mIsVertical) {
childFrame.left = startRect.left;
childFrame.top =
outRect.left = startRect.left;
outRect.top =
(direction == Direction.END ? anchorRect.bottom : anchorRect.top - childHeight);
} else {
childFrame.top = startRect.top;
childFrame.left =
outRect.top = startRect.top;
outRect.left =
(direction == Direction.END ? anchorRect.right : anchorRect.left - childWidth);
}

childFrame.right = childFrame.left + childWidth;
childFrame.bottom = childFrame.top + childHeight;
outRect.right = outRect.left + childWidth;
outRect.bottom = outRect.top + childHeight;
}

private boolean intersects(int start, int count, Rect r) {
Expand All @@ -255,8 +253,8 @@ private int findLaneThatFitsSpan(int anchorLane, int laneSpan, Direction directi
for (int l = findStart; l < findEnd; l++) {
mTempLaneInfo.set(l, anchorLane);

getChildFrame(mIsVertical ? laneSpan * mLaneSize : 1,
mIsVertical ? 1 : laneSpan * mLaneSize, mTempLaneInfo, direction, mTempRect);
getChildFrame(mTempRect, mIsVertical ? laneSpan * mLaneSize : 1,
mIsVertical ? 1 : laneSpan * mLaneSize, mTempLaneInfo, direction);

if (!intersects(l, laneSpan, mTempRect)) {
return l;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.support.v7.widget.RecyclerView.Recycler;
import android.support.v7.widget.RecyclerView.State;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
Expand Down Expand Up @@ -76,7 +75,6 @@ public SpannableItemEntry[] newArray(int size) {
};
}

private final Context mContext;
private boolean mMeasuring;

public SpannableGridLayoutManager(Context context) {
Expand All @@ -89,13 +87,11 @@ public SpannableGridLayoutManager(Context context, AttributeSet attrs) {

public SpannableGridLayoutManager(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle, DEFAULT_NUM_COLS, DEFAULT_NUM_ROWS);
mContext = context;
}

public SpannableGridLayoutManager(Context context, Orientation orientation,
int numColumns, int numRows) {
super(context, orientation, numColumns, numRows);
mContext = context;
}

private int getChildWidth(int colSpan) {
Expand Down Expand Up @@ -226,15 +222,15 @@ protected void moveLayoutToPosition(int position, int offset, Recycler recycler,
SpannableItemEntry entry = (SpannableItemEntry) getItemEntryForPosition(i);
if (entry != null) {
mTempLaneInfo.set(entry.startLane, entry.anchorLane);
lanes.getChildFrame(getChildWidth(entry.colSpan), getChildHeight(entry.rowSpan),
mTempLaneInfo, Direction.END, childFrame);
lanes.getChildFrame(childFrame, getChildWidth(entry.colSpan), getChildHeight(entry.rowSpan),
mTempLaneInfo, Direction.END);
} else {
final View child = recycler.getViewForPosition(i);
final LayoutParams lp = (LayoutParams) child.getLayoutParams();

lanes.findLane(mTempLaneInfo, getLaneSpan(lp, isVertical), Direction.END);
lanes.getChildFrame(getChildWidth(lp.colSpan), getChildHeight(lp.rowSpan),
mTempLaneInfo, Direction.END, childFrame);
lanes.getChildFrame(childFrame, getChildWidth(lp.colSpan), getChildHeight(lp.rowSpan),
mTempLaneInfo, Direction.END);

entry = (SpannableItemEntry) cacheItemEntry(child, i, mTempLaneInfo, childFrame);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import android.support.v7.widget.RecyclerView.Recycler;
import android.support.v7.widget.RecyclerView.State;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -205,8 +204,8 @@ void moveLayoutToPosition(int position, int offset, Recycler recycler, State sta

if (entry != null) {
mTempLaneInfo.set(entry.startLane, entry.anchorLane);
lanes.getChildFrame(entry.width, entry.height, mTempLaneInfo,
Direction.END, childFrame);
lanes.getChildFrame(childFrame, entry.width, entry.height, mTempLaneInfo,
Direction.END);
} else {
final View child = recycler.getViewForPosition(i);
final LayoutParams lp = (LayoutParams) child.getLayoutParams();
Expand All @@ -223,8 +222,8 @@ void moveLayoutToPosition(int position, int offset, Recycler recycler, State sta
measureChild(child);

lanes.findLane(mTempLaneInfo, lp.span, Direction.END);
lanes.getChildFrame(getDecoratedMeasuredWidth(child),
getDecoratedMeasuredHeight(child), mTempLaneInfo, Direction.END, childFrame);
lanes.getChildFrame(childFrame, getDecoratedMeasuredWidth(child),
getDecoratedMeasuredHeight(child), mTempLaneInfo, Direction.END);

entry = (StaggeredItemEntry) cacheItemEntry(child, i, mTempLaneInfo, childFrame);

Expand Down

0 comments on commit e5a41e7

Please sign in to comment.