Android: Add option to clear per-game config

This commit is contained in:
Ender's Games 2018-08-26 11:21:56 -04:00
parent ff81632578
commit 41cf6e957e
4 changed files with 85 additions and 8 deletions

View File

@ -111,11 +111,26 @@ public class PGConfigFragment extends Fragment {
.putBoolean(Emulator.pref_queuerender, queue_render.isChecked())
.putBoolean(Emulator.pref_modvols, modifier_volumes.isChecked())
.putBoolean(Emulator.pref_interrupt, interrupt_opt.isChecked()).apply();
showToastMessage(getActivity().getString(R.string.pgconfig_saved),
Snackbar.LENGTH_SHORT);
showToastMessage(getActivity().getString(R.string.pgconfig_saved), Snackbar.LENGTH_SHORT);
}
private void configureViewByGame(String gameId) {
private void clearSettings(SharedPreferences mPrefs, String gameId) {
mPrefs.edit() // Prevent clear() removing title
.remove(Gamepad.pref_js_merged + "_A")
.remove(Emulator.pref_dynarecopt)
.remove(Emulator.pref_unstable)
.remove(Emulator.pref_dynsafemode)
.remove(Emulator.pref_frameskip)
.remove(Emulator.pref_pvrrender)
.remove(Emulator.pref_syncedrender)
.remove(Emulator.pref_queuerender)
.remove(Emulator.pref_modvols)
.remove(Emulator.pref_interrupt).apply();
showToastMessage(getActivity().getString(R.string.pgconfig_cleared), Snackbar.LENGTH_SHORT);
configureViewByGame(gameId);
}
private void configureViewByGame(final String gameId) {
final SharedPreferences mPrefs = getActivity()
.getSharedPreferences(gameId, Activity.MODE_PRIVATE);
switchJoystickDpadEnabled.setChecked(mPrefs.getBoolean(
@ -170,6 +185,13 @@ public class PGConfigFragment extends Fragment {
saveSettings(mPrefs);
}
});
Button clearPGC = (Button) getView().findViewById(R.id.clear_pg_btn);
clearPGC.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
clearSettings(mPrefs, gameId);
}
});
}
private static class LocateConfigs extends AsyncTask<String, Integer, List<File>> {

View File

@ -370,7 +370,6 @@
android:gravity="center_vertical" >
<TextView
android:id="@+id/apply_pg_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
@ -389,7 +388,34 @@
android:id="@+id/save_pg_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/write_pgc" />
android:text="@string/save_pgc" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="10dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/clear_pgc_title" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/clear_pg_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/clear_pgc" />
</LinearLayout>
</TableRow>
</TableLayout>

View File

@ -370,7 +370,6 @@
android:gravity="center_vertical" >
<TextView
android:id="@+id/apply_pg_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
@ -389,7 +388,34 @@
android:id="@+id/save_pg_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/write_pgc" />
android:text="@string/save_pgc" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="10dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/save_pgc_title" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/clear_pg_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/clear_pgc" />
</LinearLayout>
</TableRow>
</TableLayout>

View File

@ -64,8 +64,11 @@
<string name="pgc_doc">Per-Game Configuration\nThese options will override the default settings.\nTo add a game, launch it from the main game list\nGames will appear when returning to this window\nAfter changing settings, make sure to \"Save PCG\"</string>
<string name="pgc_select_game">Select Game</string>
<string name="save_pgc_title">Save Per-Game Config</string>
<string name="write_pgc">Save PGC</string>
<string name="save_pgc">Save PGC</string>
<string name="pgconfig_saved">Configuration Saved</string>
<string name="clear_pgc_title">Clear Per-Game Config</string>
<string name="clear_pgc">Clear PGC</string>
<string name="pgconfig_cleared">Configuration Cleared</string>
<string name="games_listing">Game List</string>
<string name="search_hint">Game (ie. Crazy Taxi)</string>