Esempio n. 1
0
        public ContactPickedEventArgs(Type type, Contact contact)
        {
            this.type = type.ToString();
            FirstName = contact.FirstName;
            LastName = contact.LastName;

            /*switch (type)
            {
                case Type.Sms:
                    {*/
                        var phone = contact.Phones.FirstOrDefault();
                        if (phone != null)
                            Phone = phone.Number;
             /*           break;
                    }
                case Type.Email:
                    {*/
                        var email = contact.Emails.FirstOrDefault();
                        if (email != null)
                            Email = email.Address;
                 /*       break;

                    }
                default:

                    break;
            }*/
        }
        private bool Matches(Contact contact)
        {
            var matches = false;

            if ((contact.FirstName != null) || (contact.LastName != null))
            {
                matches = contact.Phones.Any(p => p.Label == "Mobile");
            }

            return matches;
        }
Esempio n. 3
0
        public ContactPage(Contact contact)
        {
            var stack = new StackLayout { Padding = 10, Spacing = 10 };

            stack.Children.Add(new Label
                {
                    Text = "DisplayName: " + contact.DisplayName
                });


            stack.Children.Add(new Label
                {
                    Text = "FirstName: " + contact.FirstName
                });

            stack.Children.Add(new Label
                {
                    Text = "MiddleName: " + contact.MiddleName
                });

            stack.Children.Add(new Label
                {
                    Text = "LastName: " + contact.LastName
                });


            stack.Children.Add(new Label
                {
                    Text = "Id: " + contact.Id
                });

            stack.Children.Add(new Label
                {
                    Text = "Nickname: " + contact.Nickname
                });

            stack.Children.Add(new Label
                {
                    Text = "Emails: "
                });

            foreach (var email in contact.Emails)
            {
                stack.Children.Add(new Label
                    {
                        Text = "Address: " + email.Address
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Label: " + email.Label
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Type: " + email.Type.ToString()
                    });
            }

            stack.Children.Add(new Label
                {
                    Text = "Addresses: "
                });

            foreach (var address in contact.Addresses)
            {
                stack.Children.Add(new Label
                    {
                        Text = "City: " + address.City
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Country: " + address.Country
                    });


                stack.Children.Add(new Label
                    {
                        Text = "label: " + address.Label
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Post: " + address.PostalCode
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Region: " + address.Region
                    });


                stack.Children.Add(new Label
                    {
                        Text = "StreetAddress: " + address.StreetAddress
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Type: " + address.Type
                    });

            }

            stack.Children.Add(new Label
                {
                    Text = "Prefix: " + contact.Prefix
                });


            stack.Children.Add(new Label
                {
                    Text = "Suffix: " + contact.Suffix
                });

      
            stack.Children.Add(new Label
                {
                    Text = "Notes: "
                });

            foreach (var note in contact.Notes)
            {
                stack.Children.Add(new Label
                    {
                        Text = "note: " + note.Contents
                    });
            }

            stack.Children.Add(new Label
                {
                    Text = "Organizations: "
                });

            foreach (var org in contact.Organizations)
            {
                stack.Children.Add(new Label
                    {
                        Text = "ContactTitle: " + org.ContactTitle
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Label: " + org.Label
                    });


                stack.Children.Add(new Label
                    {
                        Text = "Name: " + org.Name
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Type: " + org.Type
                    });
            }


            stack.Children.Add(new Label
                {
                    Text = "Phones: "
                });

            foreach (var phone in contact.Phones)
            {
                stack.Children.Add(new Label
                    {
                        Text = "Label: " + phone.Label
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Number: " + phone.Number
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Type: " + phone.Type
                    });
            }

            stack.Children.Add(new Label
                {
                    Text = "Relationships: "
                });

            foreach (var relation in contact.Relationships)
            {
                stack.Children.Add(new Label
                    {
                        Text = "Name: " + relation.Name
                    });

                stack.Children.Add(new Label
                    {
                        Text = "Type: " + relation.Type
                    });
            }

            stack.Children.Add(new Label
                {
                    Text = "Websites: "
                });

            foreach (var site in contact.Websites)
            {
                stack.Children.Add(new Label
                    {
                        Text = "Address: " + site.Address
                    });
            }


            Content = new ScrollView
            {
                Content = stack
            };
        }
Esempio n. 4
0
 public ExtendedContact(Contact contact)
 {
     InnerContact = contact;
     IsSelected = false;
 }
Esempio n. 5
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;
      }
    }
Esempio n. 6
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
      {
		if (string.IsNullOrWhiteSpace(recordId))
			return;

        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();
      }
    }
Esempio n. 7
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));

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

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

      return contact;
    }
Esempio n. 8
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)
            {
              Tag = 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();
      }
    }
Esempio n. 9
0
        private static Contact GetContact(Microsoft.Phone.UserData.Contact contact)
        {
            var c = new Contact
            {
                Tag = contact
            };

            c.DisplayName = contact.DisplayName;

            if (contact.CompleteName != null)
            {
                c.Prefix     = contact.CompleteName.Title;
                c.FirstName  = contact.CompleteName.FirstName;
                c.MiddleName = contact.CompleteName.MiddleName;
                c.LastName   = contact.CompleteName.LastName;
                c.Suffix     = contact.CompleteName.Suffix;
            }

            foreach (ContactAddress address in contact.Addresses)
            {
                c.Addresses.Add(GetAddress(address));
            }

            foreach (ContactEmailAddress email in contact.EmailAddresses)
            {
                c.Emails.Add(GetEmail(email));
            }

            foreach (ContactPhoneNumber phone in contact.PhoneNumbers)
            {
                c.Phones.Add(GetPhone(phone));
            }

            foreach (ContactCompanyInformation company in contact.Companies)
            {
                c.Organizations.Add(GetOrganization(company));
            }

            foreach (string name in contact.Children)
            {
                c.Relationships.Add(new Relationship {
                    Name = name, Type = RelationshipType.Child
                });
            }

            foreach (string name in contact.SignificantOthers)
            {
                c.Relationships.Add(new Relationship {
                    Name = name, Type = RelationshipType.SignificantOther
                });
            }

            foreach (string url in contact.Websites)
            {
                c.Websites.Add(new Website {
                    Address = url
                });
            }

            foreach (string note in contact.Notes)
            {
                c.Notes.Add(new Note {
                    Contents = note
                });
            }

            return(c);
        }
Esempio n. 10
0
 public ContactViewModel(Contact contact)
 {
     _contact = contact;
 }