android - How to modify zxing for keeping on scanning? -
i have developed application qr code scanner based on zxing,but facing problem how modify code scanner can keep on scan s sequence of qr code data until user stopped it. can give me advice?
public class scanlibrarycardactivity extends captureactivity { private progressdialog pdialog; private string uid, bname, authors, publisher, edition, callnumber, location; private int total; jsonparser jparser = new jsonparser(); jsonarray user = null; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // setcontentview(r.layout.main); // cameramanager } @override public void handledecode(final result obj, bitmap barcode) { uid = obj.gettext(); if (uid.matches("\\d+")) new checkcorrectuser().execute(); else { customizeddialog.showresultdialog(scanlibrarycardactivity.this, "invalid user"); intent = new intent(getapplicationcontext(),scanlibrarycardactivity.class); i.addflags(intent.flag_activity_no_animation); i.addflags(intent.flag_activity_clear_top); startactivity(i); finish(); } } class checkcorrectuser extends asynctask<string, string, string> { int success; /** * before starting background thread show progress dialog * */ @override protected void onpreexecute() { super.onpreexecute(); pdialog = new progressdialog(scanlibrarycardactivity.this); pdialog.setmessage("loading. please wait..."); pdialog.setindeterminate(false); pdialog.setcancelable(false); pdialog.show(); } protected string doinbackground(string... args) { // building parameters list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair(tag.gettaguid(), uid)); jsonobject json = jparser.makehttprequest(url.geturl_getuserdata(), "get", params); try { // checking success tag success = json.getint(tag.gettagsuccess()); if (success == 1) { user = json.getjsonarray("user"); jsonobject c = user.getjsonobject(0); total = c.getint("total"); } else { // error pop-up } } catch (jsonexception e) { e.printstacktrace(); } return null; } protected void onpostexecute(string file_url) { // dismiss dialog after getting products pdialog.dismiss(); // updating ui background thread runonuithread(new runnable() { public void run() { if (success == 1) { customizeddialog.showresultdialog( scanlibrarycardactivity.this, "valid user"); } else { // allow user function without save // data customizeddialog.showresultdialog( scanlibrarycardactivity.this, "invalid user"); } } }); } } } public class captureactivity extends activity 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 static final float beep_volume = 0.10f; private boolean vibrate; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); // cameramanager cameramanager.init(getapplication()); viewfinderview = (viewfinderview) findviewbyid(r.id.viewfinder_view); hassurface = false; inactivitytimer = new inactivitytimer(this); } @override protected void onresume() { super.onresume(); 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; } @override protected void onpause() { super.onpause(); if (handler != null) { handler.quitsynchronously(); handler = null; } cameramanager.get().closedriver(); } @override protected void ondestroy() { inactivitytimer.shutdown(); super.ondestroy(); } private void initcamera(surfaceholder surfaceholder) { try { cameramanager.get().opendriver(surfaceholder); } 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(); } public void handledecode(final result obj, bitmap barcode) { inactivitytimer.onactivity(); playbeepsoundandvibrate(); } private void initbeepsound() { if (playbeep && mediaplayer == null) { // volume on stream_system not adjustable, , users found // loud, // play on 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 static 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 beep has finished playing, rewind queue one. */ private final oncompletionlistener beeplistener = new oncompletionlistener() { public void oncompletion(mediaplayer mediaplayer) { mediaplayer.seekto(0); } }; }
Comments
Post a Comment