Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 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 | |
Dmitri Plotnikov | 18ffaa2 | 2010-12-03 14:28:00 -0800 | [diff] [blame] | 17 | package com.android.contacts.editor; |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 18 | |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Dmitri Plotnikov | c0130cc | 2010-10-18 19:14:54 -0700 | [diff] [blame] | 20 | import android.net.Uri; |
| 21 | import android.provider.ContactsContract.Contacts; |
Jay Shrauner | e320c0b | 2015-03-05 12:45:18 -0800 | [diff] [blame] | 22 | import android.text.TextUtils; |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 23 | import android.util.AttributeSet; |
Gary Mai | 6773ea1 | 2016-07-20 15:24:00 -0700 | [diff] [blame] | 24 | import android.view.View; |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 25 | import android.widget.ImageView; |
Daisuke Miyakawa | 6c8c077 | 2011-08-08 11:16:40 -0700 | [diff] [blame] | 26 | import android.widget.LinearLayout; |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 27 | import android.widget.TextView; |
| 28 | |
Chiao Cheng | e0b2f1e | 2012-06-12 13:07:56 -0700 | [diff] [blame] | 29 | import com.android.contacts.R; |
Yorke Lee | f677450 | 2014-02-20 10:21:26 -0800 | [diff] [blame] | 30 | import com.android.contacts.common.ContactPhotoManager; |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 31 | import com.android.contacts.editor.AggregationSuggestionEngine.Suggestion; |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * A view that contains a name, picture and other data for a contact aggregation suggestion. |
| 35 | */ |
Daisuke Miyakawa | 6c8c077 | 2011-08-08 11:16:40 -0700 | [diff] [blame] | 36 | public class AggregationSuggestionView extends LinearLayout { |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 37 | |
| 38 | public interface Listener { |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 39 | /** |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 40 | * Callback that passes the contact URI and raw contact ID to edit instead of the |
| 41 | * current contact. |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 42 | */ |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 43 | void onEditAction(Uri contactLookupUri, long rawContactId); |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | private Listener mListener; |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 47 | private Suggestion mSuggestion; |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 48 | |
| 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 Plotnikov | 9302ba7 | 2010-10-14 18:08:40 -0700 | [diff] [blame] | 61 | public void bindSuggestion(Suggestion suggestion) { |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 62 | mSuggestion = suggestion; |
| 63 | final ContactPhotoManager.DefaultImageRequest |
| 64 | request = new ContactPhotoManager.DefaultImageRequest( |
| 65 | suggestion.name, String.valueOf(suggestion.rawContactId), /* isCircular = */ false); |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 66 | final ImageView photoView = (ImageView) findViewById( |
| 67 | R.id.aggregation_suggestion_photo); |
Gary Mai | 04926c0 | 2016-11-15 17:01:56 -0800 | [diff] [blame] | 68 | ContactPhotoManager.getInstance(getContext()).loadThumbnail(photoView, |
| 69 | suggestion.photoId, |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 70 | /* darkTheme = */ false, |
| 71 | /* isCircular = */ false, |
| 72 | request); |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 73 | |
Gary Mai | 04926c0 | 2016-11-15 17:01:56 -0800 | [diff] [blame] | 74 | final TextView name = (TextView) findViewById(R.id.aggregation_suggestion_name); |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 75 | name.setText(suggestion.name); |
| 76 | |
Gary Mai | 04926c0 | 2016-11-15 17:01:56 -0800 | [diff] [blame] | 77 | final TextView data = (TextView) findViewById(R.id.aggregation_suggestion_data); |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 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; |
Gary Mai | 6773ea1 | 2016-07-20 15:24:00 -0700 | [diff] [blame] | 85 | // Phone numbers should always be in LTR mode. |
| 86 | data.setTextDirection(View.TEXT_DIRECTION_LTR); |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 87 | } |
| 88 | data.setText(dataText); |
Dmitri Plotnikov | c0130cc | 2010-10-18 19:14:54 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 91 | public void setListener(Listener listener) { |
| 92 | mListener = listener; |
| 93 | } |
| 94 | |
Daisuke Miyakawa | 6c8c077 | 2011-08-08 11:16:40 -0700 | [diff] [blame] | 95 | public boolean handleItemClickEvent() { |
Dmitri Plotnikov | a933379 | 2011-02-15 14:37:23 -0800 | [diff] [blame] | 96 | if (mListener != null && isEnabled()) { |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 97 | if (TextUtils.isEmpty(mSuggestion.contactLookupKey)) { |
| 98 | return false; |
Dmitri Plotnikov | c0130cc | 2010-10-18 19:14:54 -0700 | [diff] [blame] | 99 | } |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 100 | mListener.onEditAction( |
| 101 | Contacts.getLookupUri(mSuggestion.contactId, mSuggestion.contactLookupKey), |
| 102 | mSuggestion.rawContactId); |
Dmitri Plotnikov | bd0c12c | 2010-11-01 16:36:04 -0700 | [diff] [blame] | 103 | return true; |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 104 | } |
Dmitri Plotnikov | bd0c12c | 2010-11-01 16:36:04 -0700 | [diff] [blame] | 105 | return false; |
Dmitri Plotnikov | f491ae9 | 2010-08-16 12:18:53 -0700 | [diff] [blame] | 106 | } |
| 107 | } |