Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Mike Bluestein
Developer/Writer
Xamarin
mike.bluestein@xamarin.com
Xamarin.Mobile API
@mikebluestein
Xamarin.Mobile
• Cross Platform API
Xamarin.iOS
Xamarin.Android
Windows Store Applications
Windows Phone 8
Windows Phone 7...
Now Open Source!
Architecture
Contacts
Xamarin.Mobile
Geolocation Camera
Contacts
Contacts
• AddressBook
RequestPermission
• Contact
Phone
Email
Address
Website
Relationship
Contacts
• Maps to native implementation on each platform
• AddressBook implements IQueryable
• LINQ
ABAddressBookRef ab = ABAddressBookCreate();
CFStringRef name = CFSTR ("Smith");
CFArrayRef smiths = ABAddressBookCopyPeop...
Contacts - Android
ContentResolver content= getContentResolver();
Cursor ncursor = null;
try {
ncursor = content.query (Co...
Xamarin.Mobile Contacts
var book = new AddressBook ();
foreach (Contact c in book.Where (c => c.LastName == "Smith")) {
Co...
Geolocation
Geolocation
• Geolocator
• Position
Latitude
Longitude
Accuracy
Altitude
Altitude Accuracy
Heading
Geolocation
• Geolocator class
• Retrieve current location
• Listen for Location changes
• DesiredAccuracy influences the ...
MediaPicker
MediaPicker
• Take Photos and Videos
• Select Photos and Videos
• Programmatic feature detection
MediaPicker.PhotosSupport...
MediaPicker Camera
• Specify which camera to use
• Specify video quality
• Async and C# TPL Compatible
Task.ContinueWith, ...
MediaPicker iOS
var picker = new MediaPicker();
MediaPickerController controller = picker.GetTakePhotoUI (new
StoreCameraM...
MediaPicker Android
var picker = new MediaPicker (this);
if (!picker.IsCameraAvailable)
Console.WriteLine ("No camera!");
...
MediaPicker Android
protected override void OnActivityResult (int requestCode, Result resultCode,
Intent data)
{
// User c...
var mediaPickerController = mediaPicker.GetPickPhotoUI();
mediaPickerController.GetResultAsync()
.ContinueWith (t => {
med...
Demo
Resources
xamarin.com/mobileapi
Upcoming SlideShare
Loading in …5
×

Xamarin mobile

14,605 views

Published on

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

Xamarin mobile

  1. 1. Mike Bluestein Developer/Writer Xamarin mike.bluestein@xamarin.com Xamarin.Mobile API @mikebluestein
  2. 2. Xamarin.Mobile • Cross Platform API Xamarin.iOS Xamarin.Android Windows Store Applications Windows Phone 8 Windows Phone 7.1 • Abstracts common device features
  3. 3. Now Open Source!
  4. 4. Architecture Contacts Xamarin.Mobile Geolocation Camera
  5. 5. Contacts
  6. 6. Contacts • AddressBook RequestPermission • Contact Phone Email Address Website Relationship
  7. 7. Contacts • Maps to native implementation on each platform • AddressBook implements IQueryable • LINQ
  8. 8. ABAddressBookRef ab = ABAddressBookCreate(); CFStringRef name = CFSTR ("Smith"); CFArrayRef smiths = ABAddressBookCopyPeopleWithName(ab, name); CFRelease (name); int count = CFArrayGetCount(smiths); for (int i = 0; i < count; ++i) { ABRecordRef person = (ABRecordRef)CFArrayGetValueAtIndex(smiths, (CFIndex)i); if (ABRecordGetRecordType(person) != kABPersonType) continue; NSString *name = (NSString*)ABRecordCopyCompositeName(person); NSLog ("%@n", name); [name release]; ABMultiValueRef phoneNumberProp = ABRecordCopyValue(person, kABPersonPhoneProperty); NSArray* numbers = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProp); CFRelease(phoneNumberProp); for (NSString *pvalue in numbers) NSLog ("Phone: %@n", pvalue); [numbers release]; ABMultiValueRef emailProp = ABRecordCopyValue(person, kABPersonEmailProperty); NSArray* emails = (NSArray*)ABMultiValueCopyArrayOfAllValues(emailProp); CFRelease(emailProp); for (NSString *evalue in emails) NSLog ("Email: %@n"); [emails release]; } CFRelease (ab); CFRelease (smiths); Contacts - iOS
  9. 9. Contacts - Android ContentResolver content= getContentResolver(); Cursor ncursor = null; try { ncursor = content.query (ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data.MIMETYPE, ContactsContract.Contacts.LOOKUP_KEY, ContactsContract.Contacts.DISPLAY_NAME }, ContactsContract.Data.MIMETYPE + "=? AND " + ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME + "=?", new String[] { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, "Smith" }, null); while (ncursor.moveToNext()) { print (ncursor.getString(ncursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + lineSep); String lookupKey = ncursor.getString (ncursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); Cursor dcursor = null; try { dcursor = content.query (ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.Data.DATA1 }, ContactsContract.Contacts.LOOKUP_KEY + "=?", new String[] { lookupKey }, null); while (dcursor.moveToNext()) { String type = dcursor.getString (ncursor.getColumnIndex(ContactsContract.Data.MIMETYPE)); if (type.equals (ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) print ("Phone: " + dcursor.getString(dcursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) + lineSep); else if (type.equals (ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) print ("Email: " + dcursor.getString(dcursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA1)) + lineSep); } } finally { if (dcursor != null) dcursor.close(); } } } finally { if (ncursor != null) ncursor.close(); }
  10. 10. Xamarin.Mobile Contacts var book = new AddressBook (); foreach (Contact c in book.Where (c => c.LastName == "Smith")) { Console.WriteLine (c.DisplayName); foreach (Phone p in c.Phones) Console.WriteLine ("Phone: " + p.Number); foreach (Email e in c.Emails) Console.WriteLine ("Email: " + e.Address); }
  11. 11. Geolocation
  12. 12. Geolocation • Geolocator • Position Latitude Longitude Accuracy Altitude Altitude Accuracy Heading
  13. 13. Geolocation • Geolocator class • Retrieve current location • Listen for Location changes • DesiredAccuracy influences the location technology that is used
  14. 14. MediaPicker
  15. 15. MediaPicker • Take Photos and Videos • Select Photos and Videos • Programmatic feature detection MediaPicker.PhotosSupported MediaPicker.VideosSupported MediaPicker. IsCameraAvailable
  16. 16. MediaPicker Camera • Specify which camera to use • Specify video quality • Async and C# TPL Compatible Task.ContinueWith, IsCancelled, IsFaulted
  17. 17. MediaPicker iOS var picker = new MediaPicker(); MediaPickerController controller = picker.GetTakePhotoUI (new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MediaPickerSample" }); PresentViewController (controller, true, null); controller.GetResultAsync().ContinueWith (t => { // Dismiss the UI yourself controller.DismissViewController (true, () => { MediaFile file = t.Result; }); }, TaskScheduler.FromCurrentSynchronizationContext());
  18. 18. MediaPicker Android var picker = new MediaPicker (this); if (!picker.IsCameraAvailable) Console.WriteLine ("No camera!"); else { var intent = picker.GetTakePhotoUI (new StoreCameraMediaOptions { Name = "test.jpg", Directory = "MediaPickerSample" }); StartActivityForResult (intent, 1); }
  19. 19. MediaPicker Android protected override void OnActivityResult (int requestCode, Result resultCode, Intent data) { // User canceled if (resultCode == Result.Canceled) return; data.GetMediaFileExtraAsync (this).ContinueWith (t => { if (requestCode == 1) { // Video request ShowVideo (t.Result.Path); } else if (requestCode == 2) { // Image request ShowImage (t.Result.Path); } }, TaskScheduler.FromCurrentSynchronizationContext()); }
  20. 20. var mediaPickerController = mediaPicker.GetPickPhotoUI(); mediaPickerController.GetResultAsync() .ContinueWith (t => { mediaPickerController.DismissViewController ( true, () => { // User canceled or something went wrong if (t.IsCanceled || t.IsFaulted) return; // We get back a MediaFile MediaFile media = t.Result; }); }, TaskScheduler.FromCurrentSynchronizationContext()); MediaPicker Selecting Photos
  21. 21. Demo
  22. 22. Resources xamarin.com/mobileapi

×