Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added module and BookFlipPageTransformer class
- Loading branch information
1 parent
c5a248d
commit bbab07e
Showing
10 changed files
with
195 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
|
||
|
||
|
||
defaultConfig { | ||
minSdkVersion 15 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
|
||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
...ger/src/androidTest/java/com/wajahatkarim3/easyflipviewpager/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.wajahatkarim3.easyflipviewpager; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.wajahatkarim3.easyflipviewpager.test", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.wajahatkarim3.easyflipviewpager"/> |
84 changes: 84 additions & 0 deletions
84
...pviewpager/src/main/java/com/wajahatkarim3/easyflipviewpager/BookFlipPageTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.wajahatkarim3.easyflipviewpager; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.support.v4.view.ViewPager; | ||
import android.view.View; | ||
|
||
/** | ||
* A book based page flip animation PageTransformer implementation for ViewPager | ||
* | ||
* Set the object of this transformer to any ViewPager object. | ||
* For example, myViewPager.setPageTransformer(true, new BookFlipPageTransformer()); | ||
* | ||
* @see <a href="http://github.com/wajahatkarim3/EasyFlipViewPager">EasyFlipViewPager</a> | ||
* | ||
* @author Wajahat Karim (http://wajahatkarim.com) | ||
*/ | ||
public class BookFlipPageTransformer implements ViewPager.PageTransformer { | ||
|
||
private final int LEFT = -1; | ||
private final int RIGHT = 1; | ||
private final int CENTER = 0; | ||
|
||
@Override | ||
public void transformPage(@NonNull View page, float position) { | ||
float percentage = 1 - Math.abs(position); | ||
// Don't move pages once they are on left or right | ||
if (position > CENTER && position <= RIGHT) | ||
{ | ||
// This is behind page | ||
page.setVisibility(View.VISIBLE); | ||
page.setTranslationX(-position * (page.getWidth())); | ||
page.setTranslationY(0); | ||
page.setRotation(0); | ||
} | ||
// Otherwise flip the current page | ||
else | ||
{ | ||
flipPage(page, position, percentage); | ||
} | ||
} | ||
|
||
private void flipPage(View page, float position, float percentage) | ||
{ | ||
// Flip this page | ||
page.setCameraDistance(-20000); | ||
setVisibility(page, position); | ||
setTranslation(page); | ||
setPivot(page, 0f, page.getHeight() * 0.5f); | ||
setRotation(page, position, percentage); | ||
} | ||
|
||
private void setPivot(View page, float pivotX, float pivotY) | ||
{ | ||
page.setPivotX(pivotX); | ||
page.setPivotY(pivotY); | ||
} | ||
|
||
private void setVisibility(View page, float position) { | ||
if (position < 0.5 && position > -0.5) { | ||
page.setVisibility(View.VISIBLE); | ||
} else { | ||
page.setVisibility(View.INVISIBLE); | ||
} | ||
} | ||
|
||
private void setTranslation(View page) { | ||
ViewPager viewPager = (ViewPager) page.getParent(); | ||
int scroll = viewPager.getScrollX() - page.getLeft(); | ||
page.setTranslationX(scroll); | ||
} | ||
|
||
private void setSize(View page, float position, float percentage) { | ||
page.setScaleX((position != 0 && position != 1) ? percentage : 1); | ||
page.setScaleY((position != 0 && position != 1) ? percentage : 1); | ||
} | ||
|
||
private void setRotation(View page, float position, float percentage) { | ||
if (position > 0) { | ||
page.setRotationY(-180 * (percentage + 1)); | ||
} else { | ||
page.setRotationY(180 * (percentage + 1)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">EasyFlipViewPager</string> | ||
</resources> |
17 changes: 17 additions & 0 deletions
17
easyflipviewpager/src/test/java/com/wajahatkarim3/easyflipviewpager/ExampleUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.wajahatkarim3.easyflipviewpager; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
public class ExampleUnitTest { | ||
@Test | ||
public void addition_isCorrect() { | ||
assertEquals(4, 2 + 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':app' | ||
include ':app', ':easyflipviewpager' |