CreateJavaRunnable() public static method

public static CreateJavaRunnable ( AndroidJavaRunnable runnable ) : IntPtr
runnable AndroidJavaRunnable
return IntPtr
コード例 #1
0
 public static AndroidJavaObject Box(object obj)
 {
     if (obj == null)
     {
         return(null);
     }
     if (AndroidReflection.IsPrimitive(obj.GetType()))
     {
         if (obj is int)
         {
             return(new AndroidJavaObject("java.lang.Integer", (int)obj));
         }
         if (obj is bool)
         {
             return(new AndroidJavaObject("java.lang.Boolean", (bool)obj));
         }
         if (obj is byte)
         {
             return(new AndroidJavaObject("java.lang.Byte", (byte)obj));
         }
         if (obj is short)
         {
             return(new AndroidJavaObject("java.lang.Short", (short)obj));
         }
         if (obj is long)
         {
             return(new AndroidJavaObject("java.lang.Long", (long)obj));
         }
         if (obj is float)
         {
             return(new AndroidJavaObject("java.lang.Float", (float)obj));
         }
         if (obj is double)
         {
             return(new AndroidJavaObject("java.lang.Double", (double)obj));
         }
         if (obj is char)
         {
             return(new AndroidJavaObject("java.lang.Character", (char)obj));
         }
         throw new Exception("JNI; Unknown argument type '" + obj.GetType() + "'");
     }
     if (obj is string)
     {
         return(new AndroidJavaObject("java.lang.String", (string)obj));
     }
     if (obj is AndroidJavaClass)
     {
         return(new AndroidJavaObject(((AndroidJavaClass)obj).GetRawClass()));
     }
     if (obj is AndroidJavaObject)
     {
         return((AndroidJavaObject)obj);
     }
     if (obj is Array)
     {
         return(AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(ConvertToJNIArray((Array)obj)));
     }
     if (obj is AndroidJavaProxy)
     {
         return(AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(AndroidJNIHelper.CreateJavaProxy((AndroidJavaProxy)obj)));
     }
     if (obj is AndroidJavaRunnable)
     {
         return(AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(AndroidJNIHelper.CreateJavaRunnable((AndroidJavaRunnable)obj)));
     }
     throw new Exception("JNI; Unknown argument type '" + obj.GetType() + "'");
 }
コード例 #2
0
        public static jvalue[] CreateJNIArgArray(object[] args)
        {
            jvalue[] array = new jvalue[args.GetLength(0)];
            int      num   = 0;

            foreach (object obj in args)
            {
                if (obj == null)
                {
                    array[num].l = IntPtr.Zero;
                }
                else if (AndroidReflection.IsPrimitive(obj.GetType()))
                {
                    if (obj is int)
                    {
                        array[num].i = (int)obj;
                    }
                    else if (obj is bool)
                    {
                        array[num].z = (bool)obj;
                    }
                    else if (obj is byte)
                    {
                        array[num].b = (byte)obj;
                    }
                    else if (obj is short)
                    {
                        array[num].s = (short)obj;
                    }
                    else if (obj is long)
                    {
                        array[num].j = (long)obj;
                    }
                    else if (obj is float)
                    {
                        array[num].f = (float)obj;
                    }
                    else if (obj is double)
                    {
                        array[num].d = (double)obj;
                    }
                    else if (obj is char)
                    {
                        array[num].c = (char)obj;
                    }
                }
                else if (obj is string)
                {
                    array[num].l = AndroidJNISafe.NewStringUTF((string)obj);
                }
                else if (obj is AndroidJavaClass)
                {
                    array[num].l = ((AndroidJavaClass)obj).GetRawClass();
                }
                else if (obj is AndroidJavaObject)
                {
                    array[num].l = ((AndroidJavaObject)obj).GetRawObject();
                }
                else if (obj is Array)
                {
                    array[num].l = ConvertToJNIArray((Array)obj);
                }
                else if (obj is AndroidJavaProxy)
                {
                    array[num].l = AndroidJNIHelper.CreateJavaProxy((AndroidJavaProxy)obj);
                }
                else
                {
                    if (!(obj is AndroidJavaRunnable))
                    {
                        throw new Exception("JNI; Unknown argument type '" + obj.GetType() + "'");
                    }
                    array[num].l = AndroidJNIHelper.CreateJavaRunnable((AndroidJavaRunnable)obj);
                }
                num++;
            }
            return(array);
        }
コード例 #3
0
        public static AndroidJavaObject Box(object obj)
        {
            AndroidJavaObject result;

            if (obj == null)
            {
                result = null;
            }
            else if (AndroidReflection.IsPrimitive(obj.GetType()))
            {
                if (obj is int)
                {
                    result = new AndroidJavaObject("java.lang.Integer", new object[]
                    {
                        (int)obj
                    });
                }
                else if (obj is bool)
                {
                    result = new AndroidJavaObject("java.lang.Boolean", new object[]
                    {
                        (bool)obj
                    });
                }
                else if (obj is byte)
                {
                    result = new AndroidJavaObject("java.lang.Byte", new object[]
                    {
                        (byte)obj
                    });
                }
                else if (obj is short)
                {
                    result = new AndroidJavaObject("java.lang.Short", new object[]
                    {
                        (short)obj
                    });
                }
                else if (obj is long)
                {
                    result = new AndroidJavaObject("java.lang.Long", new object[]
                    {
                        (long)obj
                    });
                }
                else if (obj is float)
                {
                    result = new AndroidJavaObject("java.lang.Float", new object[]
                    {
                        (float)obj
                    });
                }
                else if (obj is double)
                {
                    result = new AndroidJavaObject("java.lang.Double", new object[]
                    {
                        (double)obj
                    });
                }
                else
                {
                    if (!(obj is char))
                    {
                        throw new Exception("JNI; Unknown argument type '" + obj.GetType() + "'");
                    }
                    result = new AndroidJavaObject("java.lang.Character", new object[]
                    {
                        (char)obj
                    });
                }
            }
            else if (obj is string)
            {
                result = new AndroidJavaObject("java.lang.String", new object[]
                {
                    (string)obj
                });
            }
            else if (obj is AndroidJavaClass)
            {
                result = new AndroidJavaObject(((AndroidJavaClass)obj).GetRawClass());
            }
            else if (obj is AndroidJavaObject)
            {
                result = (AndroidJavaObject)obj;
            }
            else if (obj is Array)
            {
                result = AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(_AndroidJNIHelper.ConvertToJNIArray((Array)obj));
            }
            else if (obj is AndroidJavaProxy)
            {
                result = ((AndroidJavaProxy)obj).GetProxy();
            }
            else
            {
                if (!(obj is AndroidJavaRunnable))
                {
                    throw new Exception("JNI; Unknown argument type '" + obj.GetType() + "'");
                }
                result = AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(AndroidJNIHelper.CreateJavaRunnable((AndroidJavaRunnable)obj));
            }
            return(result);
        }