Skip to content

Commit 4efa9f5

Browse files
authored
Merge pull request google#102 from google/extract_flexline
Expose the FlexLine class and mFlexLines
2 parents 175e941 + eb2d7fa commit 4efa9f5

File tree

3 files changed

+307
-207
lines changed

3 files changed

+307
-207
lines changed

flexbox/src/androidTest/java/com/google/android/flexbox/test/FlexboxAndroidTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ public void run() {
335335
onView(withId(R.id.text3)).check(isBelow(withId(R.id.text1)));
336336
onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
337337
onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
338+
assertThat(flexboxLayout.getFlexLines().size(), is(2));
338339
}
339340

340341
@Test
@@ -363,6 +364,7 @@ public void run() {
363364
// to the right of the second one and overflowing the parent FlexboxLayout.
364365
onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
365366
onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
367+
assertThat(flexboxLayout.getFlexLines().size(), is(1));
366368
}
367369

368370
@Test
@@ -390,6 +392,7 @@ public void run() {
390392
onView(withId(R.id.text3)).check(isAbove(withId(R.id.text1)));
391393
onView(withId(R.id.text3)).check(isAbove(withId(R.id.text2)));
392394
onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
395+
assertThat(flexboxLayout.getFlexLines().size(), is(2));
393396
}
394397

395398
@Test
@@ -418,6 +421,7 @@ public void run() {
418421
onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text1)));
419422
onView(withId(R.id.text3)).check(isRightOf(withId(R.id.text2)));
420423
onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
424+
assertThat(flexboxLayout.getFlexLines().size(), is(2));
421425
}
422426

423427
@Test
@@ -448,6 +452,7 @@ public void run() {
448452
// below the second one and overflowing the parent FlexboxLayout.
449453
onView(withId(R.id.text3)).check(isBelow(withId(R.id.text2)));
450454
onView(withId(R.id.text3)).check(isLeftAlignedWith(withId(R.id.flexbox_layout)));
455+
assertThat(flexboxLayout.getFlexLines().size(), is(1));
451456
}
452457

453458
@Test
@@ -478,6 +483,7 @@ public void run() {
478483
onView(withId(R.id.text3)).check(isLeftOf(withId(R.id.text1)));
479484
onView(withId(R.id.text3)).check(isLeftOf(withId(R.id.text2)));
480485
onView(withId(R.id.text3)).check(isTopAlignedWith(withId(R.id.flexbox_layout)));
486+
assertThat(flexboxLayout.getFlexLines().size(), is(2));
481487
}
482488

483489
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright 2016 Google Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.android.flexbox;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
22+
/**
23+
* Holds properties related to a single flex line. This class is not expected to be changed outside
24+
* of the {@link FlexboxLayout}, thus only exposing the getter methods that may be useful for
25+
* other classes using the {@link FlexboxLayout}.
26+
*/
27+
public class FlexLine {
28+
29+
FlexLine() {
30+
}
31+
32+
/** @see {@link #getLeft()} */
33+
int mLeft = Integer.MAX_VALUE;
34+
35+
/** @see {@link #getTop()} */
36+
int mTop = Integer.MAX_VALUE;
37+
38+
/** @see {@link #getRight()} */
39+
int mRight = Integer.MIN_VALUE;
40+
41+
/** @see {@link #getBottom()} */
42+
int mBottom = Integer.MIN_VALUE;
43+
44+
/** @see {@link #getMainSize()} */
45+
int mMainSize;
46+
47+
/**
48+
* The sum of the lengths of dividers along the main axis. This value should be lower or
49+
* than than the value of {@link #mMainSize}.
50+
*/
51+
int mDividerLengthInMainSize;
52+
53+
/** @see {@link #getCrossSize()} */
54+
int mCrossSize;
55+
56+
/** @see {@link #getItemCount()} */
57+
int mItemCount;
58+
59+
/** @see {@link #getTotalFlexGrow()} */
60+
float mTotalFlexGrow;
61+
62+
/** @see {@link #getTotalFlexShrink()} */
63+
float mTotalFlexShrink;
64+
65+
/**
66+
* The largest value of the individual child's baseline (obtained by View#getBaseline()
67+
* if the {@link FlexboxLayout#mAlignItems} value is not {@link FlexboxLayout#ALIGN_ITEMS_BASELINE}
68+
* or the flex direction is vertical, this value is not used.
69+
* If the alignment direction is from the bottom to top,
70+
* (e.g. flexWrap == FLEX_WRAP_WRAP_REVERSE and flexDirection == FLEX_DIRECTION_ROW)
71+
* store this value from the distance from the bottom of the view minus baseline.
72+
* (Calculated as view.getMeasuredHeight() - view.getBaseline - LayoutParams.bottomMargin)
73+
*/
74+
int mMaxBaseline;
75+
76+
/**
77+
* Store the indices of the children views whose alignSelf property is stretch.
78+
* The stored indices are the absolute indices including all children in the Flexbox,
79+
* not the relative indices in this flex line.
80+
*/
81+
List<Integer> mIndicesAlignSelfStretch = new ArrayList<>();
82+
83+
/**
84+
* @return the distance in pixels from the top edge of this view's parent
85+
* to the top edge of this FlexLine.
86+
*/
87+
public int getLeft() {
88+
return mLeft;
89+
}
90+
91+
/**
92+
* @return the distance in pixels from the top edge of this view's parent
93+
* to the top edge of this FlexLine.
94+
*/
95+
public int getTop() {
96+
return mTop;
97+
}
98+
99+
/**
100+
* @return the distance in pixels from the right edge of this view's parent
101+
* to the right edge of this FlexLine.
102+
*/
103+
public int getRight() {
104+
return mRight;
105+
}
106+
107+
/**
108+
* @return the distance in pixels from the bottom edge of this view's parent
109+
* to the bottom edge of this FlexLine.
110+
*/
111+
public int getBottom() {
112+
return mBottom;
113+
}
114+
115+
/**
116+
* @return the size of the flex line in pixels along the main axis of the flex container.
117+
*/
118+
public int getMainSize() {
119+
return mMainSize;
120+
}
121+
122+
/**
123+
* @return the size of the flex line in pixels along the cross axis of the flex container.
124+
*/
125+
public int getCrossSize() {
126+
return mCrossSize;
127+
}
128+
129+
/**
130+
* @return the count of the views contained in this flex line.
131+
*/
132+
public int getItemCount() {
133+
return mItemCount;
134+
}
135+
136+
/**
137+
* @return the sum of the flexGrow properties of the children included in this flex line
138+
*/
139+
public float getTotalFlexGrow() {
140+
return mTotalFlexGrow;
141+
}
142+
143+
/**
144+
* @return the sum of the flexShrink properties of the children included in this flex line
145+
*/
146+
public float getTotalFlexShrink() {
147+
return mTotalFlexShrink;
148+
}
149+
}

0 commit comments

Comments
 (0)