├── .github ├── FUNDING.yml └── publish_to_maven_central.yml ├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml └── modules.xml ├── .travis.yml ├── Art ├── FlipOnceGif.gif └── demo.gif ├── EasyFlipView ├── .gitignore ├── android-release-aar.gradle ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── wajahatkarim3 │ │ └── easyflipview │ │ └── EasyFlipView.java │ └── res │ ├── animator │ ├── animation_horizontal_flip_in.xml │ ├── animation_horizontal_flip_out.xml │ ├── animation_horizontal_right_in.xml │ ├── animation_horizontal_right_out.xml │ ├── animation_vertical_flip_front_in.xml │ ├── animation_vertical_flip_in.xml │ ├── animation_vertical_flip_out.xml │ └── animation_vertical_front_out.xml │ └── values │ ├── attrs.xml │ └── integers.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── wajahatkarim3 │ │ └── easyflipview │ │ └── demo │ │ ├── FlipOnceExampleActivity.java │ │ ├── MainActivity.java │ │ ├── RecyclerViewFlipActivity.java │ │ ├── SampleAdapter.java │ │ ├── SimpleViewFlipActivity.java │ │ └── TestModel.java │ └── res │ ├── drawable │ ├── back_side_king.png │ ├── card_back.png │ ├── card_front.png │ └── front_side_design.png │ ├── layout │ ├── activity_flip_once_example.xml │ ├── activity_main.xml │ ├── activity_recyclerview_flip.xml │ ├── activity_simple_view.xml │ ├── flash_card_layout_back.xml │ ├── flash_card_layout_front.xml │ ├── item_flip_back.xml │ ├── item_flip_front.xml │ └── item_recyclerview.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── scripts ├── publish-module.gradle └── publish-root.gradle └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: ['https://www.paypal.me/WajahatKarim/5', 'https://www.paypal.me/WajahatKarim/20', 'https://www.paypal.me/WajahatKarim/50', 'https://www.paypal.me/WajahatKarim/100'] 2 | -------------------------------------------------------------------------------- /.github/publish_to_maven_central.yml: -------------------------------------------------------------------------------- 1 | name: Publish 2 | on: 3 | release: 4 | # We'll run this workflow when a new GitHub release is created 5 | types: [released] 6 | 7 | jobs: 8 | publish: 9 | name: Release build and publish 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Check out code 13 | uses: actions/checkout@v2 14 | 15 | - name: Set up JDK 11 16 | uses: actions/setup-java@v2 17 | with: 18 | distribution: adopt 19 | java-version: 11 20 | 21 | # Builds the release artifacts of the library 22 | - name: Release build 23 | run: ./gradlew :stream-chat-android-client:assembleRelease 24 | 25 | # Generates other artifacts (javadocJar is optional) 26 | - name: Source jar and dokka 27 | run: ./gradlew androidSourcesJar javadocJar 28 | 29 | # Runs upload, and then closes & releases the repository 30 | - name: Publish to MavenCentral 31 | run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository 32 | env: 33 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 34 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} 35 | SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} 36 | SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} 37 | SIGNING_KEY: ${{ secrets.SIGNING_KEY }} 38 | SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle/ 3 | local.properties 4 | .idea/ 5 | .DS_Store 6 | build/ 7 | captures/ 8 | .externalNativeBuild 9 | 10 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wajahatkarim3/EasyFlipView/a1a787c7f7c55d82d0ea33e76d4f9fa2ca4aee1e/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | xmlns:android 11 | 12 | ^$ 13 | 14 | 15 | 16 |
17 |
18 | 19 | 20 | 21 | xmlns:.* 22 | 23 | ^$ 24 | 25 | 26 | BY_NAME 27 | 28 |
29 |
30 | 31 | 32 | 33 | .*:id 34 | 35 | http://schemas.android.com/apk/res/android 36 | 37 | 38 | 39 |
40 |
41 | 42 | 43 | 44 | .*:name 45 | 46 | http://schemas.android.com/apk/res/android 47 | 48 | 49 | 50 |
51 |
52 | 53 | 54 | 55 | name 56 | 57 | ^$ 58 | 59 | 60 | 61 |
62 |
63 | 64 | 65 | 66 | style 67 | 68 | ^$ 69 | 70 | 71 | 72 |
73 |
74 | 75 | 76 | 77 | .* 78 | 79 | ^$ 80 | 81 | 82 | BY_NAME 83 | 84 |
85 |
86 | 87 | 88 | 89 | .* 90 | 91 | http://schemas.android.com/apk/res/android 92 | 93 | 94 | ANDROID_ATTRIBUTE_ORDER 95 | 96 |
97 |
98 | 99 | 100 | 101 | .* 102 | 103 | .* 104 | 105 | 106 | BY_NAME 107 | 108 |
109 |
110 |
111 |
112 |
113 |
-------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk8 3 | android: 4 | components: 5 | - tools 6 | - build-tools-26.0.1 7 | - android-26 8 | - extra-android-m2repository 9 | - extra-android-support 10 | licenses: 11 | - 'android-sdk-preview-license-52d11cd2' 12 | - 'android-sdk-license-.+' 13 | - 'google-gdk-license-.+' 14 | notifications: 15 | email: false 16 | before_install: 17 | - chmod +x gradlew 18 | - mkdir -p "$ANDROID_HOME/licenses" 19 | - echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" 20 | script: ./gradlew clean build 21 | -------------------------------------------------------------------------------- /Art/FlipOnceGif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wajahatkarim3/EasyFlipView/a1a787c7f7c55d82d0ea33e76d4f9fa2ca4aee1e/Art/FlipOnceGif.gif -------------------------------------------------------------------------------- /Art/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wajahatkarim3/EasyFlipView/a1a787c7f7c55d82d0ea33e76d4f9fa2ca4aee1e/Art/demo.gif -------------------------------------------------------------------------------- /EasyFlipView/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /EasyFlipView/android-release-aar.gradle: -------------------------------------------------------------------------------- 1 | // ./gradlew clean build generateRelease 2 | apply plugin: 'maven' 3 | 4 | def groupId = project.PUBLISH_GROUP_ID 5 | def artifactId = project.PUBLISH_ARTIFACT_ID 6 | def version = project.PUBLISH_VERSION 7 | 8 | def localReleaseDest = "${buildDir}/release/${version}" 9 | 10 | task androidJavadocs(type: Javadoc) { 11 | failOnError = false 12 | source = android.sourceSets.main.java.srcDirs 13 | ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" 14 | classpath += files(ext.androidJar) 15 | } 16 | 17 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { 18 | classifier = 'javadoc' 19 | from androidJavadocs.destinationDir 20 | } 21 | 22 | task androidSourcesJar(type: Jar) { 23 | classifier = 'sources' 24 | from android.sourceSets.main.java.srcDirs 25 | } 26 | 27 | uploadArchives { 28 | repositories.mavenDeployer { 29 | pom.groupId = groupId 30 | pom.artifactId = artifactId 31 | pom.version = version 32 | // Add other pom properties here if you want (developer details / licenses) 33 | repository(url: "file://${localReleaseDest}") 34 | } 35 | } 36 | 37 | task zipRelease(type: Zip) { 38 | from localReleaseDest 39 | destinationDir buildDir 40 | archiveName "release-${version}.zip" 41 | } 42 | 43 | task generateRelease { 44 | doLast { 45 | println "Release ${version} can be found at ${localReleaseDest}/" 46 | println "Release ${version} zipped can be found ${buildDir}/release-${version}.zip" 47 | } 48 | } 49 | 50 | generateRelease.dependsOn(uploadArchives) 51 | generateRelease.dependsOn(zipRelease) 52 | 53 | 54 | artifacts { 55 | archives androidSourcesJar 56 | archives androidJavadocsJar 57 | } 58 | -------------------------------------------------------------------------------- /EasyFlipView/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | ext { 4 | PUBLISH_GROUP_ID = 'com.wajahatkarim' 5 | PUBLISH_ARTIFACT_ID = 'EasyFlipView' 6 | PUBLISH_VERSION = '3.0.3' 7 | PUBLISH_DESCRIPTION = 'A quick and easy flip view through which you can create views with two sides like credit cards, poker cards etc.' 8 | PUBLISH_URL = 'https://github.com/wajahatkarim3/EasyFlipView' 9 | PUBLISH_LICENSE_NAME = 'Apache License' 10 | PUBLISH_LICENSE_URL = 'https://github.com/wajahatkarim3/EasyFlipView/blob/master/LICENSE' 11 | PUBLISH_DEVELOPER_ID = 'wajahatkarim' 12 | PUBLISH_DEVELOPER_NAME = 'Wajahat Karim' 13 | PUBLISH_DEVELOPER_EMAIL = 'wajahatkarim3@mail.com' 14 | PUBLISH_SCM_CONNECTION = 'scm:git:github.com/wajahatkarim3/EasyFlipView.git' 15 | PUBLISH_SCM_DEVELOPER_CONNECTION = 'scm:git:ssh://github.com/wajahatkarim3/EasyFlipView.git' 16 | PUBLISH_SCM_URL = 'https://github.com/wajahatkarim3/EasyFlipView/tree/master' 17 | } 18 | 19 | android { 20 | compileSdkVersion 28 21 | 22 | defaultConfig { 23 | minSdkVersion 15 24 | targetSdkVersion 28 25 | versionCode 1 26 | versionName "1.0" 27 | 28 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 29 | 30 | } 31 | 32 | buildTypes { 33 | release { 34 | minifyEnabled false 35 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 36 | } 37 | } 38 | 39 | lintOptions { 40 | abortOnError false 41 | } 42 | } 43 | 44 | dependencies { 45 | implementation fileTree(dir: 'libs', include: ['*.jar']) 46 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { 47 | exclude group: 'com.android.support', module: 'support-annotations' 48 | }) 49 | implementation 'androidx.appcompat:appcompat:1.0.0' 50 | testImplementation 'junit:junit:4.12' 51 | } 52 | 53 | apply from: "${rootDir}/scripts/publish-module.gradle" -------------------------------------------------------------------------------- /EasyFlipView/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\SDK\adt-bundle-windows-x86_64-20140702\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/java/com/wajahatkarim3/easyflipview/EasyFlipView.java: -------------------------------------------------------------------------------- 1 | package com.wajahatkarim3.easyflipview; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorInflater; 5 | import android.animation.AnimatorSet; 6 | import android.content.Context; 7 | import android.content.res.TypedArray; 8 | import android.os.Handler; 9 | import android.text.TextUtils; 10 | import android.util.AttributeSet; 11 | import android.util.Log; 12 | import android.view.GestureDetector; 13 | import android.view.MotionEvent; 14 | import android.view.View; 15 | import android.view.ViewGroup; 16 | import android.widget.FrameLayout; 17 | 18 | import androidx.annotation.Nullable; 19 | import androidx.core.view.GestureDetectorCompat; 20 | 21 | 22 | /** 23 | * A quick and easy flip view through which you can create views with two sides like credit cards, 24 | * poker cards, flash cards etc. 25 | *

26 | * Add com.wajahatkarim3.easyflipview.EasyFlipView into your XML layouts with two direct children 27 | * views and you are done! 28 | * For more information, check http://github.com/wajahatkarim3/EasyFlipView 29 | * 30 | * @author Wajahat Karim (http://wajahatkarim.com) 31 | * @version 3.0.0 28/03/2019 32 | */ 33 | public class EasyFlipView extends FrameLayout { 34 | 35 | public static final String TAG = EasyFlipView.class.getSimpleName(); 36 | 37 | public static final int DEFAULT_FLIP_DURATION = 400; 38 | public static final int DEFAULT_AUTO_FLIP_BACK_TIME = 1000; 39 | private int animFlipHorizontalOutId = R.animator.animation_horizontal_flip_out; 40 | private int animFlipHorizontalInId = R.animator.animation_horizontal_flip_in; 41 | private int animFlipHorizontalRightOutId = R.animator.animation_horizontal_right_out; 42 | private int animFlipHorizontalRightInId = R.animator.animation_horizontal_right_in; 43 | private int animFlipVerticalOutId = R.animator.animation_vertical_flip_out; 44 | private int animFlipVerticalInId = R.animator.animation_vertical_flip_in; 45 | private int animFlipVerticalFrontOutId = R.animator.animation_vertical_front_out; 46 | private int animFlipVerticalFrontInId = R.animator.animation_vertical_flip_front_in; 47 | 48 | public enum FlipState { 49 | FRONT_SIDE, BACK_SIDE 50 | } 51 | 52 | private AnimatorSet mSetRightOut; 53 | private AnimatorSet mSetLeftIn; 54 | private AnimatorSet mSetTopOut; 55 | private AnimatorSet mSetBottomIn; 56 | private boolean mIsBackVisible = false; 57 | private View mCardFrontLayout; 58 | private View mCardBackLayout; 59 | private String flipType = "vertical"; 60 | private String flipTypeFrom = "right"; 61 | 62 | 63 | private boolean flipOnTouch; 64 | private int flipDuration; 65 | private boolean flipEnabled; 66 | private boolean flipOnceEnabled; 67 | private boolean autoFlipBack; 68 | private int autoFlipBackTime; 69 | 70 | private Context context; 71 | private float x1; 72 | private float y1; 73 | 74 | private FlipState mFlipState = FlipState.FRONT_SIDE; 75 | 76 | private OnFlipAnimationListener onFlipListener = null; 77 | 78 | private GestureDetectorCompat gestureDetector; 79 | 80 | public EasyFlipView(Context context) { 81 | super(context); 82 | this.context = context; 83 | init(context, null); 84 | } 85 | 86 | public EasyFlipView(Context context, AttributeSet attrs) { 87 | super(context, attrs); 88 | this.context = context; 89 | init(context, attrs); 90 | } 91 | 92 | private void init(Context context, AttributeSet attrs) { 93 | // Setting Default Values 94 | flipOnTouch = true; 95 | flipDuration = DEFAULT_FLIP_DURATION; 96 | flipEnabled = true; 97 | flipOnceEnabled = false; 98 | autoFlipBack = false; 99 | autoFlipBackTime = DEFAULT_AUTO_FLIP_BACK_TIME; 100 | 101 | // Check for the attributes 102 | if (attrs != null) { 103 | // Attribute initialization 104 | final TypedArray attrArray = 105 | context.obtainStyledAttributes(attrs, R.styleable.easy_flip_view, 0, 0); 106 | try { 107 | flipOnTouch = attrArray.getBoolean(R.styleable.easy_flip_view_flipOnTouch, true); 108 | flipDuration = attrArray.getInt(R.styleable.easy_flip_view_flipDuration, DEFAULT_FLIP_DURATION); 109 | flipEnabled = attrArray.getBoolean(R.styleable.easy_flip_view_flipEnabled, true); 110 | flipOnceEnabled = attrArray.getBoolean(R.styleable.easy_flip_view_flipOnceEnabled, false); 111 | autoFlipBack = attrArray.getBoolean(R.styleable.easy_flip_view_autoFlipBack, false); 112 | autoFlipBackTime = attrArray.getInt(R.styleable.easy_flip_view_autoFlipBackTime, DEFAULT_AUTO_FLIP_BACK_TIME); 113 | flipType = attrArray.getString(R.styleable.easy_flip_view_flipType); 114 | flipTypeFrom = attrArray.getString(R.styleable.easy_flip_view_flipFrom); 115 | 116 | if (TextUtils.isEmpty(flipType)) { 117 | flipType = "vertical"; 118 | } 119 | if (TextUtils.isEmpty(flipTypeFrom)) { 120 | flipTypeFrom = "left"; 121 | } 122 | //animFlipInId = attrArray.getResourceId(R.styleable.easy_flip_view_animFlipInId, R.animator.animation_horizontal_flip_in); 123 | //animFlipOutId = attrArray.getResourceId(R.styleable.easy_flip_view_animFlipOutId, R.animator.animation_horizontal_flip_out); 124 | } finally { 125 | attrArray.recycle(); 126 | } 127 | } 128 | 129 | loadAnimations(); 130 | } 131 | 132 | @Override 133 | protected void onFinishInflate() { 134 | super.onFinishInflate(); 135 | 136 | if (getChildCount() > 2) { 137 | throw new IllegalStateException("EasyFlipView can host only two direct children!"); 138 | } 139 | 140 | findViews(); 141 | changeCameraDistance(); 142 | setupInitializations(); 143 | initGestureDetector(); 144 | } 145 | 146 | @Override 147 | public void addView(View v, int pos, ViewGroup.LayoutParams params) { 148 | if (getChildCount() == 2) { 149 | throw new IllegalStateException("EasyFlipView can host only two direct children!"); 150 | } 151 | 152 | super.addView(v, pos, params); 153 | 154 | findViews(); 155 | changeCameraDistance(); 156 | } 157 | 158 | @Override 159 | public void removeView(View v) { 160 | super.removeView(v); 161 | 162 | findViews(); 163 | } 164 | 165 | @Override 166 | public void removeAllViewsInLayout() { 167 | super.removeAllViewsInLayout(); 168 | 169 | // Reset the state 170 | mFlipState = FlipState.FRONT_SIDE; 171 | 172 | findViews(); 173 | } 174 | 175 | private void findViews() { 176 | // Invalidation since we use this also on removeView 177 | mCardBackLayout = null; 178 | mCardFrontLayout = null; 179 | 180 | int childs = getChildCount(); 181 | if (childs < 1) { 182 | return; 183 | } 184 | 185 | if (childs < 2) { 186 | // Only invalidate flip state if we have a single child 187 | mFlipState = FlipState.FRONT_SIDE; 188 | 189 | mCardFrontLayout = getChildAt(0); 190 | } else if (childs == 2) { 191 | mCardFrontLayout = getChildAt(1); 192 | mCardBackLayout = getChildAt(0); 193 | } 194 | 195 | if (!isFlipOnTouch()) { 196 | mCardFrontLayout.setVisibility(VISIBLE); 197 | 198 | if (mCardBackLayout != null) { 199 | mCardBackLayout.setVisibility(GONE); 200 | } 201 | } 202 | } 203 | 204 | private void setupInitializations() 205 | { 206 | mCardBackLayout.setVisibility(View.GONE); 207 | } 208 | 209 | private void initGestureDetector() { 210 | gestureDetector = new GestureDetectorCompat(this.context, new SwipeDetector()); 211 | } 212 | 213 | private void loadAnimations() { 214 | if (flipType.equalsIgnoreCase("horizontal")) { 215 | 216 | if (flipTypeFrom.equalsIgnoreCase("left")) { 217 | mSetRightOut = 218 | (AnimatorSet) AnimatorInflater.loadAnimator(this.context, animFlipHorizontalOutId); 219 | mSetLeftIn = 220 | (AnimatorSet) AnimatorInflater.loadAnimator(this.context, animFlipHorizontalInId); 221 | } else { 222 | mSetRightOut = 223 | (AnimatorSet) AnimatorInflater.loadAnimator(this.context, animFlipHorizontalRightOutId); 224 | mSetLeftIn = 225 | (AnimatorSet) AnimatorInflater.loadAnimator(this.context, animFlipHorizontalRightInId); 226 | } 227 | 228 | 229 | if (mSetRightOut == null || mSetLeftIn == null) { 230 | throw new RuntimeException( 231 | "No Animations Found! Please set Flip in and Flip out animation Ids."); 232 | } 233 | 234 | mSetRightOut.removeAllListeners(); 235 | mSetRightOut.addListener(new Animator.AnimatorListener() { 236 | @Override 237 | public void onAnimationStart(Animator animator) { 238 | 239 | } 240 | 241 | @Override 242 | public void onAnimationEnd(Animator animator) { 243 | 244 | if (mFlipState == FlipState.FRONT_SIDE) { 245 | mCardBackLayout.setVisibility(GONE); 246 | mCardFrontLayout.setVisibility(VISIBLE); 247 | 248 | if (onFlipListener != null) 249 | onFlipListener.onViewFlipCompleted(EasyFlipView.this, FlipState.FRONT_SIDE); 250 | } else { 251 | mCardBackLayout.setVisibility(VISIBLE); 252 | mCardFrontLayout.setVisibility(GONE); 253 | 254 | if (onFlipListener != null) 255 | onFlipListener.onViewFlipCompleted(EasyFlipView.this, FlipState.BACK_SIDE); 256 | 257 | // Auto Flip Back 258 | if (autoFlipBack == true) 259 | { 260 | new Handler().postDelayed(new Runnable() { 261 | @Override 262 | public void run() { 263 | flipTheView(); 264 | } 265 | }, autoFlipBackTime); 266 | } 267 | } 268 | } 269 | 270 | @Override 271 | public void onAnimationCancel(Animator animator) { 272 | 273 | } 274 | 275 | @Override 276 | public void onAnimationRepeat(Animator animator) { 277 | 278 | } 279 | }); 280 | setFlipDuration(flipDuration); 281 | } else { 282 | 283 | if (!TextUtils.isEmpty(flipTypeFrom) && flipTypeFrom.equalsIgnoreCase("front")) { 284 | mSetTopOut = (AnimatorSet) AnimatorInflater.loadAnimator(this.context, animFlipVerticalFrontOutId); 285 | mSetBottomIn = 286 | (AnimatorSet) AnimatorInflater.loadAnimator(this.context, animFlipVerticalFrontInId); 287 | } else { 288 | mSetTopOut = (AnimatorSet) AnimatorInflater.loadAnimator(this.context, animFlipVerticalOutId); 289 | mSetBottomIn = 290 | (AnimatorSet) AnimatorInflater.loadAnimator(this.context, animFlipVerticalInId); 291 | } 292 | 293 | if (mSetTopOut == null || mSetBottomIn == null) { 294 | throw new RuntimeException( 295 | "No Animations Found! Please set Flip in and Flip out animation Ids."); 296 | } 297 | 298 | mSetTopOut.removeAllListeners(); 299 | mSetTopOut.addListener(new Animator.AnimatorListener() { 300 | @Override 301 | public void onAnimationStart(Animator animator) { 302 | 303 | } 304 | 305 | @Override 306 | public void onAnimationEnd(Animator animator) { 307 | 308 | if (mFlipState == FlipState.FRONT_SIDE) { 309 | mCardBackLayout.setVisibility(GONE); 310 | mCardFrontLayout.setVisibility(VISIBLE); 311 | 312 | if (onFlipListener != null) 313 | onFlipListener.onViewFlipCompleted(EasyFlipView.this, FlipState.FRONT_SIDE); 314 | } else { 315 | mCardBackLayout.setVisibility(VISIBLE); 316 | mCardFrontLayout.setVisibility(GONE); 317 | 318 | if (onFlipListener != null) 319 | onFlipListener.onViewFlipCompleted(EasyFlipView.this, FlipState.BACK_SIDE); 320 | 321 | // Auto Flip Back 322 | if (autoFlipBack == true) 323 | { 324 | new Handler().postDelayed(new Runnable() { 325 | @Override 326 | public void run() { 327 | flipTheView(); 328 | } 329 | }, autoFlipBackTime); 330 | } 331 | } 332 | } 333 | 334 | @Override 335 | public void onAnimationCancel(Animator animator) { 336 | 337 | } 338 | 339 | @Override 340 | public void onAnimationRepeat(Animator animator) { 341 | 342 | } 343 | }); 344 | setFlipDuration(flipDuration); 345 | } 346 | } 347 | 348 | private void changeCameraDistance() { 349 | int distance = 8000; 350 | float scale = getResources().getDisplayMetrics().density * distance; 351 | 352 | if (mCardFrontLayout != null) { 353 | mCardFrontLayout.setCameraDistance(scale); 354 | } 355 | if (mCardBackLayout != null) { 356 | mCardBackLayout.setCameraDistance(scale); 357 | } 358 | } 359 | 360 | /** 361 | * Play the animation of flipping and flip the view for one side! 362 | */ 363 | public void flipTheView() { 364 | if (!flipEnabled || getChildCount() < 2) return; 365 | 366 | if (flipOnceEnabled && mFlipState == FlipState.BACK_SIDE) 367 | return; 368 | 369 | if (flipType.equalsIgnoreCase("horizontal")) { 370 | if (mSetRightOut.isRunning() || mSetLeftIn.isRunning()) return; 371 | 372 | mCardBackLayout.setVisibility(VISIBLE); 373 | mCardFrontLayout.setVisibility(VISIBLE); 374 | 375 | if (mFlipState == FlipState.FRONT_SIDE) { 376 | // From front to back 377 | mSetRightOut.setTarget(mCardFrontLayout); 378 | mSetLeftIn.setTarget(mCardBackLayout); 379 | mSetRightOut.start(); 380 | mSetLeftIn.start(); 381 | mIsBackVisible = true; 382 | mFlipState = FlipState.BACK_SIDE; 383 | } else { 384 | // from back to front 385 | mSetRightOut.setTarget(mCardBackLayout); 386 | mSetLeftIn.setTarget(mCardFrontLayout); 387 | mSetRightOut.start(); 388 | mSetLeftIn.start(); 389 | mIsBackVisible = false; 390 | mFlipState = FlipState.FRONT_SIDE; 391 | } 392 | } else { 393 | if (mSetTopOut.isRunning() || mSetBottomIn.isRunning()) return; 394 | 395 | mCardBackLayout.setVisibility(VISIBLE); 396 | mCardFrontLayout.setVisibility(VISIBLE); 397 | 398 | if (mFlipState == FlipState.FRONT_SIDE) { 399 | // From front to back 400 | mSetTopOut.setTarget(mCardFrontLayout); 401 | mSetBottomIn.setTarget(mCardBackLayout); 402 | mSetTopOut.start(); 403 | mSetBottomIn.start(); 404 | mIsBackVisible = true; 405 | mFlipState = FlipState.BACK_SIDE; 406 | } else { 407 | // from back to front 408 | mSetTopOut.setTarget(mCardBackLayout); 409 | mSetBottomIn.setTarget(mCardFrontLayout); 410 | mSetTopOut.start(); 411 | mSetBottomIn.start(); 412 | mIsBackVisible = false; 413 | mFlipState = FlipState.FRONT_SIDE; 414 | } 415 | } 416 | } 417 | 418 | /** 419 | * Flip the view for one side with or without animation. 420 | * 421 | * @param withAnimation true means flip view with animation otherwise without animation. 422 | */ 423 | public void flipTheView(boolean withAnimation) { 424 | if (getChildCount() < 2) return; 425 | 426 | if (flipType.equalsIgnoreCase("horizontal")) { 427 | if (!withAnimation) { 428 | mSetLeftIn.setDuration(0); 429 | mSetRightOut.setDuration(0); 430 | boolean oldFlipEnabled = flipEnabled; 431 | flipEnabled = true; 432 | 433 | flipTheView(); 434 | 435 | mSetLeftIn.setDuration(flipDuration); 436 | mSetRightOut.setDuration(flipDuration); 437 | flipEnabled = oldFlipEnabled; 438 | } else { 439 | flipTheView(); 440 | } 441 | } else { 442 | if (!withAnimation) { 443 | mSetBottomIn.setDuration(0); 444 | mSetTopOut.setDuration(0); 445 | boolean oldFlipEnabled = flipEnabled; 446 | flipEnabled = true; 447 | 448 | flipTheView(); 449 | 450 | mSetBottomIn.setDuration(flipDuration); 451 | mSetTopOut.setDuration(flipDuration); 452 | flipEnabled = oldFlipEnabled; 453 | } else { 454 | flipTheView(); 455 | } 456 | } 457 | } 458 | 459 | @Override 460 | public boolean dispatchTouchEvent(MotionEvent ev) { 461 | try { 462 | return gestureDetector.onTouchEvent(ev) || super.dispatchTouchEvent(ev); 463 | } catch (Throwable throwable) { 464 | throw new IllegalStateException("Error in dispatchTouchEvent: ", throwable); 465 | } 466 | } 467 | 468 | @Override 469 | public boolean onTouchEvent(MotionEvent event) { 470 | if (isEnabled() && flipOnTouch) { 471 | return gestureDetector.onTouchEvent(event); 472 | } else { 473 | return super.onTouchEvent(event); 474 | } 475 | } 476 | 477 | /** 478 | * Whether view is set to flip on touch or not. 479 | * 480 | * @return true or false 481 | */ 482 | public boolean isFlipOnTouch() { 483 | return flipOnTouch; 484 | } 485 | 486 | /** 487 | * Set whether view should be flipped on touch or not! 488 | * 489 | * @param flipOnTouch value (true or false) 490 | */ 491 | public void setFlipOnTouch(boolean flipOnTouch) { 492 | this.flipOnTouch = flipOnTouch; 493 | } 494 | 495 | /** 496 | * Returns duration of flip in milliseconds! 497 | * 498 | * @return duration in milliseconds 499 | */ 500 | public int getFlipDuration() { 501 | return flipDuration; 502 | } 503 | 504 | /** 505 | * Sets the flip duration (in milliseconds) 506 | * 507 | * @param flipDuration duration in milliseconds 508 | */ 509 | public void setFlipDuration(int flipDuration) { 510 | this.flipDuration = flipDuration; 511 | if (flipType.equalsIgnoreCase("horizontal")) { 512 | //mSetRightOut.setDuration(flipDuration); 513 | mSetRightOut.getChildAnimations().get(0).setDuration(flipDuration); 514 | mSetRightOut.getChildAnimations().get(1).setStartDelay(flipDuration / 2); 515 | 516 | //mSetLeftIn.setDuration(flipDuration); 517 | mSetLeftIn.getChildAnimations().get(1).setDuration(flipDuration); 518 | mSetLeftIn.getChildAnimations().get(2).setStartDelay(flipDuration / 2); 519 | } else { 520 | mSetTopOut.getChildAnimations().get(0).setDuration(flipDuration); 521 | mSetTopOut.getChildAnimations().get(1).setStartDelay(flipDuration / 2); 522 | 523 | mSetBottomIn.getChildAnimations().get(1).setDuration(flipDuration); 524 | mSetBottomIn.getChildAnimations().get(2).setStartDelay(flipDuration / 2); 525 | } 526 | } 527 | 528 | /** 529 | * Returns whether view can be flipped only once! 530 | * 531 | * @return true or false 532 | */ 533 | public boolean isFlipOnceEnabled() { 534 | return flipOnceEnabled; 535 | } 536 | 537 | /** 538 | * Enable / Disable flip only once feature. 539 | * 540 | * @param flipOnceEnabled true or false 541 | */ 542 | public void setFlipOnceEnabled(boolean flipOnceEnabled) { 543 | this.flipOnceEnabled = flipOnceEnabled; 544 | } 545 | 546 | 547 | /** 548 | * Returns whether flip is enabled or not! 549 | * 550 | * @return true or false 551 | */ 552 | public boolean isFlipEnabled() { 553 | return flipEnabled; 554 | } 555 | 556 | /** 557 | * Enable / Disable flip view. 558 | * 559 | * @param flipEnabled true or false 560 | */ 561 | public void setFlipEnabled(boolean flipEnabled) { 562 | this.flipEnabled = flipEnabled; 563 | } 564 | 565 | /** 566 | * Returns which flip state is currently on of the flip view. 567 | * 568 | * @return current state of flip view 569 | */ 570 | public FlipState getCurrentFlipState() { 571 | return mFlipState; 572 | } 573 | 574 | /** 575 | * Returns true if the front side of flip view is visible. 576 | * 577 | * @return true if the front side of flip view is visible. 578 | */ 579 | public boolean isFrontSide() { 580 | return (mFlipState == FlipState.FRONT_SIDE); 581 | } 582 | 583 | /** 584 | * Returns true if the back side of flip view is visible. 585 | * 586 | * @return true if the back side of flip view is visible. 587 | */ 588 | public boolean isBackSide() { 589 | return (mFlipState == FlipState.BACK_SIDE); 590 | } 591 | 592 | public OnFlipAnimationListener getOnFlipListener() { 593 | return onFlipListener; 594 | } 595 | 596 | public void setOnFlipListener(OnFlipAnimationListener onFlipListener) { 597 | this.onFlipListener = onFlipListener; 598 | } 599 | 600 | /* 601 | public @AnimatorRes int getAnimFlipOutId() { 602 | return animFlipOutId; 603 | } 604 | 605 | public void setAnimFlipOutId(@AnimatorRes int animFlipOutId) { 606 | this.animFlipOutId = animFlipOutId; 607 | loadAnimations(); 608 | } 609 | 610 | public @AnimatorRes int getAnimFlipInId() { 611 | return animFlipInId; 612 | } 613 | 614 | public void setAnimFlipInId(@AnimatorRes int animFlipInId) { 615 | this.animFlipInId = animFlipInId; 616 | loadAnimations(); 617 | } 618 | */ 619 | 620 | /** 621 | * Returns true if the Flip Type of animation is Horizontal? 622 | */ 623 | public boolean isHorizontalType() { 624 | return flipType.equals("horizontal"); 625 | } 626 | 627 | /** 628 | * Returns true if the Flip Type of animation is Vertical? 629 | */ 630 | public boolean isVerticalType() { 631 | return flipType.equals("vertical"); 632 | } 633 | 634 | /** 635 | * Sets the Flip Type of animation to Horizontal 636 | */ 637 | public void setToHorizontalType() { 638 | flipType = "horizontal"; 639 | loadAnimations(); 640 | } 641 | 642 | /** 643 | * Sets the Flip Type of animation to Vertical 644 | */ 645 | public void setToVerticalType() { 646 | flipType = "vertical"; 647 | loadAnimations(); 648 | } 649 | 650 | /** 651 | * Sets the flip type from direction to right 652 | */ 653 | public void setFlipTypeFromRight() { 654 | if (flipType.equals("horizontal")) 655 | flipTypeFrom = "right"; 656 | else flipTypeFrom = "front"; 657 | loadAnimations(); 658 | } 659 | 660 | /** 661 | * Sets the flip type from direction to left 662 | */ 663 | public void setFlipTypeFromLeft() { 664 | if (flipType.equals("horizontal")) 665 | flipTypeFrom = "left"; 666 | else flipTypeFrom = "back"; 667 | loadAnimations(); 668 | } 669 | 670 | /** 671 | * Sets the flip type from direction to front 672 | */ 673 | public void setFlipTypeFromFront() { 674 | if (flipType.equals("vertical")) 675 | flipTypeFrom = "front"; 676 | else flipTypeFrom = "right"; 677 | loadAnimations(); 678 | } 679 | 680 | /** 681 | * Sets the flip type from direction to back 682 | */ 683 | public void setFlipTypeFromBack() { 684 | if (flipType.equals("vertical")) 685 | flipTypeFrom = "back"; 686 | else flipTypeFrom = "left"; 687 | loadAnimations(); 688 | } 689 | 690 | /** 691 | * Returns the flip type from direction. For horizontal, it will be either right or left and for vertical, it will be front or back. 692 | */ 693 | public String getFlipTypeFrom() { 694 | return flipTypeFrom; 695 | } 696 | 697 | /** 698 | * Returns true if Auto Flip Back is enabled 699 | */ 700 | public boolean isAutoFlipBack() { 701 | return autoFlipBack; 702 | } 703 | 704 | /** 705 | * Set if the card should be flipped back to original front side. 706 | * @param autoFlipBack true if card should be flipped back to froont side 707 | */ 708 | public void setAutoFlipBack(boolean autoFlipBack) { 709 | this.autoFlipBack = autoFlipBack; 710 | } 711 | 712 | /** 713 | * Return the time in milliseconds to auto flip back to original front side. 714 | * @return 715 | */ 716 | public int getAutoFlipBackTime() { 717 | return autoFlipBackTime; 718 | } 719 | 720 | /** 721 | * Set the time in milliseconds to auto flip back the view to the original front side 722 | * @param autoFlipBackTime The time in milliseconds 723 | */ 724 | public void setAutoFlipBackTime(int autoFlipBackTime) { 725 | this.autoFlipBackTime = autoFlipBackTime; 726 | } 727 | 728 | /** 729 | * The Flip Animation Listener for animations and flipping complete listeners 730 | */ 731 | public interface OnFlipAnimationListener { 732 | /** 733 | * Called when flip animation is completed. 734 | * 735 | * @param newCurrentSide After animation, the new side of the view. Either can be 736 | * FlipState.FRONT_SIDE or FlipState.BACK_SIDE 737 | */ 738 | void onViewFlipCompleted(EasyFlipView easyFlipView, FlipState newCurrentSide); 739 | } 740 | 741 | private class SwipeDetector extends GestureDetector.SimpleOnGestureListener { 742 | 743 | @Override 744 | public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 745 | return false; 746 | } 747 | 748 | @Override 749 | public boolean onSingleTapConfirmed(MotionEvent e) { 750 | if (isEnabled() && flipOnTouch) { 751 | flipTheView(); 752 | } 753 | return super.onSingleTapConfirmed(e); 754 | } 755 | 756 | @Override 757 | public boolean onDown(MotionEvent e) { 758 | if (isEnabled() && flipOnTouch) { 759 | return true; 760 | } 761 | return super.onDown(e); 762 | } 763 | } 764 | } 765 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/animator/animation_horizontal_flip_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 17 | 18 | 24 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/animator/animation_horizontal_flip_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 15 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/animator/animation_horizontal_right_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 15 | 21 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/animator/animation_horizontal_right_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 17 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/animator/animation_vertical_flip_front_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 16 | 17 | 23 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/animator/animation_vertical_flip_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 16 | 17 | 23 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/animator/animation_vertical_flip_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 15 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/animator/animation_vertical_front_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 15 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /EasyFlipView/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 500 4 | 250 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

New in the EasyFlipView  2 | The article on how this library was created is now published. You can read it on this link here. →. 3 |

4 | 5 | 6 | 💳 EasyFlipView 7 | ============ 8 | [![Codacy Badge](https://api.codacy.com/project/badge/Grade/b6f4c512c5cf4705a41a04fe101a6c6e)](https://www.codacy.com/app/wajahatkarim3/EasyFlipView?utm_source=github.com&utm_medium=referral&utm_content=wajahatkarim3/EasyFlipView&utm_campaign=badger) 9 | [![Build Status](https://travis-ci.org/wajahatkarim3/EasyFlipView.svg?branch=master)](https://travis-ci.org/wajahatkarim3/EasyFlipView) [ ![Download](https://api.bintray.com/packages/wajahatkarim3/EasyFlipView/com.wajahatkarim3.EasyFlipView/images/download.svg) ](https://bintray.com/wajahatkarim3/EasyFlipView/com.wajahatkarim3.EasyFlipView/_latestVersion) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-EasyFlipView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5051) [![API](https://img.shields.io/badge/API-15%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=15) [![](https://img.shields.io/badge/MaterialUp-EasyFlipView-yellowgreen.png)](https://material.uplabs.com/posts/easyflipview) [![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/wajahatkarim3) 10 | 11 |
12 | Built with ❤︎ by 13 | Wajahat Karim and 14 | 15 | contributors 16 | 17 |
18 |
19 | 20 | A quick and easy flip view through which you can create views with two sides like credit cards, poker cards etc. 21 | 22 | ![](https://github.com/wajahatkarim3/EasyFlipView/blob/master/Art/demo.gif) 23 | 24 | ✔️ Changelog 25 | ========= 26 | Changes exist in the [releases](https://github.com/wajahatkarim3/EasyFlipView/releases) tab. 27 | 28 | 💻 Installation 29 | ============ 30 | Add this in your app's `build.gradle` file: 31 | ```groovy 32 | dependencies { 33 | implementation 'com.wajahatkarim:EasyFlipView:3.0.3' 34 | } 35 | ``` 36 | 37 | New in the EasyFlipView From the version `3.0.0`, this library will only support Android X naming artifacts. If you want to use the `android.support` versions, then use `2.1.2` version. 38 | 39 | Or add EasyFlipView as a new dependency inside your pom.xml 40 | 41 | ```xml 42 | 43 | com.wajahatkarim 44 | EasyFlipView 45 | 3.0.3 46 | pom 47 | 48 | ``` 49 | ❔ Usage 50 | ===== 51 | 52 | XML 53 | --- 54 | EasyFlipView In XML layouts("Vertical") 55 | ```xml 56 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | ``` 76 | 77 | EasyFlipView In XML layouts("Horizontal") 78 | ```xml 79 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | ``` 98 | 99 | # 🎨 Customizations & Attributes 100 | All customizable attributes for EasyFlipView 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 133 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 |
Attribute NameDefault ValueDescription
app:flipOnTouch="true"trueWhether card should be flipped on touch or not.
app:flipDuration="400"400The duration of flip animation in milliseconds.
app:flipEnabled="true"trueIf this is set to false, then it won't flip ever in Single View and it has to be always false for RecyclerView
app:flipType="horizontal"verticalWhether card should flip in vertical or horizontal
app:flipType="horizontal"verticalWhether card should flip in vertical or horizontal
app:flipFrom="right" 132 | app:flipFrom="back"left 134 | frontWhether card should flip from left to right Or right to left(Horizontal type) or car should flip to front or back(Vertical type)
app:autoFlipBack="true"falseIf this is set to true, then he card will be flipped back to original front side after the time set in autoFlipBackTime.
app:autoFlipBackTime="1000"1000The time in milliseconds (ms), after the card will be flipped back to original front side.
148 | 149 | In Code (Java) 150 | ---- 151 | ```java 152 | // Flips the view with or without animation 153 | mYourFlipView.flipTheView(); 154 | mYourFlipView.flipTheView(false); 155 | 156 | // Sets and Gets the Flip Animation Duration in milliseconds (Default is 400 ms) 157 | mYourFlipView.setFlipDuration(1000); 158 | int dur = mYourFlipView.getFlipDuration(); 159 | 160 | // Sets and gets the flip enable status (Default is true) 161 | mYourFlipView.setFlipEnabled(false); 162 | boolean flipStatus = mYourFlipView.isFlipEnabled(); 163 | 164 | // Sets and gets the flip on touch status (Default is true) 165 | mYourFlipView.setFlipOntouch(false); 166 | boolean flipTouchStatus = mYourFlipView.isFlipOnTouch(); 167 | 168 | // Get current flip state in enum (FlipState.FRONT_SIDE or FlipState.BACK_SIDE) 169 | EasyFlipView.FlipState flipSide = mYourFlipView.getCurrentFlipState(); 170 | 171 | // Get whether front/back side of flip is visible or not. 172 | boolean frontVal = mYourFlipView.isFrontSide(); 173 | boolean backVal = mYourFlipView.isBackSide(); 174 | 175 | // Get/Set the FlipType to FlipType.Horizontal 176 | boolean isHorizontal = mYourFlipView.isHorizontalType(); 177 | mYourFlipView.setToHorizontalType(); 178 | 179 | // Get/Set the FlipType to FlipType.Vertical 180 | boolean isVertical = mYourFlipView.isVerticalType(); 181 | mYourFlipView.setToVerticalType(); 182 | 183 | // Get/Set if the auto flip back is enabled 184 | boolean isAutoFlipBackEnabled = mYourFlipView.isAutoFlipBack(); 185 | mYourFlipView.setAutoFlipBack(true); 186 | 187 | // Get/Set the time in milliseconds (ms) after the view is auto flip back to original front side 188 | int autoflipBackTimeInMilliseconds = mYourFlipView.getAutoFlipBackTime(); 189 | mYourFlipView.setAutoFlipBackTime(2000); 190 | 191 | // Sets the animation direction from left (horizontal) and back (vertical) 192 | easyFlipView.setFlipTypeFromLeft(); 193 | 194 | // Sets the animation direction from right (horizontal) and front (vertical) 195 | easyFlipView.setFlipTypeFromRight(); 196 | 197 | // Sets the animation direction from front (vertical) and right (horizontal) 198 | easyFlipView.setFlipTypeFromFront(); 199 | 200 | // Sets the animation direction from back (vertical) and left (horizontal) 201 | easyFlipView.setFlipTypeFromBack(); 202 | 203 | // Returns the flip type from direction. For horizontal, it will be either right or left and for vertical, it will be front or back. 204 | easyFlipView.getFlipTypeFrom(); 205 | 206 | ``` 207 | 208 | Flip Animation Listener 209 | --- 210 | ```java 211 | EasyFlipView easyFlipView = (EasyFlipView) findViewById(R.id.easyFlipView); 212 | easyFlipView.setOnFlipListener(new EasyFlipView.OnFlipAnimationListener() { 213 | @Override 214 | public void onViewFlipCompleted(EasyFlipView flipView, EasyFlipView.FlipState newCurrentSide) 215 | { 216 | 217 | // ... 218 | // Your code goes here 219 | // ... 220 | 221 | } 222 | }); 223 | ``` 224 | 225 | ❌ Known Issues 226 | ============= 227 | 228 | ## Clipping when rotation animation is running 229 | 230 | To avoid clipping of top/bottom while flipping the view, you can disable it through XML like this 231 | 232 | Add `android:clipChildren="false"` to the parent/root view of `EasyFlipView` component. And add `android:clipToPadding="false"` to the `EasyFlipView` itself. Special thanks to @ueen for this fix #64 233 | 234 | 235 | ## EasyFlipView in RecyclerViews 236 | The `EasyFlipView` doesn't flip when used in `RecyclerView`. This is because the `EasyFlipView` uses the `onTouch()` method to intercept the touch events and flip the view accordingly. One easier solution is to disable the `flipOnTouch` attribute in XML by this. 237 | ```xml 238 | app:flipOnTouch="false" 239 | ``` 240 | Now, your `RecyclerView` will scroll but the `EasyFlipView` will not flip or animate on touch etc. You will have to manually flip the view by calling the method `mYourFlipView.flipTheView()` inside the adapter or `ViewHolder` class of the `RecyclerView`. For example, 241 | ```java 242 | public class MyRecyclerViewAdapter extends RecyclerView.Adapter { 243 | 244 | private List mData; 245 | private LayoutInflater mInflater; 246 | private ItemClickListener mClickListener; 247 | 248 | // data is passed into the constructor 249 | MyRecyclerViewAdapter(Context context, List data) { 250 | this.mInflater = LayoutInflater.from(context); 251 | this.mData = data; 252 | } 253 | 254 | // inflates the row layout from xml when needed 255 | @Override 256 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 257 | View view = mInflater.inflate(R.layout.recyclerview_row, parent, false); 258 | return new ViewHolder(view); 259 | } 260 | 261 | // binds the data to the TextView in each row 262 | @Override 263 | public void onBindViewHolder(ViewHolder holder, int position) { 264 | String textData = (String) mData.get(position); 265 | holder.myTextView.setText(textData); 266 | } 267 | 268 | // total number of rows 269 | @Override 270 | public int getItemCount() { 271 | return mData.size(); 272 | } 273 | 274 | 275 | // stores and recycles views as they are scrolled off screen 276 | public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 277 | TextView myTextView; 278 | EasyFlipView myEasyFlipView; 279 | 280 | ViewHolder(View itemView) { 281 | super(itemView); 282 | myTextView = itemView.findViewById(R.id.tvAnimalName); 283 | myEasyFlipView = itemView.findViewById(R.id.myEasyFlipView); 284 | itemView.setOnClickListener(this); 285 | } 286 | 287 | @Override 288 | public void onClick(View view) { 289 | myEasyFlipView.flipTheView(); 290 | if (mClickListener != null) { 291 | mClickListener.onItemClick(view, getAdapterPosition()); 292 | } 293 | } 294 | } 295 | 296 | // convenience method for getting data at click position 297 | String getItem(int id) { 298 | return mData.get(id); 299 | } 300 | 301 | // allows clicks events to be caught 302 | void setClickListener(ItemClickListener itemClickListener) { 303 | this.mClickListener = itemClickListener; 304 | } 305 | 306 | // parent activity will implement this method to respond to click events 307 | public interface ItemClickListener { 308 | void onItemClick(View view, int position); 309 | } 310 | } 311 | ``` 312 | ___ 313 | 314 | The `EasyFlipView` has a strange behaviour when the back and front layouts are a `CardView`. To workaround it, wrap your `CardView` in a `FrameLayout` or other `ViewGroup`. 315 | 316 | 💰 Donations 317 | ============= 318 | 319 | This project needs you! If you would like to support this project's further development, the creator of this project or the continuous maintenance of this project, feel free to donate. Your donation is highly appreciated (and I love food, coffee and beer). Thank you! 320 | 321 | **PayPal** 322 | 323 | * **[Donate $5](https://www.paypal.me/WajahatKarim/5)**: Thank's for creating this project, here's a tea (or some juice) for you! 324 | * **[Donate $10](https://www.paypal.me/WajahatKarim/10)**: Wow, I am stunned. Let me take you to the movies! 325 | * **[Donate $15](https://www.paypal.me/WajahatKarim/15)**: I really appreciate your work, let's grab some lunch! 326 | * **[Donate $25](https://www.paypal.me/WajahatKarim/25)**: That's some awesome stuff you did right there, dinner is on me! 327 | * **[Donate $50](https://www.paypal.me/WajahatKarim/50)**: I really really want to support this project, great job! 328 | * **[Donate $100](https://www.paypal.me/WajahatKarim/100)**: You are the man! This project saved me hours (if not days) of struggle and hard work, simply awesome! 329 | * **[Donate $2799](https://www.paypal.me/WajahatKarim/2799)**: Go buddy, buy Macbook Pro for yourself! 330 | 331 | Of course, you can also choose what you want to donate, all donations are awesome! 332 | 333 | 👨 Developed By 334 | ============ 335 | ``` 336 | Wajahat Karim 337 | ``` 338 | - Website (http://wajahatkarim.com) 339 | - Twitter (http://twitter.com/wajahatkarim) 340 | - Medium (http://www.medium.com/@wajahatkarim3) 341 | - LinkedIn (http://www.linkedin.com/in/wajahatkarim) 342 | 343 | 💖 Special Thanks 344 | ========= 345 | - [**iGio90**](https://github.com/iGio90) for adding dynamic views support [Pull Request # 10](https://github.com/wajahatkarim3/EasyFlipView/pull/10) 346 | - [**Sachin Varma**](https://www.linkedin.com/in/sachin-varma-58b243118/) for adding vertical animations support [Pull Request # 12](https://github.com/wajahatkarim3/EasyFlipView/pull/12) 347 | - [**Sachin Varma**](https://www.linkedin.com/in/sachin-varma-58b243118/) for adding multi-dimension animations support [Pull Request # 23](https://github.com/wajahatkarim3/EasyFlipView/pull/23) 348 | - [**Sachin Varma**](https://www.linkedin.com/in/sachin-varma-58b243118/) for adding multi-dimension animations support [Pull Request # 23](https://github.com/wajahatkarim3/EasyFlipView/pull/23) 349 | - [**Daniel Luque**](https://github.com/DrankoLQ) for updating the `targetSdk` to 28 [Pull Request # 30](https://github.com/wajahatkarim3/EasyFlipView/pull/30) 350 | - [**Aditya Zope**](https://github.com/adzo261) for adding the feature to flip card only once. [Pull Request # 33](https://github.com/wajahatkarim3/EasyFlipView/pull/33) 351 | - [**Bruno Correia**](https://github.com/bffcorreia) for removing `` tag from `AndroidManifest.xml`. [Pull Request # 38](https://github.com/wajahatkarim3/EasyFlipView/pull/38) and fixing the card animation glitch issue [Pull Request # 39](https://github.com/wajahatkarim3/EasyFlipView/pull/39) 352 | 353 | 354 | # 👍 How to Contribute 355 | 1. Fork it 356 | 2. Create your feature branch (git checkout -b my-new-feature) 357 | 3. Commit your changes (git commit -am 'Add some feature') 358 | 4. Push to the branch (git push origin my-new-feature) 359 | 5. Create new Pull Request 360 | 361 | # 📃 License 362 | 363 | Copyright 2018 Wajahat Karim 364 | 365 | Licensed under the Apache License, Version 2.0 (the "License"); 366 | you may not use this file except in compliance with the License. 367 | You may obtain a copy of the License at 368 | 369 | http://www.apache.org/licenses/LICENSE-2.0 370 | 371 | Unless required by applicable law or agreed to in writing, software 372 | distributed under the License is distributed on an "AS IS" BASIS, 373 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 374 | See the License for the specific language governing permissions and 375 | limitations under the License. 376 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | 6 | defaultConfig { 7 | applicationId "com.wajahatkarim3.easyflipview.demo" 8 | minSdkVersion 15 9 | targetSdkVersion 28 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | lintOptions { 21 | abortOnError false 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(include: ['*.jar'], dir: 'libs') 27 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', { 28 | exclude group: 'com.android.support', module: 'support-annotations' 29 | }) 30 | implementation 'androidx.appcompat:appcompat:1.0.0' 31 | implementation 'com.google.android.material:material:1.0.0' 32 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 33 | implementation 'androidx.cardview:cardview:1.0.0' 34 | testImplementation 'junit:junit:4.12' 35 | 36 | implementation project(":EasyFlipView") 37 | } 38 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\SDK\adt-bundle-windows-x86_64-20140702\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/wajahatkarim3/easyflipview/demo/FlipOnceExampleActivity.java: -------------------------------------------------------------------------------- 1 | package com.wajahatkarim3.easyflipview.demo; 2 | 3 | import androidx.appcompat.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | 8 | import com.wajahatkarim3.easyflipview.EasyFlipView; 9 | 10 | public class FlipOnceExampleActivity extends AppCompatActivity 11 | { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) 15 | { 16 | super.onCreate(savedInstanceState); 17 | setContentView(R.layout.activity_flip_once_example); 18 | 19 | 20 | final EasyFlipView easyFlipView = (EasyFlipView) findViewById(R.id.cardFlipView); 21 | easyFlipView.setFlipDuration(1000); 22 | easyFlipView.setFlipEnabled(true); 23 | 24 | findViewById(R.id.king_front_side).setOnClickListener(new View.OnClickListener() { 25 | @Override 26 | public void onClick(View view) { 27 | Toast.makeText(FlipOnceExampleActivity.this, "Front Card", Toast.LENGTH_SHORT).show(); 28 | easyFlipView.flipTheView(); 29 | } 30 | }); 31 | 32 | findViewById(R.id.king_back_side).setOnClickListener(new View.OnClickListener() { 33 | @Override 34 | public void onClick(View view) { 35 | Toast.makeText(FlipOnceExampleActivity.this, "Back Card", Toast.LENGTH_SHORT).show(); 36 | easyFlipView.flipTheView(); 37 | } 38 | }); 39 | 40 | easyFlipView.setOnFlipListener(new EasyFlipView.OnFlipAnimationListener() { 41 | @Override 42 | public void onViewFlipCompleted(EasyFlipView easyFlipView, EasyFlipView.FlipState newCurrentSide) { 43 | Toast.makeText(FlipOnceExampleActivity.this, 44 | "Flipped once ! Ace revealed " + newCurrentSide, Toast.LENGTH_LONG).show(); 45 | } 46 | }); 47 | } 48 | } 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/wajahatkarim3/easyflipview/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.wajahatkarim3.easyflipview.demo; 2 | 3 | import android.content.Intent; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | 8 | public class MainActivity extends AppCompatActivity { 9 | 10 | @Override 11 | protected void onCreate(Bundle savedInstanceState) { 12 | super.onCreate(savedInstanceState); 13 | setContentView(R.layout.activity_main); 14 | 15 | findViewById(R.id.btSimpleView).setOnClickListener(new View.OnClickListener() { 16 | @Override 17 | public void onClick(View v) { 18 | startActivity(new Intent(MainActivity.this, SimpleViewFlipActivity.class)); 19 | } 20 | }); 21 | findViewById(R.id.btRecyclerView).setOnClickListener(new View.OnClickListener() { 22 | @Override 23 | public void onClick(View v) { 24 | startActivity(new Intent(MainActivity.this, RecyclerViewFlipActivity.class)); 25 | } 26 | }); 27 | findViewById(R.id.btFlipOnceEg).setOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View v) { 30 | startActivity(new Intent(MainActivity.this, FlipOnceExampleActivity.class)); 31 | } 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/wajahatkarim3/easyflipview/demo/RecyclerViewFlipActivity.java: -------------------------------------------------------------------------------- 1 | package com.wajahatkarim3.easyflipview.demo; 2 | 3 | import android.os.Bundle; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import androidx.recyclerview.widget.GridLayoutManager; 6 | import androidx.recyclerview.widget.RecyclerView; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by Sachin Varma on 18-12-2017. 12 | */ 13 | 14 | public class RecyclerViewFlipActivity extends AppCompatActivity { 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_recyclerview_flip); 20 | List list = new ArrayList<>(); 21 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); 22 | recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); 23 | for (int i = 0; i < 20; i++) { 24 | TestModel model = new TestModel(); 25 | model.isFlipped = false; 26 | list.add(model); 27 | } 28 | recyclerView.setAdapter(new SampleAdapter(list)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/wajahatkarim3/easyflipview/demo/SampleAdapter.java: -------------------------------------------------------------------------------- 1 | package com.wajahatkarim3.easyflipview.demo; 2 | 3 | import androidx.recyclerview.widget.RecyclerView; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import com.wajahatkarim3.easyflipview.EasyFlipView; 8 | import java.util.List; 9 | 10 | public class SampleAdapter extends RecyclerView.Adapter { 11 | 12 | private List list; 13 | 14 | class MyViewHolder extends RecyclerView.ViewHolder { 15 | EasyFlipView flipView; 16 | 17 | MyViewHolder(View view) { 18 | super(view); 19 | flipView = (EasyFlipView) view.findViewById(R.id.flipView); 20 | } 21 | } 22 | 23 | SampleAdapter( 24 | List list 25 | ) { 26 | this.list = list; 27 | } 28 | 29 | @Override 30 | public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 31 | View itemView = 32 | LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recyclerview, parent, false); 33 | 34 | return new MyViewHolder(itemView); 35 | } 36 | 37 | @Override 38 | public void onBindViewHolder(final MyViewHolder holder, final int position) { 39 | 40 | if (holder.flipView.getCurrentFlipState() == EasyFlipView.FlipState.FRONT_SIDE && list.get( 41 | position).isFlipped) { 42 | holder.flipView.setFlipDuration(0); 43 | holder.flipView.flipTheView(); 44 | } else if (holder.flipView.getCurrentFlipState() == EasyFlipView.FlipState.BACK_SIDE 45 | && !list.get(position).isFlipped) { 46 | holder.flipView.setFlipDuration(0); 47 | holder.flipView.flipTheView(); 48 | } 49 | holder.flipView.setOnClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View v) { 52 | if (list.get(position).isFlipped) { 53 | list.get(position).isFlipped = false; 54 | } else { 55 | list.get(position).isFlipped = true; 56 | } 57 | holder.flipView.setFlipDuration(700); 58 | holder.flipView.flipTheView(); 59 | } 60 | }); 61 | } 62 | 63 | @Override 64 | public int getItemCount() { 65 | return list.size(); 66 | } 67 | } 68 | 69 | 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/wajahatkarim3/easyflipview/demo/SimpleViewFlipActivity.java: -------------------------------------------------------------------------------- 1 | package com.wajahatkarim3.easyflipview.demo; 2 | 3 | import android.os.Bundle; 4 | import androidx.appcompat.app.AppCompatActivity; 5 | import android.view.View; 6 | import android.widget.Toast; 7 | import com.wajahatkarim3.easyflipview.EasyFlipView; 8 | 9 | /** 10 | * Created by Sachin Varma on 18-12-2017. 11 | */ 12 | 13 | public class SimpleViewFlipActivity extends AppCompatActivity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_simple_view); 19 | 20 | final EasyFlipView easyFlipView = (EasyFlipView) findViewById(R.id.easyFlipView); 21 | easyFlipView.setFlipDuration(400); 22 | easyFlipView.setFlipEnabled(true); 23 | 24 | findViewById(R.id.imgFrontCard).setOnClickListener(new View.OnClickListener() { 25 | @Override 26 | public void onClick(View view) { 27 | Toast.makeText(SimpleViewFlipActivity.this, "Front Card", Toast.LENGTH_SHORT).show(); 28 | easyFlipView.flipTheView(); 29 | } 30 | }); 31 | 32 | findViewById(R.id.imgBackCard).setOnClickListener(new View.OnClickListener() { 33 | @Override 34 | public void onClick(View view) { 35 | Toast.makeText(SimpleViewFlipActivity.this, "Back Card", Toast.LENGTH_SHORT).show(); 36 | easyFlipView.flipTheView(); 37 | } 38 | }); 39 | 40 | easyFlipView.setOnFlipListener(new EasyFlipView.OnFlipAnimationListener() { 41 | @Override 42 | public void onViewFlipCompleted(EasyFlipView easyFlipView, EasyFlipView.FlipState newCurrentSide) { 43 | Toast.makeText(SimpleViewFlipActivity.this, 44 | "Flip Completed! New Side is: " + newCurrentSide, Toast.LENGTH_LONG).show(); 45 | } 46 | }); 47 | 48 | 49 | 50 | final EasyFlipView easyFlipView2 = (EasyFlipView) findViewById(R.id.easyFlipView2); 51 | easyFlipView2.setFlipDuration(400); 52 | easyFlipView2.setToHorizontalType(); 53 | easyFlipView2.setFlipTypeFromLeft(); 54 | 55 | 56 | } 57 | } -------------------------------------------------------------------------------- /app/src/main/java/com/wajahatkarim3/easyflipview/demo/TestModel.java: -------------------------------------------------------------------------------- 1 | package com.wajahatkarim3.easyflipview.demo; 2 | 3 | class TestModel { 4 | boolean isFlipped; 5 | } 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/back_side_king.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wajahatkarim3/EasyFlipView/a1a787c7f7c55d82d0ea33e76d4f9fa2ca4aee1e/app/src/main/res/drawable/back_side_king.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/card_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wajahatkarim3/EasyFlipView/a1a787c7f7c55d82d0ea33e76d4f9fa2ca4aee1e/app/src/main/res/drawable/card_back.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/card_front.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wajahatkarim3/EasyFlipView/a1a787c7f7c55d82d0ea33e76d4f9fa2ca4aee1e/app/src/main/res/drawable/card_front.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/front_side_design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wajahatkarim3/EasyFlipView/a1a787c7f7c55d82d0ea33e76d4f9fa2ca4aee1e/app/src/main/res/drawable/front_side_design.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_flip_once_example.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 23 | 24 | 32 | 33 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 |