From d167caf107ed3181ce31e5e5fccc173f278f6a22 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Tue, 21 Jan 2014 06:07:35 -0500 Subject: [PATCH 1/9] Let's feed this thing a little speed and see if it gets excited --- shell/android/AndroidManifest.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shell/android/AndroidManifest.xml b/shell/android/AndroidManifest.xml index ab3819a5c..a05dd9e19 100644 --- a/shell/android/AndroidManifest.xml +++ b/shell/android/AndroidManifest.xml @@ -9,9 +9,12 @@ - + + + From db324d950e7b364f7b77c9c814002092e8dfb766 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Tue, 21 Jan 2014 06:30:11 -0500 Subject: [PATCH 2/9] First step in converting to async to reduce loading times --- .../src/com/reicast/emulator/FileBrowser.java | 164 +++++++++--------- 1 file changed, 85 insertions(+), 79 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/FileBrowser.java b/shell/android/src/com/reicast/emulator/FileBrowser.java index 421f85ea0..5ce28be9b 100644 --- a/shell/android/src/com/reicast/emulator/FileBrowser.java +++ b/shell/android/src/com/reicast/emulator/FileBrowser.java @@ -16,13 +16,14 @@ import org.apache.commons.lang3.StringUtils; import android.app.Activity; import android.app.AlertDialog; -import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Vibrator; @@ -154,10 +155,72 @@ public class FileBrowser extends Fragment { if (!ImgBrowse) { navigate(sdcard); } else { - generate(ExternalFiles(new File(game_directory))); + LocateGames mLocateGames = new LocateGames(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mLocateGames + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, game_directory); + } else { + mLocateGames.execute(game_directory); + } } } + class LocateGames extends AsyncTask> { + + @Override + protected List doInBackground(String... paths) { + final List tFileList = new ArrayList(); + File storage = new File(paths[0]); + Resources resources = parentActivity.getResources(); + // array of valid image file extensions + String[] mediaTypes = resources.getStringArray(R.array.images); + 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(); + File[] allMatchingFiles = fileUtils.listFilesAsArray(storage, + filter, -1); + for (File mediaFile : allMatchingFiles) { + tFileList.add(mediaFile); + } + return tFileList; + } + + @Override + protected void onPostExecute(List games) { + if (games != null && !games.isEmpty()) { + final LinearLayout list = (LinearLayout) parentActivity + .findViewById(R.id.game_list); + list.removeAllViews(); + + String heading = parentActivity + .getString(R.string.games_listing); + createListHeader(heading, list, true); + for (int i = 0; i < games.size(); i++) { + createListItem(list, games.get(i)); + } + } + } + + } + class DirSort implements Comparator { // Comparator interface requires defining compare method. @@ -170,47 +233,13 @@ public class FileBrowser extends Fragment { } } - private List ExternalFiles(File baseDirectory) { - // allows the input of a base directory for storage selection - final List tFileList = new ArrayList(); - Resources resources = getResources(); - // array of valid image file extensions - String[] mediaTypes = resources.getStringArray(R.array.images); - 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(); - File[] allMatchingFiles = fileUtils.listFilesAsArray(baseDirectory, - filter, -1); - for (File mediaFile : allMatchingFiles) { - tFileList.add(mediaFile); - } - - return tFileList; - } - private void createListHeader(String header_text, View view, boolean hasBios) { if (hasBios) { final View childview = parentActivity.getLayoutInflater().inflate( R.layout.bios_list_item, null, false); ((TextView) childview.findViewById(R.id.item_name)) - .setText(getString(R.string.boot_bios)); + .setText(parentActivity.getString(R.string.boot_bios)); childview.setTag(null); @@ -254,44 +283,24 @@ public class FileBrowser extends Fragment { ((ViewGroup) view).addView(headerView); } - - void generate(List games) { - final LinearLayout list = (LinearLayout) parentActivity - .findViewById(R.id.game_list); - list.removeAllViews(); - - String heading = parentActivity.getString(R.string.games_listing); - createListHeader(heading, list, true); - for (int i = 0; i < games.size(); i++) { - createListItem(list, games.get(i)); - } - } private void createListItem(LinearLayout list, final File game) { final String name = game.getName(); - final View childview = parentActivity - .getLayoutInflater() - .inflate(R.layout.app_list_item, null, - false); + final View childview = parentActivity.getLayoutInflater().inflate( + R.layout.app_list_item, null, false); - ((TextView) childview.findViewById(R.id.item_name)) - .setText(name); + ((TextView) childview.findViewById(R.id.item_name)).setText(name); ((ImageView) childview.findViewById(R.id.item_icon)) - .setImageResource(game == null ? R.drawable.config - : game.isDirectory() ? R.drawable.open_folder - : name.toLowerCase( - Locale.getDefault()) - .endsWith(".gdi") ? R.drawable.gdi - : name.toLowerCase( - Locale.getDefault()) - .endsWith( - ".cdi") ? R.drawable.cdi - : name.toLowerCase( - Locale.getDefault()) - .endsWith( - ".chd") ? R.drawable.chd - : R.drawable.disk_unknown); + .setImageResource(game == null ? R.drawable.config : game + .isDirectory() ? R.drawable.open_folder + : name.toLowerCase(Locale.getDefault()) + .endsWith(".gdi") ? R.drawable.gdi : name + .toLowerCase(Locale.getDefault()).endsWith( + ".cdi") ? R.drawable.cdi : name + .toLowerCase(Locale.getDefault()).endsWith( + ".chd") ? R.drawable.chd + : R.drawable.disk_unknown); childview.setTag(name); @@ -299,23 +308,20 @@ public class FileBrowser extends Fragment { // vw.findViewById(R.id.childview).setBackgroundColor(0xFFFFFFFF); - childview.findViewById(R.id.childview) - .setOnClickListener(new OnClickListener() { + childview.findViewById(R.id.childview).setOnClickListener( + new OnClickListener() { public void onClick(View view) { vib.vibrate(50); - mCallback - .onGameSelected(game != null ? Uri - .fromFile(game) - : Uri.EMPTY); + mCallback.onGameSelected(game != null ? Uri + .fromFile(game) : Uri.EMPTY); vib.vibrate(250); } }); - childview.findViewById(R.id.childview) - .setOnTouchListener(new OnTouchListener() { + childview.findViewById(R.id.childview).setOnTouchListener( + new OnTouchListener() { @SuppressWarnings("deprecation") - public boolean onTouch(View view, - MotionEvent arg1) { + public boolean onTouch(View view, MotionEvent arg1) { if (arg1.getActionMasked() == MotionEvent.ACTION_DOWN) { view.setBackgroundColor(0xFF4F3FFF); } else if (arg1.getActionMasked() == MotionEvent.ACTION_CANCEL From 58ac73df14660b45320146d31e131d6898cbaabb Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Tue, 21 Jan 2014 06:57:40 -0500 Subject: [PATCH 3/9] Default games to the system directory, Prompt when empty --- shell/android/src/com/reicast/emulator/FileBrowser.java | 5 ++++- shell/android/src/com/reicast/emulator/OptionsFragment.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/FileBrowser.java b/shell/android/src/com/reicast/emulator/FileBrowser.java index 5ce28be9b..867ea4cfa 100644 --- a/shell/android/src/com/reicast/emulator/FileBrowser.java +++ b/shell/android/src/com/reicast/emulator/FileBrowser.java @@ -55,7 +55,7 @@ public class FileBrowser extends Fragment { private SharedPreferences mPrefs; private File sdcard = Environment.getExternalStorageDirectory(); private String home_directory = sdcard + "/dc"; - private String game_directory = sdcard + "/"; + private String game_directory = sdcard + "/dc"; @Override public void onCreate(Bundle savedInstanceState) { @@ -216,6 +216,9 @@ public class FileBrowser extends Fragment { for (int i = 0; i < games.size(); i++) { createListItem(list, games.get(i)); } + } else { + Toast.makeText(getActivity(), "Please configure a games directory", + Toast.LENGTH_LONG).show(); } } diff --git a/shell/android/src/com/reicast/emulator/OptionsFragment.java b/shell/android/src/com/reicast/emulator/OptionsFragment.java index f5accc67f..2e978ead8 100644 --- a/shell/android/src/com/reicast/emulator/OptionsFragment.java +++ b/shell/android/src/com/reicast/emulator/OptionsFragment.java @@ -27,7 +27,7 @@ public class OptionsFragment extends Fragment { private SharedPreferences mPrefs; private File sdcard = Environment.getExternalStorageDirectory(); private String home_directory = sdcard + "/dc"; - private String game_directory = sdcard + "/"; + private String game_directory = sdcard + "/dc"; // Container Activity must implement this interface public interface OnClickListener { From e9cb37b1330a24767febce6a891f571bfa5754c7 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Tue, 21 Jan 2014 07:02:47 -0500 Subject: [PATCH 4/9] Make the GLES 2 a requirement to prevent incompatibility As per @skmp it was a requirement all along, just not explicitly enforced until now. --- shell/android/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/android/AndroidManifest.xml b/shell/android/AndroidManifest.xml index a05dd9e19..de25af696 100644 --- a/shell/android/AndroidManifest.xml +++ b/shell/android/AndroidManifest.xml @@ -10,7 +10,7 @@ - + Date: Tue, 21 Jan 2014 07:57:14 -0500 Subject: [PATCH 5/9] Disable recursive searching of the selected games directory --- shell/android/src/com/reicast/emulator/FileBrowser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/android/src/com/reicast/emulator/FileBrowser.java b/shell/android/src/com/reicast/emulator/FileBrowser.java index 867ea4cfa..9c9aa1074 100644 --- a/shell/android/src/com/reicast/emulator/FileBrowser.java +++ b/shell/android/src/com/reicast/emulator/FileBrowser.java @@ -196,7 +196,7 @@ public class FileBrowser extends Fragment { FileUtils fileUtils = new FileUtils(); File[] allMatchingFiles = fileUtils.listFilesAsArray(storage, - filter, -1); + filter, 0); for (File mediaFile : allMatchingFiles) { tFileList.add(mediaFile); } From f934e3a2accd95a0539ee24fec8d54562f64f3fe Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Tue, 21 Jan 2014 08:51:24 -0500 Subject: [PATCH 6/9] Nvidia controller already mirrors the 360, so set the defaults --- shell/android/src/com/reicast/emulator/GL2JNIActivity.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/android/src/com/reicast/emulator/GL2JNIActivity.java b/shell/android/src/com/reicast/emulator/GL2JNIActivity.java index cf777d70e..07c6862a8 100644 --- a/shell/android/src/com/reicast/emulator/GL2JNIActivity.java +++ b/shell/android/src/com/reicast/emulator/GL2JNIActivity.java @@ -267,6 +267,9 @@ public class GL2JNIActivity extends Activity { OuyaController.BUTTON_MENU, key_CONT_START, OuyaController.BUTTON_R1, key_CONT_START }; nVidia[playerNum] = true; + + globalLS_X[playerNum] = previousLS_X[playerNum] = 0.0f; + globalLS_Y[playerNum] = previousLS_Y[playerNum] = 0.0f; } else if (!moga.isActive) { // Ouya controller map[playerNum] = new int[] { OuyaController.BUTTON_O, key_CONT_A, From 191a720a75c5ea248d5430ef64530f946ceb30d0 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Tue, 21 Jan 2014 09:52:48 -0500 Subject: [PATCH 7/9] Allow reverting to the previously saved screen joypad layout --- .../src/com/reicast/emulator/EditVJoyActivity.java | 13 ++++++++++++- .../src/com/reicast/emulator/GL2JNIView.java | 12 ++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/shell/android/src/com/reicast/emulator/EditVJoyActivity.java b/shell/android/src/com/reicast/emulator/EditVJoyActivity.java index 28423e029..ab3ffc782 100644 --- a/shell/android/src/com/reicast/emulator/EditVJoyActivity.java +++ b/shell/android/src/com/reicast/emulator/EditVJoyActivity.java @@ -27,6 +27,8 @@ public class EditVJoyActivity extends Activity { GL2JNIView mView; PopupWindow popUp; LayoutParams params; + + private static float[][] vjoy_d_cached; View addbut(int x, OnClickListener ocl) { ImageButton but = new ImageButton(this); @@ -63,6 +65,13 @@ public class EditVJoyActivity extends Activity { } }), params); + hlay.addView(addbut(R.drawable.close, new OnClickListener() { + public void onClick(View v) { + mView.restoreCustomVjoyValues(vjoy_d_cached); + popUp.dismiss(); + } + }), params); + popUp.setContentView(hlay); } @@ -78,8 +87,10 @@ public class EditVJoyActivity extends Activity { // Create the actual GLES view mView = new GL2JNIView(getApplication(), null, false, 24, 0, true); setContentView(mView); + + vjoy_d_cached = GL2JNIView.readCustomVjoyValues(getApplicationContext()); - JNIdc.show_osd(); + JNIdc.show_osd(); Toast.makeText(getApplicationContext(), "Press the back button for a menu", Toast.LENGTH_SHORT).show(); diff --git a/shell/android/src/com/reicast/emulator/GL2JNIView.java b/shell/android/src/com/reicast/emulator/GL2JNIView.java index 5263542d7..1a2ccb107 100644 --- a/shell/android/src/com/reicast/emulator/GL2JNIView.java +++ b/shell/android/src/com/reicast/emulator/GL2JNIView.java @@ -146,7 +146,7 @@ class GL2JNIView extends GLSurfaceView prefs.edit().putFloat("touch_scale_analog", vjoy_d_custom[5][2]).commit(); } - private static float[][] readCustomVjoyValues(Context context) { + public static float[][] readCustomVjoyValues(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); return new float[][] @@ -193,6 +193,14 @@ class GL2JNIView extends GLSurfaceView resetEditMode(); requestLayout(); } + + public void restoreCustomVjoyValues(float[][] vjoy_d_cached) { + vjoy_d_custom = vjoy_d_cached; + writeCustomVjoyValues(vjoy_d_cached, context); + + resetEditMode(); + requestLayout(); + } public GL2JNIView(Context context,String newFileName,boolean translucent,int depth,int stencil,boolean editVjoyMode) { @@ -334,7 +342,7 @@ class GL2JNIView extends GLSurfaceView JNIdc.vjoy(i,vjoy[i][0],vjoy[i][1],vjoy[i][2],vjoy[i][3]); reset_analog(); - writeCustomVjoyValues(vjoy_d_custom, context); + writeCustomVjoyValues(vjoy_d_custom, context); } /* From 950e93f40964bfabcf48c1f9d3e9abc65cdb2aa2 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Tue, 21 Jan 2014 11:00:00 -0500 Subject: [PATCH 8/9] Add the proper context for toast message from background --- shell/android/src/com/reicast/emulator/FileBrowser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/android/src/com/reicast/emulator/FileBrowser.java b/shell/android/src/com/reicast/emulator/FileBrowser.java index 9c9aa1074..8a210118a 100644 --- a/shell/android/src/com/reicast/emulator/FileBrowser.java +++ b/shell/android/src/com/reicast/emulator/FileBrowser.java @@ -217,7 +217,7 @@ public class FileBrowser extends Fragment { createListItem(list, games.get(i)); } } else { - Toast.makeText(getActivity(), "Please configure a games directory", + Toast.makeText(parentActivity, "Please configure a games directory", Toast.LENGTH_LONG).show(); } } From 302b3e5b2982a0484af1267280bc9d56fac95e84 Mon Sep 17 00:00:00 2001 From: TwistedUmbrella Date: Tue, 21 Jan 2014 12:06:09 -0500 Subject: [PATCH 9/9] Revert "Make the GLES 2 a requirement to prevent incompatibility" This reverts commit e9cb37b1330a24767febce6a891f571bfa5754c7. --- shell/android/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/android/AndroidManifest.xml b/shell/android/AndroidManifest.xml index de25af696..a05dd9e19 100644 --- a/shell/android/AndroidManifest.xml +++ b/shell/android/AndroidManifest.xml @@ -10,7 +10,7 @@ - +