/
DefinitionGroup.java
110 lines (87 loc) · 3.08 KB
/
DefinitionGroup.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package mobi.parchment.widget.adapterview.griddefinitionview;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Emir Hasanbegovic on 2014-03-03.
*/
public class DefinitionGroup {
private final GridGroupDefinition mGridGroupDefinition;
private final ViewGroup mViewGroup;
private final boolean mIsVerticalScroll;
private final float mStretchRatio;
private final int mCellSpacing;
private int mStartOffset;
private final List<View> mViews = new ArrayList<View>();
public DefinitionGroup(final GridGroupDefinition gridGroupDefinition, final ViewGroup viewGroup, final boolean isVerticalScroll, final float stretchRatio, final int cellSpacing) {
mGridGroupDefinition = gridGroupDefinition;
mViewGroup = viewGroup;
mIsVerticalScroll = isVerticalScroll;
mStretchRatio = stretchRatio;
mCellSpacing = cellSpacing;
}
public void setStartOffset(final int startOffset) {
mStartOffset = startOffset;
}
public int getTop() {
if (mIsVerticalScroll) {
return mStartOffset;
}
return mCellSpacing;
}
public GridGroupDefinition getGridGroupDefinition() {
return mGridGroupDefinition;
}
public int getBottom() {
if (mIsVerticalScroll) {
final int height = mGridGroupDefinition.getMeasuredHeight(mViewGroup, mCellSpacing, mStretchRatio);
return mStartOffset + height;
}
final int viewGroupHeight = mViewGroup.getMeasuredHeight();
return viewGroupHeight - mCellSpacing;
}
public int getLeft() {
final View firstView = getFirstView();
final int left = firstView.getLeft();
return left;
}
public int getRight() {
final View lastView = getLastView();
final int right = lastView.getRight();
return right;
}
public View getLastView() {
final int numberOfItems = getNumberOfItems();
final int lastGridGroupPosition = mGridGroupDefinition.getLastGridGroupPosition(numberOfItems);
final View lastView = mViews.get(lastGridGroupPosition);
return lastView;
}
public View getFirstView() {
final int numberOfItems = getNumberOfItems();
final int firstGridGroupPosition = mGridGroupDefinition.getFirstGridGroupPosition(numberOfItems);
final View firstView = mViews.get(firstGridGroupPosition);
return firstView;
}
public void clear() {
mViews.clear();
}
public int getNumberOfItems() {
return mViews.size();
}
public void addView(final View view) {
mViews.add(view);
}
public int getBreadth() {
if (!mIsVerticalScroll) {
return mGridGroupDefinition.getMeasuredHeight(mViewGroup, mCellSpacing, mStretchRatio);
}
return mGridGroupDefinition.getMeasuredWidth(mViewGroup, mCellSpacing, mStretchRatio);
}
public boolean isEmpty() {
return mViews.isEmpty();
}
public List<View> getViews() {
return mViews;
}
}