mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
Revert "[Android] Move the main activity to use Fragments."
This is pretty pointless at the moment actually. This reverts commit bfdc1e0e601a85db973adc49215e5c77719e2d7e. - Keeps some modifications to the MainMenuActivity. Most notably the title string retains itself upon orientation changes. - Also fix some bugs in the PreferenceListFragment. Most notably, the handler message not being removed.
This commit is contained in:
parent
bfdc1e0e60
commit
97c1745909
@ -18,7 +18,7 @@
|
||||
<activity android:name="com.retroarch.browser.CoreSelection"/>
|
||||
<activity android:name="com.retroarch.browser.HistorySelection"/>
|
||||
<activity android:name="com.retroarch.browser.DisplayRefreshRateTest"/>
|
||||
<activity android:name="com.retroarch.browser.mainmenu.MainMenuActivity" android:exported="true">
|
||||
<activity android:name="com.retroarch.browser.MainMenuActivity" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/content_frame"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
@ -9,10 +9,10 @@
|
||||
<string name="key_bind_detect">Detect</string>
|
||||
<string name="optimal_settings_device">Optimal device settings</string>
|
||||
<string name="extracting_assets_please_wait_">Extracting assets, please wait …</string>
|
||||
<string name="asset_extraction">Asset Extraction</string>
|
||||
|
||||
<!-- Main Menu Strings -->
|
||||
<string name="mainmenu_title">RetroArch - Main Menu</string>
|
||||
<string name="asset_extraction">Asset Extraction</string>
|
||||
<string name="tv_mode">TV Mode</string>
|
||||
<string name="load_core">Load Core</string>
|
||||
<string name="load_game">Load Game</string>
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.retroarch.browser;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.mainmenu.MainMenuActivity;
|
||||
import com.retroarch.browser.preferences.util.ConfigFile;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
|
@ -7,7 +7,6 @@ import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.mainmenu.MainMenuActivity;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
import android.app.ListActivity;
|
||||
|
@ -1,13 +1,10 @@
|
||||
package com.retroarch.browser.mainmenu;
|
||||
package com.retroarch.browser;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.NativeInterface;
|
||||
import com.retroarch.browser.RetroActivity;
|
||||
import com.retroarch.browser.preferences.util.UserPreferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
@ -19,38 +16,34 @@ import android.media.AudioManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* Class representing the {@link FragmentActivity} for the main menu.
|
||||
*/
|
||||
public final class MainMenuActivity extends FragmentActivity {
|
||||
public final class MainMenuActivity extends PreferenceActivity {
|
||||
private static MainMenuActivity instance = null;
|
||||
private static final int ACTIVITY_LOAD_ROM = 0;
|
||||
private static final int ACTIVITY_RETROARCH = 1;
|
||||
private static final String TAG = "MainMenu";
|
||||
private static String libretro_path;
|
||||
private static String libretro_name;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Set the content view. This will give us the FrameLayout to switch fragments in and out of.
|
||||
setContentView(R.layout.main_menu_layout);
|
||||
|
||||
// Show the main UI for this FragmentActivity.
|
||||
final Fragment mainMenuFragment = new MainMenuFragment();
|
||||
final FragmentManager fm = getSupportFragmentManager();
|
||||
fm.beginTransaction().replace(R.id.content_frame, mainMenuFragment).commit();
|
||||
// Load the main menu XML.
|
||||
addPreferencesFromResource(R.xml.main_menu);
|
||||
|
||||
// Cache an instance of this class (TODO: Bad practice, kill this somehow).
|
||||
instance = this;
|
||||
|
||||
// Get libretro path and name.
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
libretro_path = prefs.getString("libretro_path", getApplicationInfo().dataDir + "/cores");
|
||||
libretro_name = prefs.getString("libretro_name", getString(R.string.no_core));
|
||||
|
||||
// Bind audio stream to hardware controls.
|
||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
@ -73,7 +66,8 @@ public final class MainMenuActivity extends FragmentActivity {
|
||||
Intent startedByIntent = getIntent();
|
||||
if (startedByIntent.getStringExtra("ROM") != null && startedByIntent.getStringExtra("LIBRETRO") != null) {
|
||||
if (savedInstanceState == null || !savedInstanceState.getBoolean("romexec"))
|
||||
loadRomExternal(startedByIntent.getStringExtra("ROM"), startedByIntent.getStringExtra("LIBRETRO"));
|
||||
loadRomExternal(startedByIntent.getStringExtra("ROM"),
|
||||
startedByIntent.getStringExtra("LIBRETRO"));
|
||||
else
|
||||
finish();
|
||||
}
|
||||
@ -111,7 +105,7 @@ public final class MainMenuActivity extends FragmentActivity {
|
||||
cacheStream.close();
|
||||
|
||||
if (currentCacheVersion == version) {
|
||||
Log.i(TAG, "Assets already extracted, skipping...");
|
||||
Log.i("ASSETS", "Assets already extracted, skipping...");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -154,7 +148,7 @@ public final class MainMenuActivity extends FragmentActivity {
|
||||
final Handler handler = new Handler();
|
||||
dialog.setContentView(R.layout.assets);
|
||||
dialog.setCancelable(false);
|
||||
dialog.setTitle(R.string.asset_extraction);
|
||||
dialog.setTitle("Asset extraction");
|
||||
|
||||
// Java is fun :)
|
||||
Thread assetsThread = new Thread(new Runnable() {
|
||||
@ -175,8 +169,8 @@ public final class MainMenuActivity extends FragmentActivity {
|
||||
public void setModule(String core_path, String core_name) {
|
||||
UserPreferences.updateConfigFile(this);
|
||||
|
||||
String libretro_path = core_path;
|
||||
String libretro_name = core_name;
|
||||
libretro_path = core_path;
|
||||
libretro_name = core_name;
|
||||
|
||||
SharedPreferences prefs = UserPreferences.getPreferences(this);
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
@ -186,6 +180,7 @@ public final class MainMenuActivity extends FragmentActivity {
|
||||
|
||||
// Set the title section to contain the name of the selected core.
|
||||
setCoreTitle(libretro_name);
|
||||
|
||||
}
|
||||
|
||||
public void setCoreTitle(String core_name) {
|
||||
@ -313,15 +308,10 @@ public final class MainMenuActivity extends FragmentActivity {
|
||||
|
||||
@Override
|
||||
public void startActivity(Intent intent) {
|
||||
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
final String corePath = sPrefs.getString("libretro_path", "");
|
||||
|
||||
// If ROMActivity is attempting to be accessed.
|
||||
if (intent.getComponent().getClassName().equals("com.retroarch.browser.diractivities.ROMActivity")) {
|
||||
// If the path for a core hasn't been set yet, prompt the user to do so.
|
||||
// otherwise, launch the activity to browse for a ROM to load.
|
||||
if (!new File(corePath).isDirectory()) {
|
||||
startActivity(intent);
|
||||
if (intent.getComponent().getClassName()
|
||||
.equals("com.retroarch.browser.diractivities.ROMActivity")) {
|
||||
if (!new File(libretro_path).isDirectory()) {
|
||||
super.startActivityForResult(intent, ACTIVITY_LOAD_ROM);
|
||||
} else {
|
||||
Toast.makeText(this, R.string.load_a_core_first, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
@ -330,12 +320,48 @@ public final class MainMenuActivity extends FragmentActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int reqCode, int resCode, Intent data) {
|
||||
switch (reqCode) {
|
||||
case ACTIVITY_LOAD_ROM: {
|
||||
if (data.getStringExtra("PATH") != null) {
|
||||
UserPreferences.updateConfigFile(this);
|
||||
String current_ime = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
Toast.makeText(this,String.format(getString(R.string.loading_data), data.getStringExtra("PATH")), Toast.LENGTH_SHORT).show();
|
||||
Intent myIntent = new Intent(this, RetroActivity.class);
|
||||
myIntent.putExtra("ROM", data.getStringExtra("PATH"));
|
||||
myIntent.putExtra("LIBRETRO", libretro_path);
|
||||
myIntent.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(this));
|
||||
myIntent.putExtra("IME", current_ime);
|
||||
startActivityForResult(myIntent, ACTIVITY_RETROARCH);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case ACTIVITY_RETROARCH: {
|
||||
Log.i(TAG, "RetroArch finished running.");
|
||||
UserPreferences.readbackConfigFile(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle data) {
|
||||
super.onSaveInstanceState(data);
|
||||
data.putCharSequence("title", getTitle());
|
||||
data.putBoolean("romexec", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle state) {
|
||||
super.onRestoreInstanceState(state);
|
||||
|
||||
if (state != null) {
|
||||
setTitle(state.getCharSequence("title"));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadRomExternal(String rom, String core) {
|
||||
UserPreferences.updateConfigFile(this);
|
||||
String current_ime = Settings.Secure.getString(getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
|
||||
@ -347,4 +373,4 @@ public final class MainMenuActivity extends FragmentActivity {
|
||||
myIntent.putExtra("IME", current_ime);
|
||||
startActivity(myIntent);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.retroarch.browser.mainmenu;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.retroarch.R;
|
||||
import com.retroarch.browser.preferences.fragments.util.PreferenceListFragment;
|
||||
|
||||
/**
|
||||
* Fragment that represents the main menu.
|
||||
*/
|
||||
public class MainMenuFragment extends PreferenceListFragment
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Load the XML for the main menu.
|
||||
this.addPreferencesFromResource(R.xml.main_menu);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user