Example #1
0
 public static short ConvertUnsignedToShort(sbyte p0)
 {
     if (id_convertUnsignedToShort_B == IntPtr.Zero)
     {
         id_convertUnsignedToShort_B = JNIEnv.GetStaticMethodID(class_ref, "convertUnsignedToShort", "(B)S");
     }
     return(JNIEnv.CallStaticShortMethod(class_ref, id_convertUnsignedToShort_B, new JValue(p0)));
 }
 public static unsafe short SwapShort(short p0)
 {
     if (id_swapShort_S == IntPtr.Zero)
     {
         id_swapShort_S = JNIEnv.GetStaticMethodID(class_ref, "swapShort", "(S)S");
     }
     try {
         JValue *__args = stackalloc JValue [1];
         __args [0] = new JValue(p0);
         return(JNIEnv.CallStaticShortMethod(class_ref, id_swapShort_S, __args));
     } finally {
     }
 }
Example #3
0
        public static unsafe short ReadShort(global::System.IO.Stream p0)
        {
            if (id_readShort_Ljava_io_InputStream_ == IntPtr.Zero)
            {
                id_readShort_Ljava_io_InputStream_ = JNIEnv.GetStaticMethodID(class_ref, "readShort", "(Ljava/io/InputStream;)S");
            }
            IntPtr native_p0 = global::Android.Runtime.InputStreamAdapter.ToLocalJniHandle(p0);

            try {
                JValue *__args = stackalloc JValue [1];
                __args [0] = new JValue(native_p0);
                short __ret = JNIEnv.CallStaticShortMethod(class_ref, id_readShort_Ljava_io_InputStream_, __args);
                return(__ret);
            } finally {
                JNIEnv.DeleteLocalRef(native_p0);
            }
        }
        //CJW
        public T CallMethod <T>(IntPtr methodId, bool bIsStaticMethod, String sig, List <object> param)
        {
            try
            {
                if (typeof(T) == typeof(byte))
                {
                    // Call the byte method
                    byte res;
                    if (bIsStaticMethod)
                    {
                        res = env.CallStaticByteMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        res = env.CallByteMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(bool))
                {
                    // Call the boolean method
                    bool res;
                    if (bIsStaticMethod)
                    {
                        res = env.CallStaticBooleanMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        res = env.CallBooleanMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    return((T)(object)res);
                }
                if (typeof(T) == typeof(char))
                {
                    // Call the char method
                    char res;
                    if (bIsStaticMethod)
                    {
                        res = env.CallStaticCharMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        res = env.CallCharMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(short))
                {
                    // Call the short method
                    short res;
                    if (bIsStaticMethod)
                    {
                        res = env.CallStaticShortMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        res = env.CallShortMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(int))
                {
                    // Call the int method
                    int res;
                    if (bIsStaticMethod)
                    {
                        res = env.CallStaticIntMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        res = env.CallIntMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(long))
                {
                    // Call the long method
                    long res;
                    if (bIsStaticMethod)
                    {
                        res = env.CallStaticLongMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        res = env.CallLongMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(float))
                {
                    // Call the float method
                    float res;
                    if (bIsStaticMethod)
                    {
                        res = env.CallStaticFloatMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        res = env.CallFloatMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(double))
                {
                    // Call the double method
                    double res;
                    if (bIsStaticMethod)
                    {
                        res = env.CallStaticDoubleMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        res = env.CallDoubleMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    return((T)(object)res); // need to fix this
                }
                else if (typeof(T) == typeof(string))
                {
                    // Call the string method
                    IntPtr jstr;
                    if (bIsStaticMethod)
                    {
                        jstr = env.CallStaticObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        jstr = env.CallObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }

                    string res = env.JStringToString(jstr);
                    env.DeleteLocalRef(jstr);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(byte[]))
                {
                    // Call the byte method
                    IntPtr jobj;
                    if (bIsStaticMethod)
                    {
                        jobj = env.CallStaticObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        jobj = env.CallObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    if (jobj == IntPtr.Zero)
                    {
                        return(default(T));
                    }
                    byte[] res = env.JStringToByte(jobj);
                    env.DeleteLocalRef(jobj);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(string[]))
                {
                    // Call the string array method
                    IntPtr jobj;
                    if (bIsStaticMethod)
                    {
                        jobj = env.CallStaticObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        jobj = env.CallObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    if (jobj == IntPtr.Zero)
                    {
                        return(default(T));
                    }

                    IntPtr[] objArray = env.GetObjectArray(jobj);
                    string[] res      = new string[objArray.Length];

                    for (int i = 0; i < objArray.Length; i++)
                    {
                        res[i] = env.JStringToString(objArray[i]);
                    }

                    env.DeleteLocalRef(jobj);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(int[]))
                {
                    // Call the int array method
                    IntPtr jobj;
                    if (bIsStaticMethod)
                    {
                        jobj = env.CallStaticObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        jobj = env.CallObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    if (jobj == IntPtr.Zero)
                    {
                        return(default(T));
                    }
                    int[] res = env.GetIntArray(jobj);
                    env.DeleteLocalRef(jobj);
                    return((T)(object)res);
                }
                else if (typeof(T) == typeof(IntPtr))
                {
                    // Call the object method and deal with whatever comes back in the call code
                    IntPtr res;
                    if (bIsStaticMethod)
                    {
                        res = env.CallStaticObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    else
                    {
                        res = env.CallObjectMethod(javaObject, methodId, ParseParameters(sig, param));
                    }
                    return((T)(object)res);
                }
                return(default(T));
            }
            catch (Exception e)
            {
                throw new Exception("JNICode Error:" + e.Message);
            }
        }