BulkCollectActivity.java
9.29 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package com.huaheng.wms.collectgoods;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.huaheng.wms.R;
import com.huaheng.wms.WMSLog;
import com.huaheng.wms.model.CommonActivity;
import com.huaheng.wms.util.SoundUtils;
import com.huaheng.wms.util.WMSUtils;
import com.huaheng.wms.views.LineLayout;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/*
** 批量收货
*/
public class BulkCollectActivity extends CommonActivity {
@BindView(R.id.snEdit)
EditText snEdit;
@BindView(R.id.scanLayout)
LinearLayout scanLayout;
@BindView(R.id.inputEdit)
EditText inputEdit;
@BindView(R.id.inputLayout)
FrameLayout inputLayout;
@BindView(R.id.wnLayout)
LineLayout wnLayout;
@BindView(R.id.cnLayout)
LineLayout cnLayout;
@BindView(R.id.barcodeLayout)
LineLayout barcodeLayout;
@BindView(R.id.commondityLayout)
LineLayout commondityLayout;
@BindView(R.id.unitLayout)
LineLayout unitLayout;
@BindView(R.id.inventoryLayout)
LineLayout inventoryLayout;
@BindView(R.id.alreadyView)
TextView alreadyView;
@BindView(R.id.tobeView)
TextView tobeView;
@BindView(R.id.ensureBtn)
Button ensureBtn;
@BindView(R.id.contentLayout)
LinearLayout contentLayout;
@BindView(R.id.ensureLayout)
LinearLayout ensureLayout;
private String wn;
private String tobeNumber = "100";
private String barcode;
private String cn;
private boolean isSubmit = false;
private boolean isEnterCN = false;
private AlertDialog mDialog;
@Override
protected void initActivityOnCreate(Bundle savedInstanceState) {
super.initActivityOnCreate(savedInstanceState);
setContentView(R.layout.activity_bulk_collect);
ButterKnife.bind(this);
setTitle(getString(R.string.bulk_collection));
initView();
enableButton(false);
}
private void initView() {
snEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
String number = editable.toString();
if(!isEnterCN) {
if (number != null && number.length() > 0) {
wn = number;
enableButton(true);
} else {
enableButton(false);
}
} else {
if (number != null && number.length() > 0) {
cn = number;
}
}
}
});
snEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
WMSLog.d("onEditorAction keyEvent:" + keyEvent.getKeyCode());
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if(isEnterCN) {
isSubmit = true;
showInputLayout();
}
}
return false;
}
});
inputEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
barcode = editable.toString();
if (barcode != null && barcode.length() > 0) {
getCollectInfo();
} else {
enableButton(false);
}
}
});
}
private void enableButton(boolean enable) {
if (enable) {
ensureBtn.setBackgroundResource(R.color.colorPrimary);
ensureLayout.setClickable(true);
} else {
ensureBtn.setBackgroundResource(R.color.gray_bg);
ensureLayout.setClickable(false);
}
}
private void getCollectInfo() {
String name = "MYR930S-X 立式饮水机 白色 S2平台网销机";
String unit = "个";
String status = "良品";
String already_received = "0";
contentLayout.setVisibility(View.VISIBLE);
wnLayout.setLineName(this.getString(R.string.warehouse_number));
wnLayout.setLineContent(wn);
cnLayout.setLineName(this.getString(R.string.container_number));
cnLayout.setLineContent(cn);
barcodeLayout.setLineName(this.getString(R.string.barcode));
barcodeLayout.setLineContent(barcode);
commondityLayout.setLineName(this.getString(R.string.commodity_name));
commondityLayout.setLineContent(name);
unitLayout.setLineName(this.getString(R.string.unit));
unitLayout.setLineContent(unit);
inventoryLayout.setLineName(this.getString(R.string.inventory_state));
inventoryLayout.setLineContent(status);
alreadyView.setText(already_received);
tobeView.setText(tobeNumber);
}
private void showInputLayout() {
WMSLog.d("showInputLayout");
scanLayout.setVisibility(View.GONE);
inputLayout.setVisibility(View.VISIBLE);
inputEdit.requestFocus();
}
@OnClick({R.id.inputBtn, R.id.ensureLayout})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.inputBtn:
showInputDialog();
break;
case R.id.ensureLayout:
WMSLog.d("isSubmit:" + isSubmit);
if (isSubmit) {
submit();
} else {
isEnterCN = true;
snEdit.requestFocus();
snEdit.setText("");
snEdit.setHint(R.string.enter_container_number);
enableButton(false);
}
break;
}
}
private void showInputDialog() {
final EditText et = new EditText(this);
et.setInputType(InputType.TYPE_CLASS_NUMBER);
AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.input_quantity_goods))
.setView(et)
.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//按下确定键后的事件
String already = et.getText().toString();
int number = Integer.parseInt(already);
if (number > 0) {
enableButton(true);
}
int tobe = Integer.parseInt(tobeNumber) - Integer.parseInt(already);
alreadyView.setText(already);
tobeView.setText(String.valueOf(tobe));
inputEdit.requestFocus();
}
}).setNegativeButton(this.getString(R.string.cancel), null);
mDialog = builder.create();
mDialog.show();
// et.addTextChangedListener(new TextWatcher() {
// @Override
// public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//
// }
//
// @Override
// public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
//
// }
//
// @Override
// public void afterTextChanged(Editable editable) {
// String text = editable.toString();
// WMSLog.d("EditText text:" + text);
// }
// });
et.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
String already = textView.getText().toString();
int number = Integer.parseInt(already);
if (number > 0) {
enableButton(true);
}
int tobe = Integer.parseInt(tobeNumber) - Integer.parseInt(already);
alreadyView.setText(already);
tobeView.setText(String.valueOf(tobe));
mDialog.dismiss();
}
return false;
}
});
}
private void submit() {
SoundUtils.getInstance(this).dingSound();
finish();
WMSUtils.startActivity(this, BulkCollectActivity.class);
}
}