parent
15ff7caa3a
commit
216f0d3e2b
@ -0,0 +1,40 @@ |
||||
package com.keylesspalace.tusky.util; |
||||
|
||||
import androidx.viewpager2.widget.ViewPager2; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
import java.lang.reflect.*; |
||||
import java.lang.*; |
||||
|
||||
/** |
||||
* ViewPager2 written by monkeys! |
||||
*/ |
||||
public class ViewPager2Fix { |
||||
/** |
||||
* Thanks to @al.e.shevelev@medium.com for solution |
||||
*/ |
||||
public static Field getViewPagerRecyclerViewField() throws NoSuchFieldException { |
||||
Field f = ViewPager2.class.getDeclaredField("mRecyclerView"); |
||||
f.setAccessible(true); |
||||
return f; |
||||
} |
||||
|
||||
public static Field getRecyclerViewTouchSlopField() throws NoSuchFieldException { |
||||
Field f = RecyclerView.class.getDeclaredField("mTouchSlop"); |
||||
f.setAccessible(true); |
||||
return f; |
||||
} |
||||
|
||||
public static void reduceVelocity(ViewPager2 pager, float val) { |
||||
try { |
||||
Field recyclerViewField = getViewPagerRecyclerViewField(); |
||||
Field touchSlopField = getRecyclerViewTouchSlopField(); |
||||
|
||||
RecyclerView recyclerView = (RecyclerView)recyclerViewField.get(pager); |
||||
int touchSlop = (int)touchSlopField.get(recyclerView); |
||||
touchSlopField.setInt(recyclerView, (int)(touchSlop*val)); |
||||
} catch(Exception e) { |
||||
// all possible exceptions must be caught during tests
|
||||
; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,34 @@ |
||||
package com.keylesspalace.tusky.util; |
||||
|
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
import org.junit.Assert; |
||||
import org.junit.runner.RunWith; |
||||
import androidx.test.ext.junit.runners.AndroidJUnit4; |
||||
import androidx.viewpager2.widget.ViewPager2; |
||||
import androidx.recyclerview.widget.RecyclerView; |
||||
import org.junit.runners.Parameterized; |
||||
import java.lang.reflect.*; |
||||
import java.lang.*; |
||||
import com.keylesspalace.tusky.util.ViewPager2Fix; |
||||
|
||||
public class ViewPager2FixTest { |
||||
@Test |
||||
public void getViewPagerRecyclerViewFieldTest() { |
||||
try { |
||||
Field f = ViewPager2Fix.getViewPagerRecyclerViewField(); |
||||
} catch(Exception e) { |
||||
Assert.fail("asdf"); |
||||
} |
||||
} |
||||
|
||||
@Test |
||||
public void getRecyclerViewTouchSlopFieldTest() { |
||||
try { |
||||
Field f = ViewPager2Fix.getRecyclerViewTouchSlopField(); |
||||
} catch(Exception e) { |
||||
Assert.fail("asdf"); |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue