194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng/* 294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Copyright (C) 2011 The Android Open Source Project 394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Licensed under the Apache License, Version 2.0 (the "License"); 594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * you may not use this file except in compliance with the License. 694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * You may obtain a copy of the License at 794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * http://www.apache.org/licenses/LICENSE-2.0 994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * 1094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Unless required by applicable law or agreed to in writing, software 1194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * distributed under the License is distributed on an "AS IS" BASIS, 1294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * See the License for the specific language governing permissions and 1494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * limitations under the License. 1594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 1694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 1794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengpackage com.android.dialer.calllog; 1894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 1994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.content.ContentUris; 2094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.content.Context; 2194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.content.Intent; 2294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.net.Uri; 2394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengimport android.provider.CallLog.Calls; 249dc924c8bcc0bc8d996452e9ce3215b5f064962eTyler Gunnimport android.telecom.PhoneAccountHandle; 2594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 269d4f3b20793a007b4489547aa40fc1049d0d8fefChiao Chengimport com.android.contacts.common.CallUtil; 2791197049c458f07092b31501d2ed512180b13d58Chiao Chengimport com.android.dialer.CallDetailActivity; 2894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 2994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng/** 3094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * Used to create an intent to attach to an action in the call log. 3194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * <p> 3294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng * The intent is constructed lazily with the given information. 3394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng */ 3494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Chengpublic abstract class IntentProvider { 35643e78532e5d40ca62e6545855f847e26eaffa4eChiao Cheng 36643e78532e5d40ca62e6545855f847e26eaffa4eChiao Cheng private static final String TAG = IntentProvider.class.getSimpleName(); 37643e78532e5d40ca62e6545855f847e26eaffa4eChiao Cheng 3894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public abstract Intent getIntent(Context context); 3994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 408f7c4368817a17727b2132d399d0895e33f67a95Nancy Chen public static IntentProvider getReturnCallIntentProvider(final String number) { 418f7c4368817a17727b2132d399d0895e33f67a95Nancy Chen return getReturnCallIntentProvider(number, null); 428f7c4368817a17727b2132d399d0895e33f67a95Nancy Chen } 438f7c4368817a17727b2132d399d0895e33f67a95Nancy Chen 4487ba489564b25d4a64c9faaeafea46e2f72d8933Nancy Chen public static IntentProvider getReturnCallIntentProvider(final String number, 45a2eadf3d68d4f6d0a948d37bc48e930115723ce0Evan Charlton final PhoneAccountHandle accountHandle) { 4694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return new IntentProvider() { 4794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 4894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public Intent getIntent(Context context) { 49a2eadf3d68d4f6d0a948d37bc48e930115723ce0Evan Charlton return CallUtil.getCallIntent(number, accountHandle); 5094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 5194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }; 5294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 5394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 548f7c4368817a17727b2132d399d0895e33f67a95Nancy Chen public static IntentProvider getReturnVideoCallIntentProvider(final String number) { 558f7c4368817a17727b2132d399d0895e33f67a95Nancy Chen return getReturnVideoCallIntentProvider(number, null); 568f7c4368817a17727b2132d399d0895e33f67a95Nancy Chen } 578f7c4368817a17727b2132d399d0895e33f67a95Nancy Chen 585619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn public static IntentProvider getReturnVideoCallIntentProvider(final String number, 59a2eadf3d68d4f6d0a948d37bc48e930115723ce0Evan Charlton final PhoneAccountHandle accountHandle) { 605619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn return new IntentProvider() { 615619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn @Override 625619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn public Intent getIntent(Context context) { 63a2eadf3d68d4f6d0a948d37bc48e930115723ce0Evan Charlton return CallUtil.getVideoCallIntent(number, accountHandle); 645619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn } 655619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn }; 665619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn } 675619f2ed87cb207352c0ff5578348baeb69ee202Tyler Gunn 6894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public static IntentProvider getPlayVoicemailIntentProvider(final long rowId, 6994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng final String voicemailUri) { 7094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return new IntentProvider() { 7194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 7294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public Intent getIntent(Context context) { 7394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Intent intent = new Intent(context, CallDetailActivity.class); 7494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.setData(ContentUris.withAppendedId( 7594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Calls.CONTENT_URI_WITH_VOICEMAIL, rowId)); 7694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (voicemailUri != null) { 7794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI, 7894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Uri.parse(voicemailUri)); 7994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 8094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_START_PLAYBACK, true); 8194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return intent; 8294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 8394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }; 8494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 8594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 86cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn /** 87cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn * Retrieves the call details intent provider for an entry in the call log. 88cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn * 89cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn * @param id The call ID of the first call in the call group. 90cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn * @param extraIds The call ID of the other calls grouped together with the call. 91cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn * @param voicemailUri If call log entry is for a voicemail, the voicemail URI. 92cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn * @return The call details intent provider. 93cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn */ 9494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public static IntentProvider getCallDetailIntentProvider( 95cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn final long id, final long[] extraIds, final String voicemailUri) { 9694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return new IntentProvider() { 9794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng @Override 9894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng public Intent getIntent(Context context) { 9994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Intent intent = new Intent(context, CallDetailActivity.class); 10094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // Check if the first item is a voicemail. 10194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng if (voicemailUri != null) { 10294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI, 10394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Uri.parse(voicemailUri)); 10494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 10594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_START_PLAYBACK, false); 10694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng 107cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn if (extraIds != null && extraIds.length > 0) { 108cf5e001120916deb770ea65ae55730e456f92137Tyler Gunn intent.putExtra(CallDetailActivity.EXTRA_CALL_LOG_IDS, extraIds); 10994b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } else { 11094b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng // If there is a single item, use the direct URI for it. 11194b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng intent.setData(ContentUris.withAppendedId( 11294b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng Calls.CONTENT_URI_WITH_VOICEMAIL, id)); 11394b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 11494b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng return intent; 11594b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 11694b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng }; 11794b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng } 11894b10b530c0fc297e2974e57e094c500d3ee6003Chiao Cheng} 119