From 1fb6275a57318261cb6dba511954cb754cd17fa2 Mon Sep 17 00:00:00 2001 From: Jeff Hamilton Date: Wed, 7 Oct 2009 04:40:27 -0500 Subject: [PATCH] Updates to the edit contact UI. - 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 | 61 ++++++++++----- src/com/android/contacts/ContactsListActivity.java | 1 + src/com/android/contacts/model/ExchangeSource.java | 4 +- src/com/android/contacts/model/ExternalSource.java | 4 +- src/com/android/contacts/model/GoogleSource.java | 4 +- .../android/contacts/ui/EditContactActivity.java | 86 +++++++++++++++++----- .../contacts/ui/widget/ContactEditorView.java | 39 +++++++--- 7 files changed, 143 insertions(+), 56 deletions(-) diff --git a/res/layout/item_contact_editor.xml b/res/layout/item_contact_editor.xml index cea4bdb..21da0aa 100644 --- a/res/layout/item_contact_editor.xml +++ b/res/layout/item_contact_editor.xml @@ -25,15 +25,16 @@ - @@ -42,12 +43,19 @@ android:layout_width="fill_parent" > + + @@ -73,14 +80,20 @@ android:textColor="?android:attr/textColorPrimary" /> + + @@ -97,28 +110,34 @@ android:layout_below="@id/stub_photo" android:layout_marginTop="6dip" android:layout_marginBottom="4dip" - android:layout_alignWithParentIfMissing="true" layout="@layout/item_generic_editor" /> + + + 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" + /> - + diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java index 0c929ba..d700195 100644 --- a/src/com/android/contacts/ContactsListActivity.java +++ b/src/com/android/contacts/ContactsListActivity.java @@ -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 { diff --git a/src/com/android/contacts/model/ExchangeSource.java b/src/com/android/contacts/model/ExchangeSource.java index 5161499..b46824c 100644 --- a/src/com/android/contacts/model/ExchangeSource.java +++ b/src/com/android/contacts/model/ExchangeSource.java @@ -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; } } diff --git a/src/com/android/contacts/model/ExternalSource.java b/src/com/android/contacts/model/ExternalSource.java index d2f14dc..743eb4e 100644 --- a/src/com/android/contacts/model/ExternalSource.java +++ b/src/com/android/contacts/model/ExternalSource.java @@ -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; } } diff --git a/src/com/android/contacts/model/GoogleSource.java b/src/com/android/contacts/model/GoogleSource.java index e8f7f46..a4b4cb2 100644 --- a/src/com/android/contacts/model/GoogleSource.java +++ b/src/com/android/contacts/model/GoogleSource.java @@ -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; } } diff --git a/src/com/android/contacts/ui/EditContactActivity.java b/src/com/android/contacts/ui/EditContactActivity.java index fef6a9f..5d095c6 100644 --- a/src/com/android/contacts/ui/EditContactActivity.java +++ b/src/com/android/contacts/ui/EditContactActivity.java @@ -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 { 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; + } } diff --git a/src/com/android/contacts/ui/widget/ContactEditorView.java b/src/com/android/contacts/ui/widget/ContactEditorView.java index 8e76e7b..bf03052 100644 --- a/src/com/android/contacts/ui/widget/ContactEditorView.java +++ b/src/com/android/contacts/ui/widget/ContactEditorView.java @@ -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); -- 2.11.0