mirror of
https://github.com/spiffcode/hostile-takeover.git
synced 2026-04-17 20:51:26 -06:00
Add Android jni method for obtaining the AssetManager
This commit is contained in:
parent
5d7e0ddf3c
commit
6b9241fbc5
@ -1,6 +1,8 @@
|
||||
#include <jni.h>
|
||||
#include <sys/stat.h>
|
||||
#include <android/log.h>
|
||||
#include <android/asset_manager.h>
|
||||
#include <android/asset_manager_jni.h>
|
||||
#include <sys/stat.h>
|
||||
#include "game/sdl/hosthelpers.h"
|
||||
#include "base/thread.h"
|
||||
#include "game/sdl/sdlhttpservice.h"
|
||||
@ -24,6 +26,7 @@ static jmethodID initiateAskMethod;
|
||||
static jmethodID initiateWebViewMethod;
|
||||
static jmethodID getAskStringMethod;
|
||||
static jmethodID getPlatformStringMethod;
|
||||
static jmethodID getAssetManagerMethod;
|
||||
|
||||
namespace wi {
|
||||
|
||||
@ -35,6 +38,7 @@ char gszSaveGamesDir[PATH_MAX]; // saved games
|
||||
char gszPrefsFilename[PATH_MAX]; // game prefs
|
||||
char gszCompletesDir[PATH_MAX]; // for "mission completed" tracking
|
||||
HttpService *gphttp;
|
||||
AAssetManager *gassetmgr;
|
||||
|
||||
IChatController *g_pchat;
|
||||
|
||||
@ -73,6 +77,7 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
getAskStringMethod = env->GetStaticMethodID(NativeLibClass, "getAskString", "()Ljava/lang/String;");
|
||||
initiateAskMethod = env->GetStaticMethodID(NativeLibClass, "initiateAsk", "(Ljava/lang/String;ILjava/lang/String;II)V");
|
||||
getPlatformStringMethod = env->GetStaticMethodID(NativeLibClass, "getPlatformString", "()Ljava/lang/String;");
|
||||
getAssetManagerMethod = env->GetStaticMethodID(NativeLibClass, "getAssetManager", "()Landroid/content/res/AssetManager;");
|
||||
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
@ -109,7 +114,10 @@ bool HostHelpers::Init() {
|
||||
// Get the app's data path from Java
|
||||
jobject path = g_env->CallStaticObjectMethod(NativeLibClass, getDataDirMethod);
|
||||
const char* dataDir = g_env->GetStringUTFChars((jstring)path, NULL);
|
||||
sprintf(gszMainDataDir, "%s", dataDir);
|
||||
|
||||
// Get the asset manager
|
||||
jobject jam = g_env->CallStaticObjectMethod(NativeLibClass, getAssetManagerMethod);
|
||||
gassetmgr = AAssetManager_fromJava(g_env, jam);
|
||||
|
||||
// Set the directory paths
|
||||
sprintf(gszTempDir, "%s/tmp", gszMainDataDir);
|
||||
|
||||
@ -57,6 +57,8 @@ public class GameActivity extends SDLActivity {
|
||||
NativeLib.screenHeight = metrics.heightPixels;
|
||||
NativeLib.screenDPI = metrics.densityDpi;
|
||||
|
||||
NativeLib.assetManager = getResources().getAssets();
|
||||
|
||||
// App data path
|
||||
NativeLib.gameDataPath = getApplication().getApplicationContext().getFilesDir().getAbsolutePath();
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ package com.spiffcode.ht;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.AssetManager;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.text.InputFilter;
|
||||
@ -16,6 +17,7 @@ public class NativeLib {
|
||||
public static int screenWidth; // in pixels
|
||||
public static int screenHeight; // in pixels
|
||||
public static int screenDPI; // in dpi
|
||||
public static AssetManager assetManager;
|
||||
public static String askString; // string from user input dialog
|
||||
public static GameActivity gameActivity; // A link back to our main gameActivity class instance
|
||||
public static ChatController chatc;
|
||||
@ -46,6 +48,10 @@ public class NativeLib {
|
||||
return screenDPI;
|
||||
}
|
||||
|
||||
static AssetManager getAssetManager() {
|
||||
return assetManager;
|
||||
}
|
||||
|
||||
static String getAndroidID() {
|
||||
return Secure.getString(GameActivity.getContext().getContentResolver(), Secure.ANDROID_ID);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user