1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.dialer.util; 18 19 import android.content.Intent; 20 import android.net.Uri; 21 import android.provider.ContactsContract; 22 23 /** Utilities for creation of intents in Dialer. */ 24 public class IntentUtil { 25 26 private static final String SMS_URI_PREFIX = "sms:"; 27 private static final int NO_PHONE_TYPE = -1; 28 29 public static Intent getSendSmsIntent(CharSequence phoneNumber) { 30 return new Intent(Intent.ACTION_SENDTO, Uri.parse(SMS_URI_PREFIX + phoneNumber)); 31 } 32 33 public static Intent getNewContactIntent() { 34 return new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI); 35 } 36 37 public static Intent getNewContactIntent(CharSequence phoneNumber) { 38 return getNewContactIntent(null /* name */, phoneNumber /* phoneNumber */, NO_PHONE_TYPE); 39 } 40 41 public static Intent getNewContactIntent( 42 CharSequence name, CharSequence phoneNumber, int phoneNumberType) { 43 Intent intent = getNewContactIntent(); 44 populateContactIntent(intent, name, phoneNumber, phoneNumberType); 45 return intent; 46 } 47 48 public static Intent getAddToExistingContactIntent() { 49 Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT); 50 intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE); 51 return intent; 52 } 53 54 public static Intent getAddToExistingContactIntent(CharSequence phoneNumber) { 55 return getAddToExistingContactIntent( 56 null /* name */, phoneNumber /* phoneNumber */, NO_PHONE_TYPE); 57 } 58 59 public static Intent getAddToExistingContactIntent( 60 CharSequence name, CharSequence phoneNumber, int phoneNumberType) { 61 Intent intent = getAddToExistingContactIntent(); 62 populateContactIntent(intent, name, phoneNumber, phoneNumberType); 63 return intent; 64 } 65 66 private static void populateContactIntent( 67 Intent intent, CharSequence name, CharSequence phoneNumber, int phoneNumberType) { 68 if (phoneNumber != null) { 69 intent.putExtra(ContactsContract.Intents.Insert.PHONE, phoneNumber); 70 } 71 if (name != null) { 72 intent.putExtra(ContactsContract.Intents.Insert.NAME, name); 73 } 74 if (phoneNumberType != NO_PHONE_TYPE) { 75 intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, phoneNumberType); 76 } 77 } 78 } 79