From 98ca741ca07c346cda3c6dcd81100fac59cc54ee Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 29 Nov 2013 01:35:56 +0100 Subject: [PATCH] (Android) Should be backwards compatible with Android 2.3.x again - 2.3.x now uses RetroActivityPast --- android/phoenix/AndroidManifest.xml | 6 +- .../retroarch/browser/HistorySelection.java | 12 +- ...Activity.java => RetroActivityFuture.java} | 4 +- .../retroarch/browser/RetroActivityPast.java | 115 ++++++++++++++++++ .../browser/mainmenu/MainMenuFragment.java | 16 ++- 5 files changed, 147 insertions(+), 6 deletions(-) rename android/phoenix/src/com/retroarch/browser/{RetroActivity.java => RetroActivityFuture.java} (97%) create mode 100644 android/phoenix/src/com/retroarch/browser/RetroActivityPast.java diff --git a/android/phoenix/AndroidManifest.xml b/android/phoenix/AndroidManifest.xml index ae9207f611..ad4cacef8f 100644 --- a/android/phoenix/AndroidManifest.xml +++ b/android/phoenix/AndroidManifest.xml @@ -30,7 +30,11 @@ - + + + + + diff --git a/android/phoenix/src/com/retroarch/browser/HistorySelection.java b/android/phoenix/src/com/retroarch/browser/HistorySelection.java index 762f2af2bd..155f2b1622 100644 --- a/android/phoenix/src/com/retroarch/browser/HistorySelection.java +++ b/android/phoenix/src/com/retroarch/browser/HistorySelection.java @@ -11,6 +11,7 @@ import com.retroarch.browser.mainmenu.MainMenuActivity; import com.retroarch.browser.preferences.util.UserPreferences; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.provider.Settings; import android.support.v4.app.DialogFragment; @@ -32,6 +33,15 @@ public final class HistorySelection extends DialogFragment { private FragmentActivity ctx; private IconAdapter adapter; + + public Intent getRetroActivity() + { + if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)) + { + return new Intent(ctx, RetroActivityFuture.class); + } + return new Intent(ctx, RetroActivityPast.class); + } /** * Creates a statically instantiated instance of HistorySelection. @@ -111,7 +121,7 @@ public final class HistorySelection extends DialogFragment String current_ime = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); Toast.makeText(ctx, String.format(getString(R.string.loading_gamepath), gamePath), Toast.LENGTH_SHORT).show(); - Intent retro = new Intent(ctx, RetroActivity.class); + Intent retro = getRetroActivity(); retro.putExtra("ROM", gamePath); retro.putExtra("LIBRETRO", corePath); retro.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(ctx)); diff --git a/android/phoenix/src/com/retroarch/browser/RetroActivity.java b/android/phoenix/src/com/retroarch/browser/RetroActivityFuture.java similarity index 97% rename from android/phoenix/src/com/retroarch/browser/RetroActivity.java rename to android/phoenix/src/com/retroarch/browser/RetroActivityFuture.java index abb072ee3d..9cb7eaae95 100644 --- a/android/phoenix/src/com/retroarch/browser/RetroActivity.java +++ b/android/phoenix/src/com/retroarch/browser/RetroActivityFuture.java @@ -13,7 +13,9 @@ import android.hardware.Camera; import android.os.Build; import android.util.Log; -public final class RetroActivity extends NativeActivity +//For Android 3.0 and up + +public final class RetroActivityFuture extends NativeActivity { private Camera mCamera; private long lastTimestamp = 0; diff --git a/android/phoenix/src/com/retroarch/browser/RetroActivityPast.java b/android/phoenix/src/com/retroarch/browser/RetroActivityPast.java new file mode 100644 index 0000000000..9ed09cc3c2 --- /dev/null +++ b/android/phoenix/src/com/retroarch/browser/RetroActivityPast.java @@ -0,0 +1,115 @@ +package com.retroarch.browser; + +import java.io.IOException; + +import com.retroarch.browser.mainmenu.MainMenuActivity; +import com.retroarch.browser.preferences.util.UserPreferences; + +import android.annotation.SuppressLint; +import android.app.NativeActivity; +import android.content.Intent; +import android.util.Log; + +// For Android 2.3.x + +public final class RetroActivityPast extends NativeActivity +{ + private Intent pendingIntent = null; + + public void onCameraStart() + { + } + + public void onCameraStop() + { + } + + public void onCameraInit() + { + } + + public boolean onCameraPoll() + { + return false; + } + + public void onCameraFree() + { + } + + @SuppressLint("NewApi") + public void onCameraTextureInit(int gl_texid) + { + } + + @SuppressLint("NewApi") + public void onCameraSetTexture(int gl_texid) throws IOException + { + } + + @Override + public void onDestroy() + { + UserPreferences.readbackConfigFile(this); + } + + @Override + public void onLowMemory() + { + } + + @Override + public void onTrimMemory(int level) + { + } + + @Override + public void onNewIntent(Intent intent) + { + Log.i("RetroActivity", "onNewIntent invoked."); + super.onNewIntent(intent); + setIntent(intent); + pendingIntent = intent; + } + + public String getPendingIntentFullPath() + { + return pendingIntent.getStringExtra("ROM"); + } + + public String getPendingIntentLibretroPath() + { + return pendingIntent.getStringExtra("LIBRETRO"); + } + + public String getPendingIntentConfigPath() + { + return pendingIntent.getStringExtra("CONFIGFILE"); + } + + public String getPendingIntentIME() + { + return pendingIntent.getStringExtra("IME"); + } + + public boolean hasPendingIntent() + { + if (pendingIntent == null) + return false; + return true; + } + + public void clearPendingIntent() + { + pendingIntent = null; + } + + @Override + public void onBackPressed() + { + Log.i("RetroActivity", "onBackKeyPressed"); + Intent retro = new Intent(this, MainMenuActivity.class); + retro.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(retro); + } +} diff --git a/android/phoenix/src/com/retroarch/browser/mainmenu/MainMenuFragment.java b/android/phoenix/src/com/retroarch/browser/mainmenu/MainMenuFragment.java index 99aa4218ef..fca6130598 100644 --- a/android/phoenix/src/com/retroarch/browser/mainmenu/MainMenuFragment.java +++ b/android/phoenix/src/com/retroarch/browser/mainmenu/MainMenuFragment.java @@ -28,7 +28,8 @@ import com.retroarch.R; import com.retroarch.browser.CoreSelection; import com.retroarch.browser.HistorySelection; import com.retroarch.browser.NativeInterface; -import com.retroarch.browser.RetroActivity; +import com.retroarch.browser.RetroActivityFuture; +import com.retroarch.browser.RetroActivityPast; import com.retroarch.browser.dirfragment.DirectoryFragment; import com.retroarch.browser.dirfragment.DirectoryFragment.OnDirectoryFragmentClosedListener; import com.retroarch.browser.mainmenu.gplwaiver.GPLWaiverDialogFragment; @@ -42,6 +43,15 @@ public final class MainMenuFragment extends PreferenceListFragment implements On { private static final String TAG = "MainMenuFragment"; private Context ctx; + + public Intent getRetroActivity() + { + if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)) + { + return new Intent(ctx, RetroActivityFuture.class); + } + return new Intent(ctx, RetroActivityPast.class); + } @Override public void onCreate(Bundle savedInstanceState) @@ -337,8 +347,8 @@ public final class MainMenuFragment extends PreferenceListFragment implements On final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); final String libretro_path = prefs.getString("libretro_path", ctx.getApplicationInfo().dataDir + "/cores"); - final Intent retro = new Intent(ctx, RetroActivity.class); final String current_ime = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); + final Intent retro = getRetroActivity(); retro.putExtra("LIBRETRO", libretro_path); retro.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(ctx)); retro.putExtra("IME", current_ime); @@ -397,7 +407,7 @@ public final class MainMenuFragment extends PreferenceListFragment implements On UserPreferences.updateConfigFile(ctx); String current_ime = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD); Toast.makeText(ctx, String.format(getString(R.string.loading_data), path), Toast.LENGTH_SHORT).show(); - Intent retro = new Intent(ctx, RetroActivity.class); + Intent retro = getRetroActivity(); retro.putExtra("ROM", path); retro.putExtra("LIBRETRO", libretro_path); retro.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(ctx));