Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2009 The Android Open Source Project
      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  */
     16 
     17 package com.android.quicksearchbox.ui;
     18 
     19 import android.content.Context;
     20 import android.util.AttributeSet;
     21 import android.widget.ListAdapter;
     22 import android.widget.ListView;
     23 
     24 import com.android.quicksearchbox.SuggestionPosition;
     25 
     26 /**
     27  * Holds a list of suggestions.
     28  */
     29 public class SuggestionsView extends ListView implements SuggestionsListView<ListAdapter> {
     30 
     31     private static final boolean DBG = false;
     32     private static final String TAG = "QSB.SuggestionsView";
     33 
     34     private SuggestionsAdapter<ListAdapter> mSuggestionsAdapter;
     35 
     36     public SuggestionsView(Context context, AttributeSet attrs) {
     37         super(context, attrs);
     38     }
     39 
     40     @Override
     41     public void setSuggestionsAdapter(SuggestionsAdapter<ListAdapter> adapter) {
     42         super.setAdapter(adapter == null ? null : adapter.getListAdapter());
     43         mSuggestionsAdapter = adapter;
     44     }
     45 
     46     @Override
     47     public SuggestionsAdapter<ListAdapter> getSuggestionsAdapter() {
     48         return mSuggestionsAdapter;
     49     }
     50 
     51     @Override
     52     public void onFinishInflate() {
     53         super.onFinishInflate();
     54         setItemsCanFocus(true);
     55     }
     56 
     57     /**
     58      * Gets the position of the selected suggestion.
     59      *
     60      * @return A 0-based index, or {@code -1} if no suggestion is selected.
     61      */
     62     public int getSelectedPosition() {
     63         return getSelectedItemPosition();
     64     }
     65 
     66     /**
     67      * Gets the selected suggestion.
     68      *
     69      * @return {@code null} if no suggestion is selected.
     70      */
     71     public SuggestionPosition getSelectedSuggestion() {
     72         return (SuggestionPosition) getSelectedItem();
     73     }
     74 
     75 
     76 }
     77