├── .gitignore ├── README.MD ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── onzhou │ │ └── tiktok │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── onzhou │ │ │ └── tiktok │ │ │ ├── CoverView.java │ │ │ ├── DesImgInfo.java │ │ │ ├── GridItemDecoration.java │ │ │ ├── MainActivity.java │ │ │ ├── VideoCoverLayer.java │ │ │ ├── VideoPlayActivity.java │ │ │ ├── VideoPlayAdapter.java │ │ │ └── VideoPlayViewHolder.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xxhdpi │ │ └── background.jpg │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── activity_video_cover_item.xml │ │ └── activity_video_play.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── onzhou │ └── tiktok │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── mine.webp └── toutiao.webp ├── settings.gradle └── transition ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── main ├── AndroidManifest.xml ├── java │ └── com │ │ └── onzhou │ │ └── transition │ │ ├── StatusBarUtils.java │ │ ├── TransitionCallback.java │ │ ├── TransitionController.java │ │ ├── TransitionParam.java │ │ └── TransitionUtils.java └── res │ ├── anim │ ├── fade_in.xml │ └── fade_out.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── styles.xml └── test └── java └── com └── onzhou └── okhttp └── transition └── ExampleUnitTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | *.iml 3 | .gradle 4 | /build 5 | /captures 6 | /outputs 7 | *.hprof 8 | 9 | bin/ 10 | gen/ 11 | out/ 12 | 13 | .gradle/ 14 | build/ 15 | local.properties 16 | 17 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 可以先看看今日头条效果 5 | 6 | ![](https://github.com/byhook/tiktok-anim/blob/master/screenshots/toutiao.webp) 7 | 8 | 9 | ## 功能分析 10 | 11 | 点击列表上的一个`item`,该`item`会放大,最后直接全屏播放小视频,刚开始看上去,以为是个`共享元素的转场动画`, 12 | 后来想到,`共享元素`要在android 5.0以上支持,而今日头条显然不会只支持5.0版本以上 13 | 14 | 笔者想到的一种方案就是进入Activity之后,在`onCreate`的生命周期回调,计算缩放的动画参数,思路如下 15 | 16 | 1.点击列表上的`item`,获取该`view`的屏幕位置信息,立即传入进入目标比如`VideoPlayAcitvity`中 17 | 2.`onCreate`生命周期方法中进行动画播放 18 | 19 | 看上去也不难,但实际有几个问题,第一步需要设置`VideoPlayAcitvity`透明,并且去掉转场动画 20 | 21 | ## 功能使用 22 | ``` 23 | transitionController = new TransitionController.Builder() 24 | .with(findViewById(R.id.main_root_layer)) 25 | //今日头条默认参数 26 | .setInterpolator(PathInterpolatorCompat.create(0.32F, 0.94F, 0.6F, 1.0F)) 27 | .duration(320) 28 | .build(); 29 | transitionController.transitionEnter(targetAnimBean, new TransitionCallback() { 30 | @Override 31 | public void onTransitionStop() { 32 | //显示小视频界面评论等控件 33 | } 34 | }); 35 | ``` 36 | 37 | 来看看实际效果: 38 | 39 | ![](https://github.com/byhook/tiktok-anim/blob/master/screenshots/mine.webp) 40 | 41 | ## 功能实现 42 | 给出部分关键的逻辑 43 | ``` 44 | /** 45 | * 进入和退出的动画 46 | * @param enterAnimation 是否入场动画 47 | * @param animatorListener 监听动画回调 48 | */ 49 | private void transitionStart(boolean enterAnimation, Animator.AnimatorListener animatorListener) { 50 | //标识我们点击的View在屏幕中可见的高度 51 | int visibleHeight = transitionParam.bottom - transitionParam.top; 52 | 53 | //计算缩放的宽和高起点,需要和外部的控件宽高看起来一致才比较细腻 54 | float scaleXStart = (float) transitionParam.width / targetWidth; 55 | float scaleYStart = (float) transitionParam.height / targetHeight; 56 | 57 | animView.setPivotX(0); 58 | animView.setPivotY(0); 59 | 60 | int startTransX = transitionParam.left; 61 | int startTransY; 62 | if (transitionParam.bottom == targetHeight) { 63 | //滑动到屏幕底部去了,这时候以点击的控件顶部为位移起始点 64 | startTransY = transitionParam.top; 65 | } else if (visibleHeight < transitionParam.height) { 66 | //滑动到屏幕顶部去了 67 | startTransY = transitionParam.bottom - transitionParam.height; 68 | } else { 69 | startTransY = transitionParam.top; 70 | } 71 | 72 | if (enterAnimation) { 73 | //显示动画设置移动的起始位置,关闭动画只指定目标位移位置 74 | animView.setTranslationX(startTransX); 75 | animView.setTranslationY(startTransY); 76 | } 77 | 78 | //设置缩放点 79 | animView.setScaleX(enterAnimation ? scaleXStart : 1.0F); 80 | animView.setScaleY(enterAnimation ? scaleYStart : 1.0F); 81 | 82 | viewAnimator = animView.animate(); 83 | //头条参数 84 | viewAnimator.setInterpolator(timeInterpolator); 85 | animView.setVisibility(View.VISIBLE); 86 | viewAnimator.setDuration(duration) 87 | .setListener(animatorListener) 88 | .scaleX(enterAnimation ? 1.0F : scaleXStart) 89 | .scaleY(enterAnimation ? 1.0F : scaleYStart) 90 | .translationX(enterAnimation ? 0.0F : startTransX) 91 | .translationY(enterAnimation ? 0.0F : startTransY) 92 | .start(); 93 | } 94 | ``` 95 | 96 | ## 手势滑动 97 | 手势滑动主要也是拦截触摸事件,计算移动的距离,根据移动的距离,等比的缩放指定的`容器` 98 | `待后续会更新` 99 | 100 | [项目地址](https://github.com/byhook/tiktok-anim) 101 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion '28.0.3' 6 | 7 | defaultConfig { 8 | applicationId "com.onzhou.tiktok" 9 | minSdkVersion 16 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | implementation fileTree(dir: 'libs', include: ['*.jar']) 25 | implementation 'androidx.appcompat:appcompat:1.0.2' 26 | api 'androidx.recyclerview:recyclerview:1.0.0' 27 | testImplementation 'junit:junit:4.12' 28 | 29 | //基于750x1334设计稿的适配库 30 | //compile 'com.onzhou.adapter:dimens:750x1334' 31 | implementation project(':transition') 32 | } 33 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/onzhou/tiktok/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.onzhou.tiktok", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/onzhou/tiktok/CoverView.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import androidx.appcompat.widget.AppCompatImageView; 7 | 8 | /** 9 | * @anchor: Andy 10 | * @date: 2018-10-17 11 | * @description: 12 | */ 13 | public class CoverView extends AppCompatImageView { 14 | 15 | public CoverView(Context context) { 16 | super(context); 17 | } 18 | 19 | public CoverView(Context context, AttributeSet attrs) { 20 | super(context, attrs); 21 | } 22 | 23 | public CoverView(Context context, AttributeSet attrs, int defStyleAttr) { 24 | super(context, attrs, defStyleAttr); 25 | } 26 | 27 | @Override 28 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 29 | int height = MeasureSpec.getSize(heightMeasureSpec); 30 | int width = (int) ((float) height / 16 * 9); 31 | super.onMeasure(heightMeasureSpec, heightMeasureSpec); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/src/main/java/com/onzhou/tiktok/DesImgInfo.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | /** 4 | * @anchor: Andy 5 | * @date: 2018-10-17 6 | * @description: 7 | */ 8 | public class DesImgInfo { 9 | 10 | public int locationX; 11 | 12 | public int locationY; 13 | 14 | public int width; 15 | 16 | public int height; 17 | 18 | 19 | public int getLocationX() { 20 | return locationX; 21 | } 22 | 23 | public void setLocationX(int locationX) { 24 | this.locationX = locationX; 25 | } 26 | 27 | public int getLocationY() { 28 | return locationY; 29 | } 30 | 31 | public void setLocationY(int locationY) { 32 | this.locationY = locationY; 33 | } 34 | 35 | public int getWidth() { 36 | return width; 37 | } 38 | 39 | public void setWidth(int width) { 40 | this.width = width; 41 | } 42 | 43 | public int getHeight() { 44 | return height; 45 | } 46 | 47 | public void setHeight(int height) { 48 | this.height = height; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/onzhou/tiktok/GridItemDecoration.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | import android.graphics.Color; 4 | import android.graphics.Paint; 5 | import android.graphics.Rect; 6 | import android.view.View; 7 | 8 | import androidx.recyclerview.widget.RecyclerView; 9 | 10 | /** 11 | * 作者: andy 12 | * 时间: 2017-01-03 13 | * 描述: 14 | */ 15 | 16 | public class GridItemDecoration extends RecyclerView.ItemDecoration { 17 | 18 | /** 19 | * 高度 20 | * 资源 21 | */ 22 | private int resItemDimen = 2; 23 | 24 | /** 25 | * 分割线的画笔 26 | * 分割 27 | */ 28 | private Paint mPaint; 29 | 30 | public GridItemDecoration() { 31 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 32 | mPaint.setColor(Color.WHITE); 33 | mPaint.setStyle(Paint.Style.FILL); 34 | } 35 | 36 | @Override 37 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { 38 | super.getItemOffsets(outRect, view, parent, state); 39 | outRect.bottom = resItemDimen; 40 | if (parent.indexOfChild(view) % 2 == 0) { 41 | outRect.right = resItemDimen; 42 | } else { 43 | outRect.right = 0; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/onzhou/tiktok/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | import android.os.Bundle; 4 | 5 | import androidx.appcompat.app.AppCompatActivity; 6 | import androidx.recyclerview.widget.GridLayoutManager; 7 | import androidx.recyclerview.widget.RecyclerView; 8 | 9 | public class MainActivity extends AppCompatActivity { 10 | 11 | private RecyclerView mRecycleView; 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | setupView(); 18 | } 19 | 20 | private void setupView() { 21 | mRecycleView = (RecyclerView) findViewById(R.id.recycle_cover); 22 | mRecycleView.setLayoutManager(new GridLayoutManager(this, 2)); 23 | //mRecycleView.addItemDecoration(new GridItemDecoration()); 24 | mRecycleView.setAdapter(new VideoPlayAdapter()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/onzhou/tiktok/VideoCoverLayer.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | import android.content.Context; 4 | import android.graphics.Rect; 5 | import android.util.AttributeSet; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.FrameLayout; 9 | import android.widget.ImageView; 10 | 11 | import androidx.annotation.NonNull; 12 | import androidx.annotation.Nullable; 13 | import androidx.appcompat.widget.AppCompatImageView; 14 | 15 | /** 16 | * @anchor: andy 17 | * @date: 2018-10-08 18 | * @description: 19 | */ 20 | public class VideoCoverLayer extends AppCompatImageView { 21 | 22 | public VideoCoverLayer(@NonNull Context context) { 23 | this(context, null); 24 | } 25 | 26 | public VideoCoverLayer(@NonNull Context context, @Nullable AttributeSet attrs) { 27 | this(context, attrs, 0); 28 | } 29 | 30 | public VideoCoverLayer(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 31 | super(context, attrs, defStyleAttr); 32 | } 33 | 34 | @Override 35 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 36 | int width = MeasureSpec.getSize(widthMeasureSpec); 37 | //测试直接硬编码,下一个页面是全屏显示 38 | Rect location = new Rect(); 39 | View rootView = (View) getParent(); 40 | rootView.getGlobalVisibleRect(location); 41 | 42 | int height = (int) ((float) width / location.right * location.bottom); 43 | super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/onzhou/tiktok/VideoPlayActivity.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | import android.animation.Animator; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.graphics.Matrix; 7 | import android.os.Build; 8 | import android.os.Bundle; 9 | import android.util.DisplayMetrics; 10 | import android.view.MotionEvent; 11 | import android.view.View; 12 | import android.view.ViewPropertyAnimator; 13 | import android.view.ViewTreeObserver; 14 | import android.widget.ImageView; 15 | 16 | import androidx.annotation.Nullable; 17 | import androidx.core.view.animation.PathInterpolatorCompat; 18 | import androidx.fragment.app.FragmentActivity; 19 | 20 | import com.onzhou.transition.StatusBarUtils; 21 | import com.onzhou.transition.TransitionCallback; 22 | import com.onzhou.transition.TransitionController; 23 | import com.onzhou.transition.TransitionParam; 24 | import com.onzhou.transition.TransitionUtils; 25 | 26 | /** 27 | * @anchor: Andy 28 | * @date: 2018-10-08 29 | * @description: 30 | */ 31 | public class VideoPlayActivity extends FragmentActivity { 32 | 33 | private static final String ANIM_PARAM = "ANIM_PARAM"; 34 | 35 | /** 36 | * 封面图 37 | */ 38 | private ImageView mIvCover; 39 | 40 | /** 41 | * 外部控件位置参数 42 | */ 43 | private TransitionParam targetAnimBean; 44 | 45 | private TransitionController transitionController; 46 | 47 | public static void intentStart(Context context, TransitionParam animBean) { 48 | Intent intent = new Intent(context, VideoPlayActivity.class); 49 | intent.putExtra(ANIM_PARAM, animBean); 50 | context.startActivity(intent); 51 | } 52 | 53 | @Override 54 | protected void onCreate(@Nullable Bundle savedInstanceState) { 55 | super.onCreate(savedInstanceState); 56 | StatusBarUtils.enableStatusBar(this, true); 57 | setContentView(R.layout.activity_video_play); 58 | setupView(); 59 | } 60 | 61 | @Override 62 | protected void onDestroy() { 63 | super.onDestroy(); 64 | if (transitionController != null) { 65 | transitionController.transitionRelease(); 66 | } 67 | } 68 | 69 | private void setupView() { 70 | mIvCover = (ImageView) findViewById(R.id.video_cover); 71 | targetAnimBean = getIntent().getParcelableExtra(ANIM_PARAM); 72 | 73 | transitionController = new TransitionController.Builder() 74 | .with(findViewById(R.id.main_root_layer)) 75 | .setInterpolator(PathInterpolatorCompat.create(0.32F, 0.94F, 0.6F, 1.0F)) 76 | .duration(320) 77 | .build(); 78 | transitionController.transitionEnter(targetAnimBean, new TransitionCallback() { 79 | @Override 80 | public void onTransitionStop() { 81 | 82 | } 83 | }); 84 | } 85 | 86 | @Override 87 | public void onBackPressed() { 88 | if (targetAnimBean != null) { 89 | transitionController.transitionExit(new TransitionCallback() { 90 | @Override 91 | public void onTransitionStop() { 92 | finish(); 93 | } 94 | }); 95 | } else { 96 | finish(); 97 | } 98 | } 99 | 100 | @Override 101 | public void finish() { 102 | super.finish(); 103 | TransitionUtils.finishTransition(this); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/src/main/java/com/onzhou/tiktok/VideoPlayAdapter.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.View; 5 | import android.view.ViewGroup; 6 | 7 | import androidx.recyclerview.widget.RecyclerView; 8 | 9 | import com.onzhou.transition.TransitionParam; 10 | import com.onzhou.transition.TransitionUtils; 11 | 12 | /** 13 | * @anchor: Andy 14 | * @date: 2018-10-08 15 | * @description: 16 | */ 17 | public class VideoPlayAdapter extends RecyclerView.Adapter { 18 | 19 | @Override 20 | public VideoPlayViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 21 | View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_video_cover_item, null); 22 | return new VideoPlayViewHolder(rootView); 23 | } 24 | 25 | @Override 26 | public void onBindViewHolder(VideoPlayViewHolder holder, int position) { 27 | holder.rootView.setOnClickListener(new View.OnClickListener() { 28 | @Override 29 | public void onClick(View view) { 30 | TransitionParam animBean = TransitionUtils.getSourceViewParam(view); 31 | VideoPlayActivity.intentStart(view.getContext(), animBean); 32 | } 33 | }); 34 | } 35 | 36 | @Override 37 | public int getItemCount() { 38 | return 10; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/onzhou/tiktok/VideoPlayViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | import android.view.View; 4 | 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | /** 8 | * @anchor: Andy 9 | * @date: 2018-10-08 10 | * @description: 11 | */ 12 | public class VideoPlayViewHolder extends RecyclerView.ViewHolder { 13 | 14 | public View rootView; 15 | 16 | public VideoPlayViewHolder(View itemView) { 17 | super(itemView); 18 | this.rootView = itemView; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/drawable-xxhdpi/background.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_video_cover_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_video_play.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | tiktok-video 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/test/java/com/onzhou/tiktok/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.tiktok; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.2.0' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | } 22 | } 23 | 24 | task clean(type: Delete) { 25 | delete rootProject.buildDir 26 | } 27 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Nov 01 19:21:29 CST 2019 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-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /screenshots/mine.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/screenshots/mine.webp -------------------------------------------------------------------------------- /screenshots/toutiao.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byhook/tiktok-anim/85ce36d5a6f17ba08502ff6e9cd755284223801d/screenshots/toutiao.webp -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':transition' 2 | -------------------------------------------------------------------------------- /transition/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /transition/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 28 5 | buildToolsVersion "28.0.3" 6 | 7 | 8 | defaultConfig { 9 | minSdkVersion 14 10 | targetSdkVersion 28 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | 25 | } 26 | 27 | dependencies { 28 | implementation fileTree(dir: 'libs', include: ['*.jar']) 29 | implementation 'androidx.appcompat:appcompat:1.0.2' 30 | testImplementation 'junit:junit:4.12' 31 | 32 | } 33 | -------------------------------------------------------------------------------- /transition/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /transition/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /transition/src/main/java/com/onzhou/transition/StatusBarUtils.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.transition; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Color; 5 | import android.os.Build; 6 | import android.view.View; 7 | import android.view.Window; 8 | import android.view.WindowManager; 9 | 10 | /** 11 | * @anchor: andy 12 | * @date: 18-10-16 13 | */ 14 | 15 | public class StatusBarUtils { 16 | 17 | public static void enableStatusBar(Activity activity, boolean enable) { 18 | if (activity != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 19 | Window window = activity.getWindow(); 20 | if (enable) { 21 | window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 22 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 23 | window.setStatusBarColor(Color.TRANSPARENT); 24 | } else { 25 | window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_LAYOUT_FLAGS | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 26 | } 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /transition/src/main/java/com/onzhou/transition/TransitionCallback.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.transition; 2 | 3 | /** 4 | * @anchor: andy 5 | * @date: 18-10-16 6 | */ 7 | 8 | public interface TransitionCallback { 9 | 10 | void onTransitionStop(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /transition/src/main/java/com/onzhou/transition/TransitionController.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.transition; 2 | 3 | import android.animation.Animator; 4 | import android.animation.TimeInterpolator; 5 | import android.os.Build; 6 | import android.view.View; 7 | import android.view.ViewPropertyAnimator; 8 | import android.view.ViewTreeObserver; 9 | 10 | import java.lang.ref.WeakReference; 11 | 12 | /** 13 | * @anchor: andy 14 | * @date: 18-10-16 15 | */ 16 | 17 | public class TransitionController { 18 | 19 | /** 20 | * 动画控件 21 | * 22 | * @param animView 23 | * @return 24 | */ 25 | private View animView; 26 | 27 | /** 28 | * 动画时长 29 | */ 30 | private long duration; 31 | 32 | /** 33 | * 插值器 34 | */ 35 | private TimeInterpolator timeInterpolator; 36 | 37 | /** 38 | * 转场动画参数 39 | */ 40 | private TransitionParam transitionParam; 41 | 42 | /** 43 | * 目标的宽和高 44 | */ 45 | private int targetWidth, targetHeight; 46 | 47 | private ViewPropertyAnimator viewAnimator; 48 | 49 | private TransitionController(View animView, long duration, int targetWidth, int targetHeight, TimeInterpolator timeInterpolator) { 50 | this.animView = animView; 51 | this.duration = duration; 52 | this.targetWidth = targetWidth; 53 | this.targetHeight = targetHeight; 54 | this.timeInterpolator = timeInterpolator; 55 | } 56 | 57 | /** 58 | * 进入和退出的动画 59 | * @param enterAnimation 60 | * @param animatorListener 61 | */ 62 | private void transitionStart(boolean enterAnimation, Animator.AnimatorListener animatorListener) { 63 | //标识我们点击的View在屏幕中可见的高度 64 | int visibleHeight = transitionParam.bottom - transitionParam.top; 65 | 66 | //计算缩放的宽和高起点,需要和外部的控件宽高看起来一致才比较细腻 67 | float scaleXStart = (float) transitionParam.width / targetWidth; 68 | float scaleYStart = (float) transitionParam.height / targetHeight; 69 | 70 | animView.setPivotX(0); 71 | animView.setPivotY(0); 72 | 73 | int startTransX = transitionParam.left; 74 | int startTransY; 75 | if (transitionParam.bottom == targetHeight) { 76 | //滑动到屏幕底部去了,这时候以点击的控件顶部为位移起始点 77 | startTransY = transitionParam.top; 78 | } else if (visibleHeight < transitionParam.height) { 79 | //滑动到屏幕顶部去了 80 | startTransY = transitionParam.bottom - transitionParam.height; 81 | } else { 82 | startTransY = transitionParam.top; 83 | } 84 | 85 | if (enterAnimation) { 86 | //显示动画设置移动的起始位置,关闭动画只指定目标位移位置 87 | animView.setTranslationX(startTransX); 88 | animView.setTranslationY(startTransY); 89 | } 90 | 91 | //设置缩放点 92 | animView.setScaleX(enterAnimation ? scaleXStart : 1.0F); 93 | animView.setScaleY(enterAnimation ? scaleYStart : 1.0F); 94 | 95 | viewAnimator = animView.animate(); 96 | //头条参数 97 | viewAnimator.setInterpolator(timeInterpolator); 98 | animView.setVisibility(View.VISIBLE); 99 | viewAnimator.setDuration(duration) 100 | .setListener(animatorListener) 101 | .scaleX(enterAnimation ? 1.0F : scaleXStart) 102 | .scaleY(enterAnimation ? 1.0F : scaleYStart) 103 | .translationX(enterAnimation ? 0.0F : startTransX) 104 | .translationY(enterAnimation ? 0.0F : startTransY) 105 | .start(); 106 | } 107 | 108 | /** 109 | * 进入的转场动画 110 | * 111 | * @param param 112 | */ 113 | public void transitionEnter(TransitionParam param, final TransitionCallback transitionCallback) { 114 | this.transitionParam = param; 115 | animView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 116 | @Override 117 | public void onGlobalLayout() { 118 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { 119 | animView.getViewTreeObserver().removeOnGlobalLayoutListener(this); 120 | } else { 121 | animView.getViewTreeObserver().removeGlobalOnLayoutListener(this); 122 | } 123 | targetWidth = animView.getMeasuredWidth(); 124 | targetHeight = animView.getMeasuredHeight(); 125 | //开始执行动画 126 | transitionStart(true, new TransitionAnimation(transitionCallback)); 127 | } 128 | }); 129 | } 130 | 131 | /** 132 | * 退出的转场动画 133 | * 134 | * @param transitionCallback 135 | */ 136 | public void transitionExit(TransitionCallback transitionCallback) { 137 | transitionStart(false, new TransitionAnimation(transitionCallback)); 138 | } 139 | 140 | /** 141 | * 释放动画 142 | */ 143 | public void transitionRelease() { 144 | if (viewAnimator != null) { 145 | viewAnimator.setListener(null); 146 | viewAnimator.cancel(); 147 | viewAnimator = null; 148 | } 149 | } 150 | 151 | private static class TransitionAnimation implements Animator.AnimatorListener { 152 | 153 | private WeakReference weakCallback; 154 | 155 | public TransitionAnimation(TransitionCallback transitionCallback) { 156 | weakCallback = new WeakReference<>(transitionCallback); 157 | } 158 | 159 | @Override 160 | public void onAnimationStart(Animator animation) { 161 | 162 | } 163 | 164 | @Override 165 | public void onAnimationEnd(Animator animation) { 166 | TransitionCallback callback = weakCallback.get(); 167 | if (callback != null) { 168 | callback.onTransitionStop(); 169 | } 170 | } 171 | 172 | @Override 173 | public void onAnimationCancel(Animator animation) { 174 | 175 | } 176 | 177 | @Override 178 | public void onAnimationRepeat(Animator animation) { 179 | 180 | } 181 | } 182 | 183 | public static class Builder { 184 | 185 | /** 186 | * 动画控件 187 | * 188 | * @param animView 189 | * @return 190 | */ 191 | private View animView; 192 | 193 | /** 194 | * 动画时长 195 | */ 196 | private long duration; 197 | 198 | /** 199 | * 插值器 200 | */ 201 | private TimeInterpolator timeInterpolator; 202 | 203 | /** 204 | * 目标的宽和高 205 | */ 206 | private int targetWidth, targetHeight; 207 | 208 | public Builder with(View animView) { 209 | this.animView = animView; 210 | return this; 211 | } 212 | 213 | public Builder duration(long duration) { 214 | this.duration = duration; 215 | return this; 216 | } 217 | 218 | public Builder setInterpolator(TimeInterpolator interpolator) { 219 | this.timeInterpolator = interpolator; 220 | return this; 221 | } 222 | 223 | public Builder targetWH(int width, int height) { 224 | this.targetWidth = width; 225 | this.targetHeight = height; 226 | return this; 227 | } 228 | 229 | public TransitionController build() { 230 | return new TransitionController(animView, duration, targetWidth, targetHeight, timeInterpolator); 231 | } 232 | 233 | } 234 | 235 | } 236 | -------------------------------------------------------------------------------- /transition/src/main/java/com/onzhou/transition/TransitionParam.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.transition; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | /** 7 | * @anchor: andy 8 | * @date: 18-10-16 9 | */ 10 | 11 | public class TransitionParam implements Parcelable { 12 | 13 | public int width; 14 | 15 | public int height; 16 | 17 | public int left; 18 | 19 | public int right; 20 | 21 | public int top; 22 | 23 | public int bottom; 24 | 25 | @Override 26 | public int describeContents() { 27 | return 0; 28 | } 29 | 30 | @Override 31 | public void writeToParcel(Parcel dest, int flags) { 32 | dest.writeInt(this.width); 33 | dest.writeInt(this.height); 34 | dest.writeInt(this.left); 35 | dest.writeInt(this.right); 36 | dest.writeInt(this.top); 37 | dest.writeInt(this.bottom); 38 | } 39 | 40 | public TransitionParam() { 41 | } 42 | 43 | protected TransitionParam(Parcel in) { 44 | this.width = in.readInt(); 45 | this.height = in.readInt(); 46 | this.left = in.readInt(); 47 | this.right = in.readInt(); 48 | this.top = in.readInt(); 49 | this.bottom = in.readInt(); 50 | } 51 | 52 | public static final Creator CREATOR = new Creator() { 53 | @Override 54 | public TransitionParam createFromParcel(Parcel source) { 55 | return new TransitionParam(source); 56 | } 57 | 58 | @Override 59 | public TransitionParam[] newArray(int size) { 60 | return new TransitionParam[size]; 61 | } 62 | }; 63 | 64 | } 65 | -------------------------------------------------------------------------------- /transition/src/main/java/com/onzhou/transition/TransitionUtils.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.transition; 2 | 3 | import android.app.Activity; 4 | import android.graphics.Rect; 5 | import android.view.View; 6 | 7 | /** 8 | * @anchor: andy 9 | * @date: 18-10-16 10 | */ 11 | 12 | public class TransitionUtils { 13 | 14 | /** 15 | * 获取源View的数据 16 | * 17 | * @param sourceView 18 | * @return 19 | */ 20 | public static TransitionParam getSourceViewParam(View sourceView) { 21 | if (sourceView == null) { 22 | throw new NullPointerException("source view is null"); 23 | } else { 24 | int width = sourceView.getMeasuredWidth(); 25 | int height = sourceView.getMeasuredHeight(); 26 | if (width > 0 && height > 0) { 27 | //宽高都有效 28 | TransitionParam animBean = new TransitionParam(); 29 | animBean.width = width; 30 | animBean.height = height; 31 | Rect visibleRect = new Rect(); 32 | sourceView.getGlobalVisibleRect(visibleRect); 33 | 34 | animBean.left = visibleRect.left; 35 | animBean.right = visibleRect.right; 36 | animBean.top = visibleRect.top; 37 | animBean.bottom = visibleRect.bottom; 38 | return animBean; 39 | } 40 | } 41 | return null; 42 | } 43 | 44 | 45 | public static void finishTransition(Activity activity) { 46 | if (activity != null) { 47 | activity.overridePendingTransition(R.anim.fade_in, R.anim.fade_out); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /transition/src/main/res/anim/fade_in.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 25 | 26 | -------------------------------------------------------------------------------- /transition/src/main/res/anim/fade_out.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /transition/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #00000000 4 | -------------------------------------------------------------------------------- /transition/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | transition 3 | 4 | -------------------------------------------------------------------------------- /transition/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 13 | 29 | -------------------------------------------------------------------------------- /transition/src/test/java/com/onzhou/okhttp/transition/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.onzhou.okhttp.transition; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } --------------------------------------------------------------------------------