Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please help about creating auto-animate #21

Open
booker0108 opened this issue Apr 4, 2012 · 6 comments
Open

Please help about creating auto-animate #21

booker0108 opened this issue Apr 4, 2012 · 6 comments

Comments

@booker0108
Copy link

Hi, Harism.

I am really appreciate your project and effort.

I have read the post before and you said the TouchEvent is the key to make auto-animate function, I would like to ask how can I make use of it as I have no ideas about how to pass a TouchEvent to the view.

@booker0108 booker0108 reopened this Apr 4, 2012
@booker0108
Copy link
Author

Oh, after a large amount of search and read, I have found the method to simulate the TouchEvent and it should be available to preform the automatic animation.

I will try to add the function to the commit later when I complete this task.

@hideko
Copy link

hideko commented Nov 24, 2012

Could you explain me how to simulate the animation performed on touch but automatically when I touch a button?

@SardarKhan299
Copy link

Can you provide the function for how to auto animate the page..

@androidqasim
Copy link

Please Harism comment the funcation which curl automatically on a button press

@androidqasim
Copy link

its really urgent

@thomasalvadev
Copy link

thomasalvadev commented Jul 26, 2017

  • Firstly, change a little bit code in onTouch() function:
    public boolean onTouch(View view, MotionEvent me) {
    ............
    case MotionEvent.ACTION_UP:
    if (mCurlState == CURL_LEFT || mCurlState == CURL_RIGHT) {
    // Animation source is the point from where animation starts.
    // Also it's handled in a way we actually simulate touch events
    // meaning the output is exactly the same as if user drags the
    // page to other side. While not producing the best looking
    // result (which is easier done by altering curl position and/or
    // direction directly), this is done in a hope it made code a
    // bit more readable and easier to maintain.
    mAnimationSource.set(mPointerPos.mPos);
    mAnimationStartTime = System.currentTimeMillis();

                 // Given the explanation, here we decide whether to simulate
                 // drag to left or right end.
                 if ((mViewMode == SHOW_ONE_PAGE && mPointerPos.mPos.x > (rightRect.left + rightRect.right) / 2)
                         || mViewMode == SHOW_TWO_PAGES
                         && mPointerPos.mPos.x > rightRect.left) {
                     // On right side target is always right page's right border.
                     if (isAutoCurl)
                         mDragStartPos.x = 0;
                     mAnimationTarget.set(mDragStartPos);
                     mAnimationTarget.x = isAutoCurl ? mRenderer.getPageRect(CurlRenderer.PAGE_LEFT).left : mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT).right;
                     mAnimationTargetEvent = isAutoCurl ? SET_CURL_TO_LEFT : SET_CURL_TO_RIGHT;
                 } else {
                     // On left side target depends on visible pages.
                     if (isAutoCurl)
                         mDragStartPos.x = rightRect.right;
                     mAnimationTarget.set(mDragStartPos);
                     if (mCurlState == CURL_RIGHT || mViewMode == SHOW_TWO_PAGES) {
                         mAnimationTarget.x = isAutoCurl ? rightRect.right : leftRect.left;
                     } else {
                         mAnimationTarget.x = rightRect.left;
                     }
                     mAnimationTargetEvent = isAutoCurl ? SET_CURL_TO_RIGHT : SET_CURL_TO_LEFT;
                 }
                 mAnimate = true;
                 requestRender();
             }
             break;
    

...........
}

  • Then create function call curlToNextPage():
    public void curlToNextPage() {
    int x = getWidth();
    int y = getHeight() / 2;

     isAutoCurl = true;
     MotionEvent me = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, x, y, 0);
     onTouch(this, me);
     for (int i = 0; i < getWidth() / 5; i++) {
         x += i;// restamos xq vamos pa la derecha
         me = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, x, y, 0);
         onTouch(this, me);
         try {
             Thread.sleep(10L);
         } catch (InterruptedException e) {
             e.printStackTrace();
         }
     }
     me = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, x, y, 0);
     onTouch(this, me);
     isAutoCurl = false;
    

    }

From now on, you can use this new function to curl page automatically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants