From 8f316c08c666796414775a66925d141e6de6ff22 Mon Sep 17 00:00:00 2001
From: lishilin <869370440@qq.com>
Date: Tue, 26 Mar 2019 11:55:57 +0800
Subject: [PATCH] =?UTF-8?q?1.=E5=9B=BE=E7=89=87=E9=A2=84=E8=A7=88RecyclerV?=
=?UTF-8?q?iew=E5=92=8CPhotoView=E6=BB=91=E5=8A=A8=E5=86=B2=E7=AA=81?=
=?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=9B=202.RecyclerView=E7=9B=91=E5=90=ACo?=
=?UTF-8?q?nScrollStateChanged=E4=B8=8D=E5=9B=9E=E8=B0=83SCROLL=5FSTATE=5F?=
=?UTF-8?q?IDLE=E9=97=AE=E9=A2=98=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../easyphotos/ui/PreviewActivity.java | 40 ++++++-------
.../ui/widget/PreviewRecyclerView.java | 59 +++++++++++++++++++
.../layout/activity_preview_easy_photos.xml | 18 +++---
3 files changed, 86 insertions(+), 31 deletions(-)
create mode 100644 easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/widget/PreviewRecyclerView.java
diff --git a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java
index f5e7548e..5e53158c 100644
--- a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java
+++ b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/PreviewActivity.java
@@ -6,6 +6,7 @@
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.IdRes;
+import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
@@ -264,31 +265,26 @@ private void initRecyclerView() {
snapHelper.attachToRecyclerView(rvPhotos);
rvPhotos.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
- public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
+ public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
- if (newState != RecyclerView.SCROLL_STATE_IDLE) {
+ View view = snapHelper.findSnapView(lm);
+ if (view == null) {
return;
}
- int leftViewPosition = snapHelper.findTargetSnapPosition(lm, 1, rvPhotos.getHeight() / 2);
- int rightViewPosition = snapHelper.findTargetSnapPosition(lm, rvPhotos.getWidth() - 1, rvPhotos.getHeight() / 2);
- if (leftViewPosition == rightViewPosition) {
- if (lastPosition == leftViewPosition - 1) {
- return;
- }
- previewFragment.setSelectedPosition(-1);
- tvNumber.setText(getString(R.string.preview_current_number_easy_photos, leftViewPosition, photos.size()));
- lastPosition = leftViewPosition - 1;
- View view = snapHelper.findSnapView(lm);
- toggleSelector();
- if (null == view) {
- return;
- }
- PreviewPhotosAdapter.PreviewPhotosViewHolder viewHolder = (PreviewPhotosAdapter.PreviewPhotosViewHolder) rvPhotos.getChildViewHolder(view);
- if (viewHolder == null || viewHolder.ivPhoto == null) {
- return;
- }
- if (viewHolder.ivPhoto.getScale() != 1f)
- viewHolder.ivPhoto.setScale(1f, true);
+ int position = lm.getPosition(view);
+ if (lastPosition == position) {
+ return;
+ }
+ lastPosition = position;
+ previewFragment.setSelectedPosition(-1);
+ tvNumber.setText(getString(R.string.preview_current_number_easy_photos, lastPosition + 1, photos.size()));
+ toggleSelector();
+ PreviewPhotosAdapter.PreviewPhotosViewHolder holder = (PreviewPhotosAdapter.PreviewPhotosViewHolder) rvPhotos.getChildViewHolder(view);
+ if (holder == null || holder.ivPhoto == null) {
+ return;
+ }
+ if (holder.ivPhoto.getScale() != 1f) {
+ holder.ivPhoto.setScale(1f, true);
}
}
});
diff --git a/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/widget/PreviewRecyclerView.java b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/widget/PreviewRecyclerView.java
new file mode 100644
index 00000000..1a1b1c8b
--- /dev/null
+++ b/easyPhotos/src/main/java/com/huantansheng/easyphotos/ui/widget/PreviewRecyclerView.java
@@ -0,0 +1,59 @@
+package com.huantansheng.easyphotos.ui.widget;
+
+import android.content.Context;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v7.widget.RecyclerView;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+
+/**
+ * 图片预览 RecyclerView
+ * Create By lishilin On 2019/3/25
+ */
+public class PreviewRecyclerView extends RecyclerView {
+
+ private boolean isLock;// 是否锁住 RecyclerView ,避免和 PhotoView 双指放大缩小操作冲突
+
+ public PreviewRecyclerView(@NonNull Context context) {
+ super(context);
+ }
+
+ public PreviewRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public PreviewRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent event) {
+ switch (event.getActionMasked()) {
+ case MotionEvent.ACTION_POINTER_DOWN:// 非第一个触点按下
+ isLock = true;
+ break;
+ case MotionEvent.ACTION_UP:// 最后一个触点抬起
+ isLock = false;
+ break;
+ }
+ if (isLock) {
+ return false;// 不拦截,交给子View处理
+ }
+ return super.onInterceptTouchEvent(event);
+ }
+
+ @Override
+ public boolean dispatchTouchEvent(MotionEvent event) {
+ switch (event.getActionMasked()) {
+ case MotionEvent.ACTION_POINTER_DOWN:// 非第一个触点按下
+ isLock = true;
+ break;
+ case MotionEvent.ACTION_UP:// 最后一个触点抬起
+ isLock = false;
+ break;
+ }
+ return super.dispatchTouchEvent(event);
+ }
+
+}
diff --git a/easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml b/easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml
index 81e8577a..58359dff 100644
--- a/easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml
+++ b/easyPhotos/src/main/res/layout/activity_preview_easy_photos.xml
@@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:background="@color/easy_photos_bg_primary">
-
@@ -18,9 +18,9 @@
@@ -113,9 +113,9 @@
android:id="@+id/tv_edit"
android:layout_width="wrap_content"
android:layout_height="42dp"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
android:layout_below="@+id/fl_fragment"
+ android:layout_alignParentStart="true"
+ android:layout_alignParentLeft="true"
android:gravity="center"
android:paddingLeft="16dp"
android:paddingRight="16dp"
@@ -141,8 +141,8 @@
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_below="@+id/fl_fragment"
- android:layout_toLeftOf="@+id/iv_selector"
android:layout_toStartOf="@+id/iv_selector"
+ android:layout_toLeftOf="@+id/iv_selector"
android:gravity="center"
android:text="@string/selector_easy_photos"
android:textColor="@color/easy_photos_fg_primary"
@@ -152,13 +152,13 @@
android:id="@+id/iv_selector"
android:layout_width="wrap_content"
android:layout_height="42dp"
+ android:layout_below="@+id/fl_fragment"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
- android:layout_below="@+id/fl_fragment"
- android:paddingEnd="16dp"
+ android:paddingStart="6dp"
android:paddingLeft="6dp"
+ android:paddingEnd="16dp"
android:paddingRight="16dp"
- android:paddingStart="6dp"
app:srcCompat="@drawable/ic_selector_easy_photos" />