Implementation of book paging in Android-Upgrade

Source: Internet
Author: User

Since the previous release of the "Android Implementation of book flip effect-end", I have received messages from many friends. Some time ago, due to many issues, the blog is too hasty to be clearly described in many details. Therefore, many people do not understand some of the issues, and many have reported the bugs. Today, I finally found out a simple summary of some issues during this period.

The previous example only enables simple drag-and-drop operations on books without page flip animation. Many people hope that I can add this one, so first let's talk about the page flip animation.

In fact, page-turning animations are easy to implement, as long as the mTouch is constantly refreshed after the Touch is lifted. x, mTouch. the value of y is enough. You can use handler, thread, or scroler. I personally prefer scroler, which is relatively simple.

Add two new functions:

Private void startanimation (INT delaymillis) {<br/> int dx, Dy; <br/> // The horizontal sliding distance of DX, A negative value will scroll to the left <br/> // The distance between DY and Dy. A negative value will scroll up <br/> If (mcornerx> 0) {<br/> dx =-(INT) (mwidth + mtouch. x); <br/>}else {<br/> dx = (INT) (mwidth-mtouch. X + mwidth); <br/>}< br/> If (mcornery> 0) {<br/> DY = (INT) (mheight-mtouch. y); <br/>}else {<br/> DY = (INT) (1-mtouch. y); // prevents mtouch. Y eventually becomes 0 <br/>}< br/> mscroller. startscroll (INT) mtouch. x, (INT) mtouch. y, dx, Dy, <br/> delaymillis); <br/>}</P> <p> Public void computescroll () {<br/> super. computescroll (); <br/> If (mscroller. computescroloffset () {<br/> float x = mscroller. getcurrx (); <br/> float y = mscroller. getcurry (); <br/> mtouch. X = x; <br/> mtouch. y = y; <br/> postinvalidate (); <br/>}< br/>}

Then you can call it when you press the lift button.

If (event. getAction () = MotionEvent. ACTION_UP ){
If (canDragOver () {// determines whether pages can be turned over
StartAnimation (1200 );
} Else {
MTouch. x = mCornerX-0.09f; // if you cannot flip the page, mTouch returns the status when it is not static.
MTouch. y = mCornerY-0.09f; //-0.09f prevents mTouch = 800 or mTouch = 0 from bugs in these values
}

 

The calcPoints () function also needs to be modified. To prevent a bug, if (mBezierStart1.x <0 | mBezierStart1.x> mWidth) {is added, however, when you flip the page, mTouch. x will be less than 0 (when turning from right to left) or mTouch. x> mWidth (from left to right) does not need to be processed in this function. Therefore, we need to block it in this case and change it:

If (mTouch. x> 0 & mTouch. x <mWidth ){
If (mBezierStart1.x <0 | mBezierStart1.x> mWidth ){

......}

}

After modification, the animation effect can be completed.

 

Some children's shoes want to make this an e-book reader, but they do not know how to convert the content in the txt file to the image needed for turning pages, and switch after turning pages. So I added a new simple class BookPageFactory to read a txt file in the SD card and convert the read content into a bitmap for display. Haha, this is just a very small function class. It just serves as a demonstration for you. You can modify the parameters as needed.

The source code comes with a simple e-book reader with flip pages. When you test the code, place test.txt in the root directory of the SD card:

Pagefactory. openbook ("/sdcard/test.txt ");

 

New interface:

 

 

Source code:

Http://download.csdn.net/source/3278901

 

 

 

 

 

 

Related Article

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.