Repository: PangHaHa12138/DouyinDemo
Branch: master
Commit: b17ae5612c22
Files: 45
Total size: 34.0 MB
Directory structure:
gitextract_zj5sevr6/
├── .gitignore
├── .idea/
│ ├── caches/
│ │ └── build_file_checksums.ser
│ ├── codeStyles/
│ │ └── Project.xml
│ ├── gradle.xml
│ ├── misc.xml
│ ├── runConfigurations.xml
│ └── vcs.xml
├── README.md
├── app/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src/
│ ├── androidTest/
│ │ └── java/
│ │ └── com/
│ │ └── example/
│ │ └── administrator/
│ │ └── douyin/
│ │ └── ExampleInstrumentedTest.java
│ ├── main/
│ │ ├── AndroidManifest.xml
│ │ ├── java/
│ │ │ └── com/
│ │ │ └── example/
│ │ │ └── administrator/
│ │ │ └── douyin/
│ │ │ ├── FullWindowVideoView.java
│ │ │ ├── Love.java
│ │ │ ├── Love2.kt
│ │ │ ├── MainActivity.java
│ │ │ ├── MyLayoutManager.java
│ │ │ ├── MyLayoutManager2.kt
│ │ │ └── OnViewPagerListener.java
│ │ └── res/
│ │ ├── drawable/
│ │ │ ├── circle_big_red.xml
│ │ │ ├── circle_red.xml
│ │ │ ├── cirque_gray.xml
│ │ │ ├── echelon_bg.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ └── play_arrow.xml
│ │ ├── drawable-v24/
│ │ │ └── ic_launcher_foreground.xml
│ │ ├── layout/
│ │ │ ├── activity_main.xml
│ │ │ └── item_view_pager.xml
│ │ ├── mipmap-anydpi-v26/
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── values/
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── values-v19/
│ │ │ └── styles.xml
│ │ └── values-v21/
│ │ └── styles.xml
│ └── test/
│ └── java/
│ └── com/
│ └── example/
│ └── administrator/
│ └── douyin/
│ └── ExampleUnitTest.java
├── app-debug.apk
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
================================================
FILE: .idea/codeStyles/Project.xml
================================================
================================================
FILE: .idea/gradle.xml
================================================
================================================
FILE: .idea/misc.xml
================================================
================================================
FILE: .idea/runConfigurations.xml
================================================
================================================
FILE: .idea/vcs.xml
================================================
================================================
FILE: README.md
================================================
# DouyinDemo
仿抖音上下滑动播放视频demo
###
效果图
###

###

###

