From d07d97e51746e3229f25611888c4931581ad861f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 2 Nov 2013 22:40:41 -0400 Subject: [PATCH 1/2] [Android] Sort the cores in the CoreSelection activity alphabetically. Also document the IconAdapter class, along with its IconAdapterItem interface. --- .../com/retroarch/browser/CoreSelection.java | 19 +++-- .../com/retroarch/browser/IconAdapter.java | 75 +++++++++++++++++++ 2 files changed, 88 insertions(+), 6 deletions(-) diff --git a/android/phoenix/src/com/retroarch/browser/CoreSelection.java b/android/phoenix/src/com/retroarch/browser/CoreSelection.java index 331ea711fc..a28a037eac 100644 --- a/android/phoenix/src/com/retroarch/browser/CoreSelection.java +++ b/android/phoenix/src/com/retroarch/browser/CoreSelection.java @@ -4,6 +4,9 @@ import com.retroarch.R; import com.retroarch.browser.preferences.util.UserPreferences; import java.io.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import android.app.*; import android.media.AudioManager; @@ -26,14 +29,11 @@ public final class CoreSelection extends ListActivity { // Setup the layout setContentView(R.layout.line_list); - // Setup the list - adapter = new IconAdapter(this, R.layout.line_list_item); - setListAdapter(adapter); - // Set the activity title. setTitle(R.string.select_libretro_core); // Populate the list + final List cores = new ArrayList(); final File[] libs = new File(getApplicationInfo().dataDir, "/cores").listFiles(); for (final File lib : libs) { String libName = lib.getName(); @@ -59,10 +59,17 @@ public final class CoreSelection extends ListActivity { if (hasNeonVersion) continue; } - - adapter.add(new ModuleWrapper(this, lib)); + + cores.add(new ModuleWrapper(this, lib)); } + // Sort the list of cores alphabetically + Collections.sort(cores); + + // Initialize the IconAdapter with the list of cores. + adapter = new IconAdapter(this, R.layout.line_list_item, cores); + setListAdapter(adapter); + this.setVolumeControlStream(AudioManager.STREAM_MUSIC); } diff --git a/android/phoenix/src/com/retroarch/browser/IconAdapter.java b/android/phoenix/src/com/retroarch/browser/IconAdapter.java index d95ab5582e..c3066fb03f 100644 --- a/android/phoenix/src/com/retroarch/browser/IconAdapter.java +++ b/android/phoenix/src/com/retroarch/browser/IconAdapter.java @@ -1,5 +1,7 @@ package com.retroarch.browser; +import java.util.List; + import com.retroarch.R; import android.content.*; @@ -7,24 +9,97 @@ import android.graphics.drawable.*; import android.view.*; import android.widget.*; +/** + * Represents an item that is capable + * of being within an {@link IconAdapter}. + */ interface IconAdapterItem { + + /** + * Gets whether or not this item is + * enabled within the adapter. + *

+ * This can be used for deciding whether or + * not to enable an item in a {@link ListView} + * if an IconAdapter is backing it. + * + * @return true if this item is enabled; false otherwise. + */ public boolean isEnabled(); + + /** + * Gets the title text of this IconAdapterItem. + * + * @return the title text of this IconAdapterItem. + */ public String getText(); + + /** + * Gets the subtitle text of this IconAdapterItem. + * + * @return the subtitle text of this IconAdapterItem. + */ public String getSubText(); + + /** + * Gets the resource ID of the icon to display + * alongside the text in this IconAdapterItem. + *

+ * Returning zero means no icon is to be displayed. + * + * @return the resource ID of this IconAdapterItem's icon. + */ public int getIconResourceId(); + + /** + * Gets the actual {@link Drawable} object that represents + * the icon that is displayed with this IconAdapterItem. + *

+ * Returning null means no icon is to be displayed. + * + * @return the actual {@link Drawable} of this IconAdapterItem's icon. + */ public Drawable getIconDrawable(); } + +/** + * An {@link ArrayAdapter} derivative that can back a {@link View} + * that accepts ArrayAdapters. Items within this ArrayAdapter derivative + * must implement the {@link IconAdapterItem} interface. + * + * @param The type of the item that will be within this IconAdapter. + * This type must implement the {@link IconAdapterItem} interface. + */ public final class IconAdapter extends ArrayAdapter { private final int resourceId; private final Context context; + /** + * Constructor + * + * @param context The current {@link Context}. + * @param resourceId The resource ID for a layout file containing a layout to use when instantiating views. + */ public IconAdapter(Context context, int resourceId) { super(context, resourceId); this.context = context; this.resourceId = resourceId; } + /** + * Constructor + * + * @param context The current {@link Context}. + * @param resourceId The resource ID for a layout file containing a layout to use when instantiating views. + * @param items The list of items to store within this IconAdapter. + */ + public IconAdapter(Context context, int resourceId, List items) { + super(context, resourceId, items); + this.context = context; + this.resourceId = resourceId; + } + @Override public View getView(int position, View convertView, ViewGroup parent) { // Build the view From 071b2c8e6aabd820c6c6e25d586d392a42c65b84 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 2 Nov 2013 23:15:56 -0400 Subject: [PATCH 2/2] [Android] Document a large amount of the Android front-end classes (also some methods). Also adjusted the tab indentation of the GPL waiver method, was one tab too far. --- .../com/retroarch/browser/CoreSelection.java | 6 ++- .../browser/DisplayRefreshRateTest.java | 4 ++ .../com/retroarch/browser/HelpActivity.java | 3 ++ .../retroarch/browser/HistorySelection.java | 4 ++ .../com/retroarch/browser/HistoryWrapper.java | 36 ++++++++++++-- .../retroarch/browser/MainMenuActivity.java | 48 ++++++++++--------- .../retroarch/browser/NativeInterface.java | 4 +- .../com/retroarch/browser/RetroTVMode.java | 3 ++ .../diractivities/DirectoryActivity.java | 39 +++++++++++++-- .../diractivities/OverlayActivity.java | 6 +++ .../browser/diractivities/ROMActivity.java | 5 ++ .../browser/diractivities/ROMDirActivity.java | 5 ++ .../browser/diractivities/SRMDirActivity.java | 5 ++ .../browser/diractivities/ShaderActivity.java | 5 ++ .../diractivities/StateDirActivity.java | 5 ++ .../diractivities/SystemDirActivity.java | 7 +++ 16 files changed, 152 insertions(+), 33 deletions(-) diff --git a/android/phoenix/src/com/retroarch/browser/CoreSelection.java b/android/phoenix/src/com/retroarch/browser/CoreSelection.java index a28a037eac..5514a2c262 100644 --- a/android/phoenix/src/com/retroarch/browser/CoreSelection.java +++ b/android/phoenix/src/com/retroarch/browser/CoreSelection.java @@ -14,8 +14,10 @@ import android.os.*; import android.widget.*; import android.view.*; -// JELLY_BEAN_MR1 = 17 - +/** + * {@link ListActivity} subclass that displays the list + * of selectable cores for emulating games. + */ public final class CoreSelection extends ListActivity { private IconAdapter adapter; diff --git a/android/phoenix/src/com/retroarch/browser/DisplayRefreshRateTest.java b/android/phoenix/src/com/retroarch/browser/DisplayRefreshRateTest.java index 3b08f25134..204d10b9d6 100644 --- a/android/phoenix/src/com/retroarch/browser/DisplayRefreshRateTest.java +++ b/android/phoenix/src/com/retroarch/browser/DisplayRefreshRateTest.java @@ -15,6 +15,10 @@ import android.util.Log; import android.view.WindowManager; import android.widget.Toast; +/** + * {@link Activity} subclass that provides the functionality + * for the refresh rate testing for device displays. + */ public final class DisplayRefreshRateTest extends Activity { private class Renderer implements GLSurfaceView.Renderer { diff --git a/android/phoenix/src/com/retroarch/browser/HelpActivity.java b/android/phoenix/src/com/retroarch/browser/HelpActivity.java index 32c50cfe08..6791bd41f4 100644 --- a/android/phoenix/src/com/retroarch/browser/HelpActivity.java +++ b/android/phoenix/src/com/retroarch/browser/HelpActivity.java @@ -6,6 +6,9 @@ import android.os.Bundle; import android.preference.PreferenceActivity; import android.preference.PreferenceManager; +/** + * Basic {@link PreferenceActivity} responsible for displaying the help articles. + */ public final class HelpActivity extends PreferenceActivity { @SuppressWarnings("deprecation") @Override diff --git a/android/phoenix/src/com/retroarch/browser/HistorySelection.java b/android/phoenix/src/com/retroarch/browser/HistorySelection.java index 8fe525614e..774d007e1b 100644 --- a/android/phoenix/src/com/retroarch/browser/HistorySelection.java +++ b/android/phoenix/src/com/retroarch/browser/HistorySelection.java @@ -17,6 +17,10 @@ import android.view.View; import android.widget.ListView; import android.widget.Toast; +/** + * Represents the {@link ListActivity} responsible + * for displaying the list of previously played games. + */ public final class HistorySelection extends ListActivity { private IconAdapter adapter; diff --git a/android/phoenix/src/com/retroarch/browser/HistoryWrapper.java b/android/phoenix/src/com/retroarch/browser/HistoryWrapper.java index f5759d8549..9fc46a7a19 100644 --- a/android/phoenix/src/com/retroarch/browser/HistoryWrapper.java +++ b/android/phoenix/src/com/retroarch/browser/HistoryWrapper.java @@ -4,13 +4,24 @@ import java.io.File; import android.graphics.drawable.Drawable; +/** + * Wraps a previously played game along with its core + * for placement within the previously played history. + */ public final class HistoryWrapper implements IconAdapterItem { - + private String gamePath; private String gamePathShort; private String corePath; private String coreName; - + + /** + * Constructor + * + * @param gamePath Path to the previously played game. + * @param corePath Path to the core the previously played game uses. + * @param coreName The actual name of the core. + */ public HistoryWrapper(String gamePath, String corePath, String coreName) { this.gamePath = gamePath; this.corePath = corePath; @@ -23,15 +34,30 @@ public final class HistoryWrapper implements IconAdapterItem { } catch (IndexOutOfBoundsException e) { } } - + + /** + * Gets the path to the previously played game. + * + * @return the path to the previously played game. + */ public String getGamePath() { return gamePath; } - + + /** + * Gets the path to the core that the previously played game uses. + * + * @return the path to the core that the previously played game uses. + */ public String getCorePath() { return corePath; } - + + /** + * Gets the name of the core used with the previously played game. + * + * @return the name of the core used with the previously played game. + */ public String getCoreName() { return coreName; } diff --git a/android/phoenix/src/com/retroarch/browser/MainMenuActivity.java b/android/phoenix/src/com/retroarch/browser/MainMenuActivity.java index 94db85a519..24bb107ce3 100644 --- a/android/phoenix/src/com/retroarch/browser/MainMenuActivity.java +++ b/android/phoenix/src/com/retroarch/browser/MainMenuActivity.java @@ -21,6 +21,10 @@ import android.provider.Settings; import android.util.Log; import android.widget.Toast; +/** + * {@link PreferenceActivity} subclass that provides all of the + * functionality of the main menu screen. + */ public final class MainMenuActivity extends PreferenceActivity { private static MainMenuActivity instance = null; private static final int ACTIVITY_LOAD_ROM = 0; @@ -30,30 +34,30 @@ public final class MainMenuActivity extends PreferenceActivity { private static String libretro_name; private void showGPLWaiver() { - AlertDialog.Builder alert = new AlertDialog.Builder(this) - .setTitle(R.string.gpl_waiver) - .setMessage(R.string.gpl_waiver_desc) - .setPositiveButton("Keep", null) - .setNegativeButton("Remove non-GPL cores", - new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - final File[] libs = new File(getApplicationInfo().dataDir, "/cores").listFiles(); - for (final File lib : libs) { - ModuleWrapper module = new ModuleWrapper(getApplicationContext(), lib); - - boolean gplv3 = module.getCoreLicense().equals("GPLv3"); - boolean gplv2 = module.getCoreLicense().equals("GPLv2"); - - if (!gplv3 && !gplv2) { - String libName = lib.getName(); - Log.i("GPL WAIVER", "Deleting non-GPL core" + libName + "..."); - lib.delete(); - } + AlertDialog.Builder alert = new AlertDialog.Builder(this) + .setTitle(R.string.gpl_waiver) + .setMessage(R.string.gpl_waiver_desc) + .setPositiveButton("Keep", null) + .setNegativeButton("Remove non-GPL cores", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + final File[] libs = new File(getApplicationInfo().dataDir, "/cores").listFiles(); + for (final File lib : libs) { + ModuleWrapper module = new ModuleWrapper(getApplicationContext(), lib); + + boolean gplv3 = module.getCoreLicense().equals("GPLv3"); + boolean gplv2 = module.getCoreLicense().equals("GPLv2"); + + if (!gplv3 && !gplv2) { + String libName = lib.getName(); + Log.i("GPL WAIVER", "Deleting non-GPL core" + libName + "..."); + lib.delete(); } } - }); - alert.show(); + } + }); + alert.show(); } @Override diff --git a/android/phoenix/src/com/retroarch/browser/NativeInterface.java b/android/phoenix/src/com/retroarch/browser/NativeInterface.java index 698698dcd4..31f16f5d6a 100644 --- a/android/phoenix/src/com/retroarch/browser/NativeInterface.java +++ b/android/phoenix/src/com/retroarch/browser/NativeInterface.java @@ -1,6 +1,8 @@ package com.retroarch.browser; -// Helper class which calls into JNI for various tasks. +/** + * Helper class which calls into JNI for various tasks. + */ public final class NativeInterface { static { diff --git a/android/phoenix/src/com/retroarch/browser/RetroTVMode.java b/android/phoenix/src/com/retroarch/browser/RetroTVMode.java index 715d080916..889b18e003 100644 --- a/android/phoenix/src/com/retroarch/browser/RetroTVMode.java +++ b/android/phoenix/src/com/retroarch/browser/RetroTVMode.java @@ -8,6 +8,9 @@ import android.os.Bundle; import android.provider.Settings; import android.util.Log; +/** + * The {@link Activity} derivative responsible for displaying the TV Mode feature. + */ public final class RetroTVMode extends Activity { private static final String TAG = "RetroTVMode"; private static final int ACTIVITY_RETROARCH = 1; diff --git a/android/phoenix/src/com/retroarch/browser/diractivities/DirectoryActivity.java b/android/phoenix/src/com/retroarch/browser/diractivities/DirectoryActivity.java index c92389e585..5dc1e8b65a 100644 --- a/android/phoenix/src/com/retroarch/browser/diractivities/DirectoryActivity.java +++ b/android/phoenix/src/com/retroarch/browser/diractivities/DirectoryActivity.java @@ -15,7 +15,17 @@ import android.os.*; import android.widget.*; import android.view.*; - +/** + * {@link ListActivity} subclass that provides a file-browser + * like UI for browsing for specific files. + *

+ * This file browser also allows for custom filtering + * depending on the type of class that inherits it. + *

+ * This file browser also uses an implementation of a + * backstack for remembering previously browsed folders + * within this DirectoryActivity. + */ public class DirectoryActivity extends ListActivity { private IconAdapter adapter; private File listedDirectory; @@ -180,14 +190,37 @@ public class DirectoryActivity extends ListActivity { return true; } - + + /** + * Allows specifying an allowed file extension. + *

+ * Any files that contain this file extension will be shown + * within the DirectoryActivity file browser. Those that don't + * contain this extension will not be shows. + *

+ * It is possible to specify more than one allowed extension by + * simply calling this method with a different file extension specified. + * + * @param ext The file extension to allow being shown in this DirectoryActivity. + */ protected void addAllowedExt(String ext) { if (allowedExt == null) allowedExt = new ArrayList(); allowedExt.add(ext); } - + + /** + * Allows specifying a disallowed file extension. + *

+ * Any files that contain this file extension will not be shown + * within the DirectoryActivity file browser. + *

+ * It is possible to specify more than one disallowed extension by + * simply calling this method with a different file extension specified. + * + * @param ext The file extension to hide from being shown in this DirectoryActivity. + */ protected void addDisallowedExt(String ext) { if (disallowedExt == null) disallowedExt = new ArrayList(); diff --git a/android/phoenix/src/com/retroarch/browser/diractivities/OverlayActivity.java b/android/phoenix/src/com/retroarch/browser/diractivities/OverlayActivity.java index 8a4363dea0..fcee83a51b 100644 --- a/android/phoenix/src/com/retroarch/browser/diractivities/OverlayActivity.java +++ b/android/phoenix/src/com/retroarch/browser/diractivities/OverlayActivity.java @@ -4,6 +4,12 @@ import java.io.File; import android.os.Bundle; +/** + * {@link DirectoryActivity} subclass used for the sole + * purpose of navigating the Android filesystem for input overlays. + * @author Lioncash-yay + * + */ public final class OverlayActivity extends DirectoryActivity { @Override public void onCreate(Bundle savedInstanceState) { diff --git a/android/phoenix/src/com/retroarch/browser/diractivities/ROMActivity.java b/android/phoenix/src/com/retroarch/browser/diractivities/ROMActivity.java index 75ec79d1f9..82c0b474ce 100644 --- a/android/phoenix/src/com/retroarch/browser/diractivities/ROMActivity.java +++ b/android/phoenix/src/com/retroarch/browser/diractivities/ROMActivity.java @@ -7,6 +7,11 @@ import com.retroarch.browser.preferences.util.UserPreferences; import android.content.SharedPreferences; import android.os.Bundle; +/** + * {@link DirectoryActivity} subclass used for the sole + * purpose of navigating the Android filesystem for selecting + * a ROM file to execute during emulation. + */ public final class ROMActivity extends DirectoryActivity { @Override public void onCreate(Bundle savedInstanceState) { diff --git a/android/phoenix/src/com/retroarch/browser/diractivities/ROMDirActivity.java b/android/phoenix/src/com/retroarch/browser/diractivities/ROMDirActivity.java index fe9b40b16f..dcdb7efe70 100644 --- a/android/phoenix/src/com/retroarch/browser/diractivities/ROMDirActivity.java +++ b/android/phoenix/src/com/retroarch/browser/diractivities/ROMDirActivity.java @@ -2,6 +2,11 @@ package com.retroarch.browser.diractivities; import android.os.Bundle; +/** + * {@link DirectoryActivity} subclass used for the sole + * purpose of navigating the Android filesystem to select + * a custom ROM directory. + */ public final class ROMDirActivity extends DirectoryActivity { @Override public void onCreate(Bundle savedInstanceState) { diff --git a/android/phoenix/src/com/retroarch/browser/diractivities/SRMDirActivity.java b/android/phoenix/src/com/retroarch/browser/diractivities/SRMDirActivity.java index e1e4bcc798..1234a1c160 100644 --- a/android/phoenix/src/com/retroarch/browser/diractivities/SRMDirActivity.java +++ b/android/phoenix/src/com/retroarch/browser/diractivities/SRMDirActivity.java @@ -2,6 +2,11 @@ package com.retroarch.browser.diractivities; import android.os.Bundle; +/** + * {@link DirectoryActivity} subclass used for the sole + * purpose of navigating the Android filesystem for selecting + * a custom save file directory. + */ public final class SRMDirActivity extends DirectoryActivity { @Override public void onCreate(Bundle savedInstanceState) { diff --git a/android/phoenix/src/com/retroarch/browser/diractivities/ShaderActivity.java b/android/phoenix/src/com/retroarch/browser/diractivities/ShaderActivity.java index ced24ddb1a..c8250e4e26 100644 --- a/android/phoenix/src/com/retroarch/browser/diractivities/ShaderActivity.java +++ b/android/phoenix/src/com/retroarch/browser/diractivities/ShaderActivity.java @@ -4,6 +4,11 @@ import java.io.File; import android.os.Bundle; +/** + * {@link DirectoryActivity} subclass used for the sole + * purpose of navigating the Android filesystem for selecting + * a shader to use during emulation. + */ public final class ShaderActivity extends DirectoryActivity { @Override public void onCreate(Bundle savedInstanceState) { diff --git a/android/phoenix/src/com/retroarch/browser/diractivities/StateDirActivity.java b/android/phoenix/src/com/retroarch/browser/diractivities/StateDirActivity.java index f9a8643868..ae8ee5735d 100644 --- a/android/phoenix/src/com/retroarch/browser/diractivities/StateDirActivity.java +++ b/android/phoenix/src/com/retroarch/browser/diractivities/StateDirActivity.java @@ -2,6 +2,11 @@ package com.retroarch.browser.diractivities; import android.os.Bundle; +/** + * {@link DirectoryActivity} subclass used for the sole + * purpose of navigating the Android filesystem to select + * a custom save state directory. + */ public final class StateDirActivity extends DirectoryActivity { @Override public void onCreate(Bundle savedInstanceState) { diff --git a/android/phoenix/src/com/retroarch/browser/diractivities/SystemDirActivity.java b/android/phoenix/src/com/retroarch/browser/diractivities/SystemDirActivity.java index d55e99641d..dde21536cc 100644 --- a/android/phoenix/src/com/retroarch/browser/diractivities/SystemDirActivity.java +++ b/android/phoenix/src/com/retroarch/browser/diractivities/SystemDirActivity.java @@ -2,6 +2,13 @@ package com.retroarch.browser.diractivities; import android.os.Bundle; +/** + * {@link DirectoryActivity} subclass used for the sole + * purpose of navigating the Android filesystem for selecting + * a custom 'System' directory that the cores will look in for + * required files, such as BIOS files and other miscellaneous + * system-required files. + */ public final class SystemDirActivity extends DirectoryActivity { @Override public void onCreate(Bundle savedInstanceState) {