Blame view

src/com/ectrip/cyt/ui/PhomeScanerOrderActivity.java 9.99 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
  package com.ectrip.cyt.ui;
  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;
  
  import com.ectrip.cyt.bean.ConfigBean;
  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 {
  
      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;
  
      /**
       * 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();
          String resultString = result.getText();
          LogUtil.i("扫码数据 = " + resultString);
          if (resultString.equals("")) {
              MToast(PhomeScanerOrderActivity.this,
                      getString(R.string.scan_fail), MToast.LENGTH_SHORT);
          } else {
              try {
                  if(resultString.startsWith("CYT_")) {
                      resultString = resultString.substring(
                              resultString.indexOf("_") + 1,
                              resultString.indexOf(","));
                      ArrayList<ConfigBean> beans = DbManager.GetConfigs();
                      // 畅游通生成的订单ID:
                      String ec_name = beans.get(0).getEc_signkey();
                      LogUtil.i("ec_name = " + ec_name);
                      ec_name = AESEncryptor.decrypt(constant.decrypt, ec_name);
                      LogUtil.i("ec_name1 = " + ec_name);
                      LogUtil.i("resultString = " + resultString);
                      resultString = DesUtil.decrypt(resultString, ec_name);
  
                  }else if(resultString.startsWith("TDOS_")){
                      resultString = resultString.substring(
                              resultString.indexOf("_") + 1,
                              resultString.indexOf(","));
                      resultString = new String(Base64.decode(resultString), "utf-8");
2707d233   杜方   1、畅游通核销app;修改扫二维码...
154
155
156
157
                  }else if((resultString.startsWith("TY_") || (resultString.startsWith("PMS_")))){
                      resultString = resultString;
                  }else{
                      resultString = resultString;
3c2353cd   杜方   1、畅游通核销app源码提交;
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
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
                  }
              } catch (Exception e) {
                  e.printStackTrace();
              }
  
              Intent intent = new Intent(PhomeScanerOrderActivity.this,
                      QRCodeOrderListActivity.class);
              intent.putExtra("mode", 1);
              intent.putExtra("input_orid", resultString);
              LogUtil.i(getString(R.string.scan_result) + resultString);
              intent.putExtra("titleName", getString(R.string.show_result));
              startActivity(intent);
          }
              Boolean scanBack = SharedPreferences2Obj.getInstance(this).setName("config").getObject("scanBack", Boolean.class);
              if (scanBack != null && scanBack) {
  
              } else {
  
                  PhomeScanerOrderActivity.this.finish();
              }
  
      }
  
      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();
      }
  }