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 30 /** Displays the contact's picture overlaid with their name and number type in a tile. */ 31 public class PhoneFavoriteSquareTileView extends PhoneFavoriteTileView { 32 33 private static final String TAG = PhoneFavoriteSquareTileView.class.getSimpleName(); 34 35 private final float mHeightToWidthRatio; 36 37 private ImageButton mSecondaryButton; 38 39 private ContactEntry mContactEntry; 40 PhoneFavoriteSquareTileView(Context context, AttributeSet attrs)41 public PhoneFavoriteSquareTileView(Context context, AttributeSet attrs) { 42 super(context, attrs); 43 44 mHeightToWidthRatio = 45 getResources().getFraction(R.dimen.contact_tile_height_to_width_ratio, 1, 1); 46 } 47 48 @Override onFinishInflate()49 protected void onFinishInflate() { 50 super.onFinishInflate(); 51 final TextView nameView = (TextView) findViewById(R.id.contact_tile_name); 52 nameView.setElegantTextHeight(false); 53 final TextView phoneTypeView = (TextView) findViewById(R.id.contact_tile_phone_type); 54 phoneTypeView.setElegantTextHeight(false); 55 mSecondaryButton = (ImageButton) findViewById(R.id.contact_tile_secondary_button); 56 } 57 58 @Override getApproximateImageSize()59 protected int getApproximateImageSize() { 60 // The picture is the full size of the tile (minus some padding, but we can be generous) 61 return getWidth(); 62 } 63 launchQuickContact()64 private void launchQuickContact() { 65 if (CompatUtils.hasPrioritizedMimeType()) { 66 QuickContact.showQuickContact( 67 getContext(), 68 PhoneFavoriteSquareTileView.this, 69 getLookupUri(), 70 null, 71 Phone.CONTENT_ITEM_TYPE); 72 } else { 73 QuickContact.showQuickContact( 74 getContext(), 75 PhoneFavoriteSquareTileView.this, 76 getLookupUri(), 77 QuickContact.MODE_LARGE, 78 null); 79 } 80 } 81 82 @Override loadFromContact(ContactEntry entry)83 public void loadFromContact(ContactEntry entry) { 84 super.loadFromContact(entry); 85 if (entry != null) { 86 mSecondaryButton.setOnClickListener( 87 new OnClickListener() { 88 @Override 89 public void onClick(View v) { 90 launchQuickContact(); 91 } 92 }); 93 } 94 mContactEntry = entry; 95 } 96 97 @Override onMeasure(int widthMeasureSpec, int heightMeasureSpec)98 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 99 final int width = MeasureSpec.getSize(widthMeasureSpec); 100 final int height = (int) (mHeightToWidthRatio * width); 101 final int count = getChildCount(); 102 for (int i = 0; i < count; i++) { 103 getChildAt(i) 104 .measure( 105 MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), 106 MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)); 107 } 108 setMeasuredDimension(width, height); 109 } 110 111 @Override getNameForView(ContactEntry contactEntry)112 protected String getNameForView(ContactEntry contactEntry) { 113 return contactEntry.getPreferredDisplayName(); 114 } 115 getContactEntry()116 public ContactEntry getContactEntry() { 117 return mContactEntry; 118 } 119 } 120