[Android] Simplify LayoutInflater retrieval within IconAdapter.java. Also removed abstract from the methods within the interface IconAdapterItem. Methods within an interface are implicitly abstract.

Joined the declaration and assignment of an Intent within HistorySelection.java.
This commit is contained in:
Lioncash 2013-10-08 23:30:15 -04:00
parent 8fb23d0fcc
commit ac2c9840ff
2 changed files with 21 additions and 23 deletions

View File

@ -64,14 +64,13 @@ public final class HistorySelection extends Activity implements AdapterView.OnIt
MainMenuActivity.getInstance().setModule(corePath, item.getCoreName()); MainMenuActivity.getInstance().setModule(corePath, item.getCoreName());
Intent myIntent;
String current_ime = Settings.Secure.getString(getContentResolver(), String current_ime = Settings.Secure.getString(getContentResolver(),
Settings.Secure.DEFAULT_INPUT_METHOD); Settings.Secure.DEFAULT_INPUT_METHOD);
UserPreferences.updateConfigFile(this); UserPreferences.updateConfigFile(this);
Toast.makeText(this, String.format(getString(R.string.loading_gamepath), gamePath), Toast.LENGTH_SHORT).show(); Toast.makeText(this, String.format(getString(R.string.loading_gamepath), gamePath), Toast.LENGTH_SHORT).show();
myIntent = new Intent(this, RetroActivity.class); Intent myIntent = new Intent(this, RetroActivity.class);
myIntent.putExtra("ROM", gamePath); myIntent.putExtra("ROM", gamePath);
myIntent.putExtra("LIBRETRO", corePath); myIntent.putExtra("LIBRETRO", corePath);
myIntent.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(this)); myIntent.putExtra("CONFIGFILE", UserPreferences.getDefaultConfigPath(this));

View File

@ -2,48 +2,48 @@ package org.retroarch.browser;
import org.retroarch.R; import org.retroarch.R;
import android.app.*;
import android.content.*; import android.content.*;
import android.graphics.drawable.*; import android.graphics.drawable.*;
import android.view.*; import android.view.*;
import android.widget.*; import android.widget.*;
interface IconAdapterItem { interface IconAdapterItem {
public abstract boolean isEnabled(); public boolean isEnabled();
public abstract String getText(); public String getText();
public abstract String getSubText(); public String getSubText();
public abstract int getIconResourceId(); public int getIconResourceId();
public abstract Drawable getIconDrawable(); public Drawable getIconDrawable();
} }
public final class IconAdapter<T extends IconAdapterItem> extends ArrayAdapter<T> { public final class IconAdapter<T extends IconAdapterItem> extends ArrayAdapter<T> {
private final int layout; private final int resourceId;
private final Context context;
public IconAdapter(Activity aContext, int aLayout) { public IconAdapter(Context context, int resourceId) {
super(aContext, aLayout); super(context, resourceId);
layout = aLayout; this.context = context;
this.resourceId = resourceId;
} }
@Override @Override
public View getView(int aPosition, View aConvertView, ViewGroup aParent) { public View getView(int position, View convertView, ViewGroup parent) {
// Build the view // Build the view
if (aConvertView == null) { if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) aParent.getContext() LayoutInflater inflater = LayoutInflater.from(context);
.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(resourceId, parent, false);
aConvertView = inflater.inflate(layout, aParent, false);
} }
// Fill the view // Fill the view
IconAdapterItem item = getItem(aPosition); IconAdapterItem item = getItem(position);
final boolean enabled = item.isEnabled(); final boolean enabled = item.isEnabled();
TextView textView = (TextView) aConvertView.findViewById(R.id.name); TextView textView = (TextView) convertView.findViewById(R.id.name);
if (null != textView) { if (null != textView) {
textView.setText(item.getText()); textView.setText(item.getText());
textView.setEnabled(enabled); textView.setEnabled(enabled);
} }
textView = (TextView) aConvertView.findViewById(R.id.sub_name); textView = (TextView) convertView.findViewById(R.id.sub_name);
if (null != textView) { if (null != textView) {
String subText = item.getSubText(); String subText = item.getSubText();
if (null != subText) { if (null != subText) {
@ -53,7 +53,7 @@ public final class IconAdapter<T extends IconAdapterItem> extends ArrayAdapter<T
} }
} }
ImageView imageView = (ImageView) aConvertView.findViewById(R.id.icon); ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
if (null != imageView) { if (null != imageView) {
if (enabled) { if (enabled) {
final int id = item.getIconResourceId(); final int id = item.getIconResourceId();
@ -67,12 +67,11 @@ public final class IconAdapter<T extends IconAdapterItem> extends ArrayAdapter<T
} }
} }
return aConvertView; return convertView;
} }
@Override @Override
public boolean isEnabled(int aPosition) { public boolean isEnabled(int aPosition) {
return getItem(aPosition).isEnabled(); return getItem(aPosition).isEnabled();
} }
} }