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:
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user