From 757b7200484f451d1f47eec7a0478021ec971060 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Fri, 27 Feb 2015 13:39:29 +0100 Subject: [PATCH 1/2] 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); From c0c684adb8607f96d6dceb2402e82e5db1452282 Mon Sep 17 00:00:00 2001 From: Maxime Biais Date: Fri, 27 Feb 2015 15:25:15 +0100 Subject: [PATCH 2/2] comment CustomSwipeRefreshLayout.onTouchEvent --- .../wordpress/android/util/ptr/CustomSwipeRefreshLayout.java | 4 ++++ 1 file changed, 4 insertions(+) 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 index 7d79872bd5aa..7cc00d1b18de 100644 --- a/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/CustomSwipeRefreshLayout.java +++ b/WordPressUtils/src/main/java/org/wordpress/android/util/ptr/CustomSwipeRefreshLayout.java @@ -22,6 +22,10 @@ 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; }