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 @@ - + + + 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/FileBrowser.java b/shell/android/src/com/reicast/emulator/FileBrowser.java index 421f85ea0..8a210118a 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; @@ -54,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) { @@ -154,10 +155,75 @@ 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, 0); + 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)); + } + } else { + Toast.makeText(parentActivity, "Please configure a games directory", + Toast.LENGTH_LONG).show(); + } + } + + } + class DirSort implements Comparator { // Comparator interface requires defining compare method. @@ -170,47 +236,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 +286,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 +311,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 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, 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); } /* 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 {