/
LineFlowActivity.java
139 lines (131 loc) · 4.05 KB
/
LineFlowActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package com.single.flowlayout;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.library.flowlayout.FlowAdapter;
import com.library.flowlayout.LineFlowLayout;
import java.util.Arrays;
import java.util.Random;
/**
* Created by xiangcheng on 17/6/3.
*/
public class LineFlowActivity extends AppCompatActivity {
private static final String arrays[] = new String[]{"1.C",
"2.Java",
"3.Objective-C",
"4.C++",
"5.PHP",
"6.C#",
"7.(Visual) Basic",
"8.Python",
"9.Perl",
"10.JavaScript",
"11.Ruby",
"12.Visual Basic .NET",
"13.Transact-SQL",
"14.Lisp",
"15.Pascal",
"16.Bash",
"17.PL/SQL",
"18.Delphi/Object Pascal",
"19.Ada",
"20.MATLAB", "1.C",
"2.Java",
"3.Objective-C",
"4.C++",
"5.PHP",
"6.C#",
"7.(Visual) Basic",
"8.Python",
"9.Perl",
"10.JavaScript",
"11.Ruby",
"12.Visual Basic .NET",
"13.Transact-SQL",
"14.Lisp",
"15.Pascal",
"16.Bash",
"17.PL/SQL",
"18.Delphi/Object Pascal",
"19.Ada",
"20.MATLAB",
"1.C",
"2.Java",
"3.Objective-C",
"4.C++",
"5.PHP",
"6.C#",
"7.(Visual) Basic",
"8.Python",
"9.Perl",
"10.JavaScript",
"11.Ruby",
"12.Visual Basic .NET",
"13.Transact-SQL",
"14.Lisp",
"15.Pascal",
"16.Bash",
"17.PL/SQL",
"18.Delphi/Object Pascal",
"19.Ada",
"20.MATLAB", "20.MATLAB", "1.C",
"2.Java",
"3.Objective-C",
"4.C++",
"5.PHP",
"6.C#",
"7.(Visual) Basic",
"8.Python",
"9.Perl",
"10.JavaScript",
"11.Ruby",
"12.Visual Basic .NET",
"13.Transact-SQL",
"14.Lisp",
"15.Pascal",
"16.Bash",
"17.PL/SQL",
"18.Delphi/Object Pascal",
"19.Ada",
"20.MATLAB"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_line_flow);
LineFlowLayout re = (LineFlowLayout) findViewById(R.id.flow);
re.setAdapter(new FlowAdapter<String>(this, Arrays.asList(arrays)) {
@Override
protected int generateLayout(int position) {
if (position % 3 == 0) {
return R.layout.flow_item_heigher;
} else {
return R.layout.flow_item;
}
}
@Override
protected void getView(final String o, View parent) {
TextView text = (TextView) parent.findViewById(R.id.flow_text);
text.setText(o);
text.setBackgroundDrawable(getBack());
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(LineFlowActivity.this, o, Toast.LENGTH_SHORT).show();
}
});
}
private Drawable getBack() {
GradientDrawable drawable = new GradientDrawable();
drawable.setCornerRadius(8);
drawable.setColor(Color.rgb(new Random().nextInt(255), new Random().nextInt(255), new Random().nextInt(255)));
return drawable;
}
});
}
}