├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── android_bg.jpg │ │ │ │ ├── google_logo.png │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── menu │ │ │ │ └── menu_main.xml │ │ │ └── layout │ │ │ │ ├── scene_in.xml │ │ │ │ ├── scene_out.xml │ │ │ │ ├── activity_drag_transition.xml │ │ │ │ ├── drag_layout.xml │ │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── hide │ │ │ └── transitionstest │ │ │ └── app │ │ │ ├── IndexActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── DragTransitionActivity.java │ │ │ └── widget │ │ │ └── DragLayout.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── hide │ │ └── transitionstest │ │ └── app │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── TransitionPlayer-lib ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ └── values │ │ │ │ └── strings.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── com │ │ │ └── hide │ │ │ └── transitionplayer │ │ │ └── lib │ │ │ ├── control │ │ │ ├── PlayControl.java │ │ │ └── ModifyAnimatorsPlayControl.java │ │ │ ├── interpolators │ │ │ ├── WrappedTimeInterpolator.java │ │ │ ├── LockEndTimeInterpolator.java │ │ │ ├── LockStartTimeInterpolator.java │ │ │ ├── ReverseTimeInterpolator.java │ │ │ └── MultiTimeInterpolator.java │ │ │ ├── transitions │ │ │ ├── ChangeTextColor.java │ │ │ ├── ChangeBackground.java │ │ │ ├── ChangeAlpha.java │ │ │ ├── ChangeScale.java │ │ │ ├── ChangeRotate.java │ │ │ ├── ChangeTransition.java │ │ │ └── AbsChangeValue.java │ │ │ ├── AnimatorUtils.java │ │ │ └── TransitionPlayer.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── hide │ │ └── transitionplayer │ │ └── lib │ │ └── ApplicationTest.java ├── proguard-rules.pro ├── build.gradle └── TransitionPlayer-lib.iml ├── settings.gradle ├── apk └── demo-debug.apk ├── screenshoot └── result.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':TransitionPlayer-lib' 2 | -------------------------------------------------------------------------------- /apk/demo-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notHide/TransitionsTest/HEAD/apk/demo-debug.apk -------------------------------------------------------------------------------- /screenshoot/result.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notHide/TransitionsTest/HEAD/screenshoot/result.gif -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notHide/TransitionsTest/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Library 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/android_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notHide/TransitionsTest/HEAD/app/src/main/res/mipmap-hdpi/android_bg.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/google_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notHide/TransitionsTest/HEAD/app/src/main/res/mipmap-hdpi/google_logo.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notHide/TransitionsTest/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notHide/TransitionsTest/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notHide/TransitionsTest/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/notHide/TransitionsTest/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | TransitionsTest 3 | 4 | Hello world! 5 | Settings 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 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.2.1-all.zip 7 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ViewDragHelper与Transition练习 2 | 3 | Android的框架层新增了ViewDragHelper这么一个类,官方的DrawerLayout就是通过它来实现的。 4 | ViewDragHelper是一个『拖拽控制器』,使用它可以用很少的代码实现很流畅的拖拽效果。Android在触摸这一块终于又进了一步。 5 | 6 | Trasition是4.4推出的,中文名字是:过渡动画,使用它可以做出各种界面变化后的过渡效果。 7 | Transition内部是对多个属性动画的封装,实现原理是通过记录View的初始状态和结束状态,然后通过属性动画进行播放 8 | 9 | 这个项目是自己对ViewDragHelper与Transition的一个小练习。 10 | 11 | # 截图: 12 | ![image](https://raw.githubusercontent.com/w9xhc/TransitionsTest/master/screenshoot/result.gif) 13 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hide/transitionstest/app/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionstest.app; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/androidTest/java/com/hide/transitionplayer/lib/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib; 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 | } -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/control/PlayControl.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.control; 2 | 3 | import android.animation.ValueAnimator; 4 | import android.transitions.everywhere.Transition; 5 | 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * Created by linfaxin on 2015/8/8. 10 | * Email: linlinfaxin@163.com 11 | */ 12 | public interface PlayControl { 13 | void onPreRunAnimator(Transition transition, ArrayList animators); 14 | } 15 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/interpolators/WrappedTimeInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.interpolators; 2 | 3 | import android.animation.TimeInterpolator; 4 | 5 | /** 6 | * Created by linfaxin on 2015/8/9. 7 | * Email: linlinfaxin@163.com 8 | */ 9 | public abstract class WrappedTimeInterpolator implements TimeInterpolator{ 10 | TimeInterpolator wrapped; 11 | public WrappedTimeInterpolator(TimeInterpolator wrapped) { 12 | this.wrapped = wrapped; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/interpolators/LockEndTimeInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.interpolators; 2 | 3 | import android.animation.TimeInterpolator; 4 | 5 | /** 6 | * Created by linfaxin on 2015/8/9. 7 | * Email: linlinfaxin@163.com 8 | */ 9 | public class LockEndTimeInterpolator extends WrappedTimeInterpolator{ 10 | public LockEndTimeInterpolator(TimeInterpolator wrapped) { 11 | super(wrapped); 12 | } 13 | @Override 14 | public float getInterpolation(float input) { 15 | return 1; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/interpolators/LockStartTimeInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.interpolators; 2 | 3 | import android.animation.TimeInterpolator; 4 | 5 | /** 6 | * Created by linfaxin on 2015/8/9. 7 | * Email: linlinfaxin@163.com 8 | */ 9 | public class LockStartTimeInterpolator extends WrappedTimeInterpolator{ 10 | public LockStartTimeInterpolator(TimeInterpolator wrapped) { 11 | super(wrapped); 12 | } 13 | @Override 14 | public float getInterpolation(float input) { 15 | return 0; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/interpolators/ReverseTimeInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.interpolators; 2 | 3 | import android.animation.TimeInterpolator; 4 | 5 | /** 6 | * Created by linfaxin on 2015/8/9. 7 | * Email: linlinfaxin@163.com 8 | */ 9 | public class ReverseTimeInterpolator extends WrappedTimeInterpolator{ 10 | public ReverseTimeInterpolator(TimeInterpolator wrapped) { 11 | super(wrapped); 12 | } 13 | @Override 14 | public float getInterpolation(float input) { 15 | return wrapped.getInterpolation(1-input); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/scene_in.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/scene_out.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 16 | 17 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/zhaoyiding/Documents/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/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 /Users/zhaoyiding/Documents/android-sdk-macosx/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 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /TransitionPlayer-lib/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:1.1.1' 7 | } 8 | } 9 | apply plugin: 'com.android.library' 10 | 11 | repositories { 12 | jcenter() 13 | } 14 | 15 | android { 16 | compileSdkVersion 23 17 | buildToolsVersion "23.0.1" 18 | 19 | defaultConfig { 20 | minSdkVersion 16 21 | targetSdkVersion 23 22 | versionCode 1 23 | versionName "1.0" 24 | } 25 | buildTypes { 26 | release { 27 | minifyEnabled false 28 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 29 | } 30 | } 31 | } 32 | 33 | dependencies { 34 | compile fileTree(dir: 'libs', include: ['*.jar']) 35 | compile 'com.android.support:appcompat-v7:23.0.1' 36 | compile 'com.github.andkulikov:transitions-everywhere:1.4.0' 37 | } 38 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:1.1.1' 7 | } 8 | } 9 | apply plugin: 'com.android.application' 10 | 11 | repositories { 12 | jcenter() 13 | } 14 | 15 | android { 16 | compileSdkVersion 23 17 | buildToolsVersion "23.0.1" 18 | 19 | defaultConfig { 20 | applicationId "com.hide.transitionstest.app" 21 | minSdkVersion 19 22 | targetSdkVersion 23 23 | versionCode 1 24 | versionName "1.0" 25 | } 26 | buildTypes { 27 | release { 28 | minifyEnabled false 29 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 30 | } 31 | } 32 | } 33 | 34 | dependencies { 35 | compile fileTree(dir: 'libs', include: ['*.jar']) 36 | compile 'com.android.support:appcompat-v7:23.0.1' 37 | compile project(':TransitionPlayer-lib') 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/transitions/ChangeTextColor.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.transitions; 2 | 3 | import android.animation.ArgbEvaluator; 4 | import android.view.View; 5 | import android.widget.TextView; 6 | 7 | /** 8 | * Created by linfaxin on 2015/8/9. 9 | * Email: linlinfaxin@163.com 10 | */ 11 | public class ChangeTextColor extends AbsChangeValue{ 12 | public ChangeTextColor() { 13 | super(new ArgbEvaluator(), "textColor", "hintTextColor"); 14 | } 15 | 16 | @Override 17 | protected Object getPropertyValue(View view, String propertyName) { 18 | if(view instanceof TextView){ 19 | if("textColor".equals(propertyName)){ 20 | return ((TextView) view).getCurrentTextColor(); 21 | } 22 | if("hintTextColor".equals(propertyName)){ 23 | return ((TextView) view).getCurrentHintTextColor(); 24 | } 25 | } 26 | return super.getPropertyValue(view, propertyName); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/transitions/ChangeBackground.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.transitions; 2 | 3 | import android.animation.ArgbEvaluator; 4 | import android.graphics.drawable.ColorDrawable; 5 | import android.graphics.drawable.Drawable; 6 | import android.transitions.everywhere.Transition; 7 | import android.transitions.everywhere.TransitionValues; 8 | import android.view.View; 9 | 10 | /** 11 | * Created by linfaxin on 2015/5/29. 12 | * Email: linlinfaxin@163.com 13 | */ 14 | public class ChangeBackground extends AbsChangeValue { 15 | private static final String FIELD_NAME = "backgroundColor"; 16 | 17 | public ChangeBackground() { 18 | super(new ArgbEvaluator(), FIELD_NAME); 19 | } 20 | 21 | @Override 22 | protected Object getPropertyValue(View view, String propertyName) { 23 | if(FIELD_NAME.equals(propertyName)){ 24 | Drawable drawable = view.getBackground(); 25 | if(drawable instanceof ColorDrawable){ 26 | return ((ColorDrawable) drawable).getColor(); 27 | } 28 | } 29 | return super.getPropertyValue(view, propertyName); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/control/ModifyAnimatorsPlayControl.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.control; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ValueAnimator; 5 | import android.transitions.everywhere.Transition; 6 | 7 | import com.hide.transitionplayer.lib.AnimatorUtils; 8 | 9 | import java.util.ArrayList; 10 | 11 | /** 12 | * Created by linfaxin on 2015/8/8. 13 | * Email: linlinfaxin@163.com 14 | */ 15 | public abstract class ModifyAnimatorsPlayControl implements PlayControl{ 16 | @Override 17 | public void onPreRunAnimator(Transition transition, ArrayList animators) { 18 | ArrayList newAnimators = new ArrayList<>(); 19 | for(int i=0, size=animators.size(); i 2 | 6 | 11 | 15 | 22 | 23 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/drag_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 16 | 19 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/transitions/ChangeAlpha.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.transitions; 2 | 3 | import android.animation.Animator; 4 | import android.animation.ObjectAnimator; 5 | import android.transitions.everywhere.Transition; 6 | import android.transitions.everywhere.TransitionValues; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | /** 11 | * Created by linfaxin on 2015/5/29. 12 | * Email: linlinfaxin@163.com 13 | */ 14 | public class ChangeAlpha extends Transition { 15 | private static final String PROPNAME_ALPHA = "android:alpha:alpha"; 16 | 17 | @Override 18 | public void captureStartValues(TransitionValues transitionValues) { 19 | transitionValues.values.put(PROPNAME_ALPHA, transitionValues.view.getAlpha()); 20 | } 21 | 22 | @Override 23 | public void captureEndValues(TransitionValues transitionValues) { 24 | transitionValues.values.put(PROPNAME_ALPHA, transitionValues.view.getAlpha()); 25 | } 26 | 27 | @Override 28 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, 29 | TransitionValues endValues) { 30 | if (startValues == null || endValues == null) { 31 | return null; 32 | } 33 | final View view = endValues.view; 34 | float startAlpha = (Float) startValues.values.get(PROPNAME_ALPHA); 35 | float endAlpha = (Float) endValues.values.get(PROPNAME_ALPHA); 36 | if (startAlpha != endAlpha) { 37 | view.setAlpha(startAlpha); 38 | return ObjectAnimator.ofFloat(view, "alpha", startAlpha, endAlpha); 39 | } 40 | return null; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/hide/transitionstest/app/IndexActivity.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionstest.app; 2 | 3 | import android.app.ListActivity; 4 | import android.content.Intent; 5 | import android.graphics.Rect; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.ListView; 10 | 11 | /** 12 | * * * * * * * * * * * * * * * * * * * * * * * 13 | * Created by zhaoyiding 14 | * Date: 15/10/11 15 | * * * * * * * * * * * * * * * * * * * * * * * 16 | **/ 17 | public class IndexActivity extends ListActivity { 18 | 19 | public static int sStatusBarHeight; 20 | private String[] indexs = new String[]{"Simple Transition", "DragTransition"}; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setListAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, indexs)); 26 | 27 | getListView().post(new Runnable() { 28 | @Override 29 | public void run() { 30 | 31 | Rect statusBarRect = new Rect(); 32 | getListView().getWindowVisibleDisplayFrame(statusBarRect); 33 | sStatusBarHeight = statusBarRect.top; 34 | } 35 | }); 36 | 37 | } 38 | 39 | @Override 40 | protected void onListItemClick(ListView l, View v, int position, long id) { 41 | switch (position) { 42 | case 0: 43 | startActivity(new Intent(this, MainActivity.class)); 44 | break; 45 | case 1: 46 | startActivity(new Intent(this, DragTransitionActivity.class)); 47 | break; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/interpolators/MultiTimeInterpolator.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.interpolators; 2 | 3 | import android.animation.TimeInterpolator; 4 | import android.util.Pair; 5 | 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * Created by linfaxin on 2015/8/9. 10 | * Email: linlinfaxin@163.com 11 | */ 12 | public class MultiTimeInterpolator implements TimeInterpolator{ 13 | ArrayList> pairs = new ArrayList<>(); 14 | private int totalWeight = 0; 15 | public MultiTimeInterpolator(TimeInterpolator... interpolators){ 16 | addInterpolators(interpolators); 17 | } 18 | 19 | public void addInterpolators(TimeInterpolator... interpolators){ 20 | for(TimeInterpolator interpolator : interpolators){ 21 | addInterpolator(interpolator, 1); 22 | } 23 | } 24 | public void addInterpolator(TimeInterpolator interpolator){ 25 | addInterpolator(interpolator, 1); 26 | } 27 | 28 | public void addInterpolator(TimeInterpolator interpolator, float weight){ 29 | if(interpolator==null || weight<0) return; 30 | pairs.add(new Pair<>(interpolator, weight)); 31 | totalWeight += weight; 32 | } 33 | 34 | @Override 35 | public float getInterpolation(float input) { 36 | float weightSum = 0; 37 | for(Pair pair : pairs){ 38 | float weight = pair.second; 39 | float weightStart = weightSum; 40 | float weightEnd = weightStart + weight; 41 | float inputWeight = input * totalWeight; 42 | if(inputWeight > weightStart && inputWeight <= weightEnd){ 43 | float convertInput = (inputWeight - weightStart) / weight; 44 | return pair.first.getInterpolation(convertInput); 45 | } 46 | weightSum = weightEnd; 47 | } 48 | return 0; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/hide/transitionstest/app/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionstest.app; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.FragmentActivity; 5 | import android.transitions.everywhere.Fade; 6 | import android.transitions.everywhere.TransitionManager; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | 11 | public class MainActivity extends FragmentActivity 12 | implements View.OnClickListener { 13 | 14 | private ViewGroup mRootView; 15 | private View mRedBox, mGreenBox, mBlueBox, mBlackBox; 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_main); 21 | 22 | mRootView = (ViewGroup) findViewById(android.R.id.content); 23 | mRootView.setOnClickListener(this); 24 | 25 | mRedBox = findViewById(R.id.red_box); 26 | mRedBox.setOnClickListener(this); 27 | mGreenBox = findViewById(R.id.green_box); 28 | mGreenBox.setOnClickListener(this); 29 | mBlueBox = findViewById(R.id.blue_box); 30 | mBlueBox.setOnClickListener(this); 31 | mBlackBox = findViewById(R.id.black_box); 32 | mBlackBox.setOnClickListener(this); 33 | 34 | } 35 | 36 | @Override 37 | public void onClick(View v) { 38 | switch (v.getId()) { 39 | case R.id.red_box: 40 | break; 41 | default: 42 | TransitionManager.beginDelayedTransition(mRootView, new Fade()); 43 | toggleVisibility(mRedBox, mGreenBox, mBlueBox, mBlackBox); 44 | break; 45 | } 46 | } 47 | 48 | private static void toggleVisibility(View... views) { 49 | for (View view : views) { 50 | boolean isVisible = view.getVisibility() == View.VISIBLE; 51 | view.setVisibility(isVisible ? View.INVISIBLE : View.VISIBLE); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 12 | 13 | 20 | 21 | 29 | 30 | 38 | 39 | 48 | 49 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/transitions/ChangeScale.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.transitions; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ObjectAnimator; 6 | import android.transitions.everywhere.Transition; 7 | import android.transitions.everywhere.TransitionValues; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | /** 12 | * Created by linfaxin on 2015/5/29. 13 | * Email: linlinfaxin@163.com 14 | */ 15 | public class ChangeScale extends Transition { 16 | private static final String PROPNAME_NAME1 = "android:scale:scalex"; 17 | private static final String PROPNAME_NAME2 = "android:scale:scaley"; 18 | private static final String FIELD_NAME1 = "scaleX"; 19 | private static final String FIELD_NAME2 = "scaleY"; 20 | 21 | @Override 22 | public void captureStartValues(TransitionValues transitionValues) { 23 | transitionValues.values.put(PROPNAME_NAME1, transitionValues.view.getScaleX()); 24 | transitionValues.values.put(PROPNAME_NAME2, transitionValues.view.getScaleY()); 25 | } 26 | 27 | @Override 28 | public void captureEndValues(TransitionValues transitionValues) { 29 | transitionValues.values.put(PROPNAME_NAME1, transitionValues.view.getScaleX()); 30 | transitionValues.values.put(PROPNAME_NAME2, transitionValues.view.getScaleY()); 31 | } 32 | 33 | @Override 34 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, 35 | TransitionValues endValues) { 36 | if (startValues == null || endValues == null) { 37 | return null; 38 | } 39 | final View view = endValues.view; 40 | float startValueX = (Float) startValues.values.get(PROPNAME_NAME1); 41 | float startValueY = (Float) startValues.values.get(PROPNAME_NAME2); 42 | float endValueX = (Float) endValues.values.get(PROPNAME_NAME1); 43 | float endValueY = (Float) endValues.values.get(PROPNAME_NAME2); 44 | AnimatorSet animatorSet = new AnimatorSet(); 45 | if (startValueX != endValueX) { 46 | view.setScaleX(startValueX); 47 | animatorSet.playTogether(ObjectAnimator.ofFloat(view, FIELD_NAME1, startValueX, endValueX)); 48 | } 49 | if (startValueY != endValueY) { 50 | view.setScaleY(startValueY); 51 | animatorSet.playTogether( ObjectAnimator.ofFloat(view, FIELD_NAME2, startValueY, endValueY)); 52 | } 53 | if(animatorSet.getChildAnimations()!=null && animatorSet.getChildAnimations().size()>0){ 54 | return animatorSet; 55 | } 56 | return null; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/java/com/hide/transitionstest/app/DragTransitionActivity.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionstest.app; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Color; 5 | import android.os.Bundle; 6 | import android.transitions.everywhere.TransitionManager; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.view.ViewTreeObserver; 10 | import android.widget.FrameLayout; 11 | import android.widget.ImageView; 12 | import com.hide.transitionplayer.lib.TransitionPlayer; 13 | import com.hide.transitionstest.app.widget.DragLayout; 14 | 15 | /** 16 | * * * * * * * * * * * * * * * * * * * * * * * 17 | * Created by zhaoyiding 18 | * Date: 15/10/12 19 | * * * * * * * * * * * * * * * * * * * * * * * 20 | **/ 21 | public class DragTransitionActivity extends Activity 22 | implements DragLayout.IDragListener { 23 | 24 | private View mDimView; 25 | private ViewGroup mSceneRoot; 26 | private TransitionPlayer mTransitionPlayer = new TransitionPlayer(); 27 | private ImageView mHeadImg; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_drag_transition); 33 | 34 | mDimView = findViewById(R.id.dimView); 35 | mSceneRoot = (ViewGroup) findViewById(R.id.scene_root); 36 | mHeadImg = (ImageView) findViewById(R.id.headimg); 37 | 38 | initImg(); 39 | 40 | final DragLayout mDragLayout = (DragLayout) findViewById(R.id.drag_layout); 41 | mDragLayout.setOnDragListener(this); 42 | mDragLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { 43 | @Override 44 | public boolean onPreDraw() { 45 | mDragLayout.getViewTreeObserver().removeOnPreDrawListener(this); 46 | 47 | 48 | TransitionManager.beginDelayedTransition(mSceneRoot, mTransitionPlayer); 49 | ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) mHeadImg.getLayoutParams(); 50 | marginParams.topMargin = 0; 51 | mHeadImg.setLayoutParams(marginParams); 52 | mHeadImg.setAlpha(1.0f); 53 | 54 | mHeadImg.post(new Runnable() { 55 | @Override 56 | public void run() { 57 | mTransitionPlayer.setCurrentFraction(1.0f); 58 | 59 | } 60 | }); 61 | return false; 62 | } 63 | }); 64 | 65 | } 66 | 67 | private void initImg() { 68 | 69 | int height = getResources().getDisplayMetrics().heightPixels / 3 - IndexActivity.sStatusBarHeight; 70 | 71 | FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height); 72 | params.topMargin = -height * 2 / 3; 73 | mHeadImg.setLayoutParams(params); 74 | mHeadImg.setAlpha(0f); 75 | } 76 | 77 | private void setDimViewAlpha(float fraction) { 78 | mDimView.setBackgroundColor(Color.argb((int) (255 * fraction), 0, 0, 0)); 79 | mTransitionPlayer.setCurrentFraction(fraction); 80 | } 81 | 82 | @Override 83 | public void onDragChange(float fraction) { 84 | setDimViewAlpha(fraction); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/transitions/ChangeRotate.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.transitions; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ObjectAnimator; 6 | import android.transitions.everywhere.Transition; 7 | import android.transitions.everywhere.TransitionValues; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | /** 12 | * Created by linfaxin on 2015/5/29. 13 | * Email: linlinfaxin@163.com 14 | */ 15 | public class ChangeRotate extends Transition { 16 | private static final String PROPNAME_NAME = "android:rotate:rotate"; 17 | private static final String PROPNAME_NAME_X = "android:rotate:rotateX"; 18 | private static final String PROPNAME_NAME_Y = "android:rotate:rotateY"; 19 | private static final String FIELD_NAME = "rotation"; 20 | private static final String FIELD_NAME_X = "rotationX"; 21 | private static final String FIELD_NAME_Y = "rotationY"; 22 | 23 | @Override 24 | public void captureStartValues(TransitionValues transitionValues) { 25 | transitionValues.values.put(PROPNAME_NAME, transitionValues.view.getRotation()); 26 | transitionValues.values.put(PROPNAME_NAME_X, transitionValues.view.getRotationX()); 27 | transitionValues.values.put(PROPNAME_NAME_Y, transitionValues.view.getRotationY()); 28 | } 29 | 30 | @Override 31 | public void captureEndValues(TransitionValues transitionValues) { 32 | transitionValues.values.put(PROPNAME_NAME, transitionValues.view.getRotation()); 33 | transitionValues.values.put(PROPNAME_NAME_X, transitionValues.view.getRotationX()); 34 | transitionValues.values.put(PROPNAME_NAME_Y, transitionValues.view.getRotationY()); 35 | } 36 | 37 | @Override 38 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, 39 | TransitionValues endValues) { 40 | if (startValues == null || endValues == null) { 41 | return null; 42 | } 43 | final View view = endValues.view; 44 | float startValue = (Float) startValues.values.get(PROPNAME_NAME); 45 | float startValueX = (Float) startValues.values.get(PROPNAME_NAME_X); 46 | float startValueY = (Float) startValues.values.get(PROPNAME_NAME_Y); 47 | float endValue = (Float) endValues.values.get(PROPNAME_NAME); 48 | float endValueX = (Float) endValues.values.get(PROPNAME_NAME_X); 49 | float endValueY = (Float) endValues.values.get(PROPNAME_NAME_Y); 50 | AnimatorSet animatorSet = new AnimatorSet(); 51 | if (startValue != endValue) { 52 | view.setRotation(startValue); 53 | animatorSet.playTogether(ObjectAnimator.ofFloat(view, FIELD_NAME, startValue, endValue)); 54 | } 55 | if (startValueX != endValueX) { 56 | view.setRotationX(startValueX); 57 | animatorSet.playTogether(ObjectAnimator.ofFloat(view, FIELD_NAME_X, startValueX, endValueX)); 58 | } 59 | if (startValueY != endValueY) { 60 | view.setRotationY(startValueY); 61 | animatorSet.playTogether(ObjectAnimator.ofFloat(view, FIELD_NAME_Y, startValueY, endValueY)); 62 | } 63 | if(animatorSet.getChildAnimations()!=null && animatorSet.getChildAnimations().size()>0){ 64 | return animatorSet; 65 | } 66 | return null; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/transitions/ChangeTransition.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.transitions; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ObjectAnimator; 6 | import android.transitions.everywhere.Transition; 7 | import android.transitions.everywhere.TransitionValues; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | /** 12 | * Created by linfaxin on 2015/5/29. 13 | * Email: linlinfaxin@163.com 14 | */ 15 | public class ChangeTransition extends Transition { 16 | private static final String PROPNAME_NAME1 = "android:transition:translationx"; 17 | private static final String PROPNAME_NAME2 = "android:transition:translationy"; 18 | // private static final String PROPNAME_NAME3 = "android:transition:translationz"; 19 | private static final String FIELD_NAME1 = "translationX"; 20 | private static final String FIELD_NAME2 = "translationY"; 21 | // private static final String FIELD_NAME3 = "translationZ"; 22 | 23 | @Override 24 | public void captureStartValues(TransitionValues transitionValues) { 25 | transitionValues.values.put(PROPNAME_NAME1, transitionValues.view.getTranslationX()); 26 | transitionValues.values.put(PROPNAME_NAME2, transitionValues.view.getTranslationY()); 27 | // transitionValues.values.put(PROPNAME_NAME3, transitionValues.view.getTranslationZ()); 28 | } 29 | 30 | @Override 31 | public void captureEndValues(TransitionValues transitionValues) { 32 | transitionValues.values.put(PROPNAME_NAME1, transitionValues.view.getTranslationX()); 33 | transitionValues.values.put(PROPNAME_NAME2, transitionValues.view.getTranslationY()); 34 | // transitionValues.values.put(PROPNAME_NAME3, transitionValues.view.getTranslationZ()); 35 | } 36 | 37 | @Override 38 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, 39 | TransitionValues endValues) { 40 | if (startValues == null || endValues == null) { 41 | return null; 42 | } 43 | final View view = endValues.view; 44 | float startValueX = (Float) startValues.values.get(PROPNAME_NAME1); 45 | float startValueY = (Float) startValues.values.get(PROPNAME_NAME2); 46 | // float startValueZ = (Float) startValues.values.get(PROPNAME_NAME3); 47 | float endValueX = (Float) endValues.values.get(PROPNAME_NAME1); 48 | float endValueY = (Float) endValues.values.get(PROPNAME_NAME2); 49 | // float endValueZ = (Float) endValues.values.get(PROPNAME_NAME3); 50 | AnimatorSet animatorSet = new AnimatorSet(); 51 | if (startValueX != endValueX) { 52 | view.setTranslationX(startValueX); 53 | animatorSet.playTogether(ObjectAnimator.ofFloat(view, FIELD_NAME1, startValueX, endValueX)); 54 | } 55 | if (startValueY != endValueY) { 56 | view.setTranslationY(startValueY); 57 | animatorSet.playTogether(ObjectAnimator.ofFloat(view, FIELD_NAME2, startValueY, endValueY)); 58 | } 59 | // if (startValueZ != endValueZ) { 60 | // view.setTranslationZ(startValueZ); 61 | // animatorSet.playTogether(ObjectAnimator.ofFloat(view, FIELD_NAME3, startValueZ, endValueZ)); 62 | // } 63 | if(animatorSet.getChildAnimations()!=null && animatorSet.getChildAnimations().size()>0){ 64 | return animatorSet; 65 | } 66 | return null; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/AnimatorUtils.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ObjectAnimator; 6 | import android.animation.PropertyValuesHolder; 7 | import android.animation.ValueAnimator; 8 | import android.annotation.TargetApi; 9 | import android.os.Build; 10 | import android.transitions.everywhere.Transition; 11 | import android.transitions.everywhere.TransitionSet; 12 | 13 | import com.hide.transitionplayer.lib.interpolators.ReverseTimeInterpolator; 14 | 15 | import java.lang.reflect.Field; 16 | import java.lang.reflect.Method; 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | /** 21 | * Created by linfaxin on 2015/8/8. 22 | * Email: linlinfaxin@163.com 23 | */ 24 | public class AnimatorUtils { 25 | 26 | public static List splitAnimatorByValues(ValueAnimator animator){ 27 | ArrayList animators = new ArrayList<>(); 28 | PropertyValuesHolder[] valuesHolders = animator.getValues(); 29 | if(valuesHolders!=null && valuesHolders.length>0){ 30 | for(PropertyValuesHolder valuesHolder : valuesHolders){ 31 | ValueAnimator clone = animator.clone(); 32 | if(clone instanceof ObjectAnimator){ 33 | ((ObjectAnimator) clone).setPropertyName(valuesHolder.getPropertyName()); 34 | } 35 | clone.setValues(valuesHolder); 36 | animators.add(clone); 37 | } 38 | }else{ 39 | animators.add(animator); 40 | } 41 | return animators; 42 | } 43 | 44 | public static float getAnimatorDurationScale() { 45 | try { 46 | Method method = ValueAnimator.class.getDeclaredMethod("getDurationScale"); 47 | method.setAccessible(true); 48 | float scale = ((Float) method.invoke(ValueAnimator.class)).floatValue(); 49 | if(scale<=0){ 50 | method = ValueAnimator.class.getDeclaredMethod("setDurationScale", float.class); 51 | method.setAccessible(true); 52 | method.invoke(ValueAnimator.class, 1); 53 | return 1; 54 | } 55 | return scale; 56 | } catch (Exception ignore) { 57 | } 58 | return 1; 59 | } 60 | 61 | public static List collectValueAnimators(Animator animator){ 62 | ArrayList valueAnimators = new ArrayList(); 63 | for(Animator anim : collectAnimators(animator)){ 64 | if(anim instanceof ValueAnimator){ 65 | valueAnimators.add((ValueAnimator) anim); 66 | } 67 | } 68 | return valueAnimators; 69 | } 70 | 71 | public static List collectAnimators(Animator animator){ 72 | if(animator instanceof AnimatorSet){ 73 | return collectAnimatorsFromSet((AnimatorSet) animator); 74 | 75 | }else{ 76 | ArrayList animators = new ArrayList(); 77 | animators.add(animator); 78 | return animators; 79 | } 80 | } 81 | 82 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 83 | public static List collectAnimatorsFromSet(AnimatorSet animatorSet){ 84 | ArrayList animators = new ArrayList(); 85 | for(Animator animator : animatorSet.getChildAnimations()){ 86 | animators.addAll(collectAnimators(animator)); 87 | } 88 | return animators; 89 | } 90 | 91 | public static List collectAnimators(Transition transition){ 92 | if(transition instanceof TransitionSet){ 93 | return collectAnimatorsFromSet((TransitionSet) transition); 94 | } 95 | return collectAnimatorsFromTransition(transition); 96 | } 97 | 98 | private static List collectAnimatorsFromSet(TransitionSet transitionSet){ 99 | ArrayList animators = new ArrayList(); 100 | for(int i=0, count = transitionSet.getTransitionCount(); i collectAnimatorsFromTransition(Transition transition){ 107 | try { 108 | Field field = Transition.class.getDeclaredField("mAnimators"); 109 | field.setAccessible(true); 110 | return (List) field.get(transition); 111 | } catch (Exception e) { 112 | e.printStackTrace(); 113 | } 114 | return new ArrayList(); 115 | } 116 | 117 | public static void reverseAnimator(Animator animator){ 118 | if(animator instanceof ValueAnimator){ 119 | animator.setInterpolator(new ReverseTimeInterpolator(((ValueAnimator)animator).getInterpolator())); 120 | }else if(Build.VERSION.SDK_INT>=18){ 121 | animator.setInterpolator(new ReverseTimeInterpolator(animator.getInterpolator())); 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /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 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/TransitionPlayer.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib; 2 | 3 | import android.animation.Animator; 4 | import android.animation.TimeInterpolator; 5 | import android.animation.ValueAnimator; 6 | import android.os.Build; 7 | import android.transitions.everywhere.ChangeBounds; 8 | import android.transitions.everywhere.Fade; 9 | import android.transitions.everywhere.Transition; 10 | import android.transitions.everywhere.TransitionSet; 11 | import android.transitions.everywhere.TransitionValues; 12 | import android.view.ViewGroup; 13 | import android.view.animation.LinearInterpolator; 14 | 15 | import com.hide.transitionplayer.lib.control.PlayControl; 16 | import com.hide.transitionplayer.lib.transitions.ChangeAlpha; 17 | import com.hide.transitionplayer.lib.transitions.ChangeBackground; 18 | import com.hide.transitionplayer.lib.transitions.ChangeRotate; 19 | import com.hide.transitionplayer.lib.transitions.ChangeScale; 20 | import com.hide.transitionplayer.lib.transitions.ChangeTextColor; 21 | import com.hide.transitionplayer.lib.transitions.ChangeTransition; 22 | 23 | import java.lang.reflect.Method; 24 | import java.util.ArrayList; 25 | import java.util.LinkedHashMap; 26 | 27 | /** 28 | * Created by linfaxin on 2015/5/27. 29 | * Email: linlinfaxin@163.com 30 | */ 31 | public class TransitionPlayer extends TransitionSet { 32 | private LinkedHashMap> animMap = new LinkedHashMap<>(); 33 | private PlayControl playControl; 34 | public final ChangeBounds changeBounds = new ChangeBounds(); 35 | public final ChangeAlpha changeAlpha = new ChangeAlpha(); 36 | public final ChangeRotate changeRotate = new ChangeRotate(); 37 | public final ChangeScale changeScale = new ChangeScale(); 38 | public final ChangeTransition changeTransition = new ChangeTransition(); 39 | public final ChangeBackground changeBackground = new ChangeBackground(); 40 | public final ChangeTextColor changeTextColor = new ChangeTextColor(); 41 | public final Fade fadeOut = new Fade(Fade.OUT); 42 | public final Fade fadeIn = new Fade(Fade.IN); 43 | 44 | public TransitionPlayer() { 45 | 46 | setOrdering(TransitionSet.ORDERING_TOGETHER); 47 | setDuration(300); 48 | 49 | addTransition(changeBounds); 50 | addTransition(changeAlpha); 51 | addTransition(changeRotate); 52 | addTransition(changeScale); 53 | addTransition(changeTransition); 54 | addTransition(changeBackground); 55 | addTransition(changeTextColor); 56 | 57 | addTransition(fadeOut); 58 | addTransition(fadeIn); 59 | 60 | setInterpolator(new LinearInterpolator()); 61 | } 62 | 63 | private void reflectSetupStartEndListeners() { 64 | try { 65 | Method method = TransitionSet.class.getDeclaredMethod("setupStartEndListeners"); 66 | method.setAccessible(true); 67 | method.invoke(this); 68 | } catch (Exception ignore) { 69 | } 70 | } 71 | 72 | @Override 73 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, 74 | TransitionValues endValues) { 75 | return null; 76 | } 77 | 78 | @Override 79 | protected void runAnimators() { 80 | reflectSetupStartEndListeners(); 81 | animMap.clear(); 82 | for(int i=0, count = getTransitionCount(); i valueAnimators = new ArrayList<>(); 85 | for(Animator animator : AnimatorUtils.collectAnimators(transition)){ 86 | valueAnimators.addAll(AnimatorUtils.collectValueAnimators(animator)); 87 | } 88 | 89 | //insure animator's duration, startDelay, Interpolator same as this transition 90 | long duration = (long) (getDuration()/ AnimatorUtils.getAnimatorDurationScale()); 91 | long startDelay = getStartDelay(); 92 | TimeInterpolator interpolator = getInterpolator(); 93 | for (ValueAnimator animator : valueAnimators) { 94 | if (duration >= 0) animator.setDuration(duration); 95 | if (startDelay >= 0) animator.setStartDelay(startDelay + animator.getStartDelay()); 96 | if (interpolator != null) animator.setInterpolator(interpolator); 97 | } 98 | 99 | animMap.put(transition, valueAnimators); 100 | //you can change transition's duration, startDelay and Interpolator at here 101 | if(playControl!=null) playControl.onPreRunAnimator(transition, valueAnimators); 102 | } 103 | 104 | } 105 | 106 | public ArrayList getAllAnimator(){ 107 | ArrayList animators = new ArrayList<>(); 108 | for(ArrayList value : animMap.values()){ 109 | animators.addAll(value); 110 | } 111 | return animators; 112 | } 113 | 114 | public void setCurrentFraction(float fraction){ 115 | if(Build.VERSION.SDK_INT>Build.VERSION_CODES.LOLLIPOP){ 116 | for (ValueAnimator valueAnimator : getAllAnimator()) { 117 | valueAnimator.setCurrentFraction(fraction); 118 | } 119 | }else{ 120 | setCurrentPlayTime((long) (fraction * getDuration())); 121 | } 122 | } 123 | public void setCurrentPlayTime(long playTime){ 124 | for (ValueAnimator valueAnimator : getAllAnimator()) { 125 | playTime -= valueAnimator.getStartDelay(); 126 | if(playTime<0) playTime=0; 127 | valueAnimator.setCurrentPlayTime(playTime); 128 | } 129 | } 130 | 131 | public PlayControl getPlayControl() { 132 | return playControl; 133 | } 134 | 135 | public void setPlayControl(PlayControl playControl) { 136 | this.playControl = playControl; 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /app/src/main/java/com/hide/transitionstest/app/widget/DragLayout.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionstest.app.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.support.v4.view.ViewCompat; 6 | import android.support.v4.widget.ViewDragHelper; 7 | import android.util.AttributeSet; 8 | import android.view.*; 9 | import android.widget.FrameLayout; 10 | import com.hide.transitionstest.app.R; 11 | 12 | /** 13 | * * * * * * * * * * * * * * * * * * * * * * * 14 | * Created by zhaoyiding 15 | * Date: 15/10/12 16 | * * * * * * * * * * * * * * * * * * * * * * * 17 | **/ 18 | public class DragLayout extends FrameLayout { 19 | 20 | public static final int STATE_COLLAPSE = 1; 21 | public static final int STATE_EXPAND = 2; 22 | 23 | private ViewGroup mDragContent; 24 | private View mTouchView; 25 | 26 | 27 | private IDragListener iDragListener; 28 | private ViewDragHelper mDragHelper; 29 | private int mSlideMaxY; 30 | private int mTopPadding; 31 | private int mCurState = STATE_EXPAND; 32 | 33 | 34 | private ViewDragHelper.Callback mCallback = new ViewDragHelper.Callback() { 35 | @Override 36 | public boolean tryCaptureView(View child, int pointerId) { 37 | return child == mDragContent; 38 | } 39 | 40 | @Override 41 | public int clampViewPositionVertical(View child, int top, int dy) { 42 | return clampHeight(top); 43 | } 44 | 45 | @Override 46 | public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { 47 | if (iDragListener != null) { 48 | iDragListener.onDragChange(dragPercent(top)); 49 | } 50 | } 51 | 52 | @Override 53 | public int getViewVerticalDragRange(View child) { 54 | return mSlideMaxY; 55 | } 56 | 57 | @Override 58 | public void onViewReleased(View releasedChild, float xvel, float yvel) { 59 | super.onViewReleased(releasedChild, xvel, yvel); 60 | 61 | int settleTop = mTopPadding; 62 | int slideRange = releasedChild.getTop() - mTopPadding; 63 | switch (mCurState) { 64 | case STATE_EXPAND: 65 | if (yvel >= 0 66 | && slideRange > mSlideMaxY / 5) { 67 | settleTop = getHeight() - mTouchView.getMeasuredHeight(); 68 | } 69 | break; 70 | case STATE_COLLAPSE: 71 | slideRange = getHeight() - releasedChild.getTop() - mTouchView.getMeasuredHeight(); 72 | if (yvel > 0 73 | || slideRange < mSlideMaxY / 5) { 74 | settleTop = getHeight() - mTouchView.getMeasuredHeight(); 75 | } 76 | break; 77 | } 78 | 79 | mDragHelper.settleCapturedViewAt(getLeft(), settleTop); 80 | invalidate(); 81 | } 82 | 83 | @Override 84 | public void onViewDragStateChanged(int state) { 85 | super.onViewDragStateChanged(state); 86 | switch (state) { 87 | case ViewDragHelper.STATE_IDLE: 88 | mCurState = mTopPadding == mDragContent.getTop() ? STATE_EXPAND : STATE_COLLAPSE; 89 | break; 90 | } 91 | } 92 | }; 93 | 94 | 95 | public DragLayout(Context context) { 96 | super(context); 97 | init(); 98 | } 99 | 100 | public DragLayout(Context context, AttributeSet attrs) { 101 | super(context, attrs); 102 | init(); 103 | } 104 | 105 | public DragLayout(Context context, AttributeSet attrs, int defStyleAttr) { 106 | super(context, attrs, defStyleAttr); 107 | init(); 108 | } 109 | 110 | private void init() { 111 | removeAllViews(); 112 | mDragContent = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.drag_layout, null); 113 | mTouchView = mDragContent.findViewById(R.id.drag); 114 | addView(mDragContent); 115 | getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { 116 | @Override 117 | public boolean onPreDraw() { 118 | getViewTreeObserver().removeOnPreDrawListener(this); 119 | 120 | int height = getContext().getResources().getDisplayMetrics().heightPixels * 2 / 3; 121 | ViewGroup.LayoutParams params = mDragContent.getLayoutParams(); 122 | params.height = height; 123 | mDragContent.setLayoutParams(params); 124 | 125 | mSlideMaxY = height - mTouchView.getMeasuredHeight(); 126 | 127 | return false; 128 | } 129 | }); 130 | 131 | mDragHelper = ViewDragHelper.create(this, 1.0f, mCallback); 132 | // ViewGroupCompat.setMotionEventSplittingEnabled(this, false); 133 | } 134 | 135 | 136 | @Override 137 | public boolean onInterceptTouchEvent(MotionEvent ev) { 138 | 139 | boolean intercept; 140 | try { 141 | intercept = mDragHelper.shouldInterceptTouchEvent(ev); 142 | } catch (Exception e) { 143 | e.printStackTrace(); 144 | intercept = false; 145 | } 146 | return intercept; 147 | } 148 | 149 | @Override 150 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { 151 | int height = getContext().getResources().getDisplayMetrics().heightPixels; 152 | int childHeight = height * 2 / 3; 153 | Rect statusBarRect = new Rect(); 154 | getWindowVisibleDisplayFrame(statusBarRect); 155 | int statusBar = statusBarRect.top; 156 | height -= statusBar; 157 | mTopPadding = height - childHeight; 158 | mDragContent.layout(left, top + mTopPadding, right, bottom); 159 | } 160 | 161 | @Override 162 | public boolean onTouchEvent(MotionEvent event) { 163 | 164 | boolean onTouch = true; 165 | try { 166 | mDragHelper.processTouchEvent(event); 167 | } catch (Exception e) { 168 | e.printStackTrace(); 169 | onTouch = false; 170 | } 171 | return onTouch; 172 | } 173 | 174 | private int clampHeight(int top) { 175 | return Math.max(mTopPadding, Math.min(top, mSlideMaxY + mTopPadding)); 176 | } 177 | 178 | private float dragPercent(int top) { 179 | return 1 - (top - mTopPadding) * 1.0f / mSlideMaxY; 180 | 181 | } 182 | 183 | 184 | @Override 185 | public void computeScroll() { 186 | super.computeScroll(); 187 | if (mDragHelper.continueSettling(true)) { 188 | ViewCompat.postInvalidateOnAnimation(this); 189 | } 190 | } 191 | 192 | public void setOnDragListener(IDragListener l) { 193 | iDragListener = l; 194 | } 195 | 196 | public interface IDragListener { 197 | void onDragChange(float fraction); 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/TransitionPlayer-lib.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /TransitionPlayer-lib/src/main/java/com/hide/transitionplayer/lib/transitions/AbsChangeValue.java: -------------------------------------------------------------------------------- 1 | package com.hide.transitionplayer.lib.transitions; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorSet; 5 | import android.animation.ObjectAnimator; 6 | import android.animation.TypeEvaluator; 7 | import android.transitions.everywhere.Transition; 8 | import android.transitions.everywhere.TransitionValues; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | 12 | import java.lang.reflect.Method; 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Created by linfaxin on 2015/8/9. 17 | * Email: linlinfaxin@163.com 18 | */ 19 | public abstract class AbsChangeValue extends Transition { 20 | protected String[] valueNames; 21 | protected final String propertyPrefix; 22 | private TypeEvaluator typeEvaluator; 23 | 24 | public AbsChangeValue(String... valueNames) { 25 | this(null, valueNames); 26 | } 27 | public AbsChangeValue(TypeEvaluator typeEvaluator, String... valueNames) { 28 | setTypeEvaluator(typeEvaluator); 29 | this.valueNames = valueNames; 30 | propertyPrefix = "android:" + getClass().getSimpleName() + ":"; 31 | } 32 | 33 | public void setTypeEvaluator(TypeEvaluator typeEvaluator) { 34 | this.typeEvaluator = typeEvaluator; 35 | } 36 | 37 | @Override 38 | public void captureStartValues(TransitionValues transitionValues) { 39 | for(String valueName : valueNames) { 40 | transitionValues.values.put(propertyPrefix + valueName, getPropertyValue(transitionValues.view, valueName)); 41 | } 42 | } 43 | 44 | @Override 45 | public void captureEndValues(TransitionValues transitionValues) { 46 | for(String valueName : valueNames) { 47 | transitionValues.values.put(propertyPrefix + valueName, getPropertyValue(transitionValues.view, valueName)); 48 | } 49 | } 50 | 51 | 52 | @Override 53 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, 54 | TransitionValues endValues) { 55 | if (startValues == null || endValues == null) { 56 | return null; 57 | } 58 | AnimatorSet animatorSet = new AnimatorSet(); 59 | final View view = endValues.view; 60 | 61 | for(String valueName : valueNames) { 62 | Object startValue = startValues.values.get(propertyPrefix + valueName); 63 | Object endValue = endValues.values.get(propertyPrefix + valueName); 64 | if(startValue!=null && endValue!=null && startValue.getClass()!=endValue.getClass()) continue; 65 | Class c = null; 66 | if(startValue!=null) c= startValue.getClass(); 67 | else if(endValue!=null) c=endValue.getClass(); 68 | if(c==null) continue; 69 | ObjectAnimator animator; 70 | if(c==Float.class || c==float.class){ 71 | animator = ObjectAnimator.ofFloat(view, valueName, (Float) startValue, (Float) endValue); 72 | animatorSet.playTogether(animator); 73 | 74 | }else if(c==Integer.class || c==int.class){ 75 | animator = ObjectAnimator.ofInt(view, valueName, (Integer) startValue, (Integer) endValue); 76 | animatorSet.playTogether(animator); 77 | 78 | }else{ 79 | animator = ObjectAnimator.ofObject(view, valueName, typeEvaluator, startValue, endValue); 80 | animatorSet.playTogether(animator); 81 | } 82 | setPropertyValue(view, valueName, startValue); 83 | if(typeEvaluator!=null) animator.setEvaluator(typeEvaluator); 84 | } 85 | 86 | ArrayList animators = animatorSet.getChildAnimations(); 87 | if(animators!=null && animators.size()>0){ 88 | if(animators.size()==1) return animators.get(0); 89 | return animatorSet; 90 | } 91 | return null; 92 | } 93 | 94 | protected Object getPropertyValue(View view, String propertyName){ 95 | Class c = view.getClass(); 96 | while(c!=Object.class){ 97 | try { 98 | String methodName = getMethodName("get", propertyName); 99 | Method m = c.getDeclaredMethod(methodName); 100 | m.setAccessible(true); 101 | return m.invoke(view); 102 | }catch (Exception ignore){ 103 | } 104 | c = c.getSuperclass(); 105 | } 106 | return null; 107 | } 108 | 109 | // We try several different types when searching for appropriate setter/getter functions. 110 | // The caller may have supplied values in a type that does not match the setter/getter 111 | // functions (such as the integers 0 and 1 to represent floating point values for alpha). 112 | // Also, the use of generics in constructors means that we end up with the Object versions 113 | // of primitive types (Float vs. float). But most likely, the setter/getter functions 114 | // will take primitive types instead. 115 | // So we supply an ordered array of other types to try before giving up. 116 | private static Class[] FLOAT_VARIANTS = {float.class, Float.class, double.class, int.class, 117 | Double.class, Integer.class}; 118 | private static Class[] INTEGER_VARIANTS = {int.class, Integer.class, float.class, double.class, 119 | Float.class, Double.class}; 120 | private static Class[] DOUBLE_VARIANTS = {double.class, Double.class, float.class, int.class, 121 | Float.class, Integer.class}; 122 | protected void setPropertyValue(View view, String propertyName, Object value){ 123 | Class c = view.getClass(); 124 | Class valueType = value.getClass(); 125 | while(c!=Object.class){ 126 | String methodName = getMethodName("set", propertyName); 127 | Class[] typeVariants; 128 | if (valueType.equals(Float.class)) { 129 | typeVariants = FLOAT_VARIANTS; 130 | } else if (valueType.equals(Integer.class)) { 131 | typeVariants = INTEGER_VARIANTS; 132 | } else if (valueType.equals(Double.class)) { 133 | typeVariants = DOUBLE_VARIANTS; 134 | } else { 135 | typeVariants = new Class[1]; 136 | typeVariants[0] = valueType; 137 | } 138 | for (Class typeVariant : typeVariants) { 139 | try { 140 | Method m = c.getMethod(methodName, typeVariant); 141 | m.setAccessible(true); 142 | m.invoke(view, value); 143 | return; 144 | } catch (Exception e) { 145 | // Swallow the error and keep trying other variants 146 | } 147 | } 148 | c = c.getSuperclass(); 149 | } 150 | } 151 | 152 | /** 153 | * Utility method to derive a setter/getter method name from a property name, where the 154 | * prefix is typically "set" or "get" and the first letter of the property name is 155 | * capitalized. 156 | * 157 | * @param prefix The precursor to the method name, before the property name begins, typically 158 | * "set" or "get". 159 | * @param propertyName The name of the property that represents the bulk of the method name 160 | * after the prefix. The first letter of this word will be capitalized in the resulting 161 | * method name. 162 | * @return String the property name converted to a method name according to the conventions 163 | * specified above. 164 | */ 165 | static String getMethodName(String prefix, String propertyName) { 166 | if (propertyName == null || propertyName.length() == 0) { 167 | // shouldn't get here 168 | return prefix; 169 | } 170 | char firstLetter = Character.toUpperCase(propertyName.charAt(0)); 171 | String theRest = propertyName.substring(1); 172 | return prefix + firstLetter + theRest; 173 | } 174 | } 175 | --------------------------------------------------------------------------------