Inheritance: IContact
Ejemplo n.º 1
0
		internal static IEnumerable<Contact> GetContacts (bool rawContacts, ContentResolver content, Resources resources, string[] ids)
		{
			ICursor c = null;

			string column = (rawContacts)
								? ContactsContract.RawContactsColumns.ContactId
								: ContactsContract.ContactsColumns.LookupKey;

			StringBuilder whereb = new StringBuilder();
			for (int i = 0; i < ids.Length; i++)
			{
				if (i > 0)
					whereb.Append (" OR ");

				whereb.Append (column);
				whereb.Append ("=?");
			}

			int x = 0;
			var map = new Dictionary<string, Contact> (ids.Length);

			try
			{
				Contact currentContact = null;

				c = content.Query (ContactsContract.Data.ContentUri, null, whereb.ToString(), ids, ContactsContract.ContactsColumns.LookupKey);
				if (c == null)
					yield break;

				int idIndex = c.GetColumnIndex (column);
				int dnIndex = c.GetColumnIndex (ContactsContract.ContactsColumns.DisplayName);
				while (c.MoveToNext())
				{
					string id = c.GetString (idIndex);
					if (currentContact == null || currentContact.Id != id)
					{
						// We need to yield these in the original ID order
						if (currentContact != null) {
							if (currentContact.Id == ids[x]) {
								yield return currentContact;
								x++;
							}
							else
								map.Add (currentContact.Id, currentContact);
						}

						currentContact = new Contact (id, !rawContacts, content);
						currentContact.DisplayName = c.GetString (dnIndex);
					}

					FillContactWithRow (resources, currentContact, c);
				}

				if (currentContact != null)
					map.Add (currentContact.Id, currentContact);

				for (; x < ids.Length; x++)
					yield return map[ids[x]];
			}
			finally
			{
				if (c != null)
					c.Close();
			}
		}
Ejemplo n.º 2
0
		internal static void FillContactExtras (bool rawContact, ContentResolver content, Resources resources, string recordId, Contact contact)
		{
			ICursor c = null;

			string column = (rawContact)
								? ContactsContract.RawContactsColumns.ContactId
								: ContactsContract.ContactsColumns.LookupKey;

			try
			{
				c = content.Query (ContactsContract.Data.ContentUri, null, column + " = ?", new[] { recordId }, null);
				if (c == null)
					return;

				while (c.MoveToNext())
					FillContactWithRow (resources, contact, c);
			}
			finally
			{
				if (c != null)
					c.Close();
			}
		}
Ejemplo n.º 3
0
		private static void FillContactWithRow (Resources resources, Contact contact, ICursor c)
		{
			string dataType = c.GetString (c.GetColumnIndex (ContactsContract.DataColumns.Mimetype));
			switch (dataType)
			{
				case ContactsContract.CommonDataKinds.Nickname.ContentItemType:
					contact.Nickname = c.GetString (c.GetColumnIndex (ContactsContract.CommonDataKinds.Nickname.Name));
					break;

				case StructuredName.ContentItemType:
					contact.Prefix = c.GetString (StructuredName.Prefix);
					contact.FirstName = c.GetString (StructuredName.GivenName);
					contact.MiddleName = c.GetString (StructuredName.MiddleName);
					contact.LastName = c.GetString (StructuredName.FamilyName);
					contact.Suffix = c.GetString (StructuredName.Suffix);
					break;

				case ContactsContract.CommonDataKinds.Phone.ContentItemType:
					contact.phones.Add (GetPhone (c, resources));
					break;

				case ContactsContract.CommonDataKinds.Email.ContentItemType:
					contact.emails.Add (GetEmail (c, resources));
					break;

				case ContactsContract.CommonDataKinds.Note.ContentItemType:
					contact.notes.Add (GetNote (c, resources));
					break;

				case ContactsContract.CommonDataKinds.Organization.ContentItemType:
					contact.organizations.Add (GetOrganization (c, resources));
					break;

				case StructuredPostal.ContentItemType:
					contact.addresses.Add (GetAddress (c, resources));
					break;

				case InstantMessaging.ContentItemType:
					contact.instantMessagingAccounts.Add (GetImAccount (c, resources));
					break;

				case WebsiteData.ContentItemType:
					contact.websites.Add (GetWebsite (c, resources));
					break;

				case Relation.ContentItemType:
					contact.relationships.Add (GetRelationship (c, resources));
					break;
			}
		}
Ejemplo n.º 4
0
		internal static Contact GetContact (bool rawContact, ContentResolver content, Resources resources, ICursor cursor)
		{
			string id = (rawContact)
							? cursor.GetString (cursor.GetColumnIndex (ContactsContract.RawContactsColumns.ContactId))
							: cursor.GetString (cursor.GetColumnIndex (ContactsContract.ContactsColumns.LookupKey));

			Contact contact = new Contact (id, !rawContact, content);
			contact.DisplayName = GetString (cursor, ContactsContract.ContactsColumns.DisplayName);

			FillContactExtras (rawContact, content, resources, id, contact);

			return contact;
		}