private void Dial()
 {
     var book = new Xamarin.Contacts.AddressBook(this);
     book.RequestPermission().ContinueWith(t =>
         {
             if (!t.Result)
             {
                 Console.WriteLine("Permission denied by user or manifest");
                 return;
             }
             var validContacts = book.Where(a => a.Phones.Any(b => b.Number.Any())).ToList();
             var totalValidContacts = validContacts.Count;
             if (totalValidContacts < 1)
             {
                 var alert = new AlertDialog.Builder(this);
                 alert.SetTitle("No valid Contacts Found");
                 alert.SetMessage("No valid Contacts Found");
             }
             var rnd = new Random();
             Contact contact = null;
             while (contact == null)
             {
                 contact = validContacts.Skip(rnd.Next(0, totalValidContacts)).FirstOrDefault();
             }
             var urlNumber = Android.Net.Uri.Parse("tel:" + contact.Phones.First().Number);
             var intent = new Intent(Intent.ActionCall);
             intent.SetData(urlNumber);
             this.StartActivity(intent);
         }, TaskScheduler.FromCurrentSynchronizationContext());
 }
Exemple #2
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			this.Title = "Contacts";
			
			list = new List<Contact>();
            
			//
			// get the address book, which gives us access to the
			// the contacts store
			//
			var book = new AddressBook ();
			
			//
			// important: PreferContactAggregation must be set to the 
			// the same value when looking up contacts by ID
			// since we look up contacts by ID on the subsequent 
			// ContactsActivity in this sample, we will set to false
			//
			book.PreferContactAggregation = true;
			
			//
			// loop through the contacts and put them into a List
			//
			// contacts can be selected and sorted using linq!
			//
			// In this sample, we'll just use LINQ to grab the first 10 users with mobile phone entries
			//
			foreach (Contact contact in book.Where(c => c.Phones.Any(p => p.Type == PhoneType.Mobile)).Take(10))
			{
				list.Add(contact);
			}
			
			//
			// create a tableview and use the list as the datasource
			//
			tableView = new UITableView()
            {
				Delegate = new TableViewDelegate(this),
                DataSource = new TableViewDataSource(list),
                AutoresizingMask =
                    UIViewAutoresizing.FlexibleHeight|
                    UIViewAutoresizing.FlexibleWidth,
            };
			
			//
			// size the tableview and add it to the parent view
			//
			tableView.SizeToFit();
			tableView.Frame = new RectangleF (
                0, 0, this.View.Frame.Width,
                this.View.Frame.Height);
            this.View.AddSubview(tableView);
		}
Exemple #3
0
		protected override void OnCreate(Bundle bundle)
		{
			base.OnCreate(bundle);
			
			//
			// get the address book, which gives us access to the
			// the contacts store
			//
			var book = new AddressBook (this);
			
			//
			// important: PreferContactAggregation must be set to the 
			// the same value when looking up contacts by ID
			// since we look up contacts by ID on the subsequent 
			// ContactsActivity in this sample, we will set both to true
			//
			book.PreferContactAggregation = true;
			
			//
			// loop through the contacts and put them into a List<String>
			//
			// Note that the contacts are ordered by last name - contacts can be selected and sorted using LINQ!
			// A more performant solution would create a custom adapter to lazily pull the contacts
			//
			// In this sample, we'll just use LINQ to grab the first 10 users with mobile phone entries
			//
			foreach (Contact contact in book.Where(c => c.Phones.Any(p => p.Type == PhoneType.Mobile)).Take(10))
			{
				contacts.Add(contact.DisplayName);
				contactIDs.Add(contact.Id); //save the ID in a parallel list
			}
			
			ListAdapter = new ArrayAdapter<string> (this, Resource.Layout.list_item, contacts.ToArray());
		    ListView.TextFilterEnabled = true;
			
			//
			// When clicked, start a new activity to display more contact details
			//	
			ListView.ItemClick += delegate (object sender, AdapterView.ItemClickEventArgs args) {
		        
				//
				// to show the contact on the details activity, we
				// need to send that activity the contacts ID
				//
				String contactID = contactIDs[args.Position];
				Intent showContactDetails = new Intent(this, typeof(ContactActivity));
				showContactDetails.PutExtra("contactID", contactID);
				StartActivity(showContactDetails);
				
				//
				// alternatively, show a toast with the name of the contact selected
				//
				//Toast.MakeText (Application, ((TextView)args.View).Text, ToastLength.Short).Show ();
		    };
		}
