Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | package com.android.contacts.editor; |
| 17 | |
John Shao | 41c6886 | 2016-08-17 21:02:41 -0700 | [diff] [blame] | 18 | import android.content.ContentValues; |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
| 21 | import android.net.Uri; |
| 22 | import android.provider.ContactsContract; |
| 23 | import android.provider.ContactsContract.Contacts; |
| 24 | import android.text.TextUtils; |
| 25 | |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 26 | import com.android.contacts.activities.ContactEditorActivity; |
Gary Mai | a6c80b3 | 2016-09-30 16:34:55 -0700 | [diff] [blame] | 27 | import com.android.contacts.activities.ContactEditorSpringBoardActivity; |
Gary Mai | 69c182a | 2016-12-05 13:07:03 -0800 | [diff] [blame] | 28 | import com.android.contacts.model.RawContactDeltaList; |
| 29 | import com.android.contacts.util.MaterialColorMapUtils.MaterialPalette; |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 30 | |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 31 | import java.util.ArrayList; |
| 32 | |
| 33 | /** |
| 34 | * Creates Intents to edit contacts. |
| 35 | */ |
| 36 | public class EditorIntents { |
| 37 | |
| 38 | private EditorIntents() { |
| 39 | } |
| 40 | |
| 41 | /** |
Gary Mai | a6c80b3 | 2016-09-30 16:34:55 -0700 | [diff] [blame] | 42 | * Returns an Intent to start the {@link ContactEditorSpringBoardActivity} for an |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 43 | * existing contact. |
| 44 | */ |
Gary Mai | a6c80b3 | 2016-09-30 16:34:55 -0700 | [diff] [blame] | 45 | public static Intent createEditContactIntent(Context context, Uri uri, |
Wenyi Wang | c41a1e5 | 2016-01-29 17:01:35 +0000 | [diff] [blame] | 46 | MaterialPalette materialPalette, long photoId) { |
Gary Mai | a6c80b3 | 2016-09-30 16:34:55 -0700 | [diff] [blame] | 47 | final Intent intent = new Intent(Intent.ACTION_EDIT, uri, context, |
| 48 | ContactEditorSpringBoardActivity.class); |
Walter Jang | 921287e | 2015-03-10 09:53:36 -0700 | [diff] [blame] | 49 | putMaterialPalette(intent, materialPalette); |
Walter Jang | ac679af | 2015-06-01 12:17:06 -0700 | [diff] [blame] | 50 | putPhotoId(intent, photoId); |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 51 | return intent; |
| 52 | } |
| 53 | |
Gary Mai | b9065dd | 2016-11-08 10:49:00 -0800 | [diff] [blame] | 54 | public static Intent createViewLinkedContactsIntent(Context context, Uri uri, |
| 55 | MaterialPalette materialPalette) { |
| 56 | final Intent intent = createEditContactIntent(context, uri, materialPalette, |
| 57 | /* photoId */ -1); |
| 58 | intent.putExtra(ContactEditorSpringBoardActivity.EXTRA_SHOW_READ_ONLY, true); |
| 59 | |
| 60 | return intent; |
| 61 | } |
| 62 | |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 63 | /** |
Gary Mai | a6c80b3 | 2016-09-30 16:34:55 -0700 | [diff] [blame] | 64 | * Returns an Intent to start the {@link ContactEditorActivity} for the given raw contact. |
| 65 | */ |
| 66 | public static Intent createEditContactIntentForRawContact(Context context, |
| 67 | Uri uri, long rawContactId, MaterialPalette materialPalette) { |
| 68 | final Intent intent = new Intent(Intent.ACTION_EDIT, uri, context, |
| 69 | ContactEditorActivity.class); |
| 70 | intent.putExtra(ContactEditorFragment.INTENT_EXTRA_RAW_CONTACT_ID_TO_DISPLAY_ALONE, |
| 71 | rawContactId); |
| 72 | putMaterialPalette(intent, materialPalette); |
| 73 | return intent; |
| 74 | } |
| 75 | |
| 76 | /** |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 77 | * Returns an Intent to start the {@link ContactEditorActivity} for a new contact with |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 78 | * the field values specified by rawContactDeltaList pre-populate in the form. |
| 79 | */ |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 80 | public static Intent createInsertContactIntent(Context context, |
John Shao | 41c6886 | 2016-08-17 21:02:41 -0700 | [diff] [blame] | 81 | RawContactDeltaList rawContactDeltaList, String displayName, String phoneticName, |
| 82 | /* Bundle updatedPhotos, */ boolean isNewLocalProfile) { |
| 83 | final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI, |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 84 | context, ContactEditorActivity.class); |
Walter Jang | 8bac28b | 2016-08-30 10:34:55 -0700 | [diff] [blame] | 85 | intent.putExtra( |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 86 | ContactEditorFragment.INTENT_EXTRA_NEW_LOCAL_PROFILE, isNewLocalProfile); |
John Shao | f8f6f95 | 2016-10-21 18:57:36 -0700 | [diff] [blame] | 87 | putRawContactDeltaValues(intent, rawContactDeltaList, displayName, phoneticName); |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 88 | return intent; |
| 89 | } |
| 90 | |
| 91 | /** |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 92 | * Returns an Intent to edit a different raw contact in the editor with whatever |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 93 | * values were already entered on the current editor. |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 94 | */ |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 95 | public static Intent createEditOtherRawContactIntent(Context context, Uri uri, |
| 96 | long rawContactId, ArrayList<ContentValues> contentValues) { |
Gary Mai | a6c80b3 | 2016-09-30 16:34:55 -0700 | [diff] [blame] | 97 | final Intent intent = new Intent(Intent.ACTION_EDIT, uri, context, |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 98 | ContactEditorActivity.class); |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 99 | intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS |
| 100 | | Intent.FLAG_ACTIVITY_FORWARD_RESULT); |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 101 | intent.putExtra(ContactEditorFragment.INTENT_EXTRA_ADD_TO_DEFAULT_DIRECTORY, ""); |
Gary Mai | 678108e | 2016-10-26 14:34:33 -0700 | [diff] [blame] | 102 | intent.putExtra(ContactEditorFragment.INTENT_EXTRA_RAW_CONTACT_ID_TO_DISPLAY_ALONE, |
| 103 | rawContactId); |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 104 | // Pass on all the data that has been entered so far |
| 105 | if (contentValues != null && contentValues.size() != 0) { |
| 106 | intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, contentValues); |
| 107 | } |
| 108 | return intent; |
| 109 | } |
| 110 | |
Walter Jang | 921287e | 2015-03-10 09:53:36 -0700 | [diff] [blame] | 111 | private static void putMaterialPalette(Intent intent, MaterialPalette materialPalette) { |
| 112 | if (materialPalette != null) { |
Walter Jang | 7b0970f | 2016-09-01 10:40:19 -0700 | [diff] [blame] | 113 | intent.putExtra( |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 114 | ContactEditorFragment.INTENT_EXTRA_MATERIAL_PALETTE_PRIMARY_COLOR, |
Walter Jang | 03debc6 | 2015-07-20 09:36:07 -0700 | [diff] [blame] | 115 | materialPalette.mPrimaryColor); |
Walter Jang | 7b0970f | 2016-09-01 10:40:19 -0700 | [diff] [blame] | 116 | intent.putExtra( |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 117 | ContactEditorFragment.INTENT_EXTRA_MATERIAL_PALETTE_SECONDARY_COLOR, |
Walter Jang | 03debc6 | 2015-07-20 09:36:07 -0700 | [diff] [blame] | 118 | materialPalette.mSecondaryColor); |
Walter Jang | 921287e | 2015-03-10 09:53:36 -0700 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
Walter Jang | ac679af | 2015-06-01 12:17:06 -0700 | [diff] [blame] | 122 | private static void putPhotoId(Intent intent, long photoId) { |
| 123 | if (photoId >= 0) { |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 124 | intent.putExtra(ContactEditorFragment.INTENT_EXTRA_PHOTO_ID, photoId); |
Walter Jang | ac679af | 2015-06-01 12:17:06 -0700 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 128 | private static void putRawContactDeltaValues(Intent intent, |
Walter Jang | bf63a6d | 2015-05-05 09:14:35 -0700 | [diff] [blame] | 129 | RawContactDeltaList rawContactDeltaList, String displayName, String phoneticName) { |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 130 | // Pass on all the data that has been entered so far |
Walter Jang | 921287e | 2015-03-10 09:53:36 -0700 | [diff] [blame] | 131 | if (rawContactDeltaList != null && !rawContactDeltaList.isEmpty()) { |
| 132 | ArrayList<ContentValues> contentValues = rawContactDeltaList.get(0).getContentValues(); |
| 133 | if (contentValues != null && contentValues.size() != 0) { |
| 134 | intent.putParcelableArrayListExtra( |
| 135 | ContactsContract.Intents.Insert.DATA, contentValues); |
| 136 | } |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 137 | } |
Walter Jang | bf63a6d | 2015-05-05 09:14:35 -0700 | [diff] [blame] | 138 | // Names must be passed separately since they are skipped in RawContactModifier.parseValues |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 139 | if (!TextUtils.isEmpty(displayName)) { |
| 140 | intent.putExtra(ContactsContract.Intents.Insert.NAME, displayName); |
| 141 | } |
Walter Jang | bf63a6d | 2015-05-05 09:14:35 -0700 | [diff] [blame] | 142 | if (!TextUtils.isEmpty(phoneticName)) { |
| 143 | intent.putExtra(ContactsContract.Intents.Insert.PHONETIC_NAME, phoneticName); |
| 144 | } |
Walter Jang | 5a7a23b | 2015-03-06 10:54:26 -0800 | [diff] [blame] | 145 | } |
| 146 | } |