From e86b928be36bb3e7136796ad519e736325d1d2b1 Mon Sep 17 00:00:00 2001 From: Megha Joshi Date: Mon, 5 Oct 2009 14:13:58 -0700 Subject: [PATCH] Prevents empty focus contacts without photo from being created. Bug: 2133257 Dr No: TS --- src/com/android/contacts/model/EntityModifier.java | 10 ++++++---- src/com/android/contacts/ui/widget/PhotoEditorView.java | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/com/android/contacts/model/EntityModifier.java b/src/com/android/contacts/model/EntityModifier.java index d6f6571..5700df2 100644 --- a/src/com/android/contacts/model/EntityModifier.java +++ b/src/com/android/contacts/model/EntityModifier.java @@ -85,7 +85,10 @@ public class EntityModifier { if (!hasChild && kind != null) { // Create child when none exists and valid kind - insertChild(state, kind); + final ValuesDelta child = insertChild(state, kind); + if (kind.mimeType.equals(Photo.CONTENT_ITEM_TYPE)) { + child.setFromTemplate(true); + } } } @@ -321,7 +324,6 @@ public class EntityModifier { public static ValuesDelta insertChild(EntityDelta state, DataKind kind, EditType type) { // Bail early if invalid kind if (kind == null) return null; - final ContentValues after = new ContentValues(); // Our parent CONTACT_ID is provided later @@ -338,7 +340,7 @@ public class EntityModifier { } final ValuesDelta child = ValuesDelta.fromAfter(after); - state.addEntry(child); + state.addEntry(child); return child; } @@ -385,6 +387,7 @@ public class EntityModifier { state.getValues().getAsString(RawContacts.ACCOUNT_TYPE)); final boolean isPhoto = TextUtils.equals(Photo.CONTENT_ITEM_TYPE, kind.mimeType); final boolean isGooglePhoto = isPhoto && isGoogleSource; + if (EntityModifier.isEmpty(entry, kind) && !isGooglePhoto) { // TODO: remove this verbose logging Log.w(TAG, "Trimming: " + entry.toString()); @@ -394,7 +397,6 @@ public class EntityModifier { } } } - if (!hasValues) { // Trim overall entity if no children exist state.markDeleted(); diff --git a/src/com/android/contacts/ui/widget/PhotoEditorView.java b/src/com/android/contacts/ui/widget/PhotoEditorView.java index 184b907..7dfe3d7 100644 --- a/src/com/android/contacts/ui/widget/PhotoEditorView.java +++ b/src/com/android/contacts/ui/widget/PhotoEditorView.java @@ -87,6 +87,7 @@ public class PhotoEditorView extends ImageView implements Editor, OnClickListene setImageBitmap(photo); setEnabled(!readOnly); mHasSetPhoto = true; + mEntry.setFromTemplate(false); } else { resetDefault(); } @@ -125,6 +126,7 @@ public class PhotoEditorView extends ImageView implements Editor, OnClickListene mEntry.put(Photo.PHOTO, out.toByteArray()); setImageBitmap(photo); mHasSetPhoto = true; + mEntry.setFromTemplate(false); } catch (IOException e) { Log.w(TAG, "Unable to serialize photo: " + e.toString()); } @@ -135,6 +137,7 @@ public class PhotoEditorView extends ImageView implements Editor, OnClickListene setScaleType(ImageView.ScaleType.CENTER); setImageResource(R.drawable.ic_menu_add_picture); mHasSetPhoto = false; + mEntry.setFromTemplate(true); } /** {@inheritDoc} */ -- 2.11.0