Blame view

src/com/ectrip/cyt/ui/PhomeScanerOrderActivity.java 12.9 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
1
  package com.ectrip.cyt.ui;
df682192   杜方   畅游通核销app: 1.优化扫CY...
2
  
3c2353cd   杜方   1、畅游通核销app源码提交;
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Vector;
  
  import android.content.Intent;
  import android.content.res.AssetFileDescriptor;
  import android.media.AudioManager;
  import android.media.MediaPlayer;
  import android.media.MediaPlayer.OnCompletionListener;
  import android.os.Bundle;
  import android.os.Handler;
  import android.os.Vibrator;
  import android.view.SurfaceHolder;
  import android.view.SurfaceHolder.Callback;
  import android.view.SurfaceView;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.Window;
  import android.view.WindowManager;
  import android.widget.TextView;
5aabe1c0   黄灿宏   畅游通核销app: 1.增加扫码配置
23
  import android.widget.Toast;
3c2353cd   杜方   1、畅游通核销app源码提交;
24
25
  
  import com.ectrip.cyt.bean.ConfigBean;
5aabe1c0   黄灿宏   畅游通核销app: 1.增加扫码配置
26
  import com.ectrip.cyt.config.DevicTool;
3c2353cd   杜方   1、畅游通核销app源码提交;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  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.Base64;
  import com.ectrip.cyt.utils.DesUtil;
  import com.ectrip.cyt.utils.LogUtil;
  import com.ectrip.cyt.utils.SharedPreferences2Obj;
  import com.ectrip.cyt.zxing.camera.CameraManager;
  import com.ectrip.cyt.zxing.decoding.CaptureActivityHandler;
  import com.ectrip.cyt.zxing.decoding.InactivityTimer;
  import com.ectrip.cyt.zxing.view.ViewfinderView;
  import com.ectrip.trips.check.R;
  import com.google.zxing.BarcodeFormat;
  import com.google.zxing.Result;
  
  /**
   * 手机版扫描二维码
   */
  public class PhomeScanerOrderActivity extends BaseActivity implements Callback {
df682192   杜方   畅游通核销app: 1.优化扫CY...
47
      public final String TAG = "PhomeScanerOrderActivity";
3c2353cd   杜方   1、畅游通核销app源码提交;
48
49
50
51
52
53
54
55
56
57
58
      private CaptureActivityHandler handler;
      private ViewfinderView viewfinderView;
      private boolean hasSurface;
      private Vector<BarcodeFormat> decodeFormats;
      private String characterSet;
      private InactivityTimer inactivityTimer;
      private MediaPlayer mediaPlayer;
      private boolean playBeep;
      private final float BEEP_VOLUME = 0.10f;
      private boolean vibrate;
      private String titleName;
df682192   杜方   畅游通核销app: 1.优化扫CY...
59
      private int typeScan;
3c2353cd   杜方   1、畅游通核销app源码提交;
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
  
      /**
       * Called when the activity is first created.
       */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          // 使屏幕不显示标题栏(必须要在setContentView方法执行前执行)
          this.requestWindowFeature(Window.FEATURE_NO_TITLE);
          // 隐藏状态栏,使内容全屏显示(必须要在setContentView方法执行前执行)
          this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                  WindowManager.LayoutParams.FLAG_FULLSCREEN);
          setContentView(R.layout.activity_capture2);
          // ViewUtil.addTopView(getApplicationContext(), this,
          // R.string.scan_card);
          CameraManager.init(getApplication());
          viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
  
          titleName = getIntent().getStringExtra("titleName");
          if (titleName != null) {
              ((TextView) findViewById(R.id.title)).setText(titleName);
          } else {
              ((TextView) findViewById(R.id.title))
                      .setText(R.string.scan_qr_code);
          }
  
          ((TextView) findViewById(R.id.title)).setVisibility(View.VISIBLE);
  
          findViewById(R.id.topBack).setOnClickListener(new OnClickListener() {
              @Override
              public void onClick(View v) {
                  finish();
              }
          });
          hasSurface = false;
          inactivityTimer = new InactivityTimer(this);
      }
  
      @SuppressWarnings("deprecation")
      @Override
      protected void onResume() {
          super.onResume();
          SharedPreferences2Obj.getInstance(PhomeScanerOrderActivity.this)
                  .setName("SelectAction").setObject("isStatistic", "0"); // 非统计
          SurfaceView surfaceView = (SurfaceView) findViewById(R.id.preview_view);
          SurfaceHolder surfaceHolder = surfaceView.getHolder();
          if (hasSurface) {
              initCamera(surfaceHolder);
          } else {
              surfaceHolder.addCallback(this);
              surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
          }
          decodeFormats = null;
          characterSet = null;
  
          playBeep = true;
          AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
          if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
              playBeep = false;
          }
          initBeepSound();
          vibrate = true;
  
      }
  
      /**
       * 处理扫描结果
       *
       * @param result
       */
      public void handleDecode(Result result) {
          inactivityTimer.onActivity();
          playBeepSoundAndVibrate();
9e9f1eb7   杜方   1、畅游通核销app:新增主界面关...
133
          String resultString = result.getText().trim();
df682192   杜方   畅游通核销app: 1.优化扫CY...
134
          LogUtil.i(TAG, "扫码数据 = " + resultString);
5aabe1c0   黄灿宏   畅游通核销app: 1.增加扫码配置
135
136
137
138
          if (resultString.startsWith("PZ")) {
              configIdent(resultString);
              return;
          }
3c2353cd   杜方   1、畅游通核销app源码提交;
139
140
141
142
143
          if (resultString.equals("")) {
              MToast(PhomeScanerOrderActivity.this,
                      getString(R.string.scan_fail), MToast.LENGTH_SHORT);
          } else {
              try {
7d3f774c   杜方   畅游通核销app: 1.修复CYT...
144
                  if (resultString.startsWith("CYT_")) {
df682192   杜方   畅游通核销app: 1.优化扫CY...
145
146
147
148
149
150
151
152
                      typeScan = 0;
                      if (resultString.contains(",")) {
                          resultString = resultString.substring(resultString.indexOf("_") + 1, resultString.indexOf(","));
                          LogUtil.i(TAG, "resultString = " + resultString);
                      } else {
                          resultString = resultString.substring(resultString.indexOf("_") + 1, resultString.length());
                          LogUtil.i(TAG, "resultString1 = " + resultString);
                      }
3c2353cd   杜方   1、畅游通核销app源码提交;
153
154
155
                      ArrayList<ConfigBean> beans = DbManager.GetConfigs();
                      // 畅游通生成的订单ID:
                      String ec_name = beans.get(0).getEc_signkey();
df682192   杜方   畅游通核销app: 1.优化扫CY...
156
                      LogUtil.i(TAG, "ec_name = " + ec_name);
3c2353cd   杜方   1、畅游通核销app源码提交;
157
                      ec_name = AESEncryptor.decrypt(constant.decrypt, ec_name);
df682192   杜方   畅游通核销app: 1.优化扫CY...
158
                      LogUtil.i(TAG, "ec_name1 = " + ec_name);
3c2353cd   杜方   1、畅游通核销app源码提交;
159
160
                      resultString = DesUtil.decrypt(resultString, ec_name);
  
7d3f774c   杜方   畅游通核销app: 1.修复CYT...
161
                  } else if (resultString.startsWith("TDOS_")) {
df682192   杜方   畅游通核销app: 1.优化扫CY...
162
                      typeScan = 0;
9b537f44   杜方   畅游通核销app: 1.优化扫TD...
163
164
165
166
167
168
169
                      if (resultString.contains(",")) {
                          resultString = resultString.substring(resultString.indexOf("_") + 1, resultString.indexOf(","));
                          LogUtil.i(TAG, "resultString = " + resultString);
                      } else {
                          resultString = resultString.substring(resultString.indexOf("_") + 1, resultString.length());
                          LogUtil.i(TAG, "resultString1 = " + resultString);
                      }
3c2353cd   杜方   1、畅游通核销app源码提交;
170
                      resultString = new String(Base64.decode(resultString), "utf-8");
7d3f774c   杜方   畅游通核销app: 1.修复CYT...
171
                  } else if ((resultString.startsWith("TY_") || (resultString.startsWith("PMS_")))) {
df682192   杜方   畅游通核销app: 1.优化扫CY...
172
                      typeScan = 1;
2707d233   杜方   1、畅游通核销app;修改扫二维码...
173
                      resultString = resultString;
7d3f774c   杜方   畅游通核销app: 1.修复CYT...
174
                  } else {
df682192   杜方   畅游通核销app: 1.优化扫CY...
175
                      typeScan = 1;
2707d233   杜方   1、畅游通核销app;修改扫二维码...
176
                      resultString = resultString;
3c2353cd   杜方   1、畅游通核销app源码提交;
177
178
179
180
181
182
183
184
185
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }
  
              Intent intent = new Intent(PhomeScanerOrderActivity.this,
                      QRCodeOrderListActivity.class);
              intent.putExtra("mode", 1);
              intent.putExtra("input_orid", resultString);
5aabe1c0   黄灿宏   畅游通核销app: 1.增加扫码配置
186
              LogUtil.i(TAG, getString(R.string.scan_result) + resultString);
3c2353cd   杜方   1、畅游通核销app源码提交;
187
              intent.putExtra("titleName", getString(R.string.show_result));
df682192   杜方   畅游通核销app: 1.优化扫CY...
188
              intent.putExtra("typeScan", typeScan);
3c2353cd   杜方   1、畅游通核销app源码提交;
189
190
              startActivity(intent);
          }
7d3f774c   杜方   畅游通核销app: 1.修复CYT...
191
192
          Boolean scanBack = SharedPreferences2Obj.getInstance(this).setName("config").getObject("scanBack", Boolean.class);
          if (scanBack != null && scanBack) {
3c2353cd   杜方   1、畅游通核销app源码提交;
193
  
7d3f774c   杜方   畅游通核销app: 1.修复CYT...
194
          } else {
3c2353cd   杜方   1、畅游通核销app源码提交;
195
  
7d3f774c   杜方   畅游通核销app: 1.修复CYT...
196
197
              PhomeScanerOrderActivity.this.finish();
          }
3c2353cd   杜方   1、畅游通核销app源码提交;
198
199
200
  
      }
  
5aabe1c0   黄灿宏   畅游通核销app: 1.增加扫码配置
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
      private void configIdent(String resultString) {
          String[] split = resultString.split(";");
          String serviceIp = split[0].split("=")[1];
          String encode = split[1].split("=")[1];
          String identity = split[2].split("=")[1];
          if (!identity.equals("")) {
              try {
                  identity = AESEncryptor.decrypt(constant.decrypt, identity);
                  LogUtil.d(TAG, getString(R.string.enterprise_communication_identifier)
                          + identity);
                  identity = AESEncryptor.encrypt(constant.decrypt, identity);
              } catch (Exception ex) {
                  try {
                      identity = AESEncryptor.encrypt(constant.decrypt,
                              identity);
                      LogUtil.d(TAG, getString(R.string.not_successfully_decrypt)
                              + identity);
                  } catch (Exception e) {
                      e.printStackTrace();
                      return;
                  }
              }
              ArrayList<ConfigBean> beans = DbManager.GetConfigs();
              ConfigBean bean = new ConfigBean();
              String mac = DevicTool.getInstance().getDevId().trim();
              bean.setEc_id(0 + "");
              bean.setEc_ip(serviceIp.trim());
              bean.setEc_identity(encode.trim());
              bean.setEc_mac(mac.toUpperCase());
              bean.setEc_passwd("123456");
              bean.setEc_signkey(identity);
              if (1 == beans.get(0).getEc_isPrint()) {
                  bean.setEc_isPrint(beans.get(0).getEc_isPrint());
              }else {
                  bean.setEc_isPrint(0);
              }
              DbManager.ClearConfig();
              DbManager.InsertConfig(bean);
c1300a1b   黄灿宏   畅游通核销app: 1.部分漏提交
239
240
241
              Intent intent = new Intent(PhomeScanerOrderActivity.this,
                      SettingsActivity.class);
              startActivity(intent);
5aabe1c0   黄灿宏   畅游通核销app: 1.增加扫码配置
242
243
244
          }
      }
  
3c2353cd   杜方   1、畅游通核销app源码提交;
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
      private void initCamera(SurfaceHolder surfaceHolder) {
          try {
              CameraManager.get().openDriver(surfaceHolder, PhomeScanerOrderActivity.this);
          } catch (IOException ioe) {
              return;
          } catch (RuntimeException e) {
              return;
          }
          if (handler == null) {
              handler = new CaptureActivityHandler(this, decodeFormats,
                      characterSet);
          }
      }
  
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width,
                                 int height) {
  
      }
  
      @Override
      public void surfaceCreated(SurfaceHolder holder) {
          if (!hasSurface) {
              hasSurface = true;
              initCamera(holder);
          }
  
      }
  
      @Override
      public void surfaceDestroyed(SurfaceHolder holder) {
          hasSurface = false;
  
      }
  
      public ViewfinderView getViewfinderView() {
          return viewfinderView;
      }
  
      public Handler getHandler() {
          return handler;
      }
  
      public void drawViewfinder() {
          viewfinderView.drawViewfinder();
  
      }
  
      private void initBeepSound() {
          if (playBeep && mediaPlayer == null) {
              // The volume on STREAM_SYSTEM is not adjustable, and users found it
              // too loud,
              // so we now play on the music stream.
              setVolumeControlStream(AudioManager.STREAM_MUSIC);
              mediaPlayer = new MediaPlayer();
              mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
              mediaPlayer.setOnCompletionListener(beepListener);
  
              AssetFileDescriptor file = getResources().openRawResourceFd(
                      R.raw.beep);
              try {
                  mediaPlayer.setDataSource(file.getFileDescriptor(),
                          file.getStartOffset(), file.getLength());
                  file.close();
                  mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
                  mediaPlayer.prepare();
              } catch (IOException e) {
                  mediaPlayer = null;
              }
          }
      }
  
      private final long VIBRATE_DURATION = 200L;
  
      private void playBeepSoundAndVibrate() {
          if (playBeep && mediaPlayer != null) {
              mediaPlayer.start();
          }
          if (vibrate) {
              Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
              vibrator.vibrate(VIBRATE_DURATION);
          }
      }
  
      /**
       * When the beep has finished playing, rewind to queue up another one.
       */
      private final OnCompletionListener beepListener = new OnCompletionListener() {
          public void onCompletion(MediaPlayer mediaPlayer) {
              mediaPlayer.seekTo(0);
          }
      };
  
      @Override
      protected void onPause() {
          super.onPause();
          if (handler != null) {
              handler.quitSynchronously();
              handler = null;
          }
          CameraManager.get().closeDriver();
      }
  
      @Override
      public void onBackPressed() {
          if (handler != null) {
              handler.quitSynchronously();
              handler = null;
          }
          CameraManager.get().closeDriver();
          super.onBackPressed();
      }
  
      @Override
      protected void onDestroy() {
          inactivityTimer.shutdown();
          super.onDestroy();
      }
  }