Merge "Fix NPE in keyPressed when getView is null" into mnc-dev
diff --git a/res/layout/call_log_list_item_actions.xml b/res/layout/call_log_list_item_actions.xml
index a10b47f..d3e18be 100644
--- a/res/layout/call_log_list_item_actions.xml
+++ b/res/layout/call_log_list_item_actions.xml
@@ -80,6 +80,20 @@
</LinearLayout>
<LinearLayout
+ android:id="@+id/send_message_action"
+ style="@style/CallLogActionStyle">
+
+ <ImageView
+ style="@style/CallLogActionIconStyle"
+ android:src="@drawable/ic_textsms_24dp" />
+
+ <TextView
+ style="@style/CallLogActionTextStyle"
+ android:text="@string/call_log_action_send_message" />
+
+ </LinearLayout>
+
+ <LinearLayout
android:id="@+id/details_action"
style="@style/CallLogActionStyle">
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 79c441d..2e236a6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -550,6 +550,11 @@
[CHAR LIMIT=30] -->
<string name="call_log_action_voicemail">LISTEN</string>
+ <!-- Button text for a button displayed underneath an entry in the call log, which opens up a
+ messaging app to send a SMS to the number represented by the call log entry.
+ [CHAR LIMIT=50] -->
+ <string name="call_log_action_send_message">Send Message</string>
+
<!-- Button text for the button displayed underneath an entry in the call log.
Tapping navigates the user to the call details screen where the user can view details for
the call log entry. [CHAR LIMIT=50] -->
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java
index 0a295c4..735d6eb 100644
--- a/src/com/android/dialer/CallDetailActivity.java
+++ b/src/com/android/dialer/CallDetailActivity.java
@@ -64,7 +64,7 @@
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 @@
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 cccc06e..25828e5 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -29,7 +29,6 @@
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.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 @@
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 @@
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 @@
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> resolveInfo = packageManager.queryIntentActivities(intent,
@@ -1171,8 +1144,8 @@
@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 4fa6561..72cbdba 100644
--- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
+++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java
@@ -72,6 +72,7 @@
public View voicemailButtonView;
public View createNewContactButtonView;
public View addToExistingContactButtonView;
+ public View sendMessageView;
public View detailsButtonView;
public View reportButtonView;
@@ -218,35 +219,26 @@
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 @@
addToExistingContactButtonView.setVisibility(View.GONE);
}
+ sendMessageView.setTag(IntentProvider.getSendSmsIntentProvider(number));
+
mCallLogListItemHelper.setActionContentDescriptions(this);
}
diff --git a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
index 8241811..99ca8db 100644
--- a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
+++ b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java
@@ -41,10 +41,9 @@
import java.util.Map;
/**
- * Implementation of {@link VoicemailNotifier} that shows a notification in the
- * status bar.
+ * VoicemailNotifier that shows a notification in the status bar.
*/
-public class DefaultVoicemailNotifier implements VoicemailNotifier {
+public class DefaultVoicemailNotifier {
public static final String TAG = "DefaultVoicemailNotifier";
/** The tag used to identify notifications from this class. */
@@ -85,8 +84,14 @@
mPhoneNumberHelper = phoneNumberHelper;
}
- /** Updates the notification and notifies of the call with the given URI. */
- @Override
+ /**
+ * Updates the notification and notifies of the call with the given URI.
+ *
+ * Clears the notification if there are no new voicemails, and notifies if the given URI
+ * corresponds to a new voicemail.
+ *
+ * It is not safe to call this method from the main thread.
+ */
public void updateNotification(Uri newCallUri) {
// Lookup the list of new voicemails to include in the notification.
// TODO: Move this into a service, to avoid holding the receiver up.
@@ -170,26 +175,10 @@
// Determine the intent to fire when the notification is clicked on.
final Intent contentIntent;
- if (newCalls.length == 1) {
- // Open the voicemail directly.
- contentIntent = new Intent(mContext, CallDetailActivity.class);
- contentIntent.setData(newCalls[0].callsUri);
- contentIntent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI,
- newCalls[0].voicemailUri);
- Intent playIntent = new Intent(mContext, CallDetailActivity.class);
- playIntent.setData(newCalls[0].callsUri);
- playIntent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI,
- newCalls[0].voicemailUri);
- playIntent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_START_PLAYBACK, true);
- playIntent.putExtra(CallDetailActivity.EXTRA_FROM_NOTIFICATION, true);
- notificationBuilder.addAction(R.drawable.ic_play_holo_dark,
- resources.getString(R.string.notification_action_voicemail_play),
- PendingIntent.getActivity(mContext, 0, playIntent, 0));
- } else {
- // Open the call log.
- contentIntent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI);
- contentIntent.putExtra(Calls.EXTRA_CALL_TYPE_FILTER, Calls.VOICEMAIL_TYPE);
- }
+ // Open the call log.
+ // TODO: Send to recents tab in Dialer instead.
+ contentIntent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI);
+ contentIntent.putExtra(Calls.EXTRA_CALL_TYPE_FILTER, Calls.VOICEMAIL_TYPE);
notificationBuilder.setContentIntent(
PendingIntent.getActivity(mContext, 0, contentIntent, 0));
@@ -209,7 +198,6 @@
return PendingIntent.getService(mContext, 0, intent, 0);
}
- @Override
public void clearNotification() {
mNotificationManager.cancel(NOTIFICATION_TAG, NOTIFICATION_ID);
}
diff --git a/src/com/android/dialer/calllog/IntentProvider.java b/src/com/android/dialer/calllog/IntentProvider.java
index 9f5150a..d7a35e8 100644
--- a/src/com/android/dialer/calllog/IntentProvider.java
+++ b/src/com/android/dialer/calllog/IntentProvider.java
@@ -30,7 +30,7 @@
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 @@
return new IntentProvider() {
@Override
public Intent getIntent(Context context) {
- return CallIntentUtil.getCallIntent(number, accountHandle);
+ return IntentUtil.getCallIntent(number, accountHandle);
}
};
}
@@ -69,7 +69,7 @@
return new IntentProvider() {
@Override
public Intent getIntent(Context context) {
- return CallIntentUtil.getVideoCallIntent(number, accountHandle);
+ return IntentUtil.getVideoCallIntent(number, accountHandle);
}
};
}
@@ -78,7 +78,7 @@
return new IntentProvider() {
@Override
public Intent getIntent(Context context) {
- return CallIntentUtil.getVoicemailIntent();
+ return IntentUtil.getVoicemailIntent();
}
};
}
@@ -101,6 +101,15 @@
};
}
+ 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 @@
// 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<ContentValues> values = contactToSave.getContentValues();
@@ -198,14 +205,9 @@
} 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/calllog/VoicemailNotifier.java b/src/com/android/dialer/calllog/VoicemailNotifier.java
deleted file mode 100644
index d433cf7..0000000
--- a/src/com/android/dialer/calllog/VoicemailNotifier.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2011 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.calllog;
-
-import android.net.Uri;
-
-/**
- * Handles notifications for voicemails.
- */
-public interface VoicemailNotifier {
- /**
- * Updates the notification and clears it if there are no new voicemails.
- * <p>
- * If the given URI corresponds to a new voicemail, also notifies about it.
- * <p>
- * It is not safe to call this method from the main thread.
- *
- * @param newCallUri URI of the new call, may be null
- */
- public void updateNotification(Uri newCallUri);
-
- /** Clears the new voicemail notification. */
- public void clearNotification();
-}
diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java
index 2ac1a5c..a1ba150 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.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 void callVoicemail() {
- DialerUtils.startActivityWithErrorToast(getActivity(), CallIntentUtil
- .getVoicemailIntent());
+ DialerUtils.startActivityWithErrorToast(getActivity(), IntentUtil.getVoicemailIntent());
hideAndClearDialpad(false);
}
@@ -1098,7 +1097,7 @@
// 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 @@
}
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 8d6de71..8455f24 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.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 @@
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 73127a2..c314478 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.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 @@
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 @@
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/DialerUtils.java b/src/com/android/dialer/util/DialerUtils.java
index 3899b37..a04719a 100644
--- a/src/com/android/dialer/util/DialerUtils.java
+++ b/src/com/android/dialer/util/DialerUtils.java
@@ -71,7 +71,7 @@
*/
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
similarity index 69%
rename from src/com/android/dialer/util/CallIntentUtil.java
rename to src/com/android/dialer/util/IntentUtil.java
index fac26f7..263d3cd 100644
--- a/src/com/android/dialer/util/CallIntentUtil.java
+++ b/src/com/android/dialer/util/IntentUtil.java
@@ -18,6 +18,7 @@
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.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 @@
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);
+ }
+ }
}
diff --git a/tests/src/com/android/dialer/util/TestConstants.java b/tests/src/com/android/dialer/util/TestConstants.java
index 8ebf7f1..a3dd051 100644
--- a/tests/src/com/android/dialer/util/TestConstants.java
+++ b/tests/src/com/android/dialer/util/TestConstants.java
@@ -1,5 +1,5 @@
package com.android.dialer.util;
public class TestConstants {
- public static final String CALL_INTENT_ACTION = CallIntentUtil.CALL_ACTION;
+ public static final String CALL_INTENT_ACTION = IntentUtil.CALL_ACTION;
}