OSDN Git Service

When editing contacts, automatically expand "More" if data has been entered
authorDaniel Lehmann <lehmannd@google.com>
Tue, 23 Mar 2010 18:45:24 +0000 (11:45 -0700)
committerDaniel Lehmann <lehmannd@google.com>
Tue, 23 Mar 2010 18:45:24 +0000 (11:45 -0700)
Bug:2534580

Change-Id: Ic56fc755299f5da4d824e38f3a38f9e5b0bab0ef

src/com/android/contacts/ui/widget/ContactEditorView.java
src/com/android/contacts/ui/widget/GenericEditorView.java
src/com/android/contacts/ui/widget/KindSectionView.java

index ebb6bbb..83bf2fb 100644 (file)
@@ -215,6 +215,7 @@ public class ContactEditorView extends BaseContactEditorView implements OnClickL
             mReadOnlyName.setVisibility(View.GONE);
         }
 
+        boolean anySecondaryFieldFilled = false;
         // Create editor sections for each possible data kind
         for (DataKind kind : source.getSortedDataKinds()) {
             // Skip kind of not editable
@@ -246,11 +247,14 @@ public class ContactEditorView extends BaseContactEditorView implements OnClickL
                 final KindSectionView section = (KindSectionView)mInflater.inflate(
                         R.layout.item_kind_section, parent, false);
                 section.setState(kind, state, mIsSourceReadOnly, vig);
+                if (kind.secondary && section.isAnyEditorFilledOut()) {
+                    anySecondaryFieldFilled = true;
+                }
                 parent.addView(section);
             }
         }
 
-        setSecondaryVisible(mSecondaryVisible);
+        setSecondaryVisible(anySecondaryFieldFilled);
     }
 
     /**
index ee5951f..24262bb 100644 (file)
@@ -37,6 +37,7 @@ import android.os.Parcelable;
 import android.telephony.PhoneNumberFormattingTextWatcher;
 import android.text.Editable;
 import android.text.InputType;
+import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.util.AttributeSet;
 import android.view.ContextThemeWrapper;
@@ -169,6 +170,17 @@ public class GenericEditorView extends RelativeLayout implements Editor, View.On
         }
     }
 
+    public boolean isAnyFieldFilledOut() {
+        int childCount = mFields.getChildCount();
+        for (int i = 0; i < childCount; i++) {
+            EditText editorView = (EditText) mFields.getChildAt(i);
+            if (!TextUtils.isEmpty(editorView.getText())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     private void rebuildValues() {
         setValues(mKind, mEntry, mState, mReadOnly, mViewIdGenerator);
     }
index 46ce514..221bc16 100644 (file)
@@ -114,6 +114,26 @@ public class KindSectionView extends LinearLayout implements OnClickListener, Ed
         this.updateEditorsVisible();
     }
 
+    public boolean isAnyEditorFilledOut() {
+        if (mState == null) {
+            return false;
+        }
+
+        if (!mState.hasMimeEntries(mKind.mimeType)) {
+            return false;
+        }
+
+        int editorCount = mEditors.getChildCount();
+        for (int i = 0; i < editorCount; i++) {
+            GenericEditorView editorView = (GenericEditorView) mEditors.getChildAt(i);
+            if (editorView.isAnyFieldFilledOut()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     /**
      * Build editors for all current {@link #mState} rows.
      */