23
23
import android .graphics .Rect ;
24
24
import android .os .Parcel ;
25
25
import android .os .Parcelable ;
26
- import android .support .annotation .IntDef ;
27
26
import android .support .v4 .view .ViewCompat ;
28
27
import android .support .v7 .widget .LinearLayoutManager ;
29
28
import android .support .v7 .widget .OrientationHelper ;
33
32
import android .view .View ;
34
33
import android .view .ViewGroup ;
35
34
36
- import java .lang .annotation .Retention ;
37
- import java .lang .annotation .RetentionPolicy ;
38
35
import java .util .ArrayList ;
39
36
import java .util .List ;
40
37
@@ -993,7 +990,7 @@ private void recycleByLayoutState(RecyclerView.Recycler recycler, LayoutState la
993
990
if (!layoutState .mShouldRecycle ) {
994
991
return ;
995
992
}
996
- if (layoutState .mLayoutDirection == LayoutDirection . START ) {
993
+ if (layoutState .mLayoutDirection == LayoutState . LAYOUT_START ) {
997
994
// TODO: Consider the case mFlexWrap is set to nowrap and view is recycled individually
998
995
recycleFlexLinesFromEnd (recycler , layoutState );
999
996
} else {
@@ -1100,7 +1097,7 @@ private int layoutFlexLineMainAxisHorizontal(FlexLine flexLine, LayoutState layo
1100
1097
int parentWidth = getWidth ();
1101
1098
1102
1099
int childTop = layoutState .mOffset ;
1103
- if (layoutState .mLayoutDirection == LayoutDirection . START ) {
1100
+ if (layoutState .mLayoutDirection == LayoutState . LAYOUT_START ) {
1104
1101
childTop = childTop - flexLine .mCrossSize ;
1105
1102
}
1106
1103
int startPosition = layoutState .mPosition ;
@@ -1143,7 +1140,7 @@ private int layoutFlexLineMainAxisHorizontal(FlexLine flexLine, LayoutState layo
1143
1140
}
1144
1141
spaceBetweenItem = Math .max (spaceBetweenItem , 0 );
1145
1142
1146
- // Used only when mLayoutDirection == LayoutDirection.START to remember the index
1143
+ // Used only when mLayoutDirection == LayoutState.LAYOUT_START to remember the index
1147
1144
// a flex item should be inserted
1148
1145
int indexInFlexLine = 0 ;
1149
1146
for (int i = startPosition , itemCount = flexLine .getItemCount ();
@@ -1153,7 +1150,7 @@ private int layoutFlexLineMainAxisHorizontal(FlexLine flexLine, LayoutState layo
1153
1150
continue ;
1154
1151
}
1155
1152
1156
- if (layoutState .mLayoutDirection == LayoutDirection . END ) {
1153
+ if (layoutState .mLayoutDirection == LayoutState . LAYOUT_END ) {
1157
1154
addView (view );
1158
1155
} else {
1159
1156
addView (view , indexInFlexLine );
@@ -1207,7 +1204,7 @@ private int layoutFlexLineMainAxisVertical(FlexLine flexLine, LayoutState layout
1207
1204
1208
1205
// Either childLeft or childRight is used depending on the layoutState.mLayoutDirection
1209
1206
int childLeft = layoutState .mOffset ;
1210
- if (layoutState .mLayoutDirection == LayoutDirection . START ) {
1207
+ if (layoutState .mLayoutDirection == LayoutState . LAYOUT_START ) {
1211
1208
childLeft = childLeft - flexLine .mCrossSize ;
1212
1209
}
1213
1210
int startPosition = layoutState .mPosition ;
@@ -1251,7 +1248,7 @@ private int layoutFlexLineMainAxisVertical(FlexLine flexLine, LayoutState layout
1251
1248
}
1252
1249
spaceBetweenItem = Math .max (spaceBetweenItem , 0 );
1253
1250
1254
- // Used only when mLayoutDirection == LayoutDirection.START to remember the index
1251
+ // Used only when mLayoutDirection == LayoutState.LAYOUT_START to remember the index
1255
1252
// a flex item should be inserted
1256
1253
int indexInFlexLine = 0 ;
1257
1254
for (int i = startPosition , itemCount = flexLine .getItemCount ();
@@ -1275,7 +1272,7 @@ private int layoutFlexLineMainAxisVertical(FlexLine flexLine, LayoutState layout
1275
1272
childTop += (lp .topMargin + getTopDecorationHeight (view ));
1276
1273
childBottom -= (lp .rightMargin + getBottomDecorationHeight (view ));
1277
1274
1278
- if (layoutState .mLayoutDirection == LayoutDirection . END ) {
1275
+ if (layoutState .mLayoutDirection == LayoutState . LAYOUT_END ) {
1279
1276
addView (view );
1280
1277
} else {
1281
1278
addView (view , indexInFlexLine );
@@ -1322,8 +1319,8 @@ boolean isMainAxisDirectionHorizontal() {
1322
1319
private void updateLayoutStateToFillEnd (AnchorInfo anchorInfo , boolean fromNextLine ) {
1323
1320
mLayoutState .mAvailable = mOrientationHelper .getEndAfterPadding () - anchorInfo .mCoordinate ;
1324
1321
mLayoutState .mPosition = anchorInfo .mPosition ;
1325
- mLayoutState .mItemDirection = ItemDirection . TAIL ;
1326
- mLayoutState .mLayoutDirection = LayoutDirection . END ;
1322
+ mLayoutState .mItemDirection = LayoutState . ITEM_DIRECTION_TAIL ;
1323
+ mLayoutState .mLayoutDirection = LayoutState . LAYOUT_END ;
1327
1324
mLayoutState .mOffset = anchorInfo .mCoordinate ;
1328
1325
mLayoutState .mScrollingOffset = LayoutState .SCROLLING_OFFSET_NaN ;
1329
1326
mLayoutState .mFlexLinePosition = anchorInfo .mFlexLinePosition ;
@@ -1351,8 +1348,8 @@ private void updateLayoutStateToFillStart(AnchorInfo anchorInfo, boolean fromPre
1351
1348
mLayoutState .mAvailable = anchorInfo .mCoordinate - mOrientationHelper
1352
1349
.getStartAfterPadding ();
1353
1350
mLayoutState .mPosition = anchorInfo .mPosition ;
1354
- mLayoutState .mItemDirection = ItemDirection . TAIL ;
1355
- mLayoutState .mLayoutDirection = LayoutDirection . START ;
1351
+ mLayoutState .mItemDirection = LayoutState . ITEM_DIRECTION_TAIL ;
1352
+ mLayoutState .mLayoutDirection = LayoutState . LAYOUT_START ;
1356
1353
mLayoutState .mOffset = anchorInfo .mCoordinate ;
1357
1354
mLayoutState .mScrollingOffset = LayoutState .SCROLLING_OFFSET_NaN ;
1358
1355
mLayoutState .mFlexLinePosition = anchorInfo .mFlexLinePosition ;
@@ -1444,7 +1441,7 @@ private int handleScrolling(int delta, RecyclerView.Recycler recycler,
1444
1441
}
1445
1442
ensureOrientationHelper ();
1446
1443
mLayoutState .mShouldRecycle = true ;
1447
- int layoutDirection = delta > 0 ? LayoutDirection . END : LayoutDirection . START ;
1444
+ int layoutDirection = delta > 0 ? LayoutState . LAYOUT_END : LayoutState . LAYOUT_START ;
1448
1445
int absDelta = Math .abs (delta );
1449
1446
1450
1447
updateLayoutState (layoutDirection , absDelta );
@@ -1460,12 +1457,12 @@ private int handleScrolling(int delta, RecyclerView.Recycler recycler,
1460
1457
return scrolled ;
1461
1458
}
1462
1459
1463
- private void updateLayoutState (@ LayoutDirection int layoutDirection , int absDelta ) {
1460
+ private void updateLayoutState (int layoutDirection , int absDelta ) {
1464
1461
assert mFlexboxHelper .mIndexToFlexLine != null ;
1465
1462
// TODO: Consider updating LayoutState#mExtra to support better smooth scrolling
1466
1463
mLayoutState .mLayoutDirection = layoutDirection ;
1467
1464
boolean mainAxisHorizontal = isMainAxisDirectionHorizontal ();
1468
- if (layoutDirection == LayoutDirection . END ) {
1465
+ if (layoutDirection == LayoutState . LAYOUT_END ) {
1469
1466
View lastVisible = getChildAt (getChildCount () - 1 );
1470
1467
mLayoutState .mOffset = mOrientationHelper .getDecoratedEnd (lastVisible );
1471
1468
int lastVisiblePosition = getPosition (lastVisible );
@@ -1477,7 +1474,7 @@ private void updateLayoutState(@LayoutDirection int layoutDirection, int absDelt
1477
1474
View referenceView = findLastReferenceViewInLine (lastVisible , lastVisibleLine );
1478
1475
1479
1476
mLayoutState .mOffset = mOrientationHelper .getDecoratedEnd (referenceView );
1480
- mLayoutState .mItemDirection = ItemDirection . TAIL ;
1477
+ mLayoutState .mItemDirection = LayoutState . ITEM_DIRECTION_TAIL ;
1481
1478
mLayoutState .mPosition = lastVisiblePosition + mLayoutState .mItemDirection ;
1482
1479
if (mFlexboxHelper .mIndexToFlexLine .length <= mLayoutState .mPosition ) {
1483
1480
mLayoutState .mFlexLinePosition = NO_POSITION ;
@@ -1527,7 +1524,7 @@ private void updateLayoutState(@LayoutDirection int layoutDirection, int absDelt
1527
1524
View referenceView = findFirstReferenceViewInLine (firstVisible , firstVisibleLine );
1528
1525
1529
1526
mLayoutState .mOffset = mOrientationHelper .getDecoratedStart (referenceView );
1530
- mLayoutState .mItemDirection = ItemDirection . TAIL ;
1527
+ mLayoutState .mItemDirection = LayoutState . ITEM_DIRECTION_TAIL ;
1531
1528
int flexLinePosition = mFlexboxHelper .mIndexToFlexLine [firstVisiblePosition ];
1532
1529
if (flexLinePosition == NO_POSITION ) {
1533
1530
flexLinePosition = 0 ;
@@ -2019,24 +2016,6 @@ public String toString() {
2019
2016
}
2020
2017
}
2021
2018
2022
- /** Defines the direction in which the layout is filled. */
2023
- @ IntDef ({LayoutDirection .START , LayoutDirection .END })
2024
- @ Retention (RetentionPolicy .SOURCE )
2025
- private @interface LayoutDirection {
2026
-
2027
- int START = -1 ;
2028
- int END = 1 ;
2029
- }
2030
-
2031
- /** Defines the direction in which the data adapter is traversed. */
2032
- @ IntDef ({ItemDirection .HEAD , ItemDirection .TAIL })
2033
- @ Retention (RetentionPolicy .SOURCE )
2034
- private @interface ItemDirection {
2035
-
2036
- int HEAD = -1 ;
2037
- int TAIL = 1 ;
2038
- }
2039
-
2040
2019
/**
2041
2020
* Helper class that keeps temporary state while the FlexboxLayoutManager is filling out the
2042
2021
* empty space.
@@ -2045,6 +2024,12 @@ private static class LayoutState {
2045
2024
2046
2025
private final static int SCROLLING_OFFSET_NaN = Integer .MIN_VALUE ;
2047
2026
2027
+ private static final int LAYOUT_START = -1 ;
2028
+ private static final int LAYOUT_END = 1 ;
2029
+
2030
+ private static final int ITEM_DIRECTION_HEAD = -1 ;
2031
+ private static final int ITEM_DIRECTION_TAIL = 1 ;
2032
+
2048
2033
/** Number of pixels that we should fill, in the layout direction. */
2049
2034
private int mAvailable ;
2050
2035
@@ -2073,11 +2058,9 @@ private static class LayoutState {
2073
2058
*/
2074
2059
int mLastScrollDelta ;
2075
2060
2076
- @ ItemDirection
2077
- private int mItemDirection = ItemDirection .TAIL ;
2061
+ private int mItemDirection = LayoutState .ITEM_DIRECTION_TAIL ;
2078
2062
2079
- @ LayoutDirection
2080
- private int mLayoutDirection = LayoutDirection .END ;
2063
+ private int mLayoutDirection = LayoutState .LAYOUT_END ;
2081
2064
2082
2065
private boolean mShouldRecycle ;
2083
2066
0 commit comments