Add a configuration option for emulator specific GUI config

This commit is contained in:
LoungeKatt 2013-12-26 23:23:05 -05:00
parent 39d88ccbb6
commit acef71f184
6 changed files with 523 additions and 20 deletions

View File

@ -0,0 +1,82 @@
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:id="@+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/select_stretch" />
<Switch
android:id="@+id/stretch_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:text="@string/set_frameskip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<SeekBar
android:layout_weight="1"
android:id="@+id/frame_seekbar"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:ems="10"
android:progress="0"
android:max="5"/>
<TextView
android:layout_weight="1"
android:id="@+id/current_frames"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:ems="10"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:id="@+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/select_render" />
<Switch
android:id="@+id/render_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,82 @@
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:id="@+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/select_stretch" />
<CheckBox
android:id="@+id/stretch_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:text="@string/set_frameskip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<SeekBar
android:layout_weight="1"
android:id="@+id/frame_seekbar"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:ems="10"
android:progress="0"
android:max="5"/>
<TextView
android:layout_weight="1"
android:id="@+id/current_frames"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:ems="10"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_weight="1"
android:id="@+id/textView1"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:ems="10"
android:text="@string/select_render" />
<CheckBox
android:id="@+id/render_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>

View File

@ -4,13 +4,13 @@
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">reicast</string>
<string name="system_path">System Path (location of dc_boot.bin/dc_flash.bin)</string>
<string name="browser_path">Default System Path</string>
<string name="games_path">Storage Path (location of .gid .cdi or .cdh images)</string>
<string name="game_path">Default Game Storage</string>
<string name="select_stretch">Stretch to Fullscreen</string>
<string name="set_frameskip">Frameskipping Amount</string>
<string name="select_render">PVR Rendering</string>
<string name="games_listing">Available Dreamcast Games</string>
<string-array name="images">
@ -18,25 +18,27 @@
<item>chd</item>
<item>gdi</item>
</string-array>
<string name="drawer_open">Slider Menu Opened</string>
<string name="drawer_close">Slider Menu Closed</string>
<!-- Nav Drawer Menu Items -->
<string-array name="nav_drawer_items">
<item >Browser</item>
<item >Options</item>
<item >About</item>
<item>Browser</item>
<item>Options</item>
<item>Emulator</item>
<item>About</item>
</string-array>
<!-- Nav Drawer List Item Icons -->
<!-- Keep them in order as the titles are in -->
<array name="nav_drawer_icons">
<item>@drawable/disk_unknown</item>
<item>@drawable/config</item>
<item>@drawable/question</item>
<item>@drawable/config</item>
<item>@drawable/question</item>
</array>
<!-- Content Description -->
<string name="desc_list_item_icon">Item Icon</string>

View File

