mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 00:39:53 +00:00
(Android) Reimplement 'Quit RetroArch'
This commit is contained in:
parent
f4f046fe17
commit
7925b4ce19
@ -2,14 +2,20 @@ package com.retroarch.browser.mainmenu;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import com.retroarch.R;
|
|
||||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||||
|
import com.retroarch.browser.retroactivity.RetroActivityFuture;
|
||||||
|
import com.retroarch.browser.retroactivity.RetroActivityPast;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Environment;
|
||||||
import android.preference.PreferenceActivity;
|
import android.preference.PreferenceActivity;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentTransaction;
|
import android.support.v4.app.FragmentTransaction;
|
||||||
|
|
||||||
@ -19,6 +25,24 @@ import android.support.v4.app.FragmentTransaction;
|
|||||||
*/
|
*/
|
||||||
public final class MainMenuActivity extends FragmentActivity
|
public final class MainMenuActivity extends FragmentActivity
|
||||||
{
|
{
|
||||||
|
public static void startRetroActivity(Intent retro, String contentPath, String corePath,
|
||||||
|
String configFilePath, String imePath, String dataDirPath, String dataSourcePath)
|
||||||
|
{
|
||||||
|
if (contentPath != null) {
|
||||||
|
retro.putExtra("ROM", contentPath);
|
||||||
|
}
|
||||||
|
retro.putExtra("LIBRETRO", corePath);
|
||||||
|
retro.putExtra("CONFIGFILE", configFilePath);
|
||||||
|
retro.putExtra("IME", imePath);
|
||||||
|
retro.putExtra("DATADIR", dataDirPath);
|
||||||
|
retro.putExtra("APK", dataSourcePath);
|
||||||
|
retro.putExtra("SDCARD", Environment.getExternalStorageDirectory().getAbsolutePath());
|
||||||
|
retro.putExtra("DOWNLOADS", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
|
||||||
|
retro.putExtra("SCREENSHOTS", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
|
||||||
|
String external = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/com.retroarch/files";
|
||||||
|
retro.putExtra("EXTERNAL", external);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState)
|
public void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
@ -33,40 +57,32 @@ public final class MainMenuActivity extends FragmentActivity
|
|||||||
if (!infoDir.exists())
|
if (!infoDir.exists())
|
||||||
infoDir.mkdir();
|
infoDir.mkdir();
|
||||||
|
|
||||||
// Load the main menu layout
|
|
||||||
setContentView(R.layout.mainmenu_activity_layout);
|
|
||||||
if (savedInstanceState == null)
|
|
||||||
{
|
|
||||||
final MainMenuFragment mmf = new MainMenuFragment();
|
|
||||||
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
|
||||||
|
|
||||||
// Add the base main menu fragment to the content view.
|
|
||||||
ft.replace(R.id.content_frame, mmf);
|
|
||||||
ft.commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bind audio stream to hardware controls.
|
// Bind audio stream to hardware controls.
|
||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
}
|
|
||||||
|
|
||||||
public void setCoreTitle(String core_name)
|
UserPreferences.updateConfigFile(this);
|
||||||
{
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
setTitle("RetroArch : " + core_name);
|
Intent retro;
|
||||||
}
|
|
||||||
|
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB))
|
||||||
|
{
|
||||||
|
retro = new Intent(this, RetroActivityFuture.class);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
retro = new Intent(this, RetroActivityPast.class);
|
||||||
|
}
|
||||||
|
retro.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
|
||||||
@Override
|
startRetroActivity(
|
||||||
protected void onSaveInstanceState(Bundle data)
|
retro,
|
||||||
{
|
null,
|
||||||
super.onSaveInstanceState(data);
|
prefs.getString("libretro_path", getApplicationInfo().dataDir + "/cores/"),
|
||||||
|
UserPreferences.getDefaultConfigPath(this),
|
||||||
data.putCharSequence("title", getTitle());
|
Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD),
|
||||||
}
|
getApplicationInfo().dataDir,
|
||||||
|
getApplicationInfo().sourceDir);
|
||||||
@Override
|
startActivity(retro);
|
||||||
protected void onRestoreInstanceState(Bundle savedInstanceState)
|
finish();
|
||||||
{
|
|
||||||
super.onRestoreInstanceState(savedInstanceState);
|
|
||||||
|
|
||||||
setTitle(savedInstanceState.getCharSequence("title"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,111 +0,0 @@
|
|||||||
package com.retroarch.browser.mainmenu;
|
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.preference.Preference;
|
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.provider.Settings;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import com.retroarch.R;
|
|
||||||
import com.retroarch.browser.preferences.fragments.util.PreferenceListFragment;
|
|
||||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
|
||||||
import com.retroarch.browser.retroactivity.RetroActivityFuture;
|
|
||||||
import com.retroarch.browser.retroactivity.RetroActivityPast;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the fragment that handles the layout of the main menu.
|
|
||||||
*/
|
|
||||||
public final class MainMenuFragment extends PreferenceListFragment implements OnPreferenceClickListener
|
|
||||||
{
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
// Cache the context
|
|
||||||
this.ctx = getActivity();
|
|
||||||
|
|
||||||
// Add the layout through the XML.
|
|
||||||
addPreferencesFromResource(R.xml.main_menu);
|
|
||||||
|
|
||||||
// Set the listeners for the menu items
|
|
||||||
findPreference("resumeContentPref").setOnPreferenceClickListener(this);
|
|
||||||
findPreference("quitRetroArch").setOnPreferenceClickListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceClick(Preference preference)
|
|
||||||
{
|
|
||||||
final String prefKey = preference.getKey();
|
|
||||||
|
|
||||||
// Resume Content
|
|
||||||
if (prefKey.equals("resumeContentPref"))
|
|
||||||
{
|
|
||||||
UserPreferences.updateConfigFile(ctx);
|
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
|
|
||||||
final Intent retro = getRetroActivity();
|
|
||||||
|
|
||||||
MainMenuFragment.startRetroActivity(
|
|
||||||
retro,
|
|
||||||
null,
|
|
||||||
prefs.getString("libretro_path", ctx.getApplicationInfo().dataDir + "/cores/"),
|
|
||||||
UserPreferences.getDefaultConfigPath(ctx),
|
|
||||||
Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD),
|
|
||||||
ctx.getApplicationInfo().dataDir,
|
|
||||||
ctx.getApplicationInfo().sourceDir);
|
|
||||||
startActivity(retro);
|
|
||||||
}
|
|
||||||
// Quit RetroArch preference
|
|
||||||
else if (prefKey.equals("quitRetroArch"))
|
|
||||||
{
|
|
||||||
// TODO - needs to close entire app gracefully - including
|
|
||||||
// NativeActivity if possible
|
|
||||||
getActivity().finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void startRetroActivity(Intent retro, String contentPath, String corePath,
|
|
||||||
String configFilePath, String imePath, String dataDirPath, String dataSourcePath)
|
|
||||||
{
|
|
||||||
if (contentPath != null) {
|
|
||||||
retro.putExtra("ROM", contentPath);
|
|
||||||
}
|
|
||||||
retro.putExtra("LIBRETRO", corePath);
|
|
||||||
retro.putExtra("CONFIGFILE", configFilePath);
|
|
||||||
retro.putExtra("IME", imePath);
|
|
||||||
retro.putExtra("DATADIR", dataDirPath);
|
|
||||||
retro.putExtra("APK", dataSourcePath);
|
|
||||||
retro.putExtra("SDCARD", Environment.getExternalStorageDirectory().getAbsolutePath());
|
|
||||||
retro.putExtra("DOWNLOADS", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
|
|
||||||
retro.putExtra("SCREENSHOTS", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
|
|
||||||
String external = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/com.retroarch/files";
|
|
||||||
retro.putExtra("EXTERNAL", external);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -22,5 +22,6 @@ public class RetroActivityCommon extends RetroActivityLocation
|
|||||||
// Use a separate JNI function to explicitly trigger the readback.
|
// Use a separate JNI function to explicitly trigger the readback.
|
||||||
public void onRetroArchExit()
|
public void onRetroArchExit()
|
||||||
{
|
{
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user