From 30cfc0b15a2b0372fb6c52dc6ce67f8b6f42bcb7 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Sun, 25 Jan 2015 15:47:18 -0500 Subject: [PATCH] Add a basic theme selection option to configuration --- .../android/res/layout/configure_fragment.xml | 20 ++++++ shell/android/res/values/donottranslate.xml | 6 ++ shell/android/res/values/strings.xml | 2 + .../emulator/config/OptionsFragment.java | 71 +++++++++++++++++++ 4 files changed, 99 insertions(+) diff --git a/shell/android/res/layout/configure_fragment.xml b/shell/android/res/layout/configure_fragment.xml index 3b7b8030b..72a26300b 100644 --- a/shell/android/res/layout/configure_fragment.xml +++ b/shell/android/res/layout/configure_fragment.xml @@ -84,6 +84,26 @@ android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:stretchColumns="*" > + + + + + + + VGA + + png + jpg + jpeg + + cdi chd diff --git a/shell/android/res/values/strings.xml b/shell/android/res/values/strings.xml index 6f244803a..c368ed330 100644 --- a/shell/android/res/values/strings.xml +++ b/shell/android/res/values/strings.xml @@ -5,6 +5,8 @@ System Path (location of the data folder with dc_boot.bin/dc_flash.bin inside) Default System Path Storage Path (location of *.gdi, *.chd or *.cdi images) + Onscreen Button Theme + Default Game Storage Please configure a home directory. Please move BIOS to %1$s/data/ diff --git a/shell/android/src/com/reicast/emulator/config/OptionsFragment.java b/shell/android/src/com/reicast/emulator/config/OptionsFragment.java index a258911a9..5fae9ee03 100644 --- a/shell/android/src/com/reicast/emulator/config/OptionsFragment.java +++ b/shell/android/src/com/reicast/emulator/config/OptionsFragment.java @@ -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> { + + @Override + protected List 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 files = fileUtils.listFiles(storage, filter, 1); + return (List) files; + } + + @Override + protected void onPostExecute(List items) { + if (items != null && !items.isEmpty()) { + ArrayAdapter themeAdapter = new ArrayAdapter( + 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()