| 1 | /* |
| 2 | * Copyright (C) 2010 Keith Kildare |
| 3 | * |
| 4 | * This file is part of SimplyDo. |
| 5 | * |
| 6 | * SimplyDo is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * SimplyDo is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with SimplyDo. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | */ |
| 20 | package kdk.android.simplydo; |
| 21 | |
| 22 | import android.graphics.Paint; |
| 23 | import android.util.Log; |
| 24 | import android.view.View; |
| 25 | import android.view.ViewGroup; |
| 26 | import android.widget.BaseAdapter; |
| 27 | import android.widget.ImageSwitcher; |
| 28 | import android.widget.TextView; |
| 29 | |
| 30 | public class ItemPropertiesAdapter extends BaseAdapter |
| 31 | { |
| 32 | private SimplyDoActivity context; |
| 33 | private DataViewer dataViewer; |
| 34 | |
| 35 | |
| 36 | public ItemPropertiesAdapter(SimplyDoActivity context, DataViewer dataViewer) |
| 37 | { |
| 38 | this.context = context; |
| 39 | this.dataViewer = dataViewer; |
| 40 | } |
| 41 | |
| 42 | |
| 43 | @Override |
| 44 | public int getCount() |
| 45 | { |
| 46 | //Log.v(L.TAG, "ItemPropertiesAdapter.getCount() called"); |
| 47 | return dataViewer.getItemData().size(); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public Object getItem(int position) |
| 52 | { |
| 53 | //Log.v(L.TAG, "ItemPropertiesAdapter.getItem() called"); |
| 54 | return dataViewer.getItemData().get(position); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public long getItemId(int position) |
| 59 | { |
| 60 | //Log.v(L.TAG, "ItemPropertiesAdapter.getItemId() called"); |
| 61 | return position; |
| 62 | } |
| 63 | |
| 64 | |
| 65 | @Override |
| 66 | public View getView(final int position, View convertView, ViewGroup parent) |
| 67 | { |
| 68 | //Log.v(L.TAG, "ItemPropertiesAdapter.getView() called"); |
| 69 | |
| 70 | View rv = null; |
| 71 | |
| 72 | try |
| 73 | { |
| 74 | if(convertView == null) |
| 75 | { |
| 76 | rv = View.inflate(context, R.layout.item_entry, null); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | rv = convertView; |
| 81 | } |
| 82 | |
| 83 | ItemDesc it = dataViewer.getItemData().get(position); |
| 84 | TextView t1 = (TextView)rv.findViewById(R.id.ieText1); |
| 85 | t1.setText(it.getLabel()); |
| 86 | t1.setTextAppearance(context, it.isActive()?R.style.ActiveText:R.style.InactiveText); |
| 87 | if(it.isActive()) |
| 88 | { |
| 89 | t1.setPaintFlags(t1.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | t1.setPaintFlags(t1.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); |
| 94 | } |
| 95 | |
| 96 | ImageSwitcher starSwitch = (ImageSwitcher)rv.findViewById(R.id.StarSwitcher); |
| 97 | starSwitch.setVisibility(it.isStar()?View.VISIBLE:View.INVISIBLE); |
| 98 | starSwitch.setDisplayedChild(it.isActive()?0:1); |
| 99 | |
| 100 | View sortedMarker = (View)rv.findViewById(R.id.SortedMarker); |
| 101 | if(it.isSorted()) |
| 102 | { |
| 103 | sortedMarker.setVisibility(View.INVISIBLE); |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | sortedMarker.setVisibility(View.VISIBLE); |
| 108 | } |
| 109 | |
| 110 | } |
| 111 | catch(Exception e) |
| 112 | { |
| 113 | Log.e(L.TAG, "Error in getView()", e); |
| 114 | } |
| 115 | |
| 116 | return rv; |
| 117 | } |
| 118 | |
| 119 | } |