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:
pelya
2010-07-23 15:11:41 +03:00
parent 32fbf19b84
commit 7580d9ff0f
8 changed files with 139 additions and 27 deletions

View File

@@ -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 )

View File

@@ -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();

View 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);
}

View File

@@ -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);