Added simple app settings dialog - it will ask you where to download app data (SD Card or phone storage), later I'll maybe add other options
This commit is contained in:
@@ -3,7 +3,6 @@ AppName="Alien Blaster"
|
||||
AppFullName=de.schwardtnet.alienblaster
|
||||
ScreenOrientation=h
|
||||
AppDataDownloadUrl="http://sites.google.com/site/xpelyax/Home/alienblaster110_data.zip?attredirects=0&d=1|http://sitesproxy.goapk.com/site/xpelyax/Home/alienblaster110_data.zip"
|
||||
DownloadToSdcard=n
|
||||
SdlVideoResize=y
|
||||
NeedDepthBuffer=n
|
||||
MultiABI=n
|
||||
|
||||
@@ -36,12 +36,6 @@ if [ -n "$var" ] ; then
|
||||
AppDataDownloadUrl="$var"
|
||||
fi
|
||||
|
||||
echo -n "\nSpecify if application data should be saved to SD Card (y) or (n),\nsay (y) if app data is bigger than 5 megabytes ($DownloadToSdcard): "
|
||||
read var
|
||||
if [ -n "$var" ] ; then
|
||||
DownloadToSdcard="$var"
|
||||
fi
|
||||
|
||||
echo -n "\nApplication window should be resized to fit into 480x320 screen (y) or (n) ($SdlVideoResize): "
|
||||
read var
|
||||
if [ -n "$var" ] ; then
|
||||
@@ -114,7 +108,6 @@ echo AppName=\"$AppName\" >> AppSettings.cfg
|
||||
echo AppFullName=$AppFullName >> AppSettings.cfg
|
||||
echo ScreenOrientation=$ScreenOrientation >> AppSettings.cfg
|
||||
echo AppDataDownloadUrl=\"$AppDataDownloadUrl\" >> AppSettings.cfg
|
||||
echo DownloadToSdcard=$DownloadToSdcard >> AppSettings.cfg
|
||||
echo SdlVideoResize=$SdlVideoResize >> AppSettings.cfg
|
||||
echo NeedDepthBuffer=$NeedDepthBuffer >> AppSettings.cfg
|
||||
echo MultiABI=$MultiABI >> AppSettings.cfg
|
||||
@@ -125,12 +118,7 @@ echo AppCflags=\'$AppCflags\' >> AppSettings.cfg
|
||||
echo ReadmeText=\'$ReadmeText\' >> AppSettings.cfg
|
||||
|
||||
AppShortName=`echo $AppName | sed 's/ //g'`
|
||||
DataPath="/data/data/$AppFullName/files"
|
||||
DownloadToSdcard1=false
|
||||
if [ "$DownloadToSdcard" = "y" ] ; then
|
||||
DownloadToSdcard1=true
|
||||
DataPath="/sdcard/$AppShortName"
|
||||
fi
|
||||
DataPath="$AppFullName"
|
||||
AppFullNameUnderscored=`echo $AppFullName | sed 's/[.]/_/g'`
|
||||
AppSharedLibrariesPath=/data/data/$AppFullName/lib
|
||||
ScreenOrientation1=portrait
|
||||
@@ -189,7 +177,6 @@ echo Patching project/src/Globals.java
|
||||
cat project/src/Globals.java | \
|
||||
sed "s/public static String ApplicationName = .*;/public static String ApplicationName = \"$AppShortName\";/" | \
|
||||
sed "s^public static String DataDownloadUrl = \".*\";^public static String DataDownloadUrl = \"$AppDataDownloadUrl1\";^" | \
|
||||
sed "s/public static boolean DownloadToSdcard = .*;/public static boolean DownloadToSdcard = $DownloadToSdcard1;/" | \
|
||||
sed "s/public static boolean NeedDepthBuffer = .*;/public static boolean NeedDepthBuffer = $NeedDepthBuffer;/" | \
|
||||
sed "s/public static boolean HorizontalOrientation = .*;/public static boolean HorizontalOrientation = $HorizontalOrientation;/" | \
|
||||
sed "s%public static String ReadmeText = .*%public static String ReadmeText = \"$ReadmeText\".replace(\"^\",\"\\\n\");%" | \
|
||||
|
||||
@@ -10,7 +10,7 @@ SDL_JAVA_PACKAGE_PATH := de_schwardtnet_alienblaster
|
||||
# Typically /sdcard/alienblaster
|
||||
# Or /data/data/de.schwardtnet.alienblaster/files if you're planning to unpack data in application private folder
|
||||
# Your application will just set current directory there
|
||||
SDL_CURDIR_PATH := /data/data/de.schwardtnet.alienblaster/files
|
||||
SDL_CURDIR_PATH := de.schwardtnet.alienblaster
|
||||
|
||||
# Android Dev Phone G1 has trackball instead of cursor keys, and
|
||||
# sends trackball movement events as rapid KeyDown/KeyUp events,
|
||||
|
||||
@@ -22,12 +22,27 @@
|
||||
#define JAVA_EXPORT_NAME1(name,package) JAVA_EXPORT_NAME2(name,package)
|
||||
#define JAVA_EXPORT_NAME(name) JAVA_EXPORT_NAME1(name,SDL_JAVA_PACKAGE_PATH)
|
||||
|
||||
|
||||
static int isSdcardUsed = 0;
|
||||
|
||||
extern C_LINKAGE void
|
||||
JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
int argc = 1;
|
||||
char * argv[] = { "sdl" };
|
||||
chdir(SDL_CURDIR_PATH);
|
||||
char curdir[512];
|
||||
if( isSdcardUsed )
|
||||
{
|
||||
strcpy(curdir, "/sdcard");
|
||||
strcat(curdir, SDL_CURDIR_PATH);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(curdir, "/data/data/");
|
||||
strcat(curdir, SDL_CURDIR_PATH);
|
||||
strcat(curdir, "/files");
|
||||
}
|
||||
chdir(curdir);
|
||||
/*
|
||||
__android_log_print(ANDROID_LOG_INFO, "libSDL", "Waiting 30s for debugger");
|
||||
sleep(30); // Wait for debugger to attach
|
||||
@@ -36,6 +51,12 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInit) ( JNIEnv* env, jobject thiz )
|
||||
main( argc, argv );
|
||||
};
|
||||
|
||||
extern C_LINKAGE void
|
||||
JAVA_EXPORT_NAME(Settings_nativeIsSdcardUsed) ( JNIEnv* env, jobject thiz, jint flag )
|
||||
{
|
||||
isSdcardUsed = flag;
|
||||
}
|
||||
|
||||
#undef JAVA_EXPORT_NAME
|
||||
#undef JAVA_EXPORT_NAME1
|
||||
#undef JAVA_EXPORT_NAME2
|
||||
|
||||
@@ -89,6 +89,7 @@ class DataDownloader extends Thread
|
||||
{
|
||||
private TextView Status;
|
||||
private MainActivity Parent;
|
||||
private String oldText = "";
|
||||
|
||||
public StatusWriter( TextView _Status, MainActivity _Parent )
|
||||
{
|
||||
@@ -100,6 +101,7 @@ class DataDownloader extends Thread
|
||||
synchronized(DataDownloader.this) {
|
||||
Status = _Status;
|
||||
Parent = _Parent;
|
||||
setText( oldText );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +118,7 @@ class DataDownloader extends Thread
|
||||
}
|
||||
synchronized(DataDownloader.this) {
|
||||
Callback cb = new Callback();
|
||||
oldText = new String(str);
|
||||
cb.text = new String(str);
|
||||
cb.Status = Status;
|
||||
if( Parent != null && Status != null )
|
||||
|
||||
@@ -25,11 +25,18 @@ public class MainActivity extends Activity {
|
||||
_tv = new TextView(this);
|
||||
_tv.setText("Initializing");
|
||||
setContentView(_tv);
|
||||
if( downloader == null )
|
||||
downloader = new DataDownloader(this, _tv);
|
||||
|
||||
Settings.Load(this);
|
||||
|
||||
mLoadLibraryStub = new LoadLibrary();
|
||||
mAudioThread = new AudioThread(this);
|
||||
}
|
||||
|
||||
public void startDownloader()
|
||||
{
|
||||
if( downloader == null )
|
||||
downloader = new DataDownloader(this, _tv);
|
||||
}
|
||||
|
||||
public void initSDL()
|
||||
{
|
||||
@@ -49,8 +56,10 @@ public class MainActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
synchronized( downloader ) {
|
||||
downloader.setParent(null, null);
|
||||
if( downloader != null ) {
|
||||
synchronized( downloader ) {
|
||||
downloader.setParent(null, null);
|
||||
}
|
||||
}
|
||||
// TODO: if application pauses it's screen is messed up
|
||||
if( wakeLock != null )
|
||||
@@ -67,18 +76,22 @@ public class MainActivity extends Activity {
|
||||
super.onResume();
|
||||
if( mGLView != null )
|
||||
mGLView.onResume();
|
||||
synchronized( downloader ) {
|
||||
downloader.setParent(this, _tv);
|
||||
if( downloader.DownloadComplete )
|
||||
initSDL();
|
||||
if( downloader != null ) {
|
||||
synchronized( downloader ) {
|
||||
downloader.setParent(this, _tv);
|
||||
if( downloader.DownloadComplete )
|
||||
initSDL();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
synchronized( downloader ) {
|
||||
downloader.setParent(null, null);
|
||||
if( downloader != null ) {
|
||||
synchronized( downloader ) {
|
||||
downloader.setParent(null, null);
|
||||
}
|
||||
}
|
||||
if( wakeLock != null )
|
||||
wakeLock.release();
|
||||
|
||||
88
alienblaster/project/src/Settings.java
Normal file
88
alienblaster/project/src/Settings.java
Normal file
@@ -0,0 +1,88 @@
|
||||
// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount
|
||||
package de.schwardtnet.alienblaster;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import android.util.Log;
|
||||
import java.io.*;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
|
||||
class Settings
|
||||
{
|
||||
static String SettingsFileName = "libsdl-settings.cfg";
|
||||
static void Load( final MainActivity p )
|
||||
{
|
||||
try {
|
||||
ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName ));
|
||||
Globals.DownloadToSdcard = settingsFile.readBoolean();
|
||||
|
||||
startDownloader(p);
|
||||
return;
|
||||
} catch( FileNotFoundException e ) {
|
||||
} catch( SecurityException e ) {
|
||||
} catch ( IOException e ) {};
|
||||
|
||||
final CharSequence[] items = {"Phone storage", "SD card"};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(p);
|
||||
builder.setTitle("Where to download application data");
|
||||
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int item)
|
||||
{
|
||||
Globals.DownloadToSdcard = (item == 1);
|
||||
|
||||
Save(p);
|
||||
dialog.dismiss();
|
||||
startDownloader(p);
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.setOwnerActivity(p);
|
||||
alert.show();
|
||||
|
||||
};
|
||||
|
||||
static void Save(final MainActivity p)
|
||||
{
|
||||
try {
|
||||
ObjectOutputStream out = new ObjectOutputStream(p.openFileOutput( SettingsFileName, p.MODE_WORLD_READABLE ));
|
||||
out.writeBoolean(Globals.DownloadToSdcard);
|
||||
out.close();
|
||||
} catch( FileNotFoundException e ) {
|
||||
} catch( SecurityException e ) {
|
||||
} catch ( IOException e ) {};
|
||||
}
|
||||
|
||||
|
||||
static void Apply()
|
||||
{
|
||||
nativeIsSdcardUsed( Globals.DownloadToSdcard ? 1 : 0 );
|
||||
}
|
||||
|
||||
static void startDownloader(MainActivity p)
|
||||
{
|
||||
class Callback implements Runnable
|
||||
{
|
||||
public MainActivity Parent;
|
||||
public void run()
|
||||
{
|
||||
Parent.startDownloader();
|
||||
}
|
||||
}
|
||||
Callback cb = new Callback();
|
||||
cb.Parent = p;
|
||||
p.runOnUiThread(cb);
|
||||
};
|
||||
|
||||
|
||||
private static native int nativeIsSdcardUsed(int flag);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer {
|
||||
|
||||
System.loadLibrary("application");
|
||||
System.loadLibrary("sdl_main");
|
||||
Settings.Apply();
|
||||
|
||||
nativeInit(); // Calls main() and never returns, hehe - we'll call eglSwapBuffers() from native code
|
||||
System.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user