├── simple
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── img.jpg
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── img1.jpg
│ │ │ │ ├── img2.jpg
│ │ │ │ ├── img3.jpg
│ │ │ │ ├── img4.jpg
│ │ │ │ ├── img5.jpg
│ │ │ │ ├── pic1.jpeg
│ │ │ │ ├── pic2.jpg
│ │ │ │ ├── pic3.jpg
│ │ │ │ ├── pic4.jpeg
│ │ │ │ ├── pic5.jpg
│ │ │ │ ├── btn_love.png
│ │ │ │ ├── btn_loved.png
│ │ │ │ ├── btn_praise.png
│ │ │ │ ├── btn_share.png
│ │ │ │ ├── btn_download.png
│ │ │ │ ├── btn_praised.png
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── btn_downloaded.png
│ │ │ │ ├── ic_share_white_24dp.png
│ │ │ │ ├── ic_file_download_white_24dp.png
│ │ │ │ ├── ic_keyboard_tab_white_24dp.png
│ │ │ │ └── ic_favorite_border_white_24dp.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-v19
│ │ │ │ └── dimens.xml
│ │ │ ├── drawable
│ │ │ │ ├── sel_btn_love.xml
│ │ │ │ ├── sel_btn_praise.xml
│ │ │ │ └── sel_btn_download.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── menu
│ │ │ │ ├── menu_drag.xml
│ │ │ │ ├── menu_blur.xml
│ │ │ │ └── menu_animate.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── layout_toolbar.xml
│ │ │ │ ├── adapter_thumb.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_animate.xml
│ │ │ │ ├── activity_drag.xml
│ │ │ │ ├── activity_drag_outside.xml
│ │ │ │ └── activity_drag_blur.xml
│ │ ├── gen
│ │ │ └── com
│ │ │ │ └── dl7
│ │ │ │ └── simple
│ │ │ │ └── drag
│ │ │ │ ├── R.java
│ │ │ │ ├── Manifest.java
│ │ │ │ └── BuildConfig.java
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── dl7
│ │ │ │ └── simple
│ │ │ │ └── drag
│ │ │ │ ├── AnimateHelper.java
│ │ │ │ ├── adapter
│ │ │ │ ├── ThumbAdapter.java
│ │ │ │ ├── PhotoPagerAdapter.java
│ │ │ │ ├── BaseRecyclerAdapter.java
│ │ │ │ ├── DividerItemDecoration.java
│ │ │ │ └── DividerGridItemDecoration.java
│ │ │ │ ├── utils
│ │ │ │ ├── AnimateHelper.java
│ │ │ │ └── RecyclerViewHelper.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── activity
│ │ │ │ ├── BaseActivity.java
│ │ │ │ ├── DragBlurActivity.java
│ │ │ │ ├── DragActivity.java
│ │ │ │ ├── DragOutsideActivity.java
│ │ │ │ └── AnimateActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── dl7
│ │ │ └── simple
│ │ │ └── drag
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── dl7
│ │ └── simple
│ │ └── drag
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── dragsloplayout
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── dl7
│ │ │ └── drag
│ │ │ ├── animate
│ │ │ ├── CustomViewAnimator.java
│ │ │ ├── in
│ │ │ │ ├── FadeInAnimator.java
│ │ │ │ ├── FlipInXAnimator.java
│ │ │ │ ├── FlipInYAnimator.java
│ │ │ │ ├── SlideInBottomAnimator.java
│ │ │ │ ├── ZoomInAnimator.java
│ │ │ │ ├── SlideInLeftAnimator.java
│ │ │ │ ├── SlideInRightAnimator.java
│ │ │ │ ├── ZoomInLeftAnimator.java
│ │ │ │ └── ZoomInRightAnimator.java
│ │ │ ├── out
│ │ │ │ ├── FadeOutAnimator.java
│ │ │ │ ├── FlipOutXAnimator.java
│ │ │ │ ├── FlipOutYAnimator.java
│ │ │ │ ├── SlideOutLeftAnimator.java
│ │ │ │ ├── ZoomOutAnimator.java
│ │ │ │ ├── SlideOutRightAnimator.java
│ │ │ │ ├── SlideOutBottomAnimator.java
│ │ │ │ ├── ZoomOutLeftAnimator.java
│ │ │ │ └── ZoomOutRightAnimator.java
│ │ │ ├── BaseViewAnimator.java
│ │ │ └── AnimatorPresenter.java
│ │ │ ├── BitmapUtils.java
│ │ │ └── DragSlopLayout.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── dl7
│ │ │ └── drag
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── dl7
│ │ └── drag
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── bintray-publish.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/simple/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/dragsloplayout/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':dragsloplayout', ':simple'
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/dragsloplayout/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DragSlopLayout
3 |
4 |
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xhdpi/img.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xhdpi/img.jpg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/img1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/img1.jpg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/img2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/img2.jpg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/img3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/img3.jpg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/img4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/img4.jpg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/img5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/img5.jpg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/pic1.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/pic1.jpeg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/pic2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/pic2.jpg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/pic3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/pic3.jpg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/pic4.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/pic4.jpeg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/pic5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/pic5.jpg
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/btn_love.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/btn_love.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/btn_loved.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/btn_loved.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/btn_praise.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/btn_praise.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/btn_share.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/btn_share.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/btn_download.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/btn_download.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/btn_praised.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/btn_praised.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/simple/src/main/res/values-v19/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 24dp
5 |
6 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | /.idea/
10 |
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/btn_downloaded.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/btn_downloaded.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/ic_share_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/ic_share_white_24dp.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/ic_file_download_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/ic_file_download_white_24dp.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/ic_keyboard_tab_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/ic_keyboard_tab_white_24dp.png
--------------------------------------------------------------------------------
/simple/src/main/res/mipmap-xxhdpi/ic_favorite_border_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rukey7/DragSlopLayout/HEAD/simple/src/main/res/mipmap-xxhdpi/ic_favorite_border_white_24dp.png
--------------------------------------------------------------------------------
/simple/src/main/gen/com/dl7/simple/drag/R.java:
--------------------------------------------------------------------------------
1 | /*___Generated_by_IDEA___*/
2 |
3 | package com.dl7.simple.drag;
4 |
5 | /* This stub is only used by the IDE. It is NOT the R class actually packed into the APK */
6 | public final class R {
7 | }
--------------------------------------------------------------------------------
/simple/src/main/gen/com/dl7/simple/drag/Manifest.java:
--------------------------------------------------------------------------------
1 | /*___Generated_by_IDEA___*/
2 |
3 | package com.dl7.simple.drag;
4 |
5 | /* This stub is only used by the IDE. It is NOT the Manifest class actually packed into the APK */
6 | public final class Manifest {
7 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/simple/src/main/res/drawable/sel_btn_love.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/simple/src/main/res/drawable/sel_btn_praise.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/simple/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #44000000
7 |
8 |
--------------------------------------------------------------------------------
/simple/src/main/res/drawable/sel_btn_download.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/simple/src/main/res/menu/menu_drag.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/simple/src/main/gen/com/dl7/simple/drag/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /*___Generated_by_IDEA___*/
2 |
3 | package com.dl7.simple.drag;
4 |
5 | /* This stub is only used by the IDE. It is NOT the BuildConfig class actually packed into the APK */
6 | public final class BuildConfig {
7 | public final static boolean DEBUG = Boolean.parseBoolean(null);
8 | }
--------------------------------------------------------------------------------
/dragsloplayout/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/simple/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 | 50dp
7 |
8 |
9 | 0dp
10 |
11 |
--------------------------------------------------------------------------------
/simple/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/dragsloplayout/src/test/java/com/dl7/drag/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dl7.drag;
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 | }
--------------------------------------------------------------------------------
/simple/src/test/java/com/dl7/simple/drag/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag;
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 | }
--------------------------------------------------------------------------------
/dragsloplayout/src/androidTest/java/com/dl7/drag/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.dl7.drag;
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 | }
--------------------------------------------------------------------------------
/simple/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/simple/src/androidTest/java/com/dl7/simple/drag/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag;
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 | }
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/CustomViewAnimator.java:
--------------------------------------------------------------------------------
1 | package com.dl7.drag.animate;
2 |
3 | import android.animation.Animator;
4 | import android.view.View;
5 |
6 | /**
7 | * Created by long on 2016/9/12.
8 | * 自定义动画
9 | */
10 | public abstract class CustomViewAnimator extends BaseViewAnimator {
11 |
12 | @Override
13 | protected void prepare(View target) {
14 | mAnimatorSet.playTogether(doAnimator());
15 | }
16 |
17 | protected abstract Animator doAnimator();
18 | }
19 |
--------------------------------------------------------------------------------
/simple/src/main/res/menu/menu_blur.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/simple/src/main/res/layout/layout_toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/simple/src/main/res/layout/adapter_thumb.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/simple/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 F:\WorkTools\Android\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/dragsloplayout/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 F:\WorkTools\Android\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/dragsloplayout/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.Rukey7'
4 |
5 | android {
6 | compileSdkVersion 23
7 | buildToolsVersion "24.0.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 23
12 | versionCode 5
13 | versionName "1.0.5"
14 | renderscriptTargetApi 23
15 | renderscriptSupportModeEnabled true
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | testCompile 'junit:junit:4.12'
28 | compile 'com.android.support:appcompat-v7:23.4.0'
29 | }
30 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/AnimateHelper.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ObjectAnimator;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by long on 2016/9/27.
9 | * 动画帮助类
10 | */
11 | public final class AnimateHelper {
12 |
13 | private AnimateHelper() {
14 | throw new RuntimeException("AnimateHelper cannot be initialized!");
15 | }
16 |
17 | /**
18 | * 心跳动画
19 | * @param view 视图
20 | * @param duration 时间
21 | */
22 | public static void doHeartBeat(View view, int duration) {
23 | AnimatorSet set = new AnimatorSet();
24 | set.playTogether(
25 | ObjectAnimator.ofFloat(view, "scaleX", 1.0f, 1.4f, 0.9f, 1.0f),
26 | ObjectAnimator.ofFloat(view, "scaleY", 1.0f, 1.4f, 0.9f, 1.0f)
27 | );
28 | set.setDuration(duration);
29 | set.start();
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/BitmapUtils.java:
--------------------------------------------------------------------------------
1 | package com.dl7.drag;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.Matrix;
5 |
6 | /**
7 | * Bitmap工具类主要包括获取Bitmap和对Bitmap的操作
8 | */
9 | final public class BitmapUtils {
10 |
11 | /**
12 | * Don't let anyone instantiate this class.
13 | */
14 | private BitmapUtils() {
15 | throw new Error("Do not need instantiate!");
16 | }
17 |
18 | /**
19 | * 放大缩小图片
20 | *
21 | * @param bitmap 源Bitmap
22 | * @param w 宽
23 | * @param h 高
24 | * @return 目标Bitmap
25 | */
26 | public static Bitmap zoom(Bitmap bitmap, int w, int h) {
27 | int width = bitmap.getWidth();
28 | int height = bitmap.getHeight();
29 | Matrix matrix = new Matrix();
30 | float scaleWidht = ((float) w / width);
31 | float scaleHeight = ((float) h / height);
32 | matrix.postScale(scaleWidht, scaleHeight);
33 | Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height,
34 | matrix, true);
35 | return newbmp;
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/simple/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/simple/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'android-apt'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "24.0.2"
7 |
8 | defaultConfig {
9 | applicationId "com.dl7.simple.drag"
10 | minSdkVersion 14
11 | targetSdkVersion 23
12 | versionCode 1
13 | versionName "1.0"
14 | renderscriptTargetApi 23
15 | renderscriptSupportModeEnabled true
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(include: ['*.jar'], dir: 'libs')
27 | testCompile 'junit:junit:4.12'
28 | compile 'com.android.support:appcompat-v7:23.4.0'
29 | compile 'com.android.support:design:23.4.0'
30 | compile project(':dragsloplayout')
31 | // compile 'com.github.Rukey7:DragSlopLayout:1.0.2'
32 | // compile 'com.github.Rukey7:DragSlopLayout:1.0.2-blur'
33 | // photoview
34 | compile 'com.github.chrisbanes.photoview:library:1.2.4'
35 | // butterknife
36 | compile 'com.jakewharton:butterknife:8.4.0'
37 | apt 'com.jakewharton:butterknife-compiler:8.4.0'
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/adapter/ThumbAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 |
10 | import com.dl7.simple.drag.R;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by long on 2017/1/6.
16 | */
17 | public class ThumbAdapter extends BaseRecyclerAdapter {
18 |
19 | public ThumbAdapter(Context context) {
20 | super(context);
21 | }
22 |
23 | public ThumbAdapter(Context context, List datas) {
24 | super(context, datas);
25 | }
26 |
27 | @Override
28 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
29 | View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_thumb, parent, false);
30 | ViewHolder viewHolder = new ViewHolder(view);
31 | return viewHolder;
32 | }
33 |
34 | @Override
35 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
36 | ((ViewHolder)holder).ivPhoto.setImageResource(mDatas.get(position));
37 | }
38 |
39 | public static class ViewHolder extends RecyclerView.ViewHolder{
40 | public ImageView ivPhoto;
41 |
42 | public ViewHolder(View rootView) {
43 | super(rootView);
44 | this.ivPhoto = (ImageView) rootView.findViewById(R.id.iv_photo);
45 | }
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/simple/src/main/res/menu/menu_animate.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/in/FadeInAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.in;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class FadeInAnimator extends BaseViewAnimator {
34 | @Override
35 | public void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "alpha", 0, 1)
38 | );
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/out/FadeOutAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.out;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class FadeOutAnimator extends BaseViewAnimator {
34 | @Override
35 | public void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "alpha", 1, 0)
38 | );
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/out/FlipOutXAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.out;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class FlipOutXAnimator extends BaseViewAnimator {
34 | @Override
35 | public void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "rotationX", 0, 90),
38 | ObjectAnimator.ofFloat(target, "alpha", 1, 0)
39 | );
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/out/FlipOutYAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.out;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class FlipOutYAnimator extends BaseViewAnimator {
34 | @Override
35 | public void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "rotationY", 0, 90),
38 | ObjectAnimator.ofFloat(target, "alpha", 1, 0)
39 | );
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/in/FlipInXAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.in;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class FlipInXAnimator extends BaseViewAnimator {
34 | @Override
35 | public void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "rotationX", 90, -15, 15, 0),
38 | ObjectAnimator.ofFloat(target, "alpha", 0.25f, 0.5f, 0.75f, 1)
39 | );
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/in/FlipInYAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.in;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class FlipInYAnimator extends BaseViewAnimator {
34 | @Override
35 | public void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "rotationY", 90, -15, 15, 0),
38 | ObjectAnimator.ofFloat(target, "alpha", 0.25f, 0.5f, 0.75f, 1)
39 | );
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/in/SlideInBottomAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.in;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class SlideInBottomAnimator extends BaseViewAnimator {
34 | @Override
35 | public void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "alpha", 0, 1),
38 | ObjectAnimator.ofFloat(target, "translationY", target.getHeight(), 0)
39 | );
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/out/SlideOutLeftAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.out;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class SlideOutLeftAnimator extends BaseViewAnimator {
34 | @Override
35 | public void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "alpha", 1, 0),
38 | ObjectAnimator.ofFloat(target, "translationX", 0, -target.getRight())
39 | );
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/in/ZoomInAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.in;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class ZoomInAnimator extends BaseViewAnimator {
34 | @Override
35 | public void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "scaleX", 0.45f, 1),
38 | ObjectAnimator.ofFloat(target, "scaleY", 0.45f, 1),
39 | ObjectAnimator.ofFloat(target, "alpha", 0, 1)
40 | );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/utils/AnimateHelper.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.utils;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by long on 2017/1/5.
9 | */
10 |
11 | public final class AnimateHelper {
12 |
13 | private AnimateHelper() {
14 | throw new AssertionError();
15 | }
16 |
17 |
18 | /**
19 | * 垂直偏移动画
20 | * @param view
21 | * @param startY
22 | * @param endY
23 | * @param duration
24 | * @return
25 | */
26 | public static Animator doMoveVertical(View view, int startY, int endY, int duration) {
27 | ObjectAnimator animator = ObjectAnimator.ofFloat(view, "translationY", startY, endY).setDuration(duration);
28 | animator.start();
29 | return animator;
30 | }
31 |
32 |
33 | /**
34 | * 动画是否在运行
35 | * @param animator
36 | */
37 | public static boolean isRunning(Animator animator) {
38 | return animator != null && animator.isRunning();
39 | }
40 |
41 | /**
42 | * 启动动画
43 | * @param animator
44 | */
45 | public static void startAnimator(Animator animator) {
46 | if (animator != null && !animator.isRunning()) {
47 | animator.start();
48 | }
49 | }
50 |
51 | /**
52 | * 停止动画
53 | * @param animator
54 | */
55 | public static void stopAnimator(Animator animator) {
56 | if (animator != null && animator.isRunning()) {
57 | animator.cancel();
58 | }
59 | }
60 |
61 | /**
62 | * 删除动画
63 | * @param animator
64 | */
65 | public static void deleteAnimator(Animator animator) {
66 | if (animator != null && animator.isRunning()) {
67 | animator.cancel();
68 | }
69 | animator = null;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/out/ZoomOutAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.out;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 |
30 | import com.dl7.drag.animate.BaseViewAnimator;
31 |
32 |
33 | public class ZoomOutAnimator extends BaseViewAnimator {
34 | @Override
35 | protected void prepare(View target) {
36 | getAnimatorAgent().playTogether(
37 | ObjectAnimator.ofFloat(target, "alpha", 1, 0, 0),
38 | ObjectAnimator.ofFloat(target, "scaleX", 1, 0.3f, 0),
39 | ObjectAnimator.ofFloat(target, "scaleY", 1, 0.3f, 0)
40 | );
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/simple/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
18 |
19 |
26 |
27 |
33 |
34 |
40 |
41 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/in/SlideInLeftAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.in;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 |
31 | import com.dl7.drag.animate.BaseViewAnimator;
32 |
33 |
34 | public class SlideInLeftAnimator extends BaseViewAnimator {
35 | @Override
36 | public void prepare(View target) {
37 | ViewGroup parent = (ViewGroup) target.getParent();
38 | int distance = parent.getWidth();
39 | getAnimatorAgent().playTogether(
40 | ObjectAnimator.ofFloat(target, "alpha", 0, 1),
41 | ObjectAnimator.ofFloat(target, "translationX", -distance, 0)
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/in/SlideInRightAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.in;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 |
31 | import com.dl7.drag.animate.BaseViewAnimator;
32 |
33 |
34 | public class SlideInRightAnimator extends BaseViewAnimator {
35 | @Override
36 | public void prepare(View target) {
37 | ViewGroup parent = (ViewGroup) target.getParent();
38 | int distance = parent.getWidth();
39 | getAnimatorAgent().playTogether(
40 | ObjectAnimator.ofFloat(target, "alpha", 0, 1),
41 | ObjectAnimator.ofFloat(target, "translationX", distance, 0)
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/out/SlideOutRightAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.out;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 |
31 | import com.dl7.drag.animate.BaseViewAnimator;
32 |
33 |
34 | public class SlideOutRightAnimator extends BaseViewAnimator {
35 | @Override
36 | public void prepare(View target) {
37 | ViewGroup parent = (ViewGroup) target.getParent();
38 | int distance = parent.getWidth();
39 | getAnimatorAgent().playTogether(
40 | ObjectAnimator.ofFloat(target, "alpha", 1, 0),
41 | ObjectAnimator.ofFloat(target, "translationX", 0, distance)
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/out/SlideOutBottomAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.out;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 |
31 | import com.dl7.drag.animate.BaseViewAnimator;
32 |
33 |
34 | public class SlideOutBottomAnimator extends BaseViewAnimator {
35 | @Override
36 | public void prepare(View target) {
37 | ViewGroup parent = (ViewGroup) target.getParent();
38 | int distance = parent.getHeight() - target.getTop();
39 | getAnimatorAgent().playTogether(
40 | ObjectAnimator.ofFloat(target, "alpha", 1, 0),
41 | ObjectAnimator.ofFloat(target, "translationY", 0, distance)
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import com.dl7.simple.drag.activity.AnimateActivity;
11 | import com.dl7.simple.drag.activity.DragActivity;
12 | import com.dl7.simple.drag.activity.DragBlurActivity;
13 | import com.dl7.simple.drag.activity.DragOutsideActivity;
14 |
15 | import butterknife.BindView;
16 | import butterknife.ButterKnife;
17 | import butterknife.OnClick;
18 |
19 | public class MainActivity extends AppCompatActivity {
20 |
21 | @BindView(R.id.btn_drag)
22 | Button mBtnDrag;
23 | @BindView(R.id.btn_animate)
24 | Button mBtnAnimate;
25 | @BindView(R.id.btn_other)
26 | Button mBtnOther;
27 | @BindView(R.id.tool_bar)
28 | Toolbar mToolBar;
29 | @BindView(R.id.btn_drag_outside)
30 | Button mBtnDragOutside;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_main);
36 | ButterKnife.bind(this);
37 |
38 | setSupportActionBar(mToolBar);
39 | mToolBar.setTitle("DragSlopLayout");
40 | }
41 |
42 | @OnClick({R.id.btn_drag, R.id.btn_animate, R.id.btn_other, R.id.btn_drag_outside})
43 | public void onClick(View view) {
44 | switch (view.getId()) {
45 | case R.id.btn_drag:
46 | startActivity(new Intent(this, DragActivity.class));
47 | break;
48 | case R.id.btn_animate:
49 | startActivity(new Intent(this, AnimateActivity.class));
50 | break;
51 | case R.id.btn_other:
52 | startActivity(new Intent(this, DragBlurActivity.class));
53 | break;
54 | case R.id.btn_drag_outside:
55 | startActivity(new Intent(this, DragOutsideActivity.class));
56 | break;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/in/ZoomInLeftAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.in;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 |
31 | import com.dl7.drag.animate.BaseViewAnimator;
32 |
33 |
34 | public class ZoomInLeftAnimator extends BaseViewAnimator {
35 | @Override
36 | public void prepare(View target) {
37 | ViewGroup parent = (ViewGroup) target.getParent();
38 | int distance = parent.getWidth();
39 | getAnimatorAgent().playTogether(
40 | ObjectAnimator.ofFloat(target, "scaleX", 0.1f, 0.5f, 1),
41 | ObjectAnimator.ofFloat(target, "scaleY", 0.1f, 0.5f, 1),
42 | ObjectAnimator.ofFloat(target, "translationX", -distance, distance * 0.2f, 0),
43 | ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1)
44 | );
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/in/ZoomInRightAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.in;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 |
31 | import com.dl7.drag.animate.BaseViewAnimator;
32 |
33 |
34 | public class ZoomInRightAnimator extends BaseViewAnimator {
35 | @Override
36 | public void prepare(View target) {
37 | ViewGroup parent = (ViewGroup) target.getParent();
38 | int distance = parent.getWidth();
39 | getAnimatorAgent().playTogether(
40 | ObjectAnimator.ofFloat(target, "scaleX", 0.1f, 0.5f, 1),
41 | ObjectAnimator.ofFloat(target, "scaleY", 0.1f, 0.5f, 1),
42 | ObjectAnimator.ofFloat(target, "translationX", distance, -distance * 0.2f, 0),
43 | ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1)
44 | );
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/out/ZoomOutLeftAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.out;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 |
31 | import com.dl7.drag.animate.BaseViewAnimator;
32 |
33 | public class ZoomOutLeftAnimator extends BaseViewAnimator {
34 | @Override
35 | protected void prepare(View target) {
36 | ViewGroup parent = (ViewGroup) target.getParent();
37 | int distance = parent.getWidth();
38 | getAnimatorAgent().playTogether(
39 | ObjectAnimator.ofFloat(target, "alpha", 1, 1, 0),
40 | ObjectAnimator.ofFloat(target, "scaleX", 1, 0.5f, 0.1f),
41 | ObjectAnimator.ofFloat(target, "scaleY", 1, 0.5f, 0.1f),
42 | ObjectAnimator.ofFloat(target, "translationX", 0, distance * 0.2f, -distance)
43 | );
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/out/ZoomOutRightAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate.out;
26 |
27 | import android.animation.ObjectAnimator;
28 | import android.view.View;
29 | import android.view.ViewGroup;
30 |
31 | import com.dl7.drag.animate.BaseViewAnimator;
32 |
33 |
34 | public class ZoomOutRightAnimator extends BaseViewAnimator {
35 | @Override
36 | protected void prepare(View target) {
37 | ViewGroup parent = (ViewGroup) target.getParent();
38 | int distance = parent.getWidth() - parent.getLeft();
39 | getAnimatorAgent().playTogether(
40 | ObjectAnimator.ofFloat(target, "alpha", 1, 1, 0),
41 | ObjectAnimator.ofFloat(target, "scaleX", 1, 0.5f, 0.1f),
42 | ObjectAnimator.ofFloat(target, "scaleY", 1, 0.5f, 0.1f),
43 | ObjectAnimator.ofFloat(target, "translationX", 0, -distance * 0.2f, distance)
44 | );
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/activity/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.activity;
2 |
3 | import android.graphics.Color;
4 | import android.os.Build;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.MenuItem;
9 | import android.view.View;
10 | import android.view.Window;
11 | import android.view.WindowManager;
12 |
13 | public abstract class BaseActivity extends AppCompatActivity {
14 |
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | initSystemBarTint();
20 | }
21 |
22 | /**
23 | * 初始化 Toolbar
24 | *
25 | * @param toolbar
26 | * @param homeAsUpEnabled
27 | * @param title
28 | */
29 | public void initToolBar(Toolbar toolbar, boolean homeAsUpEnabled, String title) {
30 | toolbar.setTitle(title);
31 | setSupportActionBar(toolbar);
32 | getSupportActionBar().setDisplayHomeAsUpEnabled(homeAsUpEnabled);
33 | }
34 |
35 | /**
36 | * 设置状态栏颜色
37 | */
38 | protected void initSystemBarTint() {
39 | // 设置状态栏全透明
40 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
41 | Window window = getWindow();
42 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
43 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
44 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
45 | window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
46 | window.setStatusBarColor(Color.TRANSPARENT);
47 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
48 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
49 | }
50 | }
51 |
52 | @Override
53 | public boolean onOptionsItemSelected(MenuItem item) {
54 | if (item.getItemId() == android.R.id.home) {
55 | onBackPressed();
56 | return true;
57 | }
58 | return super.onOptionsItemSelected(item);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/simple/src/main/res/layout/activity_animate.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
26 |
27 |
33 |
34 |
40 |
41 |
47 |
48 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/adapter/PhotoPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.PagerAdapter;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ImageView;
8 |
9 | import java.util.List;
10 |
11 | import uk.co.senab.photoview.PhotoView;
12 | import uk.co.senab.photoview.PhotoViewAttacher;
13 |
14 | /**
15 | * Created by long on 2016/8/29.
16 | * 图片浏览适配器
17 | */
18 | public class PhotoPagerAdapter extends PagerAdapter {
19 |
20 | private List mImgList;
21 | private Context mContext;
22 | private OnPhotoClickListener mListener;
23 | private boolean mIsFitXY;
24 |
25 | public PhotoPagerAdapter(Context context, List imgList, boolean isFitXY) {
26 | this.mContext = context;
27 | this.mImgList = imgList;
28 | this.mIsFitXY = isFitXY;
29 | }
30 |
31 |
32 | @Override
33 | public int getCount() {
34 | return mImgList.size();
35 | }
36 |
37 | @Override
38 | public boolean isViewFromObject(View view, Object object) {
39 | return view == object;
40 | }
41 |
42 | @Override
43 | public Object instantiateItem(ViewGroup container, int position) {
44 | PhotoView photo = new PhotoView(mContext);
45 | if (mIsFitXY) {
46 | photo.setScaleType(ImageView.ScaleType.FIT_XY);
47 | } else {
48 | photo.setScaleType(ImageView.ScaleType.FIT_CENTER);
49 | }
50 | photo.setImageResource(mImgList.get(position));
51 | container.addView(photo);
52 | photo.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
53 | @Override
54 | public void onPhotoTap(View view, float x, float y) {
55 | if (mListener != null) {
56 | mListener.onPhotoClick();
57 | }
58 | }
59 | });
60 | return photo;
61 | }
62 |
63 | @Override
64 | public void destroyItem(ViewGroup container, int position, Object object) {
65 | container.removeView((View) object);
66 | }
67 |
68 | public void setListener(OnPhotoClickListener listener) {
69 | mListener = listener;
70 | }
71 |
72 | public interface OnPhotoClickListener {
73 | void onPhotoClick();
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 |
--------------------------------------------------------------------------------
/dragsloplayout/bintray-publish.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jfrog.bintray'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 |
4 | //important
5 | Properties properties = new Properties()
6 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
7 |
8 | version = "1.0.1"
9 |
10 | def siteUrl = 'https://github.com/Rukey7/DragSlopLayout'
11 | def gitUrl = 'https://github.com/Rukey7/DragSlopLayout'
12 | group = "com.dl7.drag"
13 |
14 | bintray {
15 | user = properties.getProperty("bintray.user")
16 | key = properties.getProperty("bintray.apikey")
17 |
18 | configurations = ['archives']
19 | pkg {
20 | repo = "maven"
21 | group = group
22 | name = "DragSlopLayout"
23 | websiteUrl = siteUrl
24 | vcsUrl = gitUrl
25 | licenses = ["Apache-2.0"]
26 | publish = true
27 | }
28 | }
29 |
30 | //important
31 | task javadoc(type: Javadoc) {
32 | source = android.sourceSets.main.java.srcDirs
33 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
34 | }
35 | javadoc {
36 | options{
37 | encoding "UTF-8"
38 | charSet 'UTF-8'
39 | author true
40 | version true
41 | links "http://docs.oracle.com/javase/7/docs/api"
42 | }
43 | }
44 |
45 | task sourcesJar(type: Jar) {
46 | from android.sourceSets.main.java.srcDirs
47 | classifier = 'sources'
48 | }
49 |
50 | task javadocJar(type: Jar, dependsOn: javadoc) {
51 | classifier = 'javadoc'
52 | from javadoc.destinationDir
53 | }
54 |
55 | artifacts {
56 | archives javadocJar
57 | archives sourcesJar
58 | }
59 |
60 | install {
61 | repositories.mavenInstaller {
62 | // This generates POM.xml with proper parameters
63 | pom {
64 | project {
65 | packaging 'aar'
66 | // Add your description here
67 | name 'A UI library fro Android'
68 | url siteUrl
69 | // Set your license
70 | licenses {
71 | license {
72 | name 'The Apache Software License, Version 2.0'
73 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
74 | }
75 | }
76 | developers {
77 | developer {
78 | id 'rukey7' //
79 | name 'rukey7' //
80 | email 'rukey7@163.com' //
81 | }
82 | }
83 | scm {
84 | connection gitUrl
85 | developerConnection gitUrl
86 | url siteUrl
87 | }
88 | }
89 | }
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/adapter/BaseRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 |
6 | import java.util.ArrayList;
7 | import java.util.Collections;
8 | import java.util.List;
9 |
10 | /**
11 | * Created by 95 on 2016/4/21.
12 | * 适配器基类
13 | */
14 | public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter {
15 |
16 | protected Context mContext;
17 | protected List mDatas;
18 |
19 |
20 | public BaseRecyclerAdapter(Context context) {
21 | this.mContext = context;
22 | this.mDatas = new ArrayList<>();
23 | }
24 |
25 | public BaseRecyclerAdapter(Context context, List datas) {
26 | this.mContext = context;
27 | this.mDatas = datas;
28 | }
29 |
30 | public BaseRecyclerAdapter(Context context, T[] datas) {
31 | this.mContext = context;
32 | this.mDatas = new ArrayList();
33 | Collections.addAll(mDatas, datas);
34 | }
35 |
36 | @Override
37 | public int getItemCount() {
38 | return mDatas == null ? 0 : mDatas.size();
39 | }
40 |
41 | /**
42 | * 更新数据,替换原有数据
43 | * @param items
44 | */
45 | public void updateItems(List items) {
46 | mDatas = items;
47 | notifyDataSetChanged();
48 | }
49 |
50 | /**
51 | * 插入一条数据
52 | * @param item 数据
53 | */
54 | public void addItem(T item) {
55 | mDatas.add(0, item);
56 | notifyItemInserted(0);
57 | }
58 |
59 | /**
60 | * 插入一条数据
61 | * @param item 数据
62 | * @param position 插入位置
63 | */
64 | public void addItem(T item, int position) {
65 | position = Math.min(position, mDatas.size());
66 | mDatas.add(position, item);
67 | notifyItemInserted(position);
68 | }
69 |
70 | /**
71 | * 在列表尾添加一串数据
72 | * @param items
73 | */
74 | public void addItems(List items) {
75 | mDatas.addAll(items);
76 | }
77 |
78 | /**
79 | * 移除一条数据
80 | * @param position 位置
81 | */
82 | public void removeItem(int position) {
83 | if (position > mDatas.size() - 1) {
84 | return;
85 | }
86 | mDatas.remove(position);
87 | notifyItemRemoved(position);
88 | }
89 |
90 | /**
91 | * 移除一条数据
92 | * @param item 数据
93 | */
94 | public void removeItem(T item) {
95 | int pos = 0;
96 | for (T info : mDatas) {
97 | if (item.hashCode() == info.hashCode()) {
98 | removeItem(pos);
99 | break;
100 | }
101 | pos++;
102 | }
103 | }
104 |
105 | /**
106 | * 清除所有数据
107 | */
108 | public void cleanItems() {
109 | mDatas.clear();
110 | notifyDataSetChanged();
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/activity/DragBlurActivity.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.widget.Toolbar;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 | import android.view.View;
8 | import android.widget.ImageView;
9 | import android.widget.LinearLayout;
10 | import android.widget.TextView;
11 | import android.widget.Toast;
12 |
13 | import com.dl7.drag.DragSlopLayout;
14 | import com.dl7.simple.drag.R;
15 |
16 | import butterknife.BindView;
17 | import butterknife.ButterKnife;
18 | import butterknife.OnClick;
19 |
20 | public class DragBlurActivity extends BaseActivity {
21 |
22 | @BindView(R.id.tv_title)
23 | TextView mTvTitle;
24 | @BindView(R.id.drag_layout)
25 | DragSlopLayout mDragLayout;
26 | @BindView(R.id.iv_photo)
27 | ImageView mIvPhoto;
28 | @BindView(R.id.ll_favorite)
29 | LinearLayout mLlFavorite;
30 | @BindView(R.id.ll_next)
31 | LinearLayout mLlNext;
32 | @BindView(R.id.ll_download)
33 | LinearLayout mLlDownload;
34 | @BindView(R.id.ll_share)
35 | LinearLayout mLlShare;
36 | @BindView(R.id.tool_bar)
37 | Toolbar mToolBar;
38 |
39 | private final int[] mImgRes = new int[] {R.mipmap.pic2, R.mipmap.pic4, R.mipmap.pic5};
40 | private int mIndex = 1;
41 |
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | setContentView(R.layout.activity_drag_blur);
47 | ButterKnife.bind(this);
48 | initToolBar(mToolBar, true, "");
49 | mDragLayout.setEnableBlur(true);
50 | }
51 |
52 | @Override
53 | public boolean onCreateOptionsMenu(Menu menu) {
54 | getMenuInflater().inflate(R.menu.menu_blur, menu);
55 | return true;
56 | }
57 |
58 | @Override
59 | public boolean onOptionsItemSelected(MenuItem item) {
60 | item.setChecked(true);
61 | switch (item.getItemId()) {
62 | case R.id.blur_local:
63 | mDragLayout.setBlurFull(false);
64 | return true;
65 | case R.id.blur_full:
66 | mDragLayout.setBlurFull(true);
67 | return true;
68 | }
69 | return super.onOptionsItemSelected(item);
70 | }
71 |
72 | @OnClick({R.id.ll_favorite, R.id.ll_next, R.id.ll_download, R.id.ll_share})
73 | public void onClick(View view) {
74 | switch (view.getId()) {
75 | case R.id.ll_favorite:
76 | Toast.makeText(this, "收藏", Toast.LENGTH_SHORT).show();
77 | break;
78 | case R.id.ll_next:
79 | mIvPhoto.setImageResource(mImgRes[mIndex++ % mImgRes.length]);
80 | mDragLayout.updateBlurView();
81 | break;
82 | case R.id.ll_download:
83 | Toast.makeText(this, "下载", Toast.LENGTH_SHORT).show();
84 | break;
85 | case R.id.ll_share:
86 | Toast.makeText(this, "分享", Toast.LENGTH_SHORT).show();
87 | break;
88 | }
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/simple/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DragSlopLayout
3 |
4 | 汤姆·哈迪给人留下的最初印象是《兄弟连》和《黑鹰坠落》中英俊而带有几分邪气的美国大兵,但他是一位生在伦敦的英国演员。之后哈迪与盖尔·加西亚·贝纳尔合演了独立片《爱奴》,在南非拍摄《西蒙:一位英国退伍兵》,还在《星际迷航记之复仇女神》中出任反派,扮演毕凯舰长的复制人Shinzon一角为科幻迷所熟悉。\n
5 | 舞台剧方面,2003年哈迪荣获《标准晚报》颁发的新人奖,次年又被劳伦斯·奥利弗奖提名最佳新人。2004年他出演了马修·沃恩执导的英式黑帮片《夹心蛋糕》,与丹尼尔·克雷格、西椰娜·米勒以及本·威士肖同台。他还出演过电视剧《童贞女王-伊丽莎白一世》,以及电视片《吉昂的女儿》、《雾都孤儿》等。2008年凭借电视片《斯图尔特:逆行人生》被英国影视艺术学院奖提名最佳男演员。他将在新版的《呼啸山庄》中扮演希斯克里夫。\n
6 | 大银幕上,2008年哈迪亮相了盖·里奇的《摇滚帮》,还加盟了摩根·弗里曼、安东尼奥·班德拉斯主演的《亲密如贼》。他主演的动作片《布朗森》将在08年1月的圣丹斯电影节首映,他在片中的演技大受好评。\n
7 | 2009年,哈迪获邀加盟克里斯托弗·诺兰执导的大片《盗梦空间》,在其中饰演梦境伪造师伊姆斯,该片在2010年上映后的大热为哈迪铺就灿烂星路,顺利进军好莱坞。随后哈迪作品迭出,有爱情喜剧《情敌大战》、众星云集的《锅匠,裁缝,士兵,间谍》、经典童话黑暗版《白雪公主与猎人》、诺兰的《蝙蝠侠前传3:黑暗骑士崛起》、接棒梅尔·吉布森出演的《疯狂的麦克斯4》,前途不可限量。\n
8 |
9 | 贝尔出生于英国的一个演艺世家,10岁就出演舞台剧,12岁出演电视剧。斯皮尔伯格筹拍《太阳帝国》时看中了他担任男主角,因而步上星途。第一个成人角色是在1992年的迪士尼歌舞片《摇摆狂潮》中载歌载舞。真正的突破是在《美国杀人魔》中饰演男主角,开始受到瞩目。2005年接下蝙蝠侠的斗篷,与克里斯托弗·诺兰合作《蝙蝠侠:开战时刻》(2005)和《蝙蝠侠前传2:黑暗骑士》(2008),后者更是在全球掀起“蝙蝠”狂潮,以席卷姿态覆盖众多影迷,成为一时热议话题。除去《蝙蝠侠》系列,贝尔主演的其它影片如《致命魔术》、《决斗犹马镇》、《我不在那儿》等都是大导演强阵容的话题之作,可谓风头无两。2009年贝尔还有两部大作问世,分别是《终结者》第四部《终结者:救世军》和与约翰尼·德普联袂出演的《公众之敌》。
10 |
11 | 马克·沃尔伯格的母亲名叫阿尔玛,父亲名叫唐纳德,他有5个哥哥和3个姐姐。出生于美国波士顿,高中时候退学,后获GED资格(一般教育考试)。做过各种各样的工作包括瓦工,甚至因几次违法而被判罪。后独立组建Marky Mark and Funky Bunch乐队发行两张摇滚唱片并巡回演出(《人民的音乐》和《你要相信》)。《完美摇摆》赢得最佳舞曲,这首歌直至今天仍然很流行。他在舞台上的魅力在他脱去衬衫和裤子的时候就更加无法抵挡。1992年,他成为著名时装设计师凯文·克莱恩的内衣模特。他和超级名模凯特·摩丝在一起拍摄的几乎全裸的广告照片则令他备受争议。\n
12 | 1992年之后马克开始投身电影业,但直到1997年才因主演了《不羁夜》一炮而红,其后他与周润发合演《再战边缘》,2000年的《惊涛骇浪》以及2001年的新版《人猿星球》让他正式成为巨星。近年陆续出演不少动作类型的影片如《偷天换日》、《四兄弟》等,主演的体育励志片《万夫莫敌》也取得了不错的票房成绩。2006年加盟马丁·斯科塞斯的《无间行者》,并获得奥斯卡最佳男配角提名.07年与杰昆·菲尼克斯合演犯罪题材的《我们拥有夜晚》,并在《生死狙击》中扮演一个身手了得的狙击手。08年主演的两部话题之作《灭顶之灾》和《马克思·佩恩》都未能取得好口碑。2009年在彼得·杰克逊的新片《可爱的骨头》中扮演一个失去爱女的悲痛父亲。2010年马克主演了喜剧片《二流警探》和剧情片《斗士》,还在史蒂夫·卡瑞尔和蒂娜·菲主演的喜剧片《约会之夜》中出演配角。
13 |
14 | 美国演员,高中毕业后痴心于歌唱事业,最后决定放弃上大学,做全职的艺人。1989年首次获得葛莱美奖“最佳饶舌歌演唱奖”。进而成为NBC电视影集《活力王子》(The Fresh Prince of Bel Air)的男主角。1993年以主角身份跃登大银幕,出演一部讽刺纽约知识分子的文艺片《六度分离》,片中他扮演一个自称是黑人巨星薜尼鲍迪儿子的老千。1995年主演警匪动作片《绝地战警》便一举成名,《独立日》、《黑超特警组》全球票房奏捷后,身价飙到巅峰。近几年接拍了许多卖座的动作片,包括《全民公敌》、《我,机器人》、《黑衣人2》、《全民情敌》等,始终为影迷爱戴。\n
15 | 2012年,威尔·史密斯带着新作《黑衣人3》强势归来。《黑衣人》系列是威尔·史密斯演员生涯的代表作之一,1997和2002年推出的《黑衣人》前两集在全球共计收获了超过10亿美元票房,也让威尔·史密斯与汤米·李·琼斯饰演的J、K这对黑超探员组合成为了科幻影史的经典形象之一。
16 |
17 | 丹泽尔·华盛顿出生于纽约州的弗农山,父亲是一位牧师,母亲是个美容师。14时,他父母的关系开始恶化,丹泽尔和他的姐姐被送进了一所寄宿学校。家庭的影响使华盛顿从小就养成了一种静默沉实的性格,不调皮胡闹,而是喜爱看书,给人一种老成稳重的感觉。\n
18 | 1977年丹泽尔从富德汉姆大学毕业并获得了新闻学学士学位,毕业后他就去了旧金山,并在那里获得了美国音乐戏剧学院(ACT)的奖学金。他在美国国家戏剧学院学习了一年的表演,为他日后的成长打下了一个良好的基础。不久,丹泽尔·华盛顿便又回到了纽约。在大学期间就酷爱喜剧的他此时开始在各种电视剧中饰演角色。期间他曾参加了约瑟夫·佩珀导演的《莎士比亚》舞台剧的演出,饰演了一个颇有争议的人物理查三世。丹泽尔·华盛顿进入影坛后,出演了无数的角色,大都是正面光辉的形象。\n
19 | 1989年的《光荣》让他第一次声名远播,随后他的电影作品一部接着一部推出,1993年的《费城故事》和《塘鹅暗杀令》,1995年的《赤色风暴》,1996年的《生死豪情》,他在艺术影片与商业影片两个领域都有着不俗的表现。2001年丹泽尔·华盛顿主演的影片《训练日》终于让他成为了第二位获得奥斯卡影帝的黑人演员。近来事业一直保持良好状态,作品不断。
20 | To see the world, \nthings dangerous to come to, \nto see behind walls,\nto draw closer,\nto find each other and to feel.\nThat is the purpose of LIFE.\n开拓视野,冲破艰险,洞悉所有,贴近生活,寻找真爱,感受彼此。\n这就是人生的目的。
21 |
22 |
23 |
--------------------------------------------------------------------------------
/simple/src/main/res/layout/activity_drag.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
18 |
19 |
24 |
25 |
30 |
31 |
40 |
41 |
48 |
49 |
56 |
57 |
64 |
65 |
66 |
70 |
71 |
79 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/adapter/DividerItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.adapter;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Rect;
7 | import android.graphics.drawable.Drawable;
8 | import android.support.v7.widget.LinearLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.view.View;
11 |
12 | /**
13 | * Created by long on 2016/3/29.
14 | */
15 | public class DividerItemDecoration extends RecyclerView.ItemDecoration {
16 |
17 | private static final int[] ATTRS = new int[]{
18 | android.R.attr.listDivider
19 | };
20 |
21 | public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
22 | public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
23 | private Drawable mDivider;
24 | private int mOrientation;
25 |
26 | public DividerItemDecoration(Context context, int orientation) {
27 | final TypedArray a = context.obtainStyledAttributes(ATTRS);
28 | mDivider = a.getDrawable(0);
29 | a.recycle();
30 | setOrientation(orientation);
31 | }
32 |
33 | public void setOrientation(int orientation) {
34 | if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
35 | throw new IllegalArgumentException("invalid orientation");
36 | }
37 | mOrientation = orientation;
38 | }
39 |
40 | @Override
41 | public void onDraw(Canvas c, RecyclerView parent) {
42 | if (mOrientation == VERTICAL_LIST) {
43 | drawVertical(c, parent);
44 | } else {
45 | drawHorizontal(c, parent);
46 | }
47 |
48 | }
49 |
50 |
51 | public void drawVertical(Canvas c, RecyclerView parent) {
52 | final int left = parent.getPaddingLeft();
53 | final int right = parent.getWidth() - parent.getPaddingRight();
54 |
55 | final int childCount = parent.getChildCount();
56 | for (int i = 0; i < childCount; i++) {
57 | final View child = parent.getChildAt(i);
58 | android.support.v7.widget.RecyclerView v = new android.support.v7.widget.RecyclerView(parent.getContext());
59 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
60 | .getLayoutParams();
61 | final int top = child.getBottom() + params.bottomMargin;
62 | final int bottom = top + mDivider.getIntrinsicHeight();
63 | mDivider.setBounds(left, top, right, bottom);
64 | mDivider.draw(c);
65 | }
66 | }
67 |
68 | public void drawHorizontal(Canvas c, RecyclerView parent) {
69 | final int top = parent.getPaddingTop();
70 | final int bottom = parent.getHeight() - parent.getPaddingBottom();
71 |
72 | final int childCount = parent.getChildCount();
73 | for (int i = 0; i < childCount; i++) {
74 | final View child = parent.getChildAt(i);
75 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
76 | .getLayoutParams();
77 | final int left = child.getRight() + params.rightMargin;
78 | final int right = left + mDivider.getIntrinsicHeight();
79 | mDivider.setBounds(left, top, right, bottom);
80 | mDivider.draw(c);
81 | }
82 | }
83 |
84 | @Override
85 | public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
86 | if (mOrientation == VERTICAL_LIST) {
87 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
88 | } else {
89 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
90 | }
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/simple/src/main/res/layout/activity_drag_outside.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
18 |
19 |
25 |
26 |
32 |
33 |
37 |
38 |
44 |
45 |
52 |
53 |
56 |
57 |
60 |
61 |
68 |
69 |
70 |
71 |
72 |
81 |
82 |
88 |
89 |
95 |
96 |
102 |
103 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/utils/RecyclerViewHelper.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.utils;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.DefaultItemAnimator;
5 | import android.support.v7.widget.GridLayoutManager;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.StaggeredGridLayoutManager;
9 |
10 | import com.dl7.simple.drag.adapter.DividerGridItemDecoration;
11 | import com.dl7.simple.drag.adapter.DividerItemDecoration;
12 |
13 |
14 | /**
15 | * Created by long on 2016/3/30.
16 | * 视图帮助类
17 | */
18 | public class RecyclerViewHelper {
19 |
20 | private RecyclerViewHelper() {
21 | throw new RuntimeException("RecyclerViewHelper cannot be initialized!");
22 | }
23 |
24 | /**
25 | * 配置垂直列表RecyclerView
26 | * @param view
27 | */
28 | public static void initRecyclerViewV(Context context, RecyclerView view, boolean isDivided,
29 | RecyclerView.Adapter adapter) {
30 | LinearLayoutManager layoutManager = new LinearLayoutManager(context);
31 | layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
32 | view.setLayoutManager(layoutManager);
33 | view.setItemAnimator(new DefaultItemAnimator());
34 | if (isDivided) {
35 | view.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST));
36 | }
37 | view.setAdapter(adapter);
38 | }
39 |
40 | public static void initRecyclerViewV(Context context, RecyclerView view, RecyclerView.Adapter adapter) {
41 | initRecyclerViewV(context, view, false, adapter);
42 | }
43 |
44 | /**
45 | * 配置水平列表RecyclerView
46 | * @param view
47 | */
48 | public static void initRecyclerViewH(Context context, RecyclerView view, boolean isDivided,
49 | RecyclerView.Adapter adapter) {
50 | LinearLayoutManager layoutManager = new LinearLayoutManager(context);
51 | layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
52 | view.setLayoutManager(layoutManager);
53 | view.setItemAnimator(new DefaultItemAnimator());
54 | if (isDivided) {
55 | view.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.HORIZONTAL_LIST));
56 | }
57 | view.setAdapter(adapter);
58 | }
59 |
60 | public static void initRecyclerViewH(Context context, RecyclerView view, RecyclerView.Adapter adapter) {
61 | initRecyclerViewH(context, view, false, adapter);
62 | }
63 |
64 | /**
65 | * 配置网格列表RecyclerView
66 | * @param view
67 | */
68 | public static void initRecyclerViewG(Context context, RecyclerView view, boolean isDivided,
69 | RecyclerView.Adapter adapter, int column) {
70 | GridLayoutManager layoutManager = new GridLayoutManager(context, column, LinearLayoutManager.VERTICAL, false);
71 | view.setLayoutManager(layoutManager);
72 | view.setItemAnimator(new DefaultItemAnimator());
73 | if (isDivided) {
74 | view.addItemDecoration(new DividerGridItemDecoration(context));
75 | }
76 | view.setAdapter(adapter);
77 | }
78 |
79 | public static void initRecyclerViewG(Context context, RecyclerView view, RecyclerView.Adapter adapter, int column) {
80 | initRecyclerViewG(context, view, false, adapter, column);
81 | }
82 |
83 |
84 | /**
85 | * 配置瀑布流列表RecyclerView
86 | * @param view
87 | */
88 | public static void initRecyclerViewSV(Context context, RecyclerView view, boolean isDivided,
89 | RecyclerView.Adapter adapter, int column) {
90 | StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(column, StaggeredGridLayoutManager.VERTICAL);
91 | view.setLayoutManager(layoutManager);
92 | view.setItemAnimator(new DefaultItemAnimator());
93 | if (isDivided) {
94 | view.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL_LIST));
95 | }
96 | view.setAdapter(adapter);
97 | }
98 |
99 | public static void initRecyclerViewSV(Context context, RecyclerView view, RecyclerView.Adapter adapter, int column) {
100 | initRecyclerViewSV(context, view, false, adapter, column);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/activity/DragActivity.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.view.ViewPager;
5 | import android.support.v7.widget.Toolbar;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.widget.ScrollView;
9 | import android.widget.TextView;
10 |
11 | import com.dl7.drag.DragSlopLayout;
12 | import com.dl7.simple.drag.adapter.PhotoPagerAdapter;
13 | import com.dl7.simple.drag.R;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | import butterknife.BindView;
19 | import butterknife.ButterKnife;
20 |
21 | public class DragActivity extends BaseActivity {
22 |
23 | @BindView(R.id.vp_photo)
24 | ViewPager mVpPhoto;
25 | @BindView(R.id.tv_title)
26 | TextView mTvTitle;
27 | @BindView(R.id.tv_count)
28 | TextView mTvCount;
29 | @BindView(R.id.tv_index)
30 | TextView mTvIndex;
31 | @BindView(R.id.tv_content)
32 | TextView mTvContent;
33 | @BindView(R.id.sv_view)
34 | ScrollView mSvView;
35 | @BindView(R.id.drag_layout)
36 | DragSlopLayout mDragLayout;
37 | @BindView(R.id.tool_bar)
38 | Toolbar mToolBar;
39 |
40 | boolean isOpen = true;
41 | private boolean mIsInteract = true;
42 |
43 | @Override
44 | protected void onCreate(Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | setContentView(R.layout.activity_drag);
47 | ButterKnife.bind(this);
48 | initToolBar(mToolBar, true, "");
49 |
50 | final String[] titleList = new String[]{
51 | "汤姆·哈迪", "克里斯蒂安·贝尔", "马克·沃尔伯格", "威尔·史密斯", "丹泽尔·华盛顿",
52 | };
53 | final String[] descList = new String[]{
54 | getString(R.string.TomHardy),
55 | getString(R.string.ChristianBale),
56 | getString(R.string.MarkWahlberg),
57 | getString(R.string.WillSmith),
58 | getString(R.string.DenzelWashington),
59 | };
60 | List imgList = new ArrayList<>();
61 | imgList.add(R.mipmap.img1);
62 | imgList.add(R.mipmap.img2);
63 | imgList.add(R.mipmap.img3);
64 | imgList.add(R.mipmap.img4);
65 | imgList.add(R.mipmap.img5);
66 |
67 | PhotoPagerAdapter mPagerAdapter = new PhotoPagerAdapter(this, imgList, false);
68 | mVpPhoto.setAdapter(mPagerAdapter);
69 | // 实现 ScrollView 的平滑滚动
70 | mDragLayout.setAttachScrollView(mSvView);
71 | // 和 ViewPager 联动
72 | // mDsLayout.interactWithViewPager(mIsInteract);
73 | mDragLayout.attachViewPager(mVpPhoto);
74 |
75 | mTvCount.setText("" + imgList.size());
76 | mTvTitle.setText(titleList[0]);
77 | mTvIndex.setText("" + 1);
78 | mTvContent.setText(descList[0]);
79 |
80 | mVpPhoto.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
81 | @Override
82 | public void onPageSelected(int position) {
83 | mTvTitle.setText(titleList[position]);
84 | mTvIndex.setText("" + (position + 1));
85 | mTvContent.setText(descList[position]);
86 | }
87 | });
88 | mPagerAdapter.setListener(new PhotoPagerAdapter.OnPhotoClickListener() {
89 | @Override
90 | public void onPhotoClick() {
91 | if (isOpen) {
92 | mDragLayout.scrollOutScreen(500);
93 | } else {
94 | mDragLayout.scrollInScreen(500);
95 | }
96 | isOpen = !isOpen;
97 | }
98 | });
99 | }
100 |
101 | @Override
102 | public boolean onCreateOptionsMenu(Menu menu) {
103 | getMenuInflater().inflate(R.menu.menu_drag, menu);
104 | return true;
105 | }
106 |
107 | @Override
108 | public boolean onOptionsItemSelected(MenuItem item) {
109 | switch (item.getItemId()) {
110 | case R.id.item_interact:
111 | mIsInteract = !mIsInteract;
112 | item.setChecked(mIsInteract);
113 | // mDsLayout.interactWithViewPager(mIsInteract);
114 | if (mIsInteract) {
115 | mDragLayout.attachViewPager(mVpPhoto);
116 | } else {
117 | mDragLayout.detachViewPager();
118 | }
119 | return true;
120 | }
121 | return super.onOptionsItemSelected(item);
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/BaseViewAnimator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2014 daimajia
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 |
25 | package com.dl7.drag.animate;
26 |
27 | import android.animation.Animator.AnimatorListener;
28 | import android.animation.AnimatorSet;
29 | import android.support.v4.view.ViewCompat;
30 | import android.view.View;
31 | import android.view.animation.Interpolator;
32 |
33 | /**
34 | * https://github.com/daimajia/AndroidViewAnimations
35 | */
36 | public abstract class BaseViewAnimator {
37 |
38 | public static final long DURATION = 1000;
39 |
40 | protected AnimatorSet mAnimatorSet;
41 | private long mDuration = DURATION;
42 |
43 | {
44 | mAnimatorSet = new AnimatorSet();
45 | }
46 |
47 | protected abstract void prepare(View target);
48 |
49 | public BaseViewAnimator setTarget(View target) {
50 | reset(target);
51 | prepare(target);
52 | return this;
53 | }
54 |
55 | public void animate() {
56 | start();
57 | }
58 |
59 | /**
60 | * reset the view to default status
61 | *
62 | * @param target
63 | */
64 | public void reset(View target) {
65 | if (target != null) {
66 | ViewCompat.setAlpha(target, 1);
67 | ViewCompat.setScaleX(target, 1);
68 | ViewCompat.setScaleY(target, 1);
69 | ViewCompat.setTranslationX(target, 0);
70 | ViewCompat.setTranslationY(target, 0);
71 | ViewCompat.setRotation(target, 0);
72 | ViewCompat.setRotationY(target, 0);
73 | ViewCompat.setRotationX(target, 0);
74 | ViewCompat.setPivotX(target, target.getMeasuredWidth() / 2.0f);
75 | ViewCompat.setPivotY(target, target.getMeasuredHeight() / 2.0f);
76 | }
77 | }
78 |
79 | /**
80 | * start to animate
81 | */
82 | public void start() {
83 | mAnimatorSet.start();
84 | }
85 |
86 | public BaseViewAnimator setDuration(long duration) {
87 | mDuration = duration;
88 | mAnimatorSet.setDuration(mDuration);
89 | return this;
90 | }
91 |
92 | public BaseViewAnimator setStartDelay(long delay) {
93 | getAnimatorAgent().setStartDelay(delay);
94 | return this;
95 | }
96 |
97 | public long getStartDelay() {
98 | return mAnimatorSet.getStartDelay();
99 | }
100 |
101 | public BaseViewAnimator addAnimatorListener(AnimatorListener l) {
102 | mAnimatorSet.addListener(l);
103 | return this;
104 | }
105 |
106 | public void cancel() {
107 | mAnimatorSet.cancel();
108 | }
109 |
110 | public boolean isRunning() {
111 | return mAnimatorSet.isRunning();
112 | }
113 |
114 | public boolean isStarted() {
115 | return mAnimatorSet.isStarted();
116 | }
117 |
118 | public void removeAnimatorListener(AnimatorListener l) {
119 | mAnimatorSet.removeListener(l);
120 | }
121 |
122 | public void removeAllListener() {
123 | mAnimatorSet.removeAllListeners();
124 | }
125 |
126 | public BaseViewAnimator setInterpolator(Interpolator interpolator) {
127 | mAnimatorSet.setInterpolator(interpolator);
128 | return this;
129 | }
130 |
131 | public long getDuration() {
132 | return mDuration;
133 | }
134 |
135 | public AnimatorSet getAnimatorAgent() {
136 | return mAnimatorSet;
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DragSlopLayout
2 | [](http://www.apache.org/licenses/LICENSE-2.0.html) [](https://jitpack.io/#Rukey7/DragSlopLayout)
3 |
4 | 一个辅助开发的UI库,适用于某些特殊场景,如固定范围拖拽、动画、模糊效果等。
5 |
6 | Screenshot
7 | ---
8 |
9 | #### Drag模式,可以和 ViewPager 联动
10 | 
11 |
12 | #### Animate模式,同样可以和 ViewPager 联动(自定义动画无联动效果)
13 | 
14 |
15 | #### Blur模糊效果,包括局部模糊和全图模糊
16 | 
17 |
18 | #### 外部拖拽,在屏幕上垂直滑动就可对视图进行拖拽,能够设置主视图滑动折叠
19 | 
20 |
21 | Gradle
22 | ---
23 |
24 | ### 库依赖
25 |
26 | ```gradle
27 | allprojects {
28 | repositories {
29 | ...
30 | maven { url 'https://jitpack.io' }
31 | }
32 | }
33 | ```
34 |
35 | 因为模糊库比较大,如果你需要使用模糊效果则依赖的版本{lastest-version}后面加上'-blur',不需要则不用加
36 |
37 | ```gradle
38 | compile 'com.github.Rukey7:DragSlopLayout:{lastest-version}-blur'
39 | ```
40 |
41 | ### 使用模糊库需要设置对应的配置
42 | ```groovy
43 | android {
44 | defaultConfig {
45 | renderscriptTargetApi 23
46 | renderscriptSupportModeEnabled true
47 | }
48 | }
49 | ```
50 |
51 | Usage
52 | ---
53 |
54 | ### 属性
55 | |name|format|description|
56 | |:---:|:---:|:---:|
57 | | mode | enum | drag、animate或者drag_outside, 默认为 drag
58 | | fix_height | dimension | drag模式收缩的高度, 默认为 0
59 | | max_height | dimension | drag模式展开的高度,默认为布局高度的 2/3
60 | | collapse_parallax | float | 折叠系数,效果同 CollapsingToolbarLayout,默认为 1
61 |
62 |
63 | ### 布局
64 | ```xml
65 |
66 |
73 |
74 |
78 |
79 |
80 |
84 | // ......
85 |
86 | // ......
87 |
88 | ```
89 |
90 | ### 如果 Content View 为 ViewPager,通过以下方法来实现联动效果:
91 | ```java
92 |
93 | mDragLayout.interactWithViewPager(true);
94 | // 下面新增的方法会更适用,替换上面旧的方法
95 | mDragLayout.attachViewPager(ViewPager);
96 | mDragLayout.detachViewPager();
97 |
98 | ```
99 | ### 如果 Drag View 包含 ScrollView 或则 NestedScrollView,通过以下方法来实现平滑滚动:
100 | ```java
101 |
102 | mDragLayout.setAttachScrollView(mSvView);
103 | ```
104 | ### Content View 的模糊效果,这功能是通过模糊预处理再来动态加载的,所以对于 Content View 为 ViewPager 的界面不适用,主要用来模糊固定的背景界面
105 | ```java
106 |
107 | mDragLayout.setEnableBlur(true); // 开启模糊
108 | mDragLayout.setBlurFull(true); // 设置全背景模糊,默认为局部模糊
109 | mDragLayout.updateBlurView(); // 更新模糊背景
110 | ```
111 | ### 控制 Drag View 的进入和退出
112 | ```java
113 |
114 | mDragLayout.scrollInScreen(int duration); // Drag 模式
115 | mDragLayout.scrollOutScreen(int duration); // Drag 模式
116 |
117 | mDragLayout.startInAnim(); // Animate 模式
118 | mDragLayout.startOutAnim(); // Animate 模式
119 | mDsLayout.setAnimatorMode(DragSlopLayout.FLIP_Y); // 设置动画模式
120 | ```
121 | ### 设置拖拽监听
122 | ```java
123 |
124 | mDragLayout.setDragPositionListener(new DragSlopLayout.OnDragPositionListener() {
125 | @Override
126 | public void onDragPosition(int visibleHeight, float percent, boolean isUp) {
127 | // TODO
128 | }
129 | });
130 | ```
131 |
132 | Thanks
133 | ---
134 |
135 | - [500px-android-blur](https://github.com/500px/500px-android-blur)
136 | - [AndroidViewAnimations](https://github.com/daimajia/AndroidViewAnimations)
137 |
138 | License
139 | -------
140 |
141 | Copyright 2016 Rukey7
142 |
143 | Licensed under the Apache License, Version 2.0 (the "License");
144 | you may not use this file except in compliance with the License.
145 | You may obtain a copy of the License at
146 |
147 | http://www.apache.org/licenses/LICENSE-2.0
148 |
149 | Unless required by applicable law or agreed to in writing, software
150 | distributed under the License is distributed on an "AS IS" BASIS,
151 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
152 | See the License for the specific language governing permissions and
153 | limitations under the License.
154 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/simple/src/main/res/layout/activity_drag_blur.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
19 |
20 |
25 |
26 |
36 |
37 |
45 |
46 |
51 |
52 |
58 |
59 |
64 |
65 |
73 |
74 |
75 |
81 |
82 |
87 |
88 |
96 |
97 |
98 |
104 |
105 |
110 |
111 |
119 |
120 |
121 |
127 |
128 |
133 |
134 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/adapter/DividerGridItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.adapter;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Rect;
7 | import android.graphics.drawable.Drawable;
8 | import android.support.v7.widget.GridLayoutManager;
9 | import android.support.v7.widget.RecyclerView;
10 | import android.support.v7.widget.RecyclerView.LayoutManager;
11 | import android.support.v7.widget.StaggeredGridLayoutManager;
12 | import android.view.View;
13 |
14 | /**
15 | * 网格列表分割线
16 | */
17 | public class DividerGridItemDecoration extends RecyclerView.ItemDecoration {
18 |
19 | private static final int[] ATTRS = new int[]{android.R.attr.listDivider};
20 | private Drawable mDivider;
21 |
22 | public DividerGridItemDecoration(Context context) {
23 | final TypedArray a = context.obtainStyledAttributes(ATTRS);
24 | mDivider = a.getDrawable(0);
25 | a.recycle();
26 | }
27 |
28 | @Override
29 | public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
30 |
31 | drawHorizontal(c, parent);
32 | drawVertical(c, parent);
33 |
34 | }
35 |
36 | private int getSpanCount(RecyclerView parent) {
37 | // 列数
38 | int spanCount = -1;
39 | LayoutManager layoutManager = parent.getLayoutManager();
40 | if (layoutManager instanceof GridLayoutManager) {
41 |
42 | spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
43 | } else if (layoutManager instanceof StaggeredGridLayoutManager) {
44 | spanCount = ((StaggeredGridLayoutManager) layoutManager)
45 | .getSpanCount();
46 | }
47 | return spanCount;
48 | }
49 |
50 | public void drawHorizontal(Canvas c, RecyclerView parent) {
51 | int childCount = parent.getChildCount();
52 | for (int i = 0; i < childCount; i++) {
53 | final View child = parent.getChildAt(i);
54 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
55 | .getLayoutParams();
56 | final int left = child.getLeft() - params.leftMargin;
57 | final int right = child.getRight() + params.rightMargin
58 | + mDivider.getIntrinsicWidth();
59 | final int top = child.getBottom() + params.bottomMargin;
60 | final int bottom = top + mDivider.getIntrinsicHeight();
61 | mDivider.setBounds(left, top, right, bottom);
62 | mDivider.draw(c);
63 | }
64 | }
65 |
66 | public void drawVertical(Canvas c, RecyclerView parent) {
67 | final int childCount = parent.getChildCount();
68 | for (int i = 0; i < childCount; i++) {
69 | final View child = parent.getChildAt(i);
70 |
71 | final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
72 | .getLayoutParams();
73 | final int top = child.getTop() - params.topMargin;
74 | final int bottom = child.getBottom() + params.bottomMargin;
75 | final int left = child.getRight() + params.rightMargin;
76 | final int right = left + mDivider.getIntrinsicWidth();
77 |
78 | mDivider.setBounds(left, top, right, bottom);
79 | mDivider.draw(c);
80 | }
81 | }
82 |
83 | private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
84 | int childCount) {
85 | LayoutManager layoutManager = parent.getLayoutManager();
86 | if (layoutManager instanceof GridLayoutManager) {
87 | if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
88 | {
89 | return true;
90 | }
91 | } else if (layoutManager instanceof StaggeredGridLayoutManager) {
92 | int orientation = ((StaggeredGridLayoutManager) layoutManager)
93 | .getOrientation();
94 | if (orientation == StaggeredGridLayoutManager.VERTICAL) {
95 | if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
96 | {
97 | return true;
98 | }
99 | } else {
100 | childCount = childCount - childCount % spanCount;
101 | if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
102 | return true;
103 | }
104 | }
105 | return false;
106 | }
107 |
108 | private boolean isLastRaw(RecyclerView parent, int pos, int spanCount,
109 | int childCount) {
110 | LayoutManager layoutManager = parent.getLayoutManager();
111 | if (layoutManager instanceof GridLayoutManager) {
112 | childCount = childCount - childCount % spanCount;
113 | if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
114 | return true;
115 | } else if (layoutManager instanceof StaggeredGridLayoutManager) {
116 | int orientation = ((StaggeredGridLayoutManager) layoutManager)
117 | .getOrientation();
118 | // StaggeredGridLayoutManager 且纵向滚动
119 | if (orientation == StaggeredGridLayoutManager.VERTICAL) {
120 | childCount = childCount - childCount % spanCount;
121 | // 如果是最后一行,则不需要绘制底部
122 | if (pos >= childCount)
123 | return true;
124 | } else
125 | // StaggeredGridLayoutManager 且横向滚动
126 | {
127 | // 如果是最后一行,则不需要绘制底部
128 | if ((pos + 1) % spanCount == 0) {
129 | return true;
130 | }
131 | }
132 | }
133 | return false;
134 | }
135 |
136 | @Override
137 | public void getItemOffsets(Rect outRect, int itemPosition,
138 | RecyclerView parent) {
139 | int spanCount = getSpanCount(parent);
140 | int childCount = parent.getAdapter().getItemCount();
141 | if (isLastRaw(parent, itemPosition, spanCount, childCount))// 如果是最后一行,则不需要绘制底部
142 | {
143 | outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
144 | } else if (isLastColum(parent, itemPosition, spanCount, childCount))// 如果是最后一列,则不需要绘制右边
145 | {
146 | outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
147 | } else {
148 | outRect.set(0, 0, mDivider.getIntrinsicWidth(),
149 | mDivider.getIntrinsicHeight());
150 | }
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/activity/DragOutsideActivity.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.activity;
2 |
3 | import android.animation.Animator;
4 | import android.os.Bundle;
5 | import android.support.v4.view.ViewCompat;
6 | import android.support.v4.view.ViewPager;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.Menu;
10 | import android.view.MenuItem;
11 | import android.view.View;
12 | import android.widget.ImageView;
13 | import android.widget.LinearLayout;
14 |
15 | import com.dl7.drag.DragSlopLayout;
16 | import com.dl7.simple.drag.R;
17 | import com.dl7.simple.drag.adapter.PhotoPagerAdapter;
18 | import com.dl7.simple.drag.adapter.ThumbAdapter;
19 | import com.dl7.simple.drag.utils.AnimateHelper;
20 | import com.dl7.simple.drag.utils.RecyclerViewHelper;
21 |
22 | import java.util.ArrayList;
23 | import java.util.List;
24 |
25 | import butterknife.BindView;
26 | import butterknife.ButterKnife;
27 | import butterknife.OnClick;
28 |
29 | public class DragOutsideActivity extends BaseActivity {
30 |
31 | @BindView(R.id.vp_photo)
32 | ViewPager mVpPhoto;
33 | @BindView(R.id.rv_relate_list)
34 | RecyclerView mRvRelateList;
35 | @BindView(R.id.tool_bar)
36 | Toolbar mToolBar;
37 | @BindView(R.id.iv_favorite)
38 | ImageView mIvFavorite;
39 | @BindView(R.id.iv_download)
40 | ImageView mIvDownload;
41 | @BindView(R.id.iv_praise)
42 | ImageView mIvPraise;
43 | @BindView(R.id.iv_share)
44 | ImageView mIvShare;
45 | @BindView(R.id.bottom_bar)
46 | LinearLayout mBottomBar;
47 | @BindView(R.id.drag_layout)
48 | DragSlopLayout mDragLayout;
49 |
50 | private boolean mIsInteract = true;
51 | private ThumbAdapter mAdapter;
52 | private boolean mIsHideToolbar = false; // 是否隐藏 Toolbar
53 | private Animator mToolBarAnimator;
54 | private Animator mBottomBarAnimator;
55 |
56 | @Override
57 | protected void onCreate(Bundle savedInstanceState) {
58 | super.onCreate(savedInstanceState);
59 | setContentView(R.layout.activity_drag_outside);
60 | ButterKnife.bind(this);
61 | initToolBar(mToolBar, true, "Drag Outside Mode");
62 | // 设置 ViewPager
63 | List imgList = new ArrayList<>();
64 | imgList.add(R.mipmap.pic1);
65 | imgList.add(R.mipmap.pic2);
66 | imgList.add(R.mipmap.pic3);
67 | imgList.add(R.mipmap.pic4);
68 | imgList.add(R.mipmap.pic5);
69 | PhotoPagerAdapter mPagerAdapter = new PhotoPagerAdapter(this, imgList, true);
70 | mVpPhoto.setAdapter(mPagerAdapter);
71 | mPagerAdapter.setListener(new PhotoPagerAdapter.OnPhotoClickListener() {
72 | @Override
73 | public void onPhotoClick() {
74 | mIsHideToolbar = !mIsHideToolbar;
75 | if (mIsHideToolbar) {
76 | AnimateHelper.stopAnimator(mToolBarAnimator);
77 | mToolBarAnimator = AnimateHelper.doMoveVertical(mToolBar, (int) mToolBar.getTranslationY(),
78 | -mToolBar.getBottom(), 300);
79 | if (mBottomBar.getTranslationY() != mBottomBar.getHeight()) {
80 | AnimateHelper.stopAnimator(mBottomBarAnimator);
81 | mBottomBarAnimator = AnimateHelper.doMoveVertical(mBottomBar, (int) mBottomBar.getTranslationY(),
82 | mBottomBar.getHeight(), 300);
83 | }
84 | } else {
85 | AnimateHelper.stopAnimator(mToolBarAnimator);
86 | mToolBarAnimator = AnimateHelper.doMoveVertical(mToolBar, (int) mToolBar.getTranslationY(),
87 | 0, 300);
88 | ViewCompat.animate(mToolBar).translationY(0).setDuration(300).start();
89 | if (mBottomBar.getTranslationY() != 0) {
90 | AnimateHelper.stopAnimator(mBottomBarAnimator);
91 | mBottomBarAnimator = AnimateHelper.doMoveVertical(mBottomBar, (int) mBottomBar.getTranslationY(),
92 | 0, 300);
93 | }
94 | }
95 | }
96 | });
97 | // 设置 RecyclerView
98 | List thumbList = new ArrayList<>();
99 | thumbList.add(R.mipmap.pic1);
100 | thumbList.add(R.mipmap.pic2);
101 | thumbList.add(R.mipmap.pic3);
102 | thumbList.add(R.mipmap.pic4);
103 | thumbList.add(R.mipmap.pic5);
104 | thumbList.add(R.mipmap.pic1);
105 | thumbList.add(R.mipmap.pic2);
106 | thumbList.add(R.mipmap.pic3);
107 | thumbList.add(R.mipmap.pic4);
108 | thumbList.add(R.mipmap.pic5);
109 | thumbList.add(R.mipmap.pic1);
110 | thumbList.add(R.mipmap.pic2);
111 | thumbList.add(R.mipmap.pic3);
112 | thumbList.add(R.mipmap.pic4);
113 | thumbList.add(R.mipmap.pic5);
114 | mAdapter = new ThumbAdapter(this, thumbList);
115 | RecyclerViewHelper.initRecyclerViewH(this, mRvRelateList, mAdapter);
116 | // 和 ViewPager 联动
117 | // mDragLayout.interactWithViewPager(mIsInteract);
118 | mDragLayout.attachViewPager(mVpPhoto);
119 | mDragLayout.setDragPositionListener(new DragSlopLayout.OnDragPositionListener() {
120 | @Override
121 | public void onDragPosition(int visibleHeight, float percent, boolean isUp) {
122 | if (AnimateHelper.isRunning(mBottomBarAnimator) || mIsHideToolbar) {
123 | return;
124 | }
125 | if (isUp && mBottomBar.getTranslationY() != mBottomBar.getHeight()) {
126 | mBottomBarAnimator = AnimateHelper.doMoveVertical(mBottomBar, (int) mBottomBar.getTranslationY(),
127 | mBottomBar.getHeight(), 300);
128 | } else if (!isUp && mBottomBar.getTranslationY() != 0) {
129 | mBottomBarAnimator = AnimateHelper.doMoveVertical(mBottomBar, (int) mBottomBar.getTranslationY(),
130 | 0, 300);
131 | }
132 | }
133 | });
134 | }
135 |
136 | @Override
137 | public boolean onCreateOptionsMenu(Menu menu) {
138 | getMenuInflater().inflate(R.menu.menu_drag, menu);
139 | return true;
140 | }
141 |
142 | @Override
143 | public boolean onOptionsItemSelected(MenuItem item) {
144 | switch (item.getItemId()) {
145 | case R.id.item_interact:
146 | mIsInteract = !mIsInteract;
147 | item.setChecked(mIsInteract);
148 | // mDsLayout.interactWithViewPager(mIsInteract);
149 | if (mIsInteract) {
150 | mDragLayout.attachViewPager(mVpPhoto);
151 | } else {
152 | mDragLayout.detachViewPager();
153 | }
154 | return true;
155 | }
156 | return super.onOptionsItemSelected(item);
157 | }
158 |
159 | @Override
160 | protected void onDestroy() {
161 | super.onDestroy();
162 | AnimateHelper.deleteAnimator(mToolBarAnimator);
163 | AnimateHelper.deleteAnimator(mBottomBarAnimator);
164 | }
165 |
166 | @OnClick({R.id.iv_favorite, R.id.iv_download, R.id.iv_praise, R.id.iv_share})
167 | public void onClick(View view) {
168 | switch (view.getId()) {
169 | case R.id.iv_favorite:
170 | break;
171 | case R.id.iv_download:
172 | break;
173 | case R.id.iv_praise:
174 | break;
175 | case R.id.iv_share:
176 | break;
177 | }
178 | }
179 | }
180 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/animate/AnimatorPresenter.java:
--------------------------------------------------------------------------------
1 | package com.dl7.drag.animate;
2 |
3 | import android.support.v4.view.ViewCompat;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.view.animation.Interpolator;
7 | import android.view.animation.LinearInterpolator;
8 |
9 | import com.dl7.drag.DragSlopLayout;
10 | import com.dl7.drag.DragSlopLayout.AnimatorMode;
11 | import com.dl7.drag.animate.in.FadeInAnimator;
12 | import com.dl7.drag.animate.in.FlipInXAnimator;
13 | import com.dl7.drag.animate.in.FlipInYAnimator;
14 | import com.dl7.drag.animate.in.SlideInBottomAnimator;
15 | import com.dl7.drag.animate.in.SlideInLeftAnimator;
16 | import com.dl7.drag.animate.in.SlideInRightAnimator;
17 | import com.dl7.drag.animate.in.ZoomInAnimator;
18 | import com.dl7.drag.animate.in.ZoomInLeftAnimator;
19 | import com.dl7.drag.animate.in.ZoomInRightAnimator;
20 | import com.dl7.drag.animate.out.FadeOutAnimator;
21 | import com.dl7.drag.animate.out.FlipOutXAnimator;
22 | import com.dl7.drag.animate.out.FlipOutYAnimator;
23 | import com.dl7.drag.animate.out.SlideOutBottomAnimator;
24 | import com.dl7.drag.animate.out.SlideOutLeftAnimator;
25 | import com.dl7.drag.animate.out.SlideOutRightAnimator;
26 | import com.dl7.drag.animate.out.ZoomOutAnimator;
27 | import com.dl7.drag.animate.out.ZoomOutLeftAnimator;
28 | import com.dl7.drag.animate.out.ZoomOutRightAnimator;
29 |
30 | /**
31 | * Created by long on 2016/9/9.
32 | * 动画持有者
33 | */
34 | public final class AnimatorPresenter {
35 |
36 | private BaseViewAnimator mInAnimator;
37 | private BaseViewAnimator mOutAnimator;
38 | @AnimatorMode
39 | private int mAnimatorMode;
40 | private int mStartDelay;
41 | private int mDuration;
42 | private Interpolator mInterpolator;
43 | private boolean mIsCustomAnimator = false;
44 |
45 | public AnimatorPresenter() {
46 | mAnimatorMode = DragSlopLayout.SLIDE_BOTTOM;
47 | mInAnimator = new SlideInBottomAnimator();
48 | mOutAnimator = new SlideOutBottomAnimator();
49 | mDuration = 400;
50 | mInterpolator = new LinearInterpolator();
51 | }
52 |
53 | /**
54 | * 设置动画
55 | * @param animatorMode
56 | */
57 | public void setAnimatorMode(@AnimatorMode int animatorMode) {
58 | mAnimatorMode = animatorMode;
59 | mIsCustomAnimator = false;
60 | switch (animatorMode) {
61 | case DragSlopLayout.SLIDE_BOTTOM:
62 | mInAnimator = new SlideInBottomAnimator();
63 | mOutAnimator = new SlideOutBottomAnimator();
64 | break;
65 | case DragSlopLayout.SLIDE_LEFT:
66 | mInAnimator = new SlideInLeftAnimator();
67 | mOutAnimator = new SlideOutLeftAnimator();
68 | break;
69 | case DragSlopLayout.SLIDE_RIGHT:
70 | mInAnimator = new SlideInRightAnimator();
71 | mOutAnimator = new SlideOutRightAnimator();
72 | break;
73 | case DragSlopLayout.FADE:
74 | mInAnimator = new FadeInAnimator();
75 | mOutAnimator = new FadeOutAnimator();
76 | break;
77 | case DragSlopLayout.FLIP_X:
78 | mInAnimator = new FlipInXAnimator();
79 | mOutAnimator = new FlipOutXAnimator();
80 | break;
81 | case DragSlopLayout.FLIP_Y:
82 | mInAnimator = new FlipInYAnimator();
83 | mOutAnimator = new FlipOutYAnimator();
84 | break;
85 | case DragSlopLayout.ZOOM:
86 | mInAnimator = new ZoomInAnimator();
87 | mOutAnimator = new ZoomOutAnimator();
88 | break;
89 | case DragSlopLayout.ZOOM_LEFT:
90 | mInAnimator = new ZoomInLeftAnimator();
91 | mOutAnimator = new ZoomOutLeftAnimator();
92 | break;
93 | case DragSlopLayout.ZOOM_RIGHT:
94 | mInAnimator = new ZoomInRightAnimator();
95 | mOutAnimator = new ZoomOutRightAnimator();
96 | break;
97 | }
98 | }
99 |
100 | @AnimatorMode
101 | public int getAnimatorMode() {
102 | return mAnimatorMode;
103 | }
104 |
105 | /**
106 | * 设置自定义动画
107 | * @param inAnimator
108 | * @param outAnimator
109 | */
110 | public void setCustomAnimator(BaseViewAnimator inAnimator, BaseViewAnimator outAnimator) {
111 | mInAnimator = inAnimator;
112 | mOutAnimator = outAnimator;
113 | mIsCustomAnimator = true;
114 | }
115 |
116 | /**
117 | * 启动进入动画
118 | * @param target 目标View
119 | */
120 | public void startInAnim(View target) {
121 | if (mIsCustomAnimator) {
122 | mInAnimator.setTarget(null)
123 | .start();
124 | } else {
125 | mInAnimator.setTarget(target)
126 | .setStartDelay(mStartDelay)
127 | .setDuration(mDuration)
128 | .setInterpolator(mInterpolator)
129 | .start();
130 | }
131 | }
132 |
133 | /**
134 | * 启动退出动画
135 | * @param target 目标View
136 | */
137 | public void startOutAnim(View target) {
138 | if (mIsCustomAnimator) {
139 | mOutAnimator.setTarget(null)
140 | .start();
141 | } else {
142 | mOutAnimator.setTarget(target)
143 | .setStartDelay(mStartDelay)
144 | .setDuration(mDuration)
145 | .setInterpolator(mInterpolator)
146 | .start();
147 | }
148 | }
149 |
150 | /**
151 | * 处理动画帧
152 | * @param percent 百分比
153 | */
154 | public void handleAnimateFrame(View target, float percent) {
155 | ViewGroup parent = (ViewGroup) target.getParent();
156 | float alpha = 1.0f * (1 - percent);
157 | float translationX = 0;
158 | float translationY = 0;
159 | float rotationX = 0;
160 | float rotationY = 0;
161 | float scale = 1.0f;
162 |
163 | switch (mAnimatorMode) {
164 | case DragSlopLayout.SLIDE_BOTTOM:
165 | translationY = target.getHeight() * percent;
166 | break;
167 |
168 | case DragSlopLayout.SLIDE_LEFT:
169 | translationX = - parent.getWidth() * percent;
170 | break;
171 |
172 | case DragSlopLayout.SLIDE_RIGHT:
173 | translationX = parent.getWidth() * percent;
174 | break;
175 |
176 | case DragSlopLayout.FADE:
177 | break;
178 |
179 | case DragSlopLayout.FLIP_X:
180 | rotationX = 90 * percent;
181 | break;
182 |
183 | case DragSlopLayout.FLIP_Y:
184 | rotationY = 90 * percent;
185 | break;
186 |
187 | case DragSlopLayout.ZOOM:
188 | scale = 0.3f + 0.7f * (1 - percent);
189 | break;
190 |
191 | case DragSlopLayout.ZOOM_LEFT:
192 | alpha = Math.min(1.0f, alpha * 2);
193 | final float valueL = parent.getWidth() * 0.2f;
194 | if (percent < 0.5f) {
195 | scale = 1 - percent;
196 | translationX = percent * 2 * valueL;
197 | } else {
198 | scale = (1 - percent) * 0.8f + 0.1f;
199 | translationX = valueL - (percent * 2 - 1.0f) * parent.getWidth() * 1.2f;
200 | }
201 | break;
202 | case DragSlopLayout.ZOOM_RIGHT:
203 | alpha = Math.min(1.0f, alpha * 2);
204 | final float valueR = -parent.getWidth() * 0.2f;
205 | if (percent < 0.5f) {
206 | scale = 1 - percent;
207 | translationX = percent * 2 * valueR;
208 | } else {
209 | scale = (1 - percent) * 0.8f + 0.1f;
210 | translationX = valueR + (percent * 2 - 1.0f) * parent.getWidth() * 1.2f;
211 | }
212 | break;
213 | }
214 |
215 | ViewCompat.setAlpha(target, alpha);
216 | ViewCompat.setTranslationX(target, translationX);
217 | ViewCompat.setTranslationY(target, translationY);
218 | ViewCompat.setRotationX(target, rotationX);
219 | ViewCompat.setRotationY(target, rotationY);
220 | ViewCompat.setScaleX(target, scale);
221 | ViewCompat.setScaleY(target, scale);
222 | }
223 |
224 |
225 | public int getStartDelay() {
226 | return mStartDelay;
227 | }
228 |
229 | public void setStartDelay(int startDelay) {
230 | mStartDelay = startDelay;
231 | }
232 |
233 | public int getDuration() {
234 | return mDuration;
235 | }
236 |
237 | public void setDuration(int duration) {
238 | mDuration = duration;
239 | }
240 |
241 | public Interpolator getInterpolator() {
242 | return mInterpolator;
243 | }
244 |
245 | public void setInterpolator(Interpolator interpolator) {
246 | mInterpolator = interpolator;
247 | }
248 |
249 | public void stopAllAnimator() {
250 | if (mInAnimator.isRunning()) {
251 | mInAnimator.cancel();
252 | }
253 | if (mOutAnimator.isRunning()) {
254 | mOutAnimator.cancel();
255 | }
256 | }
257 | }
258 |
--------------------------------------------------------------------------------
/simple/src/main/java/com/dl7/simple/drag/activity/AnimateActivity.java:
--------------------------------------------------------------------------------
1 | package com.dl7.simple.drag.activity;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorSet;
5 | import android.animation.ObjectAnimator;
6 | import android.graphics.Color;
7 | import android.os.Bundle;
8 | import android.support.v4.content.ContextCompat;
9 | import android.support.v4.view.ViewPager;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 | import android.widget.ImageView;
15 | import android.widget.LinearLayout;
16 | import android.widget.Toast;
17 |
18 | import com.dl7.drag.DragSlopLayout;
19 | import com.dl7.drag.animate.CustomViewAnimator;
20 | import com.dl7.simple.drag.AnimateHelper;
21 | import com.dl7.simple.drag.adapter.PhotoPagerAdapter;
22 | import com.dl7.simple.drag.R;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | import butterknife.BindView;
28 | import butterknife.ButterKnife;
29 | import butterknife.OnClick;
30 |
31 | public class AnimateActivity extends BaseActivity {
32 |
33 | @BindView(R.id.vp_photo)
34 | ViewPager mVpPhoto;
35 | @BindView(R.id.ll_view)
36 | LinearLayout mLlView;
37 | @BindView(R.id.iv_favorite)
38 | ImageView mIvFavorite;
39 | @BindView(R.id.iv_download)
40 | ImageView mIvDownload;
41 | @BindView(R.id.iv_praise)
42 | ImageView mIvPraise;
43 | @BindView(R.id.iv_share)
44 | ImageView mIvShare;
45 | @BindView(R.id.ds_layout)
46 | DragSlopLayout mDsLayout;
47 | @BindView(R.id.tool_bar)
48 | Toolbar mToolBar;
49 |
50 | boolean isOpen = true;
51 | private boolean mIsInteract = true;
52 |
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 | setContentView(R.layout.activity_animate);
58 | ButterKnife.bind(this);
59 | initToolBar(mToolBar, true, "");
60 |
61 | mDsLayout = (DragSlopLayout) findViewById(R.id.ds_layout);
62 | List imgList = new ArrayList<>();
63 | imgList.add(R.mipmap.pic1);
64 | imgList.add(R.mipmap.pic2);
65 | imgList.add(R.mipmap.pic3);
66 | imgList.add(R.mipmap.pic4);
67 | imgList.add(R.mipmap.pic5);
68 | PhotoPagerAdapter mPagerAdapter = new PhotoPagerAdapter(this, imgList, true);
69 | mVpPhoto.setAdapter(mPagerAdapter);
70 | mPagerAdapter.setListener(new PhotoPagerAdapter.OnPhotoClickListener() {
71 | @Override
72 | public void onPhotoClick() {
73 | if (isOpen) {
74 | mDsLayout.startOutAnim();
75 | } else {
76 | mDsLayout.startInAnim();
77 | }
78 | isOpen = !isOpen;
79 | }
80 | });
81 | // mDsLayout.interactWithViewPager(mIsInteract);
82 | mDsLayout.attachViewPager(mVpPhoto);
83 | }
84 |
85 | @OnClick({R.id.iv_favorite, R.id.iv_download, R.id.iv_praise, R.id.iv_share})
86 | public void onClick(View view) {
87 | boolean isSelected = !view.isSelected();
88 | view.setSelected(isSelected);
89 | switch (view.getId()) {
90 | case R.id.iv_favorite:
91 | AnimateHelper.doHeartBeat(view, 500);
92 | break;
93 | case R.id.iv_download:
94 | break;
95 | case R.id.iv_praise:
96 | AnimateHelper.doHeartBeat(view, 500);
97 | break;
98 | case R.id.iv_share:
99 | Toast.makeText(this, "分享", Toast.LENGTH_SHORT).show();
100 | break;
101 | }
102 | }
103 |
104 | @Override
105 | public boolean onCreateOptionsMenu(Menu menu) {
106 | getMenuInflater().inflate(R.menu.menu_animate, menu);
107 | return true;
108 | }
109 |
110 | @Override
111 | public boolean onOptionsItemSelected(MenuItem item) {
112 | item.setChecked(true);
113 | // 默认的动画是控制整个 DragView
114 | mLlView.setBackgroundColor(ContextCompat.getColor(this, android.R.color.holo_green_light));
115 | switch (item.getItemId()) {
116 | case R.id.slide_bottom:
117 | mDsLayout.setAnimatorMode(DragSlopLayout.SLIDE_BOTTOM);
118 | return true;
119 | case R.id.slide_left:
120 | mDsLayout.setAnimatorMode(DragSlopLayout.SLIDE_LEFT);
121 | return true;
122 | case R.id.slide_right:
123 | mDsLayout.setAnimatorMode(DragSlopLayout.SLIDE_RIGHT);
124 | return true;
125 | case R.id.slide_fade:
126 | mDsLayout.setAnimatorMode(DragSlopLayout.FADE);
127 | return true;
128 | case R.id.slide_flip_x:
129 | mDsLayout.setAnimatorMode(DragSlopLayout.FLIP_X);
130 | return true;
131 | case R.id.slide_flip_y:
132 | mDsLayout.setAnimatorMode(DragSlopLayout.FLIP_Y);
133 | return true;
134 | case R.id.slide_zoom:
135 | mDsLayout.setAnimatorMode(DragSlopLayout.ZOOM);
136 | return true;
137 | case R.id.slide_zoom_left:
138 | mDsLayout.setAnimatorMode(DragSlopLayout.ZOOM_LEFT);
139 | return true;
140 | case R.id.slide_zoom_right:
141 | mDsLayout.setAnimatorMode(DragSlopLayout.ZOOM_RIGHT);
142 | return true;
143 | case R.id.slide_custom_one:
144 | mLlView.setBackgroundColor(Color.TRANSPARENT);
145 | _handleCustomOne();
146 | return true;
147 | case R.id.slide_custom_two:
148 | mLlView.setBackgroundColor(Color.TRANSPARENT);
149 | _handleCustomTwo();
150 | return true;
151 |
152 | case R.id.item_interact:
153 | mIsInteract = !mIsInteract;
154 | item.setChecked(mIsInteract);
155 | // mDsLayout.interactWithViewPager(mIsInteract);
156 | if (mIsInteract) {
157 | mDsLayout.attachViewPager(mVpPhoto);
158 | } else {
159 | mDsLayout.detachViewPager();
160 | }
161 | return true;
162 | }
163 | return super.onOptionsItemSelected(item);
164 | }
165 |
166 | /**
167 | * 自定义动画 1
168 | */
169 | private void _handleCustomOne() {
170 | mDsLayout.setCustomAnimator(new CustomViewAnimator() {
171 | @Override
172 | protected Animator doAnimator() {
173 | ObjectAnimator one = ObjectAnimator.ofFloat(mIvFavorite, "translationX", mDsLayout.getWidth(), -100, 50, 0);
174 | ObjectAnimator two = ObjectAnimator.ofFloat(mIvDownload, "translationX", mDsLayout.getWidth(), -100, 50, 0);
175 | two.setStartDelay(100);
176 | ObjectAnimator three = ObjectAnimator.ofFloat(mIvPraise, "translationX", mDsLayout.getWidth(), -100, 50, 0);
177 | three.setStartDelay(200);
178 | ObjectAnimator four = ObjectAnimator.ofFloat(mIvShare, "translationX", mDsLayout.getWidth(), -100, 50, 0);
179 | four.setStartDelay(300);
180 | AnimatorSet animatorSet = new AnimatorSet();
181 | animatorSet.setDuration(700);
182 | animatorSet.playTogether(one, two, three, four);
183 | return animatorSet;
184 | }
185 | }, new CustomViewAnimator() {
186 | @Override
187 | protected Animator doAnimator() {
188 | ObjectAnimator one = ObjectAnimator.ofFloat(mIvFavorite, "translationX", 0, mDsLayout.getWidth());
189 | one.setStartDelay(300);
190 | ObjectAnimator two = ObjectAnimator.ofFloat(mIvDownload, "translationX", 0, mDsLayout.getWidth());
191 | two.setStartDelay(200);
192 | ObjectAnimator three = ObjectAnimator.ofFloat(mIvPraise, "translationX", 0, mDsLayout.getWidth());
193 | three.setStartDelay(100);
194 | ObjectAnimator four = ObjectAnimator.ofFloat(mIvShare, "translationX", 0, mDsLayout.getWidth());
195 | AnimatorSet animatorSet = new AnimatorSet();
196 | animatorSet.setDuration(700);
197 | animatorSet.playTogether(four, three, two, one);
198 | return animatorSet;
199 | }
200 | });
201 | }
202 |
203 | /**
204 | * 自定义动画 2
205 | */
206 | private void _handleCustomTwo() {
207 | mDsLayout.setCustomAnimator(new CustomViewAnimator() {
208 | @Override
209 | protected Animator doAnimator() {
210 | ObjectAnimator one = ObjectAnimator.ofFloat(mIvFavorite, "translationY", mLlView.getHeight(), 0);
211 | ObjectAnimator two = ObjectAnimator.ofFloat(mIvDownload, "translationY", mLlView.getHeight(), 0);
212 | two.setStartDelay(100);
213 | ObjectAnimator three = ObjectAnimator.ofFloat(mIvPraise, "translationY", mLlView.getHeight(), 0);
214 | three.setStartDelay(200);
215 | ObjectAnimator four = ObjectAnimator.ofFloat(mIvShare, "translationY", mLlView.getHeight(), 0);
216 | four.setStartDelay(300);
217 | AnimatorSet animatorSet = new AnimatorSet();
218 | animatorSet.setDuration(300);
219 | animatorSet.playTogether(one, two, three, four);
220 | return animatorSet;
221 | }
222 | }, new CustomViewAnimator() {
223 | @Override
224 | protected Animator doAnimator() {
225 | ObjectAnimator one = ObjectAnimator.ofFloat(mIvFavorite, "translationY", 0, mLlView.getHeight());
226 | ObjectAnimator two = ObjectAnimator.ofFloat(mIvDownload, "translationY", 0, mLlView.getHeight());
227 | two.setStartDelay(100);
228 | ObjectAnimator three = ObjectAnimator.ofFloat(mIvPraise, "translationY", 0, mLlView.getHeight());
229 | three.setStartDelay(200);
230 | ObjectAnimator four = ObjectAnimator.ofFloat(mIvShare, "translationY", 0, mLlView.getHeight());
231 | four.setStartDelay(300);
232 | AnimatorSet animatorSet = new AnimatorSet();
233 | animatorSet.setDuration(300);
234 | animatorSet.playTogether(one, two, three, four);
235 | return animatorSet;
236 | }
237 | });
238 | }
239 | }
240 |
--------------------------------------------------------------------------------
/dragsloplayout/src/main/java/com/dl7/drag/DragSlopLayout.java:
--------------------------------------------------------------------------------
1 | package com.dl7.drag;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.Canvas;
7 | import android.graphics.Color;
8 | import android.graphics.drawable.BitmapDrawable;
9 | import android.graphics.drawable.ClipDrawable;
10 | import android.graphics.drawable.ColorDrawable;
11 | import android.graphics.drawable.Drawable;
12 | import android.os.Build;
13 | import android.support.annotation.IntDef;
14 | import android.support.v4.view.MotionEventCompat;
15 | import android.support.v4.view.ViewCompat;
16 | import android.support.v4.view.ViewPager;
17 | import android.support.v4.widget.NestedScrollView;
18 | import android.support.v4.widget.ScrollerCompat;
19 | import android.support.v4.widget.ViewDragHelper;
20 | import android.support.v8.renderscript.Allocation;
21 | import android.support.v8.renderscript.Element;
22 | import android.support.v8.renderscript.RenderScript;
23 | import android.support.v8.renderscript.ScriptIntrinsicBlur;
24 | import android.util.AttributeSet;
25 | import android.view.GestureDetector;
26 | import android.view.Gravity;
27 | import android.view.MotionEvent;
28 | import android.view.View;
29 | import android.view.ViewConfiguration;
30 | import android.view.ViewGroup;
31 | import android.view.ViewParent;
32 | import android.view.animation.BounceInterpolator;
33 | import android.view.animation.DecelerateInterpolator;
34 | import android.view.animation.Interpolator;
35 | import android.widget.FrameLayout;
36 | import android.widget.ScrollView;
37 |
38 | import com.dl7.drag.animate.AnimatorPresenter;
39 | import com.dl7.drag.animate.CustomViewAnimator;
40 |
41 | import java.lang.annotation.Retention;
42 | import java.lang.annotation.RetentionPolicy;
43 |
44 | /**
45 | * Created by long on 2016/9/6.
46 | * 实现拖拽出界外的布局
47 | */
48 | public class DragSlopLayout extends FrameLayout {
49 |
50 | public static final int MODE_DRAG = 1;
51 | public static final int MODE_ANIMATE = 2;
52 | public static final int MODE_DRAG_OUTSIDE = 3;
53 |
54 | // 展开
55 | static final int STATUS_EXPANDED = 1001;
56 | // 收缩
57 | static final int STATUS_COLLAPSED = 1002;
58 | // 退出
59 | static final int STATUS_EXIT = 1003;
60 | // 滚动
61 | static final int STATUS_SCROLL = 1004;
62 |
63 | // ViewDragHelper 的敏感度
64 | private static final float TOUCH_SLOP_SENSITIVITY = 1.0f;
65 | // 判断快速滑动的速率
66 | private static final float FLING_VELOCITY = 5000;
67 | // 下坠动画时间
68 | private static final int FALL_BOUND_DURATION = 1000;
69 |
70 | // 模式
71 | private int mMode;
72 | // 固定高度
73 | private int mFixHeight;
74 | // 最大高度
75 | private int mMaxHeight;
76 | // 折叠系数,1.0最大表示完全折叠,mMainView 视图不动;效果同 CollapsingToolbarLayout
77 | private float mCollapseParallax = 1.0f;
78 | // 整个布局高度
79 | private int mHeight;
80 | // 拖拽模式的临界Top值
81 | private int mCriticalTop;
82 | // 拖拽模式的展开状态Top值
83 | private int mExpandedTop;
84 | // 拖拽模式的收缩状态Top值
85 | private int mCollapsedTop;
86 | // 是否处于拖拽状态
87 | private boolean mIsDrag = false;
88 | // 拖拽状态
89 | @DragStatus
90 | private int mDragStatus = STATUS_EXPANDED;
91 | // 是否有 post 显示动画 Runnable
92 | private boolean mHasShowRunnable = false;
93 |
94 | // 布局的第1个子视图
95 | private View mMainView;
96 | // 新增模糊视图,用来处理动态模糊效果,为布局的第2个子视图
97 | private View mBlurView;
98 | // 可拖拽的视图,为布局的第3个子视图
99 | private View mDragView;
100 | // 拖拽帮助类
101 | private ViewDragHelper mDragHelper;
102 | // 下坠滚动辅助类
103 | private ScrollerCompat mFallBoundScroller;
104 | // 回升滚动辅助类
105 | private ScrollerCompat mDecelerateScroller;
106 | // ViewPager 监听器
107 | private ViewPager.OnPageChangeListener mViewPagerListener;
108 | // 动画持有者
109 | private AnimatorPresenter mAnimPresenter;
110 | // 和 ViewPager 联动时的自动执行进入动画的延迟时间,注意和动画的启动延迟时间区分
111 | private int mAutoAnimateDelay = 1000;
112 | // 是否手动执行了退出动画,如果为真则不再执行自动进入动画
113 | private boolean mIsDoOutAnim = false;
114 | // 是否设置自定义动画,true 的话关闭 ViewPager 联动动画
115 | private boolean mIsCustomAnimator = false;
116 | // 关联的 ScrollView,实现垂直方向的平滑滚动
117 | private View mAttachScrollView;
118 | // 关联的 ViewPager,实现联动
119 | private ViewPager mAttachViewPager;
120 | // 手势控制
121 | private GestureDetector mGestureDetector;
122 | // DragView的Top属性值
123 | private int mDragViewTop = 0;
124 |
125 |
126 | public DragSlopLayout(Context context) {
127 | this(context, null);
128 | }
129 |
130 | public DragSlopLayout(Context context, AttributeSet attrs) {
131 | this(context, attrs, -1);
132 | }
133 |
134 | public DragSlopLayout(Context context, AttributeSet attrs, int defStyleAttr) {
135 | super(context, attrs, defStyleAttr);
136 | _init(context, attrs);
137 | }
138 |
139 | private void _init(Context context, AttributeSet attrs) {
140 | mDragHelper = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, callback);
141 | mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_BOTTOM);
142 | mGestureDetector = new GestureDetector(context, mGestureListener);
143 | mFallBoundScroller = ScrollerCompat.create(context, new BounceInterpolator());
144 | mDecelerateScroller = ScrollerCompat.create(context, new DecelerateInterpolator());
145 | mMinTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
146 |
147 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DragSlopLayout, 0, 0);
148 | mFixHeight = a.getDimensionPixelOffset(R.styleable.DragSlopLayout_fix_height, mFixHeight);
149 | mMaxHeight = a.getDimensionPixelOffset(R.styleable.DragSlopLayout_max_height, 0);
150 | mCollapseParallax = a.getFloat(R.styleable.DragSlopLayout_collapse_parallax, 1.0f);
151 | mMode = a.getInt(R.styleable.DragSlopLayout_mode, MODE_DRAG);
152 | a.recycle();
153 | if (mMode == MODE_DRAG) {
154 | mDragStatus = STATUS_COLLAPSED;
155 | } else if (mMode == MODE_ANIMATE) {
156 | mAnimPresenter = new AnimatorPresenter();
157 | } else if (mMode == MODE_DRAG_OUTSIDE) {
158 | mDragStatus = STATUS_COLLAPSED;
159 | mFixHeight = 0;
160 | }
161 | }
162 |
163 | @Override
164 | protected void onFinishInflate() {
165 | super.onFinishInflate();
166 | int childCount = getChildCount();
167 | if (childCount < 2) {
168 | // DragLayout 必须包含两个子视图,第一个为主视图,另一个为可拖拽的视图
169 | throw new IllegalArgumentException("DragLayout must contains two sub-views.");
170 | }
171 |
172 | mBlurView = new View(getContext());
173 | mBlurView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
174 | ViewGroup.LayoutParams.MATCH_PARENT));
175 | addView(mBlurView, 1);
176 | mBlurView.setVisibility(GONE);
177 |
178 | mMainView = getChildAt(0);
179 | mDragView = getChildAt(2);
180 | }
181 |
182 | @Override
183 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
184 | super.onSizeChanged(w, h, oldw, oldh);
185 | mHeight = h;
186 | }
187 |
188 | @Override
189 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
190 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
191 | if (mMode == MODE_DRAG) {
192 | if (mMaxHeight == 0) {
193 | // 未设置最大高度则为布局高度的 2/3
194 | mMaxHeight = getMeasuredHeight() * 2 / 3;
195 | } else if (mMaxHeight > getMeasuredHeight()) {
196 | // MODE_DRAG 模式最大高度不超过布局高度
197 | mMaxHeight = getMeasuredHeight();
198 | }
199 | View childView = getChildAt(2);
200 | MarginLayoutParams lp = (MarginLayoutParams) childView.getLayoutParams();
201 | int childWidth = childView.getMeasuredWidth();
202 | int childHeight = childView.getMeasuredHeight();
203 | // 限定视图的最大高度
204 | if (childHeight > mMaxHeight) {
205 | childView.measure(MeasureSpec.makeMeasureSpec(childWidth - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY),
206 | MeasureSpec.makeMeasureSpec(mMaxHeight - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY));
207 | }
208 | } else if (mMode == MODE_DRAG_OUTSIDE) {
209 | View childView = getChildAt(2);
210 | MarginLayoutParams lp = (MarginLayoutParams) childView.getLayoutParams();
211 | int childWidth = childView.getMeasuredWidth();
212 | int childHeight = childView.getMeasuredHeight();
213 | // 不限定视图的最大高度,设置MeasureSpec.UNSPECIFIED子视图才能超过父视图高度
214 | childView.measure(MeasureSpec.makeMeasureSpec(childWidth - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY),
215 | MeasureSpec.makeMeasureSpec(childHeight - lp.topMargin - lp.bottomMargin, MeasureSpec.UNSPECIFIED));
216 | }
217 | }
218 |
219 | @Override
220 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
221 | super.onLayout(changed, l, t, r, b);
222 | MarginLayoutParams lp;
223 | View childView = getChildAt(2);
224 | lp = (MarginLayoutParams) childView.getLayoutParams();
225 | int childWidth = childView.getMeasuredWidth();
226 | int childHeight = childView.getMeasuredHeight();
227 | if (mMode == MODE_ANIMATE) {
228 | // 非拖拽模式固定高度为子视图高度
229 | mFixHeight = childHeight;
230 | } else if (mFixHeight > childHeight) {
231 | // 固定高度超过子视图高度则设置为子视图高度
232 | mFixHeight = childHeight;
233 | }
234 | mCriticalTop = b - (childHeight - mFixHeight) / 2 - mFixHeight;
235 | mExpandedTop = b - childHeight;
236 | mCollapsedTop = b - mFixHeight;
237 | // 如果本身 mDragViewTop 已经有值,则直接使用,不然会出现突然闪一下的情况
238 | if (mDragViewTop == 0 || mMode != MODE_DRAG_OUTSIDE) {
239 | if (mDragStatus == STATUS_EXIT) {
240 | // 对于 ViewPager 换页后会回调 onLayout(),需要进行处理
241 | if (mMode == MODE_DRAG || mMode == MODE_DRAG_OUTSIDE) {
242 | mDragViewTop = b;
243 | } else {
244 | mDragViewTop = b - mFixHeight;
245 | childView.setTranslationY(childHeight);
246 | }
247 | } else if (mDragStatus == STATUS_COLLAPSED) {
248 | mDragViewTop = b - mFixHeight;
249 | } else if (mDragStatus == STATUS_EXPANDED) {
250 | mDragViewTop = b - childHeight;
251 | } else {
252 | mDragViewTop = b - mFixHeight;
253 | }
254 | }
255 | childView.layout(lp.leftMargin, mDragViewTop, lp.leftMargin + childWidth, mDragViewTop + childHeight);
256 | }
257 |
258 | @Override
259 | protected void onDetachedFromWindow() {
260 | super.onDetachedFromWindow();
261 | _stopAllScroller();
262 | if (mAnimPresenter != null) {
263 | mAnimPresenter.stopAllAnimator();
264 | }
265 | if (mBitmapToBlur != null) {
266 | mBitmapToBlur.recycle();
267 | mBitmapToBlur = null;
268 | }
269 | }
270 |
271 | /***********************************
272 | * ViewDragHelper
273 | ********************************************/
274 |
275 | @Override
276 | public boolean dispatchTouchEvent(MotionEvent ev) {
277 | switch (MotionEventCompat.getActionMasked(ev)) {
278 | case MotionEvent.ACTION_UP:
279 | case MotionEvent.ACTION_CANCEL:
280 | mIsDrag = false;
281 | break;
282 | }
283 | return super.dispatchTouchEvent(ev);
284 | }
285 |
286 | @Override
287 | public boolean onInterceptTouchEvent(MotionEvent ev) {
288 | // 调用父类的方法,避免可能出现的 IllegalArgumentException: pointerIndex out of range
289 | super.onInterceptTouchEvent(ev);
290 | boolean isIntercept = mDragHelper.shouldInterceptTouchEvent(ev);
291 | if (_isNeedIntercept(ev)) {
292 | isIntercept = true;
293 | } else if (mDragHelper.isViewUnder(mDragView, (int) ev.getX(), (int) ev.getY()) && mMode != MODE_ANIMATE) {
294 | // 处于拖拽模式且点击到拖拽视图则停止滚动
295 | _stopAllScroller();
296 | }
297 | if (mMode == MODE_DRAG_OUTSIDE && !mIsDrag) {
298 | mGestureDetector.onTouchEvent(ev);
299 | }
300 | return isIntercept;
301 | }
302 |
303 | @Override
304 | public boolean onTouchEvent(MotionEvent event) {
305 | if (event.getActionMasked() == MotionEvent.ACTION_DOWN && (mMode == MODE_DRAG_OUTSIDE ||
306 | mDragHelper.isViewUnder(mDragView, (int) event.getX(), (int) event.getY()))) {
307 | // 处理一些点击事件没被消费的情况
308 | _stopAllScroller();
309 | mDragHelper.captureChildView(mDragView, 0);
310 | mIsDrag = true;
311 | } else {
312 | mDragHelper.processTouchEvent(event);
313 | }
314 | return mIsDrag;
315 | }
316 |
317 | /**
318 | * 手势监听
319 | */
320 | private GestureDetector.OnGestureListener mGestureListener = new GestureDetector.SimpleOnGestureListener() {
321 | // 是否是按下的标识,默认为其他动作,true为按下标识,false为其他动作
322 | private boolean isDownTouch;
323 |
324 | @Override
325 | public boolean onDown(MotionEvent e) {
326 | isDownTouch = true;
327 | return super.onDown(e);
328 | }
329 |
330 | @Override
331 | public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
332 | if (isDownTouch) {
333 | // 如果为上下滑动则控制拖拽
334 | if (Math.abs(distanceY) > Math.abs(distanceX)) {
335 | _stopAllScroller();
336 | mDragHelper.captureChildView(mDragView, 0);
337 | mIsDrag = true;
338 | }
339 | isDownTouch = false;
340 | }
341 | return super.onScroll(e1, e2, distanceX, distanceY);
342 | }
343 | };
344 |
345 |
346 | private ViewDragHelper.Callback callback = new ViewDragHelper.Callback() {
347 | private static final float SCROLL_DURATION = 0.3f;
348 |
349 | @Override
350 | public boolean tryCaptureView(View child, int pointerId) {
351 | mIsDrag = child == mDragView;
352 | return mIsDrag;
353 | }
354 |
355 | @Override
356 | public void onViewReleased(View releasedChild, float xvel, float yvel) {
357 | super.onViewReleased(releasedChild, xvel, yvel);
358 | float velocity = FLING_VELOCITY;
359 | if (mMode != MODE_DRAG_OUTSIDE) {
360 | velocity = FLING_VELOCITY / 2;
361 | }
362 | if (Math.abs(yvel) < velocity) {
363 | // 在 MODE_DRAG_OUTSIDE 模式下才做自动滚动处理,其它模式做收缩滚动,快速滚动在任何模式都做
364 | if (mMode == MODE_DRAG_OUTSIDE) {
365 | int finalTop = (int) (yvel * SCROLL_DURATION + mDragView.getTop());
366 | finalTop = Math.max(mExpandedTop, finalTop);
367 | finalTop = Math.min(mCollapsedTop, finalTop);
368 | mDecelerateScroller.startScroll(0, mDragView.getTop(), 0, finalTop - mDragView.getTop(), 500);
369 | } else if (mDragView.getTop() > mCriticalTop) {
370 | if (mDragStatus == STATUS_EXPANDED) {
371 | mDragHelper.smoothSlideViewTo(mDragView, 0, mCollapsedTop);
372 | } else {
373 | mFallBoundScroller.startScroll(0, mDragView.getTop(), 0, mCollapsedTop - mDragView.getTop(),
374 | FALL_BOUND_DURATION);
375 | }
376 | } else {
377 | mDragHelper.smoothSlideViewTo(mDragView, 0, mExpandedTop);
378 | }
379 | ViewCompat.postInvalidateOnAnimation(DragSlopLayout.this);
380 | } else if (yvel > 0) {
381 | if (!_flingScrollView(yvel)) {
382 | mDragHelper.settleCapturedViewAt(0, mCollapsedTop);
383 | ViewCompat.postInvalidateOnAnimation(DragSlopLayout.this);
384 | }
385 | } else {
386 | if (!_flingScrollView(yvel)) {
387 | mDragHelper.settleCapturedViewAt(0, mExpandedTop);
388 | ViewCompat.postInvalidateOnAnimation(DragSlopLayout.this);
389 | }
390 | }
391 | }
392 |
393 | @Override
394 | public void onViewDragStateChanged(int state) {
395 | super.onViewDragStateChanged(state);
396 | if (state == ViewDragHelper.STATE_IDLE) {
397 | _switchStatus();
398 | }
399 | }
400 |
401 | @Override
402 | public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
403 | super.onViewPositionChanged(changedView, left, top, dx, dy);
404 | final float percent = (mCollapsedTop - top) * 1.0f / (mCollapsedTop - mExpandedTop);
405 | _dragPositionChanged(mHeight - top, percent);
406 | }
407 |
408 | @Override
409 | public void onViewCaptured(View capturedChild, int activePointerId) {
410 | super.onViewCaptured(capturedChild, activePointerId);
411 | }
412 |
413 | @Override
414 | public int clampViewPositionVertical(View child, int top, int dy) {
415 | if (mAttachScrollView != null) {
416 | if (mAttachScrollView.getScrollY() > 0 || (mDragView.getTop() == mExpandedTop && dy < 0)) {
417 | mAttachScrollView.scrollBy(0, -dy);
418 | return mExpandedTop;
419 | }
420 | }
421 | int newTop = Math.max(mExpandedTop, top);
422 | newTop = Math.min(mCollapsedTop, newTop);
423 | return newTop;
424 | }
425 |
426 | @Override
427 | public int clampViewPositionHorizontal(View child, int left, int dx) {
428 | return 0;
429 | }
430 |
431 | @Override
432 | public int getViewVerticalDragRange(View child) {
433 | return child == mDragView ? child.getHeight() : 0;
434 | }
435 |
436 | @Override
437 | public void onEdgeDragStarted(int edgeFlags, int pointerId) {
438 | mDragHelper.captureChildView(mDragView, pointerId);
439 | }
440 | };
441 |
442 | @Override
443 | public void computeScroll() {
444 | if (mDragHelper.continueSettling(true) ||
445 | _continueSettling(mFallBoundScroller) || _continueSettling(mDecelerateScroller)) {
446 | mDragStatus = STATUS_SCROLL;
447 | final float percent = (mCollapsedTop - mDragView.getTop()) * 1.0f / (mCollapsedTop - mExpandedTop);
448 | _dragPositionChanged(mHeight - mDragView.getTop(), percent);
449 | ViewCompat.postInvalidateOnAnimation(this);
450 | }
451 | super.computeScroll();
452 | }
453 |
454 | /**
455 | * 处理自定义滚动动画
456 | */
457 | private boolean _continueSettling(ScrollerCompat scroller) {
458 | boolean keepGoing = scroller.computeScrollOffset();
459 | if (!keepGoing) {
460 | return false;
461 | }
462 | final int x = scroller.getCurrX();
463 | final int y = scroller.getCurrY();
464 | final int dx = x - mDragView.getLeft();
465 | final int dy = y - mDragView.getTop();
466 | if (dx != 0) {
467 | ViewCompat.offsetLeftAndRight(mDragView, dx);
468 | }
469 | if (dy != 0) {
470 | ViewCompat.offsetTopAndBottom(mDragView, dy);
471 | }
472 | if (keepGoing && x == scroller.getFinalX() && y == scroller.getFinalY()) {
473 | // Close enough. The interpolator/scroller might think we're still moving
474 | // but the user sure doesn't.
475 | scroller.abortAnimation();
476 | keepGoing = false;
477 | ViewCompat.postInvalidateOnAnimation(this);
478 | _switchStatus();
479 | }
480 | return keepGoing;
481 | }
482 |
483 | /**
484 | * 停止所有滚动
485 | */
486 | private void _stopAllScroller() {
487 | if (!mFallBoundScroller.isFinished()) {
488 | mFallBoundScroller.abortAnimation();
489 | }
490 | if (!mDecelerateScroller.isFinished()) {
491 | mDecelerateScroller.abortAnimation();
492 | }
493 | }
494 |
495 | /**
496 | * 滚出屏幕
497 | *
498 | * @param duration 时间
499 | */
500 | public void scrollOutScreen(int duration) {
501 | mIsDoOutAnim = true;
502 | mDecelerateScroller.startScroll(0, mDragView.getTop(), 0, mHeight - mDragView.getTop(), duration);
503 | ViewCompat.postInvalidateOnAnimation(DragSlopLayout.this);
504 | }
505 |
506 | /**
507 | * 滚进屏幕
508 | *
509 | * @param duration 时间
510 | */
511 | public void scrollInScreen(int duration) {
512 | mIsDoOutAnim = false;
513 | mDecelerateScroller.startScroll(0, mDragView.getTop(), 0, mCollapsedTop - mDragView.getTop(), duration);
514 | ViewCompat.postInvalidateOnAnimation(DragSlopLayout.this);
515 | }
516 |
517 | /***********************************
518 | * Inside
519 | ********************************************/
520 |
521 | @Retention(RetentionPolicy.SOURCE)
522 | @IntDef({STATUS_EXPANDED, STATUS_COLLAPSED, STATUS_EXIT, STATUS_SCROLL})
523 | @interface DragStatus {
524 | }
525 |
526 | /**
527 | * 切换状态
528 | */
529 | private void _switchStatus() {
530 | if (mDragView.getTop() == mExpandedTop) {
531 | mDragStatus = STATUS_EXPANDED;
532 | } else if (mDragView.getTop() == mCollapsedTop) {
533 | mDragStatus = STATUS_COLLAPSED;
534 | } else if (mDragView.getTop() == mHeight) {
535 | mDragStatus = STATUS_EXIT;
536 | } else {
537 | mDragStatus = STATUS_SCROLL;
538 | }
539 | }
540 |
541 | /**
542 | * 隐藏 DragView
543 | *
544 | * @param percent ViewPager 滑动百分比
545 | */
546 | private void _hideDragView(float percent, int curTop) {
547 | if (!mHasShowRunnable && !mIsDoOutAnim) {
548 | float hidePercent = percent * 3;
549 | if (hidePercent > 1.0f) {
550 | hidePercent = 1.0f;
551 | mDragStatus = STATUS_EXIT;
552 | } else {
553 | mDragStatus = STATUS_SCROLL;
554 | }
555 |
556 | if (mMode == MODE_ANIMATE) {
557 | mAnimPresenter.handleAnimateFrame(mDragView, hidePercent);
558 | } else {
559 | _stopAllScroller();
560 | final int y = (int) ((mCollapsedTop + mFixHeight - curTop) * hidePercent + curTop);
561 | final int dy = y - mDragView.getTop();
562 | if (dy != 0) {
563 | ViewCompat.offsetTopAndBottom(mDragView, dy);
564 | final float dragPercent = (mCollapsedTop - mDragView.getTop()) * 1.0f / (mCollapsedTop - mExpandedTop);
565 | _dragPositionChanged(mHeight - mDragView.getTop(), dragPercent);
566 | }
567 | }
568 | }
569 | }
570 |
571 | /**
572 | * 显示 DragView
573 | *
574 | * @param delay 延迟时间
575 | */
576 | private void _showDragView(int delay) {
577 | mHasShowRunnable = true;
578 | postDelayed(mShowRunnable, delay);
579 | }
580 |
581 | /**
582 | * 动画显示 Runnable
583 | */
584 | private Runnable mShowRunnable = new Runnable() {
585 | @Override
586 | public void run() {
587 | mHasShowRunnable = false;
588 | if (mMode == MODE_ANIMATE) {
589 | startInAnim();
590 | mDragStatus = STATUS_SCROLL;
591 | } else {
592 | mDecelerateScroller.startScroll(0, mDragView.getTop(), 0, mCollapsedTop - mDragView.getTop(), 500);
593 | ViewCompat.postInvalidateOnAnimation(DragSlopLayout.this);
594 | }
595 | }
596 | };
597 |
598 | /**
599 | * 拖拽位移监听
600 | *
601 | * @param visibleHeight 当前可见高度
602 | * @param percent 百分比
603 | */
604 | private void _dragPositionChanged(int visibleHeight, float percent) {
605 | if (mDragViewTop == 0) {
606 | mLastDragViewTop = mHeight - visibleHeight;
607 | }
608 | mDragViewTop = mHeight - visibleHeight;
609 | // 拖拽距离超过最小滑动距离则进行判断
610 | if (Math.abs(mDragViewTop - mLastDragViewTop) > mMinTouchSlop) {
611 | mIsUp = (mDragViewTop < mLastDragViewTop);
612 | mLastDragViewTop = mDragViewTop;
613 | }
614 | if (mEnableBlur && mBlurDrawable != null) {
615 | if (visibleHeight < mFixHeight) {
616 | return;
617 | }
618 | if (mIsBlurFull) {
619 | mBlurDrawable.setLevel(10000);
620 | } else {
621 | final int blurLevel = (int) ((visibleHeight * 1.0f / mMainView.getHeight()) * 10000);
622 | mBlurDrawable.setLevel(blurLevel);
623 | }
624 | mBlurDrawable.setAlpha((int) (percent * 255));
625 | }
626 | if (visibleHeight >= 0) {
627 | ViewCompat.setTranslationY(mMainView, -visibleHeight * (1 - mCollapseParallax));
628 | }
629 | if (mDragPositionListener != null) {
630 | mDragPositionListener.onDragPosition(visibleHeight, percent, mIsUp);
631 | }
632 | }
633 |
634 | /*********************************** ScrollView ********************************************/
635 |
636 | /**
637 | * 设置关联的 ScrollView 如果有的话,目前只支持 ScrollView 和 NestedScrollView 及其自视图
638 | *
639 | * @param attachScrollView ScrollView or NestedScrollView
640 | */
641 | public void setAttachScrollView(View attachScrollView) {
642 | if (!_isScrollView(attachScrollView)) {
643 | throw new IllegalArgumentException("The view must be ScrollView or NestedScrollView.");
644 | }
645 | mAttachScrollView = attachScrollView;
646 | }
647 |
648 | /**
649 | * 如果点击在关联的 ScrollView 区域则由父类 DragSlopLayout 中断事件接收,并全权控制处理 ScrollView
650 | *
651 | * @param ev 点击事件
652 | * @return
653 | */
654 | private boolean _isNeedIntercept(MotionEvent ev) {
655 | if (mAttachScrollView == null) {
656 | return false;
657 | }
658 | int y = (int) ev.getY() - mDragView.getTop();
659 | if (mDragHelper.isViewUnder(mAttachScrollView, (int) ev.getX(), y) && mMode != MODE_ANIMATE) {
660 | return true;
661 | }
662 | if (mEnableBlur && mDragStatus == STATUS_EXPANDED) {
663 | return true;
664 | }
665 | return false;
666 | }
667 |
668 | /**
669 | * 滑动 ScrollView
670 | *
671 | * @param yvel 滑动速度
672 | * @return
673 | */
674 | private boolean _flingScrollView(float yvel) {
675 | if (mAttachScrollView == null || mAttachScrollView.getScrollY() == 0) {
676 | return false;
677 | }
678 | if (mAttachScrollView instanceof ScrollView) {
679 | ((ScrollView) mAttachScrollView).fling((int) -yvel);
680 | } else if (mAttachScrollView instanceof NestedScrollView) {
681 | ((NestedScrollView) mAttachScrollView).fling((int) -yvel);
682 | }
683 | return true;
684 | }
685 |
686 | /**
687 | * 判断视图是否为 ScrollView or NestedScrollView 或它的子类
688 | *
689 | * @param view View
690 | * @return
691 | */
692 | private boolean _isScrollView(View view) {
693 | boolean isScrollView = false;
694 | if (view instanceof ScrollView || view instanceof NestedScrollView) {
695 | isScrollView = true;
696 | } else {
697 | ViewParent parent = view.getParent();
698 | while (parent != null) {
699 | if (parent instanceof ScrollView || parent instanceof NestedScrollView) {
700 | isScrollView = true;
701 | break;
702 | }
703 | }
704 | }
705 | return isScrollView;
706 | }
707 |
708 | /*********************************** ViewPager ********************************************/
709 |
710 |
711 | /**
712 | * 和 ViewPager 进行联动
713 | *
714 | * @param attachViewPager 关联 ViewPager
715 | */
716 | public void attachViewPager(ViewPager attachViewPager) {
717 | if (!_isViewPager(attachViewPager)) {
718 | throw new IllegalArgumentException("The first child view must be ViewPager.");
719 | }
720 | mAttachViewPager = attachViewPager;
721 | if (mViewPagerListener != null) {
722 | mAttachViewPager.removeOnPageChangeListener(mViewPagerListener);
723 | }
724 | mViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
725 |
726 | boolean isRightSlide = true;
727 | float mLastOffset = 0;
728 | int status = ViewPager.SCROLL_STATE_IDLE;
729 | int curDragViewTop;
730 |
731 | @Override
732 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
733 | if (status != ViewPager.SCROLL_STATE_IDLE && !mIsCustomAnimator) {
734 | // 判断拖拽过界的方向
735 | if (Math.abs(positionOffset - mLastOffset) > 0.8f &&
736 | status == ViewPager.SCROLL_STATE_DRAGGING) {
737 | if (positionOffset > 0.5f) {
738 | isRightSlide = false;
739 | } else {
740 | isRightSlide = true;
741 | }
742 | }
743 | float percent;
744 | if (isRightSlide) {
745 | percent = positionOffset;
746 | if (positionOffset == 0 && status == ViewPager.SCROLL_STATE_SETTLING && mLastOffset > 0.5f) {
747 | percent = 1.0f;
748 | }
749 | } else {
750 | percent = 1 - positionOffset;
751 | if (positionOffset == 0 && status == ViewPager.SCROLL_STATE_SETTLING && mLastOffset > 0.5f) {
752 | percent = 0;
753 | }
754 | }
755 | _hideDragView(percent, curDragViewTop);
756 | mLastOffset = positionOffset;
757 | }
758 | }
759 |
760 | @Override
761 | public void onPageScrollStateChanged(int state) {
762 | if (state == ViewPager.SCROLL_STATE_IDLE && !mIsCustomAnimator) {
763 | isRightSlide = true;
764 | mLastOffset = 0;
765 | // 如果手动调用退出动画则不做自动启动动画
766 | if (mDragStatus == STATUS_EXIT && !mIsDoOutAnim && mMode != MODE_DRAG_OUTSIDE) {
767 | _showDragView(mAutoAnimateDelay);
768 | }
769 | } else {
770 | if (mDragStatus == STATUS_EXIT) {
771 | getHandler().removeCallbacks(mShowRunnable);
772 | }
773 | if (state == ViewPager.SCROLL_STATE_DRAGGING) {
774 | curDragViewTop = mDragView.getTop();
775 | }
776 | }
777 | status = state;
778 | }
779 | };
780 | mAttachViewPager.addOnPageChangeListener(mViewPagerListener);
781 | }
782 |
783 | /**
784 | * 取消 ViewPager 关联
785 | */
786 | public void detachViewPager() {
787 | if (mViewPagerListener != null && mAttachViewPager != null) {
788 | mAttachViewPager.removeOnPageChangeListener(mViewPagerListener);
789 | }
790 | mViewPagerListener = null;
791 | mAttachViewPager = null;
792 | }
793 |
794 | /**
795 | * 和 ViewPager 进行联动,注意第1个子视图必须为 ViewPager 或它的子类,
796 | * 替换为 {@link #attachViewPager}
797 | * @param isInteract 是否联动
798 | */
799 | @Deprecated
800 | public void interactWithViewPager(boolean isInteract) {
801 | if (!_isViewPager(mMainView)) {
802 | throw new IllegalArgumentException("The first child view must be ViewPager.");
803 | }
804 | if (mViewPagerListener != null) {
805 | ((ViewPager) mMainView).removeOnPageChangeListener(mViewPagerListener);
806 | }
807 | if (!isInteract) {
808 | mViewPagerListener = null;
809 | return;
810 | }
811 | mViewPagerListener = new ViewPager.SimpleOnPageChangeListener() {
812 |
813 | boolean isRightSlide = true;
814 | float mLastOffset = 0;
815 | int status = ViewPager.SCROLL_STATE_IDLE;
816 | int curDragViewTop;
817 |
818 | @Override
819 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
820 | if (status != ViewPager.SCROLL_STATE_IDLE && !mIsCustomAnimator) {
821 | // 判断拖拽过界的方向
822 | if (Math.abs(positionOffset - mLastOffset) > 0.8f &&
823 | status == ViewPager.SCROLL_STATE_DRAGGING) {
824 | if (positionOffset > 0.5f) {
825 | isRightSlide = false;
826 | } else {
827 | isRightSlide = true;
828 | }
829 | }
830 | float percent;
831 | if (isRightSlide) {
832 | percent = positionOffset;
833 | if (positionOffset == 0 && status == ViewPager.SCROLL_STATE_SETTLING && mLastOffset > 0.5f) {
834 | percent = 1.0f;
835 | }
836 | } else {
837 | percent = 1 - positionOffset;
838 | if (positionOffset == 0 && status == ViewPager.SCROLL_STATE_SETTLING && mLastOffset > 0.5f) {
839 | percent = 0;
840 | }
841 | }
842 | _hideDragView(percent, curDragViewTop);
843 | mLastOffset = positionOffset;
844 | }
845 | }
846 |
847 | @Override
848 | public void onPageScrollStateChanged(int state) {
849 | if (state == ViewPager.SCROLL_STATE_IDLE && !mIsCustomAnimator) {
850 | isRightSlide = true;
851 | mLastOffset = 0;
852 | // 如果手动调用退出动画则不做自动启动动画
853 | if (mDragStatus == STATUS_EXIT && !mIsDoOutAnim && mMode != MODE_DRAG_OUTSIDE) {
854 | _showDragView(mAutoAnimateDelay);
855 | }
856 | } else {
857 | if (mDragStatus == STATUS_EXIT) {
858 | getHandler().removeCallbacks(mShowRunnable);
859 | }
860 | if (state == ViewPager.SCROLL_STATE_DRAGGING) {
861 | curDragViewTop = mDragView.getTop();
862 | }
863 | }
864 | status = state;
865 | }
866 | };
867 | ((ViewPager) mMainView).addOnPageChangeListener(mViewPagerListener);
868 | }
869 |
870 | public int getAutoAnimateDelay() {
871 | return mAutoAnimateDelay;
872 | }
873 |
874 | public void setAutoAnimateDelay(int autoAnimateDelay) {
875 | mAutoAnimateDelay = autoAnimateDelay;
876 | }
877 |
878 | /**
879 | * 判断视图是否为 ViewPager 或它的子类
880 | *
881 | * @param view View
882 | * @return
883 | */
884 | private boolean _isViewPager(View view) {
885 | boolean isViewPager = false;
886 | if (view instanceof ViewPager) {
887 | isViewPager = true;
888 | } else {
889 | ViewParent parent = view.getParent();
890 | while (parent != null) {
891 | if (parent instanceof ViewPager) {
892 | isViewPager = true;
893 | break;
894 | }
895 | }
896 | }
897 | return isViewPager;
898 | }
899 |
900 | /************************************
901 | * Animation
902 | ********************************************/
903 |
904 | public static final int SLIDE_BOTTOM = 101;
905 | public static final int SLIDE_LEFT = 102;
906 | public static final int SLIDE_RIGHT = 103;
907 | public static final int FADE = 104;
908 | public static final int FLIP_X = 105;
909 | public static final int FLIP_Y = 106;
910 | public static final int ZOOM = 107;
911 | public static final int ZOOM_LEFT = 108;
912 | public static final int ZOOM_RIGHT = 109;
913 |
914 | @Retention(RetentionPolicy.SOURCE)
915 | @IntDef({SLIDE_BOTTOM, SLIDE_LEFT, SLIDE_RIGHT, FADE, FLIP_X, FLIP_Y, ZOOM, ZOOM_LEFT, ZOOM_RIGHT})
916 | public @interface AnimatorMode {
917 | }
918 |
919 | public int getAnimatorMode() {
920 | return mAnimPresenter.getAnimatorMode();
921 | }
922 |
923 | public void setAnimatorMode(@AnimatorMode int animatorMode) {
924 | mIsCustomAnimator = false;
925 | if (mAnimPresenter == null) {
926 | mAnimPresenter = new AnimatorPresenter();
927 | }
928 | mAnimPresenter.setAnimatorMode(animatorMode);
929 | }
930 |
931 | public int getStartDelay() {
932 | return mAnimPresenter.getStartDelay();
933 | }
934 |
935 | public void setStartDelay(int startDelay) {
936 | mAnimPresenter.setStartDelay(startDelay);
937 | }
938 |
939 | public int getDuration() {
940 | return mAnimPresenter.getDuration();
941 | }
942 |
943 | public void setDuration(int duration) {
944 | mAnimPresenter.setDuration(duration);
945 | }
946 |
947 | public Interpolator getInterpolator() {
948 | return mAnimPresenter.getInterpolator();
949 | }
950 |
951 | public void setInterpolator(Interpolator interpolator) {
952 | mAnimPresenter.setInterpolator(interpolator);
953 | }
954 |
955 | /**
956 | * 启动进入动画
957 | */
958 | public void startInAnim() {
959 | mIsDoOutAnim = false;
960 | mAnimPresenter.startInAnim(mDragView);
961 | }
962 |
963 | /**
964 | * 启动退出动画
965 | * 注意:调用了退出动画则默认关闭自动启动动画效果
966 | */
967 | public void startOutAnim() {
968 | mIsDoOutAnim = true;
969 | mAnimPresenter.startOutAnim(mDragView);
970 | }
971 |
972 | /**
973 | * 设置自定义动画
974 | *
975 | * @param inAnimator 进入动画
976 | * @param outAnimator 退出动画
977 | */
978 | public void setCustomAnimator(CustomViewAnimator inAnimator, CustomViewAnimator outAnimator) {
979 | mIsCustomAnimator = true;
980 | mAnimPresenter.setCustomAnimator(inAnimator, outAnimator);
981 | }
982 |
983 | /*************************************
984 | * Blur
985 | ********************************************/
986 | private final static int DEFAULT_SAMPLE_FACTOR = 4;
987 | private final static int DEFAULT_BLUR_RADIUS = 5;
988 |
989 | // 使能模糊
990 | private boolean mEnableBlur = false;
991 | // 画布
992 | private Canvas mBlurringCanvas;
993 | // 接收画布绘制的位图
994 | private Bitmap mBitmapToBlur;
995 | private ClipDrawable mBlurDrawable;
996 | private RenderScript mRenderScript;
997 | private ScriptIntrinsicBlur mBlurScript;
998 | private Allocation mBlurInput, mBlurOutput;
999 | private int mBlurredViewWidth, mBlurredViewHeight;
1000 | // 采样因数,降低需要模糊处理图片的像素,提高处理速度
1001 | private int mSampleFactor = DEFAULT_SAMPLE_FACTOR;
1002 | // 模糊半径
1003 | private int mBlurRadius = DEFAULT_BLUR_RADIUS;
1004 | // 是否全图模糊,默认为局部模糊即只模糊 DragView 部分
1005 | private boolean mIsBlurFull = false;
1006 |
1007 | public int getSampleFactor() {
1008 | return mSampleFactor;
1009 | }
1010 |
1011 | public void setSampleFactor(int sampleFactor) {
1012 | mSampleFactor = sampleFactor;
1013 | }
1014 |
1015 | public int getBlurRadius() {
1016 | return mBlurRadius;
1017 | }
1018 |
1019 | public void setBlurRadius(int blurRadius) {
1020 | mBlurRadius = blurRadius;
1021 | if (mBlurScript != null) {
1022 | mBlurScript.setRadius(mBlurRadius);
1023 | }
1024 | }
1025 |
1026 | public void setBlurFull(boolean blurFull) {
1027 | mIsBlurFull = blurFull;
1028 | }
1029 |
1030 | /**
1031 | * 设置使能模糊效果
1032 | *
1033 | * @param enableBlur
1034 | */
1035 | public void setEnableBlur(boolean enableBlur) {
1036 | if (mEnableBlur == enableBlur) {
1037 | return;
1038 | }
1039 | mEnableBlur = enableBlur;
1040 | if (mEnableBlur) {
1041 | mBlurView.setVisibility(VISIBLE);
1042 | if (mRenderScript == null || mBlurScript == null) {
1043 | mRenderScript = RenderScript.create(getContext());
1044 | mBlurScript = ScriptIntrinsicBlur.create(mRenderScript, Element.U8_4(mRenderScript));
1045 | mBlurScript.setRadius(mBlurRadius);
1046 | }
1047 | mMainView.post(new Runnable() {
1048 | @Override
1049 | public void run() {
1050 | _handleBlurInThread();
1051 | }
1052 | });
1053 | } else {
1054 | mBlurView.setVisibility(GONE);
1055 | if (mBitmapToBlur != null) {
1056 | mBitmapToBlur.recycle();
1057 | mBitmapToBlur = null;
1058 | }
1059 | if (mBlurDrawable != null) {
1060 | mBlurDrawable = null;
1061 | }
1062 | }
1063 | }
1064 |
1065 | /**
1066 | * 刷新模糊视图
1067 | */
1068 | public void updateBlurView() {
1069 | if (mEnableBlur) {
1070 | mBlurDrawable = null;
1071 | _handleBlurInThread();
1072 | }
1073 | }
1074 |
1075 | /**
1076 | * 模糊视图
1077 | *
1078 | * @param view
1079 | */
1080 | private void _blurView(View view) {
1081 | final int width = view.getWidth();
1082 | final int height = view.getHeight();
1083 | if (width == 0 || height == 0) {
1084 | return;
1085 | }
1086 | if (mBlurringCanvas == null || mBitmapToBlur == null
1087 | || mBlurredViewWidth != width || mBlurredViewHeight != height) {
1088 |
1089 | mBlurredViewWidth = width;
1090 | mBlurredViewHeight = height;
1091 | int scaledWidth = width / mSampleFactor;
1092 | int scaledHeight = height / mSampleFactor;
1093 |
1094 | // The following manipulation is to avoid some RenderScript artifacts at the edge.
1095 | scaledWidth = scaledWidth - scaledWidth % 4 + 4;
1096 | scaledHeight = scaledHeight - scaledHeight % 4 + 4;
1097 |
1098 | mBitmapToBlur = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
1099 | if (mBitmapToBlur == null) {
1100 | throw new RuntimeException("Create bitmap failure!");
1101 | }
1102 | mBlurringCanvas = new Canvas(mBitmapToBlur);
1103 | mBlurringCanvas.scale(1.0f / mSampleFactor, 1.0f / mSampleFactor);
1104 | mBlurInput = Allocation.createFromBitmap(mRenderScript, mBitmapToBlur,
1105 | Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
1106 | mBlurOutput = Allocation.createTyped(mRenderScript, mBlurInput.getType());
1107 |
1108 | // 背景为 ColorDrawable 则设置对应颜色,否则设为透明
1109 | if (view.getBackground() != null && view.getBackground() instanceof ColorDrawable) {
1110 | mBitmapToBlur.eraseColor(((ColorDrawable) view.getBackground()).getColor());
1111 | } else {
1112 | mBitmapToBlur.eraseColor(Color.TRANSPARENT);
1113 | }
1114 | }
1115 | // 将目标视图的背景绘制到 mBitmapToBlur
1116 | view.draw(mBlurringCanvas);
1117 | // 模糊处理
1118 | mBlurInput.copyFrom(mBitmapToBlur);
1119 | mBlurScript.setInput(mBlurInput);
1120 | mBlurScript.forEach(mBlurOutput);
1121 | mBlurOutput.copyTo(mBitmapToBlur);
1122 | // 放大回原图大小
1123 | Bitmap blurredBitmap = BitmapUtils.zoom(mBitmapToBlur, width, height);
1124 | // 将模糊的 Bitmap 转化为 ClipDrawable
1125 | Drawable drawable = new BitmapDrawable(getResources(), blurredBitmap);
1126 | mBlurDrawable = new ClipDrawable(drawable, Gravity.BOTTOM, ClipDrawable.VERTICAL);
1127 | if (mDragStatus == STATUS_EXPANDED) {
1128 | if (mIsBlurFull) {
1129 | mBlurDrawable.setLevel(10000);
1130 | } else {
1131 | final int visibleHeight = mHeight - mDragView.getTop();
1132 | final int blurLevel = (int) ((visibleHeight * 1.0f / mMainView.getHeight()) * 10000);
1133 | mBlurDrawable.setLevel(blurLevel);
1134 | }
1135 | mBlurDrawable.setAlpha(255);
1136 | } else {
1137 | mBlurDrawable.setLevel(0);
1138 | mBlurDrawable.setAlpha(0);
1139 | }
1140 | }
1141 |
1142 | /**
1143 | * 在线程处理图片模糊
1144 | */
1145 | @SuppressWarnings("deprecation")
1146 | private void _handleBlurInThread() {
1147 | new Thread(new Runnable() {
1148 | @Override
1149 | public void run() {
1150 | _blurView(mMainView);
1151 | mBlurView.post(new Runnable() {
1152 | @Override
1153 | public void run() {
1154 | // 设置模糊背景
1155 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
1156 | mBlurView.setBackground(mBlurDrawable);
1157 | } else {
1158 | mBlurView.setBackgroundDrawable(mBlurDrawable);
1159 | }
1160 | }
1161 | });
1162 | }
1163 | }).start();
1164 | }
1165 |
1166 | /** ================================ 监听器 ================================ */
1167 |
1168 | // 监听器
1169 | private OnDragPositionListener mDragPositionListener;
1170 | // 是否向上拖拽
1171 | private boolean mIsUp = false;
1172 | // 上一次比较时的拖拽高度
1173 | private int mLastDragViewTop;
1174 | // 最小触摸滑动距离
1175 | private int mMinTouchSlop;
1176 |
1177 | /**
1178 | * 设置监听器
1179 | * @param dragPositionListener
1180 | */
1181 | public void setDragPositionListener(OnDragPositionListener dragPositionListener) {
1182 | mDragPositionListener = dragPositionListener;
1183 | }
1184 |
1185 | /**
1186 | * 拖拽监听器
1187 | */
1188 | public interface OnDragPositionListener {
1189 |
1190 | /**
1191 | * 拖拽监听
1192 | * @param visibleHeight 可见高度
1193 | * @param percent 可见百分比
1194 | * @param isUp 是否向上拖拽
1195 | */
1196 | void onDragPosition(int visibleHeight, float percent, boolean isUp);
1197 | }
1198 | }
1199 |
--------------------------------------------------------------------------------