Walter Jang | cab3dce | 2015-02-09 17:48:03 -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 | |
| 17 | package com.android.contacts.editor; |
| 18 | |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 19 | import android.content.Context; |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 20 | import android.content.res.Resources; |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 21 | import android.database.Cursor; |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 22 | import android.graphics.drawable.Drawable; |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 23 | import android.net.Uri; |
Gary Mai | 5336e6e | 2016-10-23 14:17:03 -0700 | [diff] [blame] | 24 | import android.os.Bundle; |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 25 | import android.os.Parcel; |
| 26 | import android.os.Parcelable; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 27 | import android.provider.ContactsContract.CommonDataKinds.Email; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 28 | import android.provider.ContactsContract.CommonDataKinds.Event; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 29 | import android.provider.ContactsContract.CommonDataKinds.GroupMembership; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 30 | import android.provider.ContactsContract.CommonDataKinds.Im; |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 31 | import android.provider.ContactsContract.CommonDataKinds.Nickname; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 32 | import android.provider.ContactsContract.CommonDataKinds.Note; |
| 33 | import android.provider.ContactsContract.CommonDataKinds.Organization; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 34 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 35 | import android.provider.ContactsContract.CommonDataKinds.Photo; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 36 | import android.provider.ContactsContract.CommonDataKinds.Relation; |
| 37 | import android.provider.ContactsContract.CommonDataKinds.SipAddress; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 38 | import android.provider.ContactsContract.CommonDataKinds.StructuredName; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 39 | import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; |
| 40 | import android.provider.ContactsContract.CommonDataKinds.Website; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 41 | import android.text.TextUtils; |
| 42 | import android.util.AttributeSet; |
| 43 | import android.util.Log; |
| 44 | import android.view.LayoutInflater; |
Walter Jang | b1c8762 | 2015-02-13 17:51:38 -0800 | [diff] [blame] | 45 | import android.view.View; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 46 | import android.view.ViewGroup; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 47 | import android.widget.AdapterView; |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 48 | import android.widget.ImageView; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 49 | import android.widget.LinearLayout; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 50 | import android.widget.ListPopupWindow; |
Walter Jang | 2d3f31c | 2015-06-18 23:15:31 -0700 | [diff] [blame] | 51 | import android.widget.TextView; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 52 | |
Gary Mai | b6e28d2 | 2016-09-12 14:04:53 -0700 | [diff] [blame] | 53 | import com.android.contacts.R; |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 54 | import com.android.contacts.common.GeoUtil; |
| 55 | import com.android.contacts.common.compat.PhoneNumberUtilsCompat; |
Gary Mai | b6e28d2 | 2016-09-12 14:04:53 -0700 | [diff] [blame] | 56 | import com.android.contacts.common.model.AccountTypeManager; |
| 57 | import com.android.contacts.common.model.RawContactDelta; |
| 58 | import com.android.contacts.common.model.RawContactDeltaList; |
| 59 | import com.android.contacts.common.model.RawContactModifier; |
| 60 | import com.android.contacts.common.model.ValuesDelta; |
| 61 | import com.android.contacts.common.model.account.AccountDisplayInfo; |
| 62 | import com.android.contacts.common.model.account.AccountDisplayInfoFactory; |
| 63 | import com.android.contacts.common.model.account.AccountType; |
| 64 | import com.android.contacts.common.model.account.AccountWithDataSet; |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 65 | import com.android.contacts.common.model.dataitem.CustomDataItem; |
Gary Mai | b6e28d2 | 2016-09-12 14:04:53 -0700 | [diff] [blame] | 66 | import com.android.contacts.common.model.dataitem.DataKind; |
| 67 | import com.android.contacts.common.util.AccountsListAdapter; |
| 68 | import com.android.contacts.common.util.MaterialColorMapUtils; |
| 69 | import com.android.contacts.util.UiClosables; |
| 70 | |
Walter Jang | 708774a | 2015-10-16 09:32:06 -0700 | [diff] [blame] | 71 | import java.io.FileNotFoundException; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 72 | import java.util.ArrayList; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 73 | import java.util.Arrays; |
| 74 | import java.util.Comparator; |
Walter Jang | 19d985f | 2015-07-01 13:36:27 -0700 | [diff] [blame] | 75 | import java.util.HashMap; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 76 | import java.util.List; |
Walter Jang | 19d985f | 2015-07-01 13:36:27 -0700 | [diff] [blame] | 77 | import java.util.Map; |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 78 | import java.util.Set; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 79 | import java.util.TreeSet; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 82 | * View to display information from multiple {@link RawContactDelta}s grouped together. |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 83 | */ |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 84 | public class RawContactEditorView extends LinearLayout implements View.OnClickListener { |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 85 | |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 86 | static final String TAG = "RawContactEditorView"; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 87 | |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 88 | /** |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 89 | * Callbacks for hosts of {@link RawContactEditorView}s. |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 90 | */ |
| 91 | public interface Listener { |
| 92 | |
| 93 | /** |
Walter Jang | 151f3e6 | 2015-02-26 15:29:40 -0800 | [diff] [blame] | 94 | * Invoked when the structured name editor field has changed. |
| 95 | * |
| 96 | * @param rawContactId The raw contact ID from the underlying {@link RawContactDelta}. |
| 97 | * @param valuesDelta The values from the underlying {@link RawContactDelta}. |
| 98 | */ |
| 99 | public void onNameFieldChanged(long rawContactId, ValuesDelta valuesDelta); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 100 | |
| 101 | /** |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 102 | * Invoked when the editor should rebind editors for a new account. |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 103 | * |
| 104 | * @param oldState Old data being edited. |
| 105 | * @param oldAccount Old account associated with oldState. |
| 106 | * @param newAccount New account to be used. |
| 107 | */ |
| 108 | public void onRebindEditorsForNewContact(RawContactDelta oldState, |
| 109 | AccountWithDataSet oldAccount, AccountWithDataSet newAccount); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * Invoked when no editors could be bound for the contact. |
| 113 | */ |
| 114 | public void onBindEditorsFailed(); |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * Invoked after editors have been bound for the contact. |
| 118 | */ |
| 119 | public void onEditorsBound(); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 120 | } |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 121 | /** |
| 122 | * Sorts kinds roughly the same as quick contacts; we diverge in the following ways: |
| 123 | * <ol> |
| 124 | * <li>All names are together at the top.</li> |
| 125 | * <li>IM is moved up after addresses</li> |
| 126 | * <li>SIP addresses are moved to below phone numbers</li> |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 127 | * <li>Group membership is placed at the end</li> |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 128 | * </ol> |
| 129 | */ |
| 130 | private static final class MimeTypeComparator implements Comparator<String> { |
| 131 | |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 132 | private static final List<String> MIME_TYPE_ORDER = Arrays.asList(new String[] { |
| 133 | StructuredName.CONTENT_ITEM_TYPE, |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 134 | Nickname.CONTENT_ITEM_TYPE, |
Walter Jang | 2ae2175 | 2015-09-25 11:25:38 -0700 | [diff] [blame] | 135 | Organization.CONTENT_ITEM_TYPE, |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 136 | Phone.CONTENT_ITEM_TYPE, |
| 137 | SipAddress.CONTENT_ITEM_TYPE, |
| 138 | Email.CONTENT_ITEM_TYPE, |
| 139 | StructuredPostal.CONTENT_ITEM_TYPE, |
| 140 | Im.CONTENT_ITEM_TYPE, |
| 141 | Website.CONTENT_ITEM_TYPE, |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 142 | Event.CONTENT_ITEM_TYPE, |
| 143 | Relation.CONTENT_ITEM_TYPE, |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 144 | Note.CONTENT_ITEM_TYPE, |
| 145 | GroupMembership.CONTENT_ITEM_TYPE |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 146 | }); |
| 147 | |
| 148 | @Override |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 149 | public int compare(String mimeType1, String mimeType2) { |
| 150 | if (mimeType1 == mimeType2) return 0; |
| 151 | if (mimeType1 == null) return -1; |
| 152 | if (mimeType2 == null) return 1; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 153 | |
| 154 | int index1 = MIME_TYPE_ORDER.indexOf(mimeType1); |
| 155 | int index2 = MIME_TYPE_ORDER.indexOf(mimeType2); |
| 156 | |
| 157 | // Fallback to alphabetical ordering of the mime type if both are not found |
| 158 | if (index1 < 0 && index2 < 0) return mimeType1.compareTo(mimeType2); |
| 159 | if (index1 < 0) return 1; |
| 160 | if (index2 < 0) return -1; |
| 161 | |
| 162 | return index1 < index2 ? -1 : 1; |
| 163 | } |
| 164 | } |
| 165 | |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 166 | public static class SavedState extends BaseSavedState { |
| 167 | |
| 168 | public static final Parcelable.Creator<SavedState> CREATOR = |
| 169 | new Parcelable.Creator<SavedState>() { |
| 170 | public SavedState createFromParcel(Parcel in) { |
| 171 | return new SavedState(in); |
| 172 | } |
| 173 | public SavedState[] newArray(int size) { |
| 174 | return new SavedState[size]; |
| 175 | } |
| 176 | }; |
| 177 | |
| 178 | private boolean mIsExpanded; |
| 179 | |
| 180 | public SavedState(Parcelable superState) { |
| 181 | super(superState); |
| 182 | } |
| 183 | |
| 184 | private SavedState(Parcel in) { |
| 185 | super(in); |
| 186 | mIsExpanded = in.readInt() != 0; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public void writeToParcel(Parcel out, int flags) { |
| 191 | super.writeToParcel(out, flags); |
| 192 | out.writeInt(mIsExpanded ? 1 : 0); |
| 193 | } |
| 194 | } |
| 195 | |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 196 | private RawContactEditorView.Listener mListener; |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 197 | |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 198 | private AccountTypeManager mAccountTypeManager; |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 199 | private AccountDisplayInfoFactory mAccountDisplayInfoFactory; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 200 | private LayoutInflater mLayoutInflater; |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 201 | |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 202 | private ViewIdGenerator mViewIdGenerator; |
Walter Jang | f46abd8 | 2015-02-20 16:52:04 -0800 | [diff] [blame] | 203 | private MaterialColorMapUtils.MaterialPalette mMaterialPalette; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 204 | private boolean mHasNewContact; |
| 205 | private boolean mIsUserProfile; |
| 206 | private AccountWithDataSet mPrimaryAccount; |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 207 | private RawContactDeltaList mRawContactDeltas; |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 208 | private RawContactDelta mCurrentRawContactDelta; |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 209 | private long mRawContactIdToDisplayAlone = -1; |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 210 | private Map<String, KindSectionData> mKindSectionDataMap = new HashMap<>(); |
| 211 | private Set<String> mSortedMimetypes = new TreeSet<>(new MimeTypeComparator()); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 212 | |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 213 | // Account header |
| 214 | private View mAccountHeaderContainer; |
Gary Mai | 079598f | 2016-11-03 15:02:45 -0700 | [diff] [blame] | 215 | private TextView mAccountHeaderPrimaryText; |
| 216 | private TextView mAccountHeaderSecondaryText; |
Tingting Wang | 91cee28 | 2015-10-07 13:48:17 -0700 | [diff] [blame] | 217 | private ImageView mAccountHeaderIcon; |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 218 | private ImageView mAccountHeaderExpanderIcon; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 219 | |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 220 | private PhotoEditorView mPhotoView; |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 221 | private ViewGroup mKindSectionViews; |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 222 | private Map<String, KindSectionView> mKindSectionViewMap = new HashMap<>(); |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 223 | private View mMoreFields; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 224 | |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 225 | private boolean mIsExpanded; |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 226 | |
Gary Mai | 5336e6e | 2016-10-23 14:17:03 -0700 | [diff] [blame] | 227 | private Bundle mIntentExtras; |
| 228 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 229 | private ValuesDelta mPhotoValuesDelta; |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 230 | |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 231 | public RawContactEditorView(Context context) { |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 232 | super(context); |
| 233 | } |
| 234 | |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 235 | public RawContactEditorView(Context context, AttributeSet attrs) { |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 236 | super(context, attrs); |
| 237 | } |
| 238 | |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 239 | /** |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 240 | * Sets the receiver for {@link RawContactEditorView} callbacks. |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 241 | */ |
| 242 | public void setListener(Listener listener) { |
| 243 | mListener = listener; |
| 244 | } |
| 245 | |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 246 | @Override |
| 247 | protected void onFinishInflate() { |
| 248 | super.onFinishInflate(); |
| 249 | |
| 250 | mAccountTypeManager = AccountTypeManager.getInstance(getContext()); |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 251 | mAccountDisplayInfoFactory = AccountDisplayInfoFactory.forWritableAccounts(getContext()); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 252 | mLayoutInflater = (LayoutInflater) |
| 253 | getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 254 | |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 255 | // Account header |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 256 | mAccountHeaderContainer = findViewById(R.id.account_header_container); |
Gary Mai | 079598f | 2016-11-03 15:02:45 -0700 | [diff] [blame] | 257 | mAccountHeaderPrimaryText = (TextView) findViewById(R.id.account_type); |
| 258 | mAccountHeaderSecondaryText = (TextView) findViewById(R.id.account_name); |
Tingting Wang | 91cee28 | 2015-10-07 13:48:17 -0700 | [diff] [blame] | 259 | mAccountHeaderIcon = (ImageView) findViewById(R.id.account_type_icon); |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 260 | mAccountHeaderExpanderIcon = (ImageView) findViewById(R.id.account_expander_icon); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 261 | |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 262 | mPhotoView = (PhotoEditorView) findViewById(R.id.photo_editor); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 263 | mKindSectionViews = (LinearLayout) findViewById(R.id.kind_section_views); |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 264 | mMoreFields = findViewById(R.id.more_fields); |
| 265 | mMoreFields.setOnClickListener(this); |
| 266 | } |
| 267 | |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 268 | @Override |
| 269 | public void onClick(View view) { |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 270 | if (view.getId() == R.id.more_fields) { |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 271 | showAllFields(); |
Walter Jang | b6ca272 | 2015-02-20 11:10:25 -0800 | [diff] [blame] | 272 | } |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | @Override |
| 276 | public void setEnabled(boolean enabled) { |
| 277 | super.setEnabled(enabled); |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 278 | final int childCount = mKindSectionViews.getChildCount(); |
| 279 | for (int i = 0; i < childCount; i++) { |
| 280 | mKindSectionViews.getChildAt(i).setEnabled(enabled); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 284 | @Override |
| 285 | public Parcelable onSaveInstanceState() { |
| 286 | final Parcelable superState = super.onSaveInstanceState(); |
| 287 | final SavedState savedState = new SavedState(superState); |
| 288 | savedState.mIsExpanded = mIsExpanded; |
| 289 | return savedState; |
| 290 | } |
| 291 | |
| 292 | @Override |
| 293 | public void onRestoreInstanceState(Parcelable state) { |
| 294 | if(!(state instanceof SavedState)) { |
| 295 | super.onRestoreInstanceState(state); |
| 296 | return; |
| 297 | } |
| 298 | final SavedState savedState = (SavedState) state; |
| 299 | super.onRestoreInstanceState(savedState.getSuperState()); |
| 300 | mIsExpanded = savedState.mIsExpanded; |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 301 | if (mIsExpanded) { |
| 302 | showAllFields(); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 306 | /** |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 307 | * Pass through to {@link PhotoEditorView#setListener}. |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 308 | */ |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 309 | public void setPhotoListener(PhotoEditorView.Listener listener) { |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 310 | mPhotoView.setListener(listener); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 313 | public void removePhoto() { |
Walter Jang | 45b86d5 | 2015-10-15 15:23:16 -0700 | [diff] [blame] | 314 | mPhotoValuesDelta.setFromTemplate(true); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 315 | mPhotoValuesDelta.put(Photo.PHOTO, (byte[]) null); |
Gary Mai | 1872418 | 2016-09-20 17:33:30 -0700 | [diff] [blame] | 316 | mPhotoValuesDelta.put(Photo.PHOTO_FILE_ID, (String) null); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 317 | |
| 318 | mPhotoView.removePhoto(); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /** |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 322 | * Pass through to {@link PhotoEditorView#setFullSizedPhoto(Uri)}. |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 323 | */ |
| 324 | public void setFullSizePhoto(Uri photoUri) { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 325 | mPhotoView.setFullSizedPhoto(photoUri); |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 326 | } |
| 327 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 328 | public void updatePhoto(Uri photoUri) { |
Walter Jang | 45b86d5 | 2015-10-15 15:23:16 -0700 | [diff] [blame] | 329 | mPhotoValuesDelta.setFromTemplate(false); |
Wenyi Wang | b8ab861 | 2015-10-27 11:18:49 -0700 | [diff] [blame] | 330 | // Unset primary for all photos |
Wenyi Wang | 9086fb9 | 2015-11-16 09:58:20 -0800 | [diff] [blame] | 331 | unsetSuperPrimaryFromAllPhotos(); |
Wenyi Wang | b8ab861 | 2015-10-27 11:18:49 -0700 | [diff] [blame] | 332 | // Mark the currently displayed photo as primary |
| 333 | mPhotoValuesDelta.setSuperPrimary(true); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 334 | |
Wenyi Wang | 4c9cf3a | 2015-10-15 17:58:23 -0700 | [diff] [blame] | 335 | // Even though high-res photos cannot be saved by passing them via |
| 336 | // an EntityDeltaList (since they cause the Bundle size limit to be |
| 337 | // exceeded), we still pass a low-res thumbnail. This simplifies |
| 338 | // code all over the place, because we don't have to test whether |
| 339 | // there is a change in EITHER the delta-list OR a changed photo... |
| 340 | // this way, there is always a change in the delta-list. |
| 341 | try { |
| 342 | final byte[] bytes = EditorUiUtils.getCompressedThumbnailBitmapBytes( |
| 343 | getContext(), photoUri); |
| 344 | if (bytes != null) { |
| 345 | mPhotoValuesDelta.setPhoto(bytes); |
| 346 | } |
| 347 | } catch (FileNotFoundException e) { |
| 348 | elog("Failed to get bitmap from photo Uri"); |
| 349 | } |
| 350 | |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 351 | mPhotoView.setFullSizedPhoto(photoUri); |
| 352 | } |
| 353 | |
Wenyi Wang | 9086fb9 | 2015-11-16 09:58:20 -0800 | [diff] [blame] | 354 | private void unsetSuperPrimaryFromAllPhotos() { |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 355 | for (int i = 0; i < mRawContactDeltas.size(); i++) { |
| 356 | final RawContactDelta rawContactDelta = mRawContactDeltas.get(i); |
| 357 | if (!rawContactDelta.hasMimeEntries(Photo.CONTENT_ITEM_TYPE)) { |
| 358 | continue; |
| 359 | } |
| 360 | final List<ValuesDelta> photosDeltas = |
| 361 | mRawContactDeltas.get(i).getMimeEntries(Photo.CONTENT_ITEM_TYPE); |
| 362 | if (photosDeltas == null) { |
| 363 | continue; |
| 364 | } |
| 365 | for (int j = 0; j < photosDeltas.size(); j++) { |
| 366 | photosDeltas.get(j).setSuperPrimary(false); |
Walter Jang | 3f18d61 | 2015-10-07 16:01:05 -0700 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
Walter Jang | 41b3ea1 | 2015-03-09 17:30:06 -0700 | [diff] [blame] | 371 | /** |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 372 | * Pass through to {@link PhotoEditorView#isWritablePhotoSet}. |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 373 | */ |
| 374 | public boolean isWritablePhotoSet() { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 375 | return mPhotoView.isWritablePhotoSet(); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /** |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 379 | * Get the raw contact ID for the current photo. |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 380 | */ |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 381 | public long getPhotoRawContactId() { |
Gary Mai | da20b47 | 2016-09-20 14:46:40 -0700 | [diff] [blame] | 382 | return mCurrentRawContactDelta.getRawContactId(); |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Gary Mai | 698cee7 | 2016-09-19 16:09:54 -0700 | [diff] [blame] | 385 | public StructuredNameEditorView getNameEditorView() { |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 386 | final KindSectionView nameKindSectionView = mKindSectionViewMap |
Gary Mai | 698cee7 | 2016-09-19 16:09:54 -0700 | [diff] [blame] | 387 | .get(StructuredName.CONTENT_ITEM_TYPE); |
| 388 | return nameKindSectionView == null |
| 389 | ? null : nameKindSectionView.getNameEditorView(); |
Walter Jang | 4f5594a | 2015-10-06 18:40:31 -0700 | [diff] [blame] | 390 | } |
| 391 | |
Gary Mai | 220d10c | 2016-09-23 13:56:39 -0700 | [diff] [blame] | 392 | public RawContactDelta getCurrentRawContactDelta() { |
| 393 | return mCurrentRawContactDelta; |
| 394 | } |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 395 | |
| 396 | /** |
Gary Mai | da20b47 | 2016-09-20 14:46:40 -0700 | [diff] [blame] | 397 | * Marks the raw contact photo given as primary for the aggregate contact. |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 398 | */ |
Gary Mai | da20b47 | 2016-09-20 14:46:40 -0700 | [diff] [blame] | 399 | public void setPrimaryPhoto() { |
Walter Jang | da258ff | 2015-11-17 11:06:02 -0800 | [diff] [blame] | 400 | |
| 401 | // Update values delta |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 402 | final ValuesDelta valuesDelta = mCurrentRawContactDelta |
| 403 | .getSuperPrimaryEntry(Photo.CONTENT_ITEM_TYPE); |
Gary Mai | da20b47 | 2016-09-20 14:46:40 -0700 | [diff] [blame] | 404 | if (valuesDelta == null) { |
| 405 | Log.wtf(TAG, "setPrimaryPhoto: had no ValuesDelta for the current RawContactDelta"); |
| 406 | return; |
| 407 | } |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 408 | valuesDelta.setFromTemplate(false); |
Wenyi Wang | 9086fb9 | 2015-11-16 09:58:20 -0800 | [diff] [blame] | 409 | unsetSuperPrimaryFromAllPhotos(); |
Wenyi Wang | b8ab861 | 2015-10-27 11:18:49 -0700 | [diff] [blame] | 410 | valuesDelta.setSuperPrimary(true); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 413 | public View getAggregationAnchorView() { |
Gary Mai | 698cee7 | 2016-09-19 16:09:54 -0700 | [diff] [blame] | 414 | final StructuredNameEditorView nameEditorView = getNameEditorView(); |
Gary Mai | 710802c | 2016-09-19 15:05:44 -0700 | [diff] [blame] | 415 | return nameEditorView != null ? nameEditorView.findViewById(R.id.anchor_view) : null; |
Walter Jang | d35e5ef | 2015-02-24 09:18:16 -0800 | [diff] [blame] | 416 | } |
| 417 | |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 418 | public void setGroupMetaData(Cursor groupMetaData) { |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 419 | final KindSectionView groupKindSectionView = |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 420 | mKindSectionViewMap.get(GroupMembership.CONTENT_ITEM_TYPE); |
| 421 | if (groupKindSectionView == null) { |
| 422 | return; |
| 423 | } |
| 424 | groupKindSectionView.setGroupMetaData(groupMetaData); |
| 425 | if (mIsExpanded) { |
| 426 | groupKindSectionView.setHideWhenEmpty(false); |
| 427 | groupKindSectionView.updateEmptyEditors(/* shouldAnimate =*/ true); |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
Gary Mai | 5336e6e | 2016-10-23 14:17:03 -0700 | [diff] [blame] | 431 | public void setIntentExtras(Bundle extras) { |
| 432 | mIntentExtras = extras; |
| 433 | } |
| 434 | |
Walter Jang | f46abd8 | 2015-02-20 16:52:04 -0800 | [diff] [blame] | 435 | public void setState(RawContactDeltaList rawContactDeltas, |
Walter Jang | 06f73a1 | 2015-06-17 11:15:48 -0700 | [diff] [blame] | 436 | MaterialColorMapUtils.MaterialPalette materialPalette, ViewIdGenerator viewIdGenerator, |
Gary Mai | da20b47 | 2016-09-20 14:46:40 -0700 | [diff] [blame] | 437 | boolean hasNewContact, boolean isUserProfile, AccountWithDataSet primaryAccount, |
Gary Mai | 5a00de3 | 2016-10-19 18:20:41 -0700 | [diff] [blame] | 438 | long rawContactIdToDisplayAlone) { |
Marcus Hagerott | f04c975 | 2016-09-08 15:22:57 -0700 | [diff] [blame] | 439 | |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 440 | mRawContactDeltas = rawContactDeltas; |
| 441 | mRawContactIdToDisplayAlone = rawContactIdToDisplayAlone; |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 442 | |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 443 | mKindSectionViewMap.clear(); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 444 | mKindSectionViews.removeAllViews(); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 445 | mMoreFields.setVisibility(View.VISIBLE); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 446 | |
Walter Jang | f46abd8 | 2015-02-20 16:52:04 -0800 | [diff] [blame] | 447 | mMaterialPalette = materialPalette; |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 448 | mViewIdGenerator = viewIdGenerator; |
Tingting Wang | f695eb3 | 2015-10-15 18:45:15 -0700 | [diff] [blame] | 449 | |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 450 | mHasNewContact = hasNewContact; |
| 451 | mIsUserProfile = isUserProfile; |
| 452 | mPrimaryAccount = primaryAccount; |
| 453 | if (mPrimaryAccount == null) { |
Marcus Hagerott | 949d4e8 | 2016-09-20 13:23:05 -0700 | [diff] [blame] | 454 | mPrimaryAccount = ContactEditorUtils.create(getContext()).getOnlyOrDefaultAccount(); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 455 | } |
| 456 | vlog("state: primary " + mPrimaryAccount); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 457 | |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 458 | // Parse the given raw contact deltas |
| 459 | if (rawContactDeltas == null || rawContactDeltas.isEmpty()) { |
| 460 | elog("No raw contact deltas"); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 461 | if (mListener != null) mListener.onBindEditorsFailed(); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 462 | return; |
| 463 | } |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 464 | pickRawContactDelta(); |
Gary Mai | 5336e6e | 2016-10-23 14:17:03 -0700 | [diff] [blame] | 465 | // Apply any intent extras now that we have selected a raw contact delta. |
| 466 | applyIntentExtras(); |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 467 | parseRawContactDelta(); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 468 | if (mKindSectionDataMap.isEmpty()) { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 469 | elog("No kind section data parsed from RawContactDelta(s)"); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 470 | if (mListener != null) mListener.onBindEditorsFailed(); |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 471 | return; |
| 472 | } |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 473 | |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 474 | final KindSectionData nameSectionData = |
| 475 | mKindSectionDataMap.get(StructuredName.CONTENT_ITEM_TYPE); |
| 476 | // Ensure that a structured name and photo exists |
| 477 | if (nameSectionData != null) { |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 478 | final RawContactDelta rawContactDelta = |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 479 | nameSectionData.getRawContactDelta(); |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 480 | RawContactModifier.ensureKindExists( |
| 481 | rawContactDelta, |
| 482 | rawContactDelta.getAccountType(mAccountTypeManager), |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 483 | StructuredName.CONTENT_ITEM_TYPE); |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 484 | RawContactModifier.ensureKindExists( |
| 485 | rawContactDelta, |
| 486 | rawContactDelta.getAccountType(mAccountTypeManager), |
Walter Jang | cbd431d | 2015-10-06 13:07:30 -0700 | [diff] [blame] | 487 | Photo.CONTENT_ITEM_TYPE); |
| 488 | } |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 489 | |
| 490 | // Setup the view |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 491 | addPhotoView(); |
Gary Mai | 079598f | 2016-11-03 15:02:45 -0700 | [diff] [blame] | 492 | setAccountInfo(); |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 493 | if (isReadOnlyRawContact()) { |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 494 | // We're want to display the inputs fields for a single read only raw contact |
| 495 | addReadOnlyRawContactEditorViews(); |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 496 | } else { |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 497 | setupEditorNormally(); |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 498 | } |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 499 | if (mListener != null) mListener.onEditorsBound(); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 500 | } |
| 501 | |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 502 | private void setupEditorNormally() { |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 503 | addKindSectionViews(); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 504 | |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 505 | mMoreFields.setVisibility(hasMoreFields() ? View.VISIBLE : View.GONE); |
| 506 | |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 507 | if (mIsExpanded) showAllFields(); |
| 508 | } |
| 509 | |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 510 | private boolean isReadOnlyRawContact() { |
| 511 | return !mCurrentRawContactDelta.getAccountType(mAccountTypeManager).areContactsWritable(); |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 514 | private void pickRawContactDelta() { |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 515 | vlog("parse: " + mRawContactDeltas.size() + " rawContactDelta(s)"); |
| 516 | for (int j = 0; j < mRawContactDeltas.size(); j++) { |
| 517 | final RawContactDelta rawContactDelta = mRawContactDeltas.get(j); |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 518 | vlog("parse: " + j + " rawContactDelta" + rawContactDelta); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 519 | if (rawContactDelta == null || !rawContactDelta.isVisible()) continue; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 520 | final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 521 | if (accountType == null) continue; |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 522 | |
| 523 | if (mRawContactIdToDisplayAlone > 0) { |
| 524 | // Look for the raw contact if specified. |
| 525 | if (rawContactDelta.getRawContactId().equals(mRawContactIdToDisplayAlone)) { |
| 526 | mCurrentRawContactDelta = rawContactDelta; |
| 527 | return; |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 528 | } |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 529 | } else if (mPrimaryAccount != null |
| 530 | && mPrimaryAccount.equals(rawContactDelta.getAccountWithDataSet())) { |
| 531 | // Otherwise try to find the one that matches the default. |
| 532 | mCurrentRawContactDelta = rawContactDelta; |
| 533 | return; |
| 534 | } else if (accountType.areContactsWritable()){ |
| 535 | // TODO: Find better raw contact delta |
| 536 | // Just select an arbitrary writable contact. |
| 537 | mCurrentRawContactDelta = rawContactDelta; |
Walter Jang | ac679af | 2015-06-01 12:17:06 -0700 | [diff] [blame] | 538 | } |
| 539 | } |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 540 | |
| 541 | } |
| 542 | |
Gary Mai | 5336e6e | 2016-10-23 14:17:03 -0700 | [diff] [blame] | 543 | private void applyIntentExtras() { |
| 544 | if (mIntentExtras == null || mIntentExtras.size() == 0) { |
| 545 | return; |
| 546 | } |
| 547 | final AccountTypeManager accountTypes = AccountTypeManager.getInstance(getContext()); |
| 548 | final AccountType type = mCurrentRawContactDelta.getAccountType(accountTypes); |
| 549 | |
| 550 | RawContactModifier.parseExtras(getContext(), type, mCurrentRawContactDelta, mIntentExtras); |
| 551 | mIntentExtras = null; |
| 552 | } |
| 553 | |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 554 | private void parseRawContactDelta() { |
| 555 | mKindSectionDataMap.clear(); |
| 556 | mSortedMimetypes.clear(); |
| 557 | |
| 558 | final AccountType accountType = mCurrentRawContactDelta.getAccountType(mAccountTypeManager); |
| 559 | final List<DataKind> dataKinds = accountType.getSortedDataKinds(); |
| 560 | final int dataKindSize = dataKinds == null ? 0 : dataKinds.size(); |
| 561 | vlog("parse: " + dataKindSize + " dataKinds(s)"); |
| 562 | |
| 563 | for (int i = 0; i < dataKindSize; i++) { |
| 564 | final DataKind dataKind = dataKinds.get(i); |
Gary Mai | d7faa65 | 2016-10-03 11:53:39 -0700 | [diff] [blame] | 565 | // Skip null and un-editable fields. |
| 566 | if (dataKind == null || !dataKind.editable) { |
| 567 | vlog("parse: " + i + |
| 568 | (dataKind == null ? " dropped null data kind" |
| 569 | : " dropped uneditable mimetype: " + dataKind.mimeType)); |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 570 | continue; |
| 571 | } |
| 572 | final String mimeType = dataKind.mimeType; |
| 573 | |
| 574 | // Skip psuedo mime types |
Gary Mai | ac5bd64 | 2016-10-12 10:31:36 -0700 | [diff] [blame] | 575 | if (DataKind.PSEUDO_MIME_TYPE_NAME.equals(mimeType) || |
| 576 | DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType)) { |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 577 | vlog("parse: " + i + " " + dataKind.mimeType + " dropped pseudo type"); |
| 578 | continue; |
| 579 | } |
| 580 | |
| 581 | // Skip custom fields |
| 582 | // TODO: Handle them when we implement editing custom fields. |
| 583 | if (CustomDataItem.MIMETYPE_CUSTOM_FIELD.equals(mimeType)) { |
| 584 | vlog("parse: " + i + " " + dataKind.mimeType + " dropped custom field"); |
| 585 | continue; |
| 586 | } |
| 587 | |
| 588 | final KindSectionData kindSectionData = |
| 589 | new KindSectionData(accountType, dataKind, mCurrentRawContactDelta); |
| 590 | mKindSectionDataMap.put(mimeType, kindSectionData); |
| 591 | mSortedMimetypes.add(mimeType); |
| 592 | |
| 593 | vlog("parse: " + i + " " + dataKind.mimeType + " " + |
| 594 | kindSectionData.getValuesDeltas().size() + " value(s) " + |
| 595 | kindSectionData.getNonEmptyValuesDeltas().size() + " non-empty value(s) " + |
| 596 | kindSectionData.getVisibleValuesDeltas().size() + |
| 597 | " visible value(s)"); |
| 598 | } |
Walter Jang | 3efae4a | 2015-02-18 11:12:00 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 601 | private void addReadOnlyRawContactEditorViews() { |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 602 | mKindSectionViews.removeAllViews(); |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 603 | final AccountTypeManager accountTypes = AccountTypeManager.getInstance( |
| 604 | getContext()); |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 605 | final AccountType type = mCurrentRawContactDelta.getAccountType(accountTypes); |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 606 | |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 607 | // Bail if invalid state or source |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 608 | if (type == null) return; |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 609 | |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 610 | // Make sure we have StructuredName |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 611 | RawContactModifier.ensureKindExists( |
| 612 | mCurrentRawContactDelta, type, StructuredName.CONTENT_ITEM_TYPE); |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 613 | |
| 614 | ValuesDelta primary; |
| 615 | |
| 616 | // Name |
| 617 | final Context context = getContext(); |
| 618 | final Resources res = context.getResources(); |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 619 | primary = mCurrentRawContactDelta.getPrimaryEntry(StructuredName.CONTENT_ITEM_TYPE); |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 620 | final String name = primary != null ? primary.getAsString(StructuredName.DISPLAY_NAME) : |
| 621 | getContext().getString(R.string.missing_name); |
| 622 | final Drawable nameDrawable = context.getDrawable(R.drawable.ic_person_24dp); |
| 623 | final String nameContentDescription = res.getString(R.string.header_name_entry); |
| 624 | bindData(nameDrawable, nameContentDescription, name, /* type */ null, |
| 625 | /* isFirstEntry */ true); |
| 626 | |
| 627 | // Phones |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 628 | final ArrayList<ValuesDelta> phones = mCurrentRawContactDelta |
| 629 | .getMimeEntries(Phone.CONTENT_ITEM_TYPE); |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 630 | final Drawable phoneDrawable = context.getDrawable(R.drawable.ic_phone_24dp); |
| 631 | final String phoneContentDescription = res.getString(R.string.header_phone_entry); |
| 632 | if (phones != null) { |
| 633 | boolean isFirstPhoneBound = true; |
| 634 | for (ValuesDelta phone : phones) { |
| 635 | final String phoneNumber = phone.getPhoneNumber(); |
| 636 | if (TextUtils.isEmpty(phoneNumber)) { |
| 637 | continue; |
| 638 | } |
| 639 | final String formattedNumber = PhoneNumberUtilsCompat.formatNumber( |
| 640 | phoneNumber, phone.getPhoneNormalizedNumber(), |
| 641 | GeoUtil.getCurrentCountryIso(getContext())); |
| 642 | CharSequence phoneType = null; |
| 643 | if (phone.hasPhoneType()) { |
| 644 | phoneType = Phone.getTypeLabel( |
| 645 | res, phone.getPhoneType(), phone.getPhoneLabel()); |
| 646 | } |
| 647 | bindData(phoneDrawable, phoneContentDescription, formattedNumber, phoneType, |
| 648 | isFirstPhoneBound, true); |
| 649 | isFirstPhoneBound = false; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | // Emails |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 654 | final ArrayList<ValuesDelta> emails = mCurrentRawContactDelta |
| 655 | .getMimeEntries(Email.CONTENT_ITEM_TYPE); |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 656 | final Drawable emailDrawable = context.getDrawable(R.drawable.ic_email_24dp); |
| 657 | final String emailContentDescription = res.getString(R.string.header_email_entry); |
| 658 | if (emails != null) { |
| 659 | boolean isFirstEmailBound = true; |
| 660 | for (ValuesDelta email : emails) { |
| 661 | final String emailAddress = email.getEmailData(); |
| 662 | if (TextUtils.isEmpty(emailAddress)) { |
| 663 | continue; |
| 664 | } |
| 665 | CharSequence emailType = null; |
| 666 | if (email.hasEmailType()) { |
| 667 | emailType = Email.getTypeLabel( |
| 668 | res, email.getEmailType(), email.getEmailLabel()); |
| 669 | } |
| 670 | bindData(emailDrawable, emailContentDescription, emailAddress, emailType, |
| 671 | isFirstEmailBound); |
| 672 | isFirstEmailBound = false; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | mKindSectionViews.setVisibility(mKindSectionViews.getChildCount() > 0 ? VISIBLE : GONE); |
| 677 | // Hide the "More fields" link |
| 678 | mMoreFields.setVisibility(GONE); |
| 679 | } |
| 680 | |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 681 | private void bindData(Drawable icon, String iconContentDescription, CharSequence data, |
| 682 | CharSequence type, boolean isFirstEntry) { |
| 683 | bindData(icon, iconContentDescription, data, type, isFirstEntry, false); |
| 684 | } |
| 685 | |
| 686 | private void bindData(Drawable icon, String iconContentDescription, CharSequence data, |
| 687 | CharSequence type, boolean isFirstEntry, boolean forceLTR) { |
Gary Mai | 34047d2 | 2016-11-17 10:36:59 -0800 | [diff] [blame^] | 688 | final View field = mLayoutInflater.inflate(R.layout.item_read_only_field, mKindSectionViews, |
| 689 | /* attachToRoot */ false); |
Gary Mai | 65971d0 | 2016-09-15 15:00:16 -0700 | [diff] [blame] | 690 | if (isFirstEntry) { |
| 691 | final ImageView imageView = (ImageView) field.findViewById(R.id.kind_icon); |
| 692 | imageView.setImageDrawable(icon); |
| 693 | imageView.setContentDescription(iconContentDescription); |
| 694 | } else { |
| 695 | final ImageView imageView = (ImageView) field.findViewById(R.id.kind_icon); |
| 696 | imageView.setVisibility(View.INVISIBLE); |
| 697 | imageView.setContentDescription(null); |
| 698 | } |
| 699 | final TextView dataView = (TextView) field.findViewById(R.id.data); |
| 700 | dataView.setText(data); |
| 701 | if (forceLTR) { |
| 702 | dataView.setTextDirection(View.TEXT_DIRECTION_LTR); |
| 703 | } |
| 704 | final TextView typeView = (TextView) field.findViewById(R.id.type); |
| 705 | if (!TextUtils.isEmpty(type)) { |
| 706 | typeView.setText(type); |
| 707 | } else { |
| 708 | typeView.setVisibility(View.GONE); |
| 709 | } |
| 710 | mKindSectionViews.addView(field); |
Walter Jang | 9a55237 | 2016-08-24 11:51:05 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Gary Mai | 079598f | 2016-11-03 15:02:45 -0700 | [diff] [blame] | 713 | private void setAccountInfo() { |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 714 | final AccountDisplayInfo account = |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 715 | mAccountDisplayInfoFactory.getAccountDisplayInfoFor(mCurrentRawContactDelta); |
Marcus Hagerott | fac695a | 2016-08-24 17:02:40 -0700 | [diff] [blame] | 716 | |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 717 | // Get the account information for the primary raw contact delta |
Gary Mai | 079598f | 2016-11-03 15:02:45 -0700 | [diff] [blame] | 718 | if (isReadOnlyRawContact()) { |
| 719 | final String accountType = account.getTypeLabel().toString(); |
| 720 | setAccountHeader(accountType, |
| 721 | getResources().getString( |
| 722 | R.string.editor_account_selector_read_only_title, accountType)); |
| 723 | } else { |
| 724 | final String accountLabel = mIsUserProfile |
| 725 | ? EditorUiUtils.getAccountHeaderLabelForMyProfile(getContext(), account) |
| 726 | : account.getNameLabel().toString(); |
| 727 | setAccountHeader(getResources().getString(R.string.editor_account_selector_title), |
| 728 | accountLabel); |
| 729 | } |
Gary Mai | d7faa65 | 2016-10-03 11:53:39 -0700 | [diff] [blame] | 730 | |
| 731 | // If we're saving a new contact and there are multiple accounts, add the account selector. |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 732 | final List<AccountWithDataSet> accounts = |
| 733 | AccountTypeManager.getInstance(getContext()).getAccounts(true); |
Gary Mai | d7faa65 | 2016-10-03 11:53:39 -0700 | [diff] [blame] | 734 | if (mHasNewContact && !mIsUserProfile && accounts.size() > 1) { |
| 735 | addAccountSelector(mCurrentRawContactDelta); |
Walter Jang | 2370954 | 2015-10-22 12:50:58 -0700 | [diff] [blame] | 736 | } |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Gary Mai | 079598f | 2016-11-03 15:02:45 -0700 | [diff] [blame] | 739 | private void setAccountHeader(String primaryText, String secondaryText) { |
| 740 | mAccountHeaderPrimaryText.setText(primaryText); |
| 741 | mAccountHeaderSecondaryText.setText(secondaryText); |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 742 | |
| 743 | // Set the icon |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 744 | final AccountType accountType = |
| 745 | mCurrentRawContactDelta.getRawContactAccountType(getContext()); |
| 746 | mAccountHeaderIcon.setImageDrawable(accountType.getDisplayIcon(getContext())); |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 747 | |
| 748 | // Set the content description |
| 749 | mAccountHeaderContainer.setContentDescription( |
Gary Mai | 34047d2 | 2016-11-17 10:36:59 -0800 | [diff] [blame^] | 750 | EditorUiUtils.getAccountInfoContentDescription(secondaryText, primaryText)); |
Walter Jang | be5e1b1 | 2015-10-17 11:38:29 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Gary Mai | d7faa65 | 2016-10-03 11:53:39 -0700 | [diff] [blame] | 753 | private void addAccountSelector(final RawContactDelta rawContactDelta) { |
| 754 | // Add handlers for choosing another account to save to. |
| 755 | mAccountHeaderExpanderIcon.setVisibility(View.VISIBLE); |
| 756 | mAccountHeaderContainer.setOnClickListener(new View.OnClickListener() { |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 757 | @Override |
| 758 | public void onClick(View v) { |
| 759 | final ListPopupWindow popup = new ListPopupWindow(getContext(), null); |
| 760 | final AccountsListAdapter adapter = |
| 761 | new AccountsListAdapter(getContext(), |
| 762 | AccountsListAdapter.AccountListFilter.ACCOUNTS_CONTACT_WRITABLE, |
| 763 | mPrimaryAccount); |
Gary Mai | 46cb310 | 2016-08-10 18:14:09 -0700 | [diff] [blame] | 764 | popup.setWidth(mAccountHeaderContainer.getWidth()); |
| 765 | popup.setAnchorView(mAccountHeaderContainer); |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 766 | popup.setAdapter(adapter); |
| 767 | popup.setModal(true); |
| 768 | popup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NOT_NEEDED); |
| 769 | popup.setOnItemClickListener(new AdapterView.OnItemClickListener() { |
| 770 | @Override |
| 771 | public void onItemClick(AdapterView<?> parent, View view, int position, |
| 772 | long id) { |
| 773 | UiClosables.closeQuietly(popup); |
| 774 | final AccountWithDataSet newAccount = adapter.getItem(position); |
| 775 | if (mListener != null && !mPrimaryAccount.equals(newAccount)) { |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 776 | mIsExpanded = false; |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 777 | mListener.onRebindEditorsForNewContact( |
Walter Jang | 82acd42 | 2015-10-17 14:01:27 -0700 | [diff] [blame] | 778 | rawContactDelta, |
Walter Jang | 708ea9e | 2015-09-10 15:42:05 -0700 | [diff] [blame] | 779 | mPrimaryAccount, |
| 780 | newAccount); |
| 781 | } |
| 782 | } |
| 783 | }); |
| 784 | popup.show(); |
| 785 | } |
Gary Mai | d7faa65 | 2016-10-03 11:53:39 -0700 | [diff] [blame] | 786 | }); |
Tingting Wang | 655ad1a | 2015-10-05 17:51:14 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 789 | private void addPhotoView() { |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 790 | if (!mCurrentRawContactDelta.hasMimeEntries(Photo.CONTENT_ITEM_TYPE)) { |
| 791 | wlog("No photo mimetype for this raw contact."); |
Gary Mai | da20b47 | 2016-09-20 14:46:40 -0700 | [diff] [blame] | 792 | mPhotoView.setVisibility(GONE); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 793 | return; |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 794 | } else { |
Gary Mai | da20b47 | 2016-09-20 14:46:40 -0700 | [diff] [blame] | 795 | mPhotoView.setVisibility(VISIBLE); |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 796 | } |
Walter Jang | 06f73a1 | 2015-06-17 11:15:48 -0700 | [diff] [blame] | 797 | |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 798 | final ValuesDelta superPrimaryDelta = mCurrentRawContactDelta |
| 799 | .getSuperPrimaryEntry(Photo.CONTENT_ITEM_TYPE); |
Gary Mai | da20b47 | 2016-09-20 14:46:40 -0700 | [diff] [blame] | 800 | if (superPrimaryDelta == null) { |
| 801 | Log.wtf(TAG, "addPhotoView: no ValueDelta found for current RawContactDelta" |
| 802 | + "that supports a photo."); |
| 803 | mPhotoView.setVisibility(GONE); |
| 804 | return; |
| 805 | } |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 806 | // Set the photo view |
Gary Mai | 1872418 | 2016-09-20 17:33:30 -0700 | [diff] [blame] | 807 | mPhotoView.setPalette(mMaterialPalette); |
| 808 | mPhotoView.setPhoto(superPrimaryDelta); |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 809 | |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 810 | if (isReadOnlyRawContact()) { |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 811 | mPhotoView.setReadOnly(true); |
| 812 | return; |
| 813 | } |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 814 | mPhotoView.setReadOnly(false); |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 815 | mPhotoValuesDelta = superPrimaryDelta; |
Walter Jang | 31a74ad | 2015-10-02 19:17:39 -0700 | [diff] [blame] | 816 | } |
| 817 | |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 818 | private void addKindSectionViews() { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 819 | int i = -1; |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 820 | |
| 821 | for (String mimeType : mSortedMimetypes) { |
Walter Jang | 3e5ae0d | 2015-09-20 12:43:37 -0700 | [diff] [blame] | 822 | i++; |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 823 | // Ignore mime types that we've already handled |
| 824 | if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) { |
| 825 | vlog("kind: " + i + " " + mimeType + " dropped"); |
| 826 | continue; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 827 | } |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 828 | final KindSectionView kindSectionView; |
Gary Mai | 4ceabed | 2016-09-16 12:14:13 -0700 | [diff] [blame] | 829 | final KindSectionData kindSectionData = mKindSectionDataMap.get(mimeType); |
Gary Mai | 698cee7 | 2016-09-19 16:09:54 -0700 | [diff] [blame] | 830 | kindSectionView = inflateKindSectionView(mKindSectionViews, kindSectionData, mimeType); |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 831 | mKindSectionViews.addView(kindSectionView); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 832 | |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 833 | // Keep a pointer to the KindSectionView for each mimeType |
| 834 | mKindSectionViewMap.put(mimeType, kindSectionView); |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 835 | } |
Walter Jang | f10ca15 | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 838 | private KindSectionView inflateKindSectionView(ViewGroup viewGroup, |
Gary Mai | 698cee7 | 2016-09-19 16:09:54 -0700 | [diff] [blame] | 839 | KindSectionData kindSectionData, String mimeType) { |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 840 | final KindSectionView kindSectionView = (KindSectionView) |
| 841 | mLayoutInflater.inflate(R.layout.item_kind_section, viewGroup, |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 842 | /* attachToRoot =*/ false); |
Walter Jang | 45b86d5 | 2015-10-15 15:23:16 -0700 | [diff] [blame] | 843 | kindSectionView.setIsUserProfile(mIsUserProfile); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 844 | |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 845 | if (Phone.CONTENT_ITEM_TYPE.equals(mimeType) |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 846 | || Email.CONTENT_ITEM_TYPE.equals(mimeType)) { |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 847 | // Phone numbers and email addresses are always displayed, |
| 848 | // even if they are empty |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 849 | kindSectionView.setHideWhenEmpty(false); |
| 850 | } |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 851 | |
Walter Jang | 192a01c | 2015-09-22 15:23:55 -0700 | [diff] [blame] | 852 | // Since phone numbers and email addresses displayed even if they are empty, |
| 853 | // they will be the only types you add new values to initially for new contacts |
| 854 | kindSectionView.setShowOneEmptyEditor(true); |
| 855 | |
Gary Mai | 698cee7 | 2016-09-19 16:09:54 -0700 | [diff] [blame] | 856 | kindSectionView.setState(kindSectionData, mViewIdGenerator, mListener); |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 857 | |
| 858 | return kindSectionView; |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 859 | } |
| 860 | |
Walter Jang | d675315 | 2015-10-02 09:23:13 -0700 | [diff] [blame] | 861 | private void showAllFields() { |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 862 | // Stop hiding empty editors and allow the user to enter values for all kinds now |
| 863 | for (int i = 0; i < mKindSectionViews.getChildCount(); i++) { |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 864 | final KindSectionView kindSectionView = |
| 865 | (KindSectionView) mKindSectionViews.getChildAt(i); |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 866 | kindSectionView.setHideWhenEmpty(false); |
| 867 | kindSectionView.updateEmptyEditors(/* shouldAnimate =*/ true); |
| 868 | } |
| 869 | mIsExpanded = true; |
Walter Jang | 79658e1 | 2015-09-24 10:36:26 -0700 | [diff] [blame] | 870 | |
Walter Jang | f5dfea4 | 2015-09-16 12:30:36 -0700 | [diff] [blame] | 871 | // Hide the more fields button |
| 872 | mMoreFields.setVisibility(View.GONE); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 873 | } |
| 874 | |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 875 | private boolean hasMoreFields() { |
Gary Mai | 363af60 | 2016-09-28 10:01:23 -0700 | [diff] [blame] | 876 | for (KindSectionView section : mKindSectionViewMap.values()) { |
Gary Mai | 98868d3 | 2016-09-14 11:55:04 -0700 | [diff] [blame] | 877 | if (section.getVisibility() != View.VISIBLE) { |
| 878 | return true; |
Marcus Hagerott | cf7f295 | 2016-09-06 13:49:17 -0700 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | return false; |
| 882 | } |
| 883 | |
Walter Jang | bf63a6d | 2015-05-05 09:14:35 -0700 | [diff] [blame] | 884 | private static void vlog(String message) { |
| 885 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 886 | Log.v(TAG, message); |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 887 | } |
| 888 | } |
Walter Jang | 363d3fd | 2015-09-16 10:29:07 -0700 | [diff] [blame] | 889 | |
| 890 | private static void wlog(String message) { |
| 891 | if (Log.isLoggable(TAG, Log.WARN)) { |
| 892 | Log.w(TAG, message); |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | private static void elog(String message) { |
| 897 | Log.e(TAG, message); |
| 898 | } |
Walter Jang | cab3dce | 2015-02-09 17:48:03 -0800 | [diff] [blame] | 899 | } |