Code Monkey home page Code Monkey logo

Comments (6)

hideko avatar hideko commented on July 19, 2024 1

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

from android-pagecurl.

androidqasim avatar androidqasim commented on July 19, 2024 1

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

from android-pagecurl.

androidqasim avatar androidqasim commented on July 19, 2024 1

its really urgent

from android-pagecurl.

booker0108 avatar booker0108 commented on July 19, 2024

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.

from android-pagecurl.

SardarKhan299 avatar SardarKhan299 commented on July 19, 2024

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

from android-pagecurl.

thomasalvadev avatar thomasalvadev commented on July 19, 2024
  • 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

from android-pagecurl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.