OSDN Git Service

Updates to the edit contact UI.
authorJeff Hamilton <jham@android.com>
Wed, 7 Oct 2009 09:40:27 +0000 (04:40 -0500)
committerJeff Hamilton <jham@android.com>
Wed, 7 Oct 2009 20:26:49 +0000 (15:26 -0500)
- Updated account colors and color layout
- Updated display in read-only mode
- Clearer strings to identify accounts
- Sort the contacts to edit so read-only ones
  always are at the bottom.

Fixes 2163539 and a good portion of 2163519.

Change-Id: Ib2afc992a8623f2a253d2a52a0b5c50ee866e5d8

res/layout/item_contact_editor.xml
src/com/android/contacts/ContactsListActivity.java
src/com/android/contacts/model/ExchangeSource.java
src/com/android/contacts/model/ExternalSource.java
src/com/android/contacts/model/GoogleSource.java
src/com/android/contacts/ui/EditContactActivity.java
src/com/android/contacts/ui/widget/ContactEditorView.java

index cea4bdb..21da0aa 100644 (file)
     <!-- Left side color bar -->
     <ImageView
         android:id="@+id/color_bar"
-        android:layout_width="15dip"
+        android:layout_width="5dip"
         android:layout_height="fill_parent"
     />
 
     <!-- The content -->
-    <RelativeLayout
+    <LinearLayout
         android:layout_width="0dip"
         android:layout_height="wrap_content"
         android:layout_weight="1"
+        android:orientation="vertical"
     >
 
         <!-- Account info header -->
             android:layout_width="fill_parent"
         >
 
+            <ImageView android:id="@+id/header_color_bar"
+                android:layout_width="fill_parent"
+                android:layout_height="2dip"
+                android:layout_marginBottom="5dip"
+            />
+
             <ImageView android:id="@+id/header_icon"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_marginLeft="7dip"
                 android:layout_marginRight="7dip"
                 android:layout_centerVertical="true"
+                android:layout_below="@id/header_color_bar"
             />
 
             <TextView android:id="@+id/header_account_type"
@@ -57,8 +65,7 @@
                 android:layout_alignTop="@id/header_icon"
                 android:layout_marginTop="-4dip"
 
-                android:textSize="24pt"
-                android:textStyle="bold"
+                android:textSize="24sp"
                 android:textColor="?android:attr/textColorPrimary"
             />
 
                 android:textColor="?android:attr/textColorPrimary"
             />
 
+            <View
+                android:layout_width="fill_parent"
+                android:layout_height="1px"
+                android:layout_alignParentBottom="true"
+
+                android:background="?android:attr/listDivider"
+            />
+
         </RelativeLayout>
 
         <FrameLayout
             android:id="@+id/stub_photo"
-            android:layout_width="100dip"
-            android:layout_height="96dip"
-            android:layout_below="@id/header"
-            android:layout_alignWithParentIfMissing="true"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
             android:paddingLeft="12dip"
             android:paddingTop="10dip">
 
             android:layout_below="@id/stub_photo"
             android:layout_marginTop="6dip"
             android:layout_marginBottom="4dip"
-            android:layout_alignWithParentIfMissing="true"
             layout="@layout/item_generic_editor" />
 
+        <TextView android:id="@+id/read_only_name"
+            android:layout_width="fill_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="6dip"
+            android:layout_marginBottom="6dip"
+            android:layout_marginLeft="10dip"
+
+            android:textAppearance="?android:attr/textAppearanceLarge"
+        />
+
         <LinearLayout
             android:id="@+id/sect_general"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@+id/edit_name"
             android:orientation="vertical"
         />
 
         <View android:id="@+id/head_secondary_divider"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@id/sect_general"
             android:background="?android:attr/listDivider" />
 
         <TextView
             android:id="@+id/head_secondary"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@+id/head_secondary_divider"
 
             android:gravity="center_vertical"
             android:minHeight="?android:attr/listPreferredItemHeight"
             android:id="@+id/sect_secondary"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@id/head_secondary"
             android:orientation="vertical" />
 
         <TextView
             android:id="@+id/edit_read_only"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
-            android:layout_below="@id/edit_name"
-            android:gravity="center_horizontal"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:paddingTop="5dip"
-            android:paddingBottom="5dip"
-            android:text="@string/edit_read_only"/>
+            android:layout_marginTop="10dip"
+            android:layout_marginBottom="10dip"
+            android:layout_marginLeft="10dip"
+
+            android:textAppearance="?android:attr/textAppearanceSmall"
+            android:textColor="?android:attr/textColorPrimary"
+            android:drawableLeft="@android:drawable/ic_dialog_alert"
+            android:drawablePadding="10dip"
+        />
 
-    </RelativeLayout>
+    </LinearLayout>
 
 </com.android.contacts.ui.widget.ContactEditorView>
index 0c929ba..d700195 100644 (file)
@@ -123,6 +123,7 @@ import java.util.concurrent.Executors;
 /**
  * Displays a list of contacts. Usually is embedded into the ContactsActivity.
  */
+@SuppressWarnings("deprecation")
 public class ContactsListActivity extends ListActivity implements
         View.OnCreateContextMenuListener, View.OnClickListener {
 
index 5161499..b46824c 100644 (file)
@@ -275,11 +275,11 @@ public class ExchangeSource extends FallbackSource {
 
     @Override
     public int getHeaderColor(Context context) {
-        return 0xff876b47;
+        return 0xffd5ba96;
     }
 
     @Override
     public int getSideBarColor(Context context) {
-        return 0xffc6ab8c;
+        return 0xffb58e59;
     }
 }
index d2f14dc..743eb4e 100644 (file)
@@ -183,11 +183,11 @@ public class ExternalSource extends FallbackSource {
 
     @Override
     public int getHeaderColor(Context context) {
-        return 0xff7f93bc;
+        return 0xff6d86b4;
     }
 
     @Override
     public int getSideBarColor(Context context) {
-        return 0xffbdc7d8;
+        return 0xff6d86b4;
     }
 }
index e8f7f46..a4b4cb2 100644 (file)
@@ -263,11 +263,11 @@ public class GoogleSource extends FallbackSource {
 
     @Override
     public int getHeaderColor(Context context) {
-        return 0xff000000;
+        return 0xff89c2c2;
     }
 
     @Override
     public int getSideBarColor(Context context) {
-        return 0xffffffff;
+        return 0xff5bb4b4;
     }
 }
index fef6a9f..5d095c6 100644 (file)
@@ -79,12 +79,14 @@ import android.widget.Toast;
 
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 
 /**
  * Activity for editing or inserting a contact.
  */
 public final class EditContactActivity extends Activity
-        implements View.OnClickListener {
+        implements View.OnClickListener, Comparator<EntityDelta> {
     private static final String TAG = "EditContactActivity";
 
     /** The launch code when picking a photo and the raw data is returned */
@@ -323,8 +325,10 @@ public final class EditContactActivity extends Activity
                 Context.LAYOUT_INFLATER_SERVICE);
         final Sources sources = Sources.getInstance(this);
 
-        // Remove any existing editors and rebuild any visible
+        // Sort the editors
+        Collections.sort(mState, this);
 
+        // Remove any existing editors and rebuild any visible
         mContent.removeAllViews();
         int size = mState.size();
         for (int i = 0; i < size; i++) {
@@ -363,18 +367,6 @@ public final class EditContactActivity extends Activity
     }
 
     /** {@inheritDoc} */
-    public void onDisplayNameClick(View view) {
-        if (!hasValidState()) return;
-        showAndManageDialog(createNameDialog());
-    }
-
-    /** {@inheritDoc} */
-    public void onPhotoClick(View view) {
-        if (!hasValidState()) return;
-        showAndManageDialog(createPhotoDialog());
-    }
-
-    /** {@inheritDoc} */
     public void onClick(View view) {
         switch (view.getId()) {
             case R.id.btn_done:
@@ -791,7 +783,7 @@ public final class EditContactActivity extends Activity
     /**
      * Pick a specific photo to be added under the currently selected tab.
      */
-    private boolean doPickPhotoAction(long rawContactId) {
+    boolean doPickPhotoAction(long rawContactId) {
         if (!hasValidState()) return false;
 
         try {
@@ -1028,11 +1020,6 @@ public final class EditContactActivity extends Activity
         return builder.create();
     }
 
-    private Dialog createPhotoDialog() {
-        // TODO: build dialog for picking primary photo
-        return null;
-    }
-
     /**
      * Create dialog for selecting primary display name.
      */
@@ -1085,4 +1072,63 @@ public final class EditContactActivity extends Activity
         return builder.create();
     }
 
+    /**
+     * Compare EntityDeltas for sorting the stack of editors.
+     */
+    public int compare(EntityDelta one, EntityDelta two) {
+        // Check direct equality
+        if (one.equals(two)) {
+            return 0;
+        }
+
+        final Sources sources = Sources.getInstance(this);
+        String accountType = one.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
+        final ContactsSource oneSource = sources.getInflatedSource(accountType,
+                ContactsSource.LEVEL_SUMMARY);
+        accountType = two.getValues().getAsString(RawContacts.ACCOUNT_TYPE);
+        final ContactsSource twoSource = sources.getInflatedSource(accountType,
+                ContactsSource.LEVEL_SUMMARY);
+
+        // Check read-only
+        if (oneSource.readOnly && !twoSource.readOnly) {
+            return 1;
+        } else if (twoSource.readOnly && !oneSource.readOnly) {
+            return -1;
+        }
+
+        // Check account type
+        boolean skipAccountTypeCheck = false;
+        boolean oneIsGoogle = oneSource instanceof GoogleSource;
+        boolean twoIsGoogle = twoSource instanceof GoogleSource;
+        if (oneIsGoogle && !twoIsGoogle) {
+            return -1;
+        } else if (twoIsGoogle && !oneIsGoogle) {
+            return 1;
+        } else {
+            skipAccountTypeCheck = true;
+        }
+
+        int value;
+        if (!skipAccountTypeCheck) {
+            value = oneSource.accountType.compareTo(twoSource.accountType);
+            if (value != 0) {
+                return value;
+            }
+        }
+
+        // Check account name
+        String oneAccount = one.getValues().getAsString(RawContacts.ACCOUNT_NAME);
+        if (oneAccount == null) oneAccount = "null";
+        String twoAccount = two.getValues().getAsString(RawContacts.ACCOUNT_NAME);
+        if (twoAccount == null) twoAccount = "null";
+        value = oneAccount.compareTo(twoAccount);
+        if (value != 0) {
+            return value;
+        }
+
+        // Both are in the same account, fall back to contact ID
+        int oneId = one.getValues().getAsInteger(RawContacts._ID);
+        int twoId = two.getValues().getAsInteger(RawContacts._ID);
+        return oneId -twoId;
+    }
 }
index 8e76e7b..bf03052 100644 (file)
@@ -18,7 +18,6 @@ package com.android.contacts.ui.widget;
 
 import com.android.contacts.R;
 import com.android.contacts.model.ContactsSource;
-import com.android.contacts.model.Editor;
 import com.android.contacts.model.EntityDelta;
 import com.android.contacts.model.EntityModifier;
 import com.android.contacts.model.ContactsSource.DataKind;
@@ -61,6 +60,7 @@ public class ContactEditorView extends LinearLayout implements OnClickListener {
     private LayoutInflater mInflater;
 
     private TextView mReadOnly;
+    private TextView mReadOnlyName;
 
     private PhotoEditorView mPhoto;
     private GenericEditorView mName;
@@ -75,7 +75,7 @@ public class ContactEditorView extends LinearLayout implements OnClickListener {
     private Drawable mSecondaryOpen;
     private Drawable mSecondaryClosed;
 
-    private View mHeader;
+    private View mHeaderColorBar;
     private View mSideBar;
     private ImageView mHeaderIcon;
     private TextView mHeaderAccountType;
@@ -109,10 +109,12 @@ public class ContactEditorView extends LinearLayout implements OnClickListener {
         mName.setMinimumHeight(photoSize);
         mName.setDeletable(false);
 
+        mReadOnlyName = (TextView) findViewById(R.id.read_only_name);
+
         mGeneral = (ViewGroup)findViewById(R.id.sect_general);
         mSecondary = (ViewGroup)findViewById(R.id.sect_secondary);
 
-        mHeader = findViewById(R.id.header);
+        mHeaderColorBar = findViewById(R.id.header_color_bar);
         mSideBar = findViewById(R.id.color_bar);
         mHeaderIcon = (ImageView) findViewById(R.id.header_icon);
         mHeaderAccountType = (TextView) findViewById(R.id.header_account_type);
@@ -188,16 +190,18 @@ public class ContactEditorView extends LinearLayout implements OnClickListener {
         EntityModifier.ensureKindExists(state, source, StructuredName.CONTENT_ITEM_TYPE);
 
         // Fill in the header info
-        mHeader.setBackgroundColor(source.getHeaderColor(mContext));
+        mHeaderColorBar.setBackgroundColor(source.getHeaderColor(mContext));
         mSideBar.setBackgroundColor(source.getSideBarColor(mContext));
         ValuesDelta values = state.getValues();
         String accountName = values.getAsString(RawContacts.ACCOUNT_NAME);
-        if (TextUtils.isEmpty(accountName)) {
-            // TODO get from resource
-            accountName = "Local contact";
+        CharSequence accountType = source.getDisplayLabel(mContext);
+        if (TextUtils.isEmpty(accountType)) {
+            accountType = mContext.getString(R.string.account_phone);
+        } else {
+            mHeaderAccountName.setText(
+                    mContext.getString(R.string.from_account_format, accountName));
         }
-        mHeaderAccountName.setText(accountName);
-        mHeaderAccountType.setText(source.getDisplayLabel(mContext));
+        mHeaderAccountType.setText(mContext.getString(R.string.account_type_format, accountType));
         mHeaderIcon.setImageDrawable(source.getDisplayIcon(mContext));
 
         mRawContactId = values.getAsLong(RawContacts._ID);
@@ -210,12 +214,22 @@ public class ContactEditorView extends LinearLayout implements OnClickListener {
         mName.setEnabled(!source.readOnly);
 
         boolean readOnly = source.readOnly;
+        // Show and hide the appropriate views
         if (readOnly) {
             mGeneral.setVisibility(View.GONE);
             mSecondary.setVisibility(View.GONE);
             mSecondaryHeader.setVisibility(View.GONE);
+            mName.setVisibility(View.GONE);
+            mReadOnly.setVisibility(View.VISIBLE);
+            mReadOnly.setText(mContext.getString(R.string.contact_read_only, accountType));
+            mReadOnlyName.setVisibility(View.VISIBLE);
         } else {
+            mGeneral.setVisibility(View.VISIBLE);
+            mSecondary.setVisibility(View.VISIBLE);
+            mSecondaryHeader.setVisibility(View.VISIBLE);
+            mName.setVisibility(View.VISIBLE);
             mReadOnly.setVisibility(View.GONE);
+            mReadOnlyName.setVisibility(View.GONE);
         }
 
         // Create editor sections for each possible data kind
@@ -227,7 +241,12 @@ public class ContactEditorView extends LinearLayout implements OnClickListener {
             if (StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) {
                 // Handle special case editor for structured name
                 final ValuesDelta primary = state.getPrimaryEntry(mimeType);
-                mName.setValues(kind, primary, state, source.readOnly);
+                if (!readOnly) {
+                    mName.setValues(kind, primary, state, source.readOnly);
+                } else {
+                    String displayName = primary.getAsString(StructuredName.DISPLAY_NAME);
+                    mReadOnlyName.setText(displayName);
+                }
             } else if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) {
                 // Handle special case editor for photos
                 final ValuesDelta primary = state.getPrimaryEntry(mimeType);