<!-- 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"
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>
/**
* Displays a list of contacts. Usually is embedded into the ContactsActivity.
*/
+@SuppressWarnings("deprecation")
public class ContactsListActivity extends ListActivity implements
View.OnCreateContextMenuListener, View.OnClickListener {
@Override
public int getHeaderColor(Context context) {
- return 0xff876b47;
+ return 0xffd5ba96;
}
@Override
public int getSideBarColor(Context context) {
- return 0xffc6ab8c;
+ return 0xffb58e59;
}
}
@Override
public int getHeaderColor(Context context) {
- return 0xff7f93bc;
+ return 0xff6d86b4;
}
@Override
public int getSideBarColor(Context context) {
- return 0xffbdc7d8;
+ return 0xff6d86b4;
}
}
@Override
public int getHeaderColor(Context context) {
- return 0xff000000;
+ return 0xff89c2c2;
}
@Override
public int getSideBarColor(Context context) {
- return 0xffffffff;
+ return 0xff5bb4b4;
}
}
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 */
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++) {
}
/** {@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:
/**
* 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 {
return builder.create();
}
- private Dialog createPhotoDialog() {
- // TODO: build dialog for picking primary photo
- return null;
- }
-
/**
* Create dialog for selecting primary display name.
*/
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;
+ }
}
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;
private LayoutInflater mInflater;
private TextView mReadOnly;
+ private TextView mReadOnlyName;
private PhotoEditorView mPhoto;
private GenericEditorView mName;
private Drawable mSecondaryOpen;
private Drawable mSecondaryClosed;
- private View mHeader;
+ private View mHeaderColorBar;
private View mSideBar;
private ImageView mHeaderIcon;
private TextView mHeaderAccountType;
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);
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);
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
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);