ManagerTaskActivity.java
6.64 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package com.huaheng.robot.task;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import com.huaheng.robot.MainActivity;
import com.huaheng.robot.R;
import com.huaheng.robot.bean.RGVBean;
import com.huaheng.robot.bean.TaskBean;
import com.huaheng.robot.https.HttpInterface2;
import com.huaheng.robot.https.Subscribers.ProgressSubscriber;
import com.huaheng.robot.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.robot.util.CommonActivity;
import com.huaheng.robot.util.WMSLog;
import com.huaheng.robot.util.WMSUtils;
import java.util.List;
import butterknife.ButterKnife;
public class ManagerTaskActivity extends CommonActivity {
private final int WC= ViewGroup.LayoutParams.WRAP_CONTENT;
private final int FP= ViewGroup.LayoutParams.WRAP_CONTENT;
private List<TaskBean> mTaskList;
private MyHandler myHandler = new MyHandler();
private static boolean startHandler = false;
@Override
protected void initActivityOnCreate(Bundle savedInstanceState) {
super.initActivityOnCreate(savedInstanceState);
setContentView(R.layout.activity_manager_task);
ButterKnife.bind(this);
setTitle(getString(R.string.manager_task));
getAllUncompleteTask();
}
public void createTable() {
TableLayout tableLayout = (TableLayout) findViewById(R.id.id_tableLayout);
tableLayout.setStretchAllColumns(true); //设置指定列号的列属性为Stretchable
if(mTaskList == null || mTaskList.size() ==0) {
tableLayout.setVisibility(View.GONE);
return;
}
tableLayout.setVisibility(View.VISIBLE);
int size = mTaskList.size();
for (int row = 0; row < size; row++) { //产生的行数
TableRow tableRow = new TableRow(ManagerTaskActivity.this);
tableRow.setBackgroundColor(Color.rgb(222, 220, 210)); //设置表格背景
final TaskBean taskBean = mTaskList.get(row);
int id = taskBean.getId();
addNTextView(tableRow, String.valueOf(id));
int taskType = taskBean.getTaskType();
addNTextView(tableRow, String.valueOf(taskType));
int fromLocationId = taskBean.getFromLocationId();
addNTextView(tableRow, String.valueOf(fromLocationId));
int toLocationId = taskBean.getToLocationId();
addNTextView(tableRow, String.valueOf(toLocationId));
int status = taskBean.getStatus();
addNTextView(tableRow, String.valueOf(status));
RGVBean rgvBean = taskBean.getRgv();
if(rgvBean != null ) {
String agvName = rgvBean.getName();
addNTextView(tableRow, agvName);
} else {
addNTextView(tableRow, "");
}
String createdBy = taskBean.getCreatedBy();
addNTextView(tableRow, createdBy);
tableLayout.addView(tableRow, new LinearLayout.LayoutParams(FP, WC));
final int finalRow = row;
tableRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showCancelTaskDialog(String.valueOf(taskBean.getId()));
}
});
}
}
private void addNTextView(TableRow tableRow, String view) {
TextView tv = new TextView(ManagerTaskActivity.this);
tv.setBackgroundResource(R.drawable.shape); //设置背景
tv.setGravity(Gravity.CENTER);
tv.setText(view);
tableRow.addView(tv);
}
private void showCancelTaskDialog(final String id){
String str = getResources().getString(R.string.cancel_task_message);
String message = String.format(str, id);
final AlertDialog.Builder normalDialog =
new AlertDialog.Builder(ManagerTaskActivity.this);
normalDialog.setTitle(R.string.cancel_task);
normalDialog.setMessage(message);
normalDialog.setPositiveButton(R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cancelTask(id);
}
});
normalDialog.setNegativeButton(R.string.cancel,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
normalDialog.show();
}
private void cancelTask(String id) {
HttpInterface2.getInsstance().cancelTask(new ProgressSubscriber<String>(this, cancelTaskListener), Integer.parseInt(id));
}
SubscriberOnNextListener cancelTaskListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String str) {
reStart();
}
@Override
public void onError(String str) {
}
};
private void getAllUncompleteTask() {
HttpInterface2.getInsstance().getAllUncompleteTask(new ProgressSubscriber<List<TaskBean>>(this, uncompleteTaskListener), 1);
}
SubscriberOnNextListener uncompleteTaskListener = new SubscriberOnNextListener<List<TaskBean>>() {
@Override
public void onNext(List<TaskBean> taskBeans) {
WMSLog.d("getAllUncompleteTask taskBeans:" + taskBeans);
if(taskBeans == null || taskBeans.size() == 0) {
WMSUtils.showShort(ManagerTaskActivity.this.getString(R.string.no_task_rgv));
}
mTaskList = taskBeans;
createTable();
WMSLog.d("startHandler:" + startHandler);
if(!startHandler) {
myHandler.sendEmptyMessageDelayed(0, 10 * 1000);
startHandler = true;
}
}
@Override
public void onError(String str) {
if(!startHandler) {
myHandler.sendEmptyMessageDelayed(0, 10 * 1000);
startHandler = true;
}
}
};
private void reStart() {
getAllUncompleteTask();
}
private class MyHandler extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
startHandler = false;
reStart();
}
}
}