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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
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 {
|
df682192
杜方
畅游通核销app: 1.优化扫CY...
|
45
|
public final String TAG = "PhomeScanerOrderActivity";
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
46
47
48
49
50
51
52
53
54
55
56
|
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...
|
57
|
private int typeScan;
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
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
|
/**
* 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:新增主界面关...
|
131
|
String resultString = result.getText().trim();
|
df682192
杜方
畅游通核销app: 1.优化扫CY...
|
132
|
LogUtil.i(TAG, "扫码数据 = " + resultString);
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
133
134
135
136
137
|
if (resultString.equals("")) {
MToast(PhomeScanerOrderActivity.this,
getString(R.string.scan_fail), MToast.LENGTH_SHORT);
} else {
try {
|
7d3f774c
杜方
畅游通核销app: 1.修复CYT...
|
138
|
if (resultString.startsWith("CYT_")) {
|
df682192
杜方
畅游通核销app: 1.优化扫CY...
|
139
140
141
142
143
144
145
146
|
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源码提交;
|
147
148
149
|
ArrayList<ConfigBean> beans = DbManager.GetConfigs();
// 畅游通生成的订单ID:
String ec_name = beans.get(0).getEc_signkey();
|
df682192
杜方
畅游通核销app: 1.优化扫CY...
|
150
|
LogUtil.i(TAG, "ec_name = " + ec_name);
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
151
|
ec_name = AESEncryptor.decrypt(constant.decrypt, ec_name);
|
df682192
杜方
畅游通核销app: 1.优化扫CY...
|
152
|
LogUtil.i(TAG, "ec_name1 = " + ec_name);
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
153
154
|
resultString = DesUtil.decrypt(resultString, ec_name);
|
7d3f774c
杜方
畅游通核销app: 1.修复CYT...
|
155
|
} else if (resultString.startsWith("TDOS_")) {
|
df682192
杜方
畅游通核销app: 1.优化扫CY...
|
156
157
158
159
|
typeScan = 0;
// resultString = resultString.substring(resultString.indexOf("_") + 1, resultString.indexOf(","));
resultString = resultString.substring(resultString.indexOf("_") + 1, resultString.length());
LogUtil.i(TAG, "resultString = " + resultString);
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
160
|
resultString = new String(Base64.decode(resultString), "utf-8");
|
7d3f774c
杜方
畅游通核销app: 1.修复CYT...
|
161
|
} else if ((resultString.startsWith("TY_") || (resultString.startsWith("PMS_")))) {
|
df682192
杜方
畅游通核销app: 1.优化扫CY...
|
162
|
typeScan = 1;
|
2707d233
杜方
1、畅游通核销app;修改扫二维码...
|
163
|
resultString = resultString;
|
7d3f774c
杜方
畅游通核销app: 1.修复CYT...
|
164
|
} else {
|
df682192
杜方
畅游通核销app: 1.优化扫CY...
|
165
|
typeScan = 1;
|
2707d233
杜方
1、畅游通核销app;修改扫二维码...
|
166
|
resultString = resultString;
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
167
168
169
170
171
172
173
174
175
176
177
|
}
} 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));
|
df682192
杜方
畅游通核销app: 1.优化扫CY...
|
178
|
intent.putExtra("typeScan", typeScan);
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
179
180
|
startActivity(intent);
}
|
7d3f774c
杜方
畅游通核销app: 1.修复CYT...
|
181
182
|
Boolean scanBack = SharedPreferences2Obj.getInstance(this).setName("config").getObject("scanBack", Boolean.class);
if (scanBack != null && scanBack) {
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
183
|
|
7d3f774c
杜方
畅游通核销app: 1.修复CYT...
|
184
|
} else {
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
185
|
|
7d3f774c
杜方
畅游通核销app: 1.修复CYT...
|
186
187
|
PhomeScanerOrderActivity.this.finish();
}
|
3c2353cd
杜方
1、畅游通核销app源码提交;
|
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
300
301
302
303
304
305
306
307
308
309
|
}
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();
}
}
|