private void BPLocationButton_Click(object sender, EventArgs eventArgs) { GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (!GPSTracker.isLocationGPSEnabled) { ShowSettingsAlert(); } if (location == null) { MessageDialog messageDialog = new MessageDialog(); messageDialog.SendToast("Unable to get location"); } else { BoundryPolygon BoundryPolygon = new BoundryPolygon() { Latitude = location.Latitude.ToString(), Longitude = location.Longitude.ToString() }; _BoundryPolygons.Add(BoundryPolygon); itemList.Add("Lat: " + location.Latitude.ToString() + " Long: " + location.Longitude.ToString()); boundaryPolygonsText.Text = String.Format("Boundary Polygons {0}", itemList.Count); arrayAdapter = new ArrayAdapter <string>(Activity, Resource.Layout.list_item, itemList); bpListView.Adapter = arrayAdapter; bpListView.ItemLongClick += Adapter_ItemSwipe; int listViewMinimumHeight = 25 * _BoundryPolygons.Count(); bpListView.SetMinimumHeight(listViewMinimumHeight); } }
void AddLocation_Click(object sender, EventArgs e) { GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (!GPSTracker.isLocationGPSEnabled) { ShowSettingsAlert(); } if (location == null) { MessageDialog messageDialog = new MessageDialog(); messageDialog.SendToast("Unable to get location"); } else { locationLinearlayout.Visibility = ViewStates.Visible; tvbLatitude.Text = "Lat: " + location.Latitude.ToString(); tvbLongitude.Text = "Long: " + location.Longitude.ToString(); accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); _GPSCoordinates = new GPSCoordinate() { Latitude = location.Latitude.ToString(), Longitude = location.Longitude.ToString() }; building.GPSCoordinates = _GPSCoordinates; } }
private void GPSLocationButton_Click(object sender, EventArgs eventArgs) { GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (!GPSTracker.isLocationGPSEnabled) { ShowSettingsAlert(); } if (location == null) { MessageDialog messageDialog = new MessageDialog(); messageDialog.SendToast("Unable to get location"); } else { tvfLatLong.Text = "Lat: " + location.Latitude.ToString() + " Long: " + location.Longitude.ToString(); accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); Location.GPSCoordinates = new GPSCoordinate() { Longitude = location.Longitude.ToString(), Latitude = location.Latitude.ToString() }; } }
private void RefashAccuracy_Click(object sender, EventArgs e) { GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (location != null) { accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); } }
private void InitializeLocation(AlertDialog dialog) { int listViewMinimumHeight = 25; streetAddress = dialog.FindViewById <EditText>(Resource.Id.etf_streetAddress); suburb = dialog.FindViewById <EditText>(Resource.Id.etf_suburb); region = dialog.FindViewById <EditText>(Resource.Id.etf_region); province = dialog.FindViewById <Spinner>(Resource.Id.sf_province); localmunicipality = dialog.FindViewById <Spinner>(Resource.Id.sf_localmunicipality); locationCancelButton = dialog.FindViewById <Button>(Resource.Id.dfil_cancelbutton); locationDoneButton = dialog.FindViewById <Button>(Resource.Id.dfil_donebutton); gpsLocationButton = dialog.FindViewById <FloatingActionButton>(Resource.Id.gpscaddlocation_button); bpLocationButton = dialog.FindViewById <FloatingActionButton>(Resource.Id.bpaddlocation_button); refashAccuracy = dialog.FindViewById <FloatingActionButton>(Resource.Id.refreshaccuracy_button); tvfLatitude = dialog.FindViewById <TextView>(Resource.Id.tvf_latitude); tvfLongitude = dialog.FindViewById <TextView>(Resource.Id.tvf_longitude); boundaryPolygonsText = dialog.FindViewById <TextView>(Resource.Id.boundaryPolygonsText); accuracyMessage = dialog.FindViewById <TextView>(Resource.Id.accuracy_message); bpListView = dialog.FindViewById <ListView>(Resource.Id.bplistView1); itemList = new List <string>(); bpListView.SetMinimumHeight(listViewMinimumHeight); refashAccuracy.Click += RefashAccuracy_Click; if (facility.Location != null) { streetAddress.Text = facility.Location.StreetAddress; suburb.Text = facility.Location.Suburb; region.Text = facility.Location.Region; province.SetSelection(GetIndex(province, facility.Location.Province)); localmunicipality.SetSelection(GetIndex(localmunicipality, facility.Location.LocalMunicipality)); listViewMinimumHeight = listViewMinimumHeight * facility.Location.BoundryPolygon.Count(); if (facility.Location.GPSCoordinates != null) { tvfLatitude.Text = "Lat: " + facility.Location.GPSCoordinates.Latitude; tvfLongitude.Text = " Long: " + facility.Location.GPSCoordinates.Longitude; } if (facility.Location.BoundryPolygon != null) { bpListView.SetMinimumHeight(listViewMinimumHeight); _BoundryPolygons = new List <BoundryPolygon>(); foreach (var BoundaryPolygon in facility.Location.BoundryPolygon) { _BoundryPolygons.Add(BoundaryPolygon); itemList.Add("Lat: " + BoundaryPolygon.Latitude.ToString() + " Long: " + BoundaryPolygon.Longitude.ToString()); } arrayAdapter = new ArrayAdapter <string>(Activity, Resource.Layout.list_item, itemList); bpListView.Adapter = arrayAdapter; bpListView.ItemLongClick += Adapter_ItemSwipe; } boundaryPolygonsText.Text = String.Format("Boundary Polygons {0}", itemList.Count); } locationCancelButton.Click += LocationCancelButton_Click; locationDoneButton.Click += LocationDoneButton_Click; bpLocationButton.Click += BPLocationButton_Click; gpsLocationButton.Click += GPSLocationButton_Click; Android.Content.Res.ColorStateList csl = new Android.Content.Res.ColorStateList(new int[][] { new int[0] }, new int[] { Android.Graphics.Color.ParseColor("#008000") }); bpLocationButton.BackgroundTintList = csl; Android.Content.Res.ColorStateList cslf = new Android.Content.Res.ColorStateList(new int[][] { new int[0] }, new int[] { Android.Graphics.Color.ParseColor("#008000") }); gpsLocationButton.BackgroundTintList = cslf; if (isEdit) { streetAddress.Enabled = true; suburb.Enabled = true; region.Enabled = true; province.Enabled = true; localmunicipality.Enabled = true; locationDoneButton.Enabled = true; gpsLocationButton.Enabled = true; bpLocationButton.Enabled = true; } else { streetAddress.Enabled = false; suburb.Enabled = false; region.Enabled = false; province.Enabled = false; localmunicipality.Enabled = false; locationDoneButton.Enabled = false; gpsLocationButton.Enabled = false; bpLocationButton.Enabled = false; } GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (location != null) { accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); } }
protected async override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); building = new Building(); ViewModel = new BuildingsViewModel(); AppPreferences ap = new AppPreferences(Android.App.Application.Context); facilityId = Convert.ToInt32(ap.GetFacilityId()); userId = Convert.ToInt32(ap.GetUserId()); var data = Intent.GetStringExtra("data"); // Create your application here saveButton = FindViewById <FloatingActionButton>(Resource.Id.save_button); occupationYear = FindViewById <EditText>(Resource.Id.etb_occupationyear); occupationyearLayout = FindViewById <TextInputLayout>(Resource.Id.occupationyear_layout); gpscAddLocationButton = FindViewById <FloatingActionButton>(Resource.Id.gpscaddlocation_button); locationLinearlayout = FindViewById <LinearLayout>(Resource.Id.blocation_linearlayout); tvbLatitude = FindViewById <TextView>(Resource.Id.tvb_latitude); tvbLongitude = FindViewById <TextView>(Resource.Id.tvb_longitude); buildingPhoto = FindViewById <ImageView>(Resource.Id.imgb_buildingphoto); _GPSCoordinates = new GPSCoordinate(); buildingName = FindViewById <EditText>(Resource.Id.etb_name); buildingType = FindViewById <Spinner>(Resource.Id.sf_buildingtype); buildingstandard = FindViewById <Spinner>(Resource.Id.sf_buildingstandard); utilisationStatus = FindViewById <EditText>(Resource.Id.etb_utilisationstatus); nooOfFoors = FindViewById <EditText>(Resource.Id.etb_nooffloors); totalFootprintAream2 = FindViewById <EditText>(Resource.Id.etb_totalfootprintaream2); totalImprovedaAeam2 = FindViewById <EditText>(Resource.Id.etb_totalimprovedaream2); heritage = FindViewById <Switch>(Resource.Id.sf_heritage); disabledAccesss = FindViewById <Spinner>(Resource.Id.sf_disabledaccesss); disabledComment = FindViewById <EditText>(Resource.Id.etb_disabledcomment); constructionDescription = FindViewById <EditText>(Resource.Id.etb_constructiondescription); accuracyMessage = FindViewById <TextView>(Resource.Id.accuracy_message); refashAccuracy = FindViewById <FloatingActionButton>(Resource.Id.refreshaccuracy_button); refashAccuracy.Click += RefashAccuracy_Click; _dir = ap.CreateDirectoryForPictures(); Android.Content.Res.ColorStateList csl = new Android.Content.Res.ColorStateList(new int[][] { new int[0] }, new int[] { Android.Graphics.Color.ParseColor("#008000") }); gpscAddLocationButton.BackgroundTintList = csl; locationLinearlayout.Visibility = ViewStates.Gone; if (data != null) { building = Newtonsoft.Json.JsonConvert.DeserializeObject <Building>(data); isEdit = true; SupportActionBar.Title = "Edit Building"; occupationYear.Text = building.OccupationYear; if (building.GPSCoordinates != null) { tvbLatitude.Text = "Lat: " + building.GPSCoordinates.Latitude; tvbLongitude.Text = "Long: " + building.GPSCoordinates.Longitude; _GPSCoordinates = building.GPSCoordinates; locationLinearlayout.Visibility = ViewStates.Visible; } buildingName.Text = building.BuildingName; buildingType.SetSelection(GetIndex(buildingType, building.BuildingType)); buildingstandard.SetSelection(GetIndex(buildingstandard, building.BuildingStandard)); disabledAccesss.SetSelection(GetIndex(disabledAccesss, building.DisabledAccess)); utilisationStatus.Text = building.Status; nooOfFoors.Text = Convert.ToString(building.NumberOfFloors); totalFootprintAream2.Text = Convert.ToString(building.FootPrintArea); totalImprovedaAeam2.Text = Convert.ToString(building.ImprovedArea); heritage.Checked = building.Heritage; disabledComment.Text = building.DisabledComment; constructionDescription.Text = building.ConstructionDescription; Bitmap bit = SetImageBitmap(_dir + "/" + building.Photo); if (bit != null) { buildingPhoto.SetImageBitmap(bit); } else if (bit == null && !String.IsNullOrEmpty(building.Photo)) { PictureViewModel pictureViewModel = new PictureViewModel(); Models.Picture picture = await pictureViewModel.ExecuteGetPictureCommand(building.Photo); if (picture != null) { var _bit = ap.StringToBitMap(picture.File); if (_bit != null) { SaveImage(_bit, building.Photo); } buildingPhoto.SetImageBitmap(_bit); } } } else { SupportActionBar.Title = "Add New Building"; } saveButton.Click += SaveButton_Click; SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); gpscAddLocationButton.Click += AddLocation_Click; buildingPhoto.Click += (sender, e) => { ShowImage_Click(); }; GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (location != null) { accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); } }
protected async override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); building = new Building(); ViewModel = new BuildingsViewModel(); appPreferences = new AppPreferences(Application.Context); facilityId = Convert.ToInt32(appPreferences.GetFacilityId()); userId = Convert.ToInt32(appPreferences.GetUserId()); helpers = new UIHelpers(); var data = Intent.GetStringExtra("data"); occupationYear = FindViewById <EditText>(Resource.Id.etb_occupationyear); occupationyearLayout = FindViewById <TextInputLayout>(Resource.Id.occupationyear_layout); gpscAddLocationButton = FindViewById <ImageView>(Resource.Id.gpscaddlocation_button); tvblatLang = FindViewById <TextView>(Resource.Id.tvf_latLang); buildingPhoto = FindViewById <ImageView>(Resource.Id.imgb_buildingphoto); _GPSCoordinates = new GPSCoordinate(); buildingName = FindViewById <EditText>(Resource.Id.etb_name); buildingType = FindViewById <Spinner>(Resource.Id.sf_buildingtype); buildingstandard = FindViewById <Spinner>(Resource.Id.sf_buildingstandard); utilisationStatus = FindViewById <EditText>(Resource.Id.etb_utilisationstatus); nooOfFoors = FindViewById <EditText>(Resource.Id.etb_nooffloors); totalFootprintAream2 = FindViewById <EditText>(Resource.Id.etb_totalfootprintaream2); totalImprovedaAeam2 = FindViewById <EditText>(Resource.Id.etb_totalimprovedaream2); heritage = FindViewById <Switch>(Resource.Id.sf_heritage); disabledAccesss = FindViewById <Spinner>(Resource.Id.sf_disabledaccesss); disabledComment = FindViewById <EditText>(Resource.Id.etb_disabledcomment); constructionDescription = FindViewById <EditText>(Resource.Id.etb_constructiondescription); accuracyMessage = FindViewById <TextView>(Resource.Id.accuracy_message); refashAccuracy = FindViewById <ImageView>(Resource.Id.refreshaccuracy_button); refashAccuracy.Click += RefashAccuracy_Click; _dir = appPreferences.CreateDirectoryForPictures(); if (data != null) { building = Newtonsoft.Json.JsonConvert.DeserializeObject <Building>(data); isEdit = true; SupportActionBar.Title = "Edit Building"; occupationYear.Text = building.OccupationYear; if (building.GPSCoordinates != null) { tvblatLang.Text = "Lat: " + building.GPSCoordinates.Latitude + " Long: " + building.GPSCoordinates.Longitude; _GPSCoordinates = building.GPSCoordinates; } buildingName.Text = building.BuildingName; buildingType.SetSelection(helpers.GetSpinnerIndex(buildingType, building.BuildingType)); buildingstandard.SetSelection(helpers.GetSpinnerIndex(buildingstandard, building.BuildingStandard)); disabledAccesss.SetSelection(helpers.GetSpinnerIndex(disabledAccesss, building.DisabledAccess)); utilisationStatus.Text = building.Status; nooOfFoors.Text = Convert.ToString(building.NumberOfFloors); totalFootprintAream2.Text = Convert.ToString(building.FootPrintArea); totalImprovedaAeam2.Text = Convert.ToString(building.ImprovedArea); heritage.Checked = building.Heritage; disabledComment.Text = building.DisabledComment; constructionDescription.Text = building.ConstructionDescription; Bitmap bit = SetImageBitmap(_dir + "/" + building.Photo); if (bit != null) { buildingPhoto.SetImageBitmap(bit); } else if (bit == null && !String.IsNullOrEmpty(building.Photo)) { PictureViewModel pictureViewModel = new PictureViewModel(); Models.Picture picture = await pictureViewModel.ExecuteGetPictureCommand(building.Photo); if (picture != null) { var _bit = appPreferences.StringToBitMap(picture.File); if (_bit != null) { SaveImage(_bit, building.Photo); } buildingPhoto.SetImageBitmap(_bit); } } } else { SupportActionBar.Title = "Add New Building"; } SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); gpscAddLocationButton.Click += AddLocation_Click; buildingPhoto.Click += (sender, e) => { ShowImage_Click(); }; GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (location != null) { accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); } Toolbar.MenuItemClick += (sender, e) => { var itemTitle = e.Item.TitleFormatted; switch (itemTitle.ToString()) { case "Log Out": var intent = new Intent(this, typeof(LoginActivity)); appPreferences.SaveUserId("0"); StartActivity(intent); break; case "Save": SaveBuilding(); break; } }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetHomeButtonEnabled(true); streetAddress = FindViewById <EditText>(Resource.Id.etf_streetAddress); suburb = FindViewById <EditText>(Resource.Id.etf_suburb); region = FindViewById <EditText>(Resource.Id.etf_region); province = FindViewById <Spinner>(Resource.Id.sf_province); localmunicipality = FindViewById <Spinner>(Resource.Id.sf_localmunicipality); gpsLocationButton = FindViewById <ImageView>(Resource.Id.gpscaddlocation_button); bpLocationButton = FindViewById <ImageView>(Resource.Id.bpaddlocation_button); refashAccuracy = FindViewById <ImageView>(Resource.Id.refreshaccuracy_button); tvfLatLong = FindViewById <TextView>(Resource.Id.tvf_latLang); boundaryPolygonsText = FindViewById <TextView>(Resource.Id.boundaryPolygonsText); accuracyMessage = FindViewById <TextView>(Resource.Id.accuracy_message); bpListView = FindViewById <ListView>(Resource.Id.bplistView1); itemList = new List <string>(); refashAccuracy.Click += RefashAccuracy_Click; _BoundryPolygons = new List <BoundryPolygon>(); ViewModel = new LocationViewModel(); appPreferences = new AppPreferences(Application.Context); helpers = new UIHelpers(); Location = new Models.Location(); var data = Intent.GetStringExtra("data"); if (data != null) { Facility = Newtonsoft.Json.JsonConvert.DeserializeObject <Facility>(data); Location = Facility.Location; if (Location != null) { streetAddress.Text = Location.StreetAddress; suburb.Text = Location.Suburb; region.Text = Location.Region; province.SetSelection(helpers.GetSpinnerIndex(province, Location.Province)); localmunicipality.SetSelection(helpers.GetSpinnerIndex(localmunicipality, Location.LocalMunicipality)); if (Location.GPSCoordinates != null) { tvfLatLong.Text = "Lat: " + Location.GPSCoordinates.Latitude + " Long: " + Location.GPSCoordinates.Longitude; } if (Location.BoundryPolygon != null) { foreach (var BoundaryPolygon in Location.BoundryPolygon) { _BoundryPolygons.Add(BoundaryPolygon); itemList.Add("Lat: " + BoundaryPolygon.Latitude.ToString() + " Long: " + BoundaryPolygon.Longitude.ToString()); } arrayAdapter = new ArrayAdapter <string>(this, Resource.Layout.list_item, itemList); bpListView.Adapter = arrayAdapter; bpListView.ItemLongClick += Adapter_ItemSwipe; ViewGroup.LayoutParams param = bpListView.LayoutParameters; param.Height = 80 * _BoundryPolygons.Count(); bpListView.LayoutParameters = param; } boundaryPolygonsText.Text = String.Format("Boundary Polygons {0}", itemList.Count); } } bpLocationButton.Click += BPLocationButton_Click; gpsLocationButton.Click += GPSLocationButton_Click; Toolbar.MenuItemClick += (sender, e) => { var itemTitle = e.Item.TitleFormatted; switch (itemTitle.ToString()) { case "Log Out": var intent = new Intent(this, typeof(LoginActivity)); appPreferences.SaveUserId("0"); StartActivity(intent); break; case "Save": SaveLocation(); break; } }; GPSTracker GPSTracker = new GPSTracker(); Android.Locations.Location location = GPSTracker.GPSCoordinate(); if (location != null) { accuracyMessage.Text = String.Format("Accurate to {0} Meters", location.Accuracy.ToString()); } }