Exemplo n.º 1
0
 public static AndroidJavaObject Box(object obj)
 {
     if (obj == null)
     {
         return((AndroidJavaObject)null);
     }
     if (AndroidReflection.IsPrimitive(obj.GetType()))
     {
         if (obj is int)
         {
             return(new AndroidJavaObject("java.lang.Integer", new object[1] {
                 (object)(int)obj
             }));
         }
         if (obj is bool)
         {
             return(new AndroidJavaObject("java.lang.Boolean", new object[1] {
                 (object)(bool)obj
             }));
         }
         if (obj is byte)
         {
             return(new AndroidJavaObject("java.lang.Byte", new object[1] {
                 (object)(byte)obj
             }));
         }
         if (obj is short)
         {
             return(new AndroidJavaObject("java.lang.Short", new object[1] {
                 (object)(short)obj
             }));
         }
         if (obj is long)
         {
             return(new AndroidJavaObject("java.lang.Long", new object[1] {
                 (object)(long)obj
             }));
         }
         if (obj is float)
         {
             return(new AndroidJavaObject("java.lang.Float", new object[1] {
                 (object)(float)obj
             }));
         }
         if (obj is double)
         {
             return(new AndroidJavaObject("java.lang.Double", new object[1] {
                 (object)(double)obj
             }));
         }
         if (!(obj is char))
         {
             throw new Exception("JNI; Unknown argument type '" + (object)obj.GetType() + "'");
         }
         return(new AndroidJavaObject("java.lang.Character", new object[1] {
             (object)(char)obj
         }));
     }
     if (obj is string)
     {
         return(new AndroidJavaObject("java.lang.String", new object[1] {
             (object)(string)obj
         }));
     }
     if (obj is AndroidJavaClass)
     {
         return(new AndroidJavaObject(((AndroidJavaObject)obj).GetRawClass()));
     }
     if (obj is AndroidJavaObject)
     {
         return((AndroidJavaObject)obj);
     }
     if (obj is Array)
     {
         return(AndroidJavaObject.AndroidJavaObjectDeleteLocalRef(_AndroidJNIHelper.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 '" + (object)obj.GetType() + "'");
 }
Exemplo n.º 2
0
 public static IntPtr CreateJavaRunnable(AndroidJavaRunnable jrunnable)
 {
     return(AndroidJNIHelper.CreateJavaProxy((AndroidJavaProxy) new AndroidJavaRunnableProxy(jrunnable)));
 }
Exemplo n.º 3
0
        public static jvalue[] CreateJNIArgArray(object[] args)
        {
            jvalue[] array = new jvalue[args.GetLength(0)];
            int      num   = 0;

            for (int i = 0; i < args.Length; i++)
            {
                object obj = args[i];
                if (obj == null)
                {
                    array[num].l = IntPtr.Zero;
                }
                else
                {
                    if (obj.GetType().IsPrimitive)
                    {
                        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 = _AndroidJNIHelper.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);
        }
Exemplo n.º 4
0
        public static jvalue[] CreateJNIArgArray(object[] args)
        {
            jvalue[] jvalueArray = new jvalue[args.GetLength(0)];
            int      index       = 0;

            foreach (object obj2 in args)
            {
                if (obj2 == null)
                {
                    jvalueArray[index].l = IntPtr.Zero;
                }
                else if (obj2.GetType().IsPrimitive)
                {
                    if (obj2 is int)
                    {
                        jvalueArray[index].i = (int)obj2;
                    }
                    else if (obj2 is bool)
                    {
                        jvalueArray[index].z = (bool)obj2;
                    }
                    else if (obj2 is byte)
                    {
                        jvalueArray[index].b = (byte)obj2;
                    }
                    else if (obj2 is short)
                    {
                        jvalueArray[index].s = (short)obj2;
                    }
                    else if (obj2 is long)
                    {
                        jvalueArray[index].j = (long)obj2;
                    }
                    else if (obj2 is float)
                    {
                        jvalueArray[index].f = (float)obj2;
                    }
                    else if (obj2 is double)
                    {
                        jvalueArray[index].d = (double)obj2;
                    }
                    else if (obj2 is char)
                    {
                        jvalueArray[index].c = (char)obj2;
                    }
                }
                else if (obj2 is string)
                {
                    jvalueArray[index].l = AndroidJNISafe.NewStringUTF((string)obj2);
                }
                else if (obj2 is AndroidJavaClass)
                {
                    jvalueArray[index].l = ((AndroidJavaClass)obj2).GetRawClass();
                }
                else if (obj2 is AndroidJavaObject)
                {
                    jvalueArray[index].l = ((AndroidJavaObject)obj2).GetRawObject();
                }
                else if (obj2 is Array)
                {
                    jvalueArray[index].l = ConvertToJNIArray((Array)obj2);
                }
                else if (obj2 is AndroidJavaProxy)
                {
                    jvalueArray[index].l = AndroidJNIHelper.CreateJavaProxy((AndroidJavaProxy)obj2);
                }
                else
                {
                    if (!(obj2 is AndroidJavaRunnable))
                    {
                        throw new Exception("JNI; Unknown argument type '" + obj2.GetType() + "'");
                    }
                    jvalueArray[index].l = AndroidJNIHelper.CreateJavaRunnable((AndroidJavaRunnable)obj2);
                }
                index++;
            }
            return(jvalueArray);
        }
 public static IntPtr CreateJavaRunnable(AndroidJavaRunnable jrunnable) =>
 AndroidJNIHelper.CreateJavaProxy(new AndroidJavaRunnableProxy(jrunnable));