コード例 #1
0
        public Contact Load(string id)
        {
            if (String.IsNullOrWhiteSpace(id))
            {
                throw new ArgumentNullException("id");
            }

            CheckStatus();

            int rowId;

            if (!Int32.TryParse(id, out rowId))
            {
                throw new ArgumentException("Not a valid contact ID", "id");
            }

            ABPerson person = this.addressBook.GetPerson(rowId);

            if (person == null)
            {
                return(null);
            }

            return(ContactHelper.GetContact(person));
        }
コード例 #2
0
        /// <summary>
        /// Attempts to load a contact for the specified <paramref name="id"/>.
        /// </summary>
        /// <param name="id"></param>
        /// <returns>The <see cref="Contact"/> if found, <c>null</c> otherwise.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="id"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="id"/> is empty.</exception>
        public Contact Load(string id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (id.Trim() == String.Empty)
            {
                throw new ArgumentException("Invalid ID", "id");
            }

            Android.Net.Uri curi; string column;
            if (PreferContactAggregation)
            {
                curi   = ContactsContract.Contacts.ContentUri;
                column = ContactsContract.ContactsColumns.LookupKey;
            }
            else
            {
                curi   = ContactsContract.RawContacts.ContentUri;
                column = ContactsContract.RawContactsColumns.ContactId;
            }

            ICursor c = null;

            try
            {
                c = this.content.Query(curi, null, column + " = ?", new[] { id }, null);
                return(c.MoveToNext() ? ContactHelper.GetContact(!PreferContactAggregation, this.content, this.resources, c) : null);
            }
            finally
            {
                if (c != null)
                {
                    c.Deactivate();
                }
            }
        }
コード例 #3
0
        public IEnumerator <Contact> GetEnumerator()
        {
            Android.Net.Uri table = (this.rawContacts)
                    ? ContactsContract.RawContacts.ContentUri
                    : ContactsContract.Contacts.ContentUri;

            string query = null;

            string[] parameters = null;
            string   sortString = null;

            string[] projections = null;

            if (this.translator != null)
            {
                table      = this.translator.Table;
                query      = this.translator.QueryString;
                parameters = this.translator.ClauseParameters;
                sortString = this.translator.SortString;

                if (this.translator.Projections != null)
                {
                    projections = this.translator.Projections
                                  .Where(p => p.Columns != null)
                                  .SelectMany(t => t.Columns)
                                  .ToArray();

                    if (projections.Length == 0)
                    {
                        projections = null;
                    }
                }

                if (this.translator.Skip > 0 || this.translator.Take > 0)
                {
                    StringBuilder limitb = new StringBuilder();

                    if (sortString == null)
                    {
                        limitb.Append(ContactsContract.ContactsColumns.LookupKey);
                    }

                    limitb.Append(" LIMIT ");

                    if (this.translator.Skip > 0)
                    {
                        limitb.Append(this.translator.Skip);
                        if (this.translator.Take > 0)
                        {
                            limitb.Append(",");
                        }
                    }

                    if (this.translator.Take > 0)
                    {
                        limitb.Append(this.translator.Take);
                    }

                    sortString = (sortString == null) ? limitb.ToString() : sortString + limitb;
                }
            }

            ICursor cursor = null;

            try
            {
                cursor = this.content.Query(table, projections, query, parameters, sortString);
                if (cursor == null)
                {
                    yield break;
                }

                foreach (Contact contact in ContactHelper.GetContacts(cursor, this.rawContacts, this.content, this.resources, BatchSize))
                {
                    yield return(contact);
                }
            }
            finally
            {
                if (cursor != null)
                {
                    cursor.Close();
                }
            }
        }
コード例 #4
0
 public IEnumerator <Contact> GetEnumerator()
 {
     return(ContactHelper.GetContacts(!PreferContactAggregation, this.content, this.resources).GetEnumerator());
 }