├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── vcs.xml ├── runConfigurations.xml ├── modules.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── app ├── .gitignore ├── app-release.apk ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable │ │ │ │ ├── icon_github.png │ │ │ │ ├── disc_auxili_dolc.jpg │ │ │ │ ├── disc_raiz_asi_en.png │ │ │ │ ├── disc_bajoqueta_apel.jpg │ │ │ │ ├── disc_diluvi_motius.jpg │ │ │ │ ├── disc_zoo_tempestes.jpg │ │ │ │ ├── disc_gossa_sorda_sao.jpg │ │ │ │ ├── disc_aspencat_essencia.jpg │ │ │ │ ├── side_nav_bar.xml │ │ │ │ ├── ic_delete.xml │ │ │ │ └── ic_action.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 │ │ │ ├── layout │ │ │ │ ├── content_main.xml │ │ │ │ ├── fragment_vertical_swipe.xml │ │ │ │ ├── fragment_swipe.xml │ │ │ │ ├── item_swing_swipe.xml │ │ │ │ ├── item_right_swipe.xml │ │ │ │ ├── item_half_right_swipe.xml │ │ │ │ ├── item_half_right_drag_swipe.xml │ │ │ │ ├── item_half_right_drag_friction_swipe.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── nav_header_main.xml │ │ │ │ ├── app_bar_main.xml │ │ │ │ ├── item_two_step_right_swipe.xml │ │ │ │ ├── item_both_side_swipe.xml │ │ │ │ ├── item_foreground_swipe.xml │ │ │ │ └── fragment_vertical_swipe_page.xml │ │ │ ├── drawable-v21 │ │ │ │ ├── ic_menu_send.xml │ │ │ │ ├── ic_menu_slideshow.xml │ │ │ │ ├── ic_menu_gallery.xml │ │ │ │ ├── ic_menu_manage.xml │ │ │ │ ├── ic_menu_camera.xml │ │ │ │ └── ic_menu_share.xml │ │ │ ├── values-v21 │ │ │ │ └── styles.xml │ │ │ ├── menu │ │ │ │ ├── main.xml │ │ │ │ └── activity_main_drawer.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── values │ │ │ │ ├── colors.xml │ │ │ │ ├── drawables.xml │ │ │ │ ├── dimens.xml │ │ │ │ ├── strings.xml │ │ │ │ └── styles.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── apps │ │ │ └── xenione │ │ │ └── com │ │ │ └── swipelayout │ │ │ └── example │ │ │ ├── swipe │ │ │ ├── HalfRightCoordinatorLayout.java │ │ │ ├── BothSideCoordinatorLayout.java │ │ │ ├── HalfRightDragCoordinatorLayout.java │ │ │ ├── HalfRightDragFrictionCoordinatorLayout.java │ │ │ ├── RightCoordinatorLayout.java │ │ │ ├── TwoStepRightCoordinatorLayout.java │ │ │ ├── VerticalCoordinatorLayout.java │ │ │ └── SwingCoordinatorLayout.java │ │ │ ├── fragment │ │ │ ├── HalfRightDragSwipeFragment.java │ │ │ ├── HalfRightDragFrictionSwipeFragment.java │ │ │ ├── BothSideSwipeFragment.java │ │ │ ├── TwoStepRightSwipeFragment.java │ │ │ ├── SwingSwipeFragment.java │ │ │ ├── RightSwipeFragment.java │ │ │ ├── HalfRightSwipeFragment.java │ │ │ └── VerticalSwipeFragment.java │ │ │ ├── data │ │ │ └── Album.java │ │ │ ├── adapter │ │ │ ├── HalfRightDragFrictionSwipeAdapter.java │ │ │ ├── HalfRightDragSwipeAdapter.java │ │ │ ├── SwingSwipeAdapter.java │ │ │ ├── BothSideSwipeAdapter.java │ │ │ ├── TwoStepRightSwipeAdapter.java │ │ │ ├── RightSwipeAdapter.java │ │ │ └── HalfRightSwipeAdapter.java │ │ │ └── MainActivity.java │ ├── test │ │ └── java │ │ │ └── apps │ │ │ └── xenione │ │ │ └── com │ │ │ └── swipelayout │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── apps │ │ └── xenione │ │ └── com │ │ └── swipelayout │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── swipemaker ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ ├── strings.xml │ │ │ │ └── ids.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── xenione │ │ │ │ └── libs │ │ │ │ └── swipemaker │ │ │ │ ├── orientation │ │ │ │ ├── OrientationStrategyFactory.java │ │ │ │ ├── HorizontalOrientationStrategy.java │ │ │ │ ├── VerticalOrientationStrategy.java │ │ │ │ └── OrientationStrategy.java │ │ │ │ ├── ScrollerHelper.java │ │ │ │ ├── AbsCoordinatorLayout.java │ │ │ │ ├── Position.java │ │ │ │ ├── SwipeLayout.java │ │ │ │ └── Anchors.java │ │ └── AndroidManifest.xml │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── xenione │ │ │ └── libs │ │ │ └── swipemaker │ │ │ └── ApplicationTest.java │ └── test │ │ └── java │ │ └── com │ │ └── xenione │ │ └── libs │ │ └── swipemaker │ │ ├── ScrollerHelperTest.java │ │ ├── AnchorsTest.java │ │ ├── SwipeLayoutTest.java │ │ ├── VerticalOrientationStrategyTest.java │ │ └── HorizontalOrientationStrategyTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── .travis.yml ├── gradle.properties ├── gradlew.bat ├── gradlew ├── README.md └── LICENSE /.idea/.name: -------------------------------------------------------------------------------- 1 | SwipeLayout -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /swipemaker/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':swipemaker' 2 | -------------------------------------------------------------------------------- /app/app-release.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/app-release.apk -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /swipemaker/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Swipe Maker 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/icon_github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/drawable/icon_github.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | /.idea/* 7 | .DS_Store 8 | /build 9 | /captures -------------------------------------------------------------------------------- /app/src/main/res/drawable/disc_auxili_dolc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/drawable/disc_auxili_dolc.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/disc_raiz_asi_en.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/drawable/disc_raiz_asi_en.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/disc_bajoqueta_apel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/drawable/disc_bajoqueta_apel.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/disc_diluvi_motius.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/drawable/disc_diluvi_motius.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/disc_zoo_tempestes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/drawable/disc_zoo_tempestes.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/disc_gossa_sorda_sao.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/drawable/disc_gossa_sorda_sao.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/disc_aspencat_essencia.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xenione/swipe-maker/HEAD/app/src/main/res/drawable/disc_aspencat_essencia.jpg -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /swipemaker/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Mar 08 19:59:05 CET 2017 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip -------------------------------------------------------------------------------- /app/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_vertical_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | -------------------------------------------------------------------------------- /swipemaker/src/main/java/com/xenione/libs/swipemaker/orientation/OrientationStrategyFactory.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker.orientation; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Created by Eugeni on 28/09/2016. 7 | */ 8 | public interface OrientationStrategyFactory { 9 | OrientationStrategy make(View view); 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/side_nav_bar.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | -------------------------------------------------------------------------------- /swipemaker/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_delete.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_send.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #000000 4 | #000000 5 | #FF4081 6 | #40FFBE 7 | 8 | @color/colorAccent 9 | @color/colorAccent 10 | 11 | -------------------------------------------------------------------------------- /app/src/test/java/apps/xenione/com/swipelayout/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 9 | */ 10 | public class ExampleUnitTest { 11 | @Test 12 | public void addition_isCorrect() throws Exception { 13 | assertEquals(4, 2 + 2); 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/apps/xenione/com/swipelayout/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /swipemaker/src/androidTest/java/com/xenione/libs/swipemaker/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_slideshow.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_gallery.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_manage.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_action.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_swing_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/drawables.xml: -------------------------------------------------------------------------------- 1 | 2 | @android:drawable/ic_menu_camera 3 | @android:drawable/ic_menu_gallery 4 | @android:drawable/ic_menu_slideshow 5 | @android:drawable/ic_menu_manage 6 | @android:drawable/ic_menu_share 7 | @android:drawable/ic_menu_send 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_right_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_camera.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 160dp 5 | 6 | 16dp 7 | 16dp 8 | 16dp 9 | 250dp 10 | 13dp 11 | 75dp 12 | 25dp 13 | 14 | -------------------------------------------------------------------------------- /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 C:\Users\Eugeni\AppData\Local\Android\sdk1/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 | -------------------------------------------------------------------------------- /swipemaker/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 C:\Users\Eugeni\AppData\Local\Android\sdk1/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 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: android 2 | jdk: oraclejdk8 3 | sudo: false 4 | 5 | android: 6 | components: 7 | - tools 8 | - build-tools-25.0.2 9 | - android-25 10 | - android-22 11 | - platform-tools 12 | - extra-android-m2repository 13 | - sys-img-armeabi-v7a-android-22 14 | 15 | before_script: 16 | # Create and start emulator 17 | - echo no | android create avd --force -n test -t android-22 --abi armeabi-v7a 18 | - emulator -avd test -no-skin -no-audio -no-window & 19 | - android-wait-for-emulator 20 | - adb shell input keyevent 82 & 21 | 22 | script: 23 | - ./gradlew connectedAndroidTest 24 | - ./gradlew testDebugUnitTest 25 | - ./gradlew createDebugCoverageReport 26 | - ./gradlew clean jacocoTestReport coveralls 27 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_share.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_half_right_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_half_right_drag_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_half_right_drag_friction_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | android.enableJetifier=true 20 | android.useAndroidX=true -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SwipeLayout 3 | 4 | Open navigation drawer 5 | Close navigation drawer 6 | 7 | Settings 8 | 9 | Share Easy Swipe Maker 10 | 11 | Action is clicked 12 | Delete is clicked 13 | 14 | La Gossa Sorda és un grup musical de Pego (Marina Alta, País Valencià). La seua música té ritmes de Ska, Rock, Reggae i Punk amb la utilització de molts ritmes mediterranis i altres influències. Fan servir instruments com la dolçaina. Les seves lletres en valencià ataquen els fonaments del sistema, la injustícia de l\'ordre social i mundial actual, la lluita per salvar el País Valencià, el consumisme, la corrupció política, la crisi econòmica i l\'integrisme religiós.]]> 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.2" 6 | 7 | defaultConfig { 8 | applicationId "apps.xenione.com.swipelayout" 9 | minSdkVersion 15 10 | targetSdkVersion 29 11 | versionCode 111 12 | versionName "1.1.1" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | 21 | android { 22 | compileOptions { 23 | sourceCompatibility 1.8 24 | targetCompatibility 1.8 25 | } 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(include: ['*.jar'], dir: 'libs') 31 | testImplementation 'junit:junit:4.12' 32 | implementation 'androidx.appcompat:appcompat:1.2.0' 33 | implementation 'com.google.android.material:material:1.2.1' 34 | implementation 'androidx.recyclerview:recyclerview:1.1.0' 35 | implementation 'com.squareup.picasso:picasso:2.5.2' 36 | implementation project(':swipemaker') 37 | } 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/nav_header_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 20 | 21 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/app_bar_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 21 | 22 | 23 | 24 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_two_step_right_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 20 | 21 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /swipemaker/src/main/java/com/xenione/libs/swipemaker/ScrollerHelper.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | 3 | import android.widget.OverScroller; 4 | 5 | /** 6 | * Created by Eugeni on 10/04/2016. 7 | */ 8 | public class ScrollerHelper { 9 | 10 | private OverScroller mScroller; 11 | 12 | public ScrollerHelper(OverScroller overScroller) { 13 | mScroller = overScroller; 14 | } 15 | 16 | public boolean startScroll(int start, int end) { 17 | if (start == end) { 18 | return false; 19 | } 20 | int delta = end - start; 21 | mScroller.startScroll(start, 0, delta, 0); 22 | return true; 23 | } 24 | 25 | public boolean startScroll(int start, int end, int duration) { 26 | if (start == end) { 27 | return false; 28 | } 29 | int delta = end - start; 30 | mScroller.startScroll(start, 0, delta, 0, duration); 31 | return true; 32 | } 33 | 34 | public void finish() { 35 | if (!mScroller.isFinished()) { 36 | mScroller.forceFinished(true); 37 | } 38 | } 39 | 40 | public boolean isFinished() { 41 | return mScroller.isFinished(); 42 | } 43 | 44 | public boolean computeScrollOffset() { 45 | return mScroller.computeScrollOffset(); 46 | } 47 | 48 | public int getCurrX() { 49 | return mScroller.getCurrX(); 50 | } 51 | } 52 | 53 | 54 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 | 26 | 27 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_both_side_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | 22 | 23 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/swipe/HalfRightCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.swipe; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import com.xenione.libs.swipemaker.AbsCoordinatorLayout; 9 | import com.xenione.libs.swipemaker.SwipeLayout; 10 | import apps.xenione.com.swipelayout.R; 11 | 12 | /** 13 | * Created on 06/04/16. 14 | */ 15 | public class HalfRightCoordinatorLayout extends AbsCoordinatorLayout { 16 | 17 | private View mBackgroundView; 18 | private SwipeLayout mForegroundView; 19 | 20 | public HalfRightCoordinatorLayout(Context context) { 21 | super(context); 22 | } 23 | 24 | public HalfRightCoordinatorLayout(Context context, AttributeSet attrs) { 25 | super(context, attrs); 26 | } 27 | 28 | public HalfRightCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 29 | super(context, attrs, defStyleAttr); 30 | } 31 | 32 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 33 | public HalfRightCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 34 | super(context, attrs, defStyleAttr, defStyleRes); 35 | } 36 | 37 | @Override 38 | public void doInitialViewsLocation() { 39 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 40 | mBackgroundView = findViewById(R.id.backgroundView); 41 | mForegroundView.anchor(mBackgroundView.getRight(), mBackgroundView.getLeft()); 42 | } 43 | 44 | @Override 45 | public void onTranslateChange(float global, int index, float relative) { 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/swipe/BothSideCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.swipe; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | 9 | import com.xenione.libs.swipemaker.AbsCoordinatorLayout; 10 | import com.xenione.libs.swipemaker.SwipeLayout; 11 | 12 | import apps.xenione.com.swipelayout.R; 13 | 14 | /** 15 | * Created on 06/04/16. 16 | */ 17 | public class BothSideCoordinatorLayout extends AbsCoordinatorLayout { 18 | 19 | private View mDelete; 20 | private View mAction; 21 | private SwipeLayout mForegroundView; 22 | 23 | public BothSideCoordinatorLayout(Context context) { 24 | super(context); 25 | } 26 | 27 | public BothSideCoordinatorLayout(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | public BothSideCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 32 | super(context, attrs, defStyleAttr); 33 | } 34 | 35 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 36 | public BothSideCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 37 | super(context, attrs, defStyleAttr, defStyleRes); 38 | } 39 | 40 | @Override 41 | public void doInitialViewsLocation() { 42 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 43 | mDelete = findViewById(R.id.delete); 44 | mAction = findViewById(R.id.action); 45 | mForegroundView.anchor(-mAction.getWidth(), 0, mDelete.getRight()); 46 | } 47 | 48 | @Override 49 | public void onTranslateChange(float global, int index, float relative) { 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_foreground_swipe.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 18 | 19 | 28 | 29 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/swipe/HalfRightDragCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.swipe; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | 9 | import com.xenione.libs.swipemaker.AbsCoordinatorLayout; 10 | import com.xenione.libs.swipemaker.SwipeLayout; 11 | 12 | import apps.xenione.com.swipelayout.R; 13 | 14 | 15 | /** 16 | * Created on 06/04/16. 17 | */ 18 | public class HalfRightDragCoordinatorLayout extends AbsCoordinatorLayout { 19 | 20 | private View mBackgroundView; 21 | private SwipeLayout mForegroundView; 22 | 23 | public HalfRightDragCoordinatorLayout(Context context) { 24 | super(context); 25 | } 26 | 27 | public HalfRightDragCoordinatorLayout(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | public HalfRightDragCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 32 | super(context, attrs, defStyleAttr); 33 | } 34 | 35 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 36 | public HalfRightDragCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 37 | super(context, attrs, defStyleAttr, defStyleRes); 38 | } 39 | 40 | @Override 41 | public void doInitialViewsLocation() { 42 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 43 | mBackgroundView = findViewById(R.id.backgroundView); 44 | mForegroundView.anchor(mBackgroundView.getRight(), mBackgroundView.getLeft()); 45 | } 46 | 47 | @Override 48 | public void onTranslateChange(float global, int index, float relative) { 49 | mBackgroundView.setTranslationX((global - 1) * mBackgroundView.getWidth()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/swipe/HalfRightDragFrictionCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.swipe; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import com.xenione.libs.swipemaker.AbsCoordinatorLayout; 9 | import com.xenione.libs.swipemaker.SwipeLayout; 10 | 11 | import apps.xenione.com.swipelayout.R; 12 | 13 | 14 | /** 15 | * Created on 06/04/16. 16 | */ 17 | public class HalfRightDragFrictionCoordinatorLayout extends AbsCoordinatorLayout { 18 | 19 | private View mBackgroundView; 20 | private SwipeLayout mForegroundView; 21 | 22 | public HalfRightDragFrictionCoordinatorLayout(Context context) { 23 | super(context); 24 | } 25 | 26 | public HalfRightDragFrictionCoordinatorLayout(Context context, AttributeSet attrs) { 27 | super(context, attrs); 28 | } 29 | 30 | public HalfRightDragFrictionCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 31 | super(context, attrs, defStyleAttr); 32 | } 33 | 34 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 35 | public HalfRightDragFrictionCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 36 | super(context, attrs, defStyleAttr, defStyleRes); 37 | } 38 | 39 | @Override 40 | public void doInitialViewsLocation() { 41 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 42 | mBackgroundView = findViewById(R.id.backgroundView); 43 | mForegroundView.anchor(mBackgroundView.getRight(), mBackgroundView.getLeft()); 44 | } 45 | 46 | @Override 47 | public void onTranslateChange(float global, int index, float relative) { 48 | mBackgroundView.setTranslationX(0.65f + 0.45f * (global - 1) * mBackgroundView.getWidth()); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_main_drawer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 12 | 16 | 17 | 21 | 22 | 26 | 27 | 31 | 35 | 36 | 40 | 41 | 42 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/swipe/RightCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.swipe; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import com.xenione.libs.swipemaker.AbsCoordinatorLayout; 9 | import com.xenione.libs.swipemaker.SwipeLayout; 10 | 11 | import apps.xenione.com.swipelayout.R; 12 | 13 | 14 | /** 15 | * Created on 06/04/16. 16 | */ 17 | public class RightCoordinatorLayout extends AbsCoordinatorLayout { 18 | 19 | public interface OnDismissListener { 20 | void onDismissed(); 21 | } 22 | 23 | private View mBackgroundView; 24 | private SwipeLayout mForegroundView; 25 | private OnDismissListener mOnDismissListener; 26 | 27 | public RightCoordinatorLayout(Context context) { 28 | super(context); 29 | } 30 | 31 | public RightCoordinatorLayout(Context context, AttributeSet attrs) { 32 | super(context, attrs); 33 | } 34 | 35 | public RightCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 36 | super(context, attrs, defStyleAttr); 37 | } 38 | 39 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 40 | public RightCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 41 | super(context, attrs, defStyleAttr, defStyleRes); 42 | } 43 | 44 | @Override 45 | public void doInitialViewsLocation() { 46 | mBackgroundView = findViewById(R.id.backgroundView); 47 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 48 | mForegroundView.anchor(this.getRight(), this.getLeft()); 49 | } 50 | 51 | public void setOnDismissListener(OnDismissListener listener) { 52 | mOnDismissListener = listener; 53 | } 54 | 55 | @Override 56 | public void onTranslateChange(float global, int index, float relative) { 57 | mBackgroundView.setAlpha(global); 58 | mForegroundView.setAlpha(1 - global); 59 | if (global == 1) { 60 | mOnDismissListener.onDismissed(); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/fragment/HalfRightDragSwipeFragment.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.fragment.app.Fragment; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Toast; 12 | 13 | import apps.xenione.com.swipelayout.R; 14 | import apps.xenione.com.swipelayout.example.adapter.HalfRightDragSwipeAdapter; 15 | import apps.xenione.com.swipelayout.example.data.Album; 16 | 17 | /** 18 | * Created by Eugeni on 13/04/2016. 19 | */ 20 | public class HalfRightDragSwipeFragment extends Fragment implements HalfRightDragSwipeAdapter.OnItemDismissListener { 21 | 22 | public static final String TAG = "HalfRightNextSwipeFragment"; 23 | 24 | public static Fragment newInstance() { 25 | return new HalfRightDragSwipeFragment(); 26 | } 27 | 28 | private HalfRightDragSwipeAdapter mAdapter; 29 | 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_swipe, container, false); 34 | initRecyclerView(view); 35 | return view; 36 | } 37 | 38 | private void initRecyclerView(View view) { 39 | RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.swipe_list); 40 | recyclerView.setHasFixedSize(true); 41 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 42 | recyclerView.setLayoutManager(layoutManager); 43 | mAdapter = new HalfRightDragSwipeAdapter(Album.getAlbum()); 44 | mAdapter.setOnItemDismissListener(this); 45 | recyclerView.setAdapter(mAdapter); 46 | } 47 | 48 | @Override 49 | public void onItemDismissed(Album album) { 50 | mAdapter.deleteItem(album); 51 | Toast.makeText(getContext(), "item deleted with title :" + album.getName(), Toast.LENGTH_LONG).show(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_vertical_swipe_page.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 12 | 17 | 18 | 22 | 23 | 31 | 32 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 54 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/fragment/HalfRightDragFrictionSwipeFragment.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.fragment.app.Fragment; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Toast; 12 | 13 | import apps.xenione.com.swipelayout.R; 14 | import apps.xenione.com.swipelayout.example.adapter.HalfRightDragFrictionSwipeAdapter; 15 | import apps.xenione.com.swipelayout.example.data.Album; 16 | 17 | /** 18 | * Created by Eugeni on 13/04/2016. 19 | */ 20 | public class HalfRightDragFrictionSwipeFragment extends Fragment implements HalfRightDragFrictionSwipeAdapter.OnItemDismissListener { 21 | 22 | public static final String TAG = "HalfRightDragFrictionSwipeFragment"; 23 | 24 | public static Fragment newInstance() { 25 | return new HalfRightDragFrictionSwipeFragment(); 26 | } 27 | 28 | private HalfRightDragFrictionSwipeAdapter mAdapter; 29 | 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_swipe, container, false); 34 | initRecyclerView(view); 35 | return view; 36 | } 37 | 38 | private void initRecyclerView(View view) { 39 | RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.swipe_list); 40 | recyclerView.setHasFixedSize(true); 41 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 42 | recyclerView.setLayoutManager(layoutManager); 43 | mAdapter = new HalfRightDragFrictionSwipeAdapter(Album.getAlbum()); 44 | mAdapter.setOnItemDismissListener(this); 45 | recyclerView.setAdapter(mAdapter); 46 | } 47 | 48 | @Override 49 | public void onItemDismissed(Album album) { 50 | mAdapter.deleteItem(album); 51 | Toast.makeText(getContext(), "item deleted with title :" + album.getName(), Toast.LENGTH_LONG).show(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /swipemaker/src/main/java/com/xenione/libs/swipemaker/AbsCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import androidx.core.view.ViewCompat; 7 | import android.util.AttributeSet; 8 | import android.widget.FrameLayout; 9 | 10 | /** 11 | * Created on 06/04/16. 12 | */ 13 | public abstract class AbsCoordinatorLayout extends FrameLayout implements SwipeLayout.OnTranslateChangeListener { 14 | 15 | private SwipeLayout mForegroundView; 16 | private int mStartPosition = 0; 17 | 18 | public Runnable initializeViews = new Runnable() { 19 | @Override 20 | public void run() { 21 | mForegroundView.translateTo(mStartPosition); 22 | } 23 | }; 24 | 25 | public AbsCoordinatorLayout(Context context) { 26 | super(context); 27 | } 28 | 29 | public AbsCoordinatorLayout(Context context, AttributeSet attrs) { 30 | super(context, attrs); 31 | } 32 | 33 | public AbsCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | } 36 | 37 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 38 | public AbsCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 39 | super(context, attrs, defStyleAttr, defStyleRes); 40 | } 41 | 42 | @Override 43 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 44 | super.onLayout(changed, left, top, right, bottom); 45 | doInitialViewsLocation(); 46 | } 47 | 48 | public abstract void doInitialViewsLocation(); 49 | 50 | public void startWith(int position) { 51 | mStartPosition = position; 52 | mForegroundView.startWith(position); 53 | } 54 | 55 | @Override 56 | protected void onFinishInflate() { 57 | super.onFinishInflate(); 58 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 59 | mForegroundView.setOnTranslateChangeListener(this); 60 | } 61 | 62 | public void sync() { 63 | if (!isInEditMode()) { 64 | ViewCompat.postOnAnimation(this, initializeViews); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /swipemaker/src/main/java/com/xenione/libs/swipemaker/Position.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | 3 | /** 4 | * Created by Eugeni on 23/04/2016. 5 | */ 6 | public class Position { 7 | 8 | private Anchors anchors; 9 | private int currX; 10 | public int section; 11 | public float relative; 12 | public float global; 13 | 14 | public void setAnchors(Anchors anchors) { 15 | this.anchors = anchors; 16 | setCurrPos(0); 17 | } 18 | 19 | public void setCurrPos(int pos) { 20 | currX = pos; 21 | section = anchors == null ? 0 : anchors.sectionFor(pos); 22 | } 23 | 24 | public void updatePosition(int newX) { 25 | if (currX == newX) { 26 | return; 27 | } 28 | updateSection(newX); 29 | this.currX = newX; 30 | this.relative = relative(newX); 31 | this.global = global(newX); 32 | } 33 | 34 | private void decSection() { 35 | if (section == 0) { 36 | return; 37 | } 38 | section--; 39 | } 40 | 41 | private void incSection() { 42 | if (section == anchors.size() - 1) { 43 | return; 44 | } 45 | section++; 46 | } 47 | 48 | private boolean moveToLeft(int newX) { 49 | return currX > newX; 50 | } 51 | 52 | private boolean moveToRight(int newX) { 53 | return currX < newX; 54 | } 55 | 56 | private void updateSection(int newX) { 57 | if (anchors == null) { 58 | return; 59 | } 60 | if (moveToLeft(newX) && (newX <= anchors.anchorFor(this.section))) { 61 | decSection(); 62 | } else if (moveToRight(newX) && (newX > anchors.anchorFor(this.section + 1))) { 63 | incSection(); 64 | } 65 | } 66 | 67 | public float global(int posX) { 68 | return anchors == null ? posX : anchors.distance(posX); 69 | } 70 | 71 | public float relative(int posX) { 72 | return anchors == null ? posX : anchors.distance(this.section, posX); 73 | } 74 | 75 | public int closeTo(int posX) { 76 | return anchors == null ? posX : anchors.closeTo(section, posX); 77 | } 78 | 79 | public int cropInLimits(int posX) { 80 | return anchors == null ? posX : anchors.cropInLimits(posX); 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/fragment/BothSideSwipeFragment.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.fragment.app.Fragment; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Toast; 12 | 13 | import apps.xenione.com.swipelayout.R; 14 | import apps.xenione.com.swipelayout.example.adapter.BothSideSwipeAdapter; 15 | import apps.xenione.com.swipelayout.example.data.Album; 16 | 17 | /** 18 | * Created by Eugeni on 13/04/2016. 19 | */ 20 | public class BothSideSwipeFragment extends Fragment implements BothSideSwipeAdapter.OnItemClickListener { 21 | 22 | public static final String TAG = "BothSideSwipeFragment"; 23 | 24 | public static Fragment newInstance() { 25 | return new BothSideSwipeFragment(); 26 | } 27 | 28 | private BothSideSwipeAdapter mAdapter; 29 | 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_swipe, container, false); 34 | initRecyclerView(view); 35 | return view; 36 | } 37 | 38 | private void initRecyclerView(View view) { 39 | RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.swipe_list); 40 | recyclerView.setHasFixedSize(true); 41 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 42 | recyclerView.setLayoutManager(layoutManager); 43 | mAdapter = new BothSideSwipeAdapter(Album.getAlbum()); 44 | mAdapter.setOnItemClickListener(this); 45 | recyclerView.setAdapter(mAdapter); 46 | } 47 | 48 | @Override 49 | public void onItemDismissed(Album album) { 50 | mAdapter.deleteItem(album); 51 | Toast.makeText(getContext(), "item deleted with title :" + album.getName(), Toast.LENGTH_LONG).show(); 52 | } 53 | 54 | @Override 55 | public void onItemAction(Album album) { 56 | Toast.makeText(getContext(), "perform action on item with title:" + album.getName(), Toast.LENGTH_LONG).show(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/fragment/TwoStepRightSwipeFragment.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.fragment.app.Fragment; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Toast; 12 | 13 | import apps.xenione.com.swipelayout.R; 14 | import apps.xenione.com.swipelayout.example.adapter.TwoStepRightSwipeAdapter; 15 | import apps.xenione.com.swipelayout.example.data.Album; 16 | 17 | /** 18 | * Created by Eugeni on 13/04/2016. 19 | */ 20 | public class TwoStepRightSwipeFragment extends Fragment implements TwoStepRightSwipeAdapter.OnItemClickListener { 21 | 22 | public static final String TAG = "TwoStepRightSwipeFragment"; 23 | 24 | public static Fragment newInstance() { 25 | return new TwoStepRightSwipeFragment(); 26 | } 27 | 28 | private TwoStepRightSwipeAdapter mAdapter; 29 | 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_swipe, container, false); 34 | initRecyclerView(view); 35 | return view; 36 | } 37 | 38 | private void initRecyclerView(View view) { 39 | RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.swipe_list); 40 | recyclerView.setHasFixedSize(true); 41 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 42 | recyclerView.setLayoutManager(layoutManager); 43 | mAdapter = new TwoStepRightSwipeAdapter(Album.getAlbum()); 44 | mAdapter.setOnItemClickListener(this); 45 | recyclerView.setAdapter(mAdapter); 46 | } 47 | 48 | @Override 49 | public void onItemDismissed(Album album) { 50 | mAdapter.deleteItem(album); 51 | Toast.makeText(getContext(), "item deleted with title :" + album.getName(), Toast.LENGTH_LONG).show(); 52 | } 53 | 54 | @Override 55 | public void onItemAction(Album album) { 56 | Toast.makeText(getContext(), "perform action on item:" + album.getName(), Toast.LENGTH_LONG).show(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/fragment/SwingSwipeFragment.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.fragment.app.Fragment; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Toast; 12 | 13 | import apps.xenione.com.swipelayout.R; 14 | import apps.xenione.com.swipelayout.example.adapter.SwingSwipeAdapter; 15 | import apps.xenione.com.swipelayout.example.data.Album; 16 | 17 | /** 18 | * Created by Eugeni on 13/04/2016. 19 | */ 20 | public class SwingSwipeFragment extends Fragment implements SwingSwipeAdapter.OnItemDismissListener { 21 | 22 | public static final String TAG = "SwingSwipeFragment"; 23 | 24 | public static Fragment newInstance() { 25 | return new SwingSwipeFragment(); 26 | } 27 | 28 | private SwingSwipeAdapter mAdapter; 29 | 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_swipe, container, false); 34 | initRecyclerView(view); 35 | return view; 36 | } 37 | 38 | private void initRecyclerView(View view) { 39 | RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.swipe_list); 40 | recyclerView.setHasFixedSize(true); 41 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 42 | recyclerView.setLayoutManager(layoutManager); 43 | mAdapter = new SwingSwipeAdapter(Album.getAlbum()); 44 | mAdapter.setOnItemDismissListener(this); 45 | recyclerView.setAdapter(mAdapter); 46 | } 47 | 48 | @Override 49 | public void onRightItemDismissed(Album album) { 50 | mAdapter.deleteItem(album); 51 | Toast.makeText(getContext(), "item swipe right with title :" + album.getName(), Toast.LENGTH_LONG).show(); 52 | } 53 | 54 | @Override 55 | public void onLeftItemDismissed(Album album) { 56 | mAdapter.deleteItem(album); 57 | Toast.makeText(getContext(), "item swipe left at position :" + album.getName(), Toast.LENGTH_LONG).show(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/fragment/RightSwipeFragment.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.fragment.app.Fragment; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Toast; 12 | 13 | import apps.xenione.com.swipelayout.R; 14 | import apps.xenione.com.swipelayout.example.adapter.RightSwipeAdapter; 15 | import apps.xenione.com.swipelayout.example.data.Album; 16 | 17 | /** 18 | * Created by Eugeni on 13/04/2016. 19 | */ 20 | public class RightSwipeFragment extends Fragment implements RightSwipeAdapter.OnItemDismissListener, RightSwipeAdapter.OnItemSelectListener { 21 | 22 | public static final String TAG = "RightSwipeFragment"; 23 | 24 | public static Fragment newInstance() { 25 | return new RightSwipeFragment(); 26 | } 27 | 28 | private RightSwipeAdapter mAdapter; 29 | 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_swipe, container, false); 34 | initRecyclerView(view); 35 | return view; 36 | } 37 | 38 | private void initRecyclerView(View view) { 39 | RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.swipe_list); 40 | recyclerView.setHasFixedSize(true); 41 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 42 | recyclerView.setLayoutManager(layoutManager); 43 | mAdapter = new RightSwipeAdapter(Album.getAlbum()); 44 | mAdapter.setOnItemDismissListener(this); 45 | mAdapter.setOnItemItemSelectListener(this); 46 | recyclerView.setAdapter(mAdapter); 47 | } 48 | 49 | @Override 50 | public void onItemDismissed(Album album) { 51 | mAdapter.deleteItem(album); 52 | Toast.makeText(getContext(), "item deleted at album : " + album.getName(), Toast.LENGTH_LONG).show(); 53 | } 54 | 55 | @Override 56 | public void onItemSelected(Album album) { 57 | Toast.makeText(getContext(), "item selected at position with title: " + album.getName(), Toast.LENGTH_LONG).show(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/fragment/HalfRightSwipeFragment.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.fragment.app.Fragment; 6 | import androidx.recyclerview.widget.LinearLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.Toast; 12 | 13 | import apps.xenione.com.swipelayout.R; 14 | import apps.xenione.com.swipelayout.example.adapter.HalfRightSwipeAdapter; 15 | import apps.xenione.com.swipelayout.example.data.Album; 16 | 17 | /** 18 | * Created by Eugeni on 13/04/2016. 19 | */ 20 | public class HalfRightSwipeFragment extends Fragment implements HalfRightSwipeAdapter.OnItemDismissListener, HalfRightSwipeAdapter.OnItemSelectListener { 21 | 22 | public static final String TAG = "HalfRightSwipeFragment"; 23 | 24 | public static Fragment newInstance() { 25 | return new HalfRightSwipeFragment(); 26 | } 27 | 28 | private HalfRightSwipeAdapter mAdapter; 29 | 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_swipe, container, false); 34 | initRecyclerView(view); 35 | return view; 36 | } 37 | 38 | private void initRecyclerView(View view) { 39 | RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.swipe_list); 40 | recyclerView.setHasFixedSize(true); 41 | LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); 42 | recyclerView.setLayoutManager(layoutManager); 43 | mAdapter = new HalfRightSwipeAdapter(Album.getAlbum()); 44 | mAdapter.setOnItemDismissListener(this); 45 | mAdapter.setOnItemItemSelectListener(this); 46 | recyclerView.setAdapter(mAdapter); 47 | } 48 | 49 | @Override 50 | public void onItemDismissed(Album album) { 51 | mAdapter.deleteItem(album); 52 | Toast.makeText(getContext(), "item deleted with title :" + album.getName(), Toast.LENGTH_LONG).show(); 53 | } 54 | 55 | @Override 56 | public void onItemSelected(Album album) { 57 | Toast.makeText(getContext(), "item selected with title :" + album.getName(), Toast.LENGTH_LONG).show(); 58 | 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /swipemaker/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.kt3k.coveralls' 3 | apply plugin: 'jacoco' 4 | 5 | 6 | 7 | ext { 8 | PUBLISH_GROUP_ID = 'com.xenione.libs' 9 | PUBLISH_ARTIFACT_ID = 'swipe-maker' 10 | PUBLISH_VERSION = '1.1.3' 11 | } 12 | 13 | android { 14 | compileSdkVersion 29 15 | buildToolsVersion "29.0.2" 16 | 17 | defaultConfig { 18 | minSdkVersion 15 19 | targetSdkVersion 29 20 | versionCode 113 21 | versionName "1.1.3" 22 | } 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 27 | } 28 | debug { 29 | testCoverageEnabled true 30 | } 31 | } 32 | testOptions { 33 | unitTests.returnDefaultValues = true 34 | unitTests.all { 35 | jacoco { 36 | includeNoLocationClasses = true 37 | } 38 | } 39 | } 40 | } 41 | 42 | coveralls { 43 | jacocoReportPath = "${buildDir}/reports/jacoco/jacocoTestReport/jacocoTestReport.xml" 44 | } 45 | 46 | dependencies { 47 | implementation fileTree(dir: 'libs', include: ['*.jar']) 48 | testImplementation 'junit:junit:4.12' 49 | implementation 'androidx.appcompat:appcompat:1.2.0' 50 | // add mockito dependencies 51 | testImplementation "org.mockito:mockito-core:2.23.0" 52 | } 53 | tasks.coveralls { 54 | dependsOn 'jacocoTestReport' 55 | onlyIf { System.env.'CI' } 56 | } 57 | 58 | task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) { 59 | 60 | reports { 61 | xml.enabled = true 62 | html.enabled = true 63 | } 64 | 65 | def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*'] 66 | def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter) 67 | def mainSrc = "${project.projectDir}/src/main/java" 68 | 69 | getSourceDirectories().setFrom(files([mainSrc])) 70 | getClassDirectories().setFrom(files([debugTree])) 71 | getExecutionData().setFrom(fileTree(dir: "$buildDir", includes: [ 72 | "jacoco/testDebugUnitTest.exec", 73 | "outputs/code-coverage/connected/*coverage.ec" 74 | ])) 75 | } 76 | 77 | apply from: 'https://raw.githubusercontent.com/blundell/release-android-library/master/android-release-aar.gradle' -------------------------------------------------------------------------------- /swipemaker/src/test/java/com/xenione/libs/swipemaker/ScrollerHelperTest.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | /* 3 | Copyright 08/06/2017 Eugeni Josep Senent i Gabriel 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | import android.widget.OverScroller; 19 | 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import static org.mockito.ArgumentMatchers.anyInt; 24 | import static org.mockito.Mockito.mock; 25 | import static org.mockito.Mockito.never; 26 | import static org.mockito.Mockito.verify; 27 | 28 | public class ScrollerHelperTest { 29 | 30 | private ScrollerHelper scrollerHelper; 31 | private OverScroller overScroller; 32 | 33 | @Before 34 | public void setup() { 35 | overScroller = mock(OverScroller.class); 36 | scrollerHelper = new ScrollerHelper(overScroller); 37 | } 38 | 39 | @Test 40 | public void WhenSrtAndEndAreDifferent_startScrollOnOverScroll() { 41 | scrollerHelper.startScroll(0, 100); 42 | verify(overScroller).startScroll(0, 0, 100, 0); 43 | } 44 | 45 | @Test 46 | public void WhenSrtAndEndAreTheSame_noStartScrollOnOverScroll() { 47 | scrollerHelper.startScroll(0, 0); 48 | verify(overScroller, never()).startScroll(anyInt(), anyInt(), anyInt(), anyInt()); 49 | } 50 | 51 | @Test 52 | public void WhenScrollingAndFinish_forceFinish() { 53 | scrollerHelper.startScroll(0, 100); 54 | scrollerHelper.finish(); 55 | verify(overScroller).forceFinished(true); 56 | } 57 | 58 | @Test 59 | public void WhenIsFinished_forwardToOverScroll() { 60 | scrollerHelper.isFinished(); 61 | verify(overScroller).isFinished(); 62 | } 63 | 64 | @Test 65 | public void WhenComputeScrollOffset_forwardToOverScroll() { 66 | scrollerHelper.computeScrollOffset(); 67 | verify(overScroller).computeScrollOffset(); 68 | } 69 | 70 | @Test 71 | public void WhenCurrX_forwardToOverScroll() { 72 | scrollerHelper.getCurrX(); 73 | verify(overScroller).getCurrX(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /swipemaker/src/main/java/com/xenione/libs/swipemaker/orientation/HorizontalOrientationStrategy.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker.orientation; 2 | 3 | import android.view.MotionEvent; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by Eugeni on 28/09/2016. 8 | */ 9 | public class HorizontalOrientationStrategy extends OrientationStrategy { 10 | 11 | private int mLastTouchX; 12 | private boolean mIsDragging; 13 | private View mView; 14 | 15 | public HorizontalOrientationStrategy(View view) { 16 | super(view); 17 | mView = view; 18 | } 19 | 20 | public HorizontalOrientationStrategy(View view, int slopTouch) { 21 | super(view, slopTouch); 22 | mView = view; 23 | } 24 | 25 | @Override 26 | public boolean onInterceptTouchEvent(MotionEvent ev) { 27 | final int action = ev.getAction(); 28 | if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { 29 | fling(); 30 | return false; 31 | } 32 | switch (action) { 33 | case MotionEvent.ACTION_DOWN: { 34 | mLastTouchX = (int) ev.getX(); 35 | mHelperScroller.finish(); 36 | break; 37 | } 38 | case MotionEvent.ACTION_MOVE: { 39 | int deltaX = Math.abs((int) ev.getX() - mLastTouchX); 40 | mIsDragging = deltaX > mTouchSlop; 41 | if (mIsDragging) { 42 | disallowParentInterceptTouchEvent(true); 43 | mLastTouchX = (int) ev.getX(); 44 | } 45 | } 46 | } 47 | 48 | return mIsDragging; 49 | } 50 | 51 | 52 | @Override 53 | public boolean onTouchEvent(MotionEvent event) { 54 | 55 | final int action = event.getAction(); 56 | if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { 57 | if (mIsDragging) { 58 | disallowParentInterceptTouchEvent(false); 59 | } 60 | boolean isFling = fling(); 61 | boolean handled = mIsDragging | isFling; 62 | mIsDragging = false; 63 | return handled; 64 | } 65 | 66 | switch (action) { 67 | case MotionEvent.ACTION_DOWN: { 68 | mLastTouchX = (int) event.getX(); 69 | break; 70 | } 71 | case MotionEvent.ACTION_MOVE: { 72 | int deltaX = (int) event.getX() - mLastTouchX; 73 | if (mIsDragging) { 74 | translateBy(deltaX); 75 | } else if (Math.abs(deltaX) > mTouchSlop) { 76 | disallowParentInterceptTouchEvent(true); 77 | mLastTouchX = (int) event.getX(); 78 | mIsDragging = true; 79 | } 80 | break; 81 | } 82 | } 83 | 84 | return mIsDragging; 85 | } 86 | 87 | @Override 88 | int getDelta() { 89 | return (int) mView.getTranslationX(); 90 | } 91 | 92 | @Override 93 | void setDelta(int delta) { 94 | mView.setTranslationX(delta); 95 | } 96 | } -------------------------------------------------------------------------------- /swipemaker/src/main/java/com/xenione/libs/swipemaker/orientation/VerticalOrientationStrategy.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker.orientation; 2 | 3 | import android.view.MotionEvent; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by Eugeni on 28/09/2016. 8 | */ 9 | public class VerticalOrientationStrategy extends OrientationStrategy { 10 | 11 | private int mLastTouchY; 12 | private boolean mIsDragging; 13 | private View mView; 14 | 15 | public VerticalOrientationStrategy(View view) { 16 | super(view); 17 | mView = view; 18 | } 19 | 20 | public VerticalOrientationStrategy(View view, int slopTouch) { 21 | super(view, slopTouch); 22 | mView = view; 23 | } 24 | 25 | @Override 26 | public boolean onInterceptTouchEvent(MotionEvent ev) { 27 | final int action = ev.getAction(); 28 | if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { 29 | fling(); 30 | mIsDragging = false; 31 | return false; 32 | } 33 | switch (action) { 34 | case MotionEvent.ACTION_DOWN: { 35 | mLastTouchY = (int) ev.getY(); 36 | mHelperScroller.finish(); 37 | break; 38 | } 39 | case MotionEvent.ACTION_MOVE: { 40 | int deltaY = Math.abs((int) ev.getY() - mLastTouchY); 41 | mIsDragging = deltaY > mTouchSlop; 42 | if (mIsDragging) { 43 | disallowParentInterceptTouchEvent(true); 44 | mLastTouchY = (int) ev.getY(); 45 | } 46 | } 47 | } 48 | 49 | return mIsDragging; 50 | } 51 | 52 | @Override 53 | public boolean onTouchEvent(MotionEvent event) { 54 | 55 | final int action = event.getAction(); 56 | if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { 57 | if (mIsDragging) { 58 | disallowParentInterceptTouchEvent(false); 59 | } 60 | boolean isFling = fling(); 61 | boolean handled = mIsDragging | isFling; 62 | mIsDragging = false; 63 | return handled; 64 | } 65 | 66 | switch (action) { 67 | case MotionEvent.ACTION_DOWN: { 68 | mLastTouchY = (int) event.getY(); 69 | break; 70 | } 71 | case MotionEvent.ACTION_MOVE: { 72 | int deltaY = (int) event.getY() - mLastTouchY; 73 | if (mIsDragging) { 74 | translateBy(deltaY); 75 | } else if (Math.abs(deltaY) > mTouchSlop) { 76 | disallowParentInterceptTouchEvent(true); 77 | mLastTouchY = (int) event.getY(); 78 | mIsDragging = true; 79 | } 80 | break; 81 | } 82 | } 83 | 84 | return mIsDragging; 85 | } 86 | 87 | @Override 88 | int getDelta() { 89 | return (int) mView.getTranslationY(); 90 | } 91 | 92 | @Override 93 | void setDelta(int delta) { 94 | mView.setTranslationY(delta); 95 | } 96 | } -------------------------------------------------------------------------------- /swipemaker/src/test/java/com/xenione/libs/swipemaker/AnchorsTest.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | /* 3 | Copyright 04/06/2017 Eugeni Josep Senent i Gabriel 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.JUnit4; 21 | 22 | import static org.hamcrest.CoreMatchers.either; 23 | import static org.hamcrest.CoreMatchers.is; 24 | import static org.junit.Assert.assertEquals; 25 | import static org.junit.Assert.assertThat; 26 | 27 | @RunWith(JUnit4.class) 28 | public class AnchorsTest { 29 | 30 | @Test 31 | public void closeTo_whenNegativeAnchors_giveClosestAnchor() { 32 | Anchors anchors = Anchors.make(new Integer[]{-20, -10, 0}); 33 | int anchor = anchors.closeTo(1, -1); 34 | assertThat(anchor, is(0)); 35 | } 36 | 37 | @Test 38 | public void closeTo_whenPositiveAnchors_giveClosestAnchor() { 39 | Anchors anchors = Anchors.make(new Integer[]{0, 10, 20}); 40 | int anchor = anchors.closeTo(0, 1); 41 | assertThat(anchor, is(0)); 42 | } 43 | 44 | @Test 45 | public void cropInLimits_whenPositivePositionExceedLimits_keepInLimits() { 46 | Anchors anchors = Anchors.make(new Integer[]{0, 10, 20}); 47 | int anchor = anchors.cropInLimits(30); 48 | assertThat(anchor, is(20)); 49 | } 50 | 51 | @Test 52 | public void cropInLimits_whenNegativePositionExceedLimits_keepInLimits() { 53 | Anchors anchors = Anchors.make(new Integer[]{0, 10, 20}); 54 | int anchor = anchors.cropInLimits(-10); 55 | assertThat(anchor, is(0)); 56 | } 57 | 58 | @Test 59 | public void sectionFor_whenPositionInASection_giveSection() { 60 | Anchors anchors = Anchors.make(new Integer[]{0, 10, 20}); 61 | int anchor = anchors.sectionFor(5); 62 | assertThat(anchor, is(0)); 63 | } 64 | 65 | @Test 66 | public void sectionFor_whenPositionIsAnchor_giveSection() { 67 | Anchors anchors = Anchors.make(new Integer[]{0, 10, 20, 30}); 68 | int anchor = anchors.sectionFor(10); 69 | assertThat(anchor, either(is(0)).or(is(1))); 70 | } 71 | 72 | @Test(expected = IllegalArgumentException.class) 73 | public void sectionFor_whenPositionExceedLimits_throwException() { 74 | Anchors anchors = Anchors.make(new Integer[]{0, 10, 20, 30}); 75 | anchors.sectionFor(50); 76 | } 77 | 78 | @Test 79 | public void distance_whenPositionWithinSection_giveDistanceFromInfAnchor() { 80 | Anchors anchors = Anchors.make(new Integer[]{0, 10, 20, 30}); 81 | float distance = anchors.distance(0, 9); 82 | assertEquals(0.9, distance, 1); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/swipe/TwoStepRightCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.swipe; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.graphics.ColorFilter; 6 | import android.graphics.PorterDuff; 7 | import android.graphics.PorterDuffColorFilter; 8 | import android.os.Build; 9 | import androidx.core.content.res.ResourcesCompat; 10 | import androidx.core.graphics.drawable.DrawableCompat; 11 | import android.util.AttributeSet; 12 | import android.view.View; 13 | import android.widget.ImageView; 14 | import com.xenione.libs.swipemaker.AbsCoordinatorLayout; 15 | import com.xenione.libs.swipemaker.SwipeLayout; 16 | 17 | import apps.xenione.com.swipelayout.R; 18 | 19 | 20 | /** 21 | * Created on 06/04/16. 22 | */ 23 | public class TwoStepRightCoordinatorLayout extends AbsCoordinatorLayout { 24 | 25 | private ImageView mBg; 26 | private View mDelete; 27 | private View mAction; 28 | private SwipeLayout mForegroundView; 29 | 30 | public enum Color { 31 | PINK(R.color.colorAccent), 32 | BLUE(R.color.colorSecondaryAccent); 33 | 34 | private int resId; 35 | private ColorFilter color; 36 | 37 | Color(int resId) { 38 | this.resId = resId; 39 | } 40 | 41 | public ColorFilter getColor(Context context) { 42 | if (color == null) { 43 | color = new PorterDuffColorFilter( 44 | ResourcesCompat.getColor(context.getResources(), resId, context.getTheme()), PorterDuff.Mode.MULTIPLY); 45 | } 46 | return color; 47 | } 48 | } 49 | 50 | public TwoStepRightCoordinatorLayout(Context context) { 51 | super(context); 52 | } 53 | 54 | public TwoStepRightCoordinatorLayout(Context context, AttributeSet attrs) { 55 | super(context, attrs); 56 | } 57 | 58 | public TwoStepRightCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 59 | super(context, attrs, defStyleAttr); 60 | } 61 | 62 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 63 | public TwoStepRightCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 64 | super(context, attrs, defStyleAttr, defStyleRes); 65 | } 66 | 67 | @Override 68 | public void doInitialViewsLocation() { 69 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 70 | mBg = (ImageView) findViewById(R.id.bg_disc); 71 | mDelete = findViewById(R.id.delete); 72 | mAction = findViewById(R.id.action); 73 | mForegroundView.anchor(0, mDelete.getRight(), mAction.getRight()); 74 | } 75 | 76 | @Override 77 | public void onTranslateChange(float global, int index, float relative) { 78 | if (index == 0) { 79 | if (relative == 0) { 80 | removeColorFilter(); 81 | } else { 82 | applyColorFilter(Color.PINK); 83 | } 84 | } else if (index == 1 && relative > 0) { 85 | applyColorFilter(Color.BLUE); 86 | } 87 | } 88 | 89 | private void removeColorFilter(){ 90 | mBg.clearColorFilter(); 91 | } 92 | 93 | private void applyColorFilter(Color color) { 94 | if (DrawableCompat.getColorFilter(mBg.getDrawable()) == color.getColor(getContext())) { 95 | return; 96 | } 97 | mBg.setColorFilter(color.getColor(getContext())); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/data/Album.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.data; 2 | 3 | import java.io.Serializable; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import apps.xenione.com.swipelayout.R; 8 | 9 | /** 10 | * Created by Eugeni on 10/04/2016. 11 | */ 12 | public class Album implements Serializable{ 13 | 14 | public static List getAlbum() { 15 | 16 | return new ArrayList() {{ 17 | add(new Album(1, "La Gossa Sorda", "Saó", 2008, R.drawable.disc_gossa_sorda_sao, 18 | "La Gossa Sorda és un grup musical de Pego (Marina Alta, País Valencià). La seua música té ritmes de Ska, Rock, Reggae i Punk amb la utilització de molts ritmes mediterranis i altres influències. Fan servir instruments com la dolçaina. Les seves lletres en valencià ataquen els fonaments del sistema, la injustícia de l\'ordre social i mundial actual, la lluita per salvar el País Valencià, el consumisme, la corrupció política, la crisi econòmica i l\'integrisme religiós.")); 19 | add(new Album(2, "ZOO", "Tempestes vénen del sud", 2014, R.drawable.disc_zoo_tempestes, 20 | "ZOO és un col·lectiu musical valencià nascut el 2014 que se centra entre el rap, el hip-hop, el rock i ska però també mescla ritmes electrònics. Les lletres de les cançons són polítiques.")); 21 | add(new Album(3, "Auxili", "Dolç Atac", 2013, R.drawable.disc_auxili_dolc, 22 | "")); 23 | add(new Album(4, "La Raíz", "Así en el cielo como en la selva", 2013, R.drawable.disc_raiz_asi_en, 24 | "La Raíz es un grupo de música de Gandía (Valencia)")); 25 | add(new Album(5, "Aspencat", "Essència", 2013, R.drawable.disc_aspencat_essencia, 26 | "Aspencat és un grup musical valencià, més concretament de Xaló, a la Marina Alta. El seu estil s\'ha basat en l\'ska, el reggae i el drum and bass, però en l\'actualitat ha avançat cap a uns ritmes més electrònics on es pot veure la presència del dubstep")); 27 | add(new Album(6, "Bajoqueta rock", "A Pèl ", 1998, R.drawable.disc_bajoqueta_apel, 28 | "Bajoqueta Rock és un grup de rock en valencià que es va formar l\'any 1988 a Riba-roja de Túria i que gaudix de molta popularitat al País Valencià per les seues actuacions excèntriques, les seues lletres rurals, un poc bèsties però sempre amb gran humor, i una gran varietat musical basada en el rock però que inclou tonades populars")); 29 | add(new Album(7, "Diluvi", "Motius", 2013, R.drawable.disc_diluvi_motius, 30 | "El diluvi universal és un mite recurrent a diverses cultures, que indica que una gran inundació va destruir tota la vida (o gairebé) en temps remots")); 31 | }}; 32 | } 33 | 34 | private long id; 35 | private String name; 36 | private String bandName; 37 | private int releaseYear; 38 | private int resId; 39 | private String description; 40 | 41 | public Album(long id, String bandName, String name, int releaseYear, int resId, String description) { 42 | this.id = id; 43 | this.bandName = bandName; 44 | this.name = name; 45 | this.releaseYear = releaseYear; 46 | this.resId = resId; 47 | this.description = description; 48 | } 49 | 50 | public long getId() { 51 | return id; 52 | } 53 | 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | public String getBandName() { 59 | return bandName; 60 | } 61 | 62 | public int getReleaseYear() { 63 | return releaseYear; 64 | } 65 | 66 | public int getResource(){ 67 | return resId; 68 | } 69 | 70 | public String getDescription(){ 71 | return description; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/swipe/VerticalCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.swipe; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.graphics.ColorFilter; 6 | import android.graphics.PorterDuff; 7 | import android.graphics.PorterDuffColorFilter; 8 | import android.os.Build; 9 | import androidx.core.content.res.ResourcesCompat; 10 | import androidx.core.graphics.drawable.DrawableCompat; 11 | import android.util.AttributeSet; 12 | import android.view.View; 13 | import android.widget.ImageView; 14 | 15 | import com.xenione.libs.swipemaker.AbsCoordinatorLayout; 16 | import com.xenione.libs.swipemaker.SwipeLayout; 17 | import com.xenione.libs.swipemaker.SwipeLayout.Orientation; 18 | 19 | import apps.xenione.com.swipelayout.R; 20 | 21 | 22 | /** 23 | * Created on 06/04/16. 24 | */ 25 | public class VerticalCoordinatorLayout extends AbsCoordinatorLayout { 26 | 27 | private ImageView mBg; 28 | private View mDelete; 29 | private View mAction; 30 | private SwipeLayout mForegroundView; 31 | 32 | public enum Color { 33 | PINK(R.color.colorAccent), 34 | BLUE(R.color.colorSecondaryAccent); 35 | 36 | private int resId; 37 | private ColorFilter color; 38 | 39 | Color(int resId) { 40 | this.resId = resId; 41 | } 42 | 43 | public ColorFilter getColor(Context context) { 44 | if (color == null) { 45 | color = new PorterDuffColorFilter( 46 | ResourcesCompat.getColor(context.getResources(), resId, context.getTheme()), PorterDuff.Mode.MULTIPLY); 47 | } 48 | return color; 49 | } 50 | } 51 | 52 | public VerticalCoordinatorLayout(Context context) { 53 | super(context); 54 | } 55 | 56 | public VerticalCoordinatorLayout(Context context, AttributeSet attrs) { 57 | super(context, attrs); 58 | } 59 | 60 | public VerticalCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 61 | super(context, attrs, defStyleAttr); 62 | } 63 | 64 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 65 | public VerticalCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 66 | super(context, attrs, defStyleAttr, defStyleRes); 67 | } 68 | 69 | @Override 70 | public void doInitialViewsLocation() { 71 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 72 | mForegroundView.setOrientation(Orientation.VERTICAL); 73 | mBg = (ImageView) findViewById(R.id.bg_disc); 74 | mDelete = findViewById(R.id.delete); 75 | mAction = findViewById(R.id.action); 76 | int deleteTop = mForegroundView.getHeight() - mDelete.getTop(); 77 | int actionTop = mForegroundView.getHeight() - mAction.getTop(); 78 | mForegroundView.anchor(-actionTop, -deleteTop, 0); 79 | } 80 | 81 | @Override 82 | public void onTranslateChange(float global, int index, float relative) { 83 | if (index == 0) { 84 | if (relative == 0) { 85 | removeColorFilter(); 86 | } else { 87 | applyColorFilter(Color.PINK); 88 | } 89 | } else if (index == 1 && relative > 0) { 90 | applyColorFilter(Color.BLUE); 91 | } 92 | } 93 | 94 | private void removeColorFilter(){ 95 | mBg.clearColorFilter(); 96 | } 97 | 98 | private void applyColorFilter(Color color) { 99 | if (DrawableCompat.getColorFilter(mBg.getDrawable()) == color.getColor(getContext())) { 100 | return; 101 | } 102 | mBg.setColorFilter(color.getColor(getContext())); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/adapter/HalfRightDragFrictionSwipeAdapter.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.adapter; 2 | 3 | import android.content.Context; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.squareup.picasso.Picasso; 12 | 13 | import java.util.List; 14 | 15 | import apps.xenione.com.swipelayout.R; 16 | import apps.xenione.com.swipelayout.example.data.Album; 17 | import apps.xenione.com.swipelayout.example.swipe.HalfRightDragFrictionCoordinatorLayout; 18 | 19 | /** 20 | * Created by Eugeni on 10/04/2016. 21 | */ 22 | public class HalfRightDragFrictionSwipeAdapter extends RecyclerView.Adapter { 23 | 24 | public interface OnItemDismissListener { 25 | void onItemDismissed(Album album); 26 | } 27 | 28 | private List mAlbums; 29 | private OnItemDismissListener mOnItemDismissListener; 30 | 31 | public HalfRightDragFrictionSwipeAdapter(List albums) { 32 | this.mAlbums = albums; 33 | } 34 | 35 | @Override 36 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 37 | return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_half_right_drag_friction_swipe, parent, false)); 38 | } 39 | 40 | @Override 41 | public void onBindViewHolder(ViewHolder holder, int position) { 42 | Album album = getItem(position); 43 | Context context = holder.itemView.getContext(); 44 | Picasso.with(context).load(album.getResource()).placeholder(R.color.placeholder).into(holder.discImage); 45 | holder.title.setText(album.getName()); 46 | holder.bandName.setText(album.getBandName()); 47 | holder.delete.setOnClickListener(new OnItemDismiss(album)); 48 | } 49 | 50 | @Override 51 | public void onViewRecycled(ViewHolder holder) { 52 | super.onViewRecycled(holder); 53 | holder.coordinatorLayout.sync(); 54 | } 55 | 56 | @Override 57 | public int getItemCount() { 58 | return mAlbums.size(); 59 | } 60 | 61 | public void deleteItem(Album album) { 62 | int index = mAlbums.indexOf(album); 63 | if (index == -1) { 64 | return; 65 | } 66 | mAlbums.remove(index); 67 | notifyItemRemoved(index); 68 | notifyItemRangeChanged(index, getItemCount()); 69 | } 70 | 71 | 72 | private Album getItem(int position) { 73 | return mAlbums.get(position); 74 | } 75 | 76 | public void setOnItemDismissListener(OnItemDismissListener listener) { 77 | mOnItemDismissListener = listener; 78 | } 79 | 80 | public class OnItemDismiss implements View.OnClickListener { 81 | 82 | private Album album; 83 | 84 | public OnItemDismiss(Album album) { 85 | this.album = album; 86 | } 87 | 88 | @Override 89 | public void onClick(View v) { 90 | mOnItemDismissListener.onItemDismissed(album); 91 | } 92 | } 93 | 94 | public static class ViewHolder extends RecyclerView.ViewHolder { 95 | public TextView title; 96 | public TextView bandName; 97 | public ImageView discImage; 98 | public View delete; 99 | public HalfRightDragFrictionCoordinatorLayout coordinatorLayout; 100 | 101 | public ViewHolder(View view) { 102 | super(view); 103 | coordinatorLayout = (HalfRightDragFrictionCoordinatorLayout) view; 104 | title = view.findViewById(R.id.title); 105 | bandName = view.findViewById(R.id.bandName); 106 | discImage = view.findViewById(R.id.bg_disc); 107 | delete = view.findViewById(R.id.backgroundView); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/adapter/HalfRightDragSwipeAdapter.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.adapter; 2 | 3 | import android.content.Context; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.squareup.picasso.Picasso; 12 | 13 | import java.util.List; 14 | 15 | import apps.xenione.com.swipelayout.R; 16 | import apps.xenione.com.swipelayout.example.data.Album; 17 | import apps.xenione.com.swipelayout.example.swipe.HalfRightDragCoordinatorLayout; 18 | 19 | /** 20 | * Created by Eugeni on 10/04/2016. 21 | */ 22 | public class HalfRightDragSwipeAdapter extends RecyclerView.Adapter { 23 | 24 | public interface OnItemDismissListener { 25 | void onItemDismissed(Album album); 26 | } 27 | 28 | private List mAlbums; 29 | private OnItemDismissListener mOnItemDismissListener; 30 | 31 | public HalfRightDragSwipeAdapter(List albums) { 32 | this.mAlbums = albums; 33 | } 34 | 35 | @Override 36 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 37 | return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_half_right_drag_swipe, parent, false)); 38 | } 39 | 40 | @Override 41 | public void onBindViewHolder(ViewHolder holder, int position) { 42 | Album album = getItem(position); 43 | Context context = holder.itemView.getContext(); 44 | Picasso.with(context).load(album.getResource()).placeholder(R.color.placeholder).into(holder.discImage); 45 | holder.title.setText(album.getName()); 46 | holder.bandName.setText(album.getBandName()); 47 | holder.delete.setOnClickListener(new OnItemDismiss(album)); 48 | Picasso.with(context).load(album.getResource()).placeholder(R.color.placeholder).into(holder.discImage); 49 | } 50 | 51 | @Override 52 | public void onViewRecycled(ViewHolder holder) { 53 | super.onViewRecycled(holder); 54 | holder.coordinatorLayout.sync(); 55 | } 56 | 57 | @Override 58 | public int getItemCount() { 59 | return mAlbums.size(); 60 | } 61 | 62 | public void deleteItem(Album album) { 63 | int index = mAlbums.indexOf(album); 64 | if (index == -1) { 65 | return; 66 | } 67 | mAlbums.remove(index); 68 | notifyItemRemoved(index); 69 | notifyItemRangeChanged(index, getItemCount()); 70 | } 71 | 72 | 73 | private Album getItem(int position) { 74 | return mAlbums.get(position); 75 | } 76 | 77 | public void setOnItemDismissListener(OnItemDismissListener listener) { 78 | mOnItemDismissListener = listener; 79 | } 80 | 81 | public class OnItemDismiss implements View.OnClickListener { 82 | 83 | private Album album; 84 | 85 | public OnItemDismiss(Album album) { 86 | this.album = album; 87 | } 88 | 89 | @Override 90 | public void onClick(View v) { 91 | mOnItemDismissListener.onItemDismissed(album); 92 | } 93 | } 94 | 95 | public static class ViewHolder extends RecyclerView.ViewHolder { 96 | 97 | public TextView title; 98 | public TextView bandName; 99 | public ImageView discImage; 100 | public View delete; 101 | public HalfRightDragCoordinatorLayout coordinatorLayout; 102 | 103 | public ViewHolder(View view) { 104 | super(view); 105 | coordinatorLayout = (HalfRightDragCoordinatorLayout) view; 106 | title = view.findViewById(R.id.title); 107 | bandName = view.findViewById(R.id.bandName); 108 | discImage = view.findViewById(R.id.bg_disc); 109 | delete = view.findViewById(R.id.backgroundView); 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/adapter/SwingSwipeAdapter.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.adapter; 2 | 3 | import android.content.Context; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.squareup.picasso.Picasso; 12 | 13 | import java.util.List; 14 | 15 | import apps.xenione.com.swipelayout.R; 16 | import apps.xenione.com.swipelayout.example.data.Album; 17 | import apps.xenione.com.swipelayout.example.swipe.SwingCoordinatorLayout; 18 | 19 | /** 20 | * Created by Eugeni on 10/04/2016. 21 | */ 22 | public class SwingSwipeAdapter extends RecyclerView.Adapter { 23 | 24 | public interface OnItemDismissListener { 25 | void onRightItemDismissed(Album album); 26 | 27 | void onLeftItemDismissed(Album album); 28 | } 29 | 30 | private List mAlbums; 31 | private OnItemDismissListener mOnItemDismissListener; 32 | 33 | public SwingSwipeAdapter(List albums) { 34 | this.mAlbums = albums; 35 | } 36 | 37 | @Override 38 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 39 | return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_swing_swipe, parent, false)); 40 | } 41 | 42 | @Override 43 | public void onBindViewHolder(ViewHolder holder, int position) { 44 | Context context = holder.itemView.getContext(); 45 | Album album = getItem(position); 46 | Picasso.with(context).load(album.getResource()).placeholder(R.color.placeholder).into(holder.discImage); 47 | holder.coordinatorLayout.setOnDismissListener(new OnItemDismiss(album)); 48 | holder.title.setText(album.getName()); 49 | holder.bandName.setText(album.getBandName()); 50 | } 51 | 52 | @Override 53 | public void onViewRecycled(ViewHolder holder) { 54 | super.onViewRecycled(holder); 55 | holder.coordinatorLayout.sync(); 56 | } 57 | 58 | @Override 59 | public int getItemCount() { 60 | return mAlbums.size(); 61 | } 62 | 63 | public void deleteItem(Album album) { 64 | int index = mAlbums.indexOf(album); 65 | if (index == -1) { 66 | return; 67 | } 68 | mAlbums.remove(album); 69 | notifyItemRemoved(index); 70 | notifyItemRangeChanged(index, getItemCount()); 71 | } 72 | 73 | private Album getItem(int position) { 74 | return mAlbums.get(position); 75 | } 76 | 77 | public void setOnItemDismissListener(OnItemDismissListener listener) { 78 | mOnItemDismissListener = listener; 79 | } 80 | 81 | public class OnItemDismiss implements SwingCoordinatorLayout.OnDismissListener { 82 | 83 | private Album album; 84 | 85 | public OnItemDismiss(Album album) { 86 | this.album = album; 87 | } 88 | 89 | @Override 90 | public void onRightDismissed() { 91 | if (mOnItemDismissListener != null) { 92 | mOnItemDismissListener.onRightItemDismissed(album); 93 | } 94 | } 95 | 96 | @Override 97 | public void onLeftDismissed() { 98 | if (mOnItemDismissListener != null) { 99 | mOnItemDismissListener.onLeftItemDismissed(album); 100 | } 101 | } 102 | } 103 | 104 | public static class ViewHolder extends RecyclerView.ViewHolder { 105 | public TextView title; 106 | public TextView bandName; 107 | public ImageView discImage; 108 | 109 | public SwingCoordinatorLayout coordinatorLayout; 110 | 111 | public ViewHolder(final View view) { 112 | super(view); 113 | coordinatorLayout = (SwingCoordinatorLayout) view; 114 | title = view.findViewById(R.id.title); 115 | bandName = view.findViewById(R.id.bandName); 116 | discImage = view.findViewById(R.id.bg_disc); 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /swipemaker/src/main/java/com/xenione/libs/swipemaker/orientation/OrientationStrategy.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker.orientation; 2 | 3 | import android.content.Context; 4 | import androidx.core.view.ViewCompat; 5 | import android.util.Log; 6 | import android.view.MotionEvent; 7 | import android.view.View; 8 | import android.view.ViewConfiguration; 9 | import android.view.ViewParent; 10 | import android.widget.OverScroller; 11 | 12 | import com.xenione.libs.swipemaker.Anchors; 13 | import com.xenione.libs.swipemaker.Position; 14 | import com.xenione.libs.swipemaker.ScrollerHelper; 15 | import com.xenione.libs.swipemaker.SwipeLayout; 16 | 17 | /** 18 | * Created by Eugeni on 28/09/2016. 19 | */ 20 | public abstract class OrientationStrategy implements Runnable { 21 | 22 | 23 | private Position mPositionInfo; 24 | private View mView; 25 | private SwipeLayout.OnTranslateChangeListener mOnTranslateChangeListener; 26 | final int mTouchSlop; 27 | ScrollerHelper mHelperScroller; 28 | 29 | 30 | public OrientationStrategy(View view) { 31 | this(view, ViewConfiguration.get(view.getContext()).getScaledTouchSlop()); 32 | } 33 | 34 | public OrientationStrategy(View view, int touchSlop) { 35 | mView = view; 36 | Context context = view.getContext(); 37 | mTouchSlop = touchSlop; 38 | mHelperScroller = new ScrollerHelper(new OverScroller(context)); 39 | mPositionInfo = new Position(); 40 | } 41 | 42 | public void setAnchor(Integer... points) { 43 | mPositionInfo.setAnchors(Anchors.make(points)); 44 | } 45 | 46 | public void setOnTranslateChangeListener(SwipeLayout.OnTranslateChangeListener listener) { 47 | mOnTranslateChangeListener = listener; 48 | } 49 | 50 | public abstract boolean onTouchEvent(MotionEvent e); 51 | 52 | public abstract boolean onInterceptTouchEvent(MotionEvent ev); 53 | 54 | abstract int getDelta(); 55 | 56 | abstract void setDelta(int delta); 57 | 58 | public void translateBy(int delta){ 59 | translateTo(getDelta() + delta); 60 | } 61 | 62 | public void translateTo(int distance) { 63 | int cropped = ensureInsideBounds(distance); 64 | if (getDelta() == cropped) { 65 | return; 66 | } 67 | setDelta(cropped); 68 | updatePosition(cropped); 69 | } 70 | 71 | private void updatePosition(int newPosition) { 72 | mPositionInfo.updatePosition(newPosition); 73 | notifyListener(); 74 | } 75 | private void notifyListener() { 76 | if (mOnTranslateChangeListener != null) { 77 | mOnTranslateChangeListener.onTranslateChange(mPositionInfo.global, mPositionInfo.section, mPositionInfo.relative); 78 | } 79 | 80 | Log.i("translate", "global x: " + mPositionInfo.global + " section:" + mPositionInfo.section + " relative:" + mPositionInfo.relative); 81 | } 82 | 83 | private int ensureInsideBounds(int x) { 84 | return mPositionInfo.cropInLimits(x); 85 | } 86 | 87 | boolean fling() { 88 | int start = getDelta(); 89 | int end = endPositionFrom(start); 90 | boolean started = mHelperScroller.startScroll(start, end); 91 | ViewCompat.postOnAnimation(mView, this); 92 | return started; 93 | } 94 | 95 | boolean isFling() { 96 | return !mHelperScroller.isFinished(); 97 | } 98 | 99 | @Override 100 | public void run() { 101 | if (mHelperScroller.computeScrollOffset()) { 102 | translateTo(mHelperScroller.getCurrX()); 103 | ViewCompat.postOnAnimation(mView, this); 104 | } 105 | } 106 | 107 | private int endPositionFrom(int currPosition) { 108 | return mPositionInfo.closeTo(currPosition); 109 | } 110 | 111 | void disallowParentInterceptTouchEvent(boolean disallow) { 112 | ViewParent parent = mView.getParent(); 113 | if (parent != null) { 114 | parent.requestDisallowInterceptTouchEvent(disallow); 115 | } 116 | } 117 | 118 | public void startWith(int position) { 119 | mPositionInfo.setCurrPos(position); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/swipe/SwingCoordinatorLayout.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.swipe; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.graphics.ColorFilter; 6 | import android.graphics.PorterDuff; 7 | import android.graphics.PorterDuffColorFilter; 8 | import android.os.Build; 9 | import androidx.core.content.res.ResourcesCompat; 10 | import androidx.core.graphics.drawable.DrawableCompat; 11 | import android.util.AttributeSet; 12 | import android.widget.ImageView; 13 | 14 | import com.xenione.libs.swipemaker.AbsCoordinatorLayout; 15 | import com.xenione.libs.swipemaker.SwipeLayout; 16 | 17 | import apps.xenione.com.swipelayout.R; 18 | 19 | 20 | /** 21 | * Created on 06/04/16. 22 | */ 23 | public class SwingCoordinatorLayout extends AbsCoordinatorLayout { 24 | 25 | public interface OnDismissListener { 26 | void onLeftDismissed(); 27 | void onRightDismissed(); 28 | } 29 | 30 | public enum Color { 31 | PINK(R.color.colorAccent), 32 | BLUE(R.color.colorSecondaryAccent); 33 | 34 | private int resId; 35 | private ColorFilter color; 36 | 37 | Color(int resId) { 38 | this.resId = resId; 39 | } 40 | 41 | public ColorFilter getColor(Context context) { 42 | if (color == null) { 43 | color = new PorterDuffColorFilter( 44 | ResourcesCompat.getColor(context.getResources(), resId, context.getTheme()), PorterDuff.Mode.MULTIPLY); 45 | } 46 | return color; 47 | } 48 | } 49 | private ImageView mBg; 50 | private SwipeLayout mForegroundView; 51 | private OnDismissListener mOnDismissListener; 52 | 53 | public SwingCoordinatorLayout(Context context) { 54 | super(context); 55 | } 56 | 57 | public SwingCoordinatorLayout(Context context, AttributeSet attrs) { 58 | super(context, attrs); 59 | } 60 | 61 | public SwingCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { 62 | super(context, attrs, defStyleAttr); 63 | } 64 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 65 | public SwingCoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 66 | super(context, attrs, defStyleAttr, defStyleRes); 67 | } 68 | 69 | @Override 70 | public void doInitialViewsLocation() { 71 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 72 | mBg=(ImageView)findViewById(R.id.bg_disc); 73 | mForegroundView.anchor(-this.getWidth(), 0, this.getWidth()); 74 | mForegroundView.setPivotX(this.getWidth() / 2); 75 | mForegroundView.setPivotY(0); 76 | } 77 | 78 | public void setOnDismissListener(OnDismissListener listener) { 79 | mOnDismissListener = listener; 80 | } 81 | 82 | @Override 83 | public void onTranslateChange(float global, int index, float relative) { 84 | mForegroundView.setRotation((0.5f - global) * 60); 85 | if (index == 0) { 86 | if (relative == 1) { 87 | removeColorFilter(); 88 | mForegroundView.setAlpha(1); 89 | } else { 90 | mForegroundView.setAlpha(relative); 91 | applyColorFilter(Color.PINK); 92 | } 93 | } else { 94 | if (relative == 0) { 95 | removeColorFilter(); 96 | mForegroundView.setAlpha(1); 97 | } else { 98 | mForegroundView.setAlpha(1 - relative); 99 | applyColorFilter(Color.BLUE); 100 | } 101 | } 102 | 103 | if (global == 1) { 104 | mOnDismissListener.onRightDismissed(); 105 | } else if (global == 0) { 106 | mOnDismissListener.onLeftDismissed(); 107 | } 108 | } 109 | 110 | private void removeColorFilter(){ 111 | mBg.clearColorFilter(); 112 | } 113 | 114 | private void applyColorFilter(Color color) { 115 | if (DrawableCompat.getColorFilter(mBg.getDrawable()) == color.getColor(getContext())) { 116 | return; 117 | } 118 | mBg.setColorFilter(color.getColor(getContext())); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/adapter/BothSideSwipeAdapter.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.adapter; 2 | 3 | import android.content.Context; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageButton; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.squareup.picasso.Picasso; 13 | 14 | import java.util.List; 15 | 16 | import apps.xenione.com.swipelayout.R; 17 | import apps.xenione.com.swipelayout.example.data.Album; 18 | import apps.xenione.com.swipelayout.example.swipe.BothSideCoordinatorLayout; 19 | 20 | /** 21 | * Created by Eugeni on 10/04/2016. 22 | */ 23 | public class BothSideSwipeAdapter extends RecyclerView.Adapter { 24 | 25 | public interface OnItemClickListener { 26 | void onItemDismissed(Album album); 27 | 28 | void onItemAction(Album album); 29 | } 30 | 31 | private List mAlbums; 32 | private OnItemClickListener mOnItemClickListener; 33 | 34 | public BothSideSwipeAdapter(List albums) { 35 | this.mAlbums = albums; 36 | } 37 | 38 | @Override 39 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 40 | return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_both_side_swipe, parent, false)); 41 | } 42 | 43 | @Override 44 | public void onBindViewHolder(ViewHolder holder, int position) { 45 | Context context = holder.itemView.getContext(); 46 | Album album = getItem(position); 47 | Picasso.with(context).load(album.getResource()).placeholder(R.color.placeholder).into(holder.discImage); 48 | holder.title.setText(album.getName()); 49 | holder.bandName.setText(album.getBandName()); 50 | holder.delete.setOnClickListener(new OnDismissListener(album)); 51 | holder.action.setOnClickListener(new OnActionListener(album)); 52 | } 53 | 54 | @Override 55 | public void onViewRecycled(ViewHolder holder) { 56 | super.onViewRecycled(holder); 57 | holder.coordinatorLayout.sync(); 58 | } 59 | 60 | @Override 61 | public int getItemCount() { 62 | return mAlbums.size(); 63 | } 64 | 65 | public void setOnItemClickListener(OnItemClickListener listener) { 66 | mOnItemClickListener = listener; 67 | } 68 | 69 | public void deleteItem(Album album) { 70 | int index = mAlbums.indexOf(album); 71 | if (index == -1) { 72 | return; 73 | } 74 | mAlbums.remove(index); 75 | notifyItemRemoved(index); 76 | notifyItemRangeChanged(index, getItemCount()); 77 | } 78 | 79 | private Album getItem(int position) { 80 | return mAlbums.get(position); 81 | } 82 | 83 | private class OnDismissListener implements View.OnClickListener { 84 | 85 | private Album album; 86 | 87 | public OnDismissListener(Album album) { 88 | this.album = album; 89 | } 90 | 91 | @Override 92 | public void onClick(View v) { 93 | mOnItemClickListener.onItemDismissed(album); 94 | } 95 | } 96 | 97 | private class OnActionListener implements View.OnClickListener { 98 | 99 | private Album album; 100 | 101 | public OnActionListener(Album album) { 102 | this.album = album; 103 | } 104 | 105 | @Override 106 | public void onClick(View v) { 107 | mOnItemClickListener.onItemAction(album); 108 | } 109 | } 110 | 111 | public static class ViewHolder extends RecyclerView.ViewHolder { 112 | 113 | public BothSideCoordinatorLayout coordinatorLayout; 114 | public TextView title; 115 | public TextView bandName; 116 | public ImageView discImage; 117 | public ImageButton delete; 118 | public ImageButton action; 119 | 120 | public ViewHolder(View view) { 121 | super(view); 122 | coordinatorLayout = (BothSideCoordinatorLayout) view; 123 | title = view.findViewById(R.id.title); 124 | bandName = view.findViewById(R.id.bandName); 125 | discImage = view.findViewById(R.id.bg_disc); 126 | delete = view.findViewById(R.id.delete); 127 | action = view.findViewById(R.id.action); 128 | } 129 | } 130 | } -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/adapter/TwoStepRightSwipeAdapter.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.adapter; 2 | 3 | import android.content.Context; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageButton; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.squareup.picasso.Picasso; 13 | 14 | import java.util.List; 15 | 16 | import apps.xenione.com.swipelayout.R; 17 | import apps.xenione.com.swipelayout.example.data.Album; 18 | import apps.xenione.com.swipelayout.example.swipe.TwoStepRightCoordinatorLayout; 19 | 20 | /** 21 | * Created by Eugeni on 10/04/2016. 22 | */ 23 | public class TwoStepRightSwipeAdapter extends RecyclerView.Adapter { 24 | 25 | public interface OnItemClickListener { 26 | void onItemDismissed(Album album); 27 | 28 | void onItemAction(Album album); 29 | } 30 | 31 | private List mAlbums; 32 | private OnItemClickListener mOnItemClickListener; 33 | 34 | public TwoStepRightSwipeAdapter(List albums) { 35 | this.mAlbums = albums; 36 | } 37 | 38 | @Override 39 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 40 | return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_two_step_right_swipe, parent, false)); 41 | } 42 | 43 | @Override 44 | public void onBindViewHolder(ViewHolder holder, int position) { 45 | Context context = holder.itemView.getContext(); 46 | Album album = getItem(position); 47 | Picasso.with(context).load(album.getResource()).placeholder(R.color.placeholder).into(holder.discImage); 48 | holder.title.setText(album.getName()); 49 | holder.bandName.setText(album.getBandName()); 50 | holder.delete.setOnClickListener(new OnDismissListener(album)); 51 | holder.action.setOnClickListener(new OnActionListener(album)); 52 | } 53 | 54 | @Override 55 | public void onViewRecycled(ViewHolder holder) { 56 | super.onViewRecycled(holder); 57 | holder.coordinatorLayout.sync(); 58 | } 59 | 60 | @Override 61 | public int getItemCount() { 62 | return mAlbums.size(); 63 | } 64 | 65 | public void setOnItemClickListener(OnItemClickListener listener) { 66 | mOnItemClickListener = listener; 67 | } 68 | 69 | public void deleteItem(Album album) { 70 | int index = mAlbums.indexOf(album); 71 | if (index == -1) { 72 | return; 73 | } 74 | mAlbums.remove(index); 75 | notifyItemRemoved(index); 76 | notifyItemRangeChanged(index, getItemCount()); 77 | } 78 | 79 | private Album getItem(int position) { 80 | return mAlbums.get(position); 81 | } 82 | 83 | private class OnDismissListener implements View.OnClickListener { 84 | 85 | private Album album; 86 | 87 | public OnDismissListener(Album album) { 88 | this.album = album; 89 | } 90 | 91 | @Override 92 | public void onClick(View v) { 93 | mOnItemClickListener.onItemDismissed(album); 94 | } 95 | } 96 | 97 | private class OnActionListener implements View.OnClickListener { 98 | 99 | private Album album; 100 | 101 | public OnActionListener(Album album) { 102 | this.album = album; 103 | } 104 | 105 | @Override 106 | public void onClick(View v) { 107 | mOnItemClickListener.onItemAction(album); 108 | } 109 | } 110 | 111 | public static class ViewHolder extends RecyclerView.ViewHolder { 112 | 113 | public TwoStepRightCoordinatorLayout coordinatorLayout; 114 | public TextView title; 115 | public TextView bandName; 116 | public ImageView discImage; 117 | public ImageButton delete; 118 | public ImageButton action; 119 | 120 | public ViewHolder(View view) { 121 | super(view); 122 | coordinatorLayout = (TwoStepRightCoordinatorLayout) view; 123 | title = view.findViewById(R.id.title); 124 | bandName = view.findViewById(R.id.bandName); 125 | discImage = view.findViewById(R.id.bg_disc); 126 | delete = view.findViewById(R.id.delete); 127 | action = view.findViewById(R.id.action); 128 | } 129 | } 130 | } -------------------------------------------------------------------------------- /swipemaker/src/main/java/com/xenione/libs/swipemaker/SwipeLayout.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.util.AttributeSet; 7 | import android.view.MotionEvent; 8 | import android.view.View; 9 | import android.widget.FrameLayout; 10 | 11 | import com.xenione.libs.swipemaker.orientation.HorizontalOrientationStrategy; 12 | import com.xenione.libs.swipemaker.orientation.OrientationStrategy; 13 | import com.xenione.libs.swipemaker.orientation.OrientationStrategyFactory; 14 | import com.xenione.libs.swipemaker.orientation.VerticalOrientationStrategy; 15 | 16 | /** 17 | * Created by Eugeni on 10/04/2016. 18 | */ 19 | public class SwipeLayout extends FrameLayout { 20 | 21 | private static final String TAG = "SwipeLayout"; 22 | 23 | public enum Orientation { 24 | HORIZONTAL(0), 25 | VERTICAL(1); 26 | 27 | Orientation(int id) { 28 | this.id = id; 29 | } 30 | 31 | final int id; 32 | 33 | OrientationStrategyFactory get() { 34 | 35 | switch (this.id) { 36 | case 0: { 37 | return new HorizontalOrientationStrategyFactory(); 38 | } 39 | default: 40 | case 1: { 41 | return new VerticalOrientationStrategyFactory(); 42 | } 43 | } 44 | } 45 | } 46 | 47 | public interface OnTranslateChangeListener { 48 | void onTranslateChange(float globalPercent, int index, float relativePercent); 49 | } 50 | 51 | OrientationStrategy orientationStrategy; 52 | 53 | public SwipeLayout(Context context) { 54 | this(context, null); 55 | } 56 | 57 | public SwipeLayout(Context context, AttributeSet attrs) { 58 | this(context, attrs, 0); 59 | } 60 | 61 | public SwipeLayout(Context context, AttributeSet attrs, int defStyleAttr) { 62 | super(context, attrs, defStyleAttr); 63 | } 64 | 65 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 66 | public SwipeLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 67 | super(context, attrs, defStyleAttr, defStyleRes); 68 | } 69 | 70 | public void setOrientation(Orientation orientation) { 71 | orientationStrategy = orientation.get().make(this); 72 | } 73 | 74 | public void setOrientation(OrientationStrategyFactory factory) { 75 | orientationStrategy = factory.make(this); 76 | } 77 | 78 | public void startWith(int position) { 79 | makeSureOrientationStrategy(); 80 | orientationStrategy.startWith(position); 81 | } 82 | 83 | public void anchor(Integer... points) { 84 | makeSureOrientationStrategy(); 85 | orientationStrategy.setAnchor(points); 86 | } 87 | 88 | public void setOnTranslateChangeListener(OnTranslateChangeListener listener) { 89 | makeSureOrientationStrategy(); 90 | orientationStrategy.setOnTranslateChangeListener(listener); 91 | } 92 | 93 | @Override 94 | public boolean onInterceptTouchEvent(MotionEvent ev) { 95 | makeSureOrientationStrategy(); 96 | return orientationStrategy.onInterceptTouchEvent(ev); 97 | } 98 | 99 | @Override 100 | public boolean onTouchEvent(MotionEvent event) { 101 | makeSureOrientationStrategy(); 102 | boolean handled = orientationStrategy.onTouchEvent(event); 103 | if (!handled) { 104 | super.onTouchEvent(event); 105 | } 106 | return true; 107 | } 108 | 109 | public void translateTo(int position) { 110 | orientationStrategy.translateTo(position); 111 | } 112 | 113 | private void makeSureOrientationStrategy() { 114 | if (orientationStrategy != null) { 115 | return; 116 | } 117 | orientationStrategy = Orientation.HORIZONTAL.get().make(this); 118 | } 119 | 120 | public static class HorizontalOrientationStrategyFactory implements OrientationStrategyFactory { 121 | 122 | @Override 123 | public OrientationStrategy make(View view) { 124 | return new HorizontalOrientationStrategy(view); 125 | } 126 | } 127 | 128 | public static class VerticalOrientationStrategyFactory implements OrientationStrategyFactory { 129 | 130 | @Override 131 | public OrientationStrategy make(View view) { 132 | return new VerticalOrientationStrategy(view); 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /swipemaker/src/main/java/com/xenione/libs/swipemaker/Anchors.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * Created by Eugeni on 16/04/2016. 7 | */ 8 | public class Anchors { 9 | AnchorHelper anchorHelper; 10 | 11 | private static class AnchorHelper { 12 | 13 | private Integer[] anchors; 14 | 15 | public AnchorHelper(Integer[] anchor) { 16 | this.anchors = anchor; 17 | } 18 | 19 | public int next(int index) { 20 | return anchors[index + 1]; 21 | } 22 | 23 | public int prev(int index) { 24 | return anchors[index - 1]; 25 | } 26 | 27 | public int pos(int index) { 28 | return anchors[index]; 29 | } 30 | 31 | public int sectionFromInf(int position) { 32 | int section = 0; 33 | for (int i = 0; i < anchors.length - 1; i++) { 34 | if (anchors[i] > position) { 35 | section = i; 36 | break; 37 | } 38 | } 39 | 40 | return section; 41 | } 42 | 43 | public int sectionFromSup(int position) { 44 | int section = 0; 45 | for (int i = anchors.length - 1; i >= 0; i--) { 46 | if (anchors[i] < position) { 47 | section = i; 48 | break; 49 | } 50 | } 51 | 52 | return section; 53 | } 54 | 55 | public int size() { 56 | return anchors.length; 57 | } 58 | 59 | public int getSupLimit() { 60 | return anchors[anchors.length - 1]; 61 | } 62 | 63 | public int getInfLimit() { 64 | return anchors[0]; 65 | } 66 | 67 | public static int distance(int init, int end) { 68 | return Math.abs(init - end); 69 | } 70 | } 71 | 72 | private Anchors(Integer[] anchor) { 73 | this.anchorHelper = new AnchorHelper(anchor); 74 | } 75 | 76 | public static Anchors make(Integer[] anchors) { 77 | if (anchors.length < 2) { 78 | throw new IllegalArgumentException("Amount of anchor points provided to SwipeLayout have to be bigger than 2"); 79 | } 80 | Arrays.sort(anchors); 81 | return new Anchors(anchors); 82 | } 83 | 84 | /** 85 | * Gives the amount of anchors that are set. 86 | * @return amount of anchors. 87 | */ 88 | public int size() { 89 | return anchorHelper.size(); 90 | } 91 | 92 | /** 93 | * Gives distance relative (1%) within the superior limit and the 94 | * Inferior limit from the inferior limit. 95 | * @param x point from where to get relative distance 96 | * @return 1% from inf limit 97 | */ 98 | public float distance(int x) { 99 | return distance(x, anchorHelper.getSupLimit(), anchorHelper.getInfLimit()); 100 | } 101 | 102 | /** 103 | * Gives distance relative (1%) within the superior Section limit and the 104 | * Inferior Section limit from the inferior limit. 105 | * @param x point from where to get relative distance 106 | * @return 1% from inf limit 107 | */ 108 | 109 | public float distance(int section, int x) { 110 | return distance(x, anchorHelper.next(section), anchorHelper.pos(section)); 111 | } 112 | 113 | private float distance(int x, int limitSup, int limitInf) { 114 | return (float) (x - limitInf) / (limitSup - limitInf); 115 | } 116 | 117 | public int anchorFor(int section) { 118 | return anchorHelper.pos(section); 119 | } 120 | 121 | public int sectionFor(int position) { 122 | if ((position > anchorHelper.getSupLimit()) || (position < anchorHelper.getInfLimit())) { 123 | throw new IllegalArgumentException("position exceed limits"); 124 | } 125 | return anchorHelper.sectionFromSup(position); 126 | } 127 | 128 | public int closeTo(int section, int point) { 129 | int distInf = AnchorHelper.distance(point, anchorHelper.pos(section)); 130 | int distSup = AnchorHelper.distance(point, anchorHelper.next(section)); 131 | if (distInf < distSup) { 132 | return anchorHelper.pos(section); 133 | } 134 | return anchorHelper.next(section); 135 | } 136 | 137 | public int cropInLimits(int x) { 138 | int inBounds = x; 139 | if (x < anchorHelper.getInfLimit()) { 140 | inBounds = anchorHelper.getInfLimit(); 141 | } else if (x > anchorHelper.getSupLimit()) { 142 | inBounds = anchorHelper.getSupLimit(); 143 | } 144 | return inBounds; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/adapter/RightSwipeAdapter.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.adapter; 2 | 3 | import android.content.Context; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.squareup.picasso.Picasso; 12 | 13 | import java.util.List; 14 | 15 | import apps.xenione.com.swipelayout.R; 16 | import apps.xenione.com.swipelayout.example.data.Album; 17 | import apps.xenione.com.swipelayout.example.swipe.RightCoordinatorLayout; 18 | 19 | /** 20 | * Created by Eugeni on 10/04/2016. 21 | */ 22 | public class RightSwipeAdapter extends RecyclerView.Adapter { 23 | 24 | public interface OnItemDismissListener { 25 | void onItemDismissed(Album album); 26 | } 27 | 28 | public interface OnItemSelectListener { 29 | void onItemSelected(Album album); 30 | } 31 | 32 | private List mAlbums; 33 | private OnItemDismissListener mOnItemDismissListener; 34 | private OnItemSelectListener mOnItemSelectListener; 35 | 36 | public RightSwipeAdapter(List albums) { 37 | this.mAlbums = albums; 38 | } 39 | 40 | @Override 41 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 42 | return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_right_swipe, parent, false)); 43 | } 44 | 45 | @Override 46 | public void onBindViewHolder(ViewHolder holder, int position) { 47 | Context context = holder.itemView.getContext(); 48 | Album album = getItem(position); 49 | Picasso.with(context).load(album.getResource()).placeholder(R.color.placeholder).into(holder.discImage); 50 | holder.foreground.setOnClickListener(new OnItemSelectedClick(album)); 51 | holder.coordinatorLayout.setOnDismissListener(new OnItemDismiss(album)); 52 | holder.title.setText(album.getName()); 53 | holder.bandName.setText(album.getBandName()); 54 | } 55 | 56 | @Override 57 | public void onViewRecycled(ViewHolder holder) { 58 | super.onViewRecycled(holder); 59 | holder.coordinatorLayout.sync(); 60 | } 61 | 62 | @Override 63 | public int getItemCount() { 64 | return mAlbums.size(); 65 | } 66 | 67 | public void deleteItem(Album album) { 68 | int index = mAlbums.indexOf(album); 69 | if (index == -1) { 70 | return; 71 | } 72 | mAlbums.remove(index); 73 | notifyItemRemoved(index); 74 | notifyItemRangeChanged(index, getItemCount()); 75 | } 76 | 77 | 78 | private Album getItem(int position) { 79 | return mAlbums.get(position); 80 | } 81 | 82 | public void setOnItemDismissListener(OnItemDismissListener listener) { 83 | mOnItemDismissListener = listener; 84 | } 85 | 86 | public void setOnItemItemSelectListener(OnItemSelectListener listener) { 87 | mOnItemSelectListener = listener; 88 | } 89 | 90 | public class OnItemDismiss implements RightCoordinatorLayout.OnDismissListener { 91 | 92 | private Album album; 93 | 94 | public OnItemDismiss(Album album) { 95 | this.album = album; 96 | } 97 | 98 | @Override 99 | public void onDismissed() { 100 | if (mOnItemDismissListener != null) { 101 | mOnItemDismissListener.onItemDismissed(album); 102 | } 103 | } 104 | } 105 | 106 | private class OnItemSelectedClick implements View.OnClickListener{ 107 | 108 | private Album album; 109 | 110 | public OnItemSelectedClick(Album album) { 111 | this.album = album; 112 | } 113 | 114 | @Override 115 | public void onClick(View v) { 116 | if (mOnItemDismissListener != null) { 117 | mOnItemSelectListener.onItemSelected(album); 118 | } 119 | } 120 | } 121 | 122 | public static class ViewHolder extends RecyclerView.ViewHolder { 123 | public TextView title; 124 | public TextView bandName; 125 | public ImageView discImage; 126 | public View foreground; 127 | public RightCoordinatorLayout coordinatorLayout; 128 | 129 | public ViewHolder(final View view) { 130 | super(view); 131 | coordinatorLayout = (RightCoordinatorLayout) view; 132 | title = view.findViewById(R.id.title); 133 | bandName = view.findViewById(R.id.bandName); 134 | discImage = view.findViewById(R.id.bg_disc); 135 | foreground = view.findViewById(R.id.foregroundView); 136 | } 137 | } 138 | } -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/fragment/VerticalSwipeFragment.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.fragment; 2 | 3 | import android.os.Bundle; 4 | import androidx.annotation.Nullable; 5 | import androidx.fragment.app.Fragment; 6 | import androidx.fragment.app.FragmentManager; 7 | import androidx.fragment.app.FragmentStatePagerAdapter; 8 | import androidx.viewpager.widget.ViewPager; 9 | import android.text.Html; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.ImageView; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.squareup.picasso.Picasso; 18 | 19 | import apps.xenione.com.swipelayout.R; 20 | import apps.xenione.com.swipelayout.example.data.Album; 21 | 22 | /** 23 | * Created by Eugeni on 13/04/2016. 24 | */ 25 | public class VerticalSwipeFragment extends Fragment { 26 | 27 | public static final String TAG = "VerticalSwipeFragment"; 28 | 29 | private final static String ALBUM_ARG = "album_arg"; 30 | 31 | public static Fragment newInstance() { 32 | return new VerticalSwipeFragment(); 33 | } 34 | 35 | ViewPager viewPager; 36 | 37 | @Nullable 38 | @Override 39 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 40 | View view = inflater.inflate(R.layout.fragment_vertical_swipe, container, false); 41 | viewPager = view.findViewById(R.id.pager); 42 | initViews(); 43 | return view; 44 | } 45 | 46 | private void initViews() { 47 | viewPager.setAdapter(new AlbumPagerAdapter(getChildFragmentManager())); 48 | } 49 | 50 | @Override 51 | public void onDestroyView() { 52 | super.onDestroyView(); 53 | } 54 | 55 | private static class AlbumPagerAdapter extends FragmentStatePagerAdapter { 56 | 57 | public AlbumPagerAdapter(FragmentManager fm) { 58 | super(fm); 59 | } 60 | 61 | @Override 62 | public Fragment getItem(int position) { 63 | return AlbumFragment.newInstance(Album.getAlbum().get(position)); 64 | } 65 | 66 | @Override 67 | public int getCount() { 68 | return Album.getAlbum().size(); 69 | } 70 | } 71 | 72 | public static class AlbumFragment extends Fragment { 73 | 74 | public static Fragment newInstance(Album album) { 75 | Fragment fragment = new AlbumFragment(); 76 | Bundle bundle = new Bundle(); 77 | bundle.putSerializable(ALBUM_ARG, album); 78 | fragment.setArguments(bundle); 79 | return fragment; 80 | } 81 | 82 | TextView titleTV; 83 | TextView bandNameTV; 84 | ImageView discBg; 85 | TextView bodyText; 86 | 87 | private Album getAlbumArg() { 88 | return (Album) getArguments().getSerializable(ALBUM_ARG); 89 | } 90 | 91 | @Nullable 92 | @Override 93 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 94 | View view = inflater.inflate(R.layout.fragment_vertical_swipe_page, container, false); 95 | titleTV = view.findViewById(R.id.title); 96 | bandNameTV = view.findViewById(R.id.bandName); 97 | discBg = view.findViewById(R.id.bg_disc); 98 | bodyText = view.findViewById(R.id.body_text); 99 | 100 | view.findViewById(R.id.delete).setOnClickListener(new View.OnClickListener() { 101 | @Override 102 | public void onClick(View v) { 103 | Toast.makeText(getActivity(), getString(R.string.delete_label), Toast.LENGTH_LONG).show(); 104 | } 105 | }); 106 | 107 | view.findViewById(R.id.action).setOnClickListener(new View.OnClickListener() { 108 | @Override 109 | public void onClick(View v) { 110 | Toast.makeText(getActivity(), getString(R.string.action_label), Toast.LENGTH_LONG).show(); 111 | } 112 | }); 113 | 114 | 115 | initViews(); 116 | return view; 117 | } 118 | 119 | public void initViews() { 120 | Album album = getAlbumArg(); 121 | titleTV.setText(album.getName()); 122 | bandNameTV.setText(album.getBandName()); 123 | Picasso.with(getContext()).load(album.getResource()).placeholder(R.color.placeholder).into(discBg); 124 | bodyText.setText(Html.fromHtml(album.getDescription())); 125 | } 126 | 127 | @Override 128 | public void onDestroyView() { 129 | super.onDestroyView(); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/adapter/HalfRightSwipeAdapter.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example.adapter; 2 | 3 | import android.content.Context; 4 | import androidx.recyclerview.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.squareup.picasso.Picasso; 12 | 13 | import java.util.List; 14 | 15 | import apps.xenione.com.swipelayout.R; 16 | import apps.xenione.com.swipelayout.example.data.Album; 17 | import apps.xenione.com.swipelayout.example.swipe.HalfRightCoordinatorLayout; 18 | 19 | /** 20 | * Created by Eugeni on 10/04/2016. 21 | */ 22 | public class HalfRightSwipeAdapter extends RecyclerView.Adapter { 23 | 24 | public interface OnItemDismissListener { 25 | void onItemDismissed(Album album); 26 | } 27 | 28 | public interface OnItemSelectListener { 29 | void onItemSelected(Album album); 30 | } 31 | 32 | private List mAlbums; 33 | private OnItemDismissListener mOnItemDismissListener; 34 | private OnItemSelectListener mOnItemSelectListener; 35 | 36 | public HalfRightSwipeAdapter(List albums) { 37 | this.mAlbums = albums; 38 | } 39 | 40 | @Override 41 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 42 | return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_half_right_swipe, parent, false)); 43 | } 44 | 45 | @Override 46 | public void onBindViewHolder(ViewHolder holder, int position) { 47 | Context context = holder.itemView.getContext(); 48 | Album album = getItem(position); 49 | Picasso.with(context).load(album.getResource()).placeholder(R.color.placeholder).into(holder.discImage); 50 | holder.foreground.setOnClickListener(new OnItemSelectedClick(album)); 51 | holder.title.setText(album.getName()); 52 | holder.bandName.setText(album.getBandName()); 53 | holder.delete.setOnClickListener(new OnItemDismiss(album)); 54 | } 55 | 56 | @Override 57 | public void onViewRecycled(ViewHolder holder) { 58 | super.onViewRecycled(holder); 59 | holder.coordinatorLayout.sync(); 60 | } 61 | 62 | @Override 63 | public int getItemCount() { 64 | return mAlbums.size(); 65 | } 66 | 67 | public void deleteItem(Album album) { 68 | int index = mAlbums.indexOf(album); 69 | if (index == -1) { 70 | return; 71 | } 72 | mAlbums.remove(index); 73 | notifyItemRemoved(index); 74 | notifyItemRangeChanged(index, getItemCount()); 75 | } 76 | 77 | 78 | private Album getItem(int position) { 79 | return mAlbums.get(position); 80 | } 81 | 82 | public void setOnItemDismissListener(OnItemDismissListener listener) { 83 | mOnItemDismissListener = listener; 84 | } 85 | 86 | public void setOnItemItemSelectListener(OnItemSelectListener listener) { 87 | mOnItemSelectListener = listener; 88 | } 89 | 90 | public class OnItemDismiss implements View.OnClickListener { 91 | 92 | private Album album; 93 | 94 | public OnItemDismiss(Album album) { 95 | this.album = album; 96 | } 97 | 98 | @Override 99 | public void onClick(View v) { 100 | if (mOnItemDismissListener != null) { 101 | mOnItemDismissListener.onItemDismissed(album); 102 | } 103 | } 104 | } 105 | 106 | private class OnItemSelectedClick implements View.OnClickListener{ 107 | 108 | private Album album; 109 | 110 | public OnItemSelectedClick(Album album) { 111 | this.album = album; 112 | } 113 | 114 | @Override 115 | public void onClick(View v) { 116 | if (mOnItemSelectListener != null) { 117 | mOnItemSelectListener.onItemSelected(album); 118 | } 119 | } 120 | } 121 | 122 | public static class ViewHolder extends RecyclerView.ViewHolder { 123 | 124 | public TextView title; 125 | public TextView bandName; 126 | public ImageView discImage; 127 | public View delete; 128 | public HalfRightCoordinatorLayout coordinatorLayout; 129 | public View foreground; 130 | 131 | public ViewHolder(View view) { 132 | super(view); 133 | coordinatorLayout = (HalfRightCoordinatorLayout) view; 134 | title = view.findViewById(R.id.title); 135 | bandName = view.findViewById(R.id.bandName); 136 | discImage = view.findViewById(R.id.bg_disc); 137 | delete = view.findViewById(R.id.backgroundView); 138 | foreground = view.findViewById(R.id.foregroundView); 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /swipemaker/src/test/java/com/xenione/libs/swipemaker/SwipeLayoutTest.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | /* 3 | Copyright 07/06/2017 Eugeni Josep Senent i Gabriel 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | import android.content.Context; 19 | import android.view.MotionEvent; 20 | import android.view.View; 21 | 22 | import com.xenione.libs.swipemaker.orientation.OrientationStrategy; 23 | import com.xenione.libs.swipemaker.orientation.OrientationStrategyFactory; 24 | 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.junit.runner.RunWith; 28 | import org.junit.runners.JUnit4; 29 | 30 | import static org.hamcrest.MatcherAssert.assertThat; 31 | import static org.hamcrest.core.IsInstanceOf.instanceOf; 32 | import static org.mockito.Mockito.mock; 33 | import static org.mockito.Mockito.verify; 34 | import static org.mockito.Mockito.verifyNoMoreInteractions; 35 | 36 | 37 | @RunWith(JUnit4.class) 38 | public class SwipeLayoutTest { 39 | 40 | private SwipeLayout swipeLayout; 41 | private OrientationStrategy orientationStrategy; 42 | 43 | @Before 44 | public void setup() { 45 | Context mockContext = mock(Context.class); 46 | swipeLayout = new SwipeLayout(mockContext); 47 | orientationStrategy = mock(OrientationStrategy.class); 48 | OrientationStrategyFactory orientationStrategyFactory = new OrientationStrategyFactory() { 49 | @Override 50 | public OrientationStrategy make(View view) { 51 | return orientationStrategy; 52 | } 53 | }; 54 | swipeLayout.setOrientation(orientationStrategyFactory); 55 | verifyNoMoreInteractions(orientationStrategy); 56 | } 57 | 58 | @Test 59 | public void whenOnInterceptTouchEvent_forwardToOrientationStrategy() { 60 | MotionEvent event = mock(MotionEvent.class); 61 | swipeLayout.onInterceptTouchEvent(event); 62 | verify(orientationStrategy).onInterceptTouchEvent(event); 63 | verifyNoMoreInteractions(orientationStrategy); 64 | } 65 | 66 | @Test 67 | public void whenOnTouchEvent_forwardToOrientationStrategy() { 68 | MotionEvent event = mock(MotionEvent.class); 69 | swipeLayout.onTouchEvent(event); 70 | verify(orientationStrategy).onTouchEvent(event); 71 | verifyNoMoreInteractions(orientationStrategy); 72 | } 73 | 74 | @Test 75 | public void whenStartWith_forwardToOrientationStrategy() { 76 | swipeLayout.startWith(0); 77 | verify(orientationStrategy).startWith(0); 78 | verifyNoMoreInteractions(orientationStrategy); 79 | } 80 | 81 | @Test 82 | public void whenSetAnchor_forwardToOrientationStrategy() { 83 | Integer[] anchors = new Integer[]{9}; 84 | swipeLayout.anchor(anchors); 85 | verify(orientationStrategy).setAnchor(anchors); 86 | verifyNoMoreInteractions(orientationStrategy); 87 | } 88 | 89 | @Test 90 | public void whenTranslateTo_forwardToOrientationStrategy() { 91 | swipeLayout.translateTo(0); 92 | verify(orientationStrategy).translateTo(0); 93 | verifyNoMoreInteractions(orientationStrategy); 94 | } 95 | 96 | @Test 97 | public void whenSetOnTranslateChangeListener_forwardToOrientationStrategy() { 98 | SwipeLayout.OnTranslateChangeListener listener = new SwipeLayout.OnTranslateChangeListener() { 99 | @Override 100 | public void onTranslateChange(float globalPercent, int index, float relativePercent) { 101 | 102 | } 103 | }; 104 | swipeLayout.setOnTranslateChangeListener(listener); 105 | verify(orientationStrategy).setOnTranslateChangeListener(listener); 106 | verifyNoMoreInteractions(orientationStrategy); 107 | } 108 | 109 | @Test 110 | public void whenGetOnTheOrientationHorizontalEnum_getTheCorrectFactory() { 111 | SwipeLayout.Orientation orientation = SwipeLayout.Orientation.HORIZONTAL; 112 | assertThat(orientation.get(),instanceOf(SwipeLayout.HorizontalOrientationStrategyFactory.class)); 113 | } 114 | 115 | @Test 116 | public void whenGetOnTheOrientationVerticalEnum_getTheCorrectFactory() { 117 | SwipeLayout.Orientation orientation = SwipeLayout.Orientation.VERTICAL; 118 | assertThat(orientation.get(),instanceOf(SwipeLayout.VerticalOrientationStrategyFactory.class)); 119 | } 120 | 121 | 122 | 123 | 124 | 125 | } 126 | -------------------------------------------------------------------------------- /swipemaker/src/test/java/com/xenione/libs/swipemaker/VerticalOrientationStrategyTest.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | /* 3 | Copyright 05/06/2017 Eugeni Josep Senent i Gabriel 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | import android.view.MotionEvent; 19 | import android.view.View; 20 | import android.view.ViewParent; 21 | 22 | import com.xenione.libs.swipemaker.orientation.VerticalOrientationStrategy; 23 | 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.junit.runners.JUnit4; 28 | import org.mockito.Mockito; 29 | 30 | import static org.hamcrest.CoreMatchers.is; 31 | import static org.hamcrest.MatcherAssert.assertThat; 32 | import static org.mockito.ArgumentMatchers.anyInt; 33 | import static org.mockito.Mockito.mock; 34 | import static org.mockito.Mockito.never; 35 | import static org.mockito.Mockito.verify; 36 | import static org.mockito.Mockito.when; 37 | 38 | @RunWith(JUnit4.class) 39 | public class VerticalOrientationStrategyTest { 40 | 41 | final int touchSlop = 50; 42 | private View view; 43 | private ViewParent parent; 44 | private VerticalOrientationStrategy vOStrategy; 45 | 46 | @Before 47 | public void setup() { 48 | view = mock(View.class); 49 | parent = mock(ViewParent.class); 50 | when(view.getParent()).thenReturn(parent); 51 | vOStrategy = new VerticalOrientationStrategy(view, touchSlop); 52 | } 53 | 54 | @Test 55 | public void whenSlideGesture_ShouldDisableParentInterceptTouch() { 56 | applySlideGesture(); 57 | Mockito.verify(parent).requestDisallowInterceptTouchEvent(true); 58 | } 59 | 60 | @Test 61 | public void whenSlideGesture_ShouldForwardToOnTouchEvent() { 62 | boolean intercept = applySlideGesture(); 63 | assertThat(intercept, is(Boolean.TRUE)); 64 | } 65 | 66 | @Test 67 | public void whenCancelTouch_ShouldEnableParentInterceptTouch() { 68 | applySlideGesture(); 69 | 70 | MotionEvent eventCancel = mock(MotionEvent.class); 71 | when(eventCancel.getAction()).thenReturn(MotionEvent.ACTION_CANCEL); 72 | when(eventCancel.getY()).thenReturn(0f); 73 | vOStrategy.onTouchEvent(eventCancel); 74 | 75 | Mockito.verify(parent).requestDisallowInterceptTouchEvent(false); 76 | } 77 | 78 | @Test 79 | public void whenSlideGesture_ShouldViewTranslate() { 80 | applySlideGesture(); 81 | 82 | MotionEvent eventDrag = mock(MotionEvent.class); 83 | when(eventDrag.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 84 | when(eventDrag.getY()).thenReturn(100f); 85 | vOStrategy.onTouchEvent(eventDrag); 86 | 87 | Mockito.verify(view).setTranslationY(49f); 88 | } 89 | 90 | @Test 91 | public void whenSlideGestureAndThenNoIncreaseTouch_ShouldViewTranslateWithZero() { 92 | applySlideGesture(); 93 | 94 | MotionEvent eventDrag = mock(MotionEvent.class); 95 | when(eventDrag.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 96 | when(eventDrag.getY()).thenReturn(touchSlop + 1f); 97 | vOStrategy.onTouchEvent(eventDrag); 98 | 99 | Mockito.verify(view, never()).setTranslationX(anyInt()); 100 | } 101 | 102 | @Test 103 | public void whenSlideGesture_ShouldNotifyChangePositionToListener() { 104 | applySlideGesture(); 105 | 106 | MotionEvent eventDrag = mock(MotionEvent.class); 107 | when(eventDrag.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 108 | when(eventDrag.getY()).thenReturn(100f); 109 | 110 | SwipeLayout.OnTranslateChangeListener listener = mock(SwipeLayout.OnTranslateChangeListener.class); 111 | vOStrategy.setAnchor(0, 100); 112 | vOStrategy.setOnTranslateChangeListener(listener); 113 | vOStrategy.onTouchEvent(eventDrag); 114 | 115 | verify(listener).onTranslateChange(0.49f, 0, 0.49f); 116 | } 117 | 118 | @Test(expected=IllegalArgumentException.class) 119 | public void whenSetLessThanTwoAnchors_ShouldThrowAnException() { 120 | vOStrategy.setAnchor(0); 121 | } 122 | 123 | private boolean applySlideGesture(){ 124 | MotionEvent eventDown = mock(MotionEvent.class); 125 | when(eventDown.getAction()).thenReturn(MotionEvent.ACTION_DOWN); 126 | when(eventDown.getY()).thenReturn(0f); 127 | vOStrategy.onInterceptTouchEvent(eventDown); 128 | 129 | MotionEvent eventMove = mock(MotionEvent.class); 130 | when(eventMove.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 131 | when(eventMove.getY()).thenReturn(touchSlop + 1f); 132 | return vOStrategy.onInterceptTouchEvent(eventMove); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /swipemaker/src/test/java/com/xenione/libs/swipemaker/HorizontalOrientationStrategyTest.java: -------------------------------------------------------------------------------- 1 | package com.xenione.libs.swipemaker; 2 | /* 3 | Copyright 05/06/2017 Eugeni Josep Senent i Gabriel 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | import android.view.MotionEvent; 19 | import android.view.View; 20 | import android.view.ViewParent; 21 | 22 | import com.xenione.libs.swipemaker.orientation.HorizontalOrientationStrategy; 23 | 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.junit.runners.JUnit4; 28 | import org.mockito.Mockito; 29 | 30 | import static org.hamcrest.CoreMatchers.is; 31 | import static org.hamcrest.MatcherAssert.assertThat; 32 | import static org.mockito.ArgumentMatchers.anyInt; 33 | import static org.mockito.Mockito.mock; 34 | import static org.mockito.Mockito.never; 35 | import static org.mockito.Mockito.verify; 36 | import static org.mockito.Mockito.when; 37 | 38 | @RunWith(JUnit4.class) 39 | public class HorizontalOrientationStrategyTest { 40 | 41 | final int touchSlop = 50; 42 | private View view; 43 | private ViewParent parent; 44 | private HorizontalOrientationStrategy hOStrategy; 45 | 46 | @Before 47 | public void setup() { 48 | view = mock(View.class); 49 | parent = mock(ViewParent.class); 50 | when(view.getParent()).thenReturn(parent); 51 | hOStrategy = new HorizontalOrientationStrategy(view, touchSlop); 52 | } 53 | 54 | @Test 55 | public void whenSlideGesture_ShouldDisableParentInterceptTouch() { 56 | applySlideGesture(); 57 | Mockito.verify(parent).requestDisallowInterceptTouchEvent(true); 58 | } 59 | 60 | @Test 61 | public void whenSlideGesture_ShouldForwardToOnTouchEvent() { 62 | boolean intercept = applySlideGesture(); 63 | assertThat(intercept, is(Boolean.TRUE)); 64 | } 65 | 66 | @Test 67 | public void whenCancelTouch_ShouldEnableParentInterceptTouch() { 68 | applySlideGesture(); 69 | 70 | MotionEvent eventCancel = mock(MotionEvent.class); 71 | when(eventCancel.getAction()).thenReturn(MotionEvent.ACTION_CANCEL); 72 | when(eventCancel.getX()).thenReturn(0f); 73 | hOStrategy.onTouchEvent(eventCancel); 74 | 75 | Mockito.verify(parent).requestDisallowInterceptTouchEvent(false); 76 | } 77 | 78 | @Test 79 | public void whenSlideGesture_ShouldViewTranslate() { 80 | applySlideGesture(); 81 | 82 | MotionEvent eventDrag = mock(MotionEvent.class); 83 | when(eventDrag.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 84 | when(eventDrag.getX()).thenReturn(100f); 85 | hOStrategy.onTouchEvent(eventDrag); 86 | 87 | Mockito.verify(view).setTranslationX(49f); 88 | } 89 | 90 | @Test 91 | public void whenSlideGestureAndThenNoIncreaseTouch_ShouldViewTranslateWithZero() { 92 | applySlideGesture(); 93 | 94 | MotionEvent eventDrag = mock(MotionEvent.class); 95 | when(eventDrag.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 96 | when(eventDrag.getX()).thenReturn(touchSlop + 1f); 97 | hOStrategy.onTouchEvent(eventDrag); 98 | 99 | Mockito.verify(view, never()).setTranslationX(anyInt()); 100 | } 101 | 102 | @Test 103 | public void whenSlideGesture_ShouldNotifyChangePositionToListener() { 104 | applySlideGesture(); 105 | 106 | MotionEvent eventDrag = mock(MotionEvent.class); 107 | when(eventDrag.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 108 | when(eventDrag.getX()).thenReturn(100f); 109 | 110 | SwipeLayout.OnTranslateChangeListener listener = mock(SwipeLayout.OnTranslateChangeListener.class); 111 | hOStrategy.setAnchor(0, 100); 112 | hOStrategy.setOnTranslateChangeListener(listener); 113 | hOStrategy.onTouchEvent(eventDrag); 114 | 115 | verify(listener).onTranslateChange(0.49f, 0, 0.49f); 116 | } 117 | 118 | @Test(expected=IllegalArgumentException.class) 119 | public void whenSetLessThanTwoAnchors_ShouldThrowAnException() { 120 | hOStrategy.setAnchor(0); 121 | } 122 | 123 | private boolean applySlideGesture(){ 124 | MotionEvent eventDown = mock(MotionEvent.class); 125 | when(eventDown.getAction()).thenReturn(MotionEvent.ACTION_DOWN); 126 | when(eventDown.getX()).thenReturn(0f); 127 | hOStrategy.onInterceptTouchEvent(eventDown); 128 | 129 | MotionEvent eventMove = mock(MotionEvent.class); 130 | when(eventMove.getAction()).thenReturn(MotionEvent.ACTION_MOVE); 131 | when(eventMove.getX()).thenReturn(touchSlop + 1f); 132 | return hOStrategy.onInterceptTouchEvent(eventMove); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /app/src/main/java/apps/xenione/com/swipelayout/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package apps.xenione.com.swipelayout.example; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import com.google.android.material.navigation.NavigationView; 6 | import androidx.fragment.app.Fragment; 7 | import androidx.fragment.app.FragmentManager; 8 | import androidx.fragment.app.FragmentTransaction; 9 | import androidx.core.view.GravityCompat; 10 | import androidx.drawerlayout.widget.DrawerLayout; 11 | import androidx.appcompat.app.ActionBarDrawerToggle; 12 | import androidx.appcompat.app.AppCompatActivity; 13 | import androidx.appcompat.widget.Toolbar; 14 | import android.view.MenuItem; 15 | 16 | import apps.xenione.com.swipelayout.R; 17 | import apps.xenione.com.swipelayout.example.fragment.BothSideSwipeFragment; 18 | import apps.xenione.com.swipelayout.example.fragment.HalfRightDragFrictionSwipeFragment; 19 | import apps.xenione.com.swipelayout.example.fragment.HalfRightDragSwipeFragment; 20 | import apps.xenione.com.swipelayout.example.fragment.HalfRightSwipeFragment; 21 | import apps.xenione.com.swipelayout.example.fragment.RightSwipeFragment; 22 | import apps.xenione.com.swipelayout.example.fragment.SwingSwipeFragment; 23 | import apps.xenione.com.swipelayout.example.fragment.TwoStepRightSwipeFragment; 24 | import apps.xenione.com.swipelayout.example.fragment.VerticalSwipeFragment; 25 | 26 | public class MainActivity extends AppCompatActivity 27 | implements NavigationView.OnNavigationItemSelectedListener { 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_main); 33 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 34 | setSupportActionBar(toolbar); 35 | 36 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 37 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 38 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 39 | drawer.addDrawerListener(toggle); 40 | toggle.syncState(); 41 | 42 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 43 | navigationView.setNavigationItemSelectedListener(this); 44 | 45 | showFragment(RightSwipeFragment.newInstance(), RightSwipeFragment.TAG); 46 | navigationView.setCheckedItem(R.id.nav_rightswipe); 47 | } 48 | 49 | @Override 50 | public void onBackPressed() { 51 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 52 | if (drawer.isDrawerOpen(GravityCompat.START)) { 53 | drawer.closeDrawer(GravityCompat.START); 54 | } else { 55 | super.onBackPressed(); 56 | } 57 | } 58 | 59 | @SuppressWarnings("StatementWithEmptyBody") 60 | @Override 61 | public boolean onNavigationItemSelected(MenuItem item) { 62 | int id = item.getItemId(); 63 | 64 | switch(id){ 65 | case R.id.nav_rightswipe: { 66 | showFragment(RightSwipeFragment.newInstance(), RightSwipeFragment.TAG); 67 | break; 68 | } 69 | case R.id.nav_half_swipe: { 70 | showFragment(HalfRightSwipeFragment.newInstance(), HalfRightSwipeFragment.TAG); 71 | break; 72 | } 73 | case R.id.nav_two_step_swipe: { 74 | showFragment(TwoStepRightSwipeFragment.newInstance(), TwoStepRightSwipeFragment.TAG); 75 | break; 76 | } 77 | case R.id.nav_both_side_swipe: { 78 | showFragment(BothSideSwipeFragment.newInstance(), BothSideSwipeFragment.TAG); 79 | break; 80 | } 81 | case R.id.nav_right_drag_swipe: { 82 | showFragment(HalfRightDragSwipeFragment.newInstance(), HalfRightDragSwipeFragment.TAG); 83 | break; 84 | } 85 | case R.id.nav_right_drag_friction_swipe: { 86 | showFragment(HalfRightDragFrictionSwipeFragment.newInstance(), HalfRightDragFrictionSwipeFragment.TAG); 87 | break; 88 | } 89 | case R.id.nav_swing_swipe: { 90 | showFragment(SwingSwipeFragment.newInstance(), SwingSwipeFragment.TAG); 91 | break; 92 | } 93 | case R.id.nav_vertical_swipe: { 94 | showFragment(VerticalSwipeFragment.newInstance(), VerticalSwipeFragment.TAG); 95 | break; 96 | } 97 | case R.id.nav_share: { 98 | launchSharer(); 99 | break; 100 | } 101 | } 102 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 103 | drawer.closeDrawer(GravityCompat.START); 104 | return true; 105 | } 106 | 107 | private void showFragment(Fragment fragment, String tag) { 108 | FragmentManager fm = getSupportFragmentManager(); 109 | Fragment prevFragment = fm.findFragmentByTag(tag); 110 | if (prevFragment != null) { 111 | return; 112 | } 113 | FragmentTransaction tr = fm.beginTransaction(); 114 | tr.replace(R.id.fragment_container, fragment, tag) 115 | .commit(); 116 | } 117 | 118 | private void launchSharer() { 119 | Intent sendIntent = new Intent(); 120 | sendIntent.setAction(Intent.ACTION_SEND); 121 | sendIntent.putExtra(Intent.EXTRA_TEXT, "Hi, I found on google play that awesome swipe library at https://github.com/xenione/SwipeLayout. Have a look !!! "); 122 | sendIntent.setType("text/html"); 123 | startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to))); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Easy Swipe Maker 2 | 3 | [![Download](https://api.bintray.com/packages/xenione/maven/Swipe-maker/images/download.svg) ](https://bintray.com/xenione/maven/Swipe-maker/_latestVersion) 4 | [![CI](https://api.travis-ci.org/xenione/swipe-maker.svg?branch=develop) ](https://travis-ci.org/xenione/swipe-maker) 5 | [![Coverage Status](https://coveralls.io/repos/github/xenione/swipe-maker/badge.svg?branch=develop)](https://coveralls.io/github/xenione/swipe-maker?branch=develop) 6 | [![Counter Download](https://img.shields.io/badge/dowloads-13%2C5k-green.svg)](https://bintray.com/xenione/maven/Swipe-maker#statistics) 7 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Easy%20Swipe%20Maker-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5020) 8 | 9 | 10 | [![Code Sponsor](https://app.codesponsor.io/embed/VijWTXcqR6TaovNHARAaH3XU/xenione/swipeMaker.svg)](https://app.codesponsor.io/link/VijWTXcqR6TaovNHARAaH3XU/xenione/swipe-maker) 11 | 12 | 13 | From the library to build your own swipeout item views. These examples will only take 5 minutes each. Have a look at the demos app available on [google play](https://play.google.com/store/apps/details?id=apps.xenione.com.swipelayout) (is not updated -NO Swing and Vertical swipe examples) 14 | 15 | This library is extrematly powerful since you can custom your own swipe effects "No limits for your imagination". Here you can find some examples: 16 | 17 | ## Example of a **Swipe of Swing** 18 | 19 | ![swing_swipe](https://cloud.githubusercontent.com/assets/4138527/21510499/6c44dd96-cc94-11e6-9cd5-c182c33d1b80.gif) 20 | 21 | ## Example of a **Swipe of Both Sides** 22 | 23 | ![both_side_swipe](https://cloud.githubusercontent.com/assets/4138527/14615552/8428c3e2-05a6-11e6-8b85-4627a6c79d87.gif) 24 | 25 | ## Example of **Drag Right Side Swipe** 26 | 27 | ![drag_swipe](https://cloud.githubusercontent.com/assets/4138527/14615553/8429c044-05a6-11e6-8d80-3d19d29e1a31.gif) 28 | 29 | ## Example of a **Two-steps Right Swipe** with amazing color change 30 | 31 | ![two_step_swipe](https://cloud.githubusercontent.com/assets/4138527/14615554/842ed408-05a6-11e6-8111-f11d91844031.gif) 32 | 33 | ### Are you ready? I'll show you how: 34 | 35 | Let's do this one (Right Side Swipe): 36 | 37 | ![screenshoot](https://cloud.githubusercontent.com/assets/4138527/14615699/3c94e41a-05a7-11e6-8cca-4e97219d63b9.png) 38 | 39 | Add it on your project: 40 | 41 | Gradle: 42 | ```java 43 | compile 'com.xenione.libs:swipe-maker:1.1.3' 44 | ``` 45 | 46 | 47 | 1.Extend AbsCoordinatorLayout and create your own Coordinator, in this case I called it HalfRightCoordinatorLayout 48 | 49 | ```java 50 | public class HalfRightCoordinatorLayout extends AbsCoordinatorLayout { 51 | ``` 52 | 53 | Override the doInitialViewsLocation() method. This hook arises when views are placed on the screen. Set anchors for the swipe widget. 54 | Anchors are the boundaries between swipe slides (look at the layout at the next point). We want that swipe slides within the button "mBackgroundView" boundaries. 55 | 56 | ```java 57 | @Override 58 | public void doInitialViewsLocation() { 59 | mForegroundView = (SwipeLayout) findViewById(R.id.foregroundView); 60 | mBackgroundView = findViewById(R.id.backgroundView); 61 | mForegroundView.anchor(mBackgroundView.getRight(), mBackgroundView.getLeft()); 62 | } 63 | 64 | ``` 65 | 2.Make your layout according to the previous point 66 | Note: SwipeLayout Id must be *@id/foregroundView* and Background View must be *@id/backgroundView* 67 | 68 | ```java 69 | 70 | 74 | 75 | 82 | 83 | 88 | 89 | 94 | 95 | 98 | 99 | 108 | 109 | 121 | 122 | 123 | 124 | 125 | 126 | ; 127 | ``` 128 | 3.Make your amazing transformations- Go back to your class inherited from AbsCoordinatorLayout (im our case HalfRightCoordinatorLayout ) and you have a hook called onTranslateChange(...). 129 | 130 | ```java 131 | @Override 132 | public void onTranslateChange(float global, int index, float relative) { 133 | } 134 | ``` 135 | 136 | where you can monitor swipe progress. 137 | 138 | The parameter descriptions are: 139 | 140 | **global**: give us percentage (1%: 0-1) :0 means left limit and 1 means right limit. 141 | 142 | **index** and **relative**: in case we have more than 1 section that would happened if we had given more than 2 anchor points (such as Two-step Swipe) 143 | 144 | **index**: is the index of the section (if we had got 3 anchor points we would have 2 sections: One from anchor 1 to 2 and the second from anchor 2 to 3) 145 | 146 | **relative**: gives us the precentage(1%: 0-1) within the index section. 147 | 148 | In our case we have only one section so we don't have to take care of that. 149 | So let's add a nice transition effect: 150 | 151 | ```java 152 | @Override 153 | public void onTranslateChange(float global, int index, float relative) { 154 | backgroundView.setAlpha(global); 155 | } 156 | ``` 157 | 158 | ## Other example of what you can do with Easy Swipe Maker 159 | 160 | ### Before-After Effect 161 | 162 | ![before_after_effect](https://cloud.githubusercontent.com/assets/4138527/19211444/9713cbdc-8d3c-11e6-84af-18a18ab02efb.gif) 163 | 164 | find out more at [github](https://github.com/xenione/BeforeAfterEffect) 165 | 166 | ## Last version v1.1.1 - Feature added: Allow vertical swipe. 167 | 168 | 169 | ![vertical swipe](https://cloud.githubusercontent.com/assets/4138527/19872352/93fbcf0a-9fb9-11e6-82b5-efee365bb2e8.gif) 170 | 171 | # License 172 | ------- 173 | 174 | Copyright 2016 Eugeni Josep Senent i Gabriel 175 | 176 | Licensed under the Apache License, Version 2.0 (the "License"); 177 | you may not use this file except in compliance with the License. 178 | You may obtain a copy of the License at 179 | 180 | http://www.apache.org/licenses/LICENSE-2.0 181 | 182 | Unless required by applicable law or agreed to in writing, software 183 | distributed under the License is distributed on an "AS IS" BASIS, 184 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 185 | See the License for the specific language governing permissions and 186 | limitations under the License. 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------