Add a basic theme selection option to configuration
This commit is contained in:
parent
e82d6a8c0e
commit
30cfc0b15a
|
@ -84,6 +84,26 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="6dp"
|
||||
android:stretchColumns="*" >
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="5dp"
|
||||
android:gravity="center_vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/button_theme_label"
|
||||
style="@style/BaseText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="0.5"
|
||||
android:text="@string/button_theme" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/pick_button_theme"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.5"
|
||||
android:prompt="@string/button_theme" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_marginTop="10dp"
|
||||
|
|
|
@ -22,6 +22,12 @@
|
|||
<item>VGA</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes">
|
||||
<item>png</item>
|
||||
<item>jpg</item>
|
||||
<item>jpeg</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="images">
|
||||
<item>cdi</item>
|
||||
<item>chd</item>
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
<string name="system_path">System Path (location of the data folder with dc_boot.bin/dc_flash.bin inside)</string>
|
||||
<string name="browser_path">Default System Path</string>
|
||||
<string name="games_path">Storage Path (location of *.gdi, *.chd or *.cdi images)</string>
|
||||
<string name="button_theme">Onscreen Button Theme</string>
|
||||
|
||||
<string name="game_path">Default Game Storage</string>
|
||||
<string name="config_home">Please configure a home directory.</string>
|
||||
<string name="config_data">Please move BIOS to %1$s/data/</string>
|
||||
|
|
|
@ -2,15 +2,21 @@ package com.reicast.emulator.config;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
|
@ -35,6 +41,7 @@ import android.widget.Spinner;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.util.FileUtils;
|
||||
import com.reicast.emulator.FileBrowser;
|
||||
import com.reicast.emulator.R;
|
||||
import com.reicast.emulator.emu.GL2JNIView;
|
||||
|
@ -48,6 +55,7 @@ public class OptionsFragment extends Fragment {
|
|||
|
||||
private Button mainBrowse;
|
||||
private Button gameBrowse;
|
||||
private Spinner mSpnrThemes;
|
||||
private OnClickListener mCallback;
|
||||
|
||||
private SharedPreferences mPrefs;
|
||||
|
@ -141,6 +149,9 @@ public class OptionsFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
new LocateThemes().execute(home_directory + "/themes");
|
||||
mSpnrThemes = (Spinner) getView().findViewById(R.id.pick_button_theme);
|
||||
|
||||
OnCheckedChangeListener details_options = new OnCheckedChangeListener() {
|
||||
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
|
@ -518,6 +529,66 @@ public class OptionsFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
private final class LocateThemes extends AsyncTask<String, Integer, List<File>> {
|
||||
|
||||
@Override
|
||||
protected List<File> doInBackground(String... paths) {
|
||||
File storage = new File(paths[0]);
|
||||
|
||||
// array of valid image file extensions
|
||||
String[] mediaTypes = getResources().getStringArray(R.array.themes);
|
||||
FilenameFilter[] filter = new FilenameFilter[mediaTypes.length];
|
||||
|
||||
int i = 0;
|
||||
for (final String type : mediaTypes) {
|
||||
filter[i] = new FilenameFilter() {
|
||||
|
||||
public boolean accept(File dir, String name) {
|
||||
if (dir.getName().startsWith(".")
|
||||
|| name.startsWith(".")) {
|
||||
return false;
|
||||
} else {
|
||||
return StringUtils.endsWithIgnoreCase(name, "."
|
||||
+ type);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
i++;
|
||||
}
|
||||
|
||||
FileUtils fileUtils = new FileUtils();
|
||||
Collection<File> files = fileUtils.listFiles(storage, filter, 1);
|
||||
return (List<File>) files;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<File> items) {
|
||||
if (items != null && !items.isEmpty()) {
|
||||
ArrayAdapter<String> themeAdapter = new ArrayAdapter<String>(
|
||||
getActivity(), android.R.layout.simple_spinner_item,
|
||||
items.toArray(new String[items.size()]));
|
||||
themeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mSpnrThemes.setAdapter(themeAdapter);
|
||||
mSpnrThemes.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
|
||||
String theme = String.valueOf(parentView.getItemAtPosition(position));
|
||||
mPrefs.edit().putString(Config.pref_theme, theme).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parentView) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
mSpnrThemes.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void hideSoftKeyBoard() {
|
||||
InputMethodManager iMm = (InputMethodManager) getActivity()
|
||||
|
|
Loading…
Reference in New Issue