Skip to content

Instantly share code, notes, and snippets.

@jzeferino
Forked from Redth/RvUtil.cs
Created January 4, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jzeferino/deac26b4efe03277cf31f10562d84115 to your computer and use it in GitHub Desktop.
Save jzeferino/deac26b4efe03277cf31f10562d84115 to your computer and use it in GitHub Desktop.
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