OkGo.get(Const.Xingqu)
.tag(this)
.execute(new BeanCallbackNoPop() {
private List list0;
private List list1;
private List list2;
private List list3;
private List list4;
private List list5;
private List list6;
@Override
public XingQuBean convertResponse(Response response) throws Throwable {
String string = response.body().string();
JSONObject jsonObject = new JSONObject(string);
int code = jsonObject.getInt("code");
System.out.println(string);
if (code == 200) {
return new Gson().fromJson(string, XingQuBean.class);
}
return super.convertResponse(response);
}
@Override
public void onSuccess(com.lzy.okgo.model.Response response) {
super.onSuccess(response);
XingQuBean body = response.body();
if (body != null) {
List data = body.getData();
List colorLists = new ArrayList<>();
for (int i = 0; i < 14; i++) {
if (i == 1) {
colorLists.add(new String[]{"#F3C736", "#E98C2B"});
} else if (i == 2) {
colorLists.add(new String[]{"#7C58F6", "#9122EF"});
} else if (i == 5) {
colorLists.add(new String[]{"#EE963A", "#E9564D"});
} else if (i == 6) {
colorLists.add(new String[]{"#775BEF", "#8E24F4"});
} else if (i == 9) {
colorLists.add(new String[]{"#5CE4A3", "#55CCD9"});
} else if (i == 10) {
colorLists.add(new String[]{"#5B99F7", "#586FFB"});
} else {
colorLists.add(R.color.white);
}
}
colorLists.addAll(colorLists);
List> listAlls = new ArrayList<>();
// 规律 个数 123 2 321
for (int i = 0; i < data.size(); i++) {
int a = i % 14;
switch (a) {
case 0:
list0 = new ArrayList<>(); // 0
list0.add(data.get(i));
listAlls.add(list0);
break;
case 1:
list1 = new ArrayList<>(); // 1
list1.add(data.get(i));
break;
case 2:
list1.add(data.get(i));
listAlls.add(list1);
break;
case 3:
list2 = new ArrayList<>(); // 2
list2.add(data.get(i));
break;
case 4:
list2.add(data.get(i));
break;
case 5:
list2.add(data.get(i));
listAlls.add(list2);
break;
case 6:
list3 = new ArrayList<>(); // 3
list3.add(data.get(i));
break;
case 7:
list3.add(data.get(i));
listAlls.add(list3);
break;
case 8:
list4 = new ArrayList<>(); //4
list4.add(data.get(i));
break;
case 9:
list4.add(data.get(i));
break;
case 10:
list4.add(data.get(i));
listAlls.add(list4);
break;
case 11:
list5 = new ArrayList<>();
list5.add(data.get(i));
break;
case 12:
list5.add(data.get(i));
listAlls.add(list5);
break;
case 13:
list6 = new ArrayList<>();
list6.add(data.get(i));
listAlls.add(list6);
break;
default:
break;
}
}
int llWidth = ScreenUtils.getScreenWidth() * 2 / 9;
int colorIndex = 0;
for (int i = 0; i < listAlls.size(); i++) {
List dataBeans = listAlls.get(i);
LinearLayout linearLayout = new LinearLayout(mContext);
linearLayout.setGravity(Gravity.CENTER);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
for (int j = 0; j < dataBeans.size(); j++) {
XingQuBean.DataBean dataBean = dataBeans.get(j);
TextView textView = new TextView(mContext);
textView.setText(dataBean.getType_name());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(llWidth, LinearLayout.LayoutParams.WRAP_CONTENT);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
textView.setTextColor(getResources().getColor(R.color.black_8a));
layoutParams.leftMargin = 30;
layoutParams.rightMargin = 30;
layoutParams.topMargin = 20;
layoutParams.bottomMargin = 20;
textView.setPadding(20, 10, 20, 10);
Object o = colorLists.get(colorIndex);
if (o instanceof Integer) {
DevShapeUtils.shape(DevShape.RECTANGLE)
.line(1, R.color.black_8a)
.solid((Integer) o)
.radius(16)
.into(textView);
} else {
String[] o1 = (String[]) o;
DevShapeUtils.shape(DevShape.RECTANGLE)
.line(1, R.color.black_8a)
.gradientLinear(o1[0], o1[1])
.orientation(DevShape.LEFT_RIGHT)
.radius(16)
.into(textView);
}
colorIndex++;
linearLayout.addView(textView);
}
mViewBinding.llcenter.addView(linearLayout);
}
}
}
});
评论列表(0条)