[Android] Sort the cores in the CoreSelection activity alphabetically. Also document the IconAdapter class, along with its IconAdapterItem interface.

This commit is contained in:
Lioncash 2013-11-02 22:40:41 -04:00
parent dd8a57f26c
commit d07d97e517
2 changed files with 88 additions and 6 deletions

View File

@ -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<ModuleWrapper>(this, R.layout.line_list_item);
setListAdapter(adapter);
// Set the activity title.
setTitle(R.string.select_libretro_core);
// Populate the list
final List<ModuleWrapper> cores = new ArrayList<ModuleWrapper>();
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<ModuleWrapper>(this, R.layout.line_list_item, cores);
setListAdapter(adapter);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
}

View File

@ -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.
* <p>
* 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.
* <p>
* 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.
* <p>
* 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 <T> The type of the item that will be within this IconAdapter.
* This type must implement the {@link IconAdapterItem} interface.
*/
public final class IconAdapter<T extends IconAdapterItem> extends ArrayAdapter<T> {
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<T> items) {
super(context, resourceId, items);
this.context = context;
this.resourceId = resourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Build the view