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 */ 16 package com.android.contacts.common.list; 17 18 import android.content.Context; 19 import android.text.TextUtils; 20 import android.util.AttributeSet; 21 import android.view.View; 22 23 import com.android.contacts.common.MoreContactUtils; 24 import com.android.contacts.common.util.ViewUtil; 25 26 /** 27 * A dark version of the {@link com.android.contacts.common.list.ContactTileView} that is used in Dialtacts 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 ContactTilePhoneFrequentView(Context context, AttributeSet attrs)35 public ContactTilePhoneFrequentView(Context context, AttributeSet attrs) { 36 super(context, attrs); 37 } 38 39 @Override isDarkTheme()40 protected boolean isDarkTheme() { 41 return true; 42 } 43 44 @Override getApproximateImageSize()45 protected int getApproximateImageSize() { 46 return ViewUtil.getConstantPreLayoutWidth(getQuickContact()); 47 } 48 49 @Override loadFromContact(ContactEntry entry)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 createClickListener()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 68 .getTargetRectFromView(ContactTilePhoneFrequentView.this)); 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 } 80