Blame view

src/com/ectrip/cyt/ui/BasewinScanActivity.java 4.89 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
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
  package com.ectrip.cyt.ui;
  
  import java.io.IOException;
  import java.io.UnsupportedEncodingException;
  import java.util.ArrayList;
  
  import com.basewin.aidl.OnBarcodeCallBack;
  import com.basewin.services.ScanBinder;
  import com.basewin.services.ServiceManager;
  import com.ectrip.cyt.bean.ConfigBean;
  import com.ectrip.cyt.config.BindService;
  import com.ectrip.cyt.constant.constant;
  import com.ectrip.cyt.db.DbManager;
  import com.ectrip.cyt.shield_home.LockLayer.MToast;
  import com.ectrip.cyt.utils.AESEncryptor;
  import com.ectrip.cyt.utils.DesUtil;
  import com.ectrip.trips.check.R;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.RemoteException;
  import android.text.TextUtils;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class BasewinScanActivity extends BaseActivity {
      private View topBack;
      private TextView title;
      private String titleName;
      private ScanBinder scan;
      private ReadThread mReadThread;
      private String scanString = null;
      private final BarcodeCallBac broadcast = new BarcodeCallBac();
  
      class BarcodeCallBac implements OnBarcodeCallBack {
  
          @Override
          public void onScanResult(String barcode) throws RemoteException {
              // TODO 扫码成功回调
              // scan Success callback
              if (!TextUtils.isEmpty(barcode)) {
                  scanString = barcode;
                  mReadThread = new ReadThread();
                  mReadThread.start();
              }
          }
  
          @Override
          public void onFinish() throws RemoteException {
              // TODO 扫码结束
              // scan end
          }
  
      }
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_newhandle_scaner);
  
          initView();
          init();
      }
  
      private void init() {
          titleName = getIntent().getStringExtra("titleName");
          title.setVisibility(View.VISIBLE);
          if (titleName != null) {
              title.setText(titleName);
          } else {
              title.setText(R.string.qr_code);
          }
          try {
              scan = ServiceManager.getInstence().getScan();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      private void initView() {
          scan = BindService.getInstance().getScan();
          title = (TextView) findViewById(R.id.title);
          topBack = findViewById(R.id.topBack);
          topBack.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  finish();
              }
          });
          Button btn_scan = (Button) findViewById(R.id.scanerBtn);
          btn_scan.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  //开始扫描
                  try {
                      scan.startScanZbar(60, broadcast);
                  } catch (RemoteException e) {
                      e.printStackTrace();
                  }
              }
          });
  
  
      }
  
      private class ReadThread extends Thread {
  
          @Override
          public void run() {
              super.run();
              try {
                  handleDecode(new String(scanString.getBytes("GBK"), "GBK"));
              } catch (UnsupportedEncodingException e) {
                  e.printStackTrace();
              }
          }
      }
  
      /**
       * 处理扫描结果
       *
       * @param result
       */
      public void handleDecode(String result) {
          if (result.equals("")) {
              MToast(BasewinScanActivity.this, getString(R.string.scan_fail),
                      MToast.LENGTH_SHORT);
          } else {
              try {
                  result = result.substring(result.indexOf("_") + 1,
                          result.indexOf(","));
                  ArrayList<ConfigBean> beans = DbManager.GetConfigs();
                  // 畅游通生成的订单ID:
                  String ec_name = beans.get(0).getEc_signkey();
                  ec_name = AESEncryptor.decrypt(constant.decrypt, ec_name);
                  result = DesUtil.decrypt(result, ec_name);
              } catch (Exception e) {
                  e.printStackTrace();
                  MToast(BasewinScanActivity.this,
                          getString(R.string.order_id_incorrect),
                          MToast.LENGTH_SHORT);
              }
  
              Intent intent = new Intent(BasewinScanActivity.this,
                      QRCodeOrderListActivity.class);
              intent.putExtra("mode", 1);
              intent.putExtra("input_orid", result);
              if (result != null) {
                  MToast(BasewinScanActivity.this, result, Toast.LENGTH_SHORT);
              }
              intent.putExtra("titleName", getString(R.string.show_result));
              startActivity(intent);
              finish();
          }
          finish();
      }
  
  
  }