summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Lee <anwlee@google.com>2015-05-13 20:05:48 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-05-13 20:05:48 +0000
commitf53037503d53f3ff4e213146566ec78cc74a3fe0 (patch)
tree86442a2bc0d5964153a6925d32d3e656ade838e2 /src
parentefdcd433307cbc602073235f500e2bcdde9bb2fd (diff)
parent0875511027e21de08feb789e358a5fb0e6902b0a (diff)
am 08755110: am 911b14d1: Merge "Reorganize Intent utilities, add send SMS intent." into mnc-dev
* commit '0875511027e21de08feb789e358a5fb0e6902b0a': Reorganize Intent utilities, add send SMS intent.
Diffstat (limited to 'src')
-rw-r--r--src/com/android/dialer/CallDetailActivity.java7
-rw-r--r--src/com/android/dialer/DialtactsActivity.java49
-rw-r--r--src/com/android/dialer/calllog/CallLogListItemViewHolder.java18
-rw-r--r--src/com/android/dialer/calllog/IntentProvider.java32
-rw-r--r--src/com/android/dialer/dialpad/DialpadFragment.java9
-rw-r--r--src/com/android/dialer/interactions/PhoneNumberInteraction.java4
-rw-r--r--src/com/android/dialer/list/SearchFragment.java18
-rw-r--r--src/com/android/dialer/util/DialerUtils.java2
-rw-r--r--src/com/android/dialer/util/IntentUtil.java (renamed from src/com/android/dialer/util/CallIntentUtil.java)61
9 files changed, 111 insertions, 89 deletions
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> 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<ContentValues> 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<Cursor> {
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/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);
+ }
+ }
}