1fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood/* 2fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Copyright (C) 2009 The Android Open Source Project 3fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 4fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Licensed under the Apache License, Version 2.0 (the "License"); 5fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * you may not use this file except in compliance with the License. 6fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * You may obtain a copy of the License at 7fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 8fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * http://www.apache.org/licenses/LICENSE-2.0 9fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * 10fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Unless required by applicable law or agreed to in writing, software 11fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * distributed under the License is distributed on an "AS IS" BASIS, 12fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * See the License for the specific language governing permissions and 14fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * limitations under the License. 15fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood */ 16fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 17fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodpackage com.android.quicksearchbox.ui; 18fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 19fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.view.View; 20fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.view.ViewGroup; 21fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.widget.BaseAdapter; 22fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodimport android.widget.ListAdapter; 23fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 24ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwoodimport com.android.quicksearchbox.SuggestionCursor; 25ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwoodimport com.android.quicksearchbox.SuggestionPosition; 26ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwoodimport com.android.quicksearchbox.Suggestions; 27ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwood 28fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood/** 29fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood * Uses a {@link Suggestions} object to back a {@link SuggestionsView}. 30fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood */ 31fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwoodpublic class SuggestionsListAdapter extends SuggestionsAdapterBase<ListAdapter> { 32fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 33fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood private Adapter mAdapter; 34fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 3577909685887bd6db7454b73cf274afc3aca2f58dBjorn Bringert public SuggestionsListAdapter(SuggestionViewFactory viewFactory) { 3677909685887bd6db7454b73cf274afc3aca2f58dBjorn Bringert super(viewFactory); 37fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood mAdapter = new Adapter(); 38fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 39fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 40fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood @Override 417a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood public boolean isEmpty() { 427a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood return mAdapter.getCount() == 0; 437a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood } 447a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 457a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood @Override 467a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood public SuggestionPosition getSuggestion(long suggestionId) { 47ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwood return new SuggestionPosition(getCurrentSuggestions(), (int) suggestionId); 487a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood } 497a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood 507a0c3a7c6fdabce949b59e0a2c6ec1d44a140c24Mathew Inwood @Override 51fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public BaseAdapter getListAdapter() { 52fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood return mAdapter; 53fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 54fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 55fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood @Override 56fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public void notifyDataSetChanged() { 57fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood mAdapter.notifyDataSetChanged(); 58fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 59fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 60fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood @Override 61fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public void notifyDataSetInvalidated() { 62fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood mAdapter.notifyDataSetInvalidated(); 63fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 64fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 65fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood class Adapter extends BaseAdapter { 66fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 67fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood @Override 68fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public int getCount() { 69ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwood SuggestionCursor s = getCurrentSuggestions(); 70ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwood return s == null ? 0 : s.getCount(); 71fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 72fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 73fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood @Override 74fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public Object getItem(int position) { 75ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwood return getSuggestion(position); 76fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 77fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 78fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood @Override 79fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public long getItemId(int position) { 80fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood return position; 81fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 82fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 83fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood @Override 84fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public View getView(int position, View convertView, ViewGroup parent) { 85fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood return SuggestionsListAdapter.this.getView( 86ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwood getCurrentSuggestions(), position, position, convertView, parent); 87fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 88fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 89fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood @Override 90fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public int getItemViewType(int position) { 91ecf356c15143ab0583c64682de16d94a57f7dd1cMathew Inwood return getSuggestionViewType(getCurrentSuggestions(), position); 92fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 93fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 94fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood @Override 95fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood public int getViewTypeCount() { 96fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood return getSuggestionViewTypeCount(); 97fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 98fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 99fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood } 100fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood 101fd4a4cbc1143a734d357897531daa7105db6459bMathew Inwood} 102