Exemplo n.º 1
0
    protected void registerClass(String p_name, String[] p_methods) {

      GodotLib.singleton(p_name, this);

      Class clazz = getClass();
      Method[] methods = clazz.getDeclaredMethods();
      for (Method method : methods) {
        boolean found = false;
        System.out.printf("METHOD: %s\n", method.getName());

        for (String s : p_methods) {
          System.out.printf("METHOD CMP WITH: %s\n", s);
          if (s.equals(method.getName())) {
            found = true;
            System.out.printf("METHOD CMP VALID");
            break;
          }
        }
        if (!found) continue;

        System.out.printf("METHOD FOUND: %s\n", method.getName());

        List<String> ptr = new ArrayList<String>();

        Class[] paramTypes = method.getParameterTypes();
        for (Class c : paramTypes) {
          ptr.add(c.getName());
        }

        String[] pt = new String[ptr.size()];
        ptr.toArray(pt);

        GodotLib.method(p_name, method.getName(), method.getReturnType().getName(), pt);
      }
    }
Exemplo n.º 2
0
 public static void setFinalStaticField(
     Class classWhichContainsField, String fieldName, Object newValue) {
   try {
     Field field = classWhichContainsField.getDeclaredField(fieldName);
     setFinalStaticField(field, newValue);
   } catch (NoSuchFieldException e) {
     throw new RuntimeException(e);
   }
 }
Exemplo n.º 3
0
 public static Object newInstanceOf(String className) {
   try {
     Class<?> clazz = Class.forName(className);
     if (clazz != null) {
       return newInstanceOf(clazz);
     }
   } catch (ClassNotFoundException e) {
   }
   return null;
 }
Exemplo n.º 4
0
    public static void setFinalStaticField(
        Class classWhichContainsField, String fieldName, Object newValue) {
      try {
        Field field = classWhichContainsField.getField(fieldName);
        field.setAccessible(true);

        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

        field.set(null, newValue);
      } catch (NoSuchFieldException e) {
        throw new RuntimeException(e);
      } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
      }
    }
Exemplo n.º 5
0
  /** This method is called by SDL using JNI. */
  public InputStream openAPKExtensionInputStream(String fileName) throws IOException {
    // Get a ZipResourceFile representing a merger of both the main and patch files
    if (expansionFile == null) {
      Integer mainVersion =
          Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
      Integer patchVersion =
          Integer.valueOf(nativeGetHint("SDL_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION"));

      try {
        // To avoid direct dependency on Google APK extension library that is
        // not a part of Android SDK we access it using reflection
        expansionFile =
            Class.forName("com.android.vending.expansion.zipfile.APKExpansionSupport")
                .getMethod("getAPKExpansionZipFile", Context.class, int.class, int.class)
                .invoke(null, this, mainVersion, patchVersion);

        expansionFileMethod = expansionFile.getClass().getMethod("getInputStream", String.class);
      } catch (Exception ex) {
        ex.printStackTrace();
        expansionFile = null;
        expansionFileMethod = null;
      }
    }

    // Get an input stream for a known file inside the expansion file ZIPs
    InputStream fileStream;
    try {
      fileStream = (InputStream) expansionFileMethod.invoke(expansionFile, fileName);
    } catch (Exception ex) {
      ex.printStackTrace();
      fileStream = null;
    }

    if (fileStream == null) {
      throw new IOException();
    }

    return fileStream;
  }