@ -0,0 +1,321 @@
package com.reicast.emulator;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Scanner;
import org.apache.commons.lang3.StringUtils;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Switch;
import android.widget.TextView;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class ConfigureFragment extends Fragment {
Activity parentActivity;
TextView mainFrames;
OnClickListener mCallback;
boolean widescreen = false;
boolean pvrrender = false;
int frameskip = 0;
private SharedPreferences mPrefs;
private File sdcard = Environment.getExternalStorageDirectory();
private String home_directory = sdcard + "/dc";
// Container Activity must implement this interface
public interface OnClickListener {
public void onMainBrowseSelected(String path_entry, boolean games);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.configure_fragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
// setContentView(R.layout.activity_main);
parentActivity = getActivity();
mPrefs = PreferenceManager.getDefaultSharedPreferences(parentActivity);
home_directory = mPrefs.getString("home_directory", home_directory);
try {
File config = new File(home_directory, "emu.cfg");
if (config.exists()) {
Scanner scanner = new Scanner(config);
String currentLine;
while (scanner.hasNextLine()) {
currentLine = scanner.nextLine();
if (StringUtils.containsIgnoreCase(currentLine,
"rend.WideScreen")) {
widescreen = Boolean.valueOf(currentLine.replace(
"rend.WideScreen=", ""));
}
if (StringUtils.containsIgnoreCase(currentLine, "ta.skip")) {
frameskip = Integer.valueOf(currentLine.replace(
"ta.skip=", ""));
}
if (StringUtils.containsIgnoreCase(currentLine, "pvr.rend")) {
pvrrender = Boolean.valueOf(currentLine.replace(
"pvr.rend=", ""));
}
}
scanner.close();
}
} catch (Exception e) {
Log.d("reicast", "Exception: " + e);
}
mainFrames = (TextView) getView().findViewById(R.id.current_frames);
mainFrames.setText(String.valueOf(frameskip));
OnCheckedChangeListener full_screen = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("stretch_view", isChecked).commit();
File config = new File(home_directory, "emu.cfg");
try {
StringBuilder rebuildFile = new StringBuilder();
if (config.exists()) {
Scanner scanner = new Scanner(config);
String currentLine;
while (scanner.hasNextLine()) {
currentLine = scanner.nextLine();
if (StringUtils.containsIgnoreCase(currentLine,
"rend.WideScreen")) {
rebuildFile.append("rend.WideScreen="
+ String.valueOf(isChecked ? 1 : 0)
+ "\n");
} else {
rebuildFile.append(currentLine + "\n");
}
}
scanner.close();
config.delete();
// Investigate alternatives to not re-read
} else {
rebuildFile.append("[config]" + "\n");
rebuildFile.append("Dynarec.Enabled=1" + "\n");
rebuildFile.append("Dynarec.idleskip=1" + "\n");
rebuildFile.append("Dynarec.unstable-opt=0" + "\n");
rebuildFile.append("Dreamcast.Cable=3" + "\n");
rebuildFile.append("Dreamcast.RTC=2018927206" + "\n");
rebuildFile.append("Dreamcast.Region=3" + "\n");
rebuildFile.append("Dreamcast.Broadcast=4" + "\n");
rebuildFile.append("aica.LimitFPS=1" + "\n");
rebuildFile.append("aica.NoBatch=0" + "\n");
rebuildFile.append("rend.UseMipmaps=1" + "\n");
rebuildFile.append("rend.WideScreen="
+ String.valueOf(isChecked ? 1 : 0) + "\n");
rebuildFile.append("pvr.Subdivide=0" + "\n");
rebuildFile.append("ta.skip=" + frameskip + "\n");
rebuildFile.append("pvr.rend="
+ String.valueOf(pvrrender ? 1 : 0) + "\n");
rebuildFile.append("image=null" + "\n");
}
FileOutputStream fos = new FileOutputStream(config);
fos.write(rebuildFile.toString().getBytes());
fos.close();
widescreen = isChecked;
} catch (Exception e) {
Log.d("reicast", "Exception: " + e);
}
}
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
Switch stretch_view = (Switch) getView().findViewById(
R.id.stretch_option);
boolean stretched = mPrefs.getBoolean("stretch_view", widescreen);
if (stretched) {
stretch_view.setChecked(true);
} else {
stretch_view.setChecked(false);
}
stretch_view.setOnCheckedChangeListener(full_screen);
} else {
CheckBox stretch_view = (CheckBox) getView().findViewById(
R.id.stretch_option);
boolean stretched = mPrefs.getBoolean("stretch_view", widescreen);
if (stretched) {
stretch_view.setChecked(true);
} else {
stretch_view.setChecked(false);
}
stretch_view.setOnCheckedChangeListener(full_screen);
}
SeekBar frameSeek = (SeekBar) getView()
.findViewById(R.id.frame_seekbar);
int userFrames = mPrefs.getInt("frame_skip", frameskip);
frameSeek.setProgress(userFrames);
frameSeek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int progressChanged = 0;
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
progressChanged = progress;
mainFrames.setText(progress);
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
mPrefs.edit().putInt("frame_skip", progressChanged).commit();
File config = new File(home_directory, "emu.cfg");
try {
StringBuilder rebuildFile = new StringBuilder();
if (config.exists()) {
Scanner scanner = new Scanner(config);
String currentLine;
while (scanner.hasNextLine()) {
currentLine = scanner.nextLine();
if (StringUtils.containsIgnoreCase(currentLine,
"ta.skip")) {
rebuildFile.append("ta.skip=" + progressChanged
+ "\n");
} else {
rebuildFile.append(currentLine + "\n");
}
}
scanner.close();
config.delete();
} else {
rebuildFile.append("[config]" + "\n");
rebuildFile.append("Dynarec.Enabled=1" + "\n");
rebuildFile.append("Dynarec.idleskip=1" + "\n");
rebuildFile.append("Dynarec.unstable-opt=0" + "\n");
rebuildFile.append("Dreamcast.Cable=3" + "\n");
rebuildFile.append("Dreamcast.RTC=2018927206" + "\n");
rebuildFile.append("Dreamcast.Region=3" + "\n");
rebuildFile.append("Dreamcast.Broadcast=4" + "\n");
rebuildFile.append("aica.LimitFPS=1" + "\n");
rebuildFile.append("aica.NoBatch=0" + "\n");
rebuildFile.append("rend.UseMipmaps=1" + "\n");
rebuildFile.append("rend.WideScreen="
+ String.valueOf(widescreen ? 1 : 0) + "\n");
rebuildFile.append("pvr.Subdivide=0" + "\n");
rebuildFile.append("ta.skip=" + progressChanged + "\n");
rebuildFile.append("pvr.rend="
+ String.valueOf(pvrrender ? 1 : 0) + "\n");
rebuildFile.append("image=null" + "\n");
}
FileOutputStream fos = new FileOutputStream(config);
fos.write(rebuildFile.toString().getBytes());
fos.close();
frameskip = progressChanged;
} catch (Exception e) {
Log.d("reicast", "Exception: " + e);
}
}
});
OnCheckedChangeListener pvr_rendering = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean("pvr_render", isChecked).commit();
File config = new File(home_directory, "emu.cfg");
try {
StringBuilder rebuildFile = new StringBuilder();
if (config.exists()) {
Scanner scanner = new Scanner(config);
String currentLine;
while (scanner.hasNextLine()) {
currentLine = scanner.nextLine();
if (StringUtils.containsIgnoreCase(currentLine,
"pvr.rend")) {
rebuildFile.append("pvr.rend="
+ String.valueOf(isChecked ? 1 : 0)
+ "\n");
} else {
rebuildFile.append(currentLine + "\n");
}
}
scanner.close();
config.delete();
// Investigate alternatives to not re-read
} else {
rebuildFile.append("[config]" + "\n");
rebuildFile.append("Dynarec.Enabled=1" + "\n");
rebuildFile.append("Dynarec.idleskip=1" + "\n");
rebuildFile.append("Dynarec.unstable-opt=0" + "\n");
rebuildFile.append("Dreamcast.Cable=3" + "\n");
rebuildFile.append("Dreamcast.RTC=2018927206" + "\n");
rebuildFile.append("Dreamcast.Region=3" + "\n");
rebuildFile.append("Dreamcast.Broadcast=4" + "\n");
rebuildFile.append("aica.LimitFPS=1" + "\n");
rebuildFile.append("aica.NoBatch=0" + "\n");
rebuildFile.append("rend.UseMipmaps=1" + "\n");
rebuildFile.append("rend.WideScreen=" + widescreen
+ "\n");
rebuildFile.append("pvr.Subdivide=0" + "\n");
rebuildFile.append("ta.skip=" + frameskip + "\n");
rebuildFile.append("pvr.rend="
+ String.valueOf(isChecked ? 1 : 0) + "\n");
rebuildFile.append("image=null" + "\n");
}
FileOutputStream fos = new FileOutputStream(config);
fos.write(rebuildFile.toString().getBytes());
fos.close();
pvrrender = isChecked;
} catch (Exception e) {
Log.d("reicast", "Exception: " + e);
}
}
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
Switch pvr_render = (Switch) getView().findViewById(
R.id.stretch_option);
boolean rendered = mPrefs.getBoolean("pvr_render", pvrrender);
if (rendered) {
pvr_render.setChecked(true);
} else {
pvr_render.setChecked(false);
}
pvr_render.setOnCheckedChangeListener(pvr_rendering);
} else {
CheckBox pvr_render = (CheckBox) getView().findViewById(
R.id.stretch_option);
boolean rendered = mPrefs.getBoolean("pvr_render", pvrrender);
if (rendered) {
pvr_render.setChecked(true);
} else {
pvr_render.setChecked(false);
}
pvr_render.setOnCheckedChangeListener(pvr_rendering);
}
}
}

