• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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.contacts.editor;
18 
19 import android.content.Context;
20 import android.net.Uri;
21 import android.provider.ContactsContract.Contacts;
22 import android.text.TextUtils;
23 import android.util.AttributeSet;
24 import android.view.View;
25 import android.widget.ImageView;
26 import android.widget.LinearLayout;
27 import android.widget.TextView;
28 
29 import com.android.contacts.ContactPhotoManager;
30 import com.android.contacts.R;
31 import com.android.contacts.editor.AggregationSuggestionEngine.Suggestion;
32 
33 /**
34  * A view that contains a name, picture and other data for a contact aggregation suggestion.
35  */
36 public class AggregationSuggestionView extends LinearLayout {
37 
38     public interface Listener {
39         /**
40          * Callback that passes the contact URI and raw contact ID to edit instead of the
41          * current contact.
42          */
onEditAction(Uri contactLookupUri, long rawContactId)43         void onEditAction(Uri contactLookupUri, long rawContactId);
44     }
45 
46     private Listener mListener;
47     private Suggestion mSuggestion;
48 
AggregationSuggestionView(Context context)49     public AggregationSuggestionView(Context context) {
50         super(context);
51     }
52 
AggregationSuggestionView(Context context, AttributeSet attrs)53     public AggregationSuggestionView(Context context, AttributeSet attrs) {
54         super(context, attrs);
55     }
56 
AggregationSuggestionView(Context context, AttributeSet attrs, int defStyle)57     public AggregationSuggestionView(Context context, AttributeSet attrs, int defStyle) {
58         super(context, attrs, defStyle);
59     }
60 
bindSuggestion(Suggestion suggestion)61     public void bindSuggestion(Suggestion suggestion) {
62         mSuggestion = suggestion;
63         final ContactPhotoManager.DefaultImageRequest
64                 request = new ContactPhotoManager.DefaultImageRequest(
65                 suggestion.name, String.valueOf(suggestion.rawContactId), /* isCircular = */ false);
66         final ImageView photoView = (ImageView) findViewById(
67                 R.id.aggregation_suggestion_photo);
68         ContactPhotoManager.getInstance(getContext()).loadThumbnail(photoView,
69                 suggestion.photoId,
70                 /* darkTheme = */ false,
71                 /* isCircular = */ false,
72                 request);
73 
74         final TextView name = (TextView) findViewById(R.id.aggregation_suggestion_name);
75         name.setText(suggestion.name);
76 
77         final TextView data = (TextView) findViewById(R.id.aggregation_suggestion_data);
78         String dataText = null;
79         if (suggestion.nickname != null) {
80             dataText = suggestion.nickname;
81         } else if (suggestion.emailAddress != null) {
82             dataText = suggestion.emailAddress;
83         } else if (suggestion.phoneNumber != null) {
84             dataText = suggestion.phoneNumber;
85             // Phone numbers should always be in LTR mode.
86             data.setTextDirection(View.TEXT_DIRECTION_LTR);
87         }
88         data.setText(dataText);
89     }
90 
setListener(Listener listener)91     public void setListener(Listener listener) {
92         mListener = listener;
93     }
94 
handleItemClickEvent()95     public boolean handleItemClickEvent() {
96         if (mListener != null && isEnabled()) {
97             if (TextUtils.isEmpty(mSuggestion.contactLookupKey)) {
98                 return false;
99             }
100             mListener.onEditAction(
101                     Contacts.getLookupUri(mSuggestion.contactId, mSuggestion.contactLookupKey),
102                     mSuggestion.rawContactId);
103             return true;
104         }
105         return false;
106     }
107 }
108