blob: 48e655bbc1deac235ea35fddddeca37f35617028 [file] [log] [blame]
Walter Jangcab3dce2015-02-09 17:48:03 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.contacts.editor;
18
19import com.android.contacts.R;
20import com.android.contacts.common.model.AccountTypeManager;
21import com.android.contacts.common.model.RawContactDelta;
22import com.android.contacts.common.model.RawContactDeltaList;
Walter Jange720fde2015-02-17 10:54:14 -080023import com.android.contacts.common.model.RawContactModifier;
Walter Jangcab3dce2015-02-09 17:48:03 -080024import com.android.contacts.common.model.ValuesDelta;
25import com.android.contacts.common.model.account.AccountType;
26import com.android.contacts.common.model.account.AccountType.EditField;
27import com.android.contacts.common.model.dataitem.DataKind;
Walter Jangf46abd82015-02-20 16:52:04 -080028import com.android.contacts.common.util.MaterialColorMapUtils;
Walter Jang3efae4a2015-02-18 11:12:00 -080029import com.android.contacts.editor.CompactContactEditorFragment.PhotoHandler;
Walter Jangcab3dce2015-02-09 17:48:03 -080030
31import android.content.Context;
Walter Jang3efae4a2015-02-18 11:12:00 -080032import android.graphics.Bitmap;
Walter Jangcab3dce2015-02-09 17:48:03 -080033import android.provider.ContactsContract.CommonDataKinds.Email;
34import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
Walter Jang3efae4a2015-02-18 11:12:00 -080035import android.provider.ContactsContract.CommonDataKinds.Nickname;
Walter Jangcab3dce2015-02-09 17:48:03 -080036import android.provider.ContactsContract.CommonDataKinds.Phone;
37import android.provider.ContactsContract.CommonDataKinds.Photo;
Walter Jangcab3dce2015-02-09 17:48:03 -080038import android.provider.ContactsContract.CommonDataKinds.StructuredName;
39import android.text.TextUtils;
40import android.util.AttributeSet;
41import android.util.Log;
42import android.view.LayoutInflater;
Walter Jangb1c87622015-02-13 17:51:38 -080043import android.view.View;
Walter Jangcab3dce2015-02-09 17:48:03 -080044import android.view.ViewGroup;
45import android.widget.LinearLayout;
46
47import java.util.ArrayList;
48import java.util.List;
49
50/**
51 * View to display information from multiple {@link RawContactDelta}s grouped together
52 * (e.g. all the phone numbers from a {@link com.android.contacts.common.model.Contact} together.
53 */
Walter Jangb6ca2722015-02-20 11:10:25 -080054public class CompactRawContactsEditorView extends LinearLayout implements View.OnClickListener {
Walter Jangcab3dce2015-02-09 17:48:03 -080055
56 private static final String TAG = "CompactEditorView";
57
Walter Jangb6ca2722015-02-20 11:10:25 -080058 /**
59 * Callbacks for hosts of {@link CompactRawContactsEditorView}s.
60 */
61 public interface Listener {
62
63 /**
64 * Invoked when the compact editor should be expanded to show all fields.
65 */
66 public void onExpandEditor();
67 }
68
69 private Listener mListener;
70
Walter Jangcab3dce2015-02-09 17:48:03 -080071 private AccountTypeManager mAccountTypeManager;
72 private LayoutInflater mLayoutInflater;
Walter Jangd35e5ef2015-02-24 09:18:16 -080073
Walter Jangcab3dce2015-02-09 17:48:03 -080074 private ViewIdGenerator mViewIdGenerator;
Walter Jangf46abd82015-02-20 16:52:04 -080075 private MaterialColorMapUtils.MaterialPalette mMaterialPalette;
Walter Jangcab3dce2015-02-09 17:48:03 -080076
Walter Janga5e4bb22015-02-24 13:08:16 -080077 private CompactPhotoEditorView mPhoto;
Walter Jangcab3dce2015-02-09 17:48:03 -080078 private ViewGroup mNames;
Walter Jangb1c87622015-02-13 17:51:38 -080079 private ViewGroup mPhoneticNames;
80 private ViewGroup mNicknames;
Walter Jangcab3dce2015-02-09 17:48:03 -080081 private ViewGroup mPhoneNumbers;
82 private ViewGroup mEmails;
83 private ViewGroup mOther;
Walter Jangb6ca2722015-02-20 11:10:25 -080084 private View mMoreFields;
Walter Jangcab3dce2015-02-09 17:48:03 -080085
Walter Jang3efae4a2015-02-18 11:12:00 -080086 private long mPhotoRawContactId;
87
Walter Jangcab3dce2015-02-09 17:48:03 -080088 public CompactRawContactsEditorView(Context context) {
89 super(context);
90 }
91
92 public CompactRawContactsEditorView(Context context, AttributeSet attrs) {
93 super(context, attrs);
94 }
95
Walter Jangb6ca2722015-02-20 11:10:25 -080096 /**
97 * Sets the receiver for {@link CompactRawContactsEditorView} callbacks.
98 */
99 public void setListener(Listener listener) {
100 mListener = listener;
101 }
102
Walter Jangcab3dce2015-02-09 17:48:03 -0800103 @Override
104 protected void onFinishInflate() {
105 super.onFinishInflate();
106
107 mAccountTypeManager = AccountTypeManager.getInstance(getContext());
108 mLayoutInflater = (LayoutInflater)
109 getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
110
Walter Janga5e4bb22015-02-24 13:08:16 -0800111 mPhoto = (CompactPhotoEditorView) findViewById(R.id.photo_editor);
Walter Jangcab3dce2015-02-09 17:48:03 -0800112 mNames = (LinearLayout) findViewById(R.id.names);
Walter Jangb1c87622015-02-13 17:51:38 -0800113 mPhoneticNames = (LinearLayout) findViewById(R.id.phonetic_names);
114 mNicknames = (LinearLayout) findViewById(R.id.nicknames);
Walter Jangcab3dce2015-02-09 17:48:03 -0800115 mPhoneNumbers = (LinearLayout) findViewById(R.id.phone_numbers);
116 mEmails = (LinearLayout) findViewById(R.id.emails);
117 mOther = (LinearLayout) findViewById(R.id.other);
Walter Jangb6ca2722015-02-20 11:10:25 -0800118 mMoreFields = findViewById(R.id.more_fields);
119 mMoreFields.setOnClickListener(this);
120 }
121
122
123 @Override
124 public void onClick(View view) {
125 if (view.getId() == R.id.more_fields && mListener != null ) {
126 mListener.onExpandEditor();
127 }
Walter Jangcab3dce2015-02-09 17:48:03 -0800128 }
129
130 @Override
131 public void setEnabled(boolean enabled) {
132 super.setEnabled(enabled);
133 setEnabled(enabled, mNames);
Walter Jangb1c87622015-02-13 17:51:38 -0800134 setEnabled(enabled, mPhoneticNames);
135 setEnabled(enabled, mNicknames);
Walter Jangcab3dce2015-02-09 17:48:03 -0800136 setEnabled(enabled, mPhoneNumbers);
137 setEnabled(enabled, mEmails);
138 setEnabled(enabled, mOther);
139 }
140
141 private void setEnabled(boolean enabled, ViewGroup viewGroup) {
142 if (viewGroup != null) {
143 final int childCount = viewGroup.getChildCount();
144 for (int i = 0; i < childCount; i++) {
145 viewGroup.getChildAt(i).setEnabled(enabled);
146 }
147 }
148 }
149
Walter Jang3efae4a2015-02-18 11:12:00 -0800150 /**
Walter Janga5e4bb22015-02-24 13:08:16 -0800151 * Pass through to {@link CompactPhotoEditorView#setPhotoHandler}.
Walter Jang3efae4a2015-02-18 11:12:00 -0800152 */
153 public void setPhotoHandler(PhotoHandler photoHandler) {
Walter Janga5e4bb22015-02-24 13:08:16 -0800154 mPhoto.setPhotoHandler(photoHandler);
Walter Jang3efae4a2015-02-18 11:12:00 -0800155 }
156
157 /**
Walter Janga5e4bb22015-02-24 13:08:16 -0800158 * Pass through to {@link CompactPhotoEditorView#setPhoto}.
Walter Jang3efae4a2015-02-18 11:12:00 -0800159 */
160 public void setPhoto(Bitmap bitmap) {
Walter Janga5e4bb22015-02-24 13:08:16 -0800161 mPhoto.setPhoto(bitmap);
Walter Jang3efae4a2015-02-18 11:12:00 -0800162 }
163
164 /**
Walter Janga5e4bb22015-02-24 13:08:16 -0800165 * Pass through to {@link CompactPhotoEditorView#isWritablePhotoSet}.
Walter Jang3efae4a2015-02-18 11:12:00 -0800166 */
167 public boolean isWritablePhotoSet() {
Walter Janga5e4bb22015-02-24 13:08:16 -0800168 return mPhoto.isWritablePhotoSet();
Walter Jang3efae4a2015-02-18 11:12:00 -0800169 }
170
171 /**
Walter Jang3efae4a2015-02-18 11:12:00 -0800172 * Get the raw contact ID for the CompactHeaderView photo.
173 */
Walter Jang3efae4a2015-02-18 11:12:00 -0800174 public long getPhotoRawContactId() {
175 return mPhotoRawContactId;
176 }
177
Walter Jangd35e5ef2015-02-24 09:18:16 -0800178 public StructuredNameEditorView getStructuredNameEditorView() {
179 // We only ever show one StructuredName
180 return mNames.getChildCount() == 0
181 ? null : (StructuredNameEditorView) mNames.getChildAt(0);
182 }
183
184 public View getAggregationAnchorView() {
185 // Since there is only one structured name we can just return it as the anchor for
186 // the aggregation suggestions popup
187 if (mNames.getChildCount() == 0) {
188 return null;
189 }
190 return mNames.getChildAt(0).findViewById(R.id.anchor_view);
191 }
192
Walter Jangf46abd82015-02-20 16:52:04 -0800193 public void setState(RawContactDeltaList rawContactDeltas,
194 MaterialColorMapUtils.MaterialPalette materialPalette,
195 ViewIdGenerator viewIdGenerator) {
Walter Jangcab3dce2015-02-09 17:48:03 -0800196 mNames.removeAllViews();
Walter Jangb1c87622015-02-13 17:51:38 -0800197 mPhoneticNames.removeAllViews();
198 mNicknames.removeAllViews();
Walter Jangcab3dce2015-02-09 17:48:03 -0800199 mPhoneNumbers.removeAllViews();
200 mEmails.removeAllViews();
201 mOther.removeAllViews();
202
203 if (rawContactDeltas == null || rawContactDeltas.isEmpty()) {
204 return;
205 }
206
207 mViewIdGenerator = viewIdGenerator;
Walter Jangcab3dce2015-02-09 17:48:03 -0800208 setId(mViewIdGenerator.getId(rawContactDeltas.get(0), /* dataKind =*/ null,
209 /* valuesDelta =*/ null, ViewIdGenerator.NO_VIEW_INDEX));
Walter Jangf46abd82015-02-20 16:52:04 -0800210 mMaterialPalette = materialPalette;
Walter Jangcab3dce2015-02-09 17:48:03 -0800211
Walter Jang3efae4a2015-02-18 11:12:00 -0800212 addHeaderView(rawContactDeltas, viewIdGenerator);
Walter Jang10446452015-02-20 13:51:16 -0800213 addStructuredNameView(rawContactDeltas);
Walter Jang3efae4a2015-02-18 11:12:00 -0800214 addEditorViews(rawContactDeltas);
Walter Jange720fde2015-02-17 10:54:14 -0800215 removeExtraEmptyTextFields(mPhoneNumbers);
216 removeExtraEmptyTextFields(mEmails);
Walter Jangcab3dce2015-02-09 17:48:03 -0800217 }
218
Walter Jang3efae4a2015-02-18 11:12:00 -0800219 private void addHeaderView(RawContactDeltaList rawContactDeltas,
Walter Jange720fde2015-02-17 10:54:14 -0800220 ViewIdGenerator viewIdGenerator) {
Walter Jangcab3dce2015-02-09 17:48:03 -0800221 for (RawContactDelta rawContactDelta : rawContactDeltas) {
222 if (!rawContactDelta.isVisible()) {
223 continue;
224 }
225 final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
Walter Jange720fde2015-02-17 10:54:14 -0800226
Walter Jang3efae4a2015-02-18 11:12:00 -0800227 // Make sure we have a photo
228 RawContactModifier.ensureKindExists(
229 rawContactDelta, accountType, Photo.CONTENT_ITEM_TYPE);
230
231 final DataKind dataKind = accountType.getKindForMimetype(Photo.CONTENT_ITEM_TYPE);
232 if (dataKind != null) {
Walter Jang10446452015-02-20 13:51:16 -0800233 if (Photo.CONTENT_ITEM_TYPE.equals(dataKind.mimeType)) {
Walter Jang3efae4a2015-02-18 11:12:00 -0800234 mPhotoRawContactId = rawContactDelta.getRawContactId();
235 final ValuesDelta valuesDelta = rawContactDelta.getSuperPrimaryEntry(
Walter Jang10446452015-02-20 13:51:16 -0800236 dataKind.mimeType, /* forceSelection =*/ true);
Walter Janga5e4bb22015-02-24 13:08:16 -0800237 mPhoto.setValues(dataKind, valuesDelta, rawContactDelta,
Walter Jangf46abd82015-02-20 16:52:04 -0800238 /* readOnly =*/ !dataKind.editable, mMaterialPalette, viewIdGenerator);
Walter Jang3efae4a2015-02-18 11:12:00 -0800239 return;
240 }
241 }
242 }
243 }
244
Walter Jang10446452015-02-20 13:51:16 -0800245 private void addStructuredNameView(RawContactDeltaList rawContactDeltas) {
246 for (RawContactDelta rawContactDelta : rawContactDeltas) {
247 if (!rawContactDelta.isVisible()) {
248 continue;
249 }
250 final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
251
252 // Make sure we have a structured name
253 RawContactModifier.ensureKindExists(
254 rawContactDelta, accountType, StructuredName.CONTENT_ITEM_TYPE);
255
256 final DataKind dataKind = accountType.getKindForMimetype(
257 StructuredName.CONTENT_ITEM_TYPE);
258 if (dataKind != null) {
259 final ValuesDelta valuesDelta = rawContactDelta.getPrimaryEntry(dataKind.mimeType);
260 if (valuesDelta != null) {
261 mNames.addView(inflateStructuredNameEditorView(
262 mNames, accountType, valuesDelta, rawContactDelta));
263 return;
264 }
265 }
266 }
267 }
268
Walter Jang3efae4a2015-02-18 11:12:00 -0800269 private void addEditorViews(RawContactDeltaList rawContactDeltas) {
270 for (RawContactDelta rawContactDelta : rawContactDeltas) {
271 if (!rawContactDelta.isVisible()) {
272 continue;
273 }
274 final AccountType accountType = rawContactDelta.getAccountType(mAccountTypeManager);
275
Walter Jangcab3dce2015-02-09 17:48:03 -0800276 for (DataKind dataKind : accountType.getSortedDataKinds()) {
277 if (!dataKind.editable) {
278 continue;
279 }
280 final String mimeType = dataKind.mimeType;
281 log(Log.VERBOSE, mimeType + " " + dataKind.fieldList.size() + " field(s)");
282 if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)
Walter Jang10446452015-02-20 13:51:16 -0800283 || StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)
Walter Jangcab3dce2015-02-09 17:48:03 -0800284 || GroupMembership.CONTENT_ITEM_TYPE.equals(mimeType)) {
Walter Jang10446452015-02-20 13:51:16 -0800285 // Photos and name are handled separately; group membership is not supported
Walter Jangcab3dce2015-02-09 17:48:03 -0800286 continue;
Walter Jangcab3dce2015-02-09 17:48:03 -0800287 } else if (DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType)) {
288 // Use the StructuredName mime type to get values
289 if (hasNonEmptyPrimaryValuesDelta(
290 rawContactDelta, StructuredName.CONTENT_ITEM_TYPE, dataKind)) {
291 final ValuesDelta valuesDelta = rawContactDelta.getPrimaryEntry(
292 StructuredName.CONTENT_ITEM_TYPE);
Walter Jangb1c87622015-02-13 17:51:38 -0800293 mPhoneticNames.addView(inflatePhoneticNameEditorView(
294 mPhoneticNames, accountType, valuesDelta, rawContactDelta));
Walter Jangcab3dce2015-02-09 17:48:03 -0800295 }
296 } else if (Nickname.CONTENT_ITEM_TYPE.equals(mimeType)) {
297 if (hasNonEmptyValuesDelta(rawContactDelta, mimeType, dataKind)) {
Walter Jangb1c87622015-02-13 17:51:38 -0800298 mNicknames.addView(inflateNicknameEditorView(
299 mNicknames, dataKind, rawContactDelta));
Walter Jangcab3dce2015-02-09 17:48:03 -0800300 }
301 } else if (Phone.CONTENT_ITEM_TYPE.equals(mimeType)) {
Walter Jange720fde2015-02-17 10:54:14 -0800302 mPhoneNumbers.addView(inflateKindSectionView(
303 mPhoneNumbers, dataKind, rawContactDelta));
Walter Jangcab3dce2015-02-09 17:48:03 -0800304 } else if (Email.CONTENT_ITEM_TYPE.equals(mimeType)) {
Walter Jange720fde2015-02-17 10:54:14 -0800305 mEmails.addView(inflateKindSectionView(
306 mEmails, dataKind, rawContactDelta));
Walter Jangcab3dce2015-02-09 17:48:03 -0800307 } else if (hasNonEmptyValuesDelta(rawContactDelta, mimeType, dataKind)) {
308 mOther.addView(inflateKindSectionView(
309 mOther, dataKind, rawContactDelta));
310 }
311 }
312 }
313 }
314
Walter Jange720fde2015-02-17 10:54:14 -0800315 // TODO: avoid inflating extra views and deleting them
316 private void removeExtraEmptyTextFields(ViewGroup viewGroup) {
317 // If there is one (or less) editors, leave it whether it is empty or not
318 if (viewGroup.getChildCount() <= 1) {
Walter Jangb1c87622015-02-13 17:51:38 -0800319 return;
320 }
Walter Jange720fde2015-02-17 10:54:14 -0800321 // Determine if there are any non-empty editors
322 boolean hasAtLeastOneNonEmptyEditorView = false;
323 for (int i = 0; i < viewGroup.getChildCount(); i++) {
324 if (!isEmptyEditorView(viewGroup.getChildAt(i))) {
325 hasAtLeastOneNonEmptyEditorView = true;
Walter Jangb1c87622015-02-13 17:51:38 -0800326 break;
327 }
328 }
Walter Jange720fde2015-02-17 10:54:14 -0800329 if (hasAtLeastOneNonEmptyEditorView) {
330 // There is at least one non-empty editor, remove all the empty ones
331 for (int i = 0; i < viewGroup.getChildCount(); i++) {
332 if (isEmptyEditorView(viewGroup.getChildAt(i))) {
333 viewGroup.getChildAt(i).setVisibility(View.GONE);
Walter Jangb1c87622015-02-13 17:51:38 -0800334 }
335 }
336 } else {
Walter Jange720fde2015-02-17 10:54:14 -0800337 // There is no non-empty editor, keep the first empty view and remove the rest
338 for (int i = 1; i < viewGroup.getChildCount(); i++) {
339 viewGroup.getChildAt(i).setVisibility(View.GONE);
Walter Jangb1c87622015-02-13 17:51:38 -0800340 }
341 }
342 }
343
Walter Jange720fde2015-02-17 10:54:14 -0800344 private static boolean isEmptyEditorView(View view) {
345 if (view instanceof TextFieldsEditorView) {
346 final TextFieldsEditorView textFieldsEditorView = (TextFieldsEditorView) view;
347 return textFieldsEditorView.isEmpty();
348 }
349 if (view instanceof KindSectionView) {
350 final KindSectionView kindSectionView = (KindSectionView) view;
351 return kindSectionView.hasEmptyEditor();
352 }
353 return false;
354 }
355
Walter Jangcab3dce2015-02-09 17:48:03 -0800356 private static boolean hasNonEmptyValuesDelta(RawContactDelta rawContactDelta,
357 String mimeType, DataKind dataKind) {
358 return !getNonEmptyValuesDeltas(rawContactDelta, mimeType, dataKind).isEmpty();
359 }
360
361 private static List<ValuesDelta> getNonEmptyValuesDeltas(RawContactDelta rawContactDelta,
362 String mimeType, DataKind dataKind) {
363 final List<ValuesDelta> result = new ArrayList<>();
364 if (rawContactDelta == null) {
365 log(Log.VERBOSE, "Null RawContactDelta");
366 return result;
367 }
368 if (!rawContactDelta.hasMimeEntries(mimeType)) {
369 log(Log.VERBOSE, "No ValueDeltas");
370 return result;
371 }
372 for (ValuesDelta valuesDelta : rawContactDelta.getMimeEntries(mimeType)) {
373 if (valuesDelta == null) {
374 log(Log.VERBOSE, "Null valuesDelta");
375 }
376 for (EditField editField : dataKind.fieldList) {
377 final String column = editField.column;
378 final String value = valuesDelta == null ? null : valuesDelta.getAsString(column);
379 log(Log.VERBOSE, "Field " + column + " empty=" + TextUtils.isEmpty(value) +
380 " value=" + value);
381 if (!TextUtils.isEmpty(value)) {
382 result.add(valuesDelta);
383 }
384 }
385 }
386 return result;
387 }
388
389 private static boolean hasNonEmptyPrimaryValuesDelta(RawContactDelta rawContactDelta,
390 String mimeType, DataKind dataKind) {
391 final ValuesDelta valuesDelta = rawContactDelta.getPrimaryEntry(mimeType);
392 if (valuesDelta == null) {
393 return false;
394 }
395 for (EditField editField : dataKind.fieldList) {
396 final String column = editField.column;
397 final String value = valuesDelta == null ? null : valuesDelta.getAsString(column);
398 log(Log.VERBOSE, "Field (primary) " + column + " empty=" + TextUtils.isEmpty(value) +
399 " value=" + value);
400 if (!TextUtils.isEmpty(value)) {
401 return true;
402 }
403 }
404 return false;
405 }
406
407 private StructuredNameEditorView inflateStructuredNameEditorView(ViewGroup viewGroup,
408 AccountType accountType, ValuesDelta valuesDelta, RawContactDelta rawContactDelta) {
409 final StructuredNameEditorView result = (StructuredNameEditorView) mLayoutInflater.inflate(
410 R.layout.structured_name_editor_view, viewGroup, /* attachToRoot =*/ false);
411 result.setValues(
412 accountType.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME),
413 valuesDelta,
414 rawContactDelta,
415 /* readOnly =*/ false,
416 mViewIdGenerator);
417 return result;
418 }
419
420 private PhoneticNameEditorView inflatePhoneticNameEditorView(ViewGroup viewGroup,
421 AccountType accountType, ValuesDelta valuesDelta, RawContactDelta rawContactDelta) {
422 final PhoneticNameEditorView result = (PhoneticNameEditorView) mLayoutInflater.inflate(
423 R.layout.phonetic_name_editor_view, viewGroup, /* attachToRoot =*/ false);
424 result.setValues(
425 accountType.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME),
426 valuesDelta,
427 rawContactDelta,
428 /* readOnly =*/ false,
429 mViewIdGenerator);
430 return result;
431 }
432
Walter Jangb1c87622015-02-13 17:51:38 -0800433 private KindSectionView inflateNicknameEditorView(ViewGroup viewGroup, DataKind dataKind,
434 RawContactDelta rawContactDelta) {
435 final KindSectionView result = (KindSectionView) mLayoutInflater.inflate(
436 R.layout.item_kind_section, viewGroup, /* attachToRoot =*/ false);
437 result.setState(
438 dataKind,
Walter Jangcab3dce2015-02-09 17:48:03 -0800439 rawContactDelta,
440 /* readOnly =*/ false,
Walter Jang10446452015-02-20 13:51:16 -0800441 /* showOneEmptyEditor =*/ false,
Walter Jangcab3dce2015-02-09 17:48:03 -0800442 mViewIdGenerator);
443 return result;
444 }
445
446 private KindSectionView inflateKindSectionView(ViewGroup viewGroup, DataKind dataKind,
447 RawContactDelta rawContactDelta) {
448 final KindSectionView result = (KindSectionView) mLayoutInflater.inflate(
449 R.layout.item_kind_section, viewGroup, /* attachToRoot =*/ false);
450 result.setState(
451 dataKind,
452 rawContactDelta,
453 /* readOnly =*/ false,
Walter Jang10446452015-02-20 13:51:16 -0800454 /* showOneEmptyEditor =*/ false,
Walter Jangcab3dce2015-02-09 17:48:03 -0800455 mViewIdGenerator);
456 return result;
457 }
458
459 private static void log(int level, String message) {
460 log(TAG, level, message);
461 }
462
463 private static void log(String tag, int level, String message) {
464 if (Log.isLoggable(tag, level)) {
465 switch (level) {
466 case Log.VERBOSE:
467 Log.v(tag, message);
468 break;
469 case Log.DEBUG:
470 Log.d(tag, message);
471 break;
472 case Log.INFO:
473 Log.i(tag, message);
474 break;
475 case Log.WARN:
476 Log.w(tag, message);
477 break;
478 case Log.ERROR:
479 Log.e(tag, message);
480 break;
481 default:
482 Log.v(tag, message);
483 break;
484 }
485 }
486 }
487}