Add a basic backend for supporting button themes
The theme path will be store as the button_theme pref and verified before loading. This will replace any existing buttons in the data folder of the emulator home_directory at runtime and load as the graphics for the button configuration. This requires button themes be standardized.
This commit is contained in:
parent
9e2b28ae46
commit
584fdae6f8
|
@ -1,6 +1,7 @@
|
|||
package com.reicast.emulator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
|
@ -154,8 +155,25 @@ public class FileBrowser extends Fragment {
|
|||
// setContentView(R.layout.activity_main);
|
||||
parentActivity = getActivity();
|
||||
try {
|
||||
File buttons = null;
|
||||
String theme = mPrefs.getString(Config.pref_theme, null);
|
||||
if (theme != null) {
|
||||
buttons = new File(theme);
|
||||
}
|
||||
File file = new File(home_directory, "data/buttons.png");
|
||||
if (!file.exists()) {
|
||||
if (buttons != null && buttons.exists()) {
|
||||
InputStream in = new FileInputStream(buttons);
|
||||
OutputStream out = new FileOutputStream(file);
|
||||
|
||||
// Transfer bytes from in to out
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
} else if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
OutputStream fo = new FileOutputStream(file);
|
||||
InputStream png = parentActivity.getAssets()
|
||||
|
|
|
@ -15,6 +15,7 @@ public class Config {
|
|||
|
||||
public static final String pref_home = "home_directory";
|
||||
public static final String pref_games = "game_directory";
|
||||
public static final String pref_theme = "button_theme";
|
||||
|
||||
public static final String pref_gamedetails = "game_details";
|
||||
public static final String pref_nativeact = "enable_native";
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.reicast.emulator.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
|
@ -403,7 +405,17 @@ public class InputModFragment extends Fragment {
|
|||
System.gc();
|
||||
}
|
||||
try {
|
||||
InputStream bitmap = getResources().getAssets().open("buttons.png");
|
||||
File buttons = null;
|
||||
InputStream bitmap = null;
|
||||
String theme = mPrefs.getString(Config.pref_theme, null);
|
||||
if (theme != null) {
|
||||
buttons = new File(theme);
|
||||
}
|
||||
if (buttons != null && buttons.exists()) {
|
||||
bitmap = new FileInputStream(buttons);
|
||||
} else {
|
||||
bitmap = getResources().getAssets().open("buttons.png");
|
||||
}
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inSampleSize = sS;
|
||||
image = BitmapFactory.decodeStream(bitmap, null, options);
|
||||
|
|
Loading…
Reference in New Issue