Skip to content

Commit 358c048

Browse files
authored
Fixes the issue google#192 that a minifyEnabled apk can't be built with (google#193)
0.3.0-alpha1 version of the library
1 parent 1890984 commit 358c048

File tree

3 files changed

+28
-43
lines changed

3 files changed

+28
-43
lines changed

demo-cat-gallery/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ android {
3131
}
3232
buildTypes {
3333
release {
34-
minifyEnabled false
34+
shrinkResources true
35+
minifyEnabled true
3536
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3637
}
3738
}

demo-playground/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ android {
3131
}
3232
buildTypes {
3333
release {
34-
minifyEnabled false
34+
shrinkResources true
35+
minifyEnabled true
3536
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
3637
}
3738
}

flexbox/src/main/java/com/google/android/flexbox/FlexboxLayoutManager.java

+24-41
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import android.graphics.Rect;
2424
import android.os.Parcel;
2525
import android.os.Parcelable;
26-
import android.support.annotation.IntDef;
2726
import android.support.v4.view.ViewCompat;
2827
import android.support.v7.widget.LinearLayoutManager;
2928
import android.support.v7.widget.OrientationHelper;
@@ -33,8 +32,6 @@
3332
import android.view.View;
3433
import android.view.ViewGroup;
3534

36-
import java.lang.annotation.Retention;
37-
import java.lang.annotation.RetentionPolicy;
3835
import java.util.ArrayList;
3936
import java.util.List;
4037

@@ -993,7 +990,7 @@ private void recycleByLayoutState(RecyclerView.Recycler recycler, LayoutState la
993990
if (!layoutState.mShouldRecycle) {
994991
return;
995992
}
996-
if (layoutState.mLayoutDirection == LayoutDirection.START) {
993+
if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
997994
// TODO: Consider the case mFlexWrap is set to nowrap and view is recycled individually
998995
recycleFlexLinesFromEnd(recycler, layoutState);
999996
} else {
@@ -1100,7 +1097,7 @@ private int layoutFlexLineMainAxisHorizontal(FlexLine flexLine, LayoutState layo
11001097
int parentWidth = getWidth();
11011098

11021099
int childTop = layoutState.mOffset;
1103-
if (layoutState.mLayoutDirection == LayoutDirection.START) {
1100+
if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
11041101
childTop = childTop - flexLine.mCrossSize;
11051102
}
11061103
int startPosition = layoutState.mPosition;
@@ -1143,7 +1140,7 @@ private int layoutFlexLineMainAxisHorizontal(FlexLine flexLine, LayoutState layo
11431140
}
11441141
spaceBetweenItem = Math.max(spaceBetweenItem, 0);
11451142

1146-
// Used only when mLayoutDirection == LayoutDirection.START to remember the index
1143+
// Used only when mLayoutDirection == LayoutState.LAYOUT_START to remember the index
11471144
// a flex item should be inserted
11481145
int indexInFlexLine = 0;
11491146
for (int i = startPosition, itemCount = flexLine.getItemCount();
@@ -1153,7 +1150,7 @@ private int layoutFlexLineMainAxisHorizontal(FlexLine flexLine, LayoutState layo
11531150
continue;
11541151
}
11551152

1156-
if (layoutState.mLayoutDirection == LayoutDirection.END) {
1153+
if (layoutState.mLayoutDirection == LayoutState.LAYOUT_END) {
11571154
addView(view);
11581155
} else {
11591156
addView(view, indexInFlexLine);
@@ -1207,7 +1204,7 @@ private int layoutFlexLineMainAxisVertical(FlexLine flexLine, LayoutState layout
12071204

12081205
// Either childLeft or childRight is used depending on the layoutState.mLayoutDirection
12091206
int childLeft = layoutState.mOffset;
1210-
if (layoutState.mLayoutDirection == LayoutDirection.START) {
1207+
if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) {
12111208
childLeft = childLeft - flexLine.mCrossSize;
12121209
}
12131210
int startPosition = layoutState.mPosition;
@@ -1251,7 +1248,7 @@ private int layoutFlexLineMainAxisVertical(FlexLine flexLine, LayoutState layout
12511248
}
12521249
spaceBetweenItem = Math.max(spaceBetweenItem, 0);
12531250

1254-
// Used only when mLayoutDirection == LayoutDirection.START to remember the index
1251+
// Used only when mLayoutDirection == LayoutState.LAYOUT_START to remember the index
12551252
// a flex item should be inserted
12561253
int indexInFlexLine = 0;
12571254
for (int i = startPosition, itemCount = flexLine.getItemCount();
@@ -1275,7 +1272,7 @@ private int layoutFlexLineMainAxisVertical(FlexLine flexLine, LayoutState layout
12751272
childTop += (lp.topMargin + getTopDecorationHeight(view));
12761273
childBottom -= (lp.rightMargin + getBottomDecorationHeight(view));
12771274

1278-
if (layoutState.mLayoutDirection == LayoutDirection.END) {
1275+
if (layoutState.mLayoutDirection == LayoutState.LAYOUT_END) {
12791276
addView(view);
12801277
} else {
12811278
addView(view, indexInFlexLine);
@@ -1322,8 +1319,8 @@ boolean isMainAxisDirectionHorizontal() {
13221319
private void updateLayoutStateToFillEnd(AnchorInfo anchorInfo, boolean fromNextLine) {
13231320
mLayoutState.mAvailable = mOrientationHelper.getEndAfterPadding() - anchorInfo.mCoordinate;
13241321
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;
13271324
mLayoutState.mOffset = anchorInfo.mCoordinate;
13281325
mLayoutState.mScrollingOffset = LayoutState.SCROLLING_OFFSET_NaN;
13291326
mLayoutState.mFlexLinePosition = anchorInfo.mFlexLinePosition;
@@ -1351,8 +1348,8 @@ private void updateLayoutStateToFillStart(AnchorInfo anchorInfo, boolean fromPre
13511348
mLayoutState.mAvailable = anchorInfo.mCoordinate - mOrientationHelper
13521349
.getStartAfterPadding();
13531350
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;
13561353
mLayoutState.mOffset = anchorInfo.mCoordinate;
13571354
mLayoutState.mScrollingOffset = LayoutState.SCROLLING_OFFSET_NaN;
13581355
mLayoutState.mFlexLinePosition = anchorInfo.mFlexLinePosition;
@@ -1444,7 +1441,7 @@ private int handleScrolling(int delta, RecyclerView.Recycler recycler,
14441441
}
14451442
ensureOrientationHelper();
14461443
mLayoutState.mShouldRecycle = true;
1447-
int layoutDirection = delta > 0 ? LayoutDirection.END : LayoutDirection.START;
1444+
int layoutDirection = delta > 0 ? LayoutState.LAYOUT_END : LayoutState.LAYOUT_START;
14481445
int absDelta = Math.abs(delta);
14491446

14501447
updateLayoutState(layoutDirection, absDelta);
@@ -1460,12 +1457,12 @@ private int handleScrolling(int delta, RecyclerView.Recycler recycler,
14601457
return scrolled;
14611458
}
14621459

1463-
private void updateLayoutState(@LayoutDirection int layoutDirection, int absDelta) {
1460+
private void updateLayoutState(int layoutDirection, int absDelta) {
14641461
assert mFlexboxHelper.mIndexToFlexLine != null;
14651462
// TODO: Consider updating LayoutState#mExtra to support better smooth scrolling
14661463
mLayoutState.mLayoutDirection = layoutDirection;
14671464
boolean mainAxisHorizontal = isMainAxisDirectionHorizontal();
1468-
if (layoutDirection == LayoutDirection.END) {
1465+
if (layoutDirection == LayoutState.LAYOUT_END) {
14691466
View lastVisible = getChildAt(getChildCount() - 1);
14701467
mLayoutState.mOffset = mOrientationHelper.getDecoratedEnd(lastVisible);
14711468
int lastVisiblePosition = getPosition(lastVisible);
@@ -1477,7 +1474,7 @@ private void updateLayoutState(@LayoutDirection int layoutDirection, int absDelt
14771474
View referenceView = findLastReferenceViewInLine(lastVisible, lastVisibleLine);
14781475

14791476
mLayoutState.mOffset = mOrientationHelper.getDecoratedEnd(referenceView);
1480-
mLayoutState.mItemDirection = ItemDirection.TAIL;
1477+
mLayoutState.mItemDirection = LayoutState.ITEM_DIRECTION_TAIL;
14811478
mLayoutState.mPosition = lastVisiblePosition + mLayoutState.mItemDirection;
14821479
if (mFlexboxHelper.mIndexToFlexLine.length <= mLayoutState.mPosition) {
14831480
mLayoutState.mFlexLinePosition = NO_POSITION;
@@ -1527,7 +1524,7 @@ private void updateLayoutState(@LayoutDirection int layoutDirection, int absDelt
15271524
View referenceView = findFirstReferenceViewInLine(firstVisible, firstVisibleLine);
15281525

15291526
mLayoutState.mOffset = mOrientationHelper.getDecoratedStart(referenceView);
1530-
mLayoutState.mItemDirection = ItemDirection.TAIL;
1527+
mLayoutState.mItemDirection = LayoutState.ITEM_DIRECTION_TAIL;
15311528
int flexLinePosition = mFlexboxHelper.mIndexToFlexLine[firstVisiblePosition];
15321529
if (flexLinePosition == NO_POSITION) {
15331530
flexLinePosition = 0;
@@ -2019,24 +2016,6 @@ public String toString() {
20192016
}
20202017
}
20212018

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-
20402019
/**
20412020
* Helper class that keeps temporary state while the FlexboxLayoutManager is filling out the
20422021
* empty space.
@@ -2045,6 +2024,12 @@ private static class LayoutState {
20452024

20462025
private final static int SCROLLING_OFFSET_NaN = Integer.MIN_VALUE;
20472026

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+
20482033
/** Number of pixels that we should fill, in the layout direction. */
20492034
private int mAvailable;
20502035

@@ -2073,11 +2058,9 @@ private static class LayoutState {
20732058
*/
20742059
int mLastScrollDelta;
20752060

2076-
@ItemDirection
2077-
private int mItemDirection = ItemDirection.TAIL;
2061+
private int mItemDirection = LayoutState.ITEM_DIRECTION_TAIL;
20782062

2079-
@LayoutDirection
2080-
private int mLayoutDirection = LayoutDirection.END;
2063+
private int mLayoutDirection = LayoutState.LAYOUT_END;
20812064

20822065
private boolean mShouldRecycle;
20832066

0 commit comments

Comments
 (0)