Watercress Book Query upgrade Edition "sweep book"

Source: Internet
Author: User

Original from: Miroslav |http://fangjie.sinaapp.com/?p=88 Reprint Please indicate the source

GitHub: https://github.com/JayFang1993/BookScaning

first of all, we can see the effect show:http://fangjie.sinaapp.com/?page_id=54

Mainactivity.java is the activity of the main interface. Bookview.java is the interface of displaying basic information of books, Captureactivity.java is scanning lens interface, reviewactivity is the list interface of notes, Reviewcontent.java is the specific interface of notes; BookInfo is the entity of book Class (adding very much information on the original basis); Review is the entity class for notes.

The basic technology is the use of zxing Open Source Library, Simple network communication, data analysis and UI Update essentials. The original demo is directly called Zxing apk to use, so it is necessary to require users to install the zxing apk, this application must not be, so I put zxing some of the package into their projects.

I. Use of zxing:
First of all, the core package of zxing into its own program, in the Zxing official Android Demo package to remove the unused, after streamlining as I above the project file. These packages are mostly about camera and parsing, and we just need to slightly modify the Captureactivity.java and Captureactivityhandler.java files. Captureactivity.java is a subclass of activity that scans the camera-enabled interface. In fact, the actual process of scanning interface processing in Captureactivityhandler.java. What we need is to return the ISBN value to the mainactivity after it has been scanned.

Mainactivity.java

Open Scan Buttonbtn.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (view view) {Intent Intent =new Intent (Mainactivity.this,captureactivity.class); Startactivityforresult (intent,100);}});

Captureactivityhandler.java

public void Handlemessage (message message) {switch (message.what) {case R.id.auto_focus:if (state = = State.preview) {came Ramanager.get (). Requestautofocus (this, r.id.auto_focus);} Break;case r.id.restart_preview:log.i ("OUTPUT", "Got restart Preview message"); Restartpreviewanddecode (); break;case r.id.decode_succeeded://Scan succeeded log.i ("OUTPUT", "Got Decode succeeded Message"); state = state.success; Bundle bundle = Message.getdata (); Bitmap Barcode = Bundle = = null? Null:(Bitmap) bundle.getparcelable (DECODETHREAD.BARCODE_BITMAP); String str_result= (Result) message.obj). GetText (); Activity.handledecode ((Result) message.obj, barcode); Intent Intent=new Intent (Activity,mainactivity.class); Intent.putextra ("Result", Str_result); Activity.setresult (100, Intent); Activity.finish () break;case r.id.decode_failed://scan failed log.i ("OUTPUT", "Got return scan result message"); state = State.preview; Cameramanager.get (). Requestpreviewframe (Decodethread.gethandler (), r.id.decode); Break;case R.id.return_scan_ result://Exit Scan LOG.I ("OUTPUT", "Got return scan result message"); Intent intent2=new Intent (activity,mainactivity.class); Activity.startactivity (intent2); break;}}

Mainactivity.java

Get the ISBN code after scanning and search for book information on the Watercress protected void onactivityresult (int requestcode,int resultcode,intent data) { Super.onactivityresult (Requestcode, ResultCode, data); if ((requestcode==100) | | | (RESULTCODE==ACTIVITY.RESULT_OK)) &&data!=null) {log.i ("OUTPUT", "Ngyufu");p rogressdialog=new ProgressDialog (this); Progressdialog.setmessage ("Please wait, reading information ...");p rogressdialog.show (); String urlstr= "https://api.douban.com/v2/book/isbn/" +data.getextras (). getString ("result");//After sweeping to ISBN, Start download thread download book Information new Downloadthread (URLSTR). Start ();}}

After returning the ISBN value, the rest is to go to the Watercress API to get the data, and then parse, update to the UI. These things in between the blog has been told, not the same is the addition of the book properties, added a note display list and note details of the interface, these things will be network communication and data parsing is very easy, not much to talk about.
Two: Watercress book API:HTTP://DEVELOPERS.DOUBAN.COM/WIKI/?TITLE=BOOK_V2
I use the following two, detailed data properties to see the API documentation. Here because the data of the Watercress Book review must be authorized after the ability to obtain complete data, no authorized users can only obtain the summary information, in order to be simple, I did not do the OAuth authentication part, directly select the note information, this data does not need authorization.

Obtaining the information of books according to ISBN get/v2/book/isbn/:name

Get all the notes for a book Get/v2/book/:id/annotations

You are welcome to follow my personal website:http://fangjie.sinaapp.com/

Watercress Book Query upgrade Edition "sweep book"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.