From df7c0cef194ab9e1a68326ebf42dcaf3a8bf7d82 Mon Sep 17 00:00:00 2001 From: Liberation Date: Sun, 22 Dec 2019 16:02:30 +0800 Subject: [PATCH 01/27] add a sample --- app/src/main/AndroidManifest.xml | 11 ++- .../java/cn/jzvd/demo/ActivityListView.java | 4 + .../cn/jzvd/demo/ActivityListViewDetail.java | 66 ++++++++++++++ .../jzvd/demo/ActivityListViewToDetail.java | 80 +++++++++++++++++ .../jzvd/demo/AdapterSmoothRecyclerView.java | 90 +++++++++++++++++++ .../cn/jzvd/demo/CustomJzvd/JzvdStdRv.java | 38 ++++++++ app/src/main/res/layout/activity_listview.xml | 7 ++ .../res/layout/activity_listview_detail.xml | 12 +++ .../main/res/layout/item_smooth_videoview.xml | 19 ++++ app/src/main/res/values/styles.xml | 4 + 10 files changed, 329 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/cn/jzvd/demo/ActivityListViewDetail.java create mode 100644 app/src/main/java/cn/jzvd/demo/ActivityListViewToDetail.java create mode 100644 app/src/main/java/cn/jzvd/demo/AdapterSmoothRecyclerView.java create mode 100644 app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdRv.java create mode 100644 app/src/main/res/layout/activity_listview_detail.xml create mode 100644 app/src/main/res/layout/item_smooth_videoview.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5e98964d..eb914847 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -98,8 +98,15 @@ - - + + diff --git a/app/src/main/java/cn/jzvd/demo/ActivityListView.java b/app/src/main/java/cn/jzvd/demo/ActivityListView.java index 88fec00a..740a9feb 100644 --- a/app/src/main/java/cn/jzvd/demo/ActivityListView.java +++ b/app/src/main/java/cn/jzvd/demo/ActivityListView.java @@ -51,4 +51,8 @@ public void clickMultiHolder(View view) { public void clickRecyclerView(View view) { startActivity(new Intent(ActivityListView.this, ActivityListViewRecyclerView.class)); } + + public void clickListSmoothToDetail(View view) { + startActivity(new Intent(ActivityListView.this, ActivityListViewToDetail.class)); + } } diff --git a/app/src/main/java/cn/jzvd/demo/ActivityListViewDetail.java b/app/src/main/java/cn/jzvd/demo/ActivityListViewDetail.java new file mode 100644 index 00000000..3d354db8 --- /dev/null +++ b/app/src/main/java/cn/jzvd/demo/ActivityListViewDetail.java @@ -0,0 +1,66 @@ +package cn.jzvd.demo; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.MenuItem; +import android.view.ViewGroup; +import android.view.ViewParent; +import android.view.ViewTreeObserver; +import android.widget.FrameLayout; +import android.widget.TextView; + +import cn.jzvd.Jzvd; +import cn.jzvd.demo.CustomJzvd.JzvdStdRv; + +/** + * 列表平滑进入详情页 + */ +public class ActivityListViewDetail extends AppCompatActivity { + private FrameLayout container; + private static final String TAG = "ActivityListViewDetail"; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + getSupportActionBar().setDisplayShowTitleEnabled(true); + getSupportActionBar().setDisplayUseLogoEnabled(false); + getSupportActionBar().setTitle("ActivityListViewDetail"); + setContentView(R.layout.activity_listview_detail); + container = findViewById(R.id.surface_container); + ViewParent parent = JzvdStdRv.CURRENT_JZVD.getParent(); + if (parent != null) { + ((ViewGroup) parent).removeAllViews(); + } + FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + container.addView(JzvdStdRv.CURRENT_JZVD,params); + } + + @Override + public void onBackPressed() { + if (Jzvd.backPress()) { + return; + } + super.onBackPressed(); + } + + @Override + public void supportFinishAfterTransition() { + super.supportFinishAfterTransition(); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + supportFinishAfterTransition(); + break; + } + return super.onOptionsItemSelected(item); + } + +} diff --git a/app/src/main/java/cn/jzvd/demo/ActivityListViewToDetail.java b/app/src/main/java/cn/jzvd/demo/ActivityListViewToDetail.java new file mode 100644 index 00000000..9bac0254 --- /dev/null +++ b/app/src/main/java/cn/jzvd/demo/ActivityListViewToDetail.java @@ -0,0 +1,80 @@ +package cn.jzvd.demo; + +import android.annotation.TargetApi; +import android.graphics.Matrix; +import android.graphics.RectF; +import android.os.Build; +import android.os.Bundle; +import android.os.Parcelable; +import android.support.annotation.Nullable; +import android.support.v4.app.SharedElementCallback; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.MenuItem; +import android.view.View; + +import cn.jzvd.Jzvd; + +/** + * 列表平滑进入详情页 + */ +public class ActivityListViewToDetail extends AppCompatActivity { + RecyclerView recyclerView; + AdapterSmoothRecyclerView adapterVideoList; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + getSupportActionBar().setDisplayShowTitleEnabled(true); + getSupportActionBar().setDisplayUseLogoEnabled(false); + getSupportActionBar().setTitle("ActivityListViewToDetail"); + setContentView(R.layout.activity_recyclerview_content); + + recyclerView = findViewById(R.id.recyclerview); + recyclerView.setLayoutManager(new LinearLayoutManager(this)); + adapterVideoList = new AdapterSmoothRecyclerView(this); + recyclerView.setAdapter(adapterVideoList); + setExitSharedElementCallback(new TransitionCallBack() { + }); + } + + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public class TransitionCallBack extends SharedElementCallback { + + @Override + public Parcelable onCaptureSharedElementSnapshot(View sharedElement, Matrix viewToGlobalMatrix, RectF screenBounds) { + sharedElement.setAlpha(1); + return super.onCaptureSharedElementSnapshot(sharedElement, viewToGlobalMatrix, screenBounds); + } + } + + + @Override + public void onBackPressed() { + if (Jzvd.backPress()) { + return; + } + super.onBackPressed(); + } + + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + break; + } + return super.onOptionsItemSelected(item); + } + + @Override + protected void onResume() { + super.onResume(); + adapterVideoList.notifyDataSetChanged(); + } +} diff --git a/app/src/main/java/cn/jzvd/demo/AdapterSmoothRecyclerView.java b/app/src/main/java/cn/jzvd/demo/AdapterSmoothRecyclerView.java new file mode 100644 index 00000000..8103013f --- /dev/null +++ b/app/src/main/java/cn/jzvd/demo/AdapterSmoothRecyclerView.java @@ -0,0 +1,90 @@ +package cn.jzvd.demo; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.support.v4.app.ActivityCompat; +import android.support.v4.app.ActivityOptionsCompat; +import android.support.v4.view.ViewCompat; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; +import android.widget.FrameLayout; + +import com.bumptech.glide.Glide; + +import cn.jzvd.Jzvd; +import cn.jzvd.demo.CustomJzvd.JzvdStdRv; + +public class AdapterSmoothRecyclerView extends RecyclerView.Adapter { + + public static final String TAG = "AdapterSmoothRecyclerView"; + int[] videoIndexs = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + private Context context; + + public AdapterSmoothRecyclerView(Context context) { + this.context = context; + } + + @Override + public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + MyViewHolder holder = new MyViewHolder(LayoutInflater.from( + context).inflate(R.layout.item_smooth_videoview, parent, + false)); + return holder; + } + + @SuppressLint("LongLogTag") + @Override + public void onBindViewHolder(MyViewHolder holder, int position) { + Log.i(TAG, "onBindViewHolder [" + holder.jzvdStd.hashCode() + "] position=" + position); + + holder.jzvdStd.setClickUi(new JzvdStdRv.ClickUi() { + @Override + public void onClickUiToggle() { + JzvdStdRv.setCurrentJzvd(holder.jzvdStd); + ViewCompat.setTransitionName(holder.container, "videoView"); + Activity activity = (Activity) holder.itemView.getContext(); + Intent intent = new Intent(activity, ActivityListViewDetail.class); + // 这里指定了共享的视图元素 + ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(activity, holder.container, "videoView"); + ActivityCompat.startActivity(activity, intent, options.toBundle()); + holder.jzvdStd.setClickUi(null); + } + }); + if (holder.container.getChildCount() == 0) { + ViewParent parent = JzvdStdRv.CURRENT_JZVD.getParent(); + if (parent != null) { + ((ViewGroup) parent).removeView(JzvdStdRv.CURRENT_JZVD); + } + holder.container.addView(JzvdStdRv.CURRENT_JZVD, new FrameLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + }else { + holder.jzvdStd.setUp( + VideoConstant.videoUrls[0][position], + VideoConstant.videoTitles[0][position], Jzvd.SCREEN_NORMAL); + Glide.with(holder.jzvdStd.getContext()).load(VideoConstant.videoThumbs[0][position]).into(holder.jzvdStd.thumbImageView); + } + } + + @Override + public int getItemCount() { + return videoIndexs.length; + } + + class MyViewHolder extends RecyclerView.ViewHolder { + JzvdStdRv jzvdStd; + FrameLayout container; + + public MyViewHolder(View itemView) { + super(itemView); + jzvdStd = itemView.findViewById(R.id.videoplayer); + container = itemView.findViewById(R.id.surface_container); + } + } + +} diff --git a/app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdRv.java b/app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdRv.java new file mode 100644 index 00000000..b555576b --- /dev/null +++ b/app/src/main/java/cn/jzvd/demo/CustomJzvd/JzvdStdRv.java @@ -0,0 +1,38 @@ +package cn.jzvd.demo.CustomJzvd; + +import android.content.Context; +import android.util.AttributeSet; +import android.util.Log; +import android.view.View; + +import cn.jzvd.JzvdStd; + +public class JzvdStdRv extends JzvdStd { + private ClickUi clickUi; + + public void setClickUi(ClickUi clickUi) { + this.clickUi = clickUi; + } + + public JzvdStdRv(Context context) { + super(context); + } + + public JzvdStdRv(Context context, AttributeSet attrs) { + super(context, attrs); + } + + + @Override + public void onClickUiToggle() { + bottomContainer.setVisibility(View.GONE); + super.onClickUiToggle(); + Log.d(TAG, "onClickUiToggle: "); + if (clickUi != null) clickUi.onClickUiToggle(); + } + + public interface ClickUi { + void onClickUiToggle(); + } + +} diff --git a/app/src/main/res/layout/activity_listview.xml b/app/src/main/res/layout/activity_listview.xml index 2c2ce802..5f43d8de 100644 --- a/app/src/main/res/layout/activity_listview.xml +++ b/app/src/main/res/layout/activity_listview.xml @@ -36,4 +36,11 @@ android:layout_gravity="center_horizontal" android:onClick="clickRecyclerView" android:text="Recyleview" /> + +