FromShortArray() public static method

public static FromShortArray ( IntPtr array ) : short[]
array System.IntPtr
return short[]
Example #1
0
        public static ArrayType ConvertFromJNIArray <ArrayType>(IntPtr array)
        {
            Type elementType = typeof(ArrayType).GetElementType();

            if (AndroidReflection.IsPrimitive(elementType))
            {
                if (elementType == typeof(int))
                {
                    return((ArrayType)(object)AndroidJNISafe.FromIntArray(array));
                }
                if (elementType == typeof(bool))
                {
                    return((ArrayType)(object)AndroidJNISafe.FromBooleanArray(array));
                }
                if (elementType == typeof(byte))
                {
                    return((ArrayType)(object)AndroidJNISafe.FromByteArray(array));
                }
                if (elementType == typeof(short))
                {
                    return((ArrayType)(object)AndroidJNISafe.FromShortArray(array));
                }
                if (elementType == typeof(long))
                {
                    return((ArrayType)(object)AndroidJNISafe.FromLongArray(array));
                }
                if (elementType == typeof(float))
                {
                    return((ArrayType)(object)AndroidJNISafe.FromFloatArray(array));
                }
                if (elementType == typeof(double))
                {
                    return((ArrayType)(object)AndroidJNISafe.FromDoubleArray(array));
                }
                if (elementType == typeof(char))
                {
                    return((ArrayType)(object)AndroidJNISafe.FromCharArray(array));
                }
                return(default(ArrayType));
            }
            if (elementType == typeof(string))
            {
                int      arrayLength = AndroidJNISafe.GetArrayLength(array);
                string[] array2      = new string[arrayLength];
                for (int i = 0; i < arrayLength; i++)
                {
                    IntPtr objectArrayElement = AndroidJNI.GetObjectArrayElement(array, i);
                    array2[i] = AndroidJNISafe.GetStringUTFChars(objectArrayElement);
                    AndroidJNISafe.DeleteLocalRef(objectArrayElement);
                }
                return((ArrayType)(object)array2);
            }
            if (elementType == typeof(AndroidJavaObject))
            {
                int arrayLength2           = AndroidJNISafe.GetArrayLength(array);
                AndroidJavaObject[] array3 = new AndroidJavaObject[arrayLength2];
                for (int j = 0; j < arrayLength2; j++)
                {
                    IntPtr objectArrayElement2 = AndroidJNI.GetObjectArrayElement(array, j);
                    array3[j] = new AndroidJavaObject(objectArrayElement2);
                    AndroidJNISafe.DeleteLocalRef(objectArrayElement2);
                }
                return((ArrayType)(object)array3);
            }
            throw new Exception("JNI: Unknown generic array type '" + elementType + "'");
        }
Example #2
0
        public static ArrayType ConvertFromJNIArray <ArrayType>(IntPtr array)
        {
            System.Type elementType = typeof(ArrayType).GetElementType();
            if (elementType.IsPrimitive)
            {
                if (elementType == typeof(int))
                {
                    return((ArrayType)AndroidJNISafe.FromIntArray(array));
                }
                if (elementType == typeof(bool))
                {
                    return((ArrayType)AndroidJNISafe.FromBooleanArray(array));
                }
                if (elementType == typeof(byte))
                {
                    return((ArrayType)AndroidJNISafe.FromByteArray(array));
                }
                if (elementType == typeof(short))
                {
                    return((ArrayType)AndroidJNISafe.FromShortArray(array));
                }
                if (elementType == typeof(long))
                {
                    return((ArrayType)AndroidJNISafe.FromLongArray(array));
                }
                if (elementType == typeof(float))
                {
                    return((ArrayType)AndroidJNISafe.FromFloatArray(array));
                }
                if (elementType == typeof(double))
                {
                    return((ArrayType)AndroidJNISafe.FromDoubleArray(array));
                }
                if (elementType != typeof(char))
                {
                    return(default(ArrayType));
                }
                return((ArrayType)AndroidJNISafe.FromCharArray(array));
            }
            if (elementType == typeof(string))
            {
                IntPtr[] ptrArray = AndroidJNISafe.FromObjectArray(array);
                int      num      = ptrArray.GetLength(0);
                string[] strArray = new string[num];
                for (int j = 0; j < num; j++)
                {
                    strArray[j] = AndroidJNISafe.GetStringUTFChars(ptrArray[j]);
                }
                return((ArrayType)strArray);
            }
            if (elementType != typeof(AndroidJavaObject))
            {
                throw new Exception("JNI: Unknown generic array type '" + elementType + "'");
            }
            IntPtr[] ptrArray2 = AndroidJNISafe.FromObjectArray(array);
            int      length    = ptrArray2.GetLength(0);

            AndroidJavaObject[] objArray = new AndroidJavaObject[length];
            for (int i = 0; i < length; i++)
            {
                objArray[i] = new AndroidJavaObject(ptrArray2[i]);
            }
            return((ArrayType)objArray);
        }
        public static ArrayType ConvertFromJNIArray <ArrayType>(IntPtr array)
        {
            System.Type elementType = typeof(ArrayType).GetElementType();
            if (AndroidReflection.IsPrimitive(elementType))
            {
                if (elementType == typeof(int))
                {
                    return((ArrayType)AndroidJNISafe.FromIntArray(array));
                }
                if (elementType == typeof(bool))
                {
                    return((ArrayType)AndroidJNISafe.FromBooleanArray(array));
                }
                if (elementType == typeof(byte))
                {
                    return((ArrayType)AndroidJNISafe.FromByteArray(array));
                }
                if (elementType == typeof(short))
                {
                    return((ArrayType)AndroidJNISafe.FromShortArray(array));
                }
                if (elementType == typeof(long))
                {
                    return((ArrayType)AndroidJNISafe.FromLongArray(array));
                }
                if (elementType == typeof(float))
                {
                    return((ArrayType)AndroidJNISafe.FromFloatArray(array));
                }
                if (elementType == typeof(double))
                {
                    return((ArrayType)AndroidJNISafe.FromDoubleArray(array));
                }
                if (elementType == typeof(char))
                {
                    return((ArrayType)AndroidJNISafe.FromCharArray(array));
                }
                return(default(ArrayType));
            }
            if (elementType == typeof(string))
            {
                int      arrayLength = AndroidJNISafe.GetArrayLength(array);
                string[] strArray    = new string[arrayLength];
                for (int index = 0; index < arrayLength; ++index)
                {
                    IntPtr objectArrayElement = AndroidJNI.GetObjectArrayElement(array, index);
                    strArray[index] = AndroidJNISafe.GetStringUTFChars(objectArrayElement);
                    AndroidJNISafe.DeleteLocalRef(objectArrayElement);
                }
                return((ArrayType)strArray);
            }
            if (elementType != typeof(AndroidJavaObject))
            {
                throw new Exception("JNI: Unknown generic array type '" + (object)elementType + "'");
            }
            int arrayLength1 = AndroidJNISafe.GetArrayLength(array);

            AndroidJavaObject[] androidJavaObjectArray = new AndroidJavaObject[arrayLength1];
            for (int index = 0; index < arrayLength1; ++index)
            {
                IntPtr objectArrayElement = AndroidJNI.GetObjectArrayElement(array, index);
                androidJavaObjectArray[index] = new AndroidJavaObject(objectArrayElement);
                AndroidJNISafe.DeleteLocalRef(objectArrayElement);
            }
            return((ArrayType)androidJavaObjectArray);
        }
        public static ArrayType ConvertFromJNIArray <ArrayType>(IntPtr array)
        {
            Type elementType = typeof(ArrayType).GetElementType();

            if (elementType.IsPrimitive)
            {
                if (elementType == typeof(int))
                {
                    return((ArrayType)((object)AndroidJNISafe.FromIntArray(array)));
                }
                if (elementType == typeof(bool))
                {
                    return((ArrayType)((object)AndroidJNISafe.FromBooleanArray(array)));
                }
                if (elementType == typeof(byte))
                {
                    return((ArrayType)((object)AndroidJNISafe.FromByteArray(array)));
                }
                if (elementType == typeof(short))
                {
                    return((ArrayType)((object)AndroidJNISafe.FromShortArray(array)));
                }
                if (elementType == typeof(long))
                {
                    return((ArrayType)((object)AndroidJNISafe.FromLongArray(array)));
                }
                if (elementType == typeof(float))
                {
                    return((ArrayType)((object)AndroidJNISafe.FromFloatArray(array)));
                }
                if (elementType == typeof(double))
                {
                    return((ArrayType)((object)AndroidJNISafe.FromDoubleArray(array)));
                }
                if (elementType == typeof(char))
                {
                    return((ArrayType)((object)AndroidJNISafe.FromCharArray(array)));
                }
                return(default(ArrayType));
            }
            else
            {
                if (elementType == typeof(string))
                {
                    IntPtr[] array2 = AndroidJNISafe.FromObjectArray(array);
                    int      length = array2.GetLength(0);
                    string[] array3 = new string[length];
                    for (int i = 0; i < length; i++)
                    {
                        array3[i] = AndroidJNISafe.GetStringUTFChars(array2[i]);
                    }
                    return((ArrayType)((object)array3));
                }
                if (elementType == typeof(AndroidJavaObject))
                {
                    IntPtr[]            array4  = AndroidJNISafe.FromObjectArray(array);
                    int                 length2 = array4.GetLength(0);
                    AndroidJavaObject[] array5  = new AndroidJavaObject[length2];
                    for (int j = 0; j < length2; j++)
                    {
                        array5[j] = new AndroidJavaObject(array4[j]);
                    }
                    return((ArrayType)((object)array5));
                }
                throw new Exception("JNI: Unknown generic array type '" + elementType + "'");
            }
        }