protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { if (requestCode != CAPTURE_PHOTO) { base.OnActivityResult(requestCode, resultCode, data); } else { if (resultCode == Result.Ok) { using (var poiImage = POIData.GetImageFile(_poi.Id.Value)) { if (poiImage != null) { _poiImageView.SetImageBitmap(poiImage); } else { var toast = Toast.MakeText(this, "No picture captured.", ToastLength.Short); toast.Show(); } } } else { var toast = Toast.MakeText(this, "Failed to capture picture.", ToastLength.Short); toast.Show(); } } }
public override View GetView(int position, View convertView, ViewGroup parent) { // when a view is available for reuse, convertView will contain a reference to the view; otherwise, it will be null and a new view should be created. // otherwise we'd need to create a new view for every single row, which would be expensive. better to reuse the rows as old ones scroll out of view. var view = convertView ?? _context.LayoutInflater.Inflate(Resource.Layout.POIListItem, null); var poi = this [position]; view.FindViewById <TextView> (Resource.Id.nameTextView).Text = poi.Name; var addressView = view.FindViewById <TextView> (Resource.Id.addrTextView); if (string.IsNullOrEmpty(poi.Address)) { addressView.Visibility = ViewStates.Gone; } else { addressView.Text = poi.Address; } if ((CurrentLocation != null) && (poi.Latitude.HasValue) && (poi.Longitude.HasValue)) { var poiLocation = new Location("") { Latitude = poi.Latitude.Value, Longitude = poi.Longitude.Value }; var distance = CurrentLocation.DistanceTo(poiLocation) * 0.000621371F; // Meters -> Miles view.FindViewById <TextView>(Resource.Id.distanceTextView).Text = String.Format("{0:0,0.00} miles", distance); } else { view.FindViewById <TextView>(Resource.Id.distanceTextView).Text = "??"; } using (var poiImage = POIData.GetImageFile(poi.Id.Value)) view.FindViewById <ImageView>(Resource.Id.poiImageView).SetImageBitmap(poiImage); return(view); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Create your application here SetContentView(Resource.Layout.POIDetail); _locationManager = GetSystemService(Context.LocationService) as LocationManager; _nameEditText = FindViewById <EditText> (Resource.Id.nameEditText); _descrEditText = FindViewById <EditText> (Resource.Id.descrEditText); _addrEditText = FindViewById <EditText> (Resource.Id.addrEditText); _latEditText = FindViewById <EditText> (Resource.Id.latEditText); _longEditText = FindViewById <EditText> (Resource.Id.longEditText); _poiImageView = FindViewById <ImageView> (Resource.Id.poiImageView); _locationImageButton = FindViewById <ImageButton>(Resource.Id.locationImageButton); _mapImageButton = FindViewById <ImageButton>(Resource.Id.mapImageButton); _photoImageButton = FindViewById <ImageButton>(Resource.Id.photoImageButton); if (Intent.HasExtra("poiId")) { int poiId = Intent.GetIntExtra("poiId", -1); _poi = POIData.Service.GetPOI(poiId); using (var poiImage = POIData.GetImageFile(_poi.Id.Value)) { if (poiImage != null) { _poiImageView.SetImageBitmap(poiImage); } } } else { _poi = new PointOfInterest(); } _locationImageButton.Click += (s, e) => { _progressDialog = ProgressDialog.Show(this, "", "Obtaining location..."); _locationManager.RequestSingleUpdate(new Criteria { Accuracy = Accuracy.NoRequirement, PowerRequirement = Power.NoRequirement }, this, null); }; _mapImageButton.Click += (s, e) => { // uri options: // geo:latitude,longitude // geo:latitude,longitude?z={zoom} where {zoom} is the zoom level // geo:0,0?q=my+street+address // geo:0,0?q=business+near+city var geocodeUri = Uri.Parse(String.IsNullOrEmpty(_addrEditText.Text) ? String.Format("geo:{0},{1}", _poi.Latitude, _poi.Longitude) : String.Format("geo:0,0?q={0}", _addrEditText.Text)); var mapIntent = new Intent(Intent.ActionView, geocodeUri); var activities = PackageManager.QueryIntentActivities(mapIntent, 0); if (activities.Any()) { StartActivity(mapIntent); } else { var alertConfirm = new AlertDialog.Builder(this); alertConfirm.SetCancelable(false); alertConfirm.SetPositiveButton("OK", delegate { }); alertConfirm.SetMessage("No map app available."); alertConfirm.Show(); } }; _photoImageButton.Click += (s, e) => { if (!_poi.Id.HasValue) { var alertConfirm = new AlertDialog.Builder(this); alertConfirm.SetCancelable(false); alertConfirm.SetPositiveButton("OK", delegate { }); alertConfirm.SetMessage("You must save the POI prior to attaching a photo"); alertConfirm.Show(); return; } // MediaStore.ActionImageCapture -> Use any existing photo app var cameraIntent = new Intent(MediaStore.ActionImageCapture); PackageManager packageManager = PackageManager; var activities = packageManager.QueryIntentActivities(cameraIntent, 0); if (activities.Any()) { // tell the external app where to store the image // we need to map our physical path to a java URI path, so... var imageFile = new Java.IO.File(POIData.Service.GetImageFilename(_poi.Id.Value)); var imageUri = Uri.FromFile(imageFile); cameraIntent.PutExtra(MediaStore.ExtraOutput, imageUri); // limit the image size cameraIntent.PutExtra(MediaStore.ExtraSizeLimit, 1.5 * 1024); // the second parameter identifies the reason for calling the intent StartActivityForResult(cameraIntent, CAPTURE_PHOTO); } else { var alertConfirm = new AlertDialog.Builder(this); alertConfirm.SetCancelable(false); alertConfirm.SetPositiveButton("OK", delegate { }); alertConfirm.SetMessage("No photo capture app is installed."); alertConfirm.Show(); } }; UpdateUI(); }