From 247df6ee4f43af916f7e7f339ed181a18807ef36 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Tue, 12 May 2015 19:09:00 -0700 Subject: Reorganize Intent utilities, add send SMS intent. + Rename CallIntentUtils.java to IntentUtil.java. + Consolidate various intent creation methods to new file, and update referenes throughout the application. Bug: 20433758 Change-Id: Iee9e37985217c38c816124d0e74dff40a2871680 --- src/com/android/dialer/CallDetailActivity.java | 7 +- src/com/android/dialer/DialtactsActivity.java | 49 ++--- .../dialer/calllog/CallLogListItemViewHolder.java | 18 +- src/com/android/dialer/calllog/IntentProvider.java | 32 ++-- .../android/dialer/dialpad/DialpadFragment.java | 9 +- .../interactions/PhoneNumberInteraction.java | 4 +- src/com/android/dialer/list/SearchFragment.java | 18 +- src/com/android/dialer/util/CallIntentUtil.java | 144 --------------- src/com/android/dialer/util/DialerUtils.java | 2 +- src/com/android/dialer/util/IntentUtil.java | 201 +++++++++++++++++++++ 10 files changed, 253 insertions(+), 231 deletions(-) delete mode 100644 src/com/android/dialer/util/CallIntentUtil.java create mode 100644 src/com/android/dialer/util/IntentUtil.java (limited to 'src') diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 0a295c4fe..735d6eb56 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -64,7 +64,7 @@ import com.android.dialer.calllog.PhoneNumberDisplayHelper; import com.android.dialer.calllog.PhoneNumberUtilsWrapper; import com.android.dialer.util.AsyncTaskExecutor; import com.android.dialer.util.AsyncTaskExecutors; -import com.android.dialer.util.CallIntentUtil; +import com.android.dialer.util.IntentUtil; import com.android.dialer.util.DialerUtils; import com.android.dialer.util.TelecomUtil; import com.android.dialer.voicemail.VoicemailPlaybackFragment; @@ -323,8 +323,9 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware getSystemService(Context.TELEPHONY_SERVICE); if (tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) { DialerUtils.startActivityWithErrorToast(this, - CallIntentUtil.getCallIntent(Uri.fromParts(PhoneAccount.SCHEME_TEL, - mNumber, null)), R.string.call_not_available); + IntentUtil.getCallIntent( + Uri.fromParts(PhoneAccount.SCHEME_TEL, mNumber, null)), + R.string.call_not_available); return true; } } diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java index cccc06ea0..25828e596 100644 --- a/src/com/android/dialer/DialtactsActivity.java +++ b/src/com/android/dialer/DialtactsActivity.java @@ -29,7 +29,6 @@ import android.content.res.Resources; import android.net.Uri; import android.os.Bundle; import android.os.Trace; -import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.Intents; import android.speech.RecognizerIntent; import android.support.v4.view.ViewPager; @@ -82,7 +81,7 @@ import com.android.dialer.list.SearchFragment; import com.android.dialer.list.SmartDialSearchFragment; import com.android.dialer.list.SpeedDialFragment; import com.android.dialer.settings.DialerSettingsActivity; -import com.android.dialer.util.CallIntentUtil; +import com.android.dialer.util.IntentUtil; import com.android.dialer.util.DialerUtils; import com.android.dialer.widget.ActionBarController; import com.android.dialer.widget.SearchEditTextLayout; @@ -587,7 +586,10 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O switch (view.getId()) { case R.id.floating_action_button: if (mListsFragment.getTabPosition() == ListsFragment.TAB_INDEX_ALL_CONTACTS) { - sendAddNewContactIntent(); + DialerUtils.startActivityWithErrorToast( + this, + IntentUtil.getNewContactIntent(), + R.string.add_contact_not_available); } else if (!mIsDialpadShown) { mInCallDialpadUp = false; showDialpadFragment(true); @@ -622,7 +624,10 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O startActivity(intent); break; case R.id.menu_add_contact: - sendAddNewContactIntent(); + DialerUtils.startActivityWithErrorToast( + this, + IntentUtil.getNewContactIntent(), + R.string.add_contact_not_available); break; case R.id.menu_import_export: // We hard-code the "contactsAreAvailable" argument because doing it properly would @@ -1082,38 +1087,6 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O return getTelecomManager().isInCall(); } - public static Intent getAddNumberToContactIntent(CharSequence text) { - return getAddToContactIntent(null /* name */, text /* phoneNumber */, - -1 /* phoneNumberType */); - } - - public static Intent getAddToContactIntent(CharSequence name, CharSequence phoneNumber, - int phoneNumberType) { - Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); - intent.putExtra(Intents.Insert.PHONE, phoneNumber); - // Only include the name and phone type extras if they are specified (the method - // getAddNumberToContactIntent does not use them). - if (name != null) { - intent.putExtra(Intents.Insert.NAME, name); - } - if (phoneNumberType != -1) { - intent.putExtra(Intents.Insert.PHONE_TYPE, phoneNumberType); - } - intent.setType(Contacts.CONTENT_ITEM_TYPE); - return intent; - } - - private void sendAddNewContactIntent() { - try { - startActivity(new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI)); - } catch (ActivityNotFoundException e) { - Toast toast = Toast.makeText(this, - R.string.add_contact_not_available, - Toast.LENGTH_SHORT); - toast.show(); - } - } - private boolean canIntentBeHandled(Intent intent) { final PackageManager packageManager = getPackageManager(); final List resolveInfo = packageManager.queryIntentActivities(intent, @@ -1171,8 +1144,8 @@ public class DialtactsActivity extends TransactionSafeActivity implements View.O @Override public void onCallNumberDirectly(String phoneNumber, boolean isVideoCall) { Intent intent = isVideoCall ? - CallIntentUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) : - CallIntentUtil.getCallIntent(phoneNumber, getCallOrigin()); + IntentUtil.getVideoCallIntent(phoneNumber, getCallOrigin()) : + IntentUtil.getCallIntent(phoneNumber, getCallOrigin()); DialerUtils.startActivityWithErrorToast(this, intent); mClearSearchOnPause = true; } diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index 4fa65613e..72cbdba72 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -72,6 +72,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { public View voicemailButtonView; public View createNewContactButtonView; public View addToExistingContactButtonView; + public View sendMessageView; public View detailsButtonView; public View reportButtonView; @@ -218,35 +219,26 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { ViewStub stub = (ViewStub) rootView.findViewById(R.id.call_log_entry_actions_stub); if (stub != null) { actionsView = (ViewGroup) stub.inflate(); - } - if (videoCallButtonView == null) { videoCallButtonView = actionsView.findViewById(R.id.video_call_action); videoCallButtonView.setOnClickListener(mActionListener); - } - if (voicemailButtonView == null) { voicemailButtonView = actionsView.findViewById(R.id.voicemail_action); voicemailButtonView.setOnClickListener(mActionListener); - } - if (createNewContactButtonView == null) { createNewContactButtonView = actionsView.findViewById(R.id.create_new_contact_action); createNewContactButtonView.setOnClickListener(mActionListener); - } - if (addToExistingContactButtonView == null) { addToExistingContactButtonView = actionsView.findViewById(R.id.add_to_existing_contact_action); addToExistingContactButtonView.setOnClickListener(mActionListener); - } - if (detailsButtonView == null) { + sendMessageView = actionsView.findViewById(R.id.send_message_action); + sendMessageView.setOnClickListener(mActionListener); + detailsButtonView = actionsView.findViewById(R.id.details_action); detailsButtonView.setOnClickListener(mActionListener); - } - if (reportButtonView == null) { reportButtonView = actionsView.findViewById(R.id.report_action); reportButtonView.setOnClickListener(new View.OnClickListener() { @Override @@ -344,6 +336,8 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder { addToExistingContactButtonView.setVisibility(View.GONE); } + sendMessageView.setTag(IntentProvider.getSendSmsIntentProvider(number)); + mCallLogListItemHelper.setActionContentDescriptions(this); } diff --git a/src/com/android/dialer/calllog/IntentProvider.java b/src/com/android/dialer/calllog/IntentProvider.java index 9f5150ac7..d7a35e8ad 100644 --- a/src/com/android/dialer/calllog/IntentProvider.java +++ b/src/com/android/dialer/calllog/IntentProvider.java @@ -30,7 +30,7 @@ import com.android.contacts.common.model.ContactLoader; import com.android.dialer.CallDetailActivity; import com.android.dialer.DialtactsActivity; import com.android.dialer.PhoneCallDetails; -import com.android.dialer.util.CallIntentUtil; +import com.android.dialer.util.IntentUtil; import com.android.dialer.util.TelecomUtil; import java.util.ArrayList; @@ -55,7 +55,7 @@ public abstract class IntentProvider { return new IntentProvider() { @Override public Intent getIntent(Context context) { - return CallIntentUtil.getCallIntent(number, accountHandle); + return IntentUtil.getCallIntent(number, accountHandle); } }; } @@ -69,7 +69,7 @@ public abstract class IntentProvider { return new IntentProvider() { @Override public Intent getIntent(Context context) { - return CallIntentUtil.getVideoCallIntent(number, accountHandle); + return IntentUtil.getVideoCallIntent(number, accountHandle); } }; } @@ -78,7 +78,7 @@ public abstract class IntentProvider { return new IntentProvider() { @Override public Intent getIntent(Context context) { - return CallIntentUtil.getVoicemailIntent(); + return IntentUtil.getVoicemailIntent(); } }; } @@ -101,6 +101,15 @@ public abstract class IntentProvider { }; } + public static IntentProvider getSendSmsIntentProvider(final String number) { + return new IntentProvider() { + @Override + public Intent getIntent(Context context) { + return IntentUtil.getSendSmsIntent(number); + } + }; + } + /** * Retrieves the call details intent provider for an entry in the call log. * @@ -157,11 +166,9 @@ public abstract class IntentProvider { // Note: This code mirrors code in Contacts/QuickContactsActivity. final Intent intent; if (isNewContact) { - intent = new Intent( - Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI); + intent = IntentUtil.getNewContactIntent(); } else { - intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); - intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); + intent = IntentUtil.getAddToExistingContactIntent(); } ArrayList values = contactToSave.getContentValues(); @@ -198,14 +205,9 @@ public abstract class IntentProvider { } else { // If no lookup uri is provided, rely on the available phone number and name. if (isNewContact) { - return DialtactsActivity.getAddToContactIntent(name, number, numberType); + return IntentUtil.getNewContactIntent(name, number, numberType); } else { - Intent intent = new Intent( - Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI); - intent.putExtra(ContactsContract.Intents.Insert.NAME, name); - intent.putExtra(ContactsContract.Intents.Insert.PHONE, number); - intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, numberType); - return intent; + return IntentUtil.getAddToExistingContactIntent(name, number, numberType); } } } diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java index 6a66eb388..229af389a 100644 --- a/src/com/android/dialer/dialpad/DialpadFragment.java +++ b/src/com/android/dialer/dialpad/DialpadFragment.java @@ -78,7 +78,7 @@ import com.android.dialer.NeededForReflection; import com.android.dialer.R; import com.android.dialer.SpecialCharSequenceMgr; import com.android.dialer.calllog.PhoneAccountUtils; -import com.android.dialer.util.CallIntentUtil; +import com.android.dialer.util.IntentUtil; import com.android.dialer.util.DialerUtils; import com.android.phone.common.CallLogAsync; import com.android.phone.common.HapticFeedback; @@ -1001,8 +1001,7 @@ public class DialpadFragment extends Fragment } public void callVoicemail() { - DialerUtils.startActivityWithErrorToast(getActivity(), CallIntentUtil - .getVoicemailIntent()); + DialerUtils.startActivityWithErrorToast(getActivity(), IntentUtil.getVoicemailIntent()); hideAndClearDialpad(false); } @@ -1098,7 +1097,7 @@ public class DialpadFragment extends Fragment // Clear the digits just in case. clearDialpad(); } else { - final Intent intent = CallIntentUtil.getCallIntent(number, + final Intent intent = IntentUtil.getCallIntent(number, (getActivity() instanceof DialtactsActivity ? ((DialtactsActivity) getActivity()).getCallOrigin() : null)); DialerUtils.startActivityWithErrorToast(getActivity(), intent); @@ -1616,7 +1615,7 @@ public class DialpadFragment extends Fragment } private Intent newFlashIntent() { - final Intent intent = CallIntentUtil.getCallIntent(EMPTY_NUMBER); + final Intent intent = IntentUtil.getCallIntent(EMPTY_NUMBER); intent.putExtra(EXTRA_SEND_EMPTY_FLASH, true); return intent; } diff --git a/src/com/android/dialer/interactions/PhoneNumberInteraction.java b/src/com/android/dialer/interactions/PhoneNumberInteraction.java index 8d6de7162..8455f2423 100644 --- a/src/com/android/dialer/interactions/PhoneNumberInteraction.java +++ b/src/com/android/dialer/interactions/PhoneNumberInteraction.java @@ -52,7 +52,7 @@ import com.android.contacts.common.activity.TransactionSafeActivity; import com.android.contacts.common.util.ContactDisplayUtils; import com.android.dialer.R; import com.android.dialer.contact.ContactUpdateService; -import com.android.dialer.util.CallIntentUtil; +import com.android.dialer.util.IntentUtil; import com.android.dialer.util.DialerUtils; import com.google.common.annotations.VisibleForTesting; @@ -322,7 +322,7 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener { Intent.ACTION_SENDTO, Uri.fromParts("sms", phoneNumber, null)); break; default: - intent = CallIntentUtil.getCallIntent(phoneNumber, callOrigin); + intent = IntentUtil.getCallIntent(phoneNumber, callOrigin); break; } DialerUtils.startActivityWithErrorToast(context, intent); diff --git a/src/com/android/dialer/list/SearchFragment.java b/src/com/android/dialer/list/SearchFragment.java index 73127a294..c314478ca 100644 --- a/src/com/android/dialer/list/SearchFragment.java +++ b/src/com/android/dialer/list/SearchFragment.java @@ -40,14 +40,13 @@ import com.android.contacts.common.list.PhoneNumberPickerFragment; import com.android.contacts.common.util.ViewUtil; import com.android.contacts.commonbind.analytics.AnalyticsUtil; import com.android.dialer.dialpad.DialpadFragment.ErrorDialogFragment; -import com.android.dialer.DialtactsActivity; import com.android.dialer.R; import com.android.dialer.util.DialerUtils; +import com.android.dialer.util.IntentUtil; import com.android.phone.common.animation.AnimUtils; public class SearchFragment extends PhoneNumberPickerFragment { private static final String TAG = SearchFragment.class.getSimpleName(); - private static final String SMS_URI_PREFIX = "sms:"; private OnListFragmentScrolledListener mActivityScrollListener; @@ -216,7 +215,7 @@ public class SearchFragment extends PhoneNumberPickerFragment { super.onItemClick(position, id); break; case DialerPhoneNumberListAdapter.SHORTCUT_DIRECT_CALL: - number = adapter.getQueryString(); + number = adapter.getQueryString(); listener = getOnPhoneNumberPickerListener(); if (listener != null && !checkForProhibitedPhoneNumber(number)) { listener.onCallNumberDirectly(number); @@ -225,26 +224,23 @@ public class SearchFragment extends PhoneNumberPickerFragment { case DialerPhoneNumberListAdapter.SHORTCUT_CREATE_NEW_CONTACT: number = TextUtils.isEmpty(mAddToContactNumber) ? adapter.getFormattedQueryString() : mAddToContactNumber; - intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI); - intent.putExtra(ContactsContract.Intents.Insert.PHONE, number); - intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, - ContactsContract.CommonDataKinds.Phone.TYPE_MAIN); + intent = IntentUtil.getNewContactIntent(number); DialerUtils.startActivityWithErrorToast(getActivity(), intent); break; case DialerPhoneNumberListAdapter.SHORTCUT_ADD_TO_EXISTING_CONTACT: number = TextUtils.isEmpty(mAddToContactNumber) ? adapter.getFormattedQueryString() : mAddToContactNumber; - intent = DialtactsActivity.getAddNumberToContactIntent(number); + intent = IntentUtil.getAddToExistingContactIntent(number); DialerUtils.startActivityWithErrorToast(getActivity(), intent, R.string.add_contact_not_available); break; case DialerPhoneNumberListAdapter.SHORTCUT_SEND_SMS_MESSAGE: - intent = new Intent( - Intent.ACTION_VIEW, Uri.parse(SMS_URI_PREFIX + getQueryString())); + number = adapter.getFormattedQueryString(); + intent = IntentUtil.getSendSmsIntent(number); DialerUtils.startActivityWithErrorToast(getActivity(), intent); break; case DialerPhoneNumberListAdapter.SHORTCUT_MAKE_VIDEO_CALL: - number = adapter.getQueryString(); + number = adapter.getQueryString(); listener = getOnPhoneNumberPickerListener(); if (listener != null && !checkForProhibitedPhoneNumber(number)) { listener.onCallNumberDirectly(number, true /* isVideoCall */); diff --git a/src/com/android/dialer/util/CallIntentUtil.java b/src/com/android/dialer/util/CallIntentUtil.java deleted file mode 100644 index fac26f7a0..000000000 --- a/src/com/android/dialer/util/CallIntentUtil.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.util; - -import android.content.Intent; -import android.net.Uri; -import android.telecom.PhoneAccount; -import android.telecom.PhoneAccountHandle; -import android.telecom.TelecomManager; -import android.telecom.VideoProfile; - -import com.android.contacts.common.CallUtil; -import com.android.phone.common.PhoneConstants; - -/** - * Utilities for creation of {@link Intent#ACTION_CALL} intents. - */ -public class CallIntentUtil { - - public static final String CALL_ACTION = Intent.ACTION_CALL; - - /** - * Return an Intent for making a phone call. Scheme (e.g. tel, sip) will be determined - * automatically. - */ - public static Intent getCallIntent(String number) { - return getCallIntent(number, null, null); - } - - /** - * Return an Intent for making a phone call. A given Uri will be used as is (without any - * sanity check). - */ - public static Intent getCallIntent(Uri uri) { - return getCallIntent(uri, null, null); - } - - /** - * A variant of {@link #getCallIntent(String)} but also accept a call origin. - * For more information about call origin, see comments in Phone package (PhoneApp). - */ - public static Intent getCallIntent(String number, String callOrigin) { - return getCallIntent(CallUtil.getCallUri(number), callOrigin, null); - } - - /** - * A variant of {@link #getCallIntent(String)} but also include {@code Account}. - */ - public static Intent getCallIntent(String number, PhoneAccountHandle accountHandle) { - return getCallIntent(number, null, accountHandle); - } - - /** - * A variant of {@link #getCallIntent(android.net.Uri)} but also include {@code Account}. - */ - public static Intent getCallIntent(Uri uri, PhoneAccountHandle accountHandle) { - return getCallIntent(uri, null, accountHandle); - } - - /** - * A variant of {@link #getCallIntent(String, String)} but also include {@code Account}. - */ - public static Intent getCallIntent( - String number, String callOrigin, PhoneAccountHandle accountHandle) { - return getCallIntent(CallUtil.getCallUri(number), callOrigin, accountHandle); - } - - /** - * A variant of {@link #getCallIntent(android.net.Uri)} but also accept a call - * origin and {@code Account}. - * For more information about call origin, see comments in Phone package (PhoneApp). - */ - public static Intent getCallIntent( - Uri uri, String callOrigin, PhoneAccountHandle accountHandle) { - return getCallIntent(uri, callOrigin, accountHandle, - VideoProfile.STATE_AUDIO_ONLY); - } - - /** - * A variant of {@link #getCallIntent(String, String)} for starting a video call. - */ - public static Intent getVideoCallIntent(String number, String callOrigin) { - return getCallIntent(CallUtil.getCallUri(number), callOrigin, null, - VideoProfile.STATE_BIDIRECTIONAL); - } - - /** - * A variant of {@link #getCallIntent(String, String, android.telecom.PhoneAccountHandle)} for - * starting a video call. - */ - public static Intent getVideoCallIntent( - String number, String callOrigin, PhoneAccountHandle accountHandle) { - return getCallIntent(CallUtil.getCallUri(number), callOrigin, accountHandle, - VideoProfile.STATE_BIDIRECTIONAL); - } - - /** - * A variant of {@link #getCallIntent(String, String, android.telecom.PhoneAccountHandle)} for - * starting a video call. - */ - public static Intent getVideoCallIntent(String number, PhoneAccountHandle accountHandle) { - return getVideoCallIntent(number, null, accountHandle); - } - - /** - * A variant of {@link #getCallIntent(android.net.Uri)} for calling Voicemail. - */ - public static Intent getVoicemailIntent() { - return getCallIntent(Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", null)); - } - - /** - * A variant of {@link #getCallIntent(android.net.Uri)} but also accept a call - * origin and {@code Account} and {@code VideoCallProfile} state. - * For more information about call origin, see comments in Phone package (PhoneApp). - */ - public static Intent getCallIntent( - Uri uri, String callOrigin, PhoneAccountHandle accountHandle, int videoState) { - final Intent intent = new Intent(CALL_ACTION, uri); - intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, videoState); - if (callOrigin != null) { - intent.putExtra(PhoneConstants.EXTRA_CALL_ORIGIN, callOrigin); - } - if (accountHandle != null) { - intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle); - } - - return intent; - } -} diff --git a/src/com/android/dialer/util/DialerUtils.java b/src/com/android/dialer/util/DialerUtils.java index 3899b3736..a04719a41 100644 --- a/src/com/android/dialer/util/DialerUtils.java +++ b/src/com/android/dialer/util/DialerUtils.java @@ -71,7 +71,7 @@ public class DialerUtils { */ public static void startActivityWithErrorToast(Context context, Intent intent, int msgId) { try { - if ((CallIntentUtil.CALL_ACTION.equals(intent.getAction()) + if ((IntentUtil.CALL_ACTION.equals(intent.getAction()) && context instanceof Activity)) { // All dialer-initiated calls should pass the touch point to the InCallUI Point touchPoint = TouchPointManager.getInstance().getPoint(); diff --git a/src/com/android/dialer/util/IntentUtil.java b/src/com/android/dialer/util/IntentUtil.java new file mode 100644 index 000000000..263d3cd74 --- /dev/null +++ b/src/com/android/dialer/util/IntentUtil.java @@ -0,0 +1,201 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.util; + +import android.content.Intent; +import android.net.Uri; +import android.provider.ContactsContract; +import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; +import android.telecom.VideoProfile; + +import com.android.contacts.common.CallUtil; +import com.android.phone.common.PhoneConstants; + +/** + * Utilities for creation of intents in Dialer, such as {@link Intent#ACTION_CALL}. + */ +public class IntentUtil { + + public static final String CALL_ACTION = Intent.ACTION_CALL; + private static final String SMS_URI_PREFIX = "sms:"; + + /** + * Return an Intent for making a phone call. Scheme (e.g. tel, sip) will be determined + * automatically. + */ + public static Intent getCallIntent(String number) { + return getCallIntent(number, null, null); + } + + /** + * Return an Intent for making a phone call. A given Uri will be used as is (without any + * sanity check). + */ + public static Intent getCallIntent(Uri uri) { + return getCallIntent(uri, null, null); + } + + /** + * A variant of {@link #getCallIntent(String)} but also accept a call origin. + * For more information about call origin, see comments in Phone package (PhoneApp). + */ + public static Intent getCallIntent(String number, String callOrigin) { + return getCallIntent(CallUtil.getCallUri(number), callOrigin, null); + } + + /** + * A variant of {@link #getCallIntent(String)} but also include {@code Account}. + */ + public static Intent getCallIntent(String number, PhoneAccountHandle accountHandle) { + return getCallIntent(number, null, accountHandle); + } + + /** + * A variant of {@link #getCallIntent(android.net.Uri)} but also include {@code Account}. + */ + public static Intent getCallIntent(Uri uri, PhoneAccountHandle accountHandle) { + return getCallIntent(uri, null, accountHandle); + } + + /** + * A variant of {@link #getCallIntent(String, String)} but also include {@code Account}. + */ + public static Intent getCallIntent( + String number, String callOrigin, PhoneAccountHandle accountHandle) { + return getCallIntent(CallUtil.getCallUri(number), callOrigin, accountHandle); + } + + /** + * A variant of {@link #getCallIntent(android.net.Uri)} but also accept a call + * origin and {@code Account}. + * For more information about call origin, see comments in Phone package (PhoneApp). + */ + public static Intent getCallIntent( + Uri uri, String callOrigin, PhoneAccountHandle accountHandle) { + return getCallIntent(uri, callOrigin, accountHandle, + VideoProfile.STATE_AUDIO_ONLY); + } + + /** + * A variant of {@link #getCallIntent(String, String)} for starting a video call. + */ + public static Intent getVideoCallIntent(String number, String callOrigin) { + return getCallIntent(CallUtil.getCallUri(number), callOrigin, null, + VideoProfile.STATE_BIDIRECTIONAL); + } + + /** + * A variant of {@link #getCallIntent(String, String, android.telecom.PhoneAccountHandle)} for + * starting a video call. + */ + public static Intent getVideoCallIntent( + String number, String callOrigin, PhoneAccountHandle accountHandle) { + return getCallIntent(CallUtil.getCallUri(number), callOrigin, accountHandle, + VideoProfile.STATE_BIDIRECTIONAL); + } + + /** + * A variant of {@link #getCallIntent(String, String, android.telecom.PhoneAccountHandle)} for + * starting a video call. + */ + public static Intent getVideoCallIntent(String number, PhoneAccountHandle accountHandle) { + return getVideoCallIntent(number, null, accountHandle); + } + + /** + * A variant of {@link #getCallIntent(android.net.Uri)} for calling Voicemail. + */ + public static Intent getVoicemailIntent() { + return getCallIntent(Uri.fromParts(PhoneAccount.SCHEME_VOICEMAIL, "", null)); + } + + /** + * A variant of {@link #getCallIntent(android.net.Uri)} but also accept a call + * origin and {@code Account} and {@code VideoCallProfile} state. + * For more information about call origin, see comments in Phone package (PhoneApp). + */ + public static Intent getCallIntent( + Uri uri, String callOrigin, PhoneAccountHandle accountHandle, int videoState) { + final Intent intent = new Intent(CALL_ACTION, uri); + intent.putExtra(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, videoState); + if (callOrigin != null) { + intent.putExtra(PhoneConstants.EXTRA_CALL_ORIGIN, callOrigin); + } + if (accountHandle != null) { + intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle); + } + + return intent; + } + + public static Intent getSendSmsIntent(CharSequence phoneNumber) { + return new Intent(Intent.ACTION_VIEW, Uri.parse(SMS_URI_PREFIX + phoneNumber)); + } + + public static Intent getNewContactIntent() { + return new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI); + } + + public static Intent getNewContactIntent(CharSequence phoneNumber) { + return getNewContactIntent( + null /* name */, + phoneNumber /* phoneNumber */, + -1 /* phoneNumberType */); + } + + public static Intent getNewContactIntent( + CharSequence name, CharSequence phoneNumber, int phoneNumberType) { + Intent intent = getNewContactIntent(); + populateContactIntent(intent, name, phoneNumber, phoneNumberType); + return intent; + } + + public static Intent getAddToExistingContactIntent() { + Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); + intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); + return intent; + } + + public static Intent getAddToExistingContactIntent(CharSequence phoneNumber) { + return getAddToExistingContactIntent( + null /* name */, + phoneNumber /* phoneNumber */, + -1 /* phoneNumberType */); + } + + public static Intent getAddToExistingContactIntent( + CharSequence name, CharSequence phoneNumber, int phoneNumberType) { + Intent intent = getAddToExistingContactIntent(); + populateContactIntent(intent, name, phoneNumber, phoneNumberType); + return intent; + } + + private static void populateContactIntent( + Intent intent, CharSequence name, CharSequence phoneNumber, int phoneNumberType) { + if (phoneNumber != null) { + intent.putExtra(ContactsContract.Intents.Insert.PHONE, phoneNumber); + } + if (name != null) { + intent.putExtra(ContactsContract.Intents.Insert.NAME, name); + } + if (phoneNumberType != -1) { + intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, phoneNumberType); + } + } +} -- cgit v1.2.3