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