diff options
author | Andrew Lee <anwlee@google.com> | 2015-05-12 19:09:00 -0700 |
---|---|---|
committer | Andrew Lee <anwlee@google.com> | 2015-05-13 11:55:22 -0700 |
commit | 247df6ee4f43af916f7e7f339ed181a18807ef36 (patch) | |
tree | 5398368b42b5b18d525a8112eb7556dde0da42e7 /src/com/android/dialer/util | |
parent | 8ba6e006159a887671862c314e94487c0fd5e8e0 (diff) |
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
Diffstat (limited to 'src/com/android/dialer/util')
-rw-r--r-- | src/com/android/dialer/util/DialerUtils.java | 2 | ||||
-rw-r--r-- | src/com/android/dialer/util/IntentUtil.java (renamed from src/com/android/dialer/util/CallIntentUtil.java) | 61 |
2 files changed, 60 insertions, 3 deletions
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/CallIntentUtil.java b/src/com/android/dialer/util/IntentUtil.java index fac26f7a0..263d3cd74 100644 --- a/src/com/android/dialer/util/CallIntentUtil.java +++ b/src/com/android/dialer/util/IntentUtil.java @@ -18,6 +18,7 @@ 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; @@ -27,11 +28,12 @@ import com.android.contacts.common.CallUtil; import com.android.phone.common.PhoneConstants; /** - * Utilities for creation of {@link Intent#ACTION_CALL} intents. + * Utilities for creation of intents in Dialer, such as {@link Intent#ACTION_CALL}. */ -public class CallIntentUtil { +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 @@ -141,4 +143,59 @@ public class CallIntentUtil { 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); + } + } } |