Skip to content

Commit 4cd54fc

Browse files
committed
可以自定义界面了
1 parent 5a6776f commit 4cd54fc

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

qrcodescanner/src/main/java/com/iqos/qrscanner/app/QRScannerActivity.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@
3030

3131

3232
public class QRScannerActivity extends Activity implements SurfaceHolder.Callback, View.OnClickListener {
33+
private static final long VIBRATE_DURATION = 200L;
34+
private static final float BEEP_VOLUME = 0.10f;
3335
public static final int SCAN_RESULT_CODE = 15613;
3436
public static final String SCAN_RESULT = "scan_result";
35-
private static final float BEEP_VOLUME = 0.10f;
3637
private ViewfinderView mScanView;
3738
private CaptureActivityHandler handler;
3839
private Vector<BarcodeFormat> decodeFormats;
@@ -43,11 +44,13 @@ public class QRScannerActivity extends Activity implements SurfaceHolder.Callbac
4344
private ImageView mIvBack;
4445
private boolean hasSurface;
4546
private boolean playBeep;
47+
4648
private boolean vibrate;
49+
4750
@Override
4851
protected void onCreate(Bundle savedInstanceState) {
4952
super.onCreate(savedInstanceState);
50-
setContentView(R.layout.activity_qrscanner);
53+
setContentView(getLayoutResources());
5154
this.setFitSystem();
5255
this.findViews();
5356
this.init();
@@ -64,6 +67,15 @@ private void setFitSystem() {
6467
}
6568
}
6669

70+
/**
71+
* 获取布局文件
72+
*
73+
* @return XML里面的布局文件
74+
*/
75+
protected int getLayoutResources() {
76+
return R.layout.activity_qrscanner;
77+
}
78+
6779
/**
6880
* 获取XML里面的控件
6981
*/
@@ -73,6 +85,7 @@ protected void findViews() {
7385
mIvBack = findViewById(R.id.app_iv_back);
7486
}
7587

88+
7689
/**
7790
* 初始化
7891
*/
@@ -85,7 +98,6 @@ protected void init() {
8598
inactivityTimer = new InactivityTimer(this);
8699
}
87100

88-
89101
@Override
90102
protected void onResume() {
91103
super.onResume();
@@ -127,11 +139,15 @@ protected void onDestroy() {
127139

128140
/**
129141
* 处理扫描结果
142+
*
143+
* @param result 扫描的结果
130144
*/
131145
public void handleDecode(Result result) {
132-
if (null == result) return;
146+
if (null == result) {
147+
this.restartQRScanner();
148+
return;
149+
}
133150
inactivityTimer.onActivity();
134-
playBeepSoundAndVibrate();
135151
String resultStr = result.getText();
136152
Intent intent = new Intent();
137153
intent.putExtra(SCAN_RESULT, resultStr);
@@ -196,9 +212,10 @@ private void initBeepSound() {
196212
}
197213
}
198214

199-
private static final long VIBRATE_DURATION = 200L;
200-
201-
private void playBeepSoundAndVibrate() {
215+
/**
216+
* 扫码成功后播放“滴”并且振动手机
217+
*/
218+
protected final void playBeepSoundAndVibrate() {
202219
if (playBeep && mediaPlayer != null) {
203220
mediaPlayer.start();
204221
}
@@ -210,6 +227,16 @@ private void playBeepSoundAndVibrate() {
210227
}
211228
}
212229

230+
/**
231+
* 连续扫描、调用此方法即可重新扫描
232+
*/
233+
protected final void restartQRScanner() {
234+
if (null != handler) {
235+
handler.restartPreviewAndDecode();//重新启动预览和解码
236+
}
237+
}
238+
239+
213240
/**
214241
* When the beep has finished playing, rewind to queue up another one.
215242
*/

qrcodescanner/src/main/java/com/iqos/qrscanner/decoding/CaptureActivityHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void quitSynchronously() {
106106
/**
107107
* 重新启动预览和解码
108108
*/
109-
private void restartPreviewAndDecode() {
109+
public void restartPreviewAndDecode() {
110110
if (state == State.SUCCESS) {
111111
state = State.PREVIEW;
112112
CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);

0 commit comments

Comments
 (0)