11package oly .netpowerctrl .listadapter ;
22
3- import java .util .ArrayList ;
43import java .util .List ;
5- import java .util .Locale ;
64import java .util .UUID ;
75
86import oly .netpowerctrl .R ;
1513import android .view .View .OnClickListener ;
1614import android .view .ViewGroup ;
1715import android .widget .BaseAdapter ;
18- import android .widget .Filter ;
19- import android .widget .Filterable ;
2016import android .widget .ImageButton ;
2117import android .widget .TextView ;
2218
23- public class DeviceListAdapter extends BaseAdapter implements Filterable , OnClickListener {
19+ public class DeviceListAdapter extends BaseAdapter implements OnClickListener {
2420
2521 private DeviceConfigureEvent deviceConfigureEvent = null ;
2622
2723 private List <DeviceInfo > all_devices ;
28- private List <DeviceInfo > visible_devices ;
2924 private LayoutInflater inflater ;
30- private DeviceFilter filter = null ;
3125 private Context context = null ;
3226
3327 public DeviceListAdapter (Context context , List <DeviceInfo > devices ) {
3428 this .context = context ;
3529 inflater = LayoutInflater .from (context );
3630 all_devices = devices ;
37- visible_devices = new ArrayList <DeviceInfo >(devices );
3831 }
3932
4033 public int getCount () {
41- return visible_devices .size ();
34+ return all_devices .size ();
4235 }
4336
4437 public Object getItem (int position ) {
45- return visible_devices .get (position );
38+ return all_devices .get (position );
4639 }
4740
4841 public long getItemId (int position ) {
@@ -63,7 +56,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
6356 if (convertView == null )
6457 convertView = inflater .inflate (R .layout .device_list_item , null );
6558
66- DeviceInfo di = visible_devices .get (position );
59+ DeviceInfo di = all_devices .get (position );
6760 TextView tvName = (TextView ) convertView .findViewById (R .id .device_name );
6861 tvName .setText (di .DeviceName );
6962
@@ -103,53 +96,8 @@ public void onClick(View v) {
10396 }
10497 }
10598
106-
107- public Filter getFilter () {
108- if (filter == null ) {
109- filter = new DeviceFilter ();
110- }
111- return filter ;
112- }
113-
114- private class DeviceFilter extends Filter
115- {
116-
117- @ Override
118- protected FilterResults performFiltering (CharSequence constraint ) {
119- FilterResults results = new FilterResults ();
120- ArrayList <DeviceInfo > list ;
121-
122- if (constraint == null || constraint .length () == 0 ) {
123- list = new ArrayList <DeviceInfo >(all_devices );
124- } else {
125- list = new ArrayList <DeviceInfo >();
126- String match = constraint .toString ().toLowerCase (Locale .US );
127- for (DeviceInfo item : all_devices ) {
128- if (item .DeviceName .toLowerCase (Locale .US ).contains (match ))
129- list .add (item );
130- }
131-
132- }
133- results .values = list ;
134- results .count = list .size ();
135- return results ;
136- }
137-
138- @ SuppressWarnings ("unchecked" )
139- @ Override
140- protected void publishResults (CharSequence constraint , FilterResults results ) {
141- visible_devices = (List <DeviceInfo >)results .values ;
142- if (results .count > 0 ) {
143- notifyDataSetChanged ();
144- } else {
145- notifyDataSetInvalidated ();
146- }
147- }
148-
149- }
150-
15199 public void update () {
152- getFilter (). filter ( "" );
100+ notifyDataSetChanged ( );
153101 }
154102
155103}
0 commit comments