From a47b3682db9693dc9388a7cdd0a9bf3f1b148d13 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Mon, 25 Nov 2019 18:54:27 +0800 Subject: [PATCH] feat:fix shaking when drag --- .../java/pub/doric/demo/MainActivity.java | 8 +++++++ .../app/src/main/res/layout/activity_main.xml | 15 ++++++++---- .../pub/doric/pullable/CircleImageView.java | 4 ++-- .../pub/doric/pullable/DoricSwipeLayout.java | 23 ++++++++++++------- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Android/app/src/main/java/pub/doric/demo/MainActivity.java b/Android/app/src/main/java/pub/doric/demo/MainActivity.java index 4eaf9ad9..c472cc8c 100644 --- a/Android/app/src/main/java/pub/doric/demo/MainActivity.java +++ b/Android/app/src/main/java/pub/doric/demo/MainActivity.java @@ -34,6 +34,7 @@ import java.util.List; import pub.doric.DoricActivity; import pub.doric.devkit.ui.DemoDebugActivity; +import pub.doric.pullable.DoricSwipeLayout; import pub.doric.utils.DoricUtils; public class MainActivity extends AppCompatActivity { @@ -43,6 +44,13 @@ public class MainActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + final DoricSwipeLayout swipeLayout = findViewById(R.id.swipe_layout); + swipeLayout.setOnRefreshListener(new DoricSwipeLayout.OnRefreshListener() { + @Override + public void onRefresh() { + swipeLayout.setRefreshing(false); + } + }); RecyclerView recyclerView = findViewById(R.id.root); recyclerView.setLayoutManager(new LinearLayoutManager(this)); try { diff --git a/Android/app/src/main/res/layout/activity_main.xml b/Android/app/src/main/res/layout/activity_main.xml index 4abb9bc3..95619501 100644 --- a/Android/app/src/main/res/layout/activity_main.xml +++ b/Android/app/src/main/res/layout/activity_main.xml @@ -1,8 +1,13 @@ - - \ No newline at end of file + android:layout_height="match_parent"> + + + \ No newline at end of file diff --git a/Android/doric/src/main/java/pub/doric/pullable/CircleImageView.java b/Android/doric/src/main/java/pub/doric/pullable/CircleImageView.java index 70f663dd..b003051b 100644 --- a/Android/doric/src/main/java/pub/doric/pullable/CircleImageView.java +++ b/Android/doric/src/main/java/pub/doric/pullable/CircleImageView.java @@ -26,8 +26,8 @@ import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.shapes.OvalShape; import android.view.View; import android.view.animation.Animation; -import android.widget.ImageView; +import androidx.appcompat.widget.AppCompatImageView; import androidx.core.content.ContextCompat; import androidx.core.view.ViewCompat; @@ -36,7 +36,7 @@ import androidx.core.view.ViewCompat; * called before the animation is actually complete and support shadows on older * platforms. */ -class CircleImageView extends ImageView { +class CircleImageView extends AppCompatImageView { private static final int KEY_SHADOW_COLOR = 0x1E000000; private static final int FILL_SHADOW_COLOR = 0x3D000000; diff --git a/Android/doric/src/main/java/pub/doric/pullable/DoricSwipeLayout.java b/Android/doric/src/main/java/pub/doric/pullable/DoricSwipeLayout.java index d128dc6e..3a1d9245 100644 --- a/Android/doric/src/main/java/pub/doric/pullable/DoricSwipeLayout.java +++ b/Android/doric/src/main/java/pub/doric/pullable/DoricSwipeLayout.java @@ -51,7 +51,7 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent @VisibleForTesting static final int CIRCLE_DIAMETER_LARGE = 56; - private static final String LOG_TAG = androidx.swiperefreshlayout.widget.SwipeRefreshLayout.class.getSimpleName(); + private static final String LOG_TAG = DoricSwipeLayout.class.getSimpleName(); private static final int MAX_ALPHA = 255; private static final int STARTING_PROGRESS_ALPHA = (int) (.3f * MAX_ALPHA); @@ -587,16 +587,19 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent if (mTarget == null) { return; } + + int circleWidth = mCircleView.getMeasuredWidth(); + int circleHeight = mCircleView.getMeasuredHeight(); + + mCircleView.layout((width / 2 - circleWidth / 2), mCurrentTargetOffsetTop, + (width / 2 + circleWidth / 2), mCurrentTargetOffsetTop + circleHeight); + final View child = mTarget; final int childLeft = getPaddingLeft(); - final int childTop = getPaddingTop(); + final int childTop = getPaddingTop() + mCircleView.getBottom(); final int childWidth = width - getPaddingLeft() - getPaddingRight(); final int childHeight = height - getPaddingTop() - getPaddingBottom(); child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); - int circleWidth = mCircleView.getMeasuredWidth(); - int circleHeight = mCircleView.getMeasuredHeight(); - mCircleView.layout((width / 2 - circleWidth / 2), mCurrentTargetOffsetTop, - (width / 2 + circleWidth / 2), mCurrentTargetOffsetTop + circleHeight); } @Override @@ -756,8 +759,10 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent consumed[1] = dy - (int) mTotalUnconsumed; mTotalUnconsumed = 0; } else { - mTotalUnconsumed -= dy; - consumed[1] = dy; + if (dy > 3) { + mTotalUnconsumed -= dy; + consumed[1] = dy; + } } moveSpinner(mTotalUnconsumed); } @@ -1179,4 +1184,6 @@ public class DoricSwipeLayout extends ViewGroup implements NestedScrollingParent */ boolean canChildScrollUp(@NonNull DoricSwipeLayout parent, @Nullable View child); } + + } \ No newline at end of file