Exemple #1
0
 /// <summary>
 /// 加载并显示Screen到设备屏幕
 /// </summary>
 public void ShowScreen()
 {
     if (setupSensors)
     {
         Type accelerometer = null;
         if (accelerometer == null)
         {
             try
             {
                 accelerometer  = JavaRuntime.ClassforName("Loon.Core.Input.Sensors.AccelerometerExecute");
                 supportSensors = true;
             }
             catch (Exception)
             {
                 supportSensors = false;
             }
         }
         if (supportSensors)
         {
             try
             {
                 object o = JavaRuntime.NewInstance(accelerometer);
                 System.Reflection.MethodInfo initialize = JavaRuntime.GetMethod(accelerometer, "Initialize");
                 initialize.Invoke(o, null);
                 System.Reflection.MethodInfo isActive = JavaRuntime.GetMethod(accelerometer, "IsActive");
                 supportSensors = (bool)isActive.Invoke(o, null);
             }
             catch (Exception)
             {
                 supportSensors = false;
             }
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// 以反射方式,尝试通过Application读取数据
 /// </summary>
 /// <param name="pathUri"></param>
 /// <returns></returns>
 public static System.IO.Stream ApplicationResourceStream(Uri pathUri)
 {
     if (!supportApplication)
     {
         return(null);
     }
     try
     {
         if (appType == null)
         {
             try
             {
                 appType            = JavaRuntime.ClassforName("System.Windows.Application");
                 supportApplication = true;
             }
             catch
             {
                 supportApplication = false;
             }
         }
         object o = JavaRuntime.NewInstance(appType);
         System.Reflection.MethodInfo method = JavaRuntime.GetMethod(appType, "GetResourceStream", pathUri.GetType());
         object res = JavaRuntime.Invoke(method, o, pathUri);
         if (res != null)
         {
             System.Reflection.MethodInfo info = res.GetType().GetMethod("get_Stream");
             object open = JavaRuntime.Invoke(info, res);
             return(open as System.IO.Stream);
         }
     }
     catch
     {
     }
     return(null);
 }
Exemple #3
0
        private static Bind.BindObject BindClass(Object o)
        {
            Bind.BindObject result;
            Type            clazz = o.GetType();

            if (methodList == null)
            {
                methodList = new Dictionary <Type, BindObject>(10);
            }
            result = (BindObject)CollectionUtils.Get(methodList, clazz);

            if (result == null)
            {
                result = new Bind.BindObject(new MethodInfo[11]);
                try
                {
                    MethodInfo setX = JavaRuntime.GetMethod(clazz, "SetX", typeof(float));
                    MethodInfo setY = JavaRuntime.GetMethod(clazz, "SetY", typeof(float));
                    result.methods[0] = setX;
                    result.methods[1] = setY;
                    result.bindPos    = true;
                }
                catch (Exception e)
                {
                    Log.Exception(e);
                    result.bindPos = false;
                }
                if (result.bindPos)
                {
                    try
                    {
                        MethodInfo getX = JavaRuntime.GetMethod(clazz, "GetX");
                        MethodInfo getY = JavaRuntime.GetMethod(clazz, "GetY");
                        result.methods[7] = getX;
                        result.methods[8] = getY;
                        result.bindGetPos = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindGetPos = false;
                    }
                }
                if (result.bindPos && !result.bindGetPos)
                {
                    try
                    {
                        MethodInfo getX_1 = JavaRuntime.GetMethod(clazz, "X");
                        MethodInfo getY_2 = JavaRuntime.GetMethod(clazz, "Y");
                        result.methods[7] = getX_1;
                        result.methods[8] = getY_2;
                        result.bindGetPos = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindGetPos = false;
                    }
                }
                if (!result.bindPos)
                {
                    try
                    {
                        MethodInfo setX_4 = JavaRuntime.GetMethod(clazz, "SetX", typeof(int));
                        MethodInfo setY_5 = JavaRuntime.GetMethod(clazz, "SetY", typeof(int));
                        result.methods[0] = setX_4;
                        result.methods[1] = setY_5;
                        result.bindPos    = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindPos = false;
                    }
                }
                if (!result.bindPos)
                {
                    try
                    {
                        MethodInfo location = JavaRuntime.GetMethod(clazz, "SetLocation", typeof(float));
                        result.methods[0] = location;
                        result.bindPos    = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindPos = false;
                    }
                }
                if (!result.bindPos)
                {
                    try
                    {
                        MethodInfo location_8 = JavaRuntime.GetMethod(clazz, "SetLocation", typeof(int));
                        result.methods[0] = location_8;
                        result.bindPos    = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindPos = false;
                    }
                }
                if (!result.bindPos)
                {
                    try
                    {
                        MethodInfo location_10 = JavaRuntime.GetMethod(clazz, "SetPosition", typeof(float));
                        result.methods[0] = location_10;
                        result.bindPos    = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindPos = false;
                    }
                }
                if (!result.bindPos)
                {
                    try
                    {
                        MethodInfo location_12 = JavaRuntime.GetMethod(clazz, "SetPosition", typeof(int));
                        result.methods[0] = location_12;
                        result.bindPos    = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindPos = false;
                    }
                }
                try
                {
                    MethodInfo rotation = JavaRuntime.GetMethod(clazz, "SetRotation", typeof(float));
                    result.methods[2]   = rotation;
                    result.bindRotation = true;
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                    result.bindRotation = false;
                }
                if (result.bindRotation)
                {
                    try
                    {
                        MethodInfo getRotation = JavaRuntime.GetMethod(clazz, "GetRotation");
                        result.methods[6]      = getRotation;
                        result.bindGetRotation = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindGetRotation = false;
                    }
                }
                if (!result.bindRotation)
                {
                    try
                    {
                        MethodInfo rotation_16 = JavaRuntime.GetMethod(clazz, "SetRotation", typeof(int));
                        result.methods[2]   = rotation_16;
                        result.bindRotation = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindRotation = false;
                    }
                }
                if (!result.bindRotation)
                {
                    try
                    {
                        MethodInfo rotation_18 = JavaRuntime.GetMethod(clazz, "SetAngle", typeof(float));
                        result.methods[2]   = rotation_18;
                        result.bindRotation = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindRotation = false;
                    }
                }
                if (result.bindRotation && !result.bindGetRotation)
                {
                    try
                    {
                        MethodInfo getRotation_20 = JavaRuntime.GetMethod(clazz, "GetAngle");
                        result.methods[6]      = getRotation_20;
                        result.bindGetRotation = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindGetRotation = false;
                    }
                }
                if (!result.bindRotation)
                {
                    try
                    {
                        MethodInfo rotation_22 = JavaRuntime.GetMethod(clazz, "SetAngle", typeof(int));
                        result.methods[2]   = rotation_22;
                        result.bindRotation = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindRotation = false;
                    }
                }
                try
                {
                    MethodInfo update = JavaRuntime.GetMethod(clazz, "Update", typeof(long));
                    result.methods[3] = update;
                    result.bindUpdate = true;
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                    result.bindUpdate = false;
                }
                try
                {
                    MethodInfo setScaleX = JavaRuntime.GetMethod(clazz, "SetScaleX", typeof(float));
                    MethodInfo setScaleY = JavaRuntime.GetMethod(clazz, "SetScaleY", typeof(float));
                    result.methods[4] = setScaleX;
                    result.methods[5] = setScaleY;
                    result.bindScale  = true;
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                    result.bindScale = false;
                }
                if (!result.bindScale)
                {
                    try
                    {
                        MethodInfo scale = JavaRuntime.GetMethod(clazz, "SetScale", typeof(float));
                        result.methods[4] = scale;
                        result.bindScale  = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Exception(ex);
                        result.bindScale = false;
                    }
                }
                try
                {
                    MethodInfo width  = JavaRuntime.GetMethod(clazz, "GetWidth");
                    MethodInfo height = JavaRuntime.GetMethod(clazz, "GetHeight");
                    result.methods[9]  = width;
                    result.methods[10] = height;
                    result.bindSize    = true;
                }
                catch (Exception ex)
                {
                    Log.Exception(ex);
                    result.bindSize = false;
                }
                CollectionUtils.Put(methodList, clazz, result);
            }
            return(result);
        }