ScanBarcodeActivity.java
2.65 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
package com.lijinji.scan;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import com.lijinji.scan.bean.ProductBean;
import com.lijinji.scan.https.HttpInterface;
import com.lijinji.scan.https.Subscribers.ProgressSubscriber;
import com.lijinji.scan.https.Subscribers.SubscriberOnNextListener;
import com.lijinji.scan.product.ProductManagerActivity;
import com.lijinji.scan.util.CommonActivity;
import com.lijinji.scan.util.Constant;
import com.lijinji.scan.util.WMSUtils;
import com.zbar.scan.ScanCaptureAct;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class ScanBarcodeActivity extends CommonActivity {
@BindView(R.id.scanView)
TextView scanView;
@BindView(R.id.scanBtn)
Button scanBtn;
private Context mContext;
private int RESULT_CODE = 1;
private String result;
@Override
protected void initActivityOnCreate(Bundle savedInstanceState) {
super.initActivityOnCreate(savedInstanceState);
setContentView(R.layout.activity_scan_barcode);
ButterKnife.bind(this);
mContext = this;
setTitle(this.getString(R.string.scan_history));
}
@OnClick(R.id.scanBtn)
public void onViewClicked() {
startScanActivity();
}
private void startScanActivity() {
Intent intent = new Intent();
intent.setClass(mContext, ScanCaptureAct.class);
this.startActivityForResult(intent, RESULT_CODE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(data != null) {
result = data.getExtras().containsKey("SCAN_RESULT") ? data.getExtras().getString("SCAN_RESULT") : null;
if (result != null) {
scanBarcodeData(result);
}
}
}
private void scanBarcodeData(String code) {
String userCode = WMSUtils.getData(Constant.LOGIN_NAME);
HttpInterface.getInsstance().scanBarcodeData(new ProgressSubscriber<String>
(mContext, dataListener), userCode, code,"123");
}
SubscriberOnNextListener dataListener = new SubscriberOnNextListener<String>() {
@Override
public void onNext(String str) {
scanView.setTextColor(getResources().getColor(R.color.black));
scanView.setText(mContext.getString(R.string.scan_success) + result);
}
@Override
public void onError(String str) {
scanView.setTextColor(getResources().getColor(R.color.red));
scanView.setText(mContext.getString(R.string.scan_error) + result);
}
};
}