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 */ 16 17 package com.android.dialer.calllog; 18 19 import android.content.res.Resources; 20 import android.provider.CallLog.Calls; 21 import android.text.TextUtils; 22 import android.view.View; 23 24 import com.android.dialer.PhoneCallDetails; 25 import com.android.dialer.PhoneCallDetailsHelper; 26 import com.android.dialer.R; 27 28 /** 29 * Helper class to fill in the views of a call log entry. 30 */ 31 /* package */class CallLogListItemHelper { 32 /** Helper for populating the details of a phone call. */ 33 private final PhoneCallDetailsHelper mPhoneCallDetailsHelper; 34 /** Helper for handling phone numbers. */ 35 private final PhoneNumberHelper mPhoneNumberHelper; 36 /** Resources to look up strings. */ 37 private final Resources mResources; 38 39 /** 40 * Creates a new helper instance. 41 * 42 * @param phoneCallDetailsHelper used to set the details of a phone call 43 * @param phoneNumberHelper used to process phone number 44 */ 45 public CallLogListItemHelper(PhoneCallDetailsHelper phoneCallDetailsHelper, 46 PhoneNumberHelper phoneNumberHelper, Resources resources) { 47 mPhoneCallDetailsHelper = phoneCallDetailsHelper; 48 mPhoneNumberHelper = phoneNumberHelper; 49 mResources = resources; 50 } 51 52 /** 53 * Sets the name, label, and number for a contact. 54 * 55 * @param views the views to populate 56 * @param details the details of a phone call needed to fill in the data 57 * @param isHighlighted whether to use the highlight text for the call 58 */ 59 public void setPhoneCallDetails(CallLogListItemViews views, PhoneCallDetails details, 60 boolean isHighlighted, boolean useCallAsPrimaryAction) { 61 mPhoneCallDetailsHelper.setPhoneCallDetails(views.phoneCallDetailsViews, details, 62 isHighlighted); 63 boolean canCall = PhoneNumberUtilsWrapper.canPlaceCallsTo(details.number, 64 details.numberPresentation); 65 boolean canPlay = details.callTypes[0] == Calls.VOICEMAIL_TYPE; 66 67 if (canPlay) { 68 // Playback action takes preference. 69 configurePlaySecondaryAction(views, isHighlighted); 70 } else if (canCall && !useCallAsPrimaryAction) { 71 // Call is the secondary action. 72 configureCallSecondaryAction(views, details); 73 } else { 74 // No action available. 75 views.secondaryActionView.setVisibility(View.GONE); 76 } 77 } 78 79 /** Sets the secondary action to correspond to the call button. */ 80 private void configureCallSecondaryAction(CallLogListItemViews views, 81 PhoneCallDetails details) { 82 views.secondaryActionView.setVisibility(View.VISIBLE); 83 views.secondaryActionView.setImageResource(R.drawable.ic_phone_dk); 84 views.secondaryActionView.setContentDescription(getCallActionDescription(details)); 85 } 86 87 /** Returns the description used by the call action for this phone call. */ 88 private CharSequence getCallActionDescription(PhoneCallDetails details) { 89 final CharSequence recipient; 90 if (!TextUtils.isEmpty(details.name)) { 91 recipient = details.name; 92 } else { 93 recipient = mPhoneNumberHelper.getDisplayNumber( 94 details.number, details.numberPresentation, details.formattedNumber); 95 } 96 return mResources.getString(R.string.description_call, recipient); 97 } 98 99 /** Sets the secondary action to correspond to the play button. */ 100 private void configurePlaySecondaryAction(CallLogListItemViews views, boolean isHighlighted) { 101 views.secondaryActionView.setVisibility(View.VISIBLE); 102 views.secondaryActionView.setImageResource( 103 isHighlighted ? R.drawable.ic_play_active_holo_dark : R.drawable.ic_play_holo_light); 104 views.secondaryActionView.setContentDescription( 105 mResources.getString(R.string.description_call_log_play_button)); 106 } 107 } 108