protected override async void OnResume () { base.OnResume (); int itemId = Intent.GetIntExtra(ShareItemIdExtraName, 0); if(itemId > 0) { shareItem = App.Database.GetItem(itemId); fileName = shareItem.ImagePath; System.Console.WriteLine("Image path: " + fileName); Bitmap b = BitmapFactory.DecodeFile (fileName); // Display the bitmap photoImageView.SetImageBitmap (b); locationText.Text = shareItem.Location; return; } if (fileName == "") { fileName = "in-progress"; var picker = new MediaPicker (this); // new MediaPicker (); on iOS if (!picker.IsCameraAvailable) System.Console.WriteLine ("No camera!"); else { var options = new StoreCameraMediaOptions { Name = DateTime.Now.ToString("yyyyMMddHHmmss"), Directory = "MediaPickerSample" }; if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } Intent intent = picker.GetTakePhotoUI (options); StartActivityForResult (intent, 1); } } else { SetImage (); } try { var locator = new Geolocator (this) { DesiredAccuracy = 50 }; // new Geolocator () { ... }; on iOS var position = await locator.GetPositionAsync (timeout: 10000); System.Console.WriteLine ("Position Latitude: {0}", position.Latitude); System.Console.WriteLine ("Position Longitude: {0}", position.Longitude); location = string.Format("{0},{1}", position.Latitude, position.Longitude); locationText.Text = location; } catch (Exception e) { System.Console.WriteLine ("Position Exception: " + e.Message); } }
void Share(Xamarin.Social.Service service) { if (fileName == "" || fileName == "in-progress") { return; } // 2. Create an item to share var text = "Xamarin.SoMA ... Social Mobile & Auth! "; if (shareItem != null) // use the existing one passed to the activity { text = shareItem.Text; fileName = shareItem.ImagePath; location = shareItem.Location; } var item = new Item { Text = text }; item.Images.Add(new ImageData(fileName)); if (isLocationSet) { item.Links.Add(new Uri("https://maps.google.com/maps?q=" + location)); } // 3. Present the UI on Android var shareIntent = service.GetShareUI(this, item, result => { // result lets you know if the user shared the item or canceled if (result == ShareResult.Cancelled) { return; } System.Console.WriteLine(service.Title + " shared"); // 4. Now save to the database for the MainScreen list var si = new Core.ShareItem() { Text = item.Text, // get the edited text from the share UI ImagePath = fileName, Location = location }; if (item.Links.Count > 0) { si.Link = item.Links[0].AbsoluteUri; } si.SocialType = service.Title; App.Database.SaveItem(si); shareItem = si; // replace the one in the activity }); StartActivity(shareIntent); }
public int SaveItem (ShareItem item) { lock (locker) { if (item.Id != 0) { Update (item); return item.Id; } else { return Insert (item); } } }
void Share(Service service) { // 2. Create an item to share var item = new Item { Text = "Xamarin.SoMA ... Social Mobile & Auth! " }; if (fileName != "in-progress" && fileName != "cancelled") // was never set, no image { item.Images.Add(new ImageData(fileName)); } if (isLocationSet) { item.Links.Add(new Uri("https://maps.google.com/maps?q=" + location)); } // 3. Present the UI on iOS var shareController = service.GetShareUI(item, result => { DismissViewController(true, null); // result lets you know if the user shared the item or canceled if (result == ShareResult.Cancelled) { return; } Console.WriteLine(service.Title + " shared"); // 4. Now save to the database for the MainScreen list var si = new Core.ShareItem() { Text = item.Text, // get the edited text from the share UI ImagePath = fileName, ThumbImagePath = fileNameThumb, Location = location }; if (item.Links.Count > 0) { si.Link = item.Links[0].AbsoluteUri; } si.SocialType = service.Title; AppDelegate.Database.SaveItem(si); shareItem = si; // 5. Return to the MainScreen NavigationController.PopViewControllerAnimated(true); }); PresentViewController(shareController, true, null); }
public int SaveItem(ShareItem item) { lock (locker) { if (item.Id != 0) { Update(item); return(item.Id); } else { return(Insert(item)); } } }
void Share (Xamarin.Social.Service service) { if (fileName == string.Empty || fileName == "in-progress") return; // 2. Create an item to share var text = "Xamarin.SoMA ... Social Mobile & Auth! "; if (shareItem != null) { // use the existing one passed to the activity text = shareItem.Text; fileName = shareItem.ImagePath; location = shareItem.Location; } var item = new Item { Text = text }; item.Images.Add (new ImageData (fileName)); if (isLocationSet) item.Links.Add (new Uri ( "https://maps.google.com/maps?q=" + location)); // 3. Present the UI on Android var shareIntent = service.GetShareUI (this, item, result => { // result lets you know if the user shared the item or canceled if (result == ShareResult.Cancelled) return; Console.WriteLine ("{0} shared", service.Title); // 4. Now save to the database for the MainScreen list var si = new ShareItem { Text = item.Text, // get the edited text from the share UI ImagePath = fileName, Location = location }; if (item.Links.Count > 0) si.Link = item.Links[0].AbsoluteUri; si.SocialType = service.Title; App.Database.SaveItem(si); shareItem = si; // replace the one in the activity }); StartActivity (shareIntent); }
void Share (Service service) { // 2. Create an item to share var item = new Item { Text = "Xamarin.SoMA ... Social Mobile & Auth! " }; item.Images.Add(new ImageData(fileName)); if (isLocationSet) item.Links.Add(new Uri( "https://maps.google.com/maps?q=" + location)); // 3. Present the UI on iOS var shareController = service.GetShareUI (item, result => { DismissViewController (true, null); // result lets you know if the user shared the item or canceled if (result == ShareResult.Cancelled) return; Console.WriteLine(service.Title + " shared"); // 4. Now save to the database for the MainScreen list var si = new Core.ShareItem() { Text = item.Text, // get the edited text from the share UI ImagePath = fileName, ThumbImagePath = fileNameThumb, Location = location }; if (item.Links.Count > 0) si.Link = item.Links[0].AbsoluteUri; si.SocialType = service.Title; AppDelegate.Database.SaveItem(si); shareItem = si; // 5. Return to the MainScreen NavigationController.PopViewControllerAnimated(true); }); PresentViewController (shareController, true, null); }
protected override async void OnResume() { base.OnResume(); int itemId = Intent.GetIntExtra(ShareItemIdExtraName, 0); if (itemId > 0) { shareItem = App.Database.GetItem(itemId); fileName = shareItem.ImagePath; System.Console.WriteLine("Image path: " + fileName); Bitmap b = BitmapFactory.DecodeFile(fileName); // Display the bitmap photoImageView.SetImageBitmap(b); locationText.Text = shareItem.Location; return; } if (fileName == "") { fileName = "in-progress"; var picker = new MediaPicker(this); // new MediaPicker (); on iOS if (!picker.IsCameraAvailable) { System.Console.WriteLine("No camera!"); } else { var options = new StoreCameraMediaOptions { Name = DateTime.Now.ToString("yyyyMMddHHmmss"), Directory = "MediaPickerSample" }; #if !VISUALSTUDIO #region new style if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } Intent intent = picker.GetTakePhotoUI(options); StartActivityForResult(intent, 1); #endregion #else #region old style (deprecated) var t = picker.TakePhotoAsync(options); await t; if (t.IsCanceled) { System.Console.WriteLine("User canceled"); fileName = "cancelled"; // TODO: return to main screen StartActivity(typeof(MainScreen)); return; } System.Console.WriteLine(t.Result.Path); fileName = t.Result.Path; fileNameThumb = fileName.Replace(".jpg", "_thumb.jpg"); Bitmap b = BitmapFactory.DecodeFile(fileName); RunOnUiThread(() => { // Display the bitmap photoImageView.SetImageBitmap(b); // Cleanup any resources held by the MediaFile instance t.Result.Dispose(); }); var boptions = new BitmapFactory.Options { OutHeight = 128, OutWidth = 128 }; var newBitmap = await BitmapFactory.DecodeFileAsync(fileName, boptions); var @out = new System.IO.FileStream(fileNameThumb, System.IO.FileMode.Create); newBitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 90, @out); //}); #endregion #endif } } try { var locator = new Geolocator(this) { DesiredAccuracy = 50 }; // new Geolocator () { ... }; on iOS var position = await locator.GetPositionAsync(timeout : 10000); System.Console.WriteLine("Position Latitude: {0}", position.Latitude); System.Console.WriteLine("Position Longitude: {0}", position.Longitude); location = string.Format("{0},{1}", position.Latitude, position.Longitude); locationText.Text = location; } catch (Exception e) { System.Console.WriteLine("Position Exception: " + e.Message); } }
protected override async void OnResume () { base.OnResume (); int itemId = Intent.GetIntExtra(ShareItemIdExtraName, 0); if(itemId > 0) { shareItem = App.Database.GetItem(itemId); fileName = shareItem.ImagePath; System.Console.WriteLine("Image path: " + fileName); Bitmap b = BitmapFactory.DecodeFile (fileName); // Display the bitmap photoImageView.SetImageBitmap (b); locationText.Text = shareItem.Location; return; } if (fileName == "") { fileName = "in-progress"; var picker = new MediaPicker (this); // new MediaPicker (); on iOS if (!picker.IsCameraAvailable) System.Console.WriteLine ("No camera!"); else { var options = new StoreCameraMediaOptions { Name = DateTime.Now.ToString("yyyyMMddHHmmss"), Directory = "MediaPickerSample" }; #if !VISUALSTUDIO #region new style if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } Intent intent = picker.GetTakePhotoUI (options); StartActivityForResult (intent, 1); #endregion #else #region old style (deprecated) var t = picker.TakePhotoAsync (options); await t; if (t.IsCanceled) { System.Console.WriteLine ("User canceled"); fileName = "cancelled"; // TODO: return to main screen StartActivity(typeof(MainScreen)); return; } System.Console.WriteLine (t.Result.Path); fileName = t.Result.Path; fileNameThumb = fileName.Replace(".jpg", "_thumb.jpg"); Bitmap b = BitmapFactory.DecodeFile (fileName); RunOnUiThread (() => { // Display the bitmap photoImageView.SetImageBitmap (b); // Cleanup any resources held by the MediaFile instance t.Result.Dispose(); }); var boptions = new BitmapFactory.Options {OutHeight = 128, OutWidth = 128}; var newBitmap = await BitmapFactory.DecodeFileAsync (fileName, boptions); var @out = new System.IO.FileStream(fileNameThumb, System.IO.FileMode.Create); newBitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 90, @out); //}); #endregion #endif } } try { var locator = new Geolocator (this) { DesiredAccuracy = 50 }; // new Geolocator () { ... }; on iOS var position = await locator.GetPositionAsync (timeout: 10000); System.Console.WriteLine ("Position Latitude: {0}", position.Latitude); System.Console.WriteLine ("Position Longitude: {0}", position.Longitude); location = string.Format("{0},{1}", position.Latitude, position.Longitude); locationText.Text = location; } catch (Exception e) { System.Console.WriteLine ("Position Exception: " + e.Message); } }
public void SetItem(Core.ShareItem item) { fileName = item.ImagePath; location = item.Location; }
public void SetItem (ShareItem item) { fileName = item.ImagePath; location = item.Location; }
protected override async void OnResume() { base.OnResume(); int itemId = Intent.GetIntExtra(ShareItemIdExtraName, 0); if (itemId > 0) { shareItem = App.Database.GetItem(itemId); fileName = shareItem.ImagePath; System.Console.WriteLine("Image path: " + fileName); Bitmap b = BitmapFactory.DecodeFile(fileName); // Display the bitmap photoImageView.SetImageBitmap(b); locationText.Text = shareItem.Location; return; } if (fileName == "") { fileName = "in-progress"; var picker = new MediaPicker(this); // new MediaPicker (); on iOS if (!picker.IsCameraAvailable) { System.Console.WriteLine("No camera!"); } else { var options = new StoreCameraMediaOptions { Name = DateTime.Now.ToString("yyyyMMddHHmmss"), Directory = "MediaPickerSample" }; if (!picker.IsCameraAvailable || !picker.PhotosSupported) { ShowUnsupported(); return; } Intent intent = picker.GetTakePhotoUI(options); StartActivityForResult(intent, 1); } } else { SetImage(); } try { var locator = new Geolocator(this) { DesiredAccuracy = 50 }; // new Geolocator () { ... }; on iOS var position = await locator.GetPositionAsync(timeout : 10000); System.Console.WriteLine("Position Latitude: {0}", position.Latitude); System.Console.WriteLine("Position Longitude: {0}", position.Longitude); location = string.Format("{0},{1}", position.Latitude, position.Longitude); locationText.Text = location; } catch (Exception e) { System.Console.WriteLine("Position Exception: " + e.Message); } }