• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 com.android.quicksearchbox.R;
20 import com.android.quicksearchbox.SearchableSource;
21 import com.android.quicksearchbox.Source;
22 import com.android.quicksearchbox.Suggestion;
23 
24 import android.app.SearchableInfo;
25 import android.content.Context;
26 import android.net.Uri;
27 import android.provider.ContactsContract;
28 import android.text.TextUtils;
29 import android.util.AttributeSet;
30 import android.view.View;
31 
32 /**
33  * View for contacts appearing in the suggestions list.
34  */
35 public class ContactSuggestionView extends DefaultSuggestionView {
36 
37     private static final String VIEW_ID = "contact";
38 
39     private ContactBadge mQuickContact;
40 
ContactSuggestionView(Context context, AttributeSet attrs, int defStyle)41     public ContactSuggestionView(Context context, AttributeSet attrs, int defStyle) {
42         super(context, attrs, defStyle);
43     }
44 
ContactSuggestionView(Context context, AttributeSet attrs)45     public ContactSuggestionView(Context context, AttributeSet attrs) {
46         super(context, attrs);
47     }
48 
ContactSuggestionView(Context context)49     public ContactSuggestionView(Context context) {
50         super(context);
51     }
52 
53     @Override
onFinishInflate()54     protected void onFinishInflate() {
55         super.onFinishInflate();
56         mQuickContact = (ContactBadge) findViewById(R.id.icon1);
57     }
58 
59     @Override
bindAsSuggestion(Suggestion suggestion, String userQuery)60     public void bindAsSuggestion(Suggestion suggestion, String userQuery) {
61         super.bindAsSuggestion(suggestion, userQuery);
62         mQuickContact.assignContactUri(Uri.parse(suggestion.getSuggestionIntentDataString()));
63         mQuickContact.setExtraOnClickListener(new ContactBadgeClickListener());
64     }
65 
66     private class ContactBadgeClickListener implements View.OnClickListener {
onClick(View v)67         public void onClick(View v) {
68             onSuggestionQuickContactClicked();
69         }
70     }
71 
72     public static class Factory extends SuggestionViewInflater {
Factory(Context context)73         public Factory(Context context) {
74             super(VIEW_ID, ContactSuggestionView.class, R.layout.contact_suggestion, context);
75         }
76 
77         @Override
canCreateView(Suggestion suggestion)78         public boolean canCreateView(Suggestion suggestion) {
79             Source source = suggestion.getSuggestionSource();
80             if (source instanceof SearchableSource) {
81                 SearchableSource searchableSource = (SearchableSource) source;
82                 return isSearchableContacts(searchableSource.getSearchableInfo());
83             }
84             return false;
85         }
86 
isSearchableContacts(SearchableInfo searchable)87         protected boolean isSearchableContacts(SearchableInfo searchable) {
88             return TextUtils.equals(ContactsContract.AUTHORITY, searchable.getSuggestAuthority());
89         }
90     }
91 }