Switch to HackyViewPager for media preview

Fixes #7344
Fixes #7335
This commit is contained in:
Moxie Marlinspike 2018-01-18 10:16:35 -08:00
parent 763fa0dd21
commit bc64230a65
2 changed files with 44 additions and 1 deletions

View file

@ -5,7 +5,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/gray95"> android:background="@color/gray95">
<android.support.v4.view.ViewPager <org.thoughtcrime.securesms.components.viewpager.HackyViewPager
android:id="@+id/media_pager" android:id="@+id/media_pager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>

View file

@ -0,0 +1,43 @@
package org.thoughtcrime.securesms.components.viewpager;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
/**
* Hacky fix for http://code.google.com/p/android/issues/detail?id=18990
* <p/>
* ScaleGestureDetector seems to mess up the touch events, which means that
* ViewGroups which make use of onInterceptTouchEvent throw a lot of
* IllegalArgumentException: pointerIndex out of range.
* <p/>
* There's not much I can do in my code for now, but we can mask the result by
* just catching the problem and ignoring it.
*
* @author Chris Banes
*/
public class HackyViewPager extends ViewPager {
private static final String TAG = HackyViewPager.class.getSimpleName();
public HackyViewPager(Context context) {
super(context);
}
public HackyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException e) {
Log.w(TAG, e);
return false;
}
}
}