blob: 713a667ea8b415618cb8a6c6ce6b8a5cf0b35268 [file] [log] [blame]
Flavio Lerdaa024c3f2011-06-10 10:47:07 +01001/*
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 */
16
17package com.android.contacts;
18
19import com.android.contacts.format.FormatUtils;
20
21import android.content.res.Resources;
22import android.graphics.Typeface;
23import android.provider.CallLog.Calls;
24import android.provider.ContactsContract.CommonDataKinds.Phone;
25import android.telephony.PhoneNumberUtils;
26import android.text.Spanned;
27import android.text.TextUtils;
28import android.text.format.DateUtils;
29import android.view.View;
30import android.widget.TextView;
31
32/**
33 * Encapsulates the views that are used to display the details of a phone call in the call log.
34 */
35public final class PhoneCallDetailsViews {
36 public final TextView mNameView;
37 public final TextView mCallTypeAndDateView;
38 public final TextView mNumberView;
39
40 /**
41 * Creates a new instance and caches its views.
42 *
43 * @param view the view which contains the elements to fill
44 */
45 public PhoneCallDetailsViews(View view) {
46 mNameView = (TextView) view.findViewById(R.id.name);
47 mCallTypeAndDateView = (TextView) view.findViewById(R.id.call_type);
48 mNumberView = (TextView) view.findViewById(R.id.number);
49 }
50
51 /**
52 * Fills the call details views with content.
53 *
54 * @param resources used to look up strings
55 * @param date the date of the call, in milliseconds since the epoch
56 * @param callType the type of call, as defined in the call log table
57 * @param name the name of the contact, if available
58 * @param number the number of the other party involved in the call
59 * @param numberType the type of phone, e.g., {@link Phone#TYPE_HOME}, 0 if not available
60 * @param numberLabel the custom label associated with the phone number in the contact
61 */
62 public void setPhoneCallDetails(Resources resources, long date, int callType,
63 CharSequence name, CharSequence number, int numberType, CharSequence numberLabel) {
64 CharSequence callTypeText = "";
65 switch (callType) {
66 case Calls.INCOMING_TYPE:
67 callTypeText = resources.getString(R.string.type_incoming);
68 break;
69
70 case Calls.OUTGOING_TYPE:
71 callTypeText = resources.getString(R.string.type_outgoing);
72 break;
73
74 case Calls.MISSED_TYPE:
75 callTypeText = resources.getString(R.string.type_missed);
76 break;
77 }
78
79 CharSequence shortDateText =
80 DateUtils.getRelativeTimeSpanString(date,
81 System.currentTimeMillis(),
82 DateUtils.MINUTE_IN_MILLIS,
83 DateUtils.FORMAT_ABBREV_RELATIVE);
84
85 CharSequence callTypeAndDateText = FormatUtils.applyStyleToSpan(Typeface.BOLD,
86 callTypeText + " " + shortDateText, 0, callTypeText.length(),
87 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
88
89 CharSequence numberFormattedLabel = null;
90 // Only show a label if the number is shown and it is not a SIP address.
91 if (!TextUtils.isEmpty(number) && !PhoneNumberUtils.isUriNumber(number.toString())) {
92 numberFormattedLabel = Phone.getTypeLabel(resources, numberType, numberLabel);
93 }
94
95 CharSequence nameText;
96 CharSequence numberText;
97 if (TextUtils.isEmpty(name)) {
98 nameText = number;
99 numberText = "";
100 } else {
101 nameText = name;
102 numberText = number;
103 if (callType != 0 && numberFormattedLabel != null) {
104 numberText = FormatUtils.applyStyleToSpan(Typeface.BOLD,
105 numberFormattedLabel + " " + number, 0,
106 numberFormattedLabel.length(),
107 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
108 }
109 }
110
111 mCallTypeAndDateView.setText(callTypeAndDateText);
112 mCallTypeAndDateView.setVisibility(View.VISIBLE);
113 mNameView.setText(nameText);
114 mNameView.setVisibility(View.VISIBLE);
115 // Do not show the number if it is not available. This happens if we have only the number,
116 // in which case the number is shown in the name field instead.
117 if (!TextUtils.isEmpty(numberText)) {
118 mNumberView.setText(numberText);
119 mNumberView.setVisibility(View.VISIBLE);
120 } else {
121 mNumberView.setVisibility(View.GONE);
122 }
123 }
124}