From fdc65d785146819f3ee842f0b3b75b15ac12ecbf Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 9 Dec 2012 20:32:00 +0100 Subject: [PATCH] (Android) - New phoenix frontend - use startActivityForResult for filebrowsing - Get rid of most PHOENIX_LEGACY ifdefs - code now works for both Phoenix and Phoenix-legacy - Refresh rate auto-configuration should work now on Phoenix - Going to get rid of Phoenix-legacy soon altogether --- android/native/jni/Android.mk | 2 +- android/native/jni/main.c | 8 +--- .../retroarch/browser/DirectoryActivity.java | 8 ++-- .../org/retroarch/browser/ModuleActivity.java | 41 +++++++++++++++++-- settings.c | 2 +- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/android/native/jni/Android.mk b/android/native/jni/Android.mk index 7ffe16fdd3..b36ac2b57f 100644 --- a/android/native/jni/Android.mk +++ b/android/native/jni/Android.mk @@ -49,7 +49,7 @@ ifeq ($(PERF_TEST), 1) LOCAL_CFLAGS += -DPERF_TEST endif -LOCAL_CFLAGS += -O3 -fno-stack-protector -funroll-loops -DNDEBUG -DHAVE_GRIFFIN -DANDROID -DPHOENIX_LEGACY -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_VID_CONTEXT -DHAVE_OPENGLES2 -DGLSL_DEBUG -DHAVE_GLSL -DHAVE_ZLIB -DWANT_RZLIB -DINLINE=inline -DLSB_FIRST -DHAVE_THREAD -D__LIBRETRO__ -DHAVE_CONFIGFILE=1 -DRARCH_PERFORMANCE_MODE -DRARCH_GPU_PERFORMANCE_MODE -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -std=gnu99 +LOCAL_CFLAGS += -O3 -fno-stack-protector -funroll-loops -DNDEBUG -DHAVE_GRIFFIN -DANDROID -DHAVE_DYNAMIC -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_VID_CONTEXT -DHAVE_OPENGLES2 -DGLSL_DEBUG -DHAVE_GLSL -DHAVE_ZLIB -DWANT_RZLIB -DINLINE=inline -DLSB_FIRST -DHAVE_THREAD -D__LIBRETRO__ -DHAVE_CONFIGFILE=1 -DRARCH_PERFORMANCE_MODE -DRARCH_GPU_PERFORMANCE_MODE -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -std=gnu99 LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -landroid -lEGL -lGLESv2 -llog -ldl LOCAL_C_INCLUDES += $(LIBXML_PATH) diff --git a/android/native/jni/main.c b/android/native/jni/main.c index a6cebc9831..f83d1b543f 100644 --- a/android/native/jni/main.c +++ b/android/native/jni/main.c @@ -26,9 +26,7 @@ #include "../../../performance.h" #include "../../../driver.h" -#ifdef PHOENIX_LEGACY #include "../../../config.def.h" -#endif void free_saved_state(struct android_app* android_app) { @@ -338,21 +336,19 @@ static void* android_app_entry(void* param) // Get arguments */ android_get_char_argv(rom_path, sizeof(rom_path), "ROM"); android_get_char_argv(libretro_path, sizeof(libretro_path), "LIBRETRO"); -#ifdef PHOENIX_LEGACY char refreshrate_char[128]; float refreshrate; android_get_char_argv(refreshrate_char,sizeof(refreshrate_char), "REFRESHRATE"); refreshrate = (float)strtod(refreshrate_char, NULL); -#endif RARCH_LOG("Checking arguments passed...\n"); RARCH_LOG("ROM Filename: [%s].\n", rom_path); RARCH_LOG("Libretro path: [%s].\n", libretro_path); -#ifdef PHOENIX_LEGACY RARCH_LOG("Display Refresh rate: %.2fHz.\n", refreshrate); +#ifdef PHOENIX_LEGACY /* ugly hack for now - hardcode libretro path to 'allowed' dir */ snprintf(libretro_path, sizeof(libretro_path), "/data/data/com.retroarch/lib/libretro.so"); #endif @@ -390,7 +386,6 @@ static void* android_app_entry(void* param) g_extern.verbose = true; -#ifdef PHOENIX_LEGACY bool disp_refresh_read = refreshrate > 0.0f; g_android.disp_refresh_rate = refresh_rate; @@ -405,7 +400,6 @@ static void* android_app_entry(void* param) } RARCH_LOG("Setting RetroArch video refresh rate to: %.2fHz.\n", g_android.disp_refresh_rate); -#endif while(!(g_android.input_state & (1ULL << RARCH_WINDOW_READY))) { diff --git a/android/phoenix/src/org/retroarch/browser/DirectoryActivity.java b/android/phoenix/src/org/retroarch/browser/DirectoryActivity.java index b79220c216..52f6db7da8 100644 --- a/android/phoenix/src/org/retroarch/browser/DirectoryActivity.java +++ b/android/phoenix/src/org/retroarch/browser/DirectoryActivity.java @@ -169,10 +169,10 @@ public class DirectoryActivity extends Activity implements AdapterView.OnItemCli } else { - final Intent intent = new Intent(this, selected.isFile() ? NativeActivity.class : DirectoryActivity.class) - .putExtra("ROM", selected.getAbsolutePath()) - .putExtra("LIBRETRO", getIntent().getStringExtra("LIBRETRO")); - startActivity(intent); + Intent intent=new Intent(); + intent.putExtra("PATH", selected.getAbsolutePath()); + setResult(RESULT_OK, intent); + finish(); } } diff --git a/android/phoenix/src/org/retroarch/browser/ModuleActivity.java b/android/phoenix/src/org/retroarch/browser/ModuleActivity.java index 179da18e2f..0196eb2a67 100644 --- a/android/phoenix/src/org/retroarch/browser/ModuleActivity.java +++ b/android/phoenix/src/org/retroarch/browser/ModuleActivity.java @@ -1,6 +1,7 @@ package org.retroarch.browser; import org.retroarch.R; + import java.io.*; import android.content.*; @@ -44,6 +45,16 @@ class ModuleWrapper implements IconAdapterItem public class ModuleActivity extends Activity implements AdapterView.OnItemClickListener { private IconAdapter adapter; + static private final int ACTIVITY_LOAD_ROM = 0; + static private String libretro_path; + + public float getRefreshRate() + { + final WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE); + final Display display = wm.getDefaultDisplay(); + float rate = display.getRefreshRate(); + return rate; + } @Override public void onCreate(Bundle savedInstanceState) { @@ -57,7 +68,7 @@ public class ModuleActivity extends Activity implements AdapterView.OnItemClickL list.setAdapter(adapter); list.setOnItemClickListener(this); - setTitle("Select Emulator"); + setTitle("Select Libretro core"); // Populate the list final String modulePath = getApplicationInfo().nativeLibraryDir; @@ -80,10 +91,32 @@ public class ModuleActivity extends Activity implements AdapterView.OnItemClickL @Override public void onItemClick(AdapterView aListView, View aView, int aPosition, long aID) { final ModuleWrapper item = adapter.getItem(aPosition); - - startActivity(new Intent(ModuleActivity.this, DirectoryActivity.class) - .putExtra("LIBRETRO", item.file.getAbsolutePath())); + libretro_path = item.file.getAbsolutePath(); + + Intent myIntent; + myIntent = new Intent(this, DirectoryActivity.class); + startActivityForResult(myIntent, ACTIVITY_LOAD_ROM); } + + protected void onActivityResult(int requestCode, int resultCode, Intent data) + { + Intent myIntent; + + switch(requestCode) + { + case ACTIVITY_LOAD_ROM: + if(data.getStringExtra("PATH") != null) + { + Toast.makeText(this, "Loading: ["+ data.getStringExtra("PATH") + "]...", Toast.LENGTH_SHORT).show(); + myIntent = new Intent(this, NativeActivity.class); + myIntent.putExtra("ROM", data.getStringExtra("PATH")); + myIntent.putExtra("LIBRETRO", libretro_path); + myIntent.putExtra("REFRESHRATE", Float.toString(getRefreshRate())); + startActivity(myIntent); + } + break; + } + } @Override public boolean onCreateOptionsMenu(Menu aMenu) { diff --git a/settings.c b/settings.c index 4796c62601..83389badf3 100644 --- a/settings.c +++ b/settings.c @@ -191,7 +191,7 @@ void config_set_defaults(void) // Android screens can have variable refresh rates - don't set a // hardcoded value for Android devices -#if defined(ANDROID) && defined(PHOENIX_LEGACY) +#if defined(ANDROID) g_settings.video.refresh_rate = g_android.disp_refresh_rate; #else g_settings.video.refresh_rate = refresh_rate;