From d07d97e51746e3229f25611888c4931581ad861f Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 2 Nov 2013 22:40:41 -0400 Subject: [PATCH] [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