Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Android] Simplify LayoutInflater retrieval within GameListAdapter, F…
…olderBrowserAdapter, and SideMenuAdapter.

Also added Javadoc to SideMenuAdapter. Gave the context variables a full spelling as well.
  • Loading branch information
lioncash committed Oct 3, 2013
1 parent 4e08a6c commit 8dfc752
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
Expand Up @@ -27,7 +27,7 @@
*/
public final class FolderBrowserAdapter extends ArrayAdapter<FolderBrowserItem>
{
private final Context c;
private final Context context;
private final int id;
private final List<FolderBrowserItem> items;

Expand All @@ -42,7 +42,7 @@ public FolderBrowserAdapter(Context context, int resourceId, List<FolderBrowserI
{
super(context, resourceId, objects);

this.c = context;
this.context = context;
this.id = resourceId;
this.items = objects;
}
Expand All @@ -59,7 +59,7 @@ public View getView(int position, View convertView, ViewGroup parent)
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater vi = LayoutInflater.from(context);
v = vi.inflate(id, parent, false);
}

Expand All @@ -78,7 +78,7 @@ public View getView(int position, View convertView, ViewGroup parent)
if(subtitle != null)
{
// Remove the subtitle for all folders, except for the parent directory folder.
if (item.isDirectory() && !item.getSubtitle().equals(c.getString(R.string.parent_directory)))
if (item.isDirectory() && !item.getSubtitle().equals(context.getString(R.string.parent_directory)))
{
subtitle.setVisibility(View.GONE);
}
Expand Down
Expand Up @@ -26,7 +26,7 @@
*/
public final class GameListAdapter extends ArrayAdapter<GameListItem>
{
private final Context c;
private final Context context;
private final int id;
private final List<GameListItem>items;

Expand All @@ -41,7 +41,7 @@ public GameListAdapter(Context context, int resourceId, List<GameListItem> objec
{
super(context, resourceId, objects);

this.c = context;
this.context = context;
this.id = resourceId;
this.items = objects;
}
Expand All @@ -58,7 +58,7 @@ public View getView(int position, View convertView, ViewGroup parent)
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater vi = LayoutInflater.from(context);
v = vi.inflate(id, parent, false);
}

Expand All @@ -78,8 +78,8 @@ public View getView(int position, View convertView, ViewGroup parent)
if (icon != null)
{
icon.setImageBitmap(item.getImage());
icon.getLayoutParams().width = (int) ((860 / c.getResources().getDisplayMetrics().density) + 0.5);
icon.getLayoutParams().height = (int)((340 / c.getResources().getDisplayMetrics().density) + 0.5);
icon.getLayoutParams().width = (int) ((860 / context.getResources().getDisplayMetrics().density) + 0.5);
icon.getLayoutParams().height = (int)((340 / context.getResources().getDisplayMetrics().density) + 0.5);
}
}

Expand Down
Expand Up @@ -11,6 +11,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;
Expand All @@ -24,16 +25,24 @@
*/
public final class SideMenuAdapter extends ArrayAdapter<SideMenuItem>
{
private final Context c;
private final Context context;
private final int id;
private final List<SideMenuItem>items;

public SideMenuAdapter(Context context, int textViewResourceId, List<SideMenuItem> objects)
/**
* 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 objects The objects to represent in the {@link ListView}.
*/
public SideMenuAdapter(Context context, int resourceId, List<SideMenuItem> objects)
{
super(context, textViewResourceId, objects);
c = context;
id = textViewResourceId;
items = objects;
super(context, resourceId, objects);

this.context = context;
this.id = resourceId;
this.items = objects;
}

@Override
Expand All @@ -48,7 +57,7 @@ public View getView(int position, View convertView, ViewGroup parent)
View v = convertView;
if (v == null)
{
LayoutInflater vi = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutInflater vi = LayoutInflater.from(context);
v = vi.inflate(id, null);
}

Expand Down

0 comments on commit 8dfc752

Please sign in to comment.