mirror of https://github.com/encounter/SDL.git
inital apk extension support
This commit is contained in:
parent
d5c109b2f4
commit
612f4a69db
|
@ -1,5 +1,7 @@
|
||||||
package org.libsdl.app;
|
package org.libsdl.app;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -20,6 +22,8 @@ import android.graphics.*;
|
||||||
import android.media.*;
|
import android.media.*;
|
||||||
import android.hardware.*;
|
import android.hardware.*;
|
||||||
|
|
||||||
|
import com.android.vending.expansion.zipfile.APKExpansionSupport;
|
||||||
|
import com.android.vending.expansion.zipfile.ZipResourceFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
SDL Activity
|
SDL Activity
|
||||||
|
@ -296,6 +300,7 @@ public class SDLActivity extends Activity {
|
||||||
int is_accelerometer, int nbuttons,
|
int is_accelerometer, int nbuttons,
|
||||||
int naxes, int nhats, int nballs);
|
int naxes, int nhats, int nballs);
|
||||||
public static native int nativeRemoveJoystick(int device_id);
|
public static native int nativeRemoveJoystick(int device_id);
|
||||||
|
public static native String getHint(String name);
|
||||||
|
|
||||||
public static void flipBuffers() {
|
public static void flipBuffers() {
|
||||||
SDLActivity.nativeFlipBuffers();
|
SDLActivity.nativeFlipBuffers();
|
||||||
|
@ -496,6 +501,27 @@ public class SDLActivity extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// APK extension files support
|
||||||
|
private ZipResourceFile expansionFile = null;
|
||||||
|
|
||||||
|
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.parseInt(getHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
|
||||||
|
Integer patchVersion = Integer.parseInt(getHint("SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"));
|
||||||
|
|
||||||
|
expansionFile = APKExpansionSupport.getAPKExpansionZipFile(this, mainVersion, patchVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get an input stream for a known file inside the expansion file ZIPs
|
||||||
|
InputStream fileStream = expansionFile.getInputStream(fileName);
|
||||||
|
|
||||||
|
if (fileStream == null) {
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileStream;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -435,6 +435,16 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
#define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES "SDL_VIDEO_MAC_FULLSCREEN_SPACES"
|
#define SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES "SDL_VIDEO_MAC_FULLSCREEN_SPACES"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Android APK expansion main file version. Should be a string number like "1", "2" etc.
|
||||||
|
*/
|
||||||
|
#define SDL_HINT_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION "SDL_ANDROID_APK_EXPANSION_MAIN_FILE_VERSION"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Android APK expansion patch file version. Should be a string number like "1", "2" etc.
|
||||||
|
*/
|
||||||
|
#define SDL_HINT_ANDROID_APK_EXPANSION_PATCH_FILE_VERSION "SDL_ANDROID_APK_EXPANSION_MAIN_PATCH_VERSION"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief An enumeration of hint priorities
|
* \brief An enumeration of hint priorities
|
||||||
|
|
|
@ -385,7 +385,15 @@ void Java_org_libsdl_app_SDLInputConnection_nativeSetComposingText(
|
||||||
(*env)->ReleaseStringUTFChars(env, text, utftext);
|
(*env)->ReleaseStringUTFChars(env, text, utftext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jstring Java_org_libsdl_app_SDLActivity_getHint(JNIEnv* env, jclass cls, jstring name) {
|
||||||
|
const char *utfname = (*env)->GetStringUTFChars(env, name, NULL);
|
||||||
|
const char *hint = SDL_GetHint(utfname);
|
||||||
|
|
||||||
|
jstring result = (*env)->NewStringUTF(env, hint);
|
||||||
|
(*env)->ReleaseStringUTFChars(env, name, utfname);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
Functions called by SDL into Java
|
Functions called by SDL into Java
|
||||||
|
@ -758,7 +766,14 @@ fallback:
|
||||||
"open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
|
"open", "(Ljava/lang/String;I)Ljava/io/InputStream;");
|
||||||
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
|
inputStream = (*mEnv)->CallObjectMethod(mEnv, assetManager, mid, fileNameJString, 1 /* ACCESS_RANDOM */);
|
||||||
if (Android_JNI_ExceptionOccurred(false)) {
|
if (Android_JNI_ExceptionOccurred(false)) {
|
||||||
goto failure;
|
// Try fallback to APK Extension files
|
||||||
|
mid = (*mEnv)->GetMethodID(mEnv, (*mEnv)->GetObjectClass(mEnv, context),
|
||||||
|
"openAPKExtensionInputStream", "(Ljava/lang/String;)Ljava/io/InputStream;");
|
||||||
|
inputStream = (*mEnv)->CallObjectMethod(mEnv, context, mid, fileNameJString);
|
||||||
|
|
||||||
|
if (Android_JNI_ExceptionOccurred(false)) {
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->hidden.androidio.inputStreamRef = (*mEnv)->NewGlobalRef(mEnv, inputStream);
|
ctx->hidden.androidio.inputStreamRef = (*mEnv)->NewGlobalRef(mEnv, inputStream);
|
||||||
|
|
Loading…
Reference in New Issue