Exemple #4
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			Title = "Contacts";
			//
			// create a tableview and use the list as the datasource
			//
			tableView = new UITableView()
			{
				Delegate = new TableViewDelegate(this),
				AutoresizingMask =
				UIViewAutoresizing.FlexibleHeight|
				UIViewAutoresizing.FlexibleWidth,
			};
			
			//
			// size the tableview and add it to the parent view
			//
			tableView.SizeToFit();
			tableView.Frame = new RectangleF (
				0, 0, this.View.Frame.Width,
				this.View.Frame.Height);
			this.View.AddSubview(tableView);


			list = new List<Contact>();

			//
			// get the address book, which gives us access to the
			// the contacts store
			//
			var book = new AddressBook ();

			//
			// important: PreferContactAggregation must be set to the 
			// the same value when looking up contacts by ID
			// since we look up contacts by ID on the subsequent 
			// ContactsActivity in this sample, we will set to false
			//
			book.PreferContactAggregation = true;

			book.RequestPermission().ContinueWith (t =>
			{
				if (!t.Result)
				{
					alert = new UIAlertView ("Permission denied", "User has denied this app access to their contacts", null, "Close");
					alert.Show();
				}
				else
				{
					//
					// loop through the contacts and put them into a List
					//
					// contacts can be selected and sorted using linq!
					//
					// In this sample, we'll just use LINQ to grab the first 10 users with mobile phone entries
					//
					foreach (Contact contact in book.Where(c => c.Phones.Any(p => p.Type == PhoneType.Mobile)).Take(10))
					{
						list.Add(contact);
					}

					tableView.DataSource = new TableViewDataSource (list);
					tableView.ReloadData();
				}
			}, TaskScheduler.FromCurrentSynchronizationContext());
		}
Exemple #5
0
 public override bool FinishedLaunching (UIApplication app, NSDictionary options)
 {
     window = new UIWindow (UIScreen.MainScreen.Bounds);
     
     var book = new AddressBook ();
     
     _rootElement = new RootElement ("Json Example"){
         
         new Section ("Json Demo"){
             JsonElement.FromFile ("sample.json"),        
             new JsonElement ("Load from url", "http://localhost/sample.json")                    
         },
         new Section ("MT.D+Linq+Xamarin.Mobile"){
             new RootElement ("Contacts with Phones") {
                 from c in book.Where (c => c.Phones.Count () > 0)
                 select new Section (c.DisplayName){
                     from p in c.Phones
                     select (Element)new StringElement (p.Number)
                 }
             }
         },
         new Section ("Tasks Sample using Json")
     };
      
     _vc = new DialogViewController (_rootElement);
     _nav = new UINavigationController (_vc);
     
     window.RootViewController = _nav;
     window.MakeKeyAndVisible ();
     
     #region task demo
     
     int n = 0;
     
     _addButton = new UIBarButtonItem (UIBarButtonSystemItem.Add);
     _vc.NavigationItem.RightBarButtonItem = _addButton;
     
     _addButton.Clicked += (sender, e) => {
         
         ++n;
         
         var task = new Task{Name = "task " + n, DueDate = DateTime.Now};
         
         var taskElement = JsonElement.FromFile ("task.json");
         
         taskElement.Caption = task.Name;
         
         var description = taskElement ["task-description"] as EntryElement;
         
         if (description != null) {
             description.Caption = task.Name;
             description.Value = task.Description;       
         }
         
         var duedate = taskElement ["task-duedate"] as DateElement;
         
         if (duedate != null) {                
             duedate.DateValue = task.DueDate;
         }
  
         _rootElement [2].Add (taskElement);
     };
     
     #endregion
     
     return true;
 }