From f34c95606f69e6a2e65af3f95ed71d845d3b43e1 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Fri, 27 Feb 2015 13:39:29 +0100 Subject: [PATCH] new CustomSwipeRefreshLayout with a workaround to catch onTouchEvent IllegalArgumentException --- .../util/ptr/CustomSwipeRefreshLayout.java | 29 +++++++++++++++++++ .../util/ptr/SwipeToRefreshHelper.java | 7 ++--- 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 WordPressUtils/src/main/java/org/wordpress/android/util/ptr/CustomSwipeRefreshLayout.java diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/CustomSwipeRefreshLayout.java b/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/CustomSwipeRefreshLayout.java new file mode 100644 index 000000000000..7d79872bd5aa --- /dev/null +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/CustomSwipeRefreshLayout.java @@ -0,0 +1,29 @@ +package org.wordpress.android.util.ptr; + +import android.content.Context; +import android.support.v4.widget.SwipeRefreshLayout; +import android.util.AttributeSet; +import android.view.MotionEvent; + +import org.wordpress.android.util.AppLog; +import org.wordpress.android.util.AppLog.T; + +public class CustomSwipeRefreshLayout extends SwipeRefreshLayout { + public CustomSwipeRefreshLayout(Context context) { + super(context); + } + + public CustomSwipeRefreshLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + try{ + return super.onTouchEvent(event); + } catch(IllegalArgumentException e) { + AppLog.e(T.UTILS, e); + return true; + } + } +} diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/SwipeToRefreshHelper.java b/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/SwipeToRefreshHelper.java index 8cad070e80b7..bdff140bbcf7 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/SwipeToRefreshHelper.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/SwipeToRefreshHelper.java @@ -3,14 +3,13 @@ import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; -import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener; import android.util.TypedValue; import org.wordpress.android.util.R; public class SwipeToRefreshHelper implements OnRefreshListener { - private SwipeRefreshLayout mSwipeRefreshLayout; + private CustomSwipeRefreshLayout mSwipeRefreshLayout; private RefreshListener mRefreshListener; private boolean mRefreshing; @@ -18,11 +17,11 @@ public interface RefreshListener { public void onRefreshStarted(); } - public SwipeToRefreshHelper(Activity activity, SwipeRefreshLayout swipeRefreshLayout, RefreshListener listener) { + public SwipeToRefreshHelper(Activity activity, CustomSwipeRefreshLayout swipeRefreshLayout, RefreshListener listener) { init(activity, swipeRefreshLayout, listener); } - public void init(Activity activity, SwipeRefreshLayout swipeRefreshLayout, RefreshListener listener) { + public void init(Activity activity, CustomSwipeRefreshLayout swipeRefreshLayout, RefreshListener listener) { mRefreshListener = listener; mSwipeRefreshLayout = swipeRefreshLayout; mSwipeRefreshLayout.setOnRefreshListener(this);