Chiao Cheng | 0a73660 | 2012-12-05 12:06:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | */ |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 16 | package com.android.contacts.list; |
Chiao Cheng | 0a73660 | 2012-12-05 12:06:58 -0800 | [diff] [blame] | 17 | |
| 18 | import android.content.Context; |
| 19 | import android.text.TextUtils; |
| 20 | import android.util.AttributeSet; |
| 21 | import android.view.View; |
| 22 | |
Gary Mai | 0a49afa | 2016-12-05 15:53:58 -0800 | [diff] [blame] | 23 | import com.android.contacts.MoreContactUtils; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 24 | import com.android.contacts.util.ViewUtil; |
Chiao Cheng | 0a73660 | 2012-12-05 12:06:58 -0800 | [diff] [blame] | 25 | |
| 26 | /** |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 27 | * A dark version of the {@link com.android.contacts.list.ContactTileView} that is used in Dialtacts |
Chiao Cheng | 0a73660 | 2012-12-05 12:06:58 -0800 | [diff] [blame] | 28 | * for frequently called contacts. Slightly different behavior from superclass... |
| 29 | * when you tap it, you want to call the frequently-called number for the |
| 30 | * contact, even if that is not the default number for that contact. |
| 31 | */ |
| 32 | public class ContactTilePhoneFrequentView extends ContactTileView { |
| 33 | private String mPhoneNumberString; |
| 34 | |
| 35 | public ContactTilePhoneFrequentView(Context context, AttributeSet attrs) { |
| 36 | super(context, attrs); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | protected boolean isDarkTheme() { |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | protected int getApproximateImageSize() { |
| 46 | return ViewUtil.getConstantPreLayoutWidth(getQuickContact()); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public void loadFromContact(ContactEntry entry) { |
| 51 | super.loadFromContact(entry); |
| 52 | mPhoneNumberString = null; // ... in case we're reusing the view |
| 53 | if (entry != null) { |
| 54 | // Grab the phone-number to call directly... see {@link onClick()} |
| 55 | mPhoneNumberString = entry.phoneNumber; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | protected OnClickListener createClickListener() { |
| 61 | return new OnClickListener() { |
| 62 | @Override |
| 63 | public void onClick(View v) { |
| 64 | if (mListener == null) return; |
| 65 | if (TextUtils.isEmpty(mPhoneNumberString)) { |
| 66 | // Copy "superclass" implementation |
| 67 | mListener.onContactSelected(getLookupUri(), MoreContactUtils |
Yorke Lee | 22426f9 | 2013-10-24 13:53:24 -0700 | [diff] [blame] | 68 | .getTargetRectFromView(ContactTilePhoneFrequentView.this)); |
Chiao Cheng | 0a73660 | 2012-12-05 12:06:58 -0800 | [diff] [blame] | 69 | } else { |
| 70 | // When you tap a frequently-called contact, you want to |
| 71 | // call them at the number that you usually talk to them |
| 72 | // at (i.e. the one displayed in the UI), regardless of |
| 73 | // whether that's their default number. |
| 74 | mListener.onCallNumberDirectly(mPhoneNumberString); |
| 75 | } |
| 76 | } |
| 77 | }; |
| 78 | } |
| 79 | } |