TaskShipItemView.java
2.62 KB
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
package com.huaheng.mobilewms.view;
import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.LinearLayout;
import com.huaheng.mobilewms.util.WMSUtils;
import java.util.ArrayList;
import java.util.List;
public class TaskShipItemView extends LinearLayout {
private int index = 0;
private boolean itemSelected = false;
private int colorNormal;
private int colorSelected1 = Color.rgb(163+10,214+10,231+10);
private int colorSelected2 = Color.rgb(163+10,214+10,231+10);
private int colorLine = Color.rgb(0, 0, 0);
public TaskShipItemView(Context context, int index){
super(context);
this.setOrientation(VERTICAL);
this.index = index;
if(index %2 == 0) {
colorNormal = Color.rgb(255,255,255);
}else{
colorNormal = Color.rgb(255,255,255);
}
this.setBackgroundColor(colorNormal);
LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
// lp.setMargins(0, 10, 0, 10);
// this.setPadding(0, 10, 0, 10);
this.setLayoutParams(lp);
View line = new View(context);
LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 12);
line.setLayoutParams(llp);
line.setBackgroundColor(colorLine);
this.addView(line);
this.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
selectSwitch();
}
});
}
public void newLine(String label, String info){
if(WMSUtils.isEmpty(info)){
return;
}
TaskShipItem item = new TaskShipItem(this.getContext(), label, info);
item.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
this.addView(item);
}
@Override
public void addView(View view){
view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
super.addView(view);
}
public void selectSwitch(){
select(!this.itemSelected);
}
public void select(boolean isSelect){
this.itemSelected = isSelect;
if(itemSelected){
if(index % 2 == 0) {
this.setBackgroundColor(this.colorSelected1);
}else{
this.setBackgroundColor(this.colorSelected2);
}
}else{
this.setBackgroundColor(this.colorNormal);
}
}
public boolean isItemSelected(){
return this.itemSelected;
}
}