diff --git a/project/java/Accelerometer.java b/project/java/Accelerometer.java index 0afdf8d43..8b0d30e94 100644 --- a/project/java/Accelerometer.java +++ b/project/java/Accelerometer.java @@ -1,6 +1,6 @@ /* Simple DirectMedia Layer -Java source code (C) 2009-2011 Sergii Pylypenko +Java source code (C) 2009-2012 Sergii Pylypenko This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/project/java/Audio.java b/project/java/Audio.java index df3c75cea..faa464d68 100644 --- a/project/java/Audio.java +++ b/project/java/Audio.java @@ -1,6 +1,6 @@ /* Simple DirectMedia Layer -Java source code (C) 2009-2011 Sergii Pylypenko +Java source code (C) 2009-2012 Sergii Pylypenko This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/project/java/DataDownloader.java b/project/java/DataDownloader.java index e50a9eb58..153128f7a 100644 --- a/project/java/DataDownloader.java +++ b/project/java/DataDownloader.java @@ -1,6 +1,6 @@ /* Simple DirectMedia Layer -Java source code (C) 2009-2011 Sergii Pylypenko +Java source code (C) 2009-2012 Sergii Pylypenko This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -122,6 +122,9 @@ class CountingInputStream extends BufferedInputStream { class DataDownloader extends Thread { + + public static final String DOWNLOAD_FLAG_FILENAME = "libsdl-DownloadFinished-"; + class StatusWriter { private TextView Status; @@ -200,7 +203,7 @@ class DataDownloader extends Thread ( Globals.OptionalDataDownload.length > i && Globals.OptionalDataDownload[i] ) || ( Globals.OptionalDataDownload.length <= i && downloadFiles[i].indexOf("!") == 0 ) ) { - if( ! DownloadDataFile(downloadFiles[i], "libsdl-DownloadFinished-" + String.valueOf(i) + ".flag", count+1, total) ) + if( ! DownloadDataFile(downloadFiles[i], DOWNLOAD_FLAG_FILENAME + String.valueOf(i) + ".flag", count+1, total) ) { DownloadFailed = true; return; @@ -604,6 +607,8 @@ class DataDownloader extends Thread private static DefaultHttpClient HttpWithDisabledSslCertCheck() { + return new DefaultHttpClient(); + // This code does not work /* HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER; @@ -619,8 +624,7 @@ class DataDownloader extends Thread HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); return http; - */ - return new DefaultHttpClient(); + */ } public StatusWriter Status; diff --git a/project/java/Globals.java b/project/java/Globals.java index 576ca1aae..48a6bf3a8 100644 --- a/project/java/Globals.java +++ b/project/java/Globals.java @@ -1,6 +1,6 @@ /* Simple DirectMedia Layer -Java source code (C) 2009-2011 Sergii Pylypenko +Java source code (C) 2009-2012 Sergii Pylypenko This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/project/java/Keycodes.java b/project/java/Keycodes.java index 26716142e..39ea6aaba 100644 --- a/project/java/Keycodes.java +++ b/project/java/Keycodes.java @@ -1,6 +1,6 @@ /* Simple DirectMedia Layer -Java source code (C) 2009-2011 Sergii Pylypenko +Java source code (C) 2009-2012 Sergii Pylypenko This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/project/java/MainActivity.java b/project/java/MainActivity.java index dbd0fb280..09e2a01fb 100644 --- a/project/java/MainActivity.java +++ b/project/java/MainActivity.java @@ -1,6 +1,6 @@ /* Simple DirectMedia Layer -Java source code (C) 2009-2011 Sergii Pylypenko +Java source code (C) 2009-2012 Sergii Pylypenko This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages diff --git a/project/java/Settings.java b/project/java/Settings.java index 0529274f0..0c3d99b5c 100644 --- a/project/java/Settings.java +++ b/project/java/Settings.java @@ -1,6 +1,6 @@ /* Simple DirectMedia Layer -Java source code (C) 2009-2011 Sergii Pylypenko +Java source code (C) 2009-2012 Sergii Pylypenko This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages @@ -206,7 +206,6 @@ class Settings // ICS update sends events in a proper way Globals.RemapHwKeycode[112] = SDL_1_2_Keycodes.SDLK_UNKNOWN; } - try { ObjectInputStream settingsFile = new ObjectInputStream(new FileInputStream( p.getFilesDir().getAbsolutePath() + "/" + SettingsFileName )); @@ -325,30 +324,25 @@ class Settings } catch ( IOException e ) {}; if( Globals.DataDir.length() == 0 ) - Globals.DataDir = Globals.DownloadToSdcard ? - Environment.getExternalStorageDirectory().getAbsolutePath() + "/app-data/" + Globals.class.getPackage().getName() : - p.getFilesDir().getAbsolutePath(); - - // 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; + if( !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) ) + { + System.out.println("libSDL: SD card or external storage is not mounted (state " + Environment.getExternalStorageState() + "), switching to the internal storage."); + Globals.DownloadToSdcard = false; + } + Globals.DataDir = Globals.DownloadToSdcard ? + SdcardAppPath.get().path(p) : + p.getFilesDir().getAbsolutePath(); + if( Globals.DownloadToSdcard ) + { + // Check if data already installed into deprecated location at /sdcard/app-data/ + String[] fileList = new File(SdcardAppPath.deprecatedPath(p)).list(); + if( fileList != null ) + for( String s: fileList ) + if( s.toUpperCase().startsWith(DataDownloader.DOWNLOAD_FLAG_FILENAME.toUpperCase()) ) + Globals.DataDir = SdcardAppPath.deprecatedPath(p); + } } - - 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" ) ); - */ System.out.println("libSDL: Settings.Load(): loading settings failed, running config dialog"); p.setUpStatusLabel(); @@ -2541,6 +2535,45 @@ class Settings } } } + + abstract static class SdcardAppPath + { + public static SdcardAppPath get() + { + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO) + return Froyo.Holder.sInstance; + else + return Dummy.Holder.sInstance; + } + public abstract String path(final Context p); + public static String deprecatedPath(final Context p) + { + return Environment.getExternalStorageDirectory().getAbsolutePath() + "/app-data/" + p.getPackageName(); + } + + private static class Froyo extends SdcardAppPath + { + private static class Holder + { + private static final Froyo sInstance = new Froyo(); + } + public String path(final Context p) + { + return p.getExternalFilesDir(null).getAbsolutePath(); + } + } + private static class Dummy extends SdcardAppPath + { + private static class Holder + { + private static final Dummy sInstance = new Dummy(); + } + public String path(final Context p) + { + return Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + p.getPackageName() + "/files"; + } + } + } private static native void nativeSetTrackballUsed(); private static native void nativeSetTrackballDampening(int value); diff --git a/project/java/Video.java b/project/java/Video.java index 2576eee91..e1a649a6a 100644 --- a/project/java/Video.java +++ b/project/java/Video.java @@ -1,6 +1,6 @@ /* Simple DirectMedia Layer -Java source code (C) 2009-2011 Sergii Pylypenko +Java source code (C) 2009-2012 Sergii Pylypenko This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages