OSDN Git Service

Prevents empty focus contacts without photo from being created.
authorMegha Joshi <mjoshi@google.com>
Mon, 5 Oct 2009 21:13:58 +0000 (14:13 -0700)
committerMegha Joshi <mjoshi@google.com>
Tue, 6 Oct 2009 17:51:19 +0000 (10:51 -0700)
Bug: 2133257
Dr No: TS

src/com/android/contacts/model/EntityModifier.java
src/com/android/contacts/ui/widget/PhotoEditorView.java

index d6f6571..5700df2 100644 (file)
@@ -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();
index 184b907..7dfe3d7 100644 (file)
@@ -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} */