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 17package com.android.dialer.calllog; 18 19import android.content.ContentUris; 20import android.content.Context; 21import android.content.Intent; 22import android.net.Uri; 23import android.provider.CallLog.Calls; 24import android.telecom.PhoneAccountHandle; 25 26import com.android.contacts.common.CallUtil; 27import com.android.dialer.CallDetailActivity; 28 29/** 30 * Used to create an intent to attach to an action in the call log. 31 * <p> 32 * The intent is constructed lazily with the given information. 33 */ 34public abstract class IntentProvider { 35 36 private static final String TAG = IntentProvider.class.getSimpleName(); 37 38 public abstract Intent getIntent(Context context); 39 40 public static IntentProvider getReturnCallIntentProvider(final String number) { 41 return getReturnCallIntentProvider(number, null); 42 } 43 44 public static IntentProvider getReturnCallIntentProvider(final String number, 45 final PhoneAccountHandle accountHandle) { 46 return new IntentProvider() { 47 @Override 48 public Intent getIntent(Context context) { 49 return CallUtil.getCallIntent(number, accountHandle); 50 } 51 }; 52 } 53 54 public static IntentProvider getReturnVideoCallIntentProvider(final String number) { 55 return getReturnVideoCallIntentProvider(number, null); 56 } 57 58 public static IntentProvider getReturnVideoCallIntentProvider(final String number, 59 final PhoneAccountHandle accountHandle) { 60 return new IntentProvider() { 61 @Override 62 public Intent getIntent(Context context) { 63 return CallUtil.getVideoCallIntent(number, accountHandle); 64 } 65 }; 66 } 67 68 public static IntentProvider getPlayVoicemailIntentProvider(final long rowId, 69 final String voicemailUri) { 70 return new IntentProvider() { 71 @Override 72 public Intent getIntent(Context context) { 73 Intent intent = new Intent(context, CallDetailActivity.class); 74 intent.setData(ContentUris.withAppendedId( 75 Calls.CONTENT_URI_WITH_VOICEMAIL, rowId)); 76 if (voicemailUri != null) { 77 intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI, 78 Uri.parse(voicemailUri)); 79 } 80 intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_START_PLAYBACK, true); 81 return intent; 82 } 83 }; 84 } 85 86 /** 87 * Retrieves the call details intent provider for an entry in the call log. 88 * 89 * @param id The call ID of the first call in the call group. 90 * @param extraIds The call ID of the other calls grouped together with the call. 91 * @param voicemailUri If call log entry is for a voicemail, the voicemail URI. 92 * @return The call details intent provider. 93 */ 94 public static IntentProvider getCallDetailIntentProvider( 95 final long id, final long[] extraIds, final String voicemailUri) { 96 return new IntentProvider() { 97 @Override 98 public Intent getIntent(Context context) { 99 Intent intent = new Intent(context, CallDetailActivity.class); 100 // Check if the first item is a voicemail. 101 if (voicemailUri != null) { 102 intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI, 103 Uri.parse(voicemailUri)); 104 } 105 intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_START_PLAYBACK, false); 106 107 if (extraIds != null && extraIds.length > 0) { 108 intent.putExtra(CallDetailActivity.EXTRA_CALL_LOG_IDS, extraIds); 109 } else { 110 // If there is a single item, use the direct URI for it. 111 intent.setData(ContentUris.withAppendedId( 112 Calls.CONTENT_URI_WITH_VOICEMAIL, id)); 113 } 114 return intent; 115 } 116 }; 117 } 118} 119