// This string is autogenerated by ChangeAppSettings.sh, do not change spaces amount package com.googlecode.opentyrian; 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; import android.content.res.Configuration; import android.os.Environment; import android.os.StatFs; class Settings { static String SettingsFileName = "libsdl-settings.cfg"; static void Save(final MainActivity p) { try { ObjectOutputStream out = new ObjectOutputStream(p.openFileOutput( SettingsFileName, p.MODE_WORLD_READABLE )); out.writeBoolean(Globals.DownloadToSdcard); out.writeBoolean(Globals.PhoneHasArrowKeys); out.writeBoolean(Globals.PhoneHasTrackball); out.writeBoolean(Globals.UseAccelerometerAsArrowKeys); out.writeBoolean(Globals.UseTouchscreenKeyboard); out.close(); } catch( FileNotFoundException e ) { } catch( SecurityException e ) { } catch ( IOException e ) {}; } static void Load( final MainActivity p ) { try { ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName )); Globals.DownloadToSdcard = settingsFile.readBoolean(); Globals.PhoneHasArrowKeys = settingsFile.readBoolean(); Globals.PhoneHasTrackball = settingsFile.readBoolean(); Globals.UseAccelerometerAsArrowKeys = settingsFile.readBoolean(); Globals.UseTouchscreenKeyboard = settingsFile.readBoolean(); startDownloader(p); return; } catch( FileNotFoundException e ) { } catch( SecurityException e ) { } catch ( IOException e ) {}; // This code fails for both of my phones! /* Configuration c = new Configuration(); c.setToDefaults(); if( c.navigation == Configuration.NAVIGATION_TRACKBALL || c.navigation == Configuration.NAVIGATION_DPAD || c.navigation == Configuration.NAVIGATION_WHEEL ) { Globals.AppNeedsArrowKeys = false; } System.out.println( "libSDL: Phone keypad type: " + ( c.navigation == Configuration.NAVIGATION_TRACKBALL ? "Trackball" : c.navigation == Configuration.NAVIGATION_DPAD ? "Dpad" : c.navigation == Configuration.NAVIGATION_WHEEL ? "Wheel" : c.navigation == Configuration.NAVIGATION_NONAV ? "None" : "Unknown" ) ); */ long freeSdcard = 0; long freePhone = 0; try { StatFs sdcard = new StatFs(Environment.getExternalStorageDirectory().getPath()); StatFs phone = new StatFs(Environment.getDataDirectory().getPath()); freeSdcard = (long)sdcard.getAvailableBlocks() * sdcard.getBlockSize() / 1024 / 1024; freePhone = (long)phone.getAvailableBlocks() * phone.getBlockSize() / 1024 / 1024; }catch(Exception e) {} final CharSequence[] items = {"Phone storage - " + String.valueOf(freePhone) + " Mb free", "SD card - " + String.valueOf(freeSdcard) + " Mb free"}; 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); dialog.dismiss(); showKeyboardConfig(p); } }); AlertDialog alert = builder.create(); alert.setOwnerActivity(p); alert.show(); }; static void showKeyboardConfig(final MainActivity p) { if( ! Globals.AppNeedsArrowKeys ) { Save(p); startDownloader(p); return; } final CharSequence[] items = {"Arrows / joystick / dpad", "Trackball", "None, only touchscreen"}; AlertDialog.Builder builder = new AlertDialog.Builder(p); builder.setTitle("What kind of navigation keys does your phone have?"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Globals.PhoneHasArrowKeys = (item == 0); Globals.PhoneHasTrackball = (item == 1); dialog.dismiss(); showAdditionalInputConfig(p); } }); AlertDialog alert = builder.create(); alert.setOwnerActivity(p); alert.show(); } static void showAdditionalInputConfig(final MainActivity p) { final CharSequence[] items = { "On-screen keyboard" + ( Globals.AppUsesMouse ? " (disables mouse input)" : ""), "Accelerometer as navigation keys" + ( Globals.AppUsesJoystick ? " (disables joystick input)" : "" ), "Both accelerometer and on-screen keyboard", "No additional controls" + ( Globals.AppNeedsArrowKeys ? " (you won't be able to play without arrow keys)" : " (only if your phone has enough buttons)") }; AlertDialog.Builder builder = new AlertDialog.Builder(p); builder.setTitle("Additional controls to use"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Globals.UseTouchscreenKeyboard = (item == 0 || item == 2); Globals.UseAccelerometerAsArrowKeys = (item == 1 || item == 2); Save(p); dialog.dismiss(); startDownloader(p); } }); AlertDialog alert = builder.create(); alert.setOwnerActivity(p); alert.show(); } static void Apply() { nativeIsSdcardUsed( Globals.DownloadToSdcard ? 1 : 0 ); if( Globals.PhoneHasTrackball ) nativeSetTrackballUsed(); if( Globals.AppUsesMouse ) nativeSetMouseUsed(); if( Globals.AppUsesJoystick && !Globals.UseAccelerometerAsArrowKeys ) nativeSetJoystickUsed(); if( Globals.AppUsesMultitouch ) nativeSetMultitouchUsed(); if( Globals.UseTouchscreenKeyboard ) { nativeSetTouchscreenKeyboardUsed(); nativeSetupScreenKeyboard(0, 4); } } 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 void nativeIsSdcardUsed(int flag); private static native void nativeSetTrackballUsed(); private static native void nativeSetMouseUsed(); private static native void nativeSetJoystickUsed(); private static native void nativeSetMultitouchUsed(); private static native void nativeSetTouchscreenKeyboardUsed(); private static native void nativeSetupScreenKeyboard(int size, int nbuttons); }