条形码扫描
条形码
CaptureActivity 继承 Activity 实现Callback 接口
private final
ScheduledExecutorService inactivityTimer =
Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory());
onCreate() 中
CameraManager.init();
得到cameraManager =new
CameraManager(context);
调用inactivityTimer = new
InactivityTimer(this);
在InactivityTimer(){
onActivity();
}
onActivity(){
cancel();
inactivityFuture =
inactivityTimer.schedule(new
FinishListener(activity),
INACTIVITY_DELAY_SECONDS,
TimeUnit.SECONDS);
}
cancel(){
if (inactivityFuture != null)
{
inactivityFuture.cancel(true);
inactivityFuture =
null;
}
}
}
onResume()
中,
SurfaceView 继承 View
SurfaceHolder
surfaceHolder=surfaceView.getHolder();
initCamera(surfaceHolder);
class DaemonThreadFactory implements
ThreadFactory{
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable);
thread.setDaemon(true);
return thread;
}
interface ThreadFactory {
public
abstract Thread newThread(Runnable
runnable);
}
initCamera(surfaceHolder){
调用的是
CameraManager.get().openDriver(surfaceHolder);
}
CameraManager类是final 类
static{
sdkInt=Integer.parserInt(Build.VERSION.SDK);
}
}
CameraConfigurationManager 类 也是个final 类
class
FinishListener implements OnClickListener,OnCnacelListener,Runnable{
public FinishListener(Activity activityToFinish){
this.activityFinish=activityToFinish;
}
onCancel(DialogInterface dailogInterface){
run();
}
onClick(DialogInterface dialogInterface,int i){
run();
}
run(){
activityFinish.finish();
}
}
public interface ScheduledFuture extends
Delayed,Future{
}
gzbbxu/TiaoxingmaTest