From f018b56985ff12a63b21cefe302421bb5f0c2209 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sat, 9 Nov 2013 12:40:15 -0800 Subject: Added icons to the drawer --- .../dsub/activity/SubsonicActivity.java | 26 +++++---- .../daneren2005/dsub/view/DrawerAdapter.java | 68 ++++++++++++++++++++++ 2 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 src/github/daneren2005/dsub/view/DrawerAdapter.java (limited to 'src') diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java index 71b2b790..3c884683 100644 --- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java +++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageInfo; +import android.content.res.TypedArray; import android.media.AudioManager; import android.os.Build; import android.os.Bundle; @@ -58,10 +59,14 @@ import github.daneren2005.dsub.service.DownloadServiceImpl; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.ImageLoader; import github.daneren2005.dsub.util.Util; +import github.daneren2005.dsub.view.DrawerAdapter; + import java.io.File; import java.io.PrintWriter; +import java.util.AbstractList; import java.util.ArrayList; import java.util.Arrays; +import java.util.Iterator; import java.util.List; public class SubsonicActivity extends ActionBarActivity implements OnItemSelectedListener { @@ -376,11 +381,18 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte int alreadyRemoved = 0; List drawerItemsList = new ArrayList(Arrays.asList(drawerItems)); List drawerItemsDescriptionsList = new ArrayList(Arrays.asList(drawerItemsDescriptions)); + List drawerItemsIconsList = new ArrayList(); + + TypedArray typedArray = getResources().obtainTypedArray(R.array.drawerItemIcons); + for(int i = 0; i < drawerItemsList.size(); i++) { + drawerItemsIconsList.add(typedArray.getResourceId(i, 0)); + } // Selectively remove podcast listing [3] if(!podcastsEnabled) { drawerItemsList.remove(3 - alreadyRemoved); drawerItemsDescriptionsList.remove(3 - alreadyRemoved); + drawerItemsIconsList.remove(3 - alreadyRemoved); alreadyRemoved++; } @@ -388,6 +400,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(!bookmarksEnabled) { drawerItemsList.remove(4 - alreadyRemoved); drawerItemsDescriptionsList.remove(4 - alreadyRemoved); + drawerItemsIconsList.remove(4 - alreadyRemoved); alreadyRemoved++; } @@ -395,6 +408,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte if(!chatEnabled) { drawerItemsList.remove(5 - alreadyRemoved); drawerItemsDescriptionsList.remove(5 - alreadyRemoved); + drawerItemsIconsList.remove(5 - alreadyRemoved); alreadyRemoved++; } @@ -404,23 +418,13 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte drawerItemsDescriptions = drawerItemsDescriptionsList.toArray(new String[0]); } - drawerList.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, drawerItems)); + drawerList.setAdapter(new DrawerAdapter(this, drawerItemsList, drawerItemsIconsList)); enabledItems[0] = podcastsEnabled; enabledItems[1] = bookmarksEnabled; enabledItems[2] = chatEnabled; } } - public void startActivity(Class t) { - Intent intent = new Intent(); - intent.setClass(SubsonicActivity.this, t); - intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(intent); - if(this.getClass() != SubsonicFragmentActivity.class) { - finish(); - } - drawer.closeDrawers(); - } public void startFragmentActivity(String fragmentType) { Intent intent = new Intent(); intent.setClass(SubsonicActivity.this, SubsonicFragmentActivity.class); diff --git a/src/github/daneren2005/dsub/view/DrawerAdapter.java b/src/github/daneren2005/dsub/view/DrawerAdapter.java new file mode 100644 index 00000000..d3639373 --- /dev/null +++ b/src/github/daneren2005/dsub/view/DrawerAdapter.java @@ -0,0 +1,68 @@ +/* + This file is part of Subsonic. + + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see . + + Copyright 2009 (C) Sindre Mehus +*/ +package github.daneren2005.dsub.view; + +import android.content.Context; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import java.util.List; + +import github.daneren2005.dsub.R; + +/** + * Created by Scott on 11/8/13. + */ +public class DrawerAdapter extends ArrayAdapter { + private static String TAG = DrawerAdapter.class.getSimpleName(); + private Context context; + private List items; + private List icons; + + public DrawerAdapter(Context context, List items, List icons) { + super(context, R.layout.drawer_list_item, items); + + this.context = context; + this.items = items; + this.icons = icons; + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + String item = items.get(position); + Integer icon = icons.get(position); + + if(convertView == null) { + convertView = LayoutInflater.from(context).inflate(R.layout.drawer_list_item, null); + } + + TextView textView = (TextView) convertView.findViewById(R.id.drawer_name); + textView.setText(item); + ImageView iconView = (ImageView) convertView.findViewById(R.id.drawer_icon); + Log.d(TAG, "icon: " + icon); + iconView.setImageResource(icon); + + return convertView; + } +} -- cgit v1.2.3