public static async Task <PlaceInfo> AsyncGetPlaceName(GpsLocation location) { //https://docs.microsoft.com/en-us/xamarin/essentials/geocoding?tabs=android try { var loc = new Xamarin.Essentials.Location(location.Latitude, location.Longitude); var placemarks = await Geocoding.GetPlacemarksAsync(loc); var placemark = placemarks?.FirstOrDefault(); if (placemark != null) { var geocodeAddress = placemark.Thoroughfare; geocodeAddress = geocodeAddress.Append(" ", placemark.SubThoroughfare); geocodeAddress = geocodeAddress.Append(", ", placemark.SubLocality); geocodeAddress = geocodeAddress.Append(", ", placemark.Locality); geocodeAddress = geocodeAddress.Append(", ", placemark.CountryCode); var country = PoiCountryHelper.GetCountry(placemark.CountryCode) ?? PoiCountryHelper.GetDefaultCountryByPhoneSettings(); return(new PlaceInfo(geocodeAddress, country)); } return(new PlaceInfo()); } catch { return(new PlaceInfo()); } }
protected override void OnResume() { base.OnResume(); Task.Run(async() => { var defaultCountry = await PoiCountryHelper.GetDefaultCountryByPhoneLocation(); MainThread.BeginInvokeOnMainThread(() => SelectCountry(defaultCountry)); }); }
private void OnSelectionUpdated(Poi poi) { FindViewById <TextView>(Resource.Id.textViewPlaceName).Text = poi.Name; FindViewById <TextView>(Resource.Id.textViewPlaceCountry).Text = PoiCountryHelper.GetCountryName(poi.Country); FindViewById <TextView>(Resource.Id.textViewAltitude).Text = $"{poi.Altitude:F0} m"; FindViewById <TextView>(Resource.Id.textViewGpsLocation).Text = GpsUtils.LocationAsString(poi.Latitude, poi.Longitude); var thumbnail = FindViewById <ImageView>(Resource.Id.Thumbnail); thumbnail.SetImageResource(PoiCategoryHelper.GetImage(poi.Category)); CalculateDownloadSize(poi); }
private void OnSave() { try { //View angle correction _settings.IsViewAngleCorrection = _switchManualViewAngle.Checked; if (_switchManualViewAngle.Checked) { _settings.CorrectionViewAngleHorizontal = _seekBarCorrectionViewAngleHorizontal.Progress / (float)10.0;; _settings.CorrectionViewAngleVertical = _seekBarCorrectionViewAngleVertical.Progress / (float)10.0; } //Manual GPS location if (_switchManualGpsLocation.Checked) { var loc = new GpsLocation( double.Parse(_editTextLongitude.Text, CultureInfo.InvariantCulture), double.Parse(_editTextLatitude.Text, CultureInfo.InvariantCulture), double.Parse(_editTextAltitude.Text, CultureInfo.InvariantCulture)); _settings.SetManualLocation(loc); } else { _settings.SetAutoLocation(); } //Auto elevation profile _settings.AutoElevationProfile = _switchAutoElevationProfile.Checked; //Altitude from elevation map _settings.AltitudeFromElevationMap = _switchAltitudeFromElevationMap.Checked; _settings.CameraResolutionSelected = _listOfCameraResolutions[_spinnerPhotoResolution.SelectedItemPosition]; _settings.Language = PoiCountryHelper.GetLanguageCode(_listOfLanguages[_spinnerLanguages.SelectedItemPosition]); _settings.NotifySettingsChanged(ChangedData.ViewOptions); AppContextLiveData.Instance.SetLocale(this); } catch (Exception ex) { PopupHelper.ErrorDialog(this, "Error when saving settings.", ex.Message); } SetResult(RESULT_OK); Finish(); }
private bool IsDirty() { if (_isDirty) { return(true); } if (!_settings.CameraResolutionSelected.Equals(_listOfCameraResolutions[_spinnerPhotoResolution.SelectedItemPosition])) { return(true); } if (_settings.Language != PoiCountryHelper.GetLanguageCode(_listOfLanguages[_spinnerLanguages.SelectedItemPosition])) { return(true); } return(false); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AppContextLiveData.Instance.SetLocale(this); if (AppContextLiveData.Instance.IsPortrait) { SetContentView(Resource.Layout.SettingsActivityPortrait); } else { SetContentView(Resource.Layout.SettingsActivityLandscape); } var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetActionBar(toolbar); ActionBar.SetDisplayShowHomeEnabled(true); ActionBar.SetDisplayHomeAsUpEnabled(true); ActionBar.SetDisplayShowTitleEnabled(true); ActionBar.SetTitle(Resource.String.SettingsActivity); _spinnerLanguages = FindViewById <Spinner>(Resource.Id.spinnerLanguage); _spinnerPhotoResolution = FindViewById <Spinner>(Resource.Id.spinnerResolution); _switchManualViewAngle = FindViewById <Switch>(Resource.Id.switchManualViewAngle); _seekBarCorrectionViewAngleHorizontal = FindViewById <SeekBar>(Resource.Id.seekBarCorrectionViewAngleHorizontal); _textViewAngleHorizontal = FindViewById <TextView>(Resource.Id.textViewAngleHorizontal); _seekBarCorrectionViewAngleVertical = FindViewById <SeekBar>(Resource.Id.seekBarCorrectionViewAngleVertical); _textViewAngleVertical = FindViewById <TextView>(Resource.Id.textViewAngleVertical); _resetButton = FindViewById <Button>(Resource.Id.reset); _resetButton.SetOnClickListener(this); var adapterLanguages = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, _listOfLanguages); _spinnerLanguages.Adapter = adapterLanguages; _spinnerLanguages.SetSelection(_listOfLanguages.FindIndex(i => i == PoiCountryHelper.GetLanguageName(_settings.Language))); _spinnerLanguages.ItemSelected += (sender, args) => { InvalidateOptionsMenu(); }; _listOfCameraResolutions = CameraUtilities.GetCameraResolutions(_settings.CameraId).Where(x => x.Width >= ScaleImageView.MIN_IMAGE_SIZE && x.Height >= ScaleImageView.MIN_IMAGE_SIZE).ToList(); var adapterPhotoResolution = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem, _listOfCameraResolutions); _spinnerPhotoResolution.Adapter = adapterPhotoResolution; var resolutionIdx = _listOfCameraResolutions.FindIndex(i => i.Equals(_settings.CameraResolutionSelected)); _spinnerPhotoResolution.SetSelection(resolutionIdx); _spinnerPhotoResolution.ItemSelected += (sender, args) => { InvalidateOptionsMenu(); }; _switchManualViewAngle.Checked = _settings.IsViewAngleCorrection; _switchManualViewAngle.SetOnClickListener(this); _seekBarCorrectionViewAngleHorizontal.Enabled = _settings.IsViewAngleCorrection; _seekBarCorrectionViewAngleHorizontal.Progress = (int)(_settings.CorrectionViewAngleHorizontal * 10); _seekBarCorrectionViewAngleHorizontal.ProgressChanged += SeekBarProgressChanged; _seekBarCorrectionViewAngleVertical.Enabled = _settings.IsViewAngleCorrection; _seekBarCorrectionViewAngleVertical.Progress = (int)(_settings.CorrectionViewAngleVertical * 10); _seekBarCorrectionViewAngleVertical.ProgressChanged += SeekBarProgressChanged; UpdateViewAngleText(_settings.CorrectionViewAngleHorizontal, _settings.CorrectionViewAngleVertical); _switchManualGpsLocation = FindViewById <Switch>(Resource.Id.switchManualGpsLocation); _switchManualGpsLocation.Checked = _settings.IsManualLocation; _switchManualGpsLocation.SetOnClickListener(this); _textViewLatitude = FindViewById <TextView>(Resource.Id.latitudeTitle); _textViewLongitude = FindViewById <TextView>(Resource.Id.longitudeTitle); _textViewAltitude = FindViewById <TextView>(Resource.Id.altitudeTitle); _editTextLatitude = FindViewById <EditText>(Resource.Id.editTextLatitude); _editTextLongitude = FindViewById <EditText>(Resource.Id.editTextLongitude); _editTextAltitude = FindViewById <EditText>(Resource.Id.editTextAltitude); _editTextLatitude.TextChanged += ManualGpsLocationChanged; _editTextLongitude.TextChanged += ManualGpsLocationChanged; _editTextAltitude.TextChanged += ManualGpsLocationChanged; EnableOrDisableGpsLocationInputs(_settings.IsManualLocation); InitializeGpsLocationInputs(_settings.IsManualLocation ? _settings.ManualLocation : AppContextLiveData.Instance.MyLocation); _switchAltitudeFromElevationMap = FindViewById <Switch>(Resource.Id.switchAltitudeFromElevationMap); _switchAltitudeFromElevationMap.Checked = _settings.AltitudeFromElevationMap; _switchAltitudeFromElevationMap.SetOnClickListener(this); _switchAutoElevationProfile = FindViewById <Switch>(Resource.Id.switchAutoElevationProfile); _switchAutoElevationProfile.Checked = _settings.AutoElevationProfile; _switchAutoElevationProfile.SetOnClickListener(this); var buttonClearElevationData = FindViewById <Button>(Resource.Id.buttonClearElevationData); buttonClearElevationData.SetOnClickListener(this); _textViewElevationDataSize = FindViewById <TextView>(Resource.Id.textViewElevationDataSize); UpdateElevationDataSize(); }
public void SetLocale(Context appContext) { PoiCountryHelper.SetLocale(appContext.Resources, Settings.Language); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); AppContextLiveData.Instance.SetLocale(this); Platform.Init(this, savedInstanceState); if (AppContextLiveData.Instance.IsPortrait) { SetContentView(Resource.Layout.EditActivityPortrait); } else { SetContentView(Resource.Layout.EditActivityLandscape); } _id = Intent.GetLongExtra("Id", -1); var toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetActionBar(toolbar); ActionBar.SetDisplayShowHomeEnabled(true); ActionBar.SetDisplayHomeAsUpEnabled(true); ActionBar.SetDisplayShowTitleEnabled(true); ActionBar.SetTitle(Resource.String.PoiEditActivity); _editTextName = FindViewById <EditText>(Resource.Id.editTextName); _editTextLatitude = FindViewById <EditText>(Resource.Id.editTextLatitude); _editTextLongitude = FindViewById <EditText>(Resource.Id.editTextLongitude); _editTextAltitude = FindViewById <EditText>(Resource.Id.editTextAltitude); _buttonFavourite = FindViewById <ImageView>(Resource.Id.buttonFavourite); _buttonOpenWiki = FindViewById <Button>(Resource.Id.buttonWiki); _buttonOpenMap = FindViewById <Button>(Resource.Id.buttonMap); _buttonTeleport = FindViewById <Button>(Resource.Id.buttonTeleport); _spinnerCategory = FindViewById <Spinner>(Resource.Id.spinnerCategory); _spinnerCountry = FindViewById <Spinner>(Resource.Id.spinnerCountry); _spinnerCountry.Adapter = new CountryAdapter(this); _spinnerCategory.Adapter = new CategoryAdapter(this); _thumbnail = FindViewById <ImageView>(Resource.Id.Thumbnail); if (_id != -1) { _item = Context.Database.GetItem(_id); var categoryIndex = (_spinnerCategory.Adapter as CategoryAdapter).GetPosition(_item.Category); _spinnerCategory.SetSelection(categoryIndex); var countryIndex = (_spinnerCountry.Adapter as CountryAdapter).GetPosition(_item.Country); _spinnerCountry.SetSelection(countryIndex); _editTextName.Text = _item.Name; _editTextAltitude.Text = $"{_item.Altitude:F0}"; _editTextLongitude.Text = $"{_item.Longitude:F7}".Replace(",", "."); _editTextLatitude.Text = $"{_item.Latitude:F7}".Replace(",", "."); _thumbnail.SetImageResource(PoiCategoryHelper.GetImage(_item.Category)); } else { var country = PoiCountryHelper.GetDefaultCountryByPhoneSettings(); var countryIndex = (_spinnerCountry.Adapter as CountryAdapter).GetPosition(country); _spinnerCountry.SetSelection(countryIndex); } _buttonFavourite.SetImageResource(_item.Favorite ? Android.Resource.Drawable.ButtonStarBigOn : Android.Resource.Drawable.ButtonStarBigOff); _buttonOpenWiki.Enabled = (string.IsNullOrEmpty(_item.Wikidata) && string.IsNullOrEmpty(_item.Wikipedia)) ? false : true; _buttonOpenWiki.Visibility = (string.IsNullOrEmpty(_item.Wikidata) && string.IsNullOrEmpty(_item.Wikipedia)) ? ViewStates.Gone : ViewStates.Visible; //finally set-up event listeners _editTextName.TextChanged += OnTextChanged; _editTextLatitude.TextChanged += OnTextChanged; _editTextLongitude.TextChanged += OnTextChanged; _editTextAltitude.TextChanged += OnTextChanged; _buttonFavourite.SetOnClickListener(this); _buttonOpenMap.SetOnClickListener(this); _buttonOpenWiki.SetOnClickListener(this); _buttonTeleport.SetOnClickListener(this); _spinnerCategory.ItemSelected += OnCategorySelected; _spinnerCountry.ItemSelected += OnCountrySelected; }
private void OnIndexDownloaded(string json) { try { _downloadViewItems = new List <DownloadViewItem>(); //fetch list of already downladed items from database var downloadedTask = AppContext.Database.GetDownloadedPoisAsync(); downloadedTask.Wait(); var _downloadItems = downloadedTask.Result.ToList(); if (!String.IsNullOrEmpty(json)) { var _horizonIndex = JsonConvert.DeserializeObject <HorizonIndex>(json); //combine those two lists together foreach (var country in _horizonIndex) { foreach (var item in country.PoiData) { var fromDB = _downloadItems.Find(x => x.Id == item.Id); if (fromDB == null) { fromDB = new PoisToDownload() { Id = item.Id, Description = item.Description, Category = item.Category, Url = item.Url, Country = country.Country, PointCount = item.PointCount, DateCreated = item.DateCreated, DownloadDate = null }; } var x = new DownloadViewItem(fromDB, item); _downloadViewItems.Add(x); } } } } catch (Exception e) { PopupHelper.ErrorDialog(this, Resource.String.Download_ErrorDownloading, e.Message); return; } var countries = _downloadViewItems.Select(x => x.fromDatabase.Country) .Distinct() .OrderBy(x => PoiCountryHelper.GetCountryName(x)) .ToList(); Task.Run(async() => { var defaultCountry = await PoiCountryHelper.GetDefaultCountryByPhoneLocation(); MainThread.BeginInvokeOnMainThread(() => { _countryAdapter.SetItems(countries); SelectCountry(defaultCountry); }); }); }