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