ManagerTaskActivity.java
8.24 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package com.huaheng.robot.task;
import android.app.AlertDialog;
import android.content.Context;
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.Constant;
import com.huaheng.robot.util.WMSLog;
import com.huaheng.robot.util.WMSUtils;
import java.util.List;
import butterknife.ButterKnife;
import rx.Subscriber;
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 int mRow = 0;
private Context mContext;
@Override
protected void initActivityOnCreate(Bundle savedInstanceState) {
super.initActivityOnCreate(savedInstanceState);
setContentView(R.layout.activity_manager_task);
ButterKnife.bind(this);
mContext = this;
setTitle(getString(R.string.manager_task));
getAllUncompleteTask();
}
private 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);
if(mRow != 0) {
tableLayout.removeViews(1, mRow);
}
int size = mTaskList.size();
mRow = 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, getTaskTypeView(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, getTaskStatusView(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));
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) {
WMSUtils.showShort(mContext.getString(R.string.success_cancel_task));
reStart();
}
@Override
public void onError(String str) {
}
};
private void getAllUncompleteTask() {
HttpInterface2.getInsstance().getAllUncompleteTask(new Subscriber<List<TaskBean>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
myHandler.removeMessages(0);
myHandler.sendEmptyMessageDelayed(0, 10 * 1000);
}
@Override
public void onNext(List<TaskBean> taskBeans) {
if(taskBeans == null || taskBeans.size() == 0) {
}
mTaskList = taskBeans;
createTable();
myHandler.removeMessages(0);
myHandler.sendEmptyMessageDelayed(0, 10 * 1000);
}
}, 1);
}
private void reStart() {
getAllUncompleteTask();
}
private class MyHandler extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
reStart();
}
}
@Override
protected void onPause() {
super.onPause();
myHandler.removeMessages(0);
}
@Override
protected void onResume() {
super.onResume();
myHandler.removeMessages(0);
myHandler.sendEmptyMessageDelayed(0, 10 * 1000);
}
private String getTaskTypeView(int taskType) {
switch (taskType) {
case Constant.TASK_TYPE_CHARGE:
return mContext.getString(R.string.task_type_charge);
case Constant.TASK_TYPE_MOVE:
return mContext.getString(R.string.task_type_move);
case Constant.TASK_TYPE_GET_PUT:
return mContext.getString(R.string.task_type_get_put);
}
return null;
}
private String getTaskStatusView(int taskStatus) {
switch (taskStatus) {
case Constant.TASK_STATUS_CREATE:
return mContext.getString(R.string.task_status_create);
case Constant.TASK_STATUS_EXECUTE:
return mContext.getString(R.string.task_status_excute);
case Constant.TASK_STATUS_GET:
return mContext.getString(R.string.task_status_get);
case Constant.TASK_STATUS_GET_COMPLETE:
return mContext.getString(R.string.task_status_get_complete);
case Constant.TASK_STATUS_PUT:
return mContext.getString(R.string.task_status_put);
case Constant.TASK_STATUS_PUT_COMPLETE:
return mContext.getString(R.string.task_status_put_complete);
case Constant.TASK_STATUS_COMPLETE:
return mContext.getString(R.string.task_status_complete);
}
return null;
}
}