View File

@ -112,9 +112,12 @@ public class MainActivity extends FragmentActivity implements
// Options
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons
.getResourceId(1, -1)));
// Config
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons
.getResourceId(2, -1)));
// About
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons
.getResourceId(2, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons
.getResourceId(3, -1)));
// Recycle the typed array
navMenuIcons.recycle();
@ -332,6 +335,17 @@ public class MainActivity extends FragmentActivity implements
frag_tag = "OPTIONS_FRAG";
break;
case 2:
fragment = (ConfigureFragment) getSupportFragmentManager()
.findFragmentByTag("CONFIG_FRAG");
if (fragment != null) {
if (fragment.isVisible()) {
return;
}
}
fragment = new ConfigureFragment();
frag_tag = "CONFIG_FRAG";
break;
case 3:
fragment = null;
// vib.vibrate(50);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(

View File

@ -19,14 +19,14 @@ import android.widget.Button;
import android.widget.EditText;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public class OptionsFragment extends Fragment{
public class OptionsFragment extends Fragment {
Activity parentActivity;
Button mainBrowse;
Button gameBrowse;
Button mainLocale;
OnClickListener mCallback;
private SharedPreferences mPrefs;
private File sdcard = Environment.getExternalStorageDirectory();
private String home_directory = sdcard + "/dc";
@ -72,12 +72,14 @@ public class OptionsFragment extends Fragment{
// setContentView(R.layout.activity_main);
parentActivity = getActivity();
mPrefs = PreferenceManager.getDefaultSharedPreferences(parentActivity);
home_directory = mPrefs.getString("home_directory", home_directory);
mainBrowse = (Button) getView().findViewById(R.id.browse_main_path);
final EditText editBrowse = (EditText) getView().findViewById(
R.id.main_path);
mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
home_directory = mPrefs.getString("home_directory", home_directory);
editBrowse.setText(home_directory);
mainBrowse.setOnClickListener(new View.OnClickListener() {
@ -88,9 +90,9 @@ public class OptionsFragment extends Fragment{
mCallback.onMainBrowseSelected(browse_entry, false);
}
});
gameBrowse = (Button) getView().findViewById(R.id.browse_game_path);
final EditText editGames = (EditText) getView().findViewById(
R.id.game_path);
game_directory = mPrefs.getString("game_directory", game_directory);