private void AtualizarAgenda(List <Contato> contatos) { if (agenda.GetPeople().Length == 0) { Console.WriteLine("O Aparelho não possui contatos."); } else { //Remove os contatos existentes RemoveContatosExistentes(contatos); //Cadastra os contatos do arquivo CadastraContatos(contatos); } }
// get correct number from database public void numbersChecked(Object sender, CheckNumbersCompletedEventArgs e) { try { if (e.Result.ValidNumbers != null) { ABAddressBook addressBook = new ABAddressBook(); ABPerson[] allContacts = addressBook.GetPeople(); foreach (var contact in allContacts) { var phone = contact.GetPhones(); foreach (var number in phone) { if (e.Result.ValidNumbers.Contains(number.Value.Replace(" ", string.Empty))) { ServiceHelper.instance.targetPhoneNumber = number.Value.Replace(" ", string.Empty); } } } ServiceHelper.instance.createMeeting(ServiceHelper.instance.targetPhoneNumber, ServiceHelper.instance.localPhoneNumber, meetingRequested); } else { MessageHelper.showCouldNotCreateMeeting(); } } catch { MessageHelper.showErrorMesage("numbersChecked failed"); } }
private Contact[] GetContacts(ABAddressBook ab) { var contacts = new List<Contact>(); foreach (var person in ab.GetPeople()) { if (string.IsNullOrEmpty(person.FirstName) && string.IsNullOrEmpty(person.LastName)) continue; string displayName = string.Format("{0} {1}", person.FirstName, person.LastName); string number; var phones = person.GetPhones(); if (phones == null || !phones.Any()) continue; number = phones[0].Value; if (!string.IsNullOrEmpty(number)) { contacts.Add(new Contact { Name = displayName, Number = number }); } } if (!contacts.Any()) { return new[] { new Contact { Name = "Egor Bogatov", Number = "+01231"}, new Contact { Name = "Ian Gillan", Number = "+01232"}, new Contact { Name = "Freddie Mercury", Number = "+01233"}, new Contact { Name = "David Gilmour", Number = "+01234"}, new Contact { Name = "Steve Ballmer", Number = "+01235"}, }; } return contacts.ToArray(); }
public void numbersChecked(Object sender, CheckNumbersCompletedEventArgs e) { if (e.Result.ValidNumbers != null) { InvokeOnMainThread(delegate() { //address book stuff ABAddressBook addressBook = new ABAddressBook(); ABPerson[] allContacts = addressBook.GetPeople(); _contacts.Clear(); //remove old foreach (var contact in allContacts) { var phone = contact.GetPhones(); foreach (var number in phone) { if (e.Result.ValidNumbers.Contains(number.Value.Replace(" ", string.Empty).ToString())) { _contacts.Add(contact); } } } //----------------------------------------------- //TableView.DataSource = new ContactsTableDataSource (this, _contacts); //TableView.Delegate = new ContactsTableViewDelegate (this, _contacts); _loading.StopAnimating(); //stop animating _loading.RemoveFromSuperview(); _tableView.ReloadData(); }); } }
public IEnumerator <IContact> GetEnumerator() { CheckStatus(); try { return(addressBook.GetPeople().Select(ContactHelper.GetContact).GetEnumerator()); } catch (Exception ex) { Debug.Write(ex); return(Enumerable.Empty <IContact>().GetEnumerator()); } }
private Contact[] GetContacts(ABAddressBook ab) { var contacts = new List <Contact>(); foreach (var person in ab.GetPeople()) { if (string.IsNullOrEmpty(person.FirstName) && string.IsNullOrEmpty(person.LastName)) { continue; } string displayName = string.Format("{0} {1}", person.FirstName, person.LastName); string number; var phones = person.GetPhones(); if (phones == null || !phones.Any()) { continue; } number = phones[0].Value; if (!string.IsNullOrEmpty(number)) { contacts.Add(new Contact { Name = displayName, Number = number }); } } if (!contacts.Any()) { return(new[] { new Contact { Name = "Egor Bogatov", Number = "+01231" }, new Contact { Name = "Ian Gillan", Number = "+01232" }, new Contact { Name = "Freddie Mercury", Number = "+01233" }, new Contact { Name = "David Gilmour", Number = "+01234" }, new Contact { Name = "Steve Ballmer", Number = "+01235" }, }); } return(contacts.ToArray()); }
public async Task <IEnumerable <Contact> > GetContacts() { return(await Task.Run(() => { var res = new List <Contact>(); var status = ABAddressBook.GetAuthorizationStatus(); if (status == ABAuthorizationStatus.Denied || status == ABAuthorizationStatus.Restricted) { return res; } else { var addressBook = new ABAddressBook(); var valorizeRes = new Action(() => { var peoples = addressBook.GetPeople(); foreach (var item in peoples) { res.Add(new Contact { Name = $"{item.FirstName} {item.LastName}" }); } }); if (status == ABAuthorizationStatus.NotDetermined) { addressBook.RequestAccess((granted, e) => { if (granted) { valorizeRes.Invoke(); } }); } else { valorizeRes.Invoke(); } return res; } })); }
public override void ViewDidLoad() { base.ViewDidLoad(); // query the address book directly using (var addressBook = new ABAddressBook()) { // Get all people with a specfied name //var people = addressBook.GetPeopleWithName ("John Doe"); //people.ToList ().ForEach (p => Console.WriteLine ("{0} {1} - ", p.FirstName, p.LastName)); // Use Linq to query contacts based upon any criteria addressBook.RequestAccess((bool x, NSError z) => {}); var people = addressBook.GetPeople(); people.ToList().FindAll(p => p.LastName == "Smith").ForEach( p => Console.WriteLine("{0} {1}", p.FirstName, p.LastName)); } }
public override void ViewDidLoad() { base.ViewDidLoad(); _updateButton = new UIBarButtonItem(); _updateButton.Title = "Update"; UIBarButtonItem checkButton = new UIBarButtonItem(); checkButton.Title = "Check"; this.Title = "Meet With"; this.NavigationItem.LeftBarButtonItem = _updateButton; this.NavigationItem.RightBarButtonItem = checkButton; /* ----------------------------------------------- * Need to Sort out which Contacts have iMeet here, * then gets passed to dataSource to display */ _tableView = new UITableView(new RectangleF(0, 0, this.View.Frame.Width, this.View.Frame.Height), UITableViewStyle.Plain); this.Add(_tableView); _tableView.DataSource = new ContactsTableDataSource(_contacts); _tableView.Delegate = new ContactsTableViewDelegate(this, _contacts); // use phone number ABAddressBook addressBook = new ABAddressBook(); ABPerson[] allContacts = addressBook.GetPeople(); //keeps crashing around here? foreach (var contact in allContacts.Where(contact => contact.GetPhones().Where(phone => (phone.Label == ABPersonPhoneLabel.Mobile || phone.Label == ABPersonPhoneLabel.iPhone || phone.Label == ABPersonPhoneLabel.Main)).Count() > 0)) { _numbers.Add(contact.GetPhones().Select(z => z.Value.Replace(" ", string.Empty).Trim().ToString()).FirstOrDefault()); } this.View.AddSubview(_loading); _loading.StartAnimating(); //start animating checkPhoneNumbers(_numbers); _updateButton.Clicked += HandleUpdateButtonClicked; checkButton.Clicked += HandleCheckButtonClicked; }
public override void ViewDidLoad() { base.ViewDidLoad (); // query the address book directly using (var addressBook = new ABAddressBook ()) { // Get all people with a specfied name //var people = addressBook.GetPeopleWithName ("John Doe"); //people.ToList ().ForEach (p => Console.WriteLine ("{0} {1} - ", p.FirstName, p.LastName)); // Use Linq to query contacts based upon any criteria addressBook.RequestAccess((bool x, NSError z) => {}); var people = addressBook.GetPeople (); people.ToList ().FindAll (p => p.LastName == "Smith").ForEach ( p => Console.WriteLine ("{0} {1}", p.FirstName, p.LastName)); } }
private void PopulateContacts() { var addressBook = new ABAddressBook(); var people = addressBook.GetPeople(); // clear address book foreach (var person in people) { addressBook.Remove(person); } addressBook.Save(); var random = new Random(); // create 200 random contacts foreach (var name in _names) { // create an ABRecordRef var record = new ABPerson(); record.FirstName = name[0]; record.LastName = name[1]; var phones = new ABMutableStringMultiValue(); phones.Add(GeneratePhone(random).ToString(), ABPersonPhoneLabel.Mobile); if (random.Next() % 2 == 1) { phones.Add(GeneratePhone(random).ToString(), ABPersonPhoneLabel.Main); } record.SetPhones(phones); addressBook.Add(record); } addressBook.Save(); }
private void PopulateContacts() { var addressBook = new ABAddressBook(); var people = addressBook.GetPeople(); // clear address book foreach(var person in people) { addressBook.Remove(person); } addressBook.Save(); var random = new Random(); // create 200 random contacts foreach (var name in _names) { // create an ABRecordRef var record = new ABPerson(); record.FirstName = name[0]; record.LastName = name[1]; var phones = new ABMutableStringMultiValue(); phones.Add(GeneratePhone(random).ToString(), ABPersonPhoneLabel.Mobile); if(random.Next() % 2 == 1) { phones.Add(GeneratePhone(random).ToString(), ABPersonPhoneLabel.Main); } record.SetPhones(phones); addressBook.Add(record); } addressBook.Save(); }
public static void getMyPersonWithEmail(ABAddressBook addressBook,List<MyPerson> ContactsWithEmail) { ABPerson[] people = addressBook.GetPeople(); foreach(var x in people) { ABMultiValue<string> Emails=x.GetEmails(); foreach(var y in Emails) { if(!String.IsNullOrEmpty(y.Value)) { MyPerson newMyPerson=new MyPerson(); newMyPerson.FirstName=String.IsNullOrEmpty(x.FirstName)?"":x.FirstName; newMyPerson.LastName=String.IsNullOrEmpty(x.LastName)?"":x.LastName; newMyPerson.Email=y.Value; ContactsWithEmail.Add(newMyPerson); continue; } } } }
public static void getMyPersonWithPhoneNumber(ABAddressBook addressBook,List<MyPerson> ContactsWithPhoneNumber) { try{ ABPerson[] people = addressBook.GetPeople(); foreach(var x in people) { ABMultiValue<string> PhoneNumbers=x.GetPhones(); foreach(var y in PhoneNumbers) { if(!String.IsNullOrEmpty(y.Value)&&y.Label.ToString().ToLower().Contains("mobile")) { MyPerson newMyPerson=new MyPerson(); newMyPerson.FirstName=String.IsNullOrEmpty(x.FirstName)?"":x.FirstName; newMyPerson.LastName=String.IsNullOrEmpty(x.LastName)?"":x.LastName; newMyPerson.Phone=y.Value; ContactsWithPhoneNumber.Add(newMyPerson); continue; } } } } catch(Exception e){ Insights.Report(e); } }
string InitializePropsUI() { var help = Source as IHelpful; var helpText = ""; var q = from t in SourceType.GetProperties () where t.DeclaringType == SourceType && t.CanWrite select t; var props = q.ToArray (); var rows = new List<Row> (); foreach (var p in props) { var ignoreAttrs = p.GetCustomAttributes (typeof(IgnoreAttribute), true); if (ignoreAttrs.Length > 0) continue; var isEmail = p.GetCustomAttributes (typeof(EmailInputAttribute), true).Length > 0; if (!isEmail && p.Name == "Email") { isEmail = true; } var isChooseEmail = p.GetCustomAttributes (typeof(ChooseEmailInputAttribute), true).Length > 0; var title = Theme.GetTitle (p.Name); if (help != null) { var h = help.HelpForProperty (p.Name); if (h != "") { helpText += title + " " + h + "\n"; } } var label = new UILabel { BackgroundColor = UIColor.Black, TextColor = Lcars.ComponentColors[LcarsComponentType.CriticalFunction], Text = title, TextAlignment = UITextAlignment.Right, BaselineAdjustment = UIBaselineAdjustment.AlignBaselines, Font = Theme.InputFont, AdjustsFontSizeToFitWidth = true }; var row = new Row { Property = p }; rows.Add (row); row.Label = label; UIKeyboardType kbd = UIKeyboardType.Default; if (isEmail || isChooseEmail) { kbd = UIKeyboardType.EmailAddress; } else if (p.Name == "Url") { kbd = UIKeyboardType.Url; } else if (p.PropertyType == typeof(int)) { kbd = UIKeyboardType.NumberPad; } var init = p.GetValue (Source, null); var text = new UITextField { Placeholder = title, BackgroundColor = UIColor.Black, TextColor = UIColor.White, Font = Theme.InputFont, AdjustsFontSizeToFitWidth = false, AutocapitalizationType = UITextAutocapitalizationType.None, KeyboardType = kbd, Text = init != null ? init.ToString () : "" }; row.Text = text; if (p.Name.ToLowerInvariant ().IndexOf ("password") >= 0) { text.SecureTextEntry = true; text.AutocorrectionType = UITextAutocorrectionType.No; } if (p.Name != "Search") { text.AutocorrectionType = UITextAutocorrectionType.No; } if (text.Text.Length == 0 && !isChooseEmail) { text.BecomeFirstResponder (); } label.Hidden = text.Text.Length == 0; if (isChooseEmail) { text.EditingDidBegin += delegate { try { bool hasPeople = false; using (var adds = new ABAddressBook ()) { foreach (var pe in adds.GetPeople ()) { var es = pe.GetEmails (); if (es.Count > 0) { hasPeople = true; break; } } } if (hasPeople) { Sounds.PlayBeep (); var em = new ChooseEmail (); em.EmailSelected += emailAddress => { text.Text = emailAddress; UpdateUI (); }; App.Inst.ShowDialog (em); NSTimer.CreateScheduledTimer (TimeSpan.FromMilliseconds (30), delegate { try { HideKeyBoard (this); } catch (Exception err) { Log.Error (err); } }); } } catch (Exception error) { Log.Error (error); } }; } text.AllEditingEvents += delegate { try { label.Hidden = string.IsNullOrEmpty (text.Text); UpdateUI (); } catch (Exception error) { Log.Error (error); } }; AddSubview (label); AddSubview (text); } _propViews = rows.ToArray (); return helpText; }
/// <summary> /// Gets all people in contact list. /// </summary> public static ABPerson[] GetAllPeopleInContactList() { ABAddressBook addressBook = new ABAddressBook(); ABPerson[] contactList = addressBook.GetPeople(); return contactList; }
private IEnumerable <IContact> GetContacts() { return(m_addressBook.GetPeople().Select(ContactHelper.GetContact)); }
static Task <List <Contact> > DoReadContacts(ContactSearchParams searchParams) { var people = searchParams.NameKeywords.HasValue() ? Addressbook.GetPeopleWithName(searchParams.NameKeywords) : Addressbook.GetPeople(); return(Task.FromResult(people.Select(x => Extract(x, searchParams)).ToList())); }
string InitializePropsUI() { var help = Source as IHelpful; var helpText = ""; var q = from t in SourceType.GetProperties() where t.DeclaringType == SourceType && t.CanWrite select t; var props = q.ToArray(); var rows = new List <Row> (); foreach (var p in props) { var ignoreAttrs = p.GetCustomAttributes(typeof(IgnoreAttribute), true); if (ignoreAttrs.Length > 0) { continue; } var isEmail = p.GetCustomAttributes(typeof(EmailInputAttribute), true).Length > 0; if (!isEmail && p.Name == "Email") { isEmail = true; } var isChooseEmail = p.GetCustomAttributes(typeof(ChooseEmailInputAttribute), true).Length > 0; var title = Theme.GetTitle(p.Name); if (help != null) { var h = help.HelpForProperty(p.Name); if (h != "") { helpText += title + " " + h + "\n"; } } var label = new UILabel { BackgroundColor = UIColor.Black, TextColor = Lcars.ComponentColors[LcarsComponentType.CriticalFunction], Text = title, TextAlignment = UITextAlignment.Right, BaselineAdjustment = UIBaselineAdjustment.AlignBaselines, Font = Theme.InputFont, AdjustsFontSizeToFitWidth = true }; var row = new Row { Property = p }; rows.Add(row); row.Label = label; UIKeyboardType kbd = UIKeyboardType.Default; if (isEmail || isChooseEmail) { kbd = UIKeyboardType.EmailAddress; } else if (p.Name == "Url") { kbd = UIKeyboardType.Url; } else if (p.PropertyType == typeof(int)) { kbd = UIKeyboardType.NumberPad; } var init = p.GetValue(Source, null); var text = new UITextField { Placeholder = title, BackgroundColor = UIColor.Black, TextColor = UIColor.White, Font = Theme.InputFont, AdjustsFontSizeToFitWidth = false, AutocapitalizationType = UITextAutocapitalizationType.None, KeyboardType = kbd, Text = init != null?init.ToString() : "" }; row.Text = text; if (p.Name.ToLowerInvariant().IndexOf("password") >= 0) { text.SecureTextEntry = true; text.AutocorrectionType = UITextAutocorrectionType.No; } if (p.Name != "Search") { text.AutocorrectionType = UITextAutocorrectionType.No; } if (text.Text.Length == 0 && !isChooseEmail) { text.BecomeFirstResponder(); } label.Hidden = text.Text.Length == 0; if (isChooseEmail) { text.EditingDidBegin += delegate { try { bool hasPeople = false; using (var adds = new ABAddressBook()) { foreach (var pe in adds.GetPeople()) { var es = pe.GetEmails(); if (es.Count > 0) { hasPeople = true; break; } } } if (hasPeople) { Sounds.PlayBeep(); var em = new ChooseEmail(); em.EmailSelected += emailAddress => { text.Text = emailAddress; UpdateUI(); }; App.Inst.ShowDialog(em); NSTimer.CreateScheduledTimer(TimeSpan.FromMilliseconds(30), delegate { try { HideKeyBoard(this); } catch (Exception err) { Log.Error(err); } }); } } catch (Exception error) { Log.Error(error); } }; } text.AllEditingEvents += delegate { try { label.Hidden = string.IsNullOrEmpty(text.Text); UpdateUI(); } catch (Exception error) { Log.Error(error); } }; AddSubview(label); AddSubview(text); } _propViews = rows.ToArray(); return(helpText); }