Skip to content

Commit 73b2425

Browse files
Merge branch 'master' of https://github.com/antondudakov/AndroidLibs into antondudakov-master
# Conflicts: # .idea/gradle.xml # .idea/misc.xml # app/build.gradle # build.gradle # flowlayoutmanager/build.gradle # flowlayoutmanager/src/main/java/com/xiaofeng/flowlayoutmanager/FlowLayoutManager.java # gradle/wrapper/gradle-wrapper.properties
1 parent 7dd1c19 commit 73b2425

11 files changed

Lines changed: 156 additions & 80 deletions

File tree

.idea/gradle.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/java/com/xiaofeng/androidlibs/MainActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@
1919

2020
public class MainActivity extends AppCompatActivity {
2121

22-
RecyclerView recyclerView;
22+
private static final int REQ_CODE_SETTINGS = 101;
23+
RecyclerView recyclerView;
2324
FlowLayoutManager flowLayoutManager;
2425
MarkdownView markdownView;
25-
private static final int REQ_CODE_SETTINGS = 101;
2626
private boolean settingChanged = false;
2727
@Override
2828
protected void onCreate(Bundle savedInstanceState) {
2929
super.onCreate(savedInstanceState);
3030
setContentView(R.layout.app_bar_main);
31-
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
32-
setSupportActionBar(toolbar);
31+
Toolbar toolbar = findViewById(R.id.toolbar);
32+
setSupportActionBar(toolbar);
3333
init();
3434
}
3535

3636
private void init() {
37-
recyclerView = (RecyclerView) findViewById(R.id.list);
38-
flowLayoutManager = new FlowLayoutManager().singleItemPerLine();
37+
recyclerView = findViewById(R.id.list);
38+
flowLayoutManager = new FlowLayoutManager().singleItemPerLine();
3939
flowLayoutManager.setAutoMeasureEnabled(true);
4040
recyclerView.setLayoutManager(flowLayoutManager);
4141
recyclerView.setAdapter(new DemoAdapter(1, DemoUtil.generate(32, 10, 60, 1, false)));

app/src/main/res/drawable/tagbg.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
<solid android:color="@color/colorPrimaryDark" />
55
<stroke
6-
android:color="@color/colorAccent"
76
android:width="1dp"
8-
/>
7+
android:color="@color/colorAccent" />
98
<corners android:radius="4dp" />
109

1110
</shape>

app/src/main/res/layout/content_main.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@
55
xmlns:tools="http://schemas.android.com/tools"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8+
android:orientation="vertical"
89
android:paddingBottom="@dimen/activity_vertical_margin"
910
android:paddingLeft="@dimen/activity_horizontal_margin"
1011
android:paddingRight="@dimen/activity_horizontal_margin"
1112
android:paddingTop="@dimen/activity_vertical_margin"
1213
app:layout_behavior="@string/appbar_scrolling_view_behavior"
1314
tools:context="com.xiaofeng.androidlibs.MainActivity"
14-
tools:showIn="@layout/app_bar_main"
15-
android:orientation="vertical">
15+
tools:showIn="@layout/app_bar_main">
1616
<FrameLayout
1717
android:layout_width="match_parent"
1818
android:layout_height="wrap_content"
19-
android:padding="8dp"
20-
android:background="@color/instructionBackground">
19+
android:background="@color/instructionBackground"
20+
android:padding="8dp">
2121
<us.feras.mdv.MarkdownView
2222
android:id="@+id/instruction_mdown"
2323
android:layout_width="match_parent"
@@ -28,11 +28,11 @@
2828
android:id="@+id/list"
2929
android:layout_width="match_parent"
3030
android:layout_height="match_parent"
31-
android:padding="48dp"
31+
android:background="?attr/colorPrimary"
3232
android:clipToPadding="false"
33-
android:scrollbars="vertical"
33+
android:fadeScrollbars="false"
34+
android:padding="48dp"
3435
android:scrollbarStyle="outsideOverlay"
3536
android:scrollbarThumbVertical="@color/colorPrimaryDark"
36-
android:fadeScrollbars="false"
37-
android:background="?attr/colorPrimary"/>
37+
android:scrollbars="vertical" />
3838
</LinearLayout>
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:orientation="horizontal"
43
android:layout_width="wrap_content"
54
android:layout_height="wrap_content"
6-
android:background="@drawable/tagbg"
5+
android:background="@drawable/tagbg"
6+
android:orientation="horizontal"
77
android:padding="10dp">
88
<TextView
99
android:id="@+id/tag_text"
1010
android:layout_width="wrap_content"
1111
android:layout_height="wrap_content"
1212
android:layout_marginRight="4dp"
13-
android:textColor="@android:color/white"
14-
android:text="0000"/>
13+
android:text="0000"
14+
android:textColor="@android:color/white" />
1515
<TextView
1616
android:id="@+id/tag_count"
1717
android:layout_width="wrap_content"
18-
android:textColor="@android:color/white"
1918
android:layout_height="wrap_content"
20-
android:text="(4)"/>
19+
android:text="(4)"
20+
android:textColor="@android:color/white" />
2121

2222
</LinearLayout>

flowlayoutmanager/.gitignore

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1-
/build
2-
.idea/
3-
/*/.idea/
1+
#built application files
2+
*.apk
3+
*.ap_
4+
5+
# files for the dex VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# generated files
12+
bin/
13+
gen/
14+
15+
# Local configuration file (sdk path, etc)
16+
local.properties
17+
18+
# Windows thumbnail db
19+
Thumbs.db
20+
21+
# OSX files
22+
.DS_Store
23+
24+
# Android Studio
25+
*.iml
26+
.idea
27+
#.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
28+
.gradle
29+
build/
30+
.navigation
31+
captures/
32+
output.json
33+
34+
#NDK
35+
obj/
36+
.externalNativeBuild

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
*/
66
public enum Alignment {
77
LEFT,
8-
RIGHT,
9-
CENTER
8+
RIGHT,
9+
CENTER
1010
}

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

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.xiaofeng.flowlayoutmanager;
22

3-
import com.xiaofeng.flowlayoutmanager.cache.CacheHelper;
4-
import com.xiaofeng.flowlayoutmanager.cache.Line;
5-
63
import android.graphics.Point;
74
import android.graphics.PointF;
85
import android.graphics.Rect;
@@ -12,7 +9,6 @@
129
import android.view.View;
1310
import android.view.ViewGroup;
1411
import android.view.ViewTreeObserver;
15-
import android.widget.Toast;
1612

1713
import com.xiaofeng.flowlayoutmanager.cache.CacheHelper;
1814
import com.xiaofeng.flowlayoutmanager.cache.Line;
@@ -27,15 +23,15 @@
2723
public class FlowLayoutManager extends RecyclerView.LayoutManager {
2824

2925
private static final String LOG_TAG = "FlowLayoutManager";
30-
RecyclerView recyclerView;
31-
int firstChildAdapterPosition = 0;
32-
RecyclerView.Recycler recyclerRef;
33-
FlowLayoutOptions flowLayoutOptions;
34-
FlowLayoutOptions newFlowLayoutOptions;
35-
LayoutHelper layoutHelper;
36-
CacheHelper cacheHelper;
37-
@Nullable
38-
private ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener;
26+
private RecyclerView recyclerView;
27+
private int firstChildAdapterPosition = 0;
28+
private RecyclerView.Recycler recyclerRef;
29+
private FlowLayoutOptions flowLayoutOptions;
30+
private FlowLayoutOptions newFlowLayoutOptions;
31+
private LayoutHelper layoutHelper;
32+
private CacheHelper cacheHelper;
33+
@Nullable
34+
private ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener;
3935

4036
public FlowLayoutManager() {
4137
flowLayoutOptions = new FlowLayoutOptions();
@@ -503,14 +499,14 @@ public void onGlobalLayout() {
503499

504500
}
505501

506-
@Override
507-
public void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler) {
508-
super.onDetachedFromWindow(view, recycler);
509-
if (globalLayoutListener != null) {
510-
view.getViewTreeObserver().removeOnGlobalLayoutListener(globalLayoutListener);
511-
globalLayoutListener = null;
512-
}
513-
}
502+
@Override
503+
public void onDetachedFromWindow(RecyclerView view, RecyclerView.Recycler recycler) {
504+
super.onDetachedFromWindow(view, recycler);
505+
if (globalLayoutListener != null) {
506+
view.getViewTreeObserver().removeOnGlobalLayoutListener(globalLayoutListener);
507+
globalLayoutListener = null;
508+
}
509+
}
514510

515511
@Override
516512
public boolean supportsPredictiveItemAnimations() {
@@ -614,9 +610,9 @@ private int getMaxHeightLayoutPositionInLine(int layoutPosition) {
614610

615611
private List<View> getAllViewsInLine(int index) {
616612
int firstItemIndex = index;
617-
while (!isStartOfLine(firstItemIndex)) {
618-
firstItemIndex --;
619-
}
613+
while (!isStartOfLine(firstItemIndex)) {
614+
firstItemIndex--;
615+
}
620616

621617
List<View> viewList = new LinkedList<>();
622618
viewList.add(getChildAt(firstItemIndex));
@@ -912,7 +908,7 @@ public int computeVerticalScrollExtent(RecyclerView.State state) {
912908
return 0;
913909
}
914910
// if (!smoothScrollbarEnabled) {
915-
return Math.abs(getPosition(startChild) - getPosition(endChild)) + 1;
911+
return Math.abs(getPosition(startChild) - getPosition(endChild)) + 1;
916912
// }
917913
// final int extend = getDecoratedRight(endChild) - getDecoratedLeft(startChild);
918914
// return Math.min(getTotalSpace(), extend);

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

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,6 @@ public LayoutHelper(RecyclerView.LayoutManager layoutManager, RecyclerView recyc
1515
this.recyclerView = recyclerView;
1616
}
1717

18-
public int leftVisibleEdge() {
19-
return recyclerView.getPaddingLeft();
20-
}
21-
22-
public int rightVisibleEdge() {
23-
return layoutManager.getWidth() - layoutManager.getPaddingRight();
24-
}
25-
26-
public int visibleAreaWidth() {
27-
return rightVisibleEdge() - leftVisibleEdge();
28-
}
29-
30-
public int topVisibleEdge() {
31-
return layoutManager.getPaddingTop();
32-
}
33-
34-
public int bottomVisibleEdge() {
35-
return layoutManager.getHeight() - layoutManager.getPaddingBottom();
36-
}
37-
3818
public static boolean hasItemsPerLineLimit(FlowLayoutOptions layoutOptions) {
3919
return layoutOptions.itemsPerLine > 0;
4020
}
@@ -47,20 +27,40 @@ public static boolean shouldStartNewline(int x, int childWidth, int leftEdge, in
4727
case RIGHT:
4828
return x - childWidth < leftEdge;
4929
case LEFT:
50-
case CENTER:
51-
default:
52-
return x + childWidth > rightEdge;
30+
case CENTER:
31+
default:
32+
return x + childWidth > rightEdge;
5333
}
5434
}
5535

36+
public int leftVisibleEdge() {
37+
return recyclerView.getPaddingLeft();
38+
}
39+
40+
public int rightVisibleEdge() {
41+
return layoutManager.getWidth() - layoutManager.getPaddingRight();
42+
}
43+
44+
public int visibleAreaWidth() {
45+
return rightVisibleEdge() - leftVisibleEdge();
46+
}
47+
48+
public int topVisibleEdge() {
49+
return layoutManager.getPaddingTop();
50+
}
51+
52+
public int bottomVisibleEdge() {
53+
return layoutManager.getHeight() - layoutManager.getPaddingBottom();
54+
}
55+
5656
public Point layoutStartPoint(LayoutContext layoutContext) {
5757
switch (layoutContext.layoutOptions.alignment) {
5858
case RIGHT:
5959
return new Point(rightVisibleEdge(), topVisibleEdge());
60-
case LEFT:
61-
case CENTER:
62-
default:
63-
return new Point(leftVisibleEdge(), topVisibleEdge());
60+
case LEFT:
61+
case CENTER:
62+
default:
63+
return new Point(leftVisibleEdge(), topVisibleEdge());
6464
}
6565
}
6666
}

0 commit comments

Comments
 (0)