1 /* 2 3 * Copyright (C) 2011 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package com.android.dialer.list; 18 19 import android.content.Context; 20 import android.provider.ContactsContract.CommonDataKinds.Phone; 21 import android.provider.ContactsContract.QuickContact; 22 import android.util.AttributeSet; 23 import android.view.View; 24 import android.widget.ImageButton; 25 import android.widget.TextView; 26 27 import com.android.contacts.common.compat.CompatUtils; 28 import com.android.contacts.common.list.ContactEntry; 29 import com.android.dialer.R; 30 31 /** 32 * Displays the contact's picture overlaid with their name and number type in a tile. 33 */ 34 public class PhoneFavoriteSquareTileView extends PhoneFavoriteTileView { 35 private static final String TAG = PhoneFavoriteSquareTileView.class.getSimpleName(); 36 37 private final float mHeightToWidthRatio; 38 39 private ImageButton mSecondaryButton; 40 41 private ContactEntry mContactEntry; 42 43 public PhoneFavoriteSquareTileView(Context context, AttributeSet attrs) { 44 super(context, attrs); 45 46 mHeightToWidthRatio = getResources().getFraction( 47 R.dimen.contact_tile_height_to_width_ratio, 1, 1); 48 } 49 50 @Override 51 protected void onFinishInflate() { 52 super.onFinishInflate(); 53 final TextView nameView = (TextView) findViewById(R.id.contact_tile_name); 54 nameView.setElegantTextHeight(false); 55 final TextView phoneTypeView = (TextView) findViewById(R.id.contact_tile_phone_type); 56 phoneTypeView.setElegantTextHeight(false); 57 mSecondaryButton = (ImageButton) findViewById(R.id.contact_tile_secondary_button); 58 } 59 60 @Override 61 protected int getApproximateImageSize() { 62 // The picture is the full size of the tile (minus some padding, but we can be generous) 63 return getWidth(); 64 } 65 66 private void launchQuickContact() { 67 if (CompatUtils.hasPrioritizedMimeType()) { 68 QuickContact.showQuickContact(getContext(), PhoneFavoriteSquareTileView.this, 69 getLookupUri(), null, Phone.CONTENT_ITEM_TYPE); 70 } else { 71 QuickContact.showQuickContact(getContext(), PhoneFavoriteSquareTileView.this, 72 getLookupUri(), QuickContact.MODE_LARGE, null); 73 } 74 } 75 76 @Override 77 public void loadFromContact(ContactEntry entry) { 78 super.loadFromContact(entry); 79 if (entry != null) { 80 mSecondaryButton.setOnClickListener(new OnClickListener() { 81 @Override 82 public void onClick(View v) { 83 launchQuickContact(); 84 } 85 }); 86 } 87 mContactEntry = entry; 88 } 89 90 @Override 91 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 92 final int width = MeasureSpec.getSize(widthMeasureSpec); 93 final int height = (int) (mHeightToWidthRatio * width); 94 final int count = getChildCount(); 95 for (int i = 0; i < count; i++) { 96 getChildAt(i).measure( 97 MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 98 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY) 99 ); 100 } 101 setMeasuredDimension(width, height); 102 } 103 104 @Override 105 protected String getNameForView(ContactEntry contactEntry) { 106 return contactEntry.getPreferredDisplayName(); 107 } 108 109 public ContactEntry getContactEntry() { 110 return mContactEntry; 111 } 112 } 113