mirror of
https://github.com/libretro/RetroArch
synced 2025-04-11 00:44:20 +00:00
Start reworking settings menus into Java Phoenix.
Fix style according to Eclipse Ctrl+F. Let frontend find default config. Start adding popup menu for different settings. Do not autodetect config on Android in native code.
This commit is contained in:
parent
cce0d9379a
commit
925a55c9e1
@ -4,7 +4,7 @@
|
|||||||
android:versionName="1.0" >
|
android:versionName="1.0" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="9"
|
android:minSdkVersion="11"
|
||||||
android:targetSdkVersion="16" />
|
android:targetSdkVersion="16" />
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||||
|
7
android/phoenix/res/menu/context_menu.xml
Normal file
7
android/phoenix/res/menu/context_menu.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
<item android:id="@+id/general_settings" android:title="@string/general_settings" android:showAsAction="ifRoom" />
|
||||||
|
<item android:id="@+id/video_settings" android:title="@string/video_settings" android:showAsAction="ifRoom" />
|
||||||
|
<item android:id="@+id/audio_settings" android:title="@string/audio_settings" android:showAsAction="ifRoom" />
|
||||||
|
<item android:id="@+id/input_method_select" android:title="@string/input_method" android:showAsAction="ifRoom" />
|
||||||
|
</menu>
|
@ -1,4 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
<item android:id="@+id/input_method_select" android:title="@string/input_method" android:showAsAction="ifRoom"></item>
|
<item android:id="@+id/settings"
|
||||||
</menu>
|
android:title="@string/settings"
|
||||||
|
android:icon="@drawable/ic_file"
|
||||||
|
android:showAsAction="ifRoom" />
|
||||||
|
</menu>
|
||||||
|
@ -3,5 +3,9 @@
|
|||||||
<string name="app_name">RetroArch</string>
|
<string name="app_name">RetroArch</string>
|
||||||
<string name="input_method">Input Method</string>
|
<string name="input_method">Input Method</string>
|
||||||
<string name="file_type_icon">File type icon</string>
|
<string name="file_type_icon">File type icon</string>
|
||||||
|
<string name="video_settings">Video Config</string>
|
||||||
|
<string name="audio_settings">Audio Config</string>
|
||||||
|
<string name="general_settings">General Config</string>
|
||||||
|
<string name="settings">Settings</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -15,40 +15,46 @@ public class ConfigFile {
|
|||||||
public void append(File file) throws IOException {
|
public void append(File file) throws IOException {
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(
|
BufferedReader br = new BufferedReader(new InputStreamReader(
|
||||||
new FileInputStream(file.getAbsolutePath())));
|
new FileInputStream(file.getAbsolutePath())));
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = br.readLine()) != null)
|
while ((line = br.readLine()) != null)
|
||||||
parseLine(line);
|
parseLine(line);
|
||||||
|
|
||||||
br.close();
|
br.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open(File file) throws IOException {
|
public void open(File file) throws IOException {
|
||||||
clear();
|
clear();
|
||||||
append(file);
|
append(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigFile(File file) throws IOException {
|
||||||
|
open(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigFile() {}
|
||||||
|
|
||||||
private void parseLine(String line) {
|
private void parseLine(String line) {
|
||||||
String[] tokens = line.split("=", 2);
|
String[] tokens = line.split("=", 2);
|
||||||
if (tokens.length < 2) {
|
if (tokens.length < 2) {
|
||||||
System.err.println("Didn't find two tokens in config line ...");
|
System.err.println("Didn't find two tokens in config line ...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < tokens.length; i++)
|
for (int i = 0; i < tokens.length; i++)
|
||||||
tokens[i] = tokens[i].trim();
|
tokens[i] = tokens[i].trim();
|
||||||
|
|
||||||
String key = tokens[0];
|
String key = tokens[0];
|
||||||
String value = tokens[1];
|
String value = tokens[1];
|
||||||
|
|
||||||
if (value.startsWith("\""))
|
if (value.startsWith("\""))
|
||||||
value = value.substring(1, value.lastIndexOf('\"'));
|
value = value.substring(1, value.lastIndexOf('\"'));
|
||||||
else
|
else
|
||||||
value = value.split(" ")[0];
|
value = value.split(" ")[0];
|
||||||
|
|
||||||
if (value.length() > 0)
|
if (value.length() > 0)
|
||||||
map.put(key, value);
|
map.put(key, value);
|
||||||
|
|
||||||
System.out.println("Parsed: \"" + key + "\" => \"" + value + "\"");
|
System.out.println("Parsed: \"" + key + "\" => \"" + value + "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +75,7 @@ public class ConfigFile {
|
|||||||
public void setString(String key, String value) {
|
public void setString(String key, String value) {
|
||||||
map.put(key, value);
|
map.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBoolean(String key, boolean value) {
|
public void setBoolean(String key, boolean value) {
|
||||||
map.put(key, Boolean.toString(value));
|
map.put(key, Boolean.toString(value));
|
||||||
}
|
}
|
||||||
@ -81,15 +87,15 @@ public class ConfigFile {
|
|||||||
public void setDouble(String key, double value) {
|
public void setDouble(String key, double value) {
|
||||||
map.put(key, Double.toString(value));
|
map.put(key, Double.toString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean keyExists(String key) {
|
public boolean keyExists(String key) {
|
||||||
return map.containsKey(key);
|
return map.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String key) {
|
public String getString(String key) {
|
||||||
Object ret = map.get(key);
|
Object ret = map.get(key);
|
||||||
if (ret != null)
|
if (ret != null)
|
||||||
return (String)ret;
|
return (String) ret;
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -101,7 +107,7 @@ public class ConfigFile {
|
|||||||
else
|
else
|
||||||
throw new NumberFormatException();
|
throw new NumberFormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDouble(String key) throws NumberFormatException {
|
public double getDouble(String key) throws NumberFormatException {
|
||||||
String str = getString(key);
|
String str = getString(key);
|
||||||
if (str != null)
|
if (str != null)
|
||||||
@ -109,7 +115,7 @@ public class ConfigFile {
|
|||||||
else
|
else
|
||||||
throw new NumberFormatException();
|
throw new NumberFormatException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBoolean(String key) {
|
public boolean getBoolean(String key) {
|
||||||
String str = getString(key);
|
String str = getString(key);
|
||||||
return Boolean.parseBoolean(str);
|
return Boolean.parseBoolean(str);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package org.retroarch.browser;
|
package org.retroarch.browser;
|
||||||
|
|
||||||
import org.retroarch.R;
|
import org.retroarch.R;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -9,252 +10,210 @@ import android.app.*;
|
|||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.view.inputmethod.*;
|
|
||||||
import android.graphics.drawable.*;
|
import android.graphics.drawable.*;
|
||||||
|
|
||||||
class FileWrapper implements IconAdapterItem
|
class FileWrapper implements IconAdapterItem {
|
||||||
{
|
public final File file;
|
||||||
public final File file;
|
public final boolean parentItem;
|
||||||
public final boolean parentItem;
|
protected final int typeIndex;
|
||||||
protected final int typeIndex;
|
protected final boolean enabled;
|
||||||
protected final boolean enabled;
|
|
||||||
|
|
||||||
public FileWrapper(File aFile, boolean aIsParentItem, boolean aIsEnabled)
|
public FileWrapper(File aFile, boolean aIsParentItem, boolean aIsEnabled) {
|
||||||
{
|
file = aFile;
|
||||||
file = aFile;
|
typeIndex = aIsParentItem ? 0 : (file.isDirectory() ? 1 : 0)
|
||||||
typeIndex = aIsParentItem ? 0 : (file.isDirectory() ? 1 : 0) + (file.isFile() ? 2 : 0);
|
+ (file.isFile() ? 2 : 0);
|
||||||
parentItem = aIsParentItem;
|
parentItem = aIsParentItem;
|
||||||
enabled = aIsParentItem || aIsEnabled;
|
enabled = aIsParentItem || aIsEnabled;
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean isEnabled()
|
|
||||||
{
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String getText()
|
|
||||||
{
|
|
||||||
return parentItem ? "[Parent Directory]" : file.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public int getIconResourceId()
|
|
||||||
{
|
|
||||||
if(!parentItem)
|
|
||||||
{
|
|
||||||
return file.isFile() ? R.drawable.ic_file : R.drawable.ic_dir;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return R.drawable.ic_dir;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public Drawable getIconDrawable()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(FileWrapper aOther)
|
|
||||||
{
|
|
||||||
if(null != aOther)
|
|
||||||
{
|
|
||||||
// Who says ternary is hard to follow
|
|
||||||
if(isEnabled() == aOther.isEnabled())
|
|
||||||
{
|
|
||||||
return (typeIndex == aOther.typeIndex) ? file.compareTo(aOther.file) : ((typeIndex < aOther.typeIndex) ? -1 : 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return isEnabled() ? -1 : 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DirectoryActivity extends Activity implements AdapterView.OnItemClickListener
|
|
||||||
{
|
|
||||||
private IconAdapter<FileWrapper> adapter;
|
|
||||||
private File listedDirectory;
|
|
||||||
|
|
||||||
public static class BackStackItem implements Parcelable
|
|
||||||
{
|
|
||||||
public String path;
|
|
||||||
public boolean parentIsBack;
|
|
||||||
|
|
||||||
public BackStackItem(String aPath, boolean aParentIsBack)
|
|
||||||
{
|
|
||||||
path = aPath;
|
|
||||||
parentIsBack = aParentIsBack;
|
|
||||||
}
|
|
||||||
|
|
||||||
private BackStackItem(Parcel aIn)
|
|
||||||
{
|
|
||||||
path = aIn.readString();
|
|
||||||
parentIsBack = aIn.readInt() != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int describeContents()
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeToParcel(Parcel out, int flags)
|
|
||||||
{
|
|
||||||
out.writeString(path);
|
|
||||||
out.writeInt(parentIsBack ? 1 : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static final Parcelable.Creator<BackStackItem> CREATOR = new Parcelable.Creator<BackStackItem>()
|
|
||||||
{
|
|
||||||
public BackStackItem createFromParcel(Parcel in) { return new BackStackItem(in); }
|
|
||||||
public BackStackItem[] newArray(int size) { return new BackStackItem[size]; }
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private ArrayList<BackStackItem> backStack;
|
|
||||||
|
|
||||||
@Override public void onCreate(Bundle savedInstanceState)
|
|
||||||
{
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.line_list);
|
|
||||||
|
|
||||||
// Setup the list
|
|
||||||
adapter = new IconAdapter<FileWrapper>(this, R.layout.line_list_item);
|
|
||||||
ListView list = (ListView)findViewById(R.id.list);
|
|
||||||
list.setAdapter(adapter);
|
|
||||||
list.setOnItemClickListener(this);
|
|
||||||
|
|
||||||
// Load Directory
|
|
||||||
if(savedInstanceState != null)
|
|
||||||
{
|
|
||||||
backStack = savedInstanceState.getParcelableArrayList("BACKSTACK");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(backStack == null || backStack.size() == 0)
|
|
||||||
{
|
|
||||||
backStack = new ArrayList<BackStackItem>();
|
|
||||||
backStack.add(new BackStackItem(Environment.getExternalStorageDirectory().getPath(), false));
|
|
||||||
}
|
|
||||||
|
|
||||||
wrapFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override protected void onSaveInstanceState(Bundle aState)
|
|
||||||
{
|
|
||||||
super.onSaveInstanceState(aState);
|
|
||||||
aState.putParcelableArrayList("BACKSTACK", backStack);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onItemClick(AdapterView<?> aListView, View aView, int aPosition, long aID)
|
|
||||||
{
|
|
||||||
final FileWrapper item = adapter.getItem(aPosition);
|
|
||||||
|
|
||||||
if(item.parentItem && backStack.get(backStack.size() - 1).parentIsBack)
|
|
||||||
{
|
|
||||||
backStack.remove(backStack.size() - 1);
|
|
||||||
wrapFiles();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final File selected = item.parentItem ? listedDirectory.getParentFile() : item.file;
|
|
||||||
|
|
||||||
if(selected.isDirectory())
|
|
||||||
{
|
|
||||||
backStack.add(new BackStackItem(selected.getAbsolutePath(), !item.parentItem));
|
|
||||||
wrapFiles();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Intent intent=new Intent();
|
|
||||||
intent.putExtra("PATH", selected.getAbsolutePath());
|
|
||||||
setResult(RESULT_OK, intent);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event)
|
public boolean isEnabled() {
|
||||||
{
|
return enabled;
|
||||||
if(keyCode == KeyEvent.KEYCODE_BACK)
|
}
|
||||||
{
|
|
||||||
if(backStack.size() > 1)
|
|
||||||
{
|
|
||||||
backStack.remove(backStack.size() - 1);
|
|
||||||
wrapFiles();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Intent intent=new Intent();
|
|
||||||
setResult(RESULT_CANCELED, intent);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onKeyDown(keyCode, event);
|
@Override
|
||||||
}
|
public String getText() {
|
||||||
|
return parentItem ? "[Parent Directory]" : file.getName();
|
||||||
|
}
|
||||||
|
|
||||||
@Override public boolean onCreateOptionsMenu(Menu aMenu)
|
@Override
|
||||||
{
|
public int getIconResourceId() {
|
||||||
super.onCreateOptionsMenu(aMenu);
|
if (!parentItem) {
|
||||||
getMenuInflater().inflate(R.menu.directory_list, aMenu);
|
return file.isFile() ? R.drawable.ic_file : R.drawable.ic_dir;
|
||||||
|
} else {
|
||||||
|
return R.drawable.ic_dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
@Override
|
||||||
}
|
public Drawable getIconDrawable() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public boolean onOptionsItemSelected(MenuItem aItem)
|
public int compareTo(FileWrapper aOther) {
|
||||||
{
|
if (null != aOther) {
|
||||||
if(R.id.input_method_select == aItem.getItemId())
|
// Who says ternary is hard to follow
|
||||||
{
|
if (isEnabled() == aOther.isEnabled()) {
|
||||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
return (typeIndex == aOther.typeIndex) ? file
|
||||||
imm.showInputMethodPicker();
|
.compareTo(aOther.file)
|
||||||
return true;
|
: ((typeIndex < aOther.typeIndex) ? -1 : 1);
|
||||||
}
|
} else {
|
||||||
|
return isEnabled() ? -1 : 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return super.onOptionsItemSelected(aItem);
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private void wrapFiles()
|
|
||||||
{
|
public class DirectoryActivity extends Activity implements
|
||||||
listedDirectory = new File(backStack.get(backStack.size() - 1).path);
|
AdapterView.OnItemClickListener {
|
||||||
|
private IconAdapter<FileWrapper> adapter;
|
||||||
if(!listedDirectory.isDirectory())
|
private File listedDirectory;
|
||||||
{
|
|
||||||
throw new IllegalArgumentException("Directory is not valid.");
|
public static class BackStackItem implements Parcelable {
|
||||||
}
|
public String path;
|
||||||
|
public boolean parentIsBack;
|
||||||
adapter.clear();
|
|
||||||
setTitle(listedDirectory.getAbsolutePath());
|
public BackStackItem(String aPath, boolean aParentIsBack) {
|
||||||
|
path = aPath;
|
||||||
if(listedDirectory.getParentFile() != null)
|
parentIsBack = aParentIsBack;
|
||||||
{
|
}
|
||||||
adapter.add(new FileWrapper(null, true, true));
|
|
||||||
}
|
private BackStackItem(Parcel aIn) {
|
||||||
|
path = aIn.readString();
|
||||||
// Copy new items
|
parentIsBack = aIn.readInt() != 0;
|
||||||
final File[] files = listedDirectory.listFiles();
|
}
|
||||||
if(files != null)
|
|
||||||
{
|
public int describeContents() {
|
||||||
for(File file: files)
|
return 0;
|
||||||
{
|
}
|
||||||
adapter.add(new FileWrapper(file, false, file.isDirectory() || true));
|
|
||||||
}
|
public void writeToParcel(Parcel out, int flags) {
|
||||||
}
|
out.writeString(path);
|
||||||
|
out.writeInt(parentIsBack ? 1 : 0);
|
||||||
// Sort items
|
}
|
||||||
adapter.sort(new Comparator<FileWrapper>()
|
|
||||||
{
|
public static final Parcelable.Creator<BackStackItem> CREATOR = new Parcelable.Creator<BackStackItem>() {
|
||||||
@Override public int compare(FileWrapper aLeft, FileWrapper aRight)
|
public BackStackItem createFromParcel(Parcel in) {
|
||||||
{
|
return new BackStackItem(in);
|
||||||
return aLeft.compareTo(aRight);
|
}
|
||||||
};
|
|
||||||
});
|
public BackStackItem[] newArray(int size) {
|
||||||
|
return new BackStackItem[size];
|
||||||
// Update
|
}
|
||||||
adapter.notifyDataSetChanged();
|
};
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private ArrayList<BackStackItem> backStack;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.line_list);
|
||||||
|
|
||||||
|
// Setup the list
|
||||||
|
adapter = new IconAdapter<FileWrapper>(this, R.layout.line_list_item);
|
||||||
|
ListView list = (ListView) findViewById(R.id.list);
|
||||||
|
list.setAdapter(adapter);
|
||||||
|
list.setOnItemClickListener(this);
|
||||||
|
|
||||||
|
// Load Directory
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
backStack = savedInstanceState.getParcelableArrayList("BACKSTACK");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backStack == null || backStack.size() == 0) {
|
||||||
|
backStack = new ArrayList<BackStackItem>();
|
||||||
|
backStack.add(new BackStackItem(Environment
|
||||||
|
.getExternalStorageDirectory().getPath(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
wrapFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSaveInstanceState(Bundle aState) {
|
||||||
|
super.onSaveInstanceState(aState);
|
||||||
|
aState.putParcelableArrayList("BACKSTACK", backStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> aListView, View aView,
|
||||||
|
int aPosition, long aID) {
|
||||||
|
final FileWrapper item = adapter.getItem(aPosition);
|
||||||
|
|
||||||
|
if (item.parentItem && backStack.get(backStack.size() - 1).parentIsBack) {
|
||||||
|
backStack.remove(backStack.size() - 1);
|
||||||
|
wrapFiles();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final File selected = item.parentItem ? listedDirectory.getParentFile()
|
||||||
|
: item.file;
|
||||||
|
|
||||||
|
if (selected.isDirectory()) {
|
||||||
|
backStack.add(new BackStackItem(selected.getAbsolutePath(),
|
||||||
|
!item.parentItem));
|
||||||
|
wrapFiles();
|
||||||
|
} else {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra("PATH", selected.getAbsolutePath());
|
||||||
|
setResult(RESULT_OK, intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
if (backStack.size() > 1) {
|
||||||
|
backStack.remove(backStack.size() - 1);
|
||||||
|
wrapFiles();
|
||||||
|
} else {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
setResult(RESULT_CANCELED, intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onKeyDown(keyCode, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void wrapFiles() {
|
||||||
|
listedDirectory = new File(backStack.get(backStack.size() - 1).path);
|
||||||
|
|
||||||
|
if (!listedDirectory.isDirectory()) {
|
||||||
|
throw new IllegalArgumentException("Directory is not valid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
adapter.clear();
|
||||||
|
setTitle(listedDirectory.getAbsolutePath());
|
||||||
|
|
||||||
|
if (listedDirectory.getParentFile() != null) {
|
||||||
|
adapter.add(new FileWrapper(null, true, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy new items
|
||||||
|
final File[] files = listedDirectory.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (File file : files) {
|
||||||
|
adapter.add(new FileWrapper(file, false,
|
||||||
|
file.isDirectory() || true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort items
|
||||||
|
adapter.sort(new Comparator<FileWrapper>() {
|
||||||
|
@Override
|
||||||
|
public int compare(FileWrapper aLeft, FileWrapper aRight) {
|
||||||
|
return aLeft.compareTo(aRight);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
package org.retroarch.browser;
|
package org.retroarch.browser;
|
||||||
|
|
||||||
import org.retroarch.R;
|
import org.retroarch.R;
|
||||||
|
|
||||||
import android.app.*;
|
import android.app.*;
|
||||||
@ -7,72 +8,64 @@ import android.graphics.drawable.*;
|
|||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
interface IconAdapterItem
|
interface IconAdapterItem {
|
||||||
{
|
|
||||||
public abstract boolean isEnabled();
|
public abstract boolean isEnabled();
|
||||||
|
|
||||||
public abstract String getText();
|
public abstract String getText();
|
||||||
|
|
||||||
public abstract int getIconResourceId();
|
public abstract int getIconResourceId();
|
||||||
|
|
||||||
public abstract Drawable getIconDrawable();
|
public abstract Drawable getIconDrawable();
|
||||||
}
|
}
|
||||||
|
|
||||||
class IconAdapter<T extends IconAdapterItem> extends ArrayAdapter<T>
|
class IconAdapter<T extends IconAdapterItem> extends ArrayAdapter<T> {
|
||||||
{
|
private final int layout;
|
||||||
private final int layout;
|
|
||||||
|
|
||||||
public IconAdapter(Activity aContext, int aLayout)
|
public IconAdapter(Activity aContext, int aLayout) {
|
||||||
{
|
super(aContext, aLayout);
|
||||||
super(aContext, aLayout);
|
|
||||||
|
|
||||||
layout = aLayout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public View getView(int aPosition, View aConvertView, ViewGroup aParent)
|
|
||||||
{
|
|
||||||
// Build the view
|
|
||||||
if(aConvertView == null)
|
|
||||||
{
|
|
||||||
LayoutInflater inflater = (LayoutInflater)aParent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
aConvertView = inflater.inflate(layout, aParent, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill the view
|
|
||||||
IconAdapterItem item = getItem(aPosition);
|
|
||||||
final boolean enabled = item.isEnabled();
|
|
||||||
|
|
||||||
TextView textView = (TextView)aConvertView.findViewById(R.id.name);
|
layout = aLayout;
|
||||||
if(null != textView)
|
}
|
||||||
{
|
|
||||||
textView.setText(item.getText());
|
@Override
|
||||||
textView.setEnabled(enabled);
|
public View getView(int aPosition, View aConvertView, ViewGroup aParent) {
|
||||||
}
|
// Build the view
|
||||||
|
if (aConvertView == null) {
|
||||||
ImageView imageView = (ImageView)aConvertView.findViewById(R.id.icon);
|
LayoutInflater inflater = (LayoutInflater) aParent.getContext()
|
||||||
if(null != imageView)
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
{
|
aConvertView = inflater.inflate(layout, aParent, false);
|
||||||
if(enabled)
|
}
|
||||||
{
|
|
||||||
final int id = item.getIconResourceId();
|
// Fill the view
|
||||||
if(0 != id)
|
IconAdapterItem item = getItem(aPosition);
|
||||||
{
|
final boolean enabled = item.isEnabled();
|
||||||
imageView.setImageResource(id);
|
|
||||||
}
|
TextView textView = (TextView) aConvertView.findViewById(R.id.name);
|
||||||
else
|
if (null != textView) {
|
||||||
{
|
textView.setText(item.getText());
|
||||||
imageView.setImageDrawable(item.getIconDrawable());
|
textView.setEnabled(enabled);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
ImageView imageView = (ImageView) aConvertView.findViewById(R.id.icon);
|
||||||
{
|
if (null != imageView) {
|
||||||
imageView.setImageDrawable(null);
|
if (enabled) {
|
||||||
}
|
final int id = item.getIconResourceId();
|
||||||
}
|
if (0 != id) {
|
||||||
|
imageView.setImageResource(id);
|
||||||
return aConvertView;
|
} else {
|
||||||
}
|
imageView.setImageDrawable(item.getIconDrawable());
|
||||||
|
}
|
||||||
@Override public boolean isEnabled(int aPosition)
|
} else {
|
||||||
{
|
imageView.setImageDrawable(null);
|
||||||
return getItem(aPosition).isEnabled();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return aConvertView;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled(int aPosition) {
|
||||||
|
return getItem(aPosition).isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package org.retroarch.browser;
|
package org.retroarch.browser;
|
||||||
import org.retroarch.R;
|
|
||||||
|
|
||||||
|
import org.retroarch.R;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@ -8,133 +8,197 @@ import android.content.*;
|
|||||||
import android.app.*;
|
import android.app.*;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.view.inputmethod.*;
|
import android.view.inputmethod.*;
|
||||||
import android.graphics.drawable.*;
|
import android.graphics.drawable.*;
|
||||||
|
|
||||||
class ModuleWrapper implements IconAdapterItem
|
class ModuleWrapper implements IconAdapterItem {
|
||||||
{
|
|
||||||
public final File file;
|
public final File file;
|
||||||
|
|
||||||
public ModuleWrapper(Context aContext, File aFile) throws IOException
|
public ModuleWrapper(Context aContext, File aFile) throws IOException {
|
||||||
{
|
|
||||||
file = aFile;
|
file = aFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean isEnabled()
|
@Override
|
||||||
{
|
public boolean isEnabled() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public String getText()
|
@Override
|
||||||
{
|
public String getText() {
|
||||||
return file.getName();
|
return file.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public int getIconResourceId()
|
@Override
|
||||||
{
|
public int getIconResourceId() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Drawable getIconDrawable()
|
@Override
|
||||||
{
|
public Drawable getIconDrawable() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModuleActivity extends Activity implements AdapterView.OnItemClickListener
|
public class ModuleActivity extends Activity implements
|
||||||
{
|
AdapterView.OnItemClickListener {
|
||||||
private IconAdapter<ModuleWrapper> adapter;
|
private IconAdapter<ModuleWrapper> adapter;
|
||||||
static private final int ACTIVITY_LOAD_ROM = 0;
|
static private final int ACTIVITY_LOAD_ROM = 0;
|
||||||
static private String libretro_path;
|
static private String libretro_path;
|
||||||
|
static private final String TAG = "RetroArch";
|
||||||
public float getRefreshRate()
|
private ConfigFile config;
|
||||||
{
|
|
||||||
final WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
|
public float getRefreshRate() {
|
||||||
final Display display = wm.getDefaultDisplay();
|
final WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
|
||||||
float rate = display.getRefreshRate();
|
final Display display = wm.getDefaultDisplay();
|
||||||
return rate;
|
float rate = display.getRefreshRate();
|
||||||
}
|
return rate;
|
||||||
|
}
|
||||||
@Override public void onCreate(Bundle savedInstanceState)
|
|
||||||
{
|
@Override
|
||||||
super.onCreate(savedInstanceState);
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.line_list);
|
|
||||||
|
try {
|
||||||
// Setup the list
|
config = new ConfigFile(new File(getDefaultConfigPath()));
|
||||||
adapter = new IconAdapter<ModuleWrapper>(this, R.layout.line_list_item);
|
} catch (IOException e) {
|
||||||
ListView list = (ListView)findViewById(R.id.list);
|
config = new ConfigFile();
|
||||||
list.setAdapter(adapter);
|
}
|
||||||
list.setOnItemClickListener(this);
|
|
||||||
|
|
||||||
setTitle("Select Libretro core");
|
|
||||||
|
|
||||||
// Populate the list
|
|
||||||
final String modulePath = getApplicationInfo().nativeLibraryDir;
|
|
||||||
for(final File lib: new File(modulePath).listFiles())
|
|
||||||
{
|
|
||||||
if(lib.getName().startsWith("libretro_"))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
adapter.add(new ModuleWrapper(this, lib));;
|
|
||||||
}
|
|
||||||
catch(Exception e)
|
|
||||||
{
|
|
||||||
//Logger.d("Couldn't add module: " + lib.getPath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onItemClick(AdapterView<?> aListView, View aView, int aPosition, long aID)
|
|
||||||
{
|
|
||||||
final ModuleWrapper item = adapter.getItem(aPosition);
|
|
||||||
libretro_path = item.file.getAbsolutePath();
|
|
||||||
|
|
||||||
Intent myIntent;
|
setContentView(R.layout.line_list);
|
||||||
myIntent = new Intent(this, DirectoryActivity.class);
|
|
||||||
startActivityForResult(myIntent, ACTIVITY_LOAD_ROM);
|
// Setup the list
|
||||||
|
adapter = new IconAdapter<ModuleWrapper>(this, R.layout.line_list_item);
|
||||||
|
ListView list = (ListView) findViewById(R.id.list);
|
||||||
|
list.setAdapter(adapter);
|
||||||
|
list.setOnItemClickListener(this);
|
||||||
|
|
||||||
|
setTitle("Select Libretro core");
|
||||||
|
|
||||||
|
// Populate the list
|
||||||
|
final String modulePath = getApplicationInfo().nativeLibraryDir;
|
||||||
|
for (final File lib : new File(modulePath).listFiles()) {
|
||||||
|
String libName = lib.getName();
|
||||||
|
|
||||||
|
// Allow both libretro-core.so and libretro_core.so.
|
||||||
|
if (libName.startsWith("libretro") && !libName.startsWith("libretroarch")) {
|
||||||
|
try {
|
||||||
|
adapter.add(new ModuleWrapper(this, lib));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> aListView, View aView,
|
||||||
|
int aPosition, long aID) {
|
||||||
|
final ModuleWrapper item = adapter.getItem(aPosition);
|
||||||
|
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)
|
private String getDefaultConfigPath() {
|
||||||
{
|
String internal = System.getenv("INTERNAL_STORAGE");
|
||||||
Intent myIntent;
|
String external = System.getenv("EXTERNAL_STORAGE");
|
||||||
|
|
||||||
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()));
|
|
||||||
myIntent.putExtra("CONFIGFILE", "");
|
|
||||||
startActivity(myIntent);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean onCreateOptionsMenu(Menu aMenu)
|
if (external != null) {
|
||||||
{
|
String confPath = external + File.separator + "retroarch.cfg";
|
||||||
super.onCreateOptionsMenu(aMenu);
|
if (new File(confPath).exists())
|
||||||
getMenuInflater().inflate(R.menu.directory_list, aMenu);
|
return confPath;
|
||||||
return true;
|
} else if (internal != null) {
|
||||||
}
|
String confPath = internal + File.separator + "retroarch.cfg";
|
||||||
|
if (new File(confPath).exists())
|
||||||
|
return confPath;
|
||||||
|
} else {
|
||||||
|
String confPath = "/mnt/extsd/retroarch.cfg";
|
||||||
|
if (new File(confPath).exists())
|
||||||
|
return confPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (internal != null && new File(internal + File.separator + "retroarch.cfg").canWrite())
|
||||||
|
return internal + File.separator + "retroarch.cfg";
|
||||||
|
else if (external != null && new File(internal + File.separator + "retroarch.cfg").canWrite())
|
||||||
|
return external + File.separator + "retroarch.cfg";
|
||||||
|
else
|
||||||
|
return getCacheDir().getAbsolutePath() + File.separator + "retroarch.cfg";
|
||||||
|
}
|
||||||
|
|
||||||
@Override public boolean onOptionsItemSelected(MenuItem aItem)
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
{
|
Intent myIntent;
|
||||||
if(R.id.input_method_select == aItem.getItemId())
|
|
||||||
{
|
switch (requestCode) {
|
||||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
case ACTIVITY_LOAD_ROM:
|
||||||
imm.showInputMethodPicker();
|
if (data.getStringExtra("PATH") != null) {
|
||||||
return true;
|
Toast.makeText(this,
|
||||||
}
|
"Loading: [" + data.getStringExtra("PATH") + "]...",
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
return super.onOptionsItemSelected(aItem);
|
myIntent = new Intent(this, NativeActivity.class);
|
||||||
}
|
myIntent.putExtra("ROM", data.getStringExtra("PATH"));
|
||||||
|
myIntent.putExtra("LIBRETRO", libretro_path);
|
||||||
|
myIntent.putExtra("REFRESHRATE",
|
||||||
|
Float.toString(getRefreshRate()));
|
||||||
|
myIntent.putExtra("CONFIGFILE", getDefaultConfigPath());
|
||||||
|
startActivity(myIntent);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreateOptionsMenu(Menu aMenu) {
|
||||||
|
super.onCreateOptionsMenu(aMenu);
|
||||||
|
getMenuInflater().inflate(R.menu.directory_list, aMenu);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showPopup(View v) {
|
||||||
|
PopupMenu menu = new PopupMenu(this, v);
|
||||||
|
MenuInflater inflater = menu.getMenuInflater();
|
||||||
|
inflater.inflate(R.menu.context_menu, menu.getMenu());
|
||||||
|
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.input_method_select:
|
||||||
|
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
imm.showInputMethodPicker();
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.video_settings:
|
||||||
|
Log.i(TAG, "Video settings clicked!");
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.audio_settings:
|
||||||
|
Log.i(TAG, "Audio settings clicked!");
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case R.id.general_settings:
|
||||||
|
Log.i(TAG, "General settings clicked!");
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem aItem) {
|
||||||
|
switch (aItem.getItemId()) {
|
||||||
|
case R.id.settings:
|
||||||
|
showPopup(findViewById(R.id.settings));
|
||||||
|
Log.i(TAG, "Got settings ...");
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(aItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
37
settings.c
37
settings.c
@ -279,43 +279,6 @@ static config_file_t *open_default_config_file(void)
|
|||||||
}
|
}
|
||||||
if (!conf)
|
if (!conf)
|
||||||
conf = config_file_new("/etc/retroarch.cfg");
|
conf = config_file_new("/etc/retroarch.cfg");
|
||||||
#elif defined(ANDROID)
|
|
||||||
char conf_path[PATH_MAX];
|
|
||||||
const char *storage = getenv("EXTERNAL_STORAGE");
|
|
||||||
|
|
||||||
if (storage)
|
|
||||||
{
|
|
||||||
snprintf(conf_path, sizeof(conf_path), "%s/retroarch.cfg", storage);
|
|
||||||
conf = config_file_new(conf_path);
|
|
||||||
|
|
||||||
if (!conf)
|
|
||||||
RARCH_WARN("Could not load config file: [%s].\n", conf_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!conf)
|
|
||||||
{
|
|
||||||
storage = getenv("INTERNAL_STORAGE");
|
|
||||||
|
|
||||||
if (storage)
|
|
||||||
{
|
|
||||||
snprintf(conf_path, sizeof(conf_path), "%s/retroarch.cfg", storage);
|
|
||||||
RARCH_WARN("Trying: [%s].\n", conf_path);
|
|
||||||
conf = config_file_new(conf_path);
|
|
||||||
|
|
||||||
if (!conf)
|
|
||||||
RARCH_WARN("Could not load config file: [%s].\n", conf_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Try this as a last chance (EXTSD)...
|
|
||||||
if (!conf)
|
|
||||||
{
|
|
||||||
RARCH_WARN("Trying last fallback: [%s].\n", "/mnt/extsd/retroarch.cfg");
|
|
||||||
conf = config_file_new("/mnt/extsd/retroarch.cfg");
|
|
||||||
|
|
||||||
if (conf)
|
|
||||||
RARCH_LOG("Successfully loaded config file: [%s].\n", "/mnt/extsd/retroarch.cfg");
|
|
||||||
}
|
|
||||||
#elif !defined(__CELLOS_LV2__) && !defined(_XBOX)
|
#elif !defined(__CELLOS_LV2__) && !defined(_XBOX)
|
||||||
char conf_path[PATH_MAX];
|
char conf_path[PATH_MAX];
|
||||||
const char *xdg = getenv("XDG_CONFIG_HOME");
|
const char *xdg = getenv("XDG_CONFIG_HOME");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user