TaskShipItemView.java
3.07 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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.R;
import com.huaheng.mobilewms.bean.TaskDetail;
import com.huaheng.mobilewms.util.WMSUtils;
public class TaskShipItemView extends LinearLayout {
private int index = 0;
private boolean itemSelected = false;
private int colorNormal = Color.rgb(255,255,255);
private int colorDone = Color.rgb(245, 245, 245);
private int colorSelected = Color.rgb(163-10,214-10,231-10);
private TaskDetail taskDetal;
public TaskShipItemView(Context context, int index, TaskDetail taskDetal){
super(context);
this.setOrientation(VERTICAL);
this.index = index;
this.taskDetal = taskDetal;
this.setBackgroundColor(colorNormal);
LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
this.setLayoutParams(lp);
this.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
selectSwitch();
}
});
if(isDone()){
this.setBackgroundColor(colorDone);
}
initView();
}
public void initView(){
newLine(getContext().getString(R.string.commodity_name), String.valueOf(taskDetal.getMaterialName()));
String qty = WMSUtils.cleanFloatZero(String.valueOf(taskDetal.getQty()));
String taskQty = WMSUtils.cleanFloatZero(String.valueOf(taskDetal.getTaskQty()));
newLine(getContext().getString(R.string.commodity_number), taskQty + " / " + qty);
addView(WMSUtils.newDevider(getContext()));
}
public void newLine(String label, String info){
if(WMSUtils.isEmpty(info)){
return;
}
TaskShipItem item = new TaskShipItem(this.getContext(), label, info);
if(this.isDone()){
//设置已经完成的样式:灰色字体
item.setDone();
}
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){
if(this.isDone()){
return;
}
this.itemSelected = isSelect;
if(itemSelected){
this.setBackgroundColor(this.colorSelected);
}else{
this.setBackgroundColor(this.colorNormal);
}
}
public boolean isItemSelected(){
return this.itemSelected;
}
/**
* qty <= taskQty 表示Done
* @return
*/
public boolean isDone(){
return taskDetal.getQty().compareTo(taskDetal.getTaskQty()) <= 0;
}
public TaskDetail getTaskDetal() {
return taskDetal;
}
}