Skip to content

Instantly share code, notes, and snippets.

@jonpryor
Created December 7, 2011 18:16
Show Gist options
  • Save jonpryor/1443928 to your computer and use it in GitHub Desktop.
Save jonpryor/1443928 to your computer and use it in GitHub Desktop.
[Register ("android/accounts/AccountManagerFuture", DoNotGenerateAcw=true)]
interface IAccountManagerFuture {
[Register ("cancel", "(Z)Z", "GetCancelHandler:AccountManagerFutureInvoker, YourAssemblyName, Version=0.0.0")]
bool Cancel (bool mayInterruptIfRunning);
// ...
}
class IAccountManagerFutureInvoker : IAccountManagerFuture {
public IAccountManagerFutureInvoker (IntPtr handle, JniHandleOwnership transfer)
: base (handle, transfer)
{
IntPtr local_ref = JNIEnv.GetObjectClass (Handle);
this.class_ref = JNIEnv.NewGlobalRef (local_ref);
JNIEnv.DeleteLocalRef (local_ref);
}
protected override void Dispose (bool disposing)
{
if (this.class_ref != IntPtr.Zero)
JNIEnv.DeleteGlobalRef (this.class_ref);
this.class_ref = IntPtr.Zero;
base.Dispose (disposing);
}
protected override IntPtr ThresholdClass {
get { return class_ref; }
}
protected override System.Type ThresholdType {
get { return typeof (IAccountManagerFutureInvoker); }
}
static Delegate cb_cancel;
static Delegate GetCancelHandler ()
{
if (cb_cancel == null)
cb_cancel = JNINativeWrapper.CreateDelegate ((Action<IntPtr, IntPtr>) n_Cancel);
return cb_cancel;
}
static void n_Cancel (IntPtr jnienv, IntPtr native__this, bool mayInterruptIfRunning)
{
IAccountManagerFuture __this = Java.Lang.Object.GetObject<IAccountManagerFuture> (native__this, JniHandleOwnership.DoNotTransfer);
return __this.Cancel (mayInterruptIfRunning);
}
IntPtr id_cancel;
public bool Cancel (bool mayInterruptIfRunning)
{
if (id_cancel == IntPtr.Zero)
id_cancel = JNIEnv.GetMethodID (class_ref, "cancel", "(Z)Z");
return JNIEnv.CallBooleanMethod (Handle, id_run, new JValue (mayInterruptIfRunning));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment