diff --git a/android/phoenix/src/org/retroarch/browser/CoreSelection.java b/android/phoenix/src/org/retroarch/browser/CoreSelection.java index 59bcdab638..f9c8a68630 100644 --- a/android/phoenix/src/org/retroarch/browser/CoreSelection.java +++ b/android/phoenix/src/org/retroarch/browser/CoreSelection.java @@ -33,13 +33,14 @@ public final class CoreSelection extends ListActivity { final String cpuInfo = UserPreferences.readCPUInfo(); final boolean cpuIsNeon = cpuInfo.contains("neon"); + // Setup the layout setContentView(R.layout.line_list); // Setup the list adapter = new IconAdapter(this, R.layout.line_list_item); - ListView list = getListView(); - list.setAdapter(adapter); + setListAdapter(adapter); + // Set the activity title. setTitle(R.string.select_libretro_core); // Populate the list diff --git a/android/phoenix/src/org/retroarch/browser/FileWrapper.java b/android/phoenix/src/org/retroarch/browser/FileWrapper.java index cee18e991f..9f0a3ac91f 100644 --- a/android/phoenix/src/org/retroarch/browser/FileWrapper.java +++ b/android/phoenix/src/org/retroarch/browser/FileWrapper.java @@ -6,25 +6,24 @@ import org.retroarch.R; import android.graphics.drawable.Drawable; -public final class FileWrapper implements IconAdapterItem { - public final File file; - public final boolean parentItem; - public final boolean dirSelectItem; - - protected final boolean enabled; - +public final class FileWrapper implements IconAdapterItem, Comparable { + public static final int DIRSELECT = 0; public static final int PARENT = 1; public static final int FILE = 2; - - protected final int typeIndex; + + private final File file; + private final boolean parentItem; + private final boolean dirSelectItem; + private final boolean enabled; + private final int typeIndex; public FileWrapper(File file, int type, boolean isEnabled) { this.file = file; - this.parentItem = type == PARENT; - this.dirSelectItem = type == DIRSELECT; - this.typeIndex = type == FILE ? (FILE + (file.isDirectory() ? 0 : 1)) : type; + this.parentItem = (type == PARENT); + this.dirSelectItem = (type == DIRSELECT); + this.typeIndex = (type == FILE) ? (FILE + (file.isDirectory() ? 0 : 1)) : type; this.enabled = parentItem || dirSelectItem || isEnabled; } @@ -43,7 +42,7 @@ public final class FileWrapper implements IconAdapterItem { else return file.getName(); } - + @Override public String getSubText() { return null; @@ -63,6 +62,38 @@ public final class FileWrapper implements IconAdapterItem { return null; } + /** + * Checks whether or not the wrapped {@link File} is + * the "Parent Directory" item in the file browser. + * + * @return true if the wrapped {@link File} is the "Parent Directory" + * item in the file browser; false otherwise. + */ + public boolean isParentItem() { + return parentItem; + } + + /** + * Checks whether or not the wrapped {@link File} + * is the "use this directory" item. + * + * @return true if the wrapped {@link File} is the "Use this directory" + * item in the file browser; false otherwise. + */ + public boolean isDirSelectItem() { + return dirSelectItem; + } + + /** + * Gets the file wrapped by this FileWrapper. + * + * @return the file wrapped by this FileWrapper. + */ + public File getFile() { + return file; + } + + @Override public int compareTo(FileWrapper other) { if (other != null) { // Who says ternary is hard to follow diff --git a/android/phoenix/src/org/retroarch/browser/HistorySelection.java b/android/phoenix/src/org/retroarch/browser/HistorySelection.java index 94f52af3e0..2c2b6e5f44 100644 --- a/android/phoenix/src/org/retroarch/browser/HistorySelection.java +++ b/android/phoenix/src/org/retroarch/browser/HistorySelection.java @@ -24,18 +24,19 @@ public final class HistorySelection extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + + // Setup the layout. setContentView(R.layout.line_list); // Setup the list adapter = new IconAdapter(this, R.layout.line_list_item); - ListView list = getListView(); - list.setAdapter(adapter); + setListAdapter(adapter); + // Set activity title. setTitle(R.string.recently_played_games); - + File history = new File(getApplicationInfo().dataDir, "retroarch-history.txt"); - + try { BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(history))); @@ -46,14 +47,14 @@ public final class HistorySelection extends ListActivity { String name = br.readLine(); if (game == null || core == null || name == null) break; - + adapter.add(new HistoryWrapper(game, core, name)); } br.close(); } catch (IOException ex) { } } - + @Override public void onListItemClick(ListView listView, View view, int position, long id) { final HistoryWrapper item = adapter.getItem(position); diff --git a/android/phoenix/src/org/retroarch/browser/diractivities/DirectoryActivity.java b/android/phoenix/src/org/retroarch/browser/diractivities/DirectoryActivity.java index c08b746824..65f3e36e38 100644 --- a/android/phoenix/src/org/retroarch/browser/diractivities/DirectoryActivity.java +++ b/android/phoenix/src/org/retroarch/browser/diractivities/DirectoryActivity.java @@ -21,8 +21,8 @@ public class DirectoryActivity extends ListActivity { private File listedDirectory; public static class BackStackItem implements Parcelable { - public String path; - public boolean parentIsBack; + private final String path; + private final boolean parentIsBack; public BackStackItem(String path, boolean parentIsBack) { this.path = path; @@ -80,8 +80,7 @@ public class DirectoryActivity extends ListActivity { // Setup the list adapter = new IconAdapter(this, R.layout.line_list_item); - ListView list = getListView(); - list.setAdapter(adapter); + setListAdapter(adapter); // Load Directory if (savedInstanceState != null) { @@ -123,21 +122,20 @@ public class DirectoryActivity extends ListActivity { public void onListItemClick(ListView listView, View aView, int position, long id) { final FileWrapper item = adapter.getItem(position); - if (item.parentItem && backStack.get(backStack.size() - 1).parentIsBack) { + if (item.isParentItem() && backStack.get(backStack.size() - 1).parentIsBack) { backStack.remove(backStack.size() - 1); wrapFiles(); return; - } else if (item.dirSelectItem) { + } else if (item.isDirSelectItem()) { finishWithPath(listedDirectory.getAbsolutePath()); return; } - final File selected = item.parentItem ? listedDirectory.getParentFile() - : item.file; + final File selected = item.isParentItem() ? listedDirectory.getParentFile() : item.getFile(); if (selected.isDirectory()) { backStack.add(new BackStackItem(selected.getAbsolutePath(), - !item.parentItem)); + !item.isParentItem())); wrapFiles(); } else { String filePath = selected.getAbsolutePath(); @@ -229,8 +227,8 @@ public class DirectoryActivity extends ListActivity { // Sort items adapter.sort(new Comparator() { @Override - public int compare(FileWrapper aLeft, FileWrapper aRight) { - return aLeft.compareTo(aRight); + public int compare(FileWrapper left, FileWrapper right) { + return left.compareTo(right); }; });