IsLandActivity.java
8.66 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
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 com.huaheng.robot.R;
import com.huaheng.robot.bean.ActivityIslandBean;
import com.huaheng.robot.bean.EquipmentBean;
import com.huaheng.robot.bean.EquipmentPropsBean;
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.DataBaseHelpter;
import com.huaheng.robot.util.WMSLog;
import com.huaheng.robot.util.WMSUtils;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import rx.Subscriber;
public class IsLandActivity extends CommonActivity {
@BindView(R.id.car_tableLayout)
TableLayout carTableLayout;
private Context mContext;
// private MyHandler myHandler = new MyHandler();
private int mRow = 0;
private List<ActivityIslandBean> mActivityIslandBeans;
private final int WC= ViewGroup.LayoutParams.WRAP_CONTENT;
private final int FP= ViewGroup.LayoutParams.WRAP_CONTENT;
@Override
protected void initActivityOnCreate(Bundle savedInstanceState) {
super.initActivityOnCreate(savedInstanceState);
setContentView(R.layout.activity_island);
ButterKnife.bind(this);
mContext = this;
setTitle(getString(R.string.island_info));
}
@Override
protected void onPause() {
super.onPause();
// myHandler.removeMessages(0);
}
@Override
protected void onResume() {
super.onResume();
getAllActivityIsland();
// myHandler.removeMessages(0);
// myHandler.sendEmptyMessageDelayed(0, 1 * 1000);
}
private void getAllActivityIsland() {
HttpInterface2.getInsstance().getAllActivityIsland(new Subscriber<List<ActivityIslandBean>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
// myHandler.removeMessages(0);
// myHandler.sendEmptyMessageDelayed(0, 1 * 1000);
}
@Override
public void onNext(List<ActivityIslandBean> activityIslandBeans) {
if(activityIslandBeans != null) {
mActivityIslandBeans = activityIslandBeans;
}
createTable();
// myHandler.removeMessages(0);
// myHandler.sendEmptyMessageDelayed(0, 1 * 1000);
}
});
};
private void createTable() {
TableLayout tableLayout = (TableLayout) findViewById(R.id.car_tableLayout);
tableLayout.setStretchAllColumns(true); //设置指定列号的列属性为Stretchable
if (mActivityIslandBeans == null || mActivityIslandBeans.size() == 0) {
tableLayout.setVisibility(View.GONE);
return;
}
if(mRow != 0) {
tableLayout.removeViews(1, mRow);
}
tableLayout.setVisibility(View.VISIBLE);
int size = mActivityIslandBeans.size();
mRow = size;
for (int row = 0; row < size; row++) { //产生的行数
TableRow tableRow = new TableRow(mContext);
tableRow.setBackgroundColor(Color.rgb(222, 220, 210)); //设置表格背景
final ActivityIslandBean activityIslandBean = mActivityIslandBeans.get(row);
String code = activityIslandBean.getCode();
String name = activityIslandBean.getName();
String line = WMSUtils.getData(Constant.CURREN_LINE_NAME);
String detailCode = activityIslandBean.getWorkProcessDetail().getName();
int direction = activityIslandBean.getDirection();
int status = activityIslandBean.getStatus();
int signalStatus = activityIslandBean.getSignalStatus();
addNTextView(tableRow, code);
addNTextView(tableRow, name);
addNTextView(tableRow, line);
addNTextView(tableRow, detailCode);
addNTextView(tableRow, getDirection(direction));
addNTextView(tableRow, getStatus(status));
addNTextView(tableRow, getSignalstatus(signalStatus));
tableLayout.addView(tableRow, new LinearLayout.LayoutParams(FP, WC));
tableRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showChooseDialog(activityIslandBean.getId());
}
});
}
}
private void showChooseDialog(final int id){
List<String> lists = new ArrayList<>();
lists.add(mContext.getString(R.string.cancel_emplace));
lists.add(mContext.getString(R.string.cancel_request));
final AlertDialog.Builder normalDialog =
new AlertDialog.Builder(mContext);
normalDialog.setTitle(R.string.choose_task);
String[] strs1= lists.toArray(new String[lists.size()]);
normalDialog.setItems(strs1, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case 0:
cancelActivityIslandOccupy(id);
break;
case 1:
cancelActivityIslandRequest(id);
break;
}
}
});
normalDialog.show();
}
private void cancelActivityIslandOccupy(int id) {
HttpInterface2.getInsstance().cancelActivityIslandOccupy(new ProgressSubscriber<String>(this, cancelOccupyListener), id);
}
SubscriberOnNextListener cancelOccupyListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String result) {
WMSUtils.showShort(mContext.getString(R.string.success_cancel_emplace));
getAllActivityIsland();
}
@Override
public void onError(String str) {
getAllActivityIsland();
WMSLog.d("onError:" + str);
}
};
private void cancelActivityIslandRequest(int id) {
HttpInterface2.getInsstance().cancelActivityIslandRequest(new ProgressSubscriber<String>(this, cancelRequestListener), id);
}
SubscriberOnNextListener cancelRequestListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String result) {
WMSUtils.showShort(mContext.getString(R.string.success_cancel_request));
getAllActivityIsland();
}
@Override
public void onError(String str) {
getAllActivityIsland();
WMSLog.d("onError:" + str);
}
};
private String getDirection(int direction) {
switch (direction) {
case 1:
return mContext.getString(R.string.left);
case 2:
return mContext.getString(R.string.right);
}
return mContext.getString(R.string.left);
}
private String getSignalstatus(int signalStatus) {
switch (signalStatus) {
case 0:
return mContext.getString(R.string.signal_status_none);
case 1:
return mContext.getString(R.string.signal_status_request);
case 2:
return mContext.getString(R.string.signal_status_emplace);
}
return mContext.getString(R.string.left);
}
private String getStatus(int status) {
switch (status) {
case 0:
return mContext.getString(R.string.status_free);
case 1:
return mContext.getString(R.string.status_lock);
}
return mContext.getString(R.string.status_free);
}
private void addNTextView(TableRow tableRow, String view) {
TextView tv = new TextView(mContext);
tv.setBackgroundResource(R.drawable.shape); //设置背景
tv.setGravity(Gravity.CENTER);
tv.setText(view);
tableRow.addView(tv);
}
// private class MyHandler extends Handler {
// @Override
// public void handleMessage(Message msg) {
// super.handleMessage(msg);
// getAllActivityIsland();
// }
// }
}