Created
January 4, 2018 14:40
-
-
Save Redth/fb991f97bb078ac8551f2df2f06d9286 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RvUtil | |
{ | |
public RvUtil (RecyclerView rv) | |
{ | |
recyclerView = rv; | |
} | |
RecyclerView recyclerView; | |
IntPtr id_setNestedScrollingEnabled; | |
IntPtr id_isNestedScrollingEnabled; | |
public IntPtr baseHandle | |
{ | |
get { return recyclerView.Handle; } | |
} | |
public IntPtr ThresholdClass | |
{ | |
get { | |
var t = typeof(RecyclerView); | |
var m = t.GetProperty("ThresholdClass", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); | |
return (IntPtr)m.GetValue(recyclerView); | |
} | |
} | |
public Type ThresholdType { | |
get { | |
var t = typeof(RecyclerView); | |
var m = t.GetProperty("ThresholdType", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); | |
return (Type)m.GetValue(recyclerView); | |
} | |
} | |
public IntPtr class_ref | |
{ | |
get { | |
var t = typeof(RecyclerView); | |
var m = t.GetProperty("class_ref", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); | |
return (IntPtr)m.GetValue(recyclerView); | |
} | |
} | |
[Register("isNestedScrollingEnabled", "()Z", "GetIsNestedScrollingEnabledHandler")] | |
public unsafe virtual bool IsNestedScrollingEnabled () | |
{ | |
if (id_isNestedScrollingEnabled == IntPtr.Zero) { | |
id_isNestedScrollingEnabled = JNIEnv.GetMethodID(class_ref, "isNestedScrollingEnabled", "()Z"); | |
} | |
if (recyclerView.GetType().BaseType == ThresholdType) { | |
return JNIEnv.CallBooleanMethod(baseHandle, id_isNestedScrollingEnabled); | |
} | |
return JNIEnv.CallNonvirtualBooleanMethod(baseHandle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "isNestedScrollingEnabled", "()Z")); | |
} | |
[Register("setNestedScrollingEnabled", "(Z)V", "GetSetNestedScrollingEnabledHandler")] | |
public unsafe virtual void SetNestedScrollingEnabled(bool value) | |
{ | |
if (id_setNestedScrollingEnabled == IntPtr.Zero) { | |
id_setNestedScrollingEnabled = JNIEnv.GetMethodID(class_ref, "setNestedScrollingEnabled", "(Z)V"); | |
} | |
JValue* ptr = stackalloc JValue[1]; | |
*ptr = new JValue(value); | |
if (recyclerView.GetType().BaseType == ThresholdType) { | |
JNIEnv.CallVoidMethod(baseHandle, id_setNestedScrollingEnabled, ptr); | |
return; | |
} | |
JNIEnv.CallNonvirtualVoidMethod(baseHandle, ThresholdClass, JNIEnv.GetMethodID(ThresholdClass, "setNestedScrollingEnabled", "(Z)V"), ptr); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment