diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/helpers/SwipeToRefreshHelper.java b/WordPressUtils/src/main/java/org/wordpress/android/util/helpers/SwipeToRefreshHelper.java index 72df841470ab..d68e00b56aed 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/helpers/SwipeToRefreshHelper.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/helpers/SwipeToRefreshHelper.java @@ -3,14 +3,14 @@ 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; +import org.wordpress.android.util.widgets.CustomSwipeRefreshLayout; public class SwipeToRefreshHelper implements OnRefreshListener { - private SwipeRefreshLayout mSwipeRefreshLayout; + private CustomSwipeRefreshLayout mSwipeRefreshLayout; private RefreshListener mRefreshListener; private boolean mRefreshing; @@ -18,11 +18,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); diff --git a/WordPressUtils/src/main/java/org/wordpress/android/util/widgets/CustomSwipeRefreshLayout.java b/WordPressUtils/src/main/java/org/wordpress/android/util/widgets/CustomSwipeRefreshLayout.java new file mode 100644 index 000000000000..356268922dc1 --- /dev/null +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/widgets/CustomSwipeRefreshLayout.java @@ -0,0 +1,33 @@ +package org.wordpress.android.util.widgets; + +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) { + // Fix for https://github.com/wordpress-mobile/WordPress-Android/issues/2373 + // Catch IllegalArgumentException which can be fired by the underlying SwipeRefreshLayout.onTouchEvent() + // method. + // When android support-v4 fixes it, we'll have to remove that custom layout completely. + AppLog.e(T.UTILS, e); + return true; + } + } +}