From 87dc7309388941ec0017f3ff1aee329364dec484 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Wed, 18 Mar 2015 17:10:56 -0700 Subject: Add shortcut for creating new contact with number. Add a shortcut in the search fragment for "Create new contact" which opens the compact editor with the entered phone number populated as the main phone number. Bug: 19372539 Change-Id: I9ccb462f399e3fab77c2d8ad536dbd0bd0e23609 --- .../dialer/list/DialerPhoneNumberListAdapter.java | 13 +++++++++---- .../dialer/list/RegularSearchListAdapter.java | 1 + src/com/android/dialer/list/SearchFragment.java | 20 ++++++++++++++++---- .../dialer/list/SmartDialNumberListAdapter.java | 1 + 4 files changed, 27 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/com/android/dialer/list/DialerPhoneNumberListAdapter.java b/src/com/android/dialer/list/DialerPhoneNumberListAdapter.java index 089937259..f5d8ee0bb 100644 --- a/src/com/android/dialer/list/DialerPhoneNumberListAdapter.java +++ b/src/com/android/dialer/list/DialerPhoneNumberListAdapter.java @@ -27,11 +27,12 @@ public class DialerPhoneNumberListAdapter extends PhoneNumberListAdapter { public final static int SHORTCUT_INVALID = -1; public final static int SHORTCUT_DIRECT_CALL = 0; - public final static int SHORTCUT_ADD_TO_EXISTING_CONTACT = 1; - public final static int SHORTCUT_SEND_SMS_MESSAGE = 2; - public final static int SHORTCUT_MAKE_VIDEO_CALL = 3; + public final static int SHORTCUT_CREATE_NEW_CONTACT = 1; + public final static int SHORTCUT_ADD_TO_EXISTING_CONTACT = 2; + public final static int SHORTCUT_SEND_SMS_MESSAGE = 3; + public final static int SHORTCUT_MAKE_VIDEO_CALL = 4; - public final static int SHORTCUT_COUNT = 4; + public final static int SHORTCUT_COUNT = 5; private final boolean[] mShortcutEnabled = new boolean[SHORTCUT_COUNT]; @@ -143,6 +144,10 @@ public class DialerPhoneNumberListAdapter extends PhoneNumberListAdapter { text = resources.getString(R.string.search_shortcut_call_number, number); drawableId = R.drawable.ic_search_phone; break; + case SHORTCUT_CREATE_NEW_CONTACT: + text = resources.getString(R.string.search_shortcut_create_new_contact); + drawableId = R.drawable.ic_search_add_contact; + break; case SHORTCUT_ADD_TO_EXISTING_CONTACT: text = resources.getString(R.string.search_shortcut_add_to_existing_contact); drawableId = R.drawable.ic_person_24dp; diff --git a/src/com/android/dialer/list/RegularSearchListAdapter.java b/src/com/android/dialer/list/RegularSearchListAdapter.java index 87d4fd2c8..722dc2ed6 100644 --- a/src/com/android/dialer/list/RegularSearchListAdapter.java +++ b/src/com/android/dialer/list/RegularSearchListAdapter.java @@ -69,6 +69,7 @@ public class RegularSearchListAdapter extends DialerPhoneNumberListAdapter { final boolean showNumberShortcuts = !TextUtils.isEmpty(getFormattedQueryString()); boolean changed = false; changed |= setShortcutEnabled(SHORTCUT_DIRECT_CALL, showNumberShortcuts); + changed |= setShortcutEnabled(SHORTCUT_CREATE_NEW_CONTACT, showNumberShortcuts); changed |= setShortcutEnabled(SHORTCUT_ADD_TO_EXISTING_CONTACT, showNumberShortcuts); changed |= setShortcutEnabled(SHORTCUT_MAKE_VIDEO_CALL, showNumberShortcuts && CallUtil.isVideoEnabled(getContext())); diff --git a/src/com/android/dialer/list/SearchFragment.java b/src/com/android/dialer/list/SearchFragment.java index e60936234..24ddc7351 100644 --- a/src/com/android/dialer/list/SearchFragment.java +++ b/src/com/android/dialer/list/SearchFragment.java @@ -20,6 +20,7 @@ import android.content.Intent; import android.content.res.Resources; import android.net.Uri; import android.os.Bundle; +import android.provider.ContactsContract; import android.text.TextUtils; import android.view.View; import android.view.animation.Interpolator; @@ -152,6 +153,8 @@ public class SearchFragment extends PhoneNumberPickerFragment { final DialerPhoneNumberListAdapter adapter = (DialerPhoneNumberListAdapter) getAdapter(); final int shortcutType = adapter.getShortcutTypeFromPosition(position); final OnPhoneNumberPickerActionListener listener; + final Intent intent; + final String number; switch (shortcutType) { case DialerPhoneNumberListAdapter.SHORTCUT_INVALID: @@ -163,17 +166,26 @@ public class SearchFragment extends PhoneNumberPickerFragment { listener.onCallNumberDirectly(getQueryString()); } break; + 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); + DialerUtils.startActivityWithErrorToast(getActivity(), intent); + break; case DialerPhoneNumberListAdapter.SHORTCUT_ADD_TO_EXISTING_CONTACT: - final String number = TextUtils.isEmpty(mAddToContactNumber) ? + number = TextUtils.isEmpty(mAddToContactNumber) ? adapter.getFormattedQueryString() : mAddToContactNumber; - final Intent intent = DialtactsActivity.getAddNumberToContactIntent(number); + intent = DialtactsActivity.getAddNumberToContactIntent(number); DialerUtils.startActivityWithErrorToast(getActivity(), intent, R.string.add_contact_not_available); break; case DialerPhoneNumberListAdapter.SHORTCUT_SEND_SMS_MESSAGE: - final Intent sendSmsIntent = new Intent( + intent = new Intent( Intent.ACTION_VIEW, Uri.parse(SMS_URI_PREFIX + getQueryString())); - DialerUtils.startActivityWithErrorToast(getActivity(), sendSmsIntent); + DialerUtils.startActivityWithErrorToast(getActivity(), intent); break; case DialerPhoneNumberListAdapter.SHORTCUT_MAKE_VIDEO_CALL: listener = getOnPhoneNumberPickerListener(); diff --git a/src/com/android/dialer/list/SmartDialNumberListAdapter.java b/src/com/android/dialer/list/SmartDialNumberListAdapter.java index ed01baf2f..22ee92df2 100644 --- a/src/com/android/dialer/list/SmartDialNumberListAdapter.java +++ b/src/com/android/dialer/list/SmartDialNumberListAdapter.java @@ -116,6 +116,7 @@ public class SmartDialNumberListAdapter extends DialerPhoneNumberListAdapter { public void setQueryString(String queryString) { final boolean showNumberShortcuts = !TextUtils.isEmpty(getFormattedQueryString()); boolean changed = false; + changed |= setShortcutEnabled(SHORTCUT_CREATE_NEW_CONTACT, showNumberShortcuts); changed |= setShortcutEnabled(SHORTCUT_ADD_TO_EXISTING_CONTACT, showNumberShortcuts); changed |= setShortcutEnabled(SHORTCUT_SEND_SMS_MESSAGE, showNumberShortcuts); changed |= setShortcutEnabled(SHORTCUT_MAKE_VIDEO_CALL, -- cgit v1.2.3