Android: Add options to import / export PGC
This commit is contained in:
parent
75ae974f68
commit
dd88d7a8e9
|
@ -35,7 +35,12 @@ import com.reicast.emulator.R;
|
||||||
import com.reicast.emulator.periph.Gamepad;
|
import com.reicast.emulator.periph.Gamepad;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -186,6 +191,37 @@ public class PGConfigFragment extends Fragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Button importPGC = (Button) getView().findViewById(R.id.import_pg_btn);
|
||||||
|
importPGC.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
try {
|
||||||
|
copy(new File(getActivity().getExternalFilesDir(null), gameId
|
||||||
|
+ ".xml"), new File("/data/data/" + getActivity()
|
||||||
|
.getPackageName(),"/shared_prefs/" + gameId + ".xml"));
|
||||||
|
showToastMessage(getActivity().getString(
|
||||||
|
R.string.pgconfig_imported), Snackbar.LENGTH_SHORT);
|
||||||
|
configureViewByGame(gameId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Button exportPGC = (Button) getView().findViewById(R.id.export_pg_btn);
|
||||||
|
exportPGC.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View view) {
|
||||||
|
try {
|
||||||
|
copy(new File("/data/data/" + getActivity().getPackageName(),
|
||||||
|
"/shared_prefs/" + gameId + ".xml"), new File(getActivity()
|
||||||
|
.getExternalFilesDir(null), gameId + ".xml"));
|
||||||
|
showToastMessage(getActivity().getString(
|
||||||
|
R.string.pgconfig_exported), Snackbar.LENGTH_SHORT);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Button clearPGC = (Button) getView().findViewById(R.id.clear_pg_btn);
|
Button clearPGC = (Button) getView().findViewById(R.id.clear_pg_btn);
|
||||||
clearPGC.setOnClickListener(new View.OnClickListener() {
|
clearPGC.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
@ -194,6 +230,35 @@ public class PGConfigFragment extends Fragment {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void copy(File src, File dst) throws IOException {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
|
try (InputStream in = new FileInputStream(src)) {
|
||||||
|
try (OutputStream out = new FileOutputStream(dst)) {
|
||||||
|
// Transfer bytes from in to out
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
out.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
InputStream in = new FileInputStream(src);
|
||||||
|
OutputStream out = new FileOutputStream(dst);
|
||||||
|
try {
|
||||||
|
// Transfer bytes from in to out
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = in.read(buf)) > 0) {
|
||||||
|
out.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
in.close();
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class LocateConfigs extends AsyncTask<String, Integer, List<File>> {
|
private static class LocateConfigs extends AsyncTask<String, Integer, List<File>> {
|
||||||
private WeakReference<PGConfigFragment> options;
|
private WeakReference<PGConfigFragment> options;
|
||||||
|
|
||||||
|
|
|
@ -683,7 +683,6 @@ public class GL2JNIView extends GLSurfaceView
|
||||||
Gamepad.pref_js_merged + "_A", ((GL2JNINative) context).getPad().joystick[0]);
|
Gamepad.pref_js_merged + "_A", ((GL2JNINative) context).getPad().joystick[0]);
|
||||||
mPrefs.edit().putString(Config.game_title, reiosSoftware.trim()).apply();
|
mPrefs.edit().putString(Config.game_title, reiosSoftware.trim()).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
|
|
@ -368,56 +368,42 @@
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:gravity="center_vertical" >
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginRight="6dp" >
|
||||||
|
|
||||||
<TextView
|
<Button
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/clear_pg_btn"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
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_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="right"
|
android:text="@string/clear_pgc" />
|
||||||
android:orientation="vertical" >
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/save_pg_btn"
|
android:id="@+id/save_pg_btn"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/save_pgc" />
|
android:layout_weight="1"
|
||||||
</LinearLayout>
|
android:text="@string/save_pgc" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:gravity="center_vertical" >
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginRight="6dp" >
|
||||||
|
|
||||||
<TextView
|
<Button
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/import_pg_btn"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
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_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="right"
|
android:text="@string/import_pgc" />
|
||||||
android:orientation="vertical" >
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/clear_pg_btn"
|
android:id="@+id/export_pg_btn"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/clear_pgc" />
|
android:layout_weight="1"
|
||||||
</LinearLayout>
|
android:text="@string/export_pgc" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableLayout>
|
</TableLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -368,57 +368,44 @@
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:gravity="center_vertical" >
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginRight="6dp" >
|
||||||
|
|
||||||
<TextView
|
<Button
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/clear_pg_btn"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
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_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="right"
|
android:text="@string/clear_pgc" />
|
||||||
android:orientation="vertical" >
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/save_pg_btn"
|
android:id="@+id/save_pg_btn"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/save_pgc" />
|
android:layout_weight="1"
|
||||||
</LinearLayout>
|
android:text="@string/save_pgc" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:gravity="center_vertical" >
|
android:gravity="center_vertical"
|
||||||
|
android:layout_marginRight="6dp" >
|
||||||
|
|
||||||
<TextView
|
<Button
|
||||||
android:layout_width="wrap_content"
|
android:id="@+id/import_pg_btn"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="match_parent"
|
||||||
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_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="right"
|
android:text="@string/import_pgc" />
|
||||||
android:orientation="vertical" >
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/clear_pg_btn"
|
android:id="@+id/export_pg_btn"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/clear_pgc" />
|
android:layout_weight="1"
|
||||||
</LinearLayout>
|
android:text="@string/export_pgc" />
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
||||||
</TableLayout>
|
</TableLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -63,12 +63,14 @@
|
||||||
|
|
||||||
<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_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">PGC Game</string>
|
<string name="pgc_select_game">PGC Game</string>
|
||||||
<string name="save_pgc_title">Save Per-Game Config</string>
|
|
||||||
<string name="save_pgc">Save PGC</string>
|
<string name="save_pgc">Save PGC</string>
|
||||||
<string name="pgconfig_saved">Configuration Saved</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="clear_pgc">Clear PGC</string>
|
||||||
<string name="pgconfig_cleared">Configuration Cleared</string>
|
<string name="pgconfig_cleared">Configuration Cleared</string>
|
||||||
|
<string name="import_pgc">Import PGC</string>
|
||||||
|
<string name="pgconfig_imported">Configuration Imported</string>
|
||||||
|
<string name="export_pgc">Export PGC</string>
|
||||||
|
<string name="pgconfig_exported">Configuration Exported</string>
|
||||||
|
|
||||||
<string name="games_listing">Game List</string>
|
<string name="games_listing">Game List</string>
|
||||||
<string name="search_hint">Game (ie. Crazy Taxi)</string>
|
<string name="search_hint">Game (ie. Crazy Taxi)</string>
|
||||||
|
|
Loading…
Reference in New Issue