// Result of an activity, back to work! protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode == Result.Ok) { if (requestCode == 10) // Map { IList <String> p = null; if (data != null) { p = data.Extras.GetStringArrayList("coordinates") ?? new string[0]; } // Check validity of parameter if ((p != null) && (p.Count == 2)) { // List is valid, populate login & password String sLat2 = GCStuffs.ConvertDegreesToDDMM(GCStuffs.ConvertToDouble(p[0]), true); String sLon2 = GCStuffs.ConvertDegreesToDDMM(GCStuffs.ConvertToDouble(p[1]), false); txtCoord.Text = /*"DD° MM.MMM: " + */ sLat2 + " " + sLon2; Toast.MakeText(this, this.Resources.GetString(Resource.String.PickDone), ToastLength.Short).Show(); } } } }
public void OnMapReady(GoogleMap googleMap) { if (googleMap != null) { //Map is ready for use _map = googleMap; if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) == Permission.Granted) { _map.MyLocationEnabled = true; _map.UiSettings.CompassEnabled = true; _map.UiSettings.ZoomControlsEnabled = true; _map.MarkerDragEnd += myMarkerDragEnd; CameraPosition.Builder builder = CameraPosition.InvokeBuilder(); LatLng location = null; if ((lat != "") && (lon != "")) { location = new LatLng(GCStuffs.ConvertToDouble(lat), GCStuffs.ConvertToDouble(lon)); } else { // Don't forget to assign a value to lat and lon // If omeone click on save coord without moving the marker, these values will be used lat = "43.3"; lon = "5.4"; location = new LatLng(43.3, 5.4); } builder.Target(location); builder.Zoom(10);// 13); CameraPosition cameraPosition = builder.Build(); CameraUpdate cameraUpdate = CameraUpdateFactory.NewCameraPosition(cameraPosition); _map.MoveCamera(cameraUpdate); // Create marker _marker = new MarkerOptions(); _marker.SetPosition(location); TextView lblCoord = FindViewById <TextView>(Resource.Id.lblCoord); lblCoord.Text = /*"DD° MM.MMM: " + */ NiceCoordToString(location); _marker.Draggable(true); _marker.SetTitle(NiceCoordToString(location)); //_marker.SetIcon(BitmapDescriptorFactory.FromResource(geo.GetIconResourceId())); _map.AddMarker(_marker); // Create circle if possible CreateCircle(location); } else { // Show rationale and request permission. Toast.MakeText(this, this.Resources.GetString(Resource.String.ErrorLocation), ToastLength.Short).Show(); } } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "MapLayout" layout resource SetContentView(Resource.Layout.MapLayout); // Get params IList <String> p = null; if (Intent.Extras != null) { p = Intent.Extras.GetStringArrayList("coordinates") ?? new string[0]; } // Check validity of parameter if (p != null) { if (p.Count >= 2) { // List is valid, populate login & password lat = p[0]; lon = p[1]; } if (p.Count >= 3) { if (!Int32.TryParse(p[2], out radius)) { radius = 0; } } } if ((lat != "") && (lon != "")) { // Textview to diplay coordinates TextView lblCoord = FindViewById <TextView>(Resource.Id.lblCoord); String sLat2 = GCStuffs.ConvertDegreesToDDMM(GCStuffs.ConvertToDouble(lat), true); String sLon2 = GCStuffs.ConvertDegreesToDDMM(GCStuffs.ConvertToDouble(lon), false); lblCoord.Text = /*"DD° MM.MMM: " + */ sLat2 + " " + sLon2; } // Create your application here var frag = FragmentManager.FindFragmentById <MapFragment>(Resource.Id.map); frag.GetMapAsync(this); Button button = FindViewById <Button>(Resource.Id.Save); button.Click += Save_Click; button = FindViewById <Button>(Resource.Id.BtnQuit); button.Click += Cancel_Click; }
private void CreateNotifications() { // Check if internet access is available if (!GCStuffs.CheckNetworkAccess(this)) { Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Short).Show(); return; } try { // Get all the nested values // Get coordinates String coord = txtCoord.Text; String sLat = ""; String sLon = ""; if (!GCStuffs.TryToConvertCoordinates(coord, ref sLat, ref sLon)) { // Cancel creation wrong coordinates Toast.MakeText(this, this.Resources.GetString(Resource.String.BadCoordinates), ToastLength.Short).Show(); return; } // convert to double double dlat = GCStuffs.ConvertToDouble(sLat); double dlon = GCStuffs.ConvertToDouble(sLon); // Get radius String radius = FindViewById <EditText>(Resource.Id.editRadius).Text; int distance = 0; if (!Int32.TryParse(radius, out distance) || (distance == 0)) { // Cancel creation wrong radius Toast.MakeText(this, this.Resources.GetString(Resource.String.BadDistance), ToastLength.Short).Show(); return; } // Get Name String name = FindViewById <EditText>(Resource.Id.editName).Text; if (name == "") { // Cancel creation since empty name Toast.MakeText(this, this.Resources.GetString(Resource.String.BadName), ToastLength.Short).Show(); return; } // Email Spinner mySpinner = FindViewById <Spinner>(Resource.Id.spinnerEmail); String email = ""; if (mySpinner.Visibility != ViewStates.Invisible) { if (mySpinner.SelectedItem != null) { email = mySpinner.SelectedItem.ToString(); } /* * if (email == "") * { * // Cancel creation since empty name * Toast.MakeText(this, this.Resources.GetString(Resource.String.BadEmail), ToastLength.Short).Show(); * return; * }*/ } // Types : check that at least one type is checked List <Tuple <int, string, List <string>, int> > selectedTypes = new List <Tuple <int, string, List <string>, int> >(); foreach (var tc in _typecaches) { // Is it checked ? if (tc.Checked) { // Yes, so we find the correspoding tuple foreach (var tpl in _allowedtypes) { if (tpl.Item2 == tc.Type) { // Found it ! selectedTypes.Add(tpl); } } } } // At least one type selected ? int nbsel = selectedTypes.Count; if (nbsel == 0) { // Cancel creation since no type Toast.MakeText(this, this.Resources.GetString(Resource.String.NoType), ToastLength.Short).Show(); return; } else { // Check if we go higher that 40 notifications if ((nbNotifs + nbsel) > 40) { int maxnb = 40 - nbNotifs; String msg = String.Format(this.Resources.GetString(Resource.String.MaxNotifWillReached), nbNotifs, maxnb); Toast.MakeText(this, msg, ToastLength.Long).Show(); return; } } // Ask if we are ready var builder = new AlertDialog.Builder(this); builder.SetMessage(this.Resources.GetString(Resource.String.ConfirmCreate)); builder.SetPositiveButton(this.Resources.GetString(Resource.String.BtnYes), (s, ev) => { // Launch application inside a progress bar ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.SetProgressStyle(ProgressDialogStyle.Horizontal); progressDialog.SetMessage(this.Resources.GetString(Resource.String.LblCreateInProgress)); progressDialog.SetTitle(this.Resources.GetString(Resource.String.OperationInProgress)); progressDialog.Progress = 0; progressDialog.Max = selectedTypes.Count; progressDialog.SetCancelable(false); _Canceled = false; progressDialog.SetButton((int)(DialogButtonType.Negative), this.Resources.GetString(Resource.String.Cancel), (st, evt) => { // Tell the system about cancellation _Canceled = true; }); progressDialog.Show(); ThreadPool.QueueUserWorkItem(o => CreateNotificationsImpl(progressDialog, dlat, dlon, distance, name, selectedTypes, email)); }); builder.SetNegativeButton(this.Resources.GetString(Resource.String.BtnNo), (s, ev) => { // do something on Cancel click }); builder.Create().Show(); } catch (Exception) { Toast.MakeText(this, this.Resources.GetString(Resource.String.Error), ToastLength.Short).Show(); } }
// Save button clicked private void Save_Click(object sender, EventArgs e) { // Check if internet access is available if (!GCStuffs.CheckNetworkAccess(this)) { Toast.MakeText(this, this.Resources.GetString(Resource.String.NoInternet), ToastLength.Short).Show(); return; } try { // Get all the nested values // Get coordinates String coord = txtCoord.Text; String sLat = ""; String sLon = ""; if (!GCStuffs.TryToConvertCoordinates(coord, ref sLat, ref sLon)) { // Cancel creation wrong coordinates Toast.MakeText(this, this.Resources.GetString(Resource.String.BadCoordinates), ToastLength.Short).Show(); return; } // convert to double double dlat = GCStuffs.ConvertToDouble(sLat); double dlon = GCStuffs.ConvertToDouble(sLon); // Ask if we are ready var builder = new AlertDialog.Builder(this); builder.SetMessage(this.Resources.GetString(Resource.String.ConfirmUpdateCoord)); builder.SetPositiveButton(this.Resources.GetString(Resource.String.BtnYes), (s, ev) => { // Launch application inside a progress bar ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.SetProgressStyle(ProgressDialogStyle.Horizontal); progressDialog.SetMessage(this.Resources.GetString(Resource.String.LblUpdateInProgress)); progressDialog.SetTitle(this.Resources.GetString(Resource.String.OperationInProgress)); progressDialog.Progress = 0; progressDialog.Max = _ids.Count; progressDialog.SetCancelable(false); _Canceled = false; progressDialog.SetButton((int)(DialogButtonType.Negative), this.Resources.GetString(Resource.String.Cancel), (st, evt) => { // Tell the system about cancellation _Canceled = true; }); progressDialog.Show(); ThreadPool.QueueUserWorkItem(o => UpdateCoord(progressDialog, dlat, dlon)); }); builder.SetNegativeButton(this.Resources.GetString(Resource.String.BtnNo), (s, ev) => { // do something on Cancel click }); builder.Create().Show(); } catch (Exception) { Toast.MakeText(this, this.Resources.GetString(Resource.String.Error), ToastLength.Short).Show(); } }