blob: 42db014035e1e245a81a031bc4c7101f5481045c [file] [log] [blame]
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -07001/*
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
Dmitri Plotnikov18ffaa22010-12-03 14:28:00 -080017package com.android.contacts.editor;
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070018
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070019import android.content.Context;
Dmitri Plotnikovc0130cc2010-10-18 19:14:54 -070020import android.net.Uri;
21import android.provider.ContactsContract.Contacts;
Jay Shraunere320c0b2015-03-05 12:45:18 -080022import android.text.TextUtils;
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070023import android.util.AttributeSet;
Gary Mai6773ea12016-07-20 15:24:00 -070024import android.view.View;
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070025import android.widget.ImageView;
Daisuke Miyakawa6c8c0772011-08-08 11:16:40 -070026import android.widget.LinearLayout;
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070027import android.widget.TextView;
28
Chiao Chenge0b2f1e2012-06-12 13:07:56 -070029import com.android.contacts.R;
Yorke Leef6774502014-02-20 10:21:26 -080030import com.android.contacts.common.ContactPhotoManager;
Gary Mai678108e2016-10-26 14:34:33 -070031import com.android.contacts.editor.AggregationSuggestionEngine.Suggestion;
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070032
33/**
34 * A view that contains a name, picture and other data for a contact aggregation suggestion.
35 */
Daisuke Miyakawa6c8c0772011-08-08 11:16:40 -070036public class AggregationSuggestionView extends LinearLayout {
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070037
38 public interface Listener {
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070039 /**
Gary Mai678108e2016-10-26 14:34:33 -070040 * Callback that passes the contact URI and raw contact ID to edit instead of the
41 * current contact.
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070042 */
Gary Mai678108e2016-10-26 14:34:33 -070043 void onEditAction(Uri contactLookupUri, long rawContactId);
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070044 }
45
46 private Listener mListener;
Gary Mai678108e2016-10-26 14:34:33 -070047 private Suggestion mSuggestion;
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070048
49 public AggregationSuggestionView(Context context) {
50 super(context);
51 }
52
53 public AggregationSuggestionView(Context context, AttributeSet attrs) {
54 super(context, attrs);
55 }
56
57 public AggregationSuggestionView(Context context, AttributeSet attrs, int defStyle) {
58 super(context, attrs, defStyle);
59 }
60
Dmitri Plotnikov9302ba72010-10-14 18:08:40 -070061 public void bindSuggestion(Suggestion suggestion) {
Gary Mai678108e2016-10-26 14:34:33 -070062 mSuggestion = suggestion;
63 final ContactPhotoManager.DefaultImageRequest
64 request = new ContactPhotoManager.DefaultImageRequest(
65 suggestion.name, String.valueOf(suggestion.rawContactId), /* isCircular = */ false);
Gary Mai678108e2016-10-26 14:34:33 -070066 final ImageView photoView = (ImageView) findViewById(
67 R.id.aggregation_suggestion_photo);
Gary Mai04926c02016-11-15 17:01:56 -080068 ContactPhotoManager.getInstance(getContext()).loadThumbnail(photoView,
69 suggestion.photoId,
Gary Mai678108e2016-10-26 14:34:33 -070070 /* darkTheme = */ false,
71 /* isCircular = */ false,
72 request);
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070073
Gary Mai04926c02016-11-15 17:01:56 -080074 final TextView name = (TextView) findViewById(R.id.aggregation_suggestion_name);
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070075 name.setText(suggestion.name);
76
Gary Mai04926c02016-11-15 17:01:56 -080077 final TextView data = (TextView) findViewById(R.id.aggregation_suggestion_data);
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070078 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;
Gary Mai6773ea12016-07-20 15:24:00 -070085 // Phone numbers should always be in LTR mode.
86 data.setTextDirection(View.TEXT_DIRECTION_LTR);
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070087 }
88 data.setText(dataText);
Dmitri Plotnikovc0130cc2010-10-18 19:14:54 -070089 }
90
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -070091 public void setListener(Listener listener) {
92 mListener = listener;
93 }
94
Daisuke Miyakawa6c8c0772011-08-08 11:16:40 -070095 public boolean handleItemClickEvent() {
Dmitri Plotnikova9333792011-02-15 14:37:23 -080096 if (mListener != null && isEnabled()) {
Gary Mai678108e2016-10-26 14:34:33 -070097 if (TextUtils.isEmpty(mSuggestion.contactLookupKey)) {
98 return false;
Dmitri Plotnikovc0130cc2010-10-18 19:14:54 -070099 }
Gary Mai678108e2016-10-26 14:34:33 -0700100 mListener.onEditAction(
101 Contacts.getLookupUri(mSuggestion.contactId, mSuggestion.contactLookupKey),
102 mSuggestion.rawContactId);
Dmitri Plotnikovbd0c12c2010-11-01 16:36:04 -0700103 return true;
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -0700104 }
Dmitri Plotnikovbd0c12c2010-11-01 16:36:04 -0700105 return false;
Dmitri Plotnikovf491ae92010-08-16 12:18:53 -0700106 }
107}