2 Copyright (C) 2014 Samsung Electronics Polska Sp. z o.o.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU AFFERO General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 You may obtain a copy of the License at
10 http://www.gnu.org/licenses/agpl-3.0.txt
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com.samsung.srpol.ui.drawer;
23 import java.util.Collection;
25 import com.samsung.srpol.R;
26 import com.samsung.srpol.data.Category;
28 import android.content.Context;
29 import android.text.Spannable;
30 import android.text.SpannableString;
31 import android.text.style.ForegroundColorSpan;
32 import android.view.LayoutInflater;
33 import android.view.View;
34 import android.view.ViewGroup;
35 import android.widget.ArrayAdapter;
36 import android.widget.ImageView;
37 import android.widget.TextView;
39 public class CategoryArrayAdapter extends ArrayAdapter<Category> {
40 private final Context mContext;
41 private String mTextPrefix ;
42 private String mCountTextPrefix;
43 private int mSpanTextColor;
45 private static class ViewHolder {
52 public CategoryArrayAdapter(Context context) {
53 super(context, R.layout.drawer_list_item);
54 mTextPrefix = context.getResources().getString(R.string.drawer_header_text_prefix);
55 mCountTextPrefix = context.getResources().getString(R.string.items_string_quantity);
56 mSpanTextColor = context.getResources().getColor(R.color.text_menu);
61 public void addAll(Collection<? extends Category> collection) {
62 for (Category category : collection) {
68 public View getView(int position, View convertView, ViewGroup parent) {
69 ViewHolder holder = null;
70 if (convertView == null) {
71 LayoutInflater inflater = (LayoutInflater) mContext
72 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
73 convertView = inflater.inflate(R.layout.drawer_list_item, parent,
75 holder = new ViewHolder();
76 holder.textView1 = (TextView) convertView.findViewById(R.id.text1);
77 holder.textView2 = (TextView) convertView.findViewById(R.id.text2);
78 holder.textView3 = (TextView) convertView.findViewById(R.id.text3);
79 holder.imageView = (ImageView) convertView.findViewById(R.id.icon);
81 convertView.setTag(holder);
83 holder = (ViewHolder) convertView.getTag();
86 Category category = getItem(position);
87 if (category.getIconRes() > 0)
88 holder.imageView.setImageResource(category.getIconRes());
89 holder.textView1.setText(mTextPrefix + category.getHeader());
90 holder.textView2.setText(category.getShortDescription());
91 holder.textView3.setText(createSpannableCountText(category.getCurrentlyVisible()));
95 private Spannable createSpannableCountText(int count){
97 Spannable spannable = new SpannableString(mCountTextPrefix + count);
98 spannable.setSpan(new ForegroundColorSpan(mSpanTextColor),mCountTextPrefix.length(), spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);