================================================
FILE: app/.gitignore
================================================
/build
================================================
FILE: app/build.gradle
================================================
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.example.administrator.douyin"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:recyclerview-v7:27+'
/*第三方库*/
implementation 'de.hdodenhof:circleimageview:2.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}
================================================
FILE: app/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: app/src/androidTest/java/com/example/administrator/douyin/ExampleInstrumentedTest.java
================================================
package com.example.administrator.douyin;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see Testing documentation
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.example.administrator.douyin", appContext.getPackageName());
}
}
================================================
FILE: app/src/main/AndroidManifest.xml
================================================
================================================
FILE: app/src/main/java/com/example/administrator/douyin/FullWindowVideoView.java
================================================
package com.example.administrator.douyin;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;
public class FullWindowVideoView extends VideoView {
public FullWindowVideoView(Context context) {
super(context);
}
public FullWindowVideoView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public FullWindowVideoView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// 其实就是在这里做了一些处理。
int width = getDefaultSize(0, widthMeasureSpec);
int height = getDefaultSize(0, heightMeasureSpec);
setMeasuredDimension(width, height);
}
}
================================================
FILE: app/src/main/java/com/example/administrator/douyin/Love.java
================================================
package com.example.administrator.douyin;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.content.Context;
import android.graphics.Canvas;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import java.util.Random;
public class Love extends RelativeLayout {
private Context mContext;
float[] num = {-30, -20, 0, 20, 30};//随机心形图片角度
public Love(Context context) {
super(context);
initView(context);
}
public Love(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initView(context);
}
public Love(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context);
}
private void initView(Context context) {
mContext = context;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
final ImageView imageView = new ImageView(mContext);
LayoutParams params = new LayoutParams(300, 300);
params.leftMargin = (int) event.getX() - 150;
params.topMargin = (int) event.getY() - 300;
imageView.setImageDrawable(getResources().getDrawable(R.mipmap.icon_home_like_after));
imageView.setLayoutParams(params);
addView(imageView);
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(scale(imageView, "scaleX", 2f, 0.9f, 100, 0))
.with(scale(imageView, "scaleY", 2f, 0.9f, 100, 0))
.with(rotation(imageView, 0, 0, num[new Random().nextInt(4)]))
.with(alpha(imageView, 0, 1, 100, 0))
.with(scale(imageView, "scaleX", 0.9f, 1, 50, 150))
.with(scale(imageView, "scaleY", 0.9f, 1, 50, 150))
.with(translationY(imageView, 0, -600, 800, 400))
.with(alpha(imageView, 1, 0, 300, 400))
.with(scale(imageView, "scaleX", 1, 3f, 700, 400))
.with(scale(imageView, "scaleY", 1, 3f, 700, 400));
animatorSet.start();
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
removeViewInLayout(imageView);
}
});
return super.onTouchEvent(event);
}
public static ObjectAnimator scale(View view, String propertyName, float from, float to, long time, long delayTime) {
ObjectAnimator translation = ObjectAnimator.ofFloat(view
, propertyName
, from, to);
translation.setInterpolator(new LinearInterpolator());
translation.setStartDelay(delayTime);
translation.setDuration(time);
return translation;
}
public static ObjectAnimator translationX(View view, float from, float to, long time, long delayTime) {
ObjectAnimator translation = ObjectAnimator.ofFloat(view
, "translationX"
, from, to);
translation.setInterpolator(new LinearInterpolator());
translation.setStartDelay(delayTime);
translation.setDuration(time);
return translation;
}
public static ObjectAnimator translationY(View view, float from, float to, long time, long delayTime) {
ObjectAnimator translation = ObjectAnimator.ofFloat(view
, "translationY"
, from, to);
translation.setInterpolator(new LinearInterpolator());
translation.setStartDelay(delayTime);
translation.setDuration(time);
return translation;
}
public static ObjectAnimator alpha(View view, float from, float to, long time, long delayTime) {
ObjectAnimator translation = ObjectAnimator.ofFloat(view
, "alpha"
, from, to);
translation.setInterpolator(new LinearInterpolator());
translation.setStartDelay(delayTime);
translation.setDuration(time);
return translation;
}
public static ObjectAnimator rotation(View view, long time, long delayTime, float... values) {
ObjectAnimator rotation = ObjectAnimator.ofFloat(view, "rotation", values);
rotation.setDuration(time);
rotation.setStartDelay(delayTime);
rotation.setInterpolator(new TimeInterpolator() {
@Override
public float getInterpolation(float input) {
return input;
}
});
return rotation;
}
}
================================================
FILE: app/src/main/java/com/example/administrator/douyin/Love2.kt
================================================
package com.example.administrator.douyin
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.animation.TimeInterpolator
import android.content.Context
import android.os.SystemClock
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import android.widget.RelativeLayout
import java.util.*
/**
* information:仿抖音点赞功能
*/
class Love2(context: Context) : RelativeLayout(context) {
var mContext: Context? = null
//动画中随机❤的旋转角度
var num = floatArrayOf(-35f, -25f, 0f, 25f, 35f)
//用来判断是否是连续的点击事件
private val mHits = LongArray(3)
constructor(context: Context, attrs: AttributeSet) : this(context) {
mContext = context
}
override fun onTouchEvent(event: MotionEvent?): Boolean {
System.arraycopy(mHits, 1, mHits, 0, mHits.size - 1)
mHits[mHits.size - 1] = SystemClock.uptimeMillis()
//用这个来判断是否是3击事件,判断数组中pos=2的点击事件的时间与数组中pos=0的点击事件的时间差值是否小于500,若是小于500认为是3击事件,这时需要绘制爱心图片
if (mHits[0] >= (SystemClock.uptimeMillis() - 500)) {
//点击是触发心形的图片add到整个view中,然后执行动画
//有连续触摸的时候,创建一个展示心形的图片
var iv: ImageView = ImageView(mContext)
//设置展示的位置,需要在手指触摸的位置上方,即触摸点是心形的右下角的位置
var lp: LayoutParams = LayoutParams(300, 300)
lp.leftMargin = (event?.x!! - 150F).toInt()
lp.topMargin = (event?.y!! - 300F).toInt()
//设置图片资源
iv.setImageDrawable(resources.getDrawable(R.mipmap.icon_home_like_after))
iv.layoutParams = lp
//把IV添加到父布局当中
addView(iv)
//设置控件的动画
var animatorSet: AnimatorSet = AnimatorSet()
animatorSet.play(
//缩放动画,X轴2倍缩小至0.9倍
scaleAni(iv, "scaleX", 2f, 0.9f, 100, 0))
//缩放动画,Y轴2倍缩放至0.9倍
.with(scaleAni(iv, "scaleY", 2f, 0.9f, 100, 0))
//旋转动画,随机旋转角
.with(rotation(iv, 0, 0, num[Random().nextInt(4)]))
//渐变透明动画,透明度从0-1
.with(alphaAni(iv, 0F, 1F, 100, 0))
//缩放动画,X轴0.9倍缩小至
.with(scaleAni(iv, "scaleX", 0.9f, 1F, 50, 150))
//缩放动画,Y轴0.9倍缩放至
.with(scaleAni(iv, "scaleY", 0.9f, 1F, 50, 150))
//位移动画,Y轴从0上移至600
.with(translationY(iv, 0F, -600F, 800, 400))
//透明动画,从1-0
.with(alphaAni(iv, 1F, 0F, 300, 400))
//缩放动画,X轴1至3倍
.with(scaleAni(iv, "scaleX", 1F, 3f, 700, 400))
//缩放动画,Y轴1至3倍
.with(scaleAni(iv, "scaleY", 1F, 3f, 700, 400))
//开始动画
animatorSet.start()
//设置动画结束监听
animatorSet.addListener(object : AnimatorListenerAdapter() {
override fun onAnimationEnd(animation: Animator?) {
super.onAnimationEnd(animation)
//当动画结束以后,需要把控件从父布局移除
removeViewInLayout(iv)
}
})
}
return super.onTouchEvent(event)
}
fun scaleAni(view: View, propertyName: String, from: Float, to: Float, time: Long, delayTime: Long): ObjectAnimator {
val ani: ObjectAnimator = ObjectAnimator.ofFloat(view, propertyName, from, to)
ani.interpolator = LinearInterpolator()
ani.startDelay = delayTime
ani.duration = time
return ani
}
fun translationX(view: View, from: Float, to: Float, time: Long, delayTime: Long): ObjectAnimator {
val ani: ObjectAnimator = ObjectAnimator.ofFloat(view, "translationX", from, to)
ani.interpolator = LinearInterpolator()
ani.startDelay = delayTime
ani.duration = time
return ani
}
fun translationY(view: View, from: Float, to: Float, time: Long, delayTime: Long): ObjectAnimator {
val ani: ObjectAnimator = ObjectAnimator.ofFloat(view, "translationY", from, to)
ani.interpolator = LinearInterpolator()
ani.startDelay = delayTime
ani.duration = time
return ani
}
fun alphaAni(view: View, from: Float, to: Float, time: Long, delayTime: Long): ObjectAnimator {
val ani = ObjectAnimator.ofFloat(view, "alpha", from, to)
ani.interpolator = LinearInterpolator()
ani.startDelay = delayTime
ani.duration = time
return ani
}
fun rotation(view: View, time: Long, delayTime: Long, vararg values: Float): ObjectAnimator {
val ani = ObjectAnimator.ofFloat(view, "rotation", *values)
ani.duration = time
ani.startDelay = delayTime
ani.interpolator = TimeInterpolator { input -> input }
return ani
}
}
================================================
FILE: app/src/main/java/com/example/administrator/douyin/MainActivity.java
================================================
package com.example.administrator.douyin;
import android.annotation.TargetApi;
import android.content.Context;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.VideoView;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "douyin";
private RecyclerView mRecyclerView;
private MyAdapter mAdapter;
MyLayoutManager2 myLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initListener();
}
private void initView() {
mRecyclerView = findViewById(R.id.recycler);
myLayoutManager = new MyLayoutManager2(this, OrientationHelper.VERTICAL, false);
mAdapter = new MyAdapter(this);
mRecyclerView.setLayoutManager(myLayoutManager);
mRecyclerView.setAdapter(mAdapter);
}
private void initListener() {
myLayoutManager.setOnViewPagerListener(new OnViewPagerListener() {
@Override
public void onInitComplete() {
}
@Override
public void onPageRelease(boolean isNext, int position) {
Log.e(TAG, "释放位置:" + position + " 下一页:" + isNext);
int index = 0;
if (isNext) {
index = 0;
} else {
index = 1;
}
releaseVideo(index);
}
@Override
public void onPageSelected(int position, boolean bottom) {
Log.e(TAG, "选择位置:" + position + " 下一页:" + bottom);
playVideo(0);
}
});
}
class MyAdapter extends RecyclerView.Adapter {
private int[] imgs = {R.mipmap.img_video_1, R.mipmap.img_video_2, R.mipmap.img_video_3, R.mipmap.img_video_4, R.mipmap.img_video_5, R.mipmap.img_video_6, R.mipmap.img_video_7, R.mipmap.img_video_8};
private int[] videos = {R.raw.video_1, R.raw.video_2, R.raw.video_3, R.raw.video_4, R.raw.video_5, R.raw.video_6, R.raw.video_7, R.raw.video_8};
private int index = 0;
private Context mContext;
public MyAdapter(Context context) {
this.mContext = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_view_pager, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.img_thumb.setImageResource(imgs[index]);
holder.videoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + videos[index]));
index++;
if (index >= 7) {
index = 0;
}
}
@Override
public int getItemCount() {
return 88;
}
public class ViewHolder extends RecyclerView.ViewHolder {
ImageView img_thumb;
VideoView videoView;
ImageView img_play;
RelativeLayout rootView;
public ViewHolder(View itemView) {
super(itemView);
img_thumb = itemView.findViewById(R.id.img_thumb);
videoView = itemView.findViewById(R.id.video_view);
img_play = itemView.findViewById(R.id.img_play);
rootView = itemView.findViewById(R.id.root_view);
}
}
}
private void releaseVideo(int index) {
View itemView = mRecyclerView.getChildAt(index);
final VideoView videoView = itemView.findViewById(R.id.video_view);
final ImageView imgThumb = itemView.findViewById(R.id.img_thumb);
final ImageView imgPlay = itemView.findViewById(R.id.img_play);
videoView.stopPlayback();
imgThumb.animate().alpha(1).start();
imgPlay.animate().alpha(0f).start();
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void playVideo(int position) {
View itemView = mRecyclerView.getChildAt(position);
final FullWindowVideoView videoView = itemView.findViewById(R.id.video_view);
final ImageView imgPlay = itemView.findViewById(R.id.img_play);
final ImageView imgThumb = itemView.findViewById(R.id.img_thumb);
final RelativeLayout rootView = itemView.findViewById(R.id.root_view);
final MediaPlayer[] mediaPlayer = new MediaPlayer[1];
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
}
});
videoView.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
mediaPlayer[0] = mp;
mp.setLooping(true);
imgThumb.animate().alpha(0).setDuration(200).start();
return false;
}
});
videoView.start();
imgPlay.setOnClickListener(new View.OnClickListener() {
boolean isPlaying = true;
@Override
public void onClick(View v) {
if (videoView.isPlaying()) {
imgPlay.animate().alpha(0.7f).start();
videoView.pause();
isPlaying = false;
} else {
imgPlay.animate().alpha(0f).start();
videoView.start();
isPlaying = true;
}
}
});
}
}
================================================
FILE: app/src/main/java/com/example/administrator/douyin/MyLayoutManager.java
================================================
package com.example.administrator.douyin;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PagerSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
public class MyLayoutManager extends LinearLayoutManager implements RecyclerView.OnChildAttachStateChangeListener {
private int mDrift;//位移,用来判断移动方向
private PagerSnapHelper mPagerSnapHelper;
private OnViewPagerListener mOnViewPagerListener;
public MyLayoutManager(Context context) {
super(context);
}
public MyLayoutManager(Context context, int orientation, boolean reverseLayout) {
super(context, orientation, reverseLayout);
mPagerSnapHelper = new PagerSnapHelper();
}
@Override
public void onAttachedToWindow(RecyclerView view) {
view.addOnChildAttachStateChangeListener(this);
mPagerSnapHelper.attachToRecyclerView(view);
super.onAttachedToWindow(view);
}
//当Item添加进来了 调用这个方法
//
@Override
public void onChildViewAttachedToWindow(@NonNull View view) {
// 播放视频操作 即将要播放的是上一个视频 还是下一个视频
int position = getPosition(view);
if (0 == position) {
if (mOnViewPagerListener != null) {
mOnViewPagerListener.onPageSelected(getPosition(view), false);
}
}
}
public void setOnViewPagerListener(OnViewPagerListener mOnViewPagerListener) {
this.mOnViewPagerListener = mOnViewPagerListener;
}
@Override
public void onScrollStateChanged(int state) {
switch (state) {
case RecyclerView.SCROLL_STATE_IDLE:
View view = mPagerSnapHelper.findSnapView(this);
int position = getPosition(view);
if (mOnViewPagerListener != null) {
mOnViewPagerListener.onPageSelected(position, position == getItemCount() - 1);
}
// postion ---回调 ----》播放
break;
}
super.onScrollStateChanged(state);
}
@Override
public void onChildViewDetachedFromWindow(@NonNull View view) {
//暂停播放操作
if (mDrift >= 0) {
if (mOnViewPagerListener != null)
mOnViewPagerListener.onPageRelease(true, getPosition(view));
} else {
if (mOnViewPagerListener != null)
mOnViewPagerListener.onPageRelease(false, getPosition(view));
}
}
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
this.mDrift = dy;
return super.scrollVerticallyBy(dy, recycler, state);
}
@Override
public boolean canScrollVertically() {
return true;
}
}
================================================
FILE: app/src/main/java/com/example/administrator/douyin/MyLayoutManager2.kt
================================================
package com.example.administrator.douyin
import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.PagerSnapHelper
import android.support.v7.widget.RecyclerView
import android.view.View
/**
* @desc
* @auth ${user}
* @time 2018/8/9 15:38
*/
class MyLayoutManager2 : LinearLayoutManager, RecyclerView.OnChildAttachStateChangeListener {
constructor(context: Context) : super(context)
constructor(context: Context, @RecyclerView.Orientation orientation: Int,
reverseLayout: Boolean) : super(context, orientation, reverseLayout) {
pagerSpaner = PagerSnapHelper()
}
var pagerSpaner: PagerSnapHelper? = null
var viewPagerListener: OnViewPagerListener? = null
var diffY = 0
override fun onAttachedToWindow(view: RecyclerView) {
super.onAttachedToWindow(view)
view.addOnChildAttachStateChangeListener(this)
pagerSpaner!!.attachToRecyclerView(view)
}
override fun onChildViewDetachedFromWindow(view: View?) {
val position = getPosition(view)
if (0 < diffY) {
viewPagerListener?.onPageRelease(true, position)
} else {
viewPagerListener?.onPageRelease(false, position)
}
}
override fun onChildViewAttachedToWindow(view: View?) {
val position = getPosition(view)
if (0 == position) {
viewPagerListener?.onPageSelected(position, false)
}
}
override fun onScrollStateChanged(state: Int) {
if (RecyclerView.SCROLL_STATE_IDLE == state) {
val view = pagerSpaner!!.findSnapView(this)
val position = getPosition(view)
viewPagerListener?.onPageSelected(position, position == itemCount - 1)
}
super.onScrollStateChanged(state)
}
public fun setOnViewPagerListener(listener: OnViewPagerListener) {
viewPagerListener = listener
}
override fun scrollVerticallyBy(dy: Int, recycler: RecyclerView.Recycler?, state: RecyclerView.State?): Int {
diffY = dy
return super.scrollVerticallyBy(dy, recycler, state)
}
}
================================================
FILE: app/src/main/java/com/example/administrator/douyin/OnViewPagerListener.java
================================================
package com.example.administrator.douyin;
public interface OnViewPagerListener {
/*初始化完成*/
void onInitComplete();
/*释放的监听*/
void onPageRelease(boolean isNext, int position);
/*选中的监听以及判断是否滑动到底部*/
void onPageSelected(int position, boolean isBottom);
}
================================================
FILE: app/src/main/res/drawable/circle_big_red.xml
================================================
================================================
FILE: app/src/main/res/drawable/circle_red.xml
================================================
================================================
FILE: app/src/main/res/drawable/cirque_gray.xml
================================================
================================================
FILE: app/src/main/res/drawable/echelon_bg.xml
================================================
================================================
FILE: app/src/main/res/drawable/ic_launcher_background.xml
================================================
================================================
FILE: app/src/main/res/drawable/play_arrow.xml
================================================
================================================
FILE: app/src/main/res/drawable-v24/ic_launcher_foreground.xml
================================================
================================================
FILE: app/src/main/res/layout/activity_main.xml
================================================
================================================
FILE: app/src/main/res/layout/item_view_pager.xml
================================================
================================================
FILE: app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
================================================
================================================
FILE: app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
================================================
================================================
FILE: app/src/main/res/values/colors.xml
================================================
#3F51B5
#303F9F
#FF4081
================================================
FILE: app/src/main/res/values/strings.xml
================================================
仿抖音1
================================================
FILE: app/src/main/res/values/styles.xml
================================================
================================================
FILE: app/src/main/res/values-v19/styles.xml
================================================
================================================
FILE: app/src/main/res/values-v21/styles.xml
================================================
================================================
FILE: app/src/test/java/com/example/administrator/douyin/ExampleUnitTest.java
================================================
package com.example.administrator.douyin;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see Testing documentation
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
================================================
FILE: app-debug.apk
================================================
[File too large to display: 34.0 MB]
================================================
FILE: build.gradle
================================================
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.60'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Wed Aug 08 20:04:27 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: settings.gradle
================================================
include ':app'