Merge "Import new translations."
diff --git a/res/layout/item_kind_section.xml b/res/layout/item_kind_section.xml
index ebfeddf..d1dec5e 100644
--- a/res/layout/item_kind_section.xml
+++ b/res/layout/item_kind_section.xml
@@ -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"
diff --git a/src/com/android/contacts/ContactsListActivity.java b/src/com/android/contacts/ContactsListActivity.java
index 9badeb6..c4976e2 100644
--- a/src/com/android/contacts/ContactsListActivity.java
+++ b/src/com/android/contacts/ContactsListActivity.java
@@ -1666,9 +1666,7 @@
finish();
} else if (mMode == MODE_PICK_PHONE || mMode == MODE_QUERY_PICK_PHONE) {
Cursor c = (Cursor) mAdapter.getItem(position);
- long contactId = c.getLong(PHONE_CONTACT_ID_COLUMN_INDEX);
- returnPickerResult(c, c.getString(PHONE_DISPLAY_NAME_COLUMN_INDEX),
- ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId));
+ returnPickerResult(c, c.getString(PHONE_DISPLAY_NAME_COLUMN_INDEX), uri);
} else if ((mMode & MODE_MASK_PICKER) != 0) {
Cursor c = (Cursor) mAdapter.getItem(position);
returnPickerResult(c, c.getString(getSummaryDisplayNameColumnIndex()), uri);
@@ -1690,10 +1688,10 @@
}
/**
- * @param contactUri In most cases, this should be a lookup {@link Uri}, possibly
+ * @param selectedUri In most cases, this should be a lookup {@link Uri}, possibly
* generated through {@link Contacts#getLookupUri(long, String)}.
*/
- private void returnPickerResult(Cursor c, String name, Uri contactUri) {
+ private void returnPickerResult(Cursor c, String name, Uri selectedUri) {
final Intent intent = new Intent();
if (mShortcutAction != null) {
@@ -1704,13 +1702,13 @@
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
- shortcutIntent.setData(contactUri);
+ shortcutIntent.setData(selectedUri);
shortcutIntent.putExtra(ContactsContract.QuickContact.EXTRA_MODE,
ContactsContract.QuickContact.MODE_LARGE);
shortcutIntent.putExtra(ContactsContract.QuickContact.EXTRA_EXCLUDE_MIMES,
(String[]) null);
- final Bitmap icon = framePhoto(loadContactPhoto(contactUri, null));
+ final Bitmap icon = framePhoto(loadContactPhoto(selectedUri, null));
if (icon != null) {
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, scaleToAppIconSize(icon));
} else {
@@ -1737,7 +1735,7 @@
shortcutIntent = new Intent(mShortcutAction, phoneUri);
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON,
- generatePhoneNumberIcon(contactUri, type, resid));
+ generatePhoneNumberIcon(selectedUri, type, resid));
}
shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
@@ -1745,7 +1743,7 @@
setResult(RESULT_OK, intent);
} else {
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
- setResult(RESULT_OK, intent.setData(contactUri));
+ setResult(RESULT_OK, intent.setData(selectedUri));
}
finish();
}
@@ -2071,13 +2069,29 @@
return CONTACTS_SUMMARY_PROJECTION;
}
- private Bitmap loadContactPhoto(Uri lookupUri, BitmapFactory.Options options) {
+ private Bitmap loadContactPhoto(Uri selectedUri, BitmapFactory.Options options) {
+ Uri contactUri = null;
+ if (Contacts.CONTENT_ITEM_TYPE.equals(getContentResolver().getType(selectedUri))) {
+ // TODO we should have a "photo" directory under the lookup URI itself
+ contactUri = Contacts.lookupContact(getContentResolver(), selectedUri);
+ } else {
+
+ Cursor cursor = getContentResolver().query(selectedUri,
+ new String[] { Data.CONTACT_ID }, null, null, null);
+ try {
+ if (cursor != null && cursor.moveToFirst()) {
+ final long contactId = cursor.getLong(0);
+ contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
+ }
+ } finally {
+ if (cursor != null) cursor.close();
+ }
+ }
+
Cursor cursor = null;
Bitmap bm = null;
try {
- // TODO we should have a "photo" directory under the lookup URI itself
- Uri contactUri = Contacts.lookupContact(getContentResolver(), lookupUri);
Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
cursor = getContentResolver().query(photoUri, new String[] {Photo.PHOTO},
null, null, null);
diff --git a/src/com/android/contacts/model/ContactsSource.java b/src/com/android/contacts/model/ContactsSource.java
index 1198837..d008482 100644
--- a/src/com/android/contacts/model/ContactsSource.java
+++ b/src/com/android/contacts/model/ContactsSource.java
@@ -141,7 +141,7 @@
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 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 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 @@
this.iconRes = iconRes;
this.weight = weight;
this.editable = editable;
+ this.isList = true;
this.typeOverallMax = -1;
}
}
diff --git a/src/com/android/contacts/model/ExchangeSource.java b/src/com/android/contacts/model/ExchangeSource.java
index b26bdeb..2313b33 100644
--- a/src/com/android/contacts/model/ExchangeSource.java
+++ b/src/com/android/contacts/model/ExchangeSource.java
@@ -110,7 +110,7 @@
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 @@
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 @@
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 @@
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));
diff --git a/src/com/android/contacts/model/FallbackSource.java b/src/com/android/contacts/model/FallbackSource.java
index 8c3a9d2..08c0e28 100644
--- a/src/com/android/contacts/model/FallbackSource.java
+++ b/src/com/android/contacts/model/FallbackSource.java
@@ -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.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 @@
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 @@
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);
diff --git a/src/com/android/contacts/ui/widget/KindSectionView.java b/src/com/android/contacts/ui/widget/KindSectionView.java
index e379b69..46ce514 100644
--- a/src/com/android/contacts/ui/widget/KindSectionView.java
+++ b/src/com/android/contacts/ui/widget/KindSectionView.java
@@ -32,6 +32,7 @@
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 @@
private ViewGroup mEditors;
private View mAdd;
+ private ImageView mAddPlusButton;
private TextView mTitle;
private DataKind mKind;
@@ -77,6 +79,8 @@
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 @@
// 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 @@
// 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;
+ // Check if we are displaying anything here
+ boolean hasEntries = mState.hasMimeEntries(mKind.mimeType);
- 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);
+ 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 @@
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();