mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-14 22:47:44 +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" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="9"
|
||||
android:minSdkVersion="11"
|
||||
android:targetSdkVersion="16" />
|
||||
<uses-permission android:name="android.permission.WRITE_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"?>
|
||||
<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>
|
||||
</menu>
|
||||
<item android:id="@+id/settings"
|
||||
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="input_method">Input Method</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>
|
@ -15,40 +15,46 @@ public class ConfigFile {
|
||||
public void append(File file) throws IOException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(
|
||||
new FileInputStream(file.getAbsolutePath())));
|
||||
|
||||
|
||||
String line;
|
||||
while ((line = br.readLine()) != null)
|
||||
parseLine(line);
|
||||
|
||||
|
||||
br.close();
|
||||
}
|
||||
|
||||
|
||||
public void open(File file) throws IOException {
|
||||
clear();
|
||||
append(file);
|
||||
}
|
||||
|
||||
public ConfigFile(File file) throws IOException {
|
||||
open(file);
|
||||
}
|
||||
|
||||
public ConfigFile() {}
|
||||
|
||||
private void parseLine(String line) {
|
||||
String[] tokens = line.split("=", 2);
|
||||
if (tokens.length < 2) {
|
||||
System.err.println("Didn't find two tokens in config line ...");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < tokens.length; i++)
|
||||
tokens[i] = tokens[i].trim();
|
||||
|
||||
|
||||
String key = tokens[0];
|
||||
String value = tokens[1];
|
||||
|
||||
|
||||
if (value.startsWith("\""))
|
||||
value = value.substring(1, value.lastIndexOf('\"'));
|
||||
else
|
||||
value = value.split(" ")[0];
|
||||
|
||||
|
||||
if (value.length() > 0)
|
||||
map.put(key, value);
|
||||
|
||||
|
||||
System.out.println("Parsed: \"" + key + "\" => \"" + value + "\"");
|
||||
}
|
||||
|
||||
@ -69,7 +75,7 @@ public class ConfigFile {
|
||||
public void setString(String key, String value) {
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
|
||||
public void setBoolean(String key, boolean value) {
|
||||
map.put(key, Boolean.toString(value));
|
||||
}
|
||||
@ -81,15 +87,15 @@ public class ConfigFile {
|
||||
public void setDouble(String key, double value) {
|
||||
map.put(key, Double.toString(value));
|
||||
}
|
||||
|
||||
|
||||
public boolean keyExists(String key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
|
||||
public String getString(String key) {
|
||||
Object ret = map.get(key);
|
||||
if (ret != null)
|
||||
return (String)ret;
|
||||
return (String) ret;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
@ -101,7 +107,7 @@ public class ConfigFile {
|
||||
else
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
|
||||
|
||||
public double getDouble(String key) throws NumberFormatException {
|
||||
String str = getString(key);
|
||||
if (str != null)
|
||||
@ -109,7 +115,7 @@ public class ConfigFile {
|
||||
else
|
||||
throw new NumberFormatException();
|
||||
}
|
||||
|
||||
|
||||
public boolean getBoolean(String key) {
|
||||
String str = getString(key);
|
||||
return Boolean.parseBoolean(str);
|
||||
|
@ -1,4 +1,5 @@
|
||||
package org.retroarch.browser;
|
||||
|
||||
import org.retroarch.R;
|
||||
|
||||
import java.util.*;
|
||||
@ -9,252 +10,210 @@ import android.app.*;
|
||||
import android.os.*;
|
||||
import android.widget.*;
|
||||
import android.view.*;
|
||||
import android.view.inputmethod.*;
|
||||
import android.graphics.drawable.*;
|
||||
|
||||
class FileWrapper implements IconAdapterItem
|
||||
{
|
||||
public final File file;
|
||||
public final boolean parentItem;
|
||||
protected final int typeIndex;
|
||||
protected final boolean enabled;
|
||||
class FileWrapper implements IconAdapterItem {
|
||||
public final File file;
|
||||
public final boolean parentItem;
|
||||
protected final int typeIndex;
|
||||
protected final boolean enabled;
|
||||
|
||||
public FileWrapper(File aFile, boolean aIsParentItem, boolean aIsEnabled)
|
||||
{
|
||||
file = aFile;
|
||||
typeIndex = aIsParentItem ? 0 : (file.isDirectory() ? 1 : 0) + (file.isFile() ? 2 : 0);
|
||||
parentItem = aIsParentItem;
|
||||
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();
|
||||
}
|
||||
public FileWrapper(File aFile, boolean aIsParentItem, boolean aIsEnabled) {
|
||||
file = aFile;
|
||||
typeIndex = aIsParentItem ? 0 : (file.isDirectory() ? 1 : 0)
|
||||
+ (file.isFile() ? 2 : 0);
|
||||
parentItem = aIsParentItem;
|
||||
enabled = aIsParentItem || aIsEnabled;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
@Override
|
||||
public String getText() {
|
||||
return parentItem ? "[Parent Directory]" : file.getName();
|
||||
}
|
||||
|
||||
@Override public boolean onCreateOptionsMenu(Menu aMenu)
|
||||
{
|
||||
super.onCreateOptionsMenu(aMenu);
|
||||
getMenuInflater().inflate(R.menu.directory_list, aMenu);
|
||||
@Override
|
||||
public int getIconResourceId() {
|
||||
if (!parentItem) {
|
||||
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)
|
||||
{
|
||||
if(R.id.input_method_select == aItem.getItemId())
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showInputMethodPicker();
|
||||
return true;
|
||||
}
|
||||
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 super.onOptionsItemSelected(aItem);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
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
|
||||
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;
|
||||
|
||||
import org.retroarch.R;
|
||||
|
||||
import android.app.*;
|
||||
@ -7,72 +8,64 @@ import android.graphics.drawable.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
interface IconAdapterItem
|
||||
{
|
||||
interface IconAdapterItem {
|
||||
public abstract boolean isEnabled();
|
||||
|
||||
public abstract String getText();
|
||||
|
||||
public abstract int getIconResourceId();
|
||||
|
||||
public abstract Drawable getIconDrawable();
|
||||
}
|
||||
|
||||
class IconAdapter<T extends IconAdapterItem> extends ArrayAdapter<T>
|
||||
{
|
||||
private final int layout;
|
||||
class IconAdapter<T extends IconAdapterItem> extends ArrayAdapter<T> {
|
||||
private final int layout;
|
||||
|
||||
public IconAdapter(Activity aContext, int 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();
|
||||
public IconAdapter(Activity aContext, int aLayout) {
|
||||
super(aContext, aLayout);
|
||||
|
||||
TextView textView = (TextView)aConvertView.findViewById(R.id.name);
|
||||
if(null != textView)
|
||||
{
|
||||
textView.setText(item.getText());
|
||||
textView.setEnabled(enabled);
|
||||
}
|
||||
|
||||
ImageView imageView = (ImageView)aConvertView.findViewById(R.id.icon);
|
||||
if(null != imageView)
|
||||
{
|
||||
if(enabled)
|
||||
{
|
||||
final int id = item.getIconResourceId();
|
||||
if(0 != id)
|
||||
{
|
||||
imageView.setImageResource(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
imageView.setImageDrawable(item.getIconDrawable());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
imageView.setImageDrawable(null);
|
||||
}
|
||||
}
|
||||
|
||||
return aConvertView;
|
||||
}
|
||||
|
||||
@Override public boolean isEnabled(int aPosition)
|
||||
{
|
||||
return getItem(aPosition).isEnabled();
|
||||
}
|
||||
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);
|
||||
if (null != textView) {
|
||||
textView.setText(item.getText());
|
||||
textView.setEnabled(enabled);
|
||||
}
|
||||
|
||||
ImageView imageView = (ImageView) aConvertView.findViewById(R.id.icon);
|
||||
if (null != imageView) {
|
||||
if (enabled) {
|
||||
final int id = item.getIconResourceId();
|
||||
if (0 != id) {
|
||||
imageView.setImageResource(id);
|
||||
} else {
|
||||
imageView.setImageDrawable(item.getIconDrawable());
|
||||
}
|
||||
} else {
|
||||
imageView.setImageDrawable(null);
|
||||
}
|
||||
}
|
||||
|
||||
return aConvertView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(int aPosition) {
|
||||
return getItem(aPosition).isEnabled();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.retroarch.browser;
|
||||
import org.retroarch.R;
|
||||
|
||||
import org.retroarch.R;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@ -8,133 +8,197 @@ import android.content.*;
|
||||
import android.app.*;
|
||||
import android.os.*;
|
||||
import android.widget.*;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
import android.view.inputmethod.*;
|
||||
import android.graphics.drawable.*;
|
||||
|
||||
class ModuleWrapper implements IconAdapterItem
|
||||
{
|
||||
class ModuleWrapper implements IconAdapterItem {
|
||||
public final File file;
|
||||
|
||||
public ModuleWrapper(Context aContext, File aFile) throws IOException
|
||||
{
|
||||
|
||||
public ModuleWrapper(Context aContext, File aFile) throws IOException {
|
||||
file = aFile;
|
||||
}
|
||||
|
||||
@Override public boolean isEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public String getText()
|
||||
{
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
@Override public int getIconResourceId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override public Drawable getIconDrawable()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return file.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconResourceId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIconDrawable() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class ModuleActivity extends Activity implements AdapterView.OnItemClickListener
|
||||
{
|
||||
private IconAdapter<ModuleWrapper> adapter;
|
||||
public class ModuleActivity extends Activity implements
|
||||
AdapterView.OnItemClickListener {
|
||||
private IconAdapter<ModuleWrapper> 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)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.line_list);
|
||||
|
||||
// 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())
|
||||
{
|
||||
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();
|
||||
static private final String TAG = "RetroArch";
|
||||
private ConfigFile config;
|
||||
|
||||
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) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
try {
|
||||
config = new ConfigFile(new File(getDefaultConfigPath()));
|
||||
} catch (IOException e) {
|
||||
config = new ConfigFile();
|
||||
}
|
||||
|
||||
Intent myIntent;
|
||||
myIntent = new Intent(this, DirectoryActivity.class);
|
||||
startActivityForResult(myIntent, ACTIVITY_LOAD_ROM);
|
||||
setContentView(R.layout.line_list);
|
||||
|
||||
// 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)
|
||||
{
|
||||
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()));
|
||||
myIntent.putExtra("CONFIGFILE", "");
|
||||
startActivity(myIntent);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
private String getDefaultConfigPath() {
|
||||
String internal = System.getenv("INTERNAL_STORAGE");
|
||||
String external = System.getenv("EXTERNAL_STORAGE");
|
||||
|
||||
@Override public boolean onCreateOptionsMenu(Menu aMenu)
|
||||
{
|
||||
super.onCreateOptionsMenu(aMenu);
|
||||
getMenuInflater().inflate(R.menu.directory_list, aMenu);
|
||||
return true;
|
||||
}
|
||||
if (external != null) {
|
||||
String confPath = external + File.separator + "retroarch.cfg";
|
||||
if (new File(confPath).exists())
|
||||
return confPath;
|
||||
} 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)
|
||||
{
|
||||
if(R.id.input_method_select == aItem.getItemId())
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showInputMethodPicker();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(aItem);
|
||||
}
|
||||
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()));
|
||||
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)
|
||||
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)
|
||||
char conf_path[PATH_MAX];
|
||||
const char *xdg = getenv("XDG_CONFIG_HOME");
|
||||
|
Loading…
x
Reference in New Issue
Block a user