ContactTilePhoneFrequentView.java revision d0c8da65af3b67ba551a220ca40be31f644dfed6
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.contacts.common.list;
17
18import android.content.Context;
19import android.text.TextUtils;
20import android.util.AttributeSet;
21import android.view.View;
22
23import com.android.contacts.common.MoreContactUtils;
24import com.android.contacts.common.list.ContactTileAdapter.ContactEntry;
25import com.android.contacts.common.util.ViewUtil;
26
27/**
28 * A dark version of the {@link com.android.contacts.common.list.ContactTileView} that is used in Dialtacts
29 * for frequently called contacts. Slightly different behavior from superclass...
30 * when you tap it, you want to call the frequently-called number for the
31 * contact, even if that is not the default number for that contact.
32 */
33public class ContactTilePhoneFrequentView extends ContactTileView {
34    private String mPhoneNumberString;
35
36    public ContactTilePhoneFrequentView(Context context, AttributeSet attrs) {
37        super(context, attrs);
38    }
39
40    @Override
41    protected boolean isDarkTheme() {
42        return true;
43    }
44
45    @Override
46    protected int getApproximateImageSize() {
47        return ViewUtil.getConstantPreLayoutWidth(getQuickContact());
48    }
49
50    @Override
51    public void loadFromContact(ContactEntry entry) {
52        super.loadFromContact(entry);
53        mPhoneNumberString = null; // ... in case we're reusing the view
54        if (entry != null) {
55            // Grab the phone-number to call directly... see {@link onClick()}
56            mPhoneNumberString = entry.phoneNumber;
57        }
58    }
59
60    @Override
61    protected OnClickListener createClickListener() {
62        return new OnClickListener() {
63            @Override
64            public void onClick(View v) {
65                if (mListener == null) return;
66                if (TextUtils.isEmpty(mPhoneNumberString)) {
67                    // Copy "superclass" implementation
68                    mListener.onContactSelected(getLookupUri(), MoreContactUtils
69                            .getTargetRectFromView(
70                                    mContext, ContactTilePhoneFrequentView.this));
71                } else {
72                    // When you tap a frequently-called contact, you want to
73                    // call them at the number that you usually talk to them
74                    // at (i.e. the one displayed in the UI), regardless of
75                    // whether that's their default number.
76                    mListener.onCallNumberDirectly(mPhoneNumberString);
77                }
78            }
79        };
80    }
81}
82