Skip to content

Commit 3dd7737

Browse files
Merge branch 'master' of https://github.com/Mantano/AndroidLibs into Mantano-master
# Conflicts: # flowlayoutmanager/build.gradle # flowlayoutmanager/src/main/java/com/xiaofeng/flowlayoutmanager/FlowLayoutManager.java
2 parents 74d957d + d8c2bd7 commit 3dd7737

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

flowlayoutmanager/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ project.ext {
1212
siteUrl = 'https://github.com/xiaofeng-han/AndroidLibs'
1313
}
1414

15+
repositories {
16+
jcenter()
17+
}
18+
1519
group = 'com.xiaofeng.android'
1620
version = libVersion
1721

@@ -48,7 +52,13 @@ dependencies {
4852
compile(group: 'com.android.support', name: 'recyclerview-v7', version: supportLibVersion)
4953
androidTestCompile 'com.android.support:support-annotations:26.1.0'
5054
androidTestCompile 'com.android.support.test:runner:1.0.1'
55+
5156
}
5257

5358
Properties properties = new Properties()
5459
properties.load(project.rootProject.file('local.properties').newDataInputStream())
60+
61+
62+
task wrapper(type: Wrapper) {
63+
gradleVersion = '2.10'
64+
}

flowlayoutmanager/src/main/java/com/xiaofeng/flowlayoutmanager/FlowLayoutManager.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.graphics.Point;
44
import android.graphics.PointF;
55
import android.graphics.Rect;
6+
import android.os.Build;
67
import android.support.annotation.Nullable;
78
import android.support.v7.widget.LinearSmoothScroller;
89
import android.support.v7.widget.RecyclerView;
@@ -472,17 +473,14 @@ public void onAttachedToWindow(final RecyclerView view) {
472473
layoutHelper = new LayoutHelper(this, recyclerView);
473474
cacheHelper = new CacheHelper(flowLayoutOptions.itemsPerLine, layoutHelper.visibleAreaWidth());
474475
if (layoutHelper.visibleAreaWidth() == 0) {
475-
if (globalLayoutListener == null) {
476-
globalLayoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
477-
@Override
478-
public void onGlobalLayout() {
479-
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);
480-
globalLayoutListener = null;
481-
cacheHelper.contentAreaWidth(layoutHelper.visibleAreaWidth());
482-
}
483-
};
484-
}
485-
view.getViewTreeObserver().addOnGlobalLayoutListener(globalLayoutListener);
476+
477+
view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
478+
@Override
479+
public void onGlobalLayout() {
480+
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
481+
cacheHelper.contentAreaWidth(layoutHelper.visibleAreaWidth());
482+
}
483+
});
486484
}
487485

488486
}
@@ -491,7 +489,9 @@ public void onGlobalLayout() {
491489
public void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler) {
492490
super.onDetachedFromWindow(view, recycler);
493491
if (globalLayoutListener != null) {
494-
view.getViewTreeObserver().removeOnGlobalLayoutListener(globalLayoutListener);
492+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
493+
view.getViewTreeObserver().removeOnGlobalLayoutListener(globalLayoutListener);
494+
}
495495
globalLayoutListener = null;
496496
}
497497
}

0 commit comments

Comments
 (0)