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.QuickContact;
21 import android.util.AttributeSet;
22 import android.view.View;
23 import android.widget.ImageButton;
24 import android.widget.TextView;
25 
26 import com.android.contacts.common.list.ContactEntry;
27 import com.android.dialer.R;
28 
29 /**
30  * Displays the contact's picture overlaid with their name and number type in a tile.
31  */
32 public class PhoneFavoriteSquareTileView extends PhoneFavoriteTileView {
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 = getResources().getFraction(
45                 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         QuickContact.showQuickContact(getContext(), PhoneFavoriteSquareTileView.this,
66                 getLookupUri(), QuickContact.MODE_LARGE, null);
67     }
68 
69     @Override
loadFromContact(ContactEntry entry)70     public void loadFromContact(ContactEntry entry) {
71         super.loadFromContact(entry);
72         if (entry != null) {
73             mSecondaryButton.setOnClickListener(new OnClickListener() {
74                 @Override
75                 public void onClick(View v) {
76                     launchQuickContact();
77                 }
78             });
79         }
80         mContactEntry = entry;
81     }
82 
83     @Override
onMeasure(int widthMeasureSpec, int heightMeasureSpec)84     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
85         final int width = MeasureSpec.getSize(widthMeasureSpec);
86         final int height = (int) (mHeightToWidthRatio * width);
87         final int count = getChildCount();
88         for (int i = 0; i < count; i++) {
89             getChildAt(i).measure(
90                     MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY),
91                     MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY)
92                     );
93         }
94         setMeasuredDimension(width, height);
95     }
96 
getContactEntry()97     public ContactEntry getContactEntry() {
98         return mContactEntry;
99     }
100 }
101