3D Style Page Flip on Android

Overview

Android Arsenal

PageFlip

This project is aimed to implement 3D style page flip on Android system based on OpenGL 2.0.

For JNI version, please visit: android-PageFlip-JNI

Table of Contents

Preview

SinglePage DoublePages

Installation

Gradle

Add it to your build.gradle with:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

and:

dependencies {
    compile 'com.github.eschao:android-PageFlip:1.0.2'
}

Android Version Support

The following versions have been tested on emulator:

Android version API version Support
3.2 API 13 x
4.1 API 16
4.2 API 17
4.3 API 18
4.4 API 19
5.0 API 21
5.1 API 22
6.0 API 23
7.0 API 24
7.1.1 API 25
7.+ API 26

Usage

I. Simple steps for introducing PageFlip into your project

  • Creates a surface view class extending from GLSurfaceView

  • Implements android Renderer interface to draw your content on a bitmap and set it as a texture of PageFlip

  • Instanitiates a PageFlip object in the constructor of your surface view

  • Configures PageFlip, For example: set animating duration, page mode or mesh pixels

  • Handles the below android events:

    • onFingerDown: notify PageFlip object to prepare flip
    • onFingerMove: notify PageFlip object to compute data for drawing flip frame
    • onFingerUp: notify PageFlip object to determine whether or not launching a flip animation
    • onSurfaceCreated: notify PageFlip object to handle usreface creating event
    • onSurfaceChanged: notify PageFlip object to handle surface changing event
  • You may need a message handler to send/receive an drawing message. Please refer to PageFlipView in sample application.

  • You may need a lock to avoid conflicts between main thread and OpenGL rendering thread. Please refer to PageFlipView in sample application.

More details, please take a look PageFlipView in sample application.

II. Configure PageFlip

PageFlip library provides some configurations for customizing its behaviors. For example: shadow color and alpha, mesh pixels and page mode.

1. Page Mode

There are two page modes provided by PageFlip:

  • Auto Page Mode: In this mode, PageFlip will automatically decide to use single page or double pages to present content on screen. That means single page is used for portrait mode and double pages is used for lanscape mode.
  • Single Page Mode: No matter screen is portait or landscape mode, PageFlip always use single page to show content

You can use enableAutoPage to enable auto page mode or disable it(equally enable single page mode).

Example:

  // enable auto page mode
  mPageFlip.enableAutopage(true); 

2. Click screen to flip

You can enable/disable clicking screen to flip

Example:

  // enable clicking to flip
  mPageFlip.enableClickToFlip(true);

3. Area of clicking to flip

You can give a ratio of page width from 0 to 0.5f to set an area for reponsing click event to trigger a page flip. The default value is 0.5f, which means the backfward flip will happen if you click the left half of screen and forward flip will start if you click the right half of screen in single page mode.

Example:

  // set ratio with 0.3
  mPageFlip.setWidthRatioOfClickToFlip(0.3f);

4. PageFlip listener

You can set a listener to tell PageFlip if the forward flip or backward flip could happen.

Example:

  mPageFlip.setListener(mListener);

5. Mesh pixels

Set how many pixels are used for a mesh. The less pxiels the mesh uses, the more fine the drawing is and the lower the performance is. The default value is 10 pixels.

Example:

  mPageFlip.setPixelsOfMesh(5);

6. Ratio of semi-peremeter

When page is curled, it is actually tackled as a semi-cylinder by PageFlip. You can set size of the semi-cylinder to change the flip shap. Since the semi-cylinder dependeds on the line length from the touch point to original point(see the below illustration), you need to provide a ratio of this line length to tell PageFlip the peremeter of the semi-cylinder. The default value is 0.8f.

  +----------------+
  |   touchP       |
  |       .        | 
  |        \       |
  |         + p0   |
  |          \     |
  |           \    |
  |        p1  +   |
  |              \ |
  +----------------+
              original point, that means you drag the page from here to touch point(touchP)

  The length from p0 to p1 is peremeter of semi-cylinder and determined by ratio your giving

Example:

  mPageFlip.setSemiPerimeterRatio(0.6f);

7. Mask alpha for the back of fold page

You can set the mask alpha for the back of fold page when page is curled in single page mode. The default value is 0.6f.

Example:

  mPageFlip.setMaskAlphaOfFold(0.5f);

8. Edge shadow color/alpha of fold page

You can set start/end color and start/end alpha for edge shadow of fold page.

Example:

  // set start color with 0.1f, start alpha with 0.2f, end color with 0.5f
  // and end alpha with 1f
  mPageFlip.setShadowColorOfFoldBase(0.1f, 0.2f, 0.5f, 1f);

9. Base shadow color/alpha of fold page

You can set start/end color and start/end alpha for base shadow of fold page.

Example:

  mPageFlip.setShadowColorOfFoldBase(0.05f, 0.2f, 0.5f, 1f);

10. Edge shadow width of fold page

When page is curled, the size of fold page will follow the finger movement to be changed and its edge shadow width should be changed accordingly. You can set an appropriate width range for shadow width.

Example:

  // set the minimal width is 5 pixels and maximum width is 40 pixels.
  // set the ratio is 0.3f which means the width will be firstly computed by formula: 
  // width = diameter of semi-cylinder * 0.3f, and then compare it with minimal
  // and maximal value to make sure the width is in range.
  mPageFlip.setShadowWidthOfFoldEdges(5, 40, 0.3f);

11. Base shadow width of fold page

Like Edge shadow width of fold page, You can set an appropriate width range for base shadow of fold page.

Example:

  // see {@link #setShadowWidthOfFoldEdges} function
  mPageFlip.setShadowWidthOfFoldBase(5, 40, 0.4f);

12. Duration of flip animating

You can give a duration for flip animating when you call onFingerUp function to handle the finger up event.

Example:

  // the last parameter is duration with millisecond unit, here we set it with 2 seconds.
  mPageFlip.onFingerUp(x, y, 2000);

License

This project is licensed under the Apache License Version 2.0.

Comments
  • Demo not working in landscape mode

    Demo not working in landscape mode

    I am using this library in a sample app and found that the page flip doeant work in landscape mode. I tried the semo app on play store and found that portrait mode works but landscape mode shows black screen as earlier reported. I am stuck here. I wish i could fix it. Can someone please help me. Many many thanks in advance.

    opened by arindammitra06 22
  • Is it really to highlight the text on pages?

    Is it really to highlight the text on pages?

    I need to implement the text highlight on pages to copy it (for example). I'm clicking on text (eg "First page" which is default) and hold it, but have no action. Is it really to use a TextView rather than Bitmap or I missing something?

    opened by acuna-public 9
  • Sample not working in the Emulator

    Sample not working in the Emulator

    When I open the Sample in the Android Emulator(API 25), it displays a black screen and this error is displayed in the Run tab of the Android Studio. distrib/android-emugl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glDeleteShader:622 error 0x501 and this in logcat

      EGL_emulation  E  tid 5175: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
     OpenGLRenderer  W  Failed to set EGL_SWAP_BEHAVIOR on surface 0xa13fd320, error=EGL_BAD_MATCH
           GLShader  E  Can'top compile shader for type: 35632Error: 0
                     E  Compile shader error: ERROR: 0:3: '' : No precision specified for (float)
       PageFlipView  E  Failed to run PageFlipFlipRender:onSurfaceCreated
     LoadBitmapTask  D  Load Queue:0 in background!
                     D  Load Queue:0 in background!
    emuglGLESv2_enc  E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glUseProgram:1083 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glVertexAttribPointer:290 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glEnableVertexAttribArray:469 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glVertexAttribPointer:290 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glEnableVertexAttribArray:469 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glUseProgram:1083 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glVertexAttribPointer:290 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glEnableVertexAttribArray:469 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glVertexAttribPointer:290 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glEnableVertexAttribArray:469 GL error 0x501
      Choreographer  I  Skipped 34 frames!  The application may be doing too much work on its main thread.
    emuglGLESv2_enc  E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glUseProgram:1083 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glVertexAttribPointer:290 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glEnableVertexAttribArray:469 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glVertexAttribPointer:290 GL error 0x501
                     E  device/generic/goldfish-opengl/system/GLESv2_enc/GL2Encoder.cpp:s_glEnableVertexAttribArray:469 GL error 0x501
    
    opened by hegazy 8
  • How to get Bitmaps in an order other than displaying Randomly ?

    How to get Bitmaps in an order other than displaying Randomly ?

    Hi

    Could you please let me know how can I get the bitmaps in an order ? In the LoadBitmapTask class there is a method getRandomBitmap() which is generating bitmaps randomly. How the code should be written if I want to display them in a specific order ? (like the pages in book, which has an order).

    opened by sayansubhrabanerjee 6
  • how to move particular page?

    how to move particular page?

    Hello. First of all, thank you for making this open-source.

    I would like to have a way to navigate to a particular page. When analyzing source, page movement seems to be possible only through touch. how to move particular page?

    opened by edgelv34 6
  • AsyncPageRenderer?

    AsyncPageRenderer?

    Hi, first of all amazing for, however I need to customize bitmap loading logic. Can you please give me pointers as how to implement if bitmap wants to be loaded asynchronously, say from network, I see that LoadbitmapTask.getBitmap is synchronous. (not thinking about decoding)

    • maybe some callback to request ahead bitmaps so they can get preloaded?

    Thanks you

    opened by ursusursus 5
  • Zoom in Page Flip

    Zoom in Page Flip

    Hi i'm a newbie with open gl. I use your example and want to zoom with two fingers a picture. I have add in code ScaleGestureDetector and Listener. Where should i change scale ? Thanks.

    opened by OleksandrGrument 5
  • Unnecessary steps (?)

    Unnecessary steps (?)

    https://github.com/eschao/android-PageFlip/blob/09d2755a021981eb791b586bd56b484ef14cb1f4/Sample/src/main/java/com/eschao/android/widget/sample/pageflip/LoadBitmapTask.java#L206

    By the end of this method, variable mBGSizeIndex will always have value equals to LARGE_BG. Is this by intention? If it is, we could rewrite this method like below:

    public void set(int w, int h, int maxCached) {
        mIsLandscape = w > h;
    
        if (maxCached != mQueueMaxSize) {
            mQueueMaxSize = maxCached;
        }
    
        mBGSizeIndex = LARGE_BG;
        synchronized (this) {
            cleanQueue();
            notify();
        }
    }
    

    Regards.

    bug 
    opened by yuwono95 4
  • How to click a button to flip page?

    How to click a button to flip page?

    Hi There,

    It's so nice to see your library. I'm trying to customized it. After research couple day, I still have some questions:

    1. How to determine which page that user move finger in (left page or right page)?
    2. How is clickToFlip() works?, I want to know that because I want to detect the action click to flip the page.
    3. Can I use the pageFlipView as a customize view in layout? It's seem wrong Point X Y when I'm trying to do that.
    help wanted 
    opened by tranchunghieu118 3
  • What About loading image remotely

    What About loading image remotely

    Hii eschao, thanks for wonderful library .but what about loading image from server not from local can we do this. if we can then how to do please provide some directions.

    thanks

    opened by mohittanwar94 3
  • How can I modify the current page?

    How can I modify the current page?

    We found that the drawPage method, located inside the SinglePageRender on the sample app, displays the current page in text.

    If the current page is three, the text will show three.

    I would like to change the number on the current page without flip it.

    What should I do?

    opened by edgelv34 2
  • Could not find com.github.eschao:android-PageFlip:1.0.2.

    Could not find com.github.eschao:android-PageFlip:1.0.2.

    When I try to run projeckt that I use PageFlip suddenly there is problem with importing project.

    Whole error that I get:

    [](

    • What went wrong: Execution failed for task ':app:mergeDebugNativeLibs'.

    Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not find com.github.eschao:android-PageFlip:1.0.2. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/github/eschao/android-PageFlip/1.0.2/android-PageFlip-1.0.2.pom - https://jcenter.bintray.com/com/github/eschao/android-PageFlip/1.0.2/android-PageFlip-1.0.2.pom - file:/C:/Users/user_name/.m2/repository/com/github/eschao/android-PageFlip/1.0.2/android-PageFlip-1.0.2.pom - https://jitpack.io/com/github/eschao/android-PageFlip/1.0.2/android-PageFlip-1.0.2.pom Required by: project :app)

    opened by KyluAce 3
  • Navigating to a specific page

    Navigating to a specific page

    Is there a way, where i can directly navigate to page no. 'X' ? where x is a number within the range of the array defined. Or make auto swipe with a delay?

    opened by JoysonF 1
  • Any suggestions on how to handle front and back pages in doublePagesRender?

    Any suggestions on how to handle front and back pages in doublePagesRender?

    @eschao Many thanks for you work.

    I was wondering how to handle the cover and back pages in the DoublePageRender so they are treated like Single Pages. DO you have any insights or pointers that you could think of?

    Many thanks Simon

    opened by simon-rob 3
Releases(1.0.2)
Owner
eschao
eschao
💳 A quick and easy flip view through which you can create views with two sides like credit cards, poker cards etc.

The article on how this library was created is now published. You can read it on this link here. →. ?? EasyFlipView Built with ❤︎ by Wajahat Karim and

Wajahat Karim 1.3k Dec 14, 2022
💳 Bank Card View is a simple and elegant card view with Flip animation.

Visualização de cartão bancário ?? Bank Card View é uma visualização de cartão simples e elegante com animação Flip. Versões Selecione a língua : Engl

Geovani Amaral 10 Dec 12, 2022
💳 Bank Card View is a simple and elegant card view with Flip animation.

Visualização de cartão bancário ?? Bank Card View é uma visualização de cartão simples e elegante com animação Flip. Versões Selecione a língua : Engl

Geovani Amaral 9 Aug 26, 2022
Page Curl for Android

Page Curl for Android Overview The android-page-curl is a 2D View which simulates a page curl effect. Without OpenGL, only the android canvas has been

Moritz Wundke 377 Jan 3, 2023
Page Curl for Android

Page Curl for Android Overview The android-page-curl is a 2D View which simulates a page curl effect. Without OpenGL, only the android canvas has been

Moritz Wundke 376 Nov 20, 2022
ViewAnimator view with a lollipop style reveal effect

ViewRevealAnimator Widget ViewAnimator view with a lollipop style reveal effect. Regular animation can be set (just like the default ViewAnimator) for

Alessandro Crugnola 339 Jun 3, 2022
A program that converts an SGF-file to an animated GIF a la Hayauchi Super Igo style.

sgf2gif A program that converts an SGF-file to an animated GIF. The animated GIF is highly inspired by the classic game Hayauchi Super Igo for NES. Us

null 12 Jul 6, 2022
:rocket: Ultimate Android Reference - Your Road to Become a Better Android Developer

The goal of this project is to provide a hand-picked collection of Android libraries, tools, open-source projects, books, blogs, tutorials - you name

Aritra Roy 7.6k Jan 4, 2023
Deprecated in favour of https://developer.android.com/reference/android/support/v4/view/animation/PathInterpolatorCompat.html

Deprecated: use https://developer.android.com/reference/android/support/v4/view/animation/PathInterpolatorCompat.html instead. android-cubic-bezier-in

Codesoup 161 Jan 1, 2023
Android Country Picker is a Kotlin-first, flexible and powerful Android library that allows to integrate Country Picker with just a few lines.

1. Add dependency dependencies { implementation 'com.hbb20:android-country-picker:X.Y.Z' } For latest version, 2. Decide your use-case

Harsh B. Bhakta 65 Dec 6, 2022
Allows the easy creation of animated transition effects when the state of Android UI has changed

android-transition Android-Transition allows the easy creation of view transitions that reacts to user inputs. The library is designed to be general e

Kai 615 Nov 14, 2022
Actions for android animations. Inspired by libgdx scene2d actions.

Android Animations Actions Actions for android animations. Inspired by libgdx scene2d actions. The main goal of this project is making creating of com

dtx12 137 Nov 29, 2022
Android library for swipable gestures

Swipper Android Library for custom views to control brightness , volume and seek through swipable gestures . These views could easily replace the conv

Mobile Development Group 105 Dec 30, 2022
Android Library that lights items for tutorials or walk-throughs etc...

Spotlight Gradle dependencies { implementation 'com.github.takusemba:spotlight:x.x.x' } Usage val spotlight = Spotlight.Builder(this) .setTarg

TakuSemba 3.4k Jan 4, 2023
[] An Android library which allows developers to easily add animations to ListView items

DEPRECATED ListViewAnimations is deprecated in favor of new RecyclerView solutions. No new development will be taking place, but the existing versions

Niek Haarman 5.6k Dec 30, 2022
An amazing and convenient Android image slider.

Android Image Slider ![Gitter](https://badges.gitter.im/Join Chat.svg) This is an amazing image slider for the Android platform. I decided to open sou

代码家 5.6k Jan 7, 2023
Android ImageViews animated by Ken Burns Effect

KenBurnsView Android library that provides an extension to ImageView that creates an immersive experience by animating its drawable using the Ken Burn

Flávio Faria 2.7k Jan 2, 2023
You can easily access the top of the screen in Android. Like a iPhone 6 & 6 Plus.

Reachability on Android Easy access on top. Like a iPhone 6 & 6 Plus. demo apk Usage Add dependencies compile 'com.github.sakebook:Reachability:0.2.0@

sakebook 258 Nov 12, 2022
Android Animation Easing Functions. Let's make animation more real!

Android Easing Functions This project is originally from my another project, AndroidViewAnimation, which is an animation collection, to help you make

代码家 2.5k Jan 4, 2023