blob: b867b3181e29475b229393403a9de7251bb26728 [file] [log] [blame]
Walter Jang5a7a23b2015-03-06 10:54:26 -08001/*
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 */
16package com.android.contacts.editor;
17
John Shao41c68862016-08-17 21:02:41 -070018import android.content.ContentValues;
19import android.content.Context;
20import android.content.Intent;
21import android.net.Uri;
22import android.provider.ContactsContract;
23import android.provider.ContactsContract.Contacts;
24import android.text.TextUtils;
25
Gary Mai363af602016-09-28 10:01:23 -070026import com.android.contacts.activities.ContactEditorActivity;
Gary Maia6c80b32016-09-30 16:34:55 -070027import com.android.contacts.activities.ContactEditorSpringBoardActivity;
Walter Jang5a7a23b2015-03-06 10:54:26 -080028import com.android.contacts.common.model.RawContactDeltaList;
29import com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette;
30
Walter Jang5a7a23b2015-03-06 10:54:26 -080031import java.util.ArrayList;
32
33/**
34 * Creates Intents to edit contacts.
35 */
36public class EditorIntents {
37
38 private EditorIntents() {
39 }
40
41 /**
Gary Maia6c80b32016-09-30 16:34:55 -070042 * Returns an Intent to start the {@link ContactEditorSpringBoardActivity} for an
Walter Jang5a7a23b2015-03-06 10:54:26 -080043 * existing contact.
44 */
Gary Maia6c80b32016-09-30 16:34:55 -070045 public static Intent createEditContactIntent(Context context, Uri uri,
Wenyi Wangc41a1e52016-01-29 17:01:35 +000046 MaterialPalette materialPalette, long photoId) {
Gary Maia6c80b32016-09-30 16:34:55 -070047 final Intent intent = new Intent(Intent.ACTION_EDIT, uri, context,
48 ContactEditorSpringBoardActivity.class);
Walter Jang921287e2015-03-10 09:53:36 -070049 putMaterialPalette(intent, materialPalette);
Walter Jangac679af2015-06-01 12:17:06 -070050 putPhotoId(intent, photoId);
Walter Jang5a7a23b2015-03-06 10:54:26 -080051 return intent;
52 }
53
Gary Maib9065dd2016-11-08 10:49:00 -080054 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 Jang5a7a23b2015-03-06 10:54:26 -080063 /**
Gary Maia6c80b32016-09-30 16:34:55 -070064 * 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 Mai363af602016-09-28 10:01:23 -070077 * Returns an Intent to start the {@link ContactEditorActivity} for a new contact with
Walter Jang5a7a23b2015-03-06 10:54:26 -080078 * the field values specified by rawContactDeltaList pre-populate in the form.
79 */
Gary Mai363af602016-09-28 10:01:23 -070080 public static Intent createInsertContactIntent(Context context,
John Shao41c68862016-08-17 21:02:41 -070081 RawContactDeltaList rawContactDeltaList, String displayName, String phoneticName,
82 /* Bundle updatedPhotos, */ boolean isNewLocalProfile) {
83 final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI,
Gary Mai363af602016-09-28 10:01:23 -070084 context, ContactEditorActivity.class);
Walter Jang8bac28b2016-08-30 10:34:55 -070085 intent.putExtra(
Gary Mai363af602016-09-28 10:01:23 -070086 ContactEditorFragment.INTENT_EXTRA_NEW_LOCAL_PROFILE, isNewLocalProfile);
John Shaof8f6f952016-10-21 18:57:36 -070087 putRawContactDeltaValues(intent, rawContactDeltaList, displayName, phoneticName);
Walter Jang5a7a23b2015-03-06 10:54:26 -080088 return intent;
89 }
90
91 /**
Gary Mai678108e2016-10-26 14:34:33 -070092 * Returns an Intent to edit a different raw contact in the editor with whatever
Gary Mai363af602016-09-28 10:01:23 -070093 * values were already entered on the current editor.
Walter Jang5a7a23b2015-03-06 10:54:26 -080094 */
Gary Mai678108e2016-10-26 14:34:33 -070095 public static Intent createEditOtherRawContactIntent(Context context, Uri uri,
96 long rawContactId, ArrayList<ContentValues> contentValues) {
Gary Maia6c80b32016-09-30 16:34:55 -070097 final Intent intent = new Intent(Intent.ACTION_EDIT, uri, context,
Gary Mai363af602016-09-28 10:01:23 -070098 ContactEditorActivity.class);
Walter Jang5a7a23b2015-03-06 10:54:26 -080099 intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
100 | Intent.FLAG_ACTIVITY_FORWARD_RESULT);
Gary Mai363af602016-09-28 10:01:23 -0700101 intent.putExtra(ContactEditorFragment.INTENT_EXTRA_ADD_TO_DEFAULT_DIRECTORY, "");
Gary Mai678108e2016-10-26 14:34:33 -0700102 intent.putExtra(ContactEditorFragment.INTENT_EXTRA_RAW_CONTACT_ID_TO_DISPLAY_ALONE,
103 rawContactId);
Walter Jang5a7a23b2015-03-06 10:54:26 -0800104 // 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 Jang921287e2015-03-10 09:53:36 -0700111 private static void putMaterialPalette(Intent intent, MaterialPalette materialPalette) {
112 if (materialPalette != null) {
Walter Jang7b0970f2016-09-01 10:40:19 -0700113 intent.putExtra(
Gary Mai363af602016-09-28 10:01:23 -0700114 ContactEditorFragment.INTENT_EXTRA_MATERIAL_PALETTE_PRIMARY_COLOR,
Walter Jang03debc62015-07-20 09:36:07 -0700115 materialPalette.mPrimaryColor);
Walter Jang7b0970f2016-09-01 10:40:19 -0700116 intent.putExtra(
Gary Mai363af602016-09-28 10:01:23 -0700117 ContactEditorFragment.INTENT_EXTRA_MATERIAL_PALETTE_SECONDARY_COLOR,
Walter Jang03debc62015-07-20 09:36:07 -0700118 materialPalette.mSecondaryColor);
Walter Jang921287e2015-03-10 09:53:36 -0700119 }
120 }
121
Walter Jangac679af2015-06-01 12:17:06 -0700122 private static void putPhotoId(Intent intent, long photoId) {
123 if (photoId >= 0) {
Gary Mai363af602016-09-28 10:01:23 -0700124 intent.putExtra(ContactEditorFragment.INTENT_EXTRA_PHOTO_ID, photoId);
Walter Jangac679af2015-06-01 12:17:06 -0700125 }
126 }
127
Walter Jang5a7a23b2015-03-06 10:54:26 -0800128 private static void putRawContactDeltaValues(Intent intent,
Walter Jangbf63a6d2015-05-05 09:14:35 -0700129 RawContactDeltaList rawContactDeltaList, String displayName, String phoneticName) {
Walter Jang5a7a23b2015-03-06 10:54:26 -0800130 // Pass on all the data that has been entered so far
Walter Jang921287e2015-03-10 09:53:36 -0700131 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 Jang5a7a23b2015-03-06 10:54:26 -0800137 }
Walter Jangbf63a6d2015-05-05 09:14:35 -0700138 // Names must be passed separately since they are skipped in RawContactModifier.parseValues
Walter Jang5a7a23b2015-03-06 10:54:26 -0800139 if (!TextUtils.isEmpty(displayName)) {
140 intent.putExtra(ContactsContract.Intents.Insert.NAME, displayName);
141 }
Walter Jangbf63a6d2015-05-05 09:14:35 -0700142 if (!TextUtils.isEmpty(phoneticName)) {
143 intent.putExtra(ContactsContract.Intents.Insert.PHONETIC_NAME, phoneticName);
144 }
Walter Jang5a7a23b2015-03-06 10:54:26 -0800145 }
146}