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.app.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 import com.android.contacts.common.list.ContactEntry; 27 import com.android.dialer.app.R; 28 import com.android.dialer.compat.CompatUtils; 29 import com.android.dialer.logging.InteractionEvent; 30 import com.android.dialer.logging.Logger; 31 32 /** Displays the contact's picture overlaid with their name and number type in a tile. */ 33 public class PhoneFavoriteSquareTileView extends PhoneFavoriteTileView { 34 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 = 47 getResources().getFraction(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( 69 getContext(), 70 PhoneFavoriteSquareTileView.this, 71 getLookupUri(), 72 null, 73 Phone.CONTENT_ITEM_TYPE); 74 } else { 75 QuickContact.showQuickContact( 76 getContext(), 77 PhoneFavoriteSquareTileView.this, 78 getLookupUri(), 79 QuickContact.MODE_LARGE, 80 null); 81 } 82 } 83 84 @Override 85 public void loadFromContact(ContactEntry entry) { 86 super.loadFromContact(entry); 87 if (entry != null) { 88 mSecondaryButton.setOnClickListener( 89 new OnClickListener() { 90 @Override 91 public void onClick(View v) { 92 Logger.get(getContext()) 93 .logInteraction(InteractionEvent.Type.SPEED_DIAL_OPEN_CONTACT_CARD); 94 launchQuickContact(); 95 } 96 }); 97 } 98 mContactEntry = entry; 99 } 100 101 @Override 102 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 103 final int width = MeasureSpec.getSize(widthMeasureSpec); 104 final int height = (int) (mHeightToWidthRatio * width); 105 final int count = getChildCount(); 106 for (int i = 0; i < count; i++) { 107 getChildAt(i) 108 .measure( 109 MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 110 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); 111 } 112 setMeasuredDimension(width, height); 113 } 114 115 @Override 116 protected String getNameForView(ContactEntry contactEntry) { 117 return contactEntry.getPreferredDisplayName(); 118 } 119 120 public ContactEntry getContactEntry() { 121 return mContactEntry; 122 } 123 } 124