/TextEnlarger/src/com/ideal/textenlarger/ExtendedCheckBoxListAdapter.java
Java | 145 lines | 57 code | 20 blank | 68 comment | 5 complexity | c861f6474babd6c54489b02d14af3ae4 MD5 | raw file
1/* 2 * Copyright (C) 2010 The IDEAL Group 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16package com.ideal.textenlarger; 17 18 19import java.util.ArrayList; 20import java.util.List; 21 22import android.content.Context; 23import android.view.View; 24import android.view.ViewGroup; 25import android.widget.BaseAdapter; 26 27/** 28 * Class needed by ApplicationsListActivity. 29 * 30 * This was taken from a checkbox list tutorial at anddev.org: 31 * http://www.anddev.org/extended_checkbox_list__extension_of_checkbox_text_list_tu-t5734.html 32 */ 33public class ExtendedCheckBoxListAdapter extends BaseAdapter { 34 35 /** Remember our context so we can use it when constructing views. */ 36 private Context mContext; 37 38 private List<ExtendedCheckBox> mItems = new ArrayList<ExtendedCheckBox>(); 39 40 /** 41 * 42 * @param context - Render context 43 */ 44 public ExtendedCheckBoxListAdapter(Context context) { 45 mContext = context; 46 } 47 48 /** 49 * Add a new Item at the end of the exiting ones 50 * @param it - New item to be added 51 */ 52 public void addItem(ExtendedCheckBox it) { 53 mItems.add(it); 54 } 55 56 /** 57 * Will force to use a list of items 58 * @param lit - List of items to be used 59 */ 60 public void setListItems(List<ExtendedCheckBox> lit) { 61 mItems = lit; 62 } 63 64 /** 65 * @return The number of items this adapter offers 66 */ 67 public int getCount() { 68 return mItems.size(); 69 } 70 71 /** 72 * Return item at a specific position 73 */ 74 public Object getItem(int position) { 75 return mItems.get(position); 76 } 77 78 /** 79 * Returns the position of an element 80 */ 81 public int GetPosition( ExtendedCheckBox item ) { 82 int count = getCount(); 83 for ( int i = 0; i < count; i++ ) 84 { 85 if ( item.compareTo((ExtendedCheckBox)getItem(i)) == 0 ) 86 return i; 87 } 88 return -1; 89 } 90 91 /** 92 * Set selection of an item 93 * @param value - true or false 94 * @param position - position 95 */ 96 public void setChecked(boolean value, int position) { 97 mItems.get(position).setChecked(value); 98 } 99 100 /** 101 * Select all elements 102 */ 103 public void selectAll() { 104 for(ExtendedCheckBox cboxtxt: mItems) 105 cboxtxt.setChecked(true); 106 107 /* Things have changed, do a redraw. */ 108 this.notifyDataSetInvalidated(); 109 } 110 111 /** 112 * Deselect all elements 113 */ 114 public void deselectAll() { 115 for(ExtendedCheckBox cboxtxt: mItems) 116 cboxtxt.setChecked(false); 117 118 /* Things have changed, do a redraw. */ 119 this.notifyDataSetInvalidated(); 120 } 121 122 /** 123 * Decides if all items are selectable 124 * @return - true or false 125 */ 126 public boolean areAllItemsSelectable() { 127 return false; 128 } 129 130 /** 131 * Use the array index as a unique id 132 */ 133 public long getItemId(int position) { 134 return position; 135 } 136 137 /** 138 * Do not recycle a view if one is already there, if not the data could get corrupted and 139 * the checkbox state could be lost. 140 * @param convertView The old view to overwrite 141 * @returns a CheckBoxifiedTextView that holds wraps around an CheckBoxifiedText */ 142 public View getView(int position, View convertView, ViewGroup parent ){ 143 return new ExtendedCheckBoxListView(mContext, mItems.get(position)); 144 } 145}