OSDN Git Service

Converted lists with a maximum of one entry into single-item-lists. Also made "Notes...
authorDaniel Lehmann <lehmannd@google.com>
Fri, 26 Feb 2010 19:41:53 +0000 (11:41 -0800)
committerDaniel Lehmann <lehmannd@google.com>
Fri, 26 Feb 2010 19:41:53 +0000 (11:41 -0800)
Bug: 2472403

Change-Id: I4dd767fb6cf1112e57a6343a14a7ab6303daaeae

res/layout/item_kind_section.xml
src/com/android/contacts/model/ContactsSource.java
src/com/android/contacts/model/ExchangeSource.java
src/com/android/contacts/model/FallbackSource.java
src/com/android/contacts/ui/widget/KindSectionView.java

index ebfeddf..d1dec5e 100644 (file)
@@ -54,6 +54,7 @@
             android:fadingEdge="horizontal" />
 
         <ImageView
+            android:id="@+id/kind_plus"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:duplicateParentState="true"
index 1198837..d008482 100644 (file)
@@ -141,7 +141,7 @@ public abstract class ContactsSource {
     abstract public int getHeaderColor(Context context);
 
     abstract public int getSideBarColor(Context context);
-    
+
     /**
      * {@link Comparator} to sort by {@link DataKind#weight}.
      */
@@ -196,6 +196,12 @@ public abstract class ContactsSource {
         public boolean secondary;
         public boolean editable;
 
+        /**
+         * If this is true (default), the user can add and remove values.
+         * If false, the editor will always show a single field (which might be empty).
+         */
+        public boolean isList;
+
         public StringInflater actionHeader;
         public StringInflater actionAltHeader;
         public StringInflater actionBody;
@@ -203,6 +209,11 @@ public abstract class ContactsSource {
         public boolean actionBodySocial = false;
 
         public String typeColumn;
+
+        /**
+         * Maximum number of values allowed in the list. -1 represents infinity.
+         * If {@link DataKind#isList} is false, this value is ignored.
+         */
         public int typeOverallMax;
 
         public List<EditType> typeList;
@@ -219,6 +230,7 @@ public abstract class ContactsSource {
             this.iconRes = iconRes;
             this.weight = weight;
             this.editable = editable;
+            this.isList = true;
             this.typeOverallMax = -1;
         }
     }
index b26bdeb..2313b33 100644 (file)
@@ -110,7 +110,7 @@ public class ExchangeSource extends FallbackSource {
         final DataKind kind = super.inflateNickname(ContactsSource.LEVEL_MIMETYPES);
 
         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
-            kind.typeOverallMax = 1;
+            kind.isList = false;
 
             kind.fieldList = Lists.newArrayList();
             kind.fieldList.add(new EditField(Nickname.NAME, R.string.nicknameLabelsGroup,
@@ -246,8 +246,7 @@ public class ExchangeSource extends FallbackSource {
         final DataKind kind = super.inflateOrganization(ContactsSource.LEVEL_MIMETYPES);
 
         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
-            kind.typeOverallMax = 1;
-
+            kind.isList = false;
             kind.typeColumn = Organization.TYPE;
             kind.typeList = Lists.newArrayList();
             kind.typeList.add(buildOrgType(Organization.TYPE_WORK).setSpecificMax(1));
@@ -284,8 +283,6 @@ public class ExchangeSource extends FallbackSource {
         final DataKind kind = super.inflateNote(ContactsSource.LEVEL_MIMETYPES);
 
         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
-            kind.typeOverallMax = 1;
-
             kind.fieldList = Lists.newArrayList();
             kind.fieldList.add(new EditField(Note.NOTE, R.string.label_notes, FLAGS_NOTE));
         }
@@ -298,7 +295,7 @@ public class ExchangeSource extends FallbackSource {
         final DataKind kind = super.inflateWebsite(ContactsSource.LEVEL_MIMETYPES);
 
         if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
-            kind.typeOverallMax = 1;
+            kind.isList = false;
 
             kind.fieldList = Lists.newArrayList();
             kind.fieldList.add(new EditField(Website.URL, R.string.websiteLabelsGroup, FLAGS_WEBSITE));
index 8c3a9d2..08c0e28 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.android.contacts.model;
 
+import com.android.contacts.R;
+import com.google.android.collect.Lists;
+
 import android.content.ContentValues;
 import android.content.Context;
 import android.content.res.Resources;
@@ -32,13 +35,8 @@ import android.provider.ContactsContract.CommonDataKinds.Photo;
 import android.provider.ContactsContract.CommonDataKinds.StructuredName;
 import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
 import android.provider.ContactsContract.CommonDataKinds.Website;
-import android.util.Log;
 import android.view.inputmethod.EditorInfo;
 
-import com.google.android.collect.Lists;
-
-import com.android.contacts.R;
-
 import java.util.Locale;
 
 public class FallbackSource extends ContactsSource {
@@ -159,6 +157,7 @@ public class FallbackSource extends ContactsSource {
             kind = addKind(new DataKind(Nickname.CONTENT_ITEM_TYPE,
                     R.string.nicknameLabelsGroup, -1, 115, true));
             kind.secondary = true;
+            kind.isList = false;
             kind.actionHeader = new SimpleInflater(R.string.nicknameLabelsGroup);
             kind.actionBody = new SimpleInflater(Nickname.NAME);
         }
@@ -387,6 +386,7 @@ public class FallbackSource extends ContactsSource {
         if (kind == null) {
             kind = addKind(new DataKind(Note.CONTENT_ITEM_TYPE,
                     R.string.label_notes, R.drawable.sym_note, 110, true));
+            kind.isList = false;
             kind.secondary = true;
             kind.actionHeader = new SimpleInflater(R.string.label_notes);
             kind.actionBody = new SimpleInflater(Note.NOTE);
index e379b69..46ce514 100644 (file)
@@ -32,6 +32,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.View.OnClickListener;
+import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
@@ -47,6 +48,7 @@ public class KindSectionView extends LinearLayout implements OnClickListener, Ed
 
     private ViewGroup mEditors;
     private View mAdd;
+    private ImageView mAddPlusButton;
     private TextView mTitle;
 
     private DataKind mKind;
@@ -77,6 +79,8 @@ public class KindSectionView extends LinearLayout implements OnClickListener, Ed
         mAdd = findViewById(R.id.kind_header);
         mAdd.setOnClickListener(this);
 
+        mAddPlusButton = (ImageView) findViewById(R.id.kind_plus);
+
         mTitle = (TextView)findViewById(R.id.kind_title);
     }
 
@@ -102,6 +106,9 @@ public class KindSectionView extends LinearLayout implements OnClickListener, Ed
         // TODO: handle resources from remote packages
         mTitle.setText(kind.titleRes);
 
+        // Only show the add button if this is a list
+        mAddPlusButton.setVisibility(mKind.isList ? View.VISIBLE : View.GONE);
+
         this.rebuildFromState();
         this.updateAddEnabled();
         this.updateEditorsVisible();
@@ -114,17 +121,44 @@ public class KindSectionView extends LinearLayout implements OnClickListener, Ed
         // Remove any existing editors
         mEditors.removeAllViews();
 
-        // Build individual editors for each entry
-        if (!mState.hasMimeEntries(mKind.mimeType)) return;
-        for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
-            // Skip entries that aren't visible
-            if (!entry.isVisible()) continue;
-
-            final GenericEditorView editor = (GenericEditorView)mInflater.inflate(
-                    R.layout.item_generic_editor, mEditors, false);
-            editor.setValues(mKind, entry, mState, mReadOnly, mViewIdGenerator);
-            editor.setEditorListener(this);
-            mEditors.addView(editor);
+        // Check if we are displaying anything here
+        boolean hasEntries = mState.hasMimeEntries(mKind.mimeType);
+
+        if (!mKind.isList) {
+            if (hasEntries) {
+                // we might have no visible entries. check that, too
+                for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
+                    if (!entry.isVisible()) {
+                        hasEntries = false;
+                        break;
+                    }
+                }
+            }
+
+            if (!hasEntries) {
+                EntityModifier.insertChild(mState, mKind);
+                hasEntries = true;
+            }
+        }
+
+        if (hasEntries) {
+            int entryIndex = 0;
+            for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
+                // Skip entries that aren't visible
+                if (!entry.isVisible()) continue;
+
+                final GenericEditorView editor = (GenericEditorView)mInflater.inflate(
+                        R.layout.item_generic_editor, mEditors, false);
+                editor.setValues(mKind, entry, mState, mReadOnly, mViewIdGenerator);
+                // older versions of android had lists where we now have a single value
+                // in these cases we should show the remove button for all but the first value
+                // to ensure that nothing is removed
+                editor.mDelete.setVisibility((mKind.isList || (entryIndex != 0))
+                        ? View.VISIBLE : View.GONE);
+                editor.setEditorListener(this);
+                mEditors.addView(editor);
+                entryIndex++;
+            }
         }
     }
 
@@ -136,12 +170,17 @@ public class KindSectionView extends LinearLayout implements OnClickListener, Ed
     protected void updateAddEnabled() {
         // Set enabled state on the "add" view
         final boolean canInsert = EntityModifier.canInsert(mState, mKind);
-       final boolean isEnabled = !mReadOnly && canInsert;
+        final boolean isEnabled = !mReadOnly && canInsert;
         mAdd.setEnabled(isEnabled);
     }
 
     /** {@inheritDoc} */
     public void onClick(View v) {
+        // if this is not a list the plus button is not visible but the user might have clicked
+        // the text.
+        if (!mKind.isList)
+            return;
+
         // Insert a new child and rebuild
         final ValuesDelta newValues = EntityModifier.insertChild(mState, mKind);
         this.rebuildFromState();