Ejemplo 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);
      }
    }
Ejemplo n.º 2
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;
  }