private void InitLocationRequest() { try { locationRequest = new LocationRequest() .SetPriority(LocationRequest.PriorityHighAccuracy) .SetInterval(6 * 1000 * 2) .SetFastestInterval(6 * 1000); locationCallback = new FusedLocationProviderCallback((MainActivity)CrossCurrentActivity.Current.Activity); fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(CrossCurrentActivity.Current.Activity); /*Criteria locationCriteria = new Criteria(); * //locationCriteria.Accuracy = Accuracy.High; * locationCriteria.PowerRequirement = Power.High; * * var locationProvider = locationManager.GetBestProvider(locationCriteria, true); * * var intent = new Intent(CrossCurrentActivity.Current.Activity, typeof(MainActivity)); * var resultPendingIntent = PendingIntent.GetActivity(Forms.Context, 0, intent, PendingIntentFlags.OneShot); * * locationManager.RequestLocationUpdates(locationProvider, 2000, 1, resultPendingIntent);*/ } catch (Exception ex) { Log.Error("GPS EXCEPTION", ex.StackTrace); } }
public OnCallbackSettingsSuccessListener(RequestWithCallbackActivity locationActivity, FusedLocationProviderClient fusedLocationProviderClient, LocationRequest locationRequest, LocationCallback callback) { this.locationActivity = locationActivity; this.fusedLocationProviderClient = fusedLocationProviderClient; this.locationRequest = locationRequest; this.locationCallback = callback; }
// Lighthouse private async void StartLighthouse() { System.Diagnostics.Debug.WriteLine("StartLighthouse"); // Initialize Estimote (TODO: Remove values when distributing) EstimoteSdk.Common.Config.Estimote.EnableDebugLogging(true); EstimoteSdk.Common.Config.Estimote.Initialize(Application.Context, LHPEEstimoteId, LHPEEstimoteKey); // Initialize GPS Location if (IsPlayServicesAvailable()) { locationRequest = new LocationRequest() .SetPriority(LocationRequest.PriorityBalancedPowerAccuracy) .SetInterval(1000) .SetFastestInterval(locationFrequencySeconds * 1000); locationCallback = new FusedLocationProviderCallback((MainActivity)CrossCurrentActivity.Current.Activity); fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); } // Initialize lhpe await Lighthouse.Start(LHPEEnvironment, LHPEAppId, LHPEAppKey); // Stop Loading Activity, Start Main Activity var intent = new Intent(this, typeof(LHPEXamarinSample.Droid.MainActivity)); StartActivity(intent); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); if (bundle != null) { isRequestingLocationUpdates = bundle.KeySet().Contains(KEY_REQUESTING_LOCATION_UPDATES) && bundle.GetBoolean(KEY_REQUESTING_LOCATION_UPDATES); } else { isRequestingLocationUpdates = false; } // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); isGooglePlayServicesInstalled = IsGooglePlayServicesInstalled(); rootLayout = FindViewById(Resource.Id.root_layout); // UI to display last location getLastLocationButton = FindViewById <Button>(Resource.Id.get_last_location_button); latitude = FindViewById <TextView>(Resource.Id.latitude); longitude = FindViewById <TextView>(Resource.Id.longitude); provider = FindViewById <TextView>(Resource.Id.provider); // UI to display location updates requestLocationUpdatesButton = FindViewById <Button>(Resource.Id.request_location_updates_button); latitude2 = FindViewById <TextView>(Resource.Id.latitude2); longitude2 = FindViewById <TextView>(Resource.Id.longitude2); provider2 = FindViewById <TextView>(Resource.Id.provider2); //addressText = FindViewById<TextView>(Resource.Id.address_text); //locationText = FindViewById<TextView>(Resource.Id.location_text); macAddressText = FindViewById <TextView>(Resource.Id.macaddress); batteryLevelText = FindViewById <TextView>(Resource.Id.batterylevel); //batteryLevelText = FindViewById<TextView>(Resource.Id.batterylevel_text); //FindViewById<TextView>(Resource.Id.get_address_button).Click += AddressButton_OnClick; if (isGooglePlayServicesInstalled) { locationRequest = new LocationRequest() .SetPriority(LocationRequest.PriorityHighAccuracy) .SetInterval(FIVE_MINUTES) .SetFastestInterval(TWO_MINUTES); locationCallback = new FusedLocationProviderCallback(this); fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); getLastLocationButton.Click += GetLastLocationButtonOnClick; requestLocationUpdatesButton.Click += RequestLocationUpdatesButtonOnClick; } else { // If there is no Google Play Services installed, then this sample won't run. Snackbar.Make(rootLayout, Resource.String.missing_googleplayservices_terminating, Snackbar.LengthIndefinite) .SetAction(Resource.String.ok, delegate { FinishAndRemoveTask(); }) .Show(); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); if (bundle != null) { isRequestingLocationUpdates = bundle.KeySet().Contains(KEY_REQUESTING_LOCATION_UPDATES) && bundle.GetBoolean(KEY_REQUESTING_LOCATION_UPDATES); } else { isRequestingLocationUpdates = false; } // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); isGooglePlayServicesInstalled = IsGooglePlayServicesInstalled(); rootLayout = FindViewById(Resource.Id.root_layout); // UI to display last location getLastLocationButton = FindViewById <Button>(Resource.Id.get_last_location_button); latitude = FindViewById <TextView>(Resource.Id.latitude); longitude = FindViewById <TextView>(Resource.Id.longitude); speed = FindViewById <TextView>(Resource.Id.speed); provider = FindViewById <TextView>(Resource.Id.provider); // UI to display location updates requestLocationUpdatesButton = FindViewById <Button>(Resource.Id.request_location_updates_button); latitude2 = FindViewById <TextView>(Resource.Id.latitude2); longitude2 = FindViewById <TextView>(Resource.Id.longitude2); speed2 = FindViewById <TextView>(Resource.Id.speed2); provider2 = FindViewById <TextView>(Resource.Id.provider2); fileLogger = new FileLogger(); _locationFetcher = new Timer(); if (isGooglePlayServicesInstalled) { locationRequest = new LocationRequest() .SetPriority(LocationRequest.PriorityHighAccuracy) .SetInterval(1000) .SetFastestInterval(1000); locationCallback = new FusedLocationProviderCallback(this); fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); getLastLocationButton.Click += GetLastLocationButtonOnClick; requestLocationUpdatesButton.Click += RequestLocationUpdatesButtonOnClick; } else { // If there is no Google Play Services installed, then this sample won't run. Snackbar.Make(rootLayout, Resource.String.missing_googleplayservices_terminating, Snackbar.LengthIndefinite) .SetAction(Resource.String.ok, delegate { FinishAndRemoveTask(); }) .Show(); } //_locationFetcher.Elapsed += new ElapsedEventHandler(Timer_Elapsed); //_locationFetcher.Interval = 1000; //_locationFetcher.Start(); Start(); }
public LocationValueEventListener(LocationCallback callback, DatabaseReference keyRef) { this.callback = callback; this.keyRef = keyRef; keyRef.ValueChanged += (this.onDataChange); //System.EventHandler<ValueChangedEventArgs> ValueChanged = onDataChange; }
public LocationHandler(Context context) { // Create client from context client = LocationServices.GetFusedLocationProviderClient(context); // Create Android location manager locationManager = context.GetSystemService(Context.LocationService) as LocationManager; // Create location request and set some options locationRequest = new LocationRequest(); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(1000); // Receives all location updates locationCallback = new LocationCallback(); locationCallback.LocationResult += (sender, args) => { if (args.Result == null) { return; } foreach (var location in args.Result.Locations) { OnLocationUpdate?.Invoke(location); } }; // Start receiving location updates Start(); }
protected void StartLocationUpdates() //must run on UI thread { try { int interval; if (!(Session.InAppLocationRate is null)) { interval = (int)Session.InAppLocationRate; } else { interval = (int)Settings.InAppLocationRate; } LocationRequest locationRequest = new LocationRequest() .SetFastestInterval((long)(interval * 1000 * 0.8)) .SetInterval(interval * 1000); if (Session.LocationAccuracy == 0) { locationRequest.SetPriority(LocationRequest.PriorityBalancedPowerAccuracy); } else { locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); } locationCallback = new FusedLocationProviderCallback(this); fusedLocationProviderClient.RequestLocationUpdatesAsync(locationRequest, locationCallback); locationUpdating = true; currentLocationRate = interval; CommonMethods.LogStatic("Location updates started with interval " + interval); }
/// <inheritdoc /> public override void OnCreate() { _fusedLocationClient = LocationServices.GetFusedLocationProviderClient(this); _locationCallback = new LocationCallback(); _locationCallback.LocationResult += (sender, args) => OnNewLocation(args.Result.LastLocation); CreateLocationRequest(); GetLastLocation(); var handlerThread = new HandlerThread(Tag); handlerThread.Start(); _serviceHandler = new Handler(handlerThread.Looper); _notificationManager = (NotificationManager)GetSystemService(NotificationService); // Android O requires a Notification Channel. if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var name = GetString(Resource.String.app_name); // Create the channel for the notification var mChannel = new NotificationChannel(ChannelId, name, NotificationImportance.Low); // Set the Notification Channel for the Notification Manager. _notificationManager.CreateNotificationChannel(mChannel); } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_huaweilocation); //Button click listeners FindViewById(Resource.Id.location_requestLocationUpdatesWithCallback).SetOnClickListener(this); FindViewById(Resource.Id.location_removeLocationUpdatesWithcallback).SetOnClickListener(this); AddLogFragment(); mFusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); mSettingsClient = LocationServices.GetSettingsClient(this); mLocationRequest = new LocationRequest(); // Sets the interval for location update (unit: Millisecond) mLocationRequest.SetInterval(5000); // Sets the priority mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); if (null == mLocationCallback) { mLocationCallback = new LocationCallbackImpl(); } if (Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != Permission.Granted && Android.Support.V4.Content.ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessCoarseLocation) != Permission.Granted) { string[] strings = { Manifest.Permission.AccessFineLocation, Manifest.Permission.AccessCoarseLocation }; ActivityCompat.RequestPermissions(this, strings, 1); } }
public async Task GetLocationUpdates(Action <WeatherLocation> action, Action error) { var locationRequest = new LocationRequest() .SetPriority(LocationRequest.PriorityLowPower) .SetInterval(60 * 1000 * 5) .SetFastestInterval(60 * 1000 * 2); _locationCallback = new FusedLocationProviderCallback(action, error); await _locationProvider.RequestLocationUpdatesAsync(locationRequest, _locationCallback); }
private async Task CreateLocationRequest() { _mLocationRequest = new LocationRequest(); _mLocationRequest.SetInterval(UPDATE_INTERVAL_IN_MILLISECONDS); _mLocationRequest.SetFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS); _mLocationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); LocationRequestCallback = new LocationCallback(); LocationRequestCallback.LocationResult += OnLocationRequestResult; await FusedLocationProviderClient.RequestLocationUpdatesAsync(_mLocationRequest, LocationRequestCallback); _requestingLocationUpdates = true; }
private void InitializeFields() { locationCallback = new GeoFenceLocationCallback(); locationRequest = new LocationRequest(); locationRequest.SetInterval(5000); locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); settingsClient = LocationServices.GetSettingsClient(this); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); textLastLocation = FindViewById <TextView>(Resource.Id.textLastLocation); textLocationUpdates = FindViewById <TextView>(Resource.Id.textLocationUpdates); // Create our client and location callback fusedClient = new FusedLocationProviderClient(this); locationCallback = new LocationCallback(); }
public override void OnCreate() { FusedLocationClient = LocationServices.GetFusedLocationProviderClient(this); LocationCallback = new LocationCallbackImpl { Service = this }; CreateLocationRequest(); HandlerThread handlerThread = new HandlerThread(Tag); handlerThread.Start(); ServiceHandler = new Handler(handlerThread.Looper); NotificationManager = (NotificationManager)GetSystemService(NotificationService); }
private void InitializeFields() { locationRequest = new LocationRequest(); //Sets the interval for location update (unit: Millisecond) locationRequest.SetInterval(10000); //Sets the priority locationRequest.SetPriority(LocationRequest.PriorityHighAccuracy); fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); settingsClient = LocationServices.GetSettingsClient(this); if (locationCallback == null) { locationCallback = new HMSLocationCallback(); } }
public void SetHDSuccess() { if (mLocationCallback == null) { mLocationCallback = new LocationCallBackWrap(); } mFusedLocationProviderClient .requestLocationUpdatesEx(mLocationRequest, mLocationCallback, Looper.getMainLooper()) .addOnSuccessListener(new LocationSuccessListener((AndroidJavaObject o) => { TestTip.Inst.ShowText("SetCallbackSuccess success"); })) .addOnFailureListener(new HmsFailureListener((Exception e) => { TestTip.Inst.ShowText("SetCallbackSuccess fail"); })); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); _fusedLocationClient = new FusedLocationProviderClient(this); _locationCallback = new LocationCallback(); _locationCallback.LocationResult += OnLocationResult; Button startButton = FindViewById <Button>(Resource.Id.startTrackingButton); startButton.Click += StartButtonClicked; Button stopButton = FindViewById <Button>(Resource.Id.stopTrackingButton); stopButton.Click += StopButtonClicked; }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); textViewHello = FindViewById <TextView>(Resource.Id.txtHello); IsGooglePlayServicesInstalled(); fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); locationRequest = new LocationRequest() .SetPriority(LocationRequest.PriorityHighAccuracy) .SetInterval(1000) .SetFastestInterval(1000); locationCallback = new FusedLocationProviderCallback(this); await StartRequestingLocationUpdates(); }
public async Task StartRequestingLocation(int miliseconds = 1000 * 60 * 30) { Log.Error("Starting location", miliseconds.ToString()); if (!Utils.CheckIfLocationIsEnabled()) { Toast.MakeText(Application.Context, "Nu aveti locatia activata", ToastLength.Long).Show(); return; } if (!Utils.IsGooglePlayServicesInstalled(Application.Context)) { return; } if (_fusedLocationProviderClient is null || _locationRequest is null) { _locationRequest = new LocationRequest() .SetPriority(LocationRequest.PriorityHighAccuracy); _locationCallback = new FusedLocationProviderCallback(this); _fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(Application.Context); } await ChangeInterval(miliseconds); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_location); startButton = FindViewById <Button>(Resource.Id.btnStartLocationRequest); stopButton = FindViewById <Button>(Resource.Id.btnStopLocationRequest); startButton.Click += StartButton_Click; stopButton.Click += StopButton_Click; act = this; lstView = FindViewById <ListView>(Resource.Id.lstLocations); fusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(this); locationSettings = LocationServices.GetSettingsClient(this); locationRequest = new LocationRequest().SetPriority(LocationRequest.PriorityHighAccuracy); locationRequest.SetInterval(100000); locationRequest.SetNeedAddress(true); locationRequest.SetLanguage("en"); locationRequest.SetCountryCode("EN"); if (locationCallback == null) { locationCallback = new CustomLocationCallback(this); } }
public override void OnCreate() { FusedLocationClient = LocationServices.GetFusedLocationProviderClient(this); LocationCallback = new LocationCallbackImpl { Service = this }; CreateLocationRequest(); GetLastLocation(); HandlerThread handlerThread = new HandlerThread(Tag); handlerThread.Start(); ServiceHandler = new Handler(handlerThread.Looper); NotificationManager = (NotificationManager)GetSystemService(NotificationService); if (Build.VERSION.SdkInt >= Build.VERSION_CODES.O) { string name = GetString(Resource.String.app_name); NotificationChannel mChannel = new NotificationChannel(ChannelId, name, NotificationManager.ImportanceDefault); NotificationManager.CreateNotificationChannel(mChannel); } }
private void StartLocationUpdatesInt() { FusedLocationClient = LocationServices.GetFusedLocationProviderClient(this); LocationCallback = new LocationCallbackImpl { Service = this }; CreateLocationRequest(); CheckLocationSettings(); // GetLastLocation(); // RequestLocationUpdates(); /* * locationCallback = new FusedLocationProviderCallback(this); * * locationRequest = new LocationRequest() * .SetPriority(priorityAccuracy) * .SetInterval(updateIntervalInMilliseconds) * .SetFastestInterval(fastestUpdateIntervalInMilliseconds); * CheckLocationSettings(); */ }
public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your fragment here if (Arguments != null) { using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader( new System.IO.StringReader(Arguments.GetString("data", null)))) { location = LocationData.FromJson(jsonTextReader); } if (location != null && wLoader == null) { wLoader = new WeatherDataLoader(location, this, this); } } if (WearableHelper.IsGooglePlayServicesInstalled && !WearableHelper.HasGPS) { mFusedLocationClient = new FusedLocationProviderClient(Activity); mLocCallback = new LocationCallback(); mLocCallback.LocationResult += async(sender, e) => { mLocation = e.Result.LastLocation; if (Settings.FollowGPS && await UpdateLocation()) { // Setup loader from updated location wLoader = new WeatherDataLoader(this.location, this, this); await RefreshWeather(false); } await mFusedLocationClient.RemoveLocationUpdatesAsync(mLocCallback); }; } else { mLocListnr = new Droid.Helpers.LocationListener(); mLocListnr.LocationChanged += async(Android.Locations.Location location) => { if (Settings.FollowGPS && await UpdateLocation()) { // Setup loader from updated location wLoader = new WeatherDataLoader(this.location, this, this); await RefreshWeather(false); } }; } dataReceiver = new LocalBroadcastReceiver(); dataReceiver.BroadcastReceived += async(context, intent) => { if (WearableHelper.LocationPath.Equals(intent?.Action) || WearableHelper.WeatherPath.Equals(intent?.Action)) { if (WearableHelper.WeatherPath.Equals(intent.Action) || (!loaded && location != null)) { if (timer.Enabled) { timer.Stop(); } // We got all our data; now load the weather wLoader = new WeatherDataLoader(location, this, this); await wLoader.ForceLoadSavedWeatherData(); } if (WearableHelper.LocationPath.Equals(intent.Action)) { // We got the location data location = Settings.HomeData; loaded = false; } } else if (WearableHelper.ErrorPath.Equals(intent?.Action)) { // An error occurred; cancel the sync operation await CancelDataSync(); } else if (WearableHelper.IsSetupPath.Equals(intent?.Action)) { if (Settings.DataSync != WearableDataSync.Off) { bool isDeviceSetup = intent.GetBooleanExtra(WearableDataListenerService.EXTRA_DEVICESETUPSTATUS, false); var connStatus = (WearConnectionStatus)intent.GetIntExtra(WearableDataListenerService.EXTRA_CONNECTIONSTATUS, 0); if (isDeviceSetup && connStatus == WearConnectionStatus.Connected) { // Device is setup and connected; proceed with sync Activity?.StartService(new Intent(Activity, typeof(WearableDataListenerService)) .SetAction(WearableDataListenerService.ACTION_REQUESTLOCATIONUPDATE)); Activity?.StartService(new Intent(Activity, typeof(WearableDataListenerService)) .SetAction(WearableDataListenerService.ACTION_REQUESTWEATHERUPDATE)); ResetTimer(); } else { // Device is not connected; cancel sync await CancelDataSync(); } } } }; loaded = true; }
/// <summary> /// Start listen to location update / gather device location. /// </summary> private void StartLocationUpdate() { InvokeOnMainThread(async() => { // Don't start another location manager if there is one already running if (FusedLocationClient == null || LocationManager == null) { var isRequestLocationSuccessful = false; var isLastKnownLocationUseable = false; // Check permission if (IsPermissionGrantedImpl()) { // Check if Google Play service is available, if it is available, then we can only use fused location service if (IsGooglePlayLocationAvailableAndEnabled()) { try { FusedLocationClient = LocationServices.GetFusedLocationProviderClient(Application.Context); if (FusedLocationClient != null) { // Try get the last known location or current device location if (!UpdateLocation(await FusedLocationClient.GetLastLocationAsync())) { // Then request the location update var locationRequest = new LocationRequest() .SetPriority(LocationRequest.PriorityHighAccuracy) .SetInterval(5000) // Google document mention 5 seconds .SetFastestInterval(0); FusedLocationCallback = new LocationCallback(); FusedLocationCallback.LocationResult += FusedLocationCallback_LocationResult; await FusedLocationClient.RequestLocationUpdatesAsync(locationRequest, FusedLocationCallback); } else { // No need to get next provider for location since we already have the location isLastKnownLocationUseable = true; } isRequestLocationSuccessful = true; } } catch { // Ignore all error including lack of permission or provider is not enabled } } // In some event that Google Play service is not available or not ready, fall back to Android location instead // Acquire a reference to the system Location Manager if (!isLastKnownLocationUseable) { LocationManager = (LocationManager)Application.Context.GetSystemService(Context.LocationService); if (LocationManager != null && LocationManager.AllProviders != null) { // Get location from all provider to increase the chances of getting a location foreach (var provider in LocationManager.AllProviders) { try { // Try get the last known location or current device location if (!UpdateLocation(LocationManager.GetLastKnownLocation(provider))) { // Then request the location update LocationManager.RequestLocationUpdates(provider, 0, 0f, this); isRequestLocationSuccessful = true; } else { // No need to get next provider for location since we already have the location isRequestLocationSuccessful = true; isLastKnownLocationUseable = true; break; } } catch { // Ignore all error including lack of permission or provider is not enabled } } } } } // Stop location service if initialized failed or we already have the location if (!isRequestLocationSuccessful) { StopLocationUpdate(GeolocationStatus.SetupError); } else if (isLastKnownLocationUseable) { StopLocationUpdate(GeolocationStatus.Successful); } } }); }
public void CreateLocationCallback() { mLocationCallback = new LocationCallbackClass { Activity = this }; }
private void BuildLocationCallBack() { locationCallback = new DriverLocationCallBack(this); }
void LocationCallBack() { LocationCallback1 = new MyLocationCallBack(this); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.activity_setup); cts = new CancellationTokenSource(); wm = WeatherData.WeatherManager.GetInstance(); // Set default API to HERE // if a valid API key hasn't been entered yet if (wm.KeyRequired && !Settings.KeyVerified) { Settings.API = WeatherData.WeatherAPI.Here; wm.UpdateAPI(); if (String.IsNullOrWhiteSpace(wm.GetAPIKey())) { // If (internal) key doesn't exist, fallback to Yahoo Settings.API = WeatherData.WeatherAPI.Yahoo; wm.UpdateAPI(); Settings.UsePersonalKey = true; Settings.KeyVerified = false; } else { // If key exists, go ahead Settings.UsePersonalKey = false; Settings.KeyVerified = true; } } // Controls searchButton = FindViewById <FloatingActionButton>(Resource.Id.search_button); searchButton.Click += (sender, e) => { FragmentManager.BeginTransaction() .Replace(Resource.Id.search_fragment_container, new LocationSearchFragment()) .Commit(); mWearableActionDrawer.Controller.CloseDrawer(); }; locationButton = FindViewById <FloatingActionButton>(Resource.Id.location_button); locationButton.Click += async(sender, e) => { await FetchGeoLocation(); }; mWearableActionDrawer = FindViewById <WearableActionDrawerView>(Resource.Id.bottom_action_drawer); mWearableActionDrawer.SetOnMenuItemClickListener(this); mWearableActionDrawer.LockedWhenClosed = true; mWearableActionDrawer.Controller.PeekDrawer(); progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar); progressBar.Visibility = ViewStates.Gone; // Location client if (WearableHelper.IsGooglePlayServicesInstalled && !WearableHelper.HasGPS) { mFusedLocationClient = new FusedLocationProviderClient(this); mLocCallback = new LocationCallback(); mLocCallback.LocationResult += async(sender, e) => { if (e.Result == null) { mLocation = null; } else { mLocation = e.Result.LastLocation; } if (mLocation == null) { EnableControls(true); Toast.MakeText(this, Resource.String.error_retrieve_location, ToastLength.Short).Show(); } else { await FetchGeoLocation(); } await mFusedLocationClient.RemoveLocationUpdatesAsync(mLocCallback); }; mLocCallback.LocationAvailability += async(sender, e) => { await mFusedLocationClient.FlushLocationsAsync(); if (!e.Availability.IsLocationAvailable) { EnableControls(true); Toast.MakeText(this, Resource.String.error_retrieve_location, ToastLength.Short).Show(); } }; } else { mLocListnr = new Droid.Helpers.LocationListener(); mLocListnr.LocationChanged += async(Location location) => { mLocation = location; await FetchGeoLocation(); }; } }
public LocCallSettOnSuccessListenerImpl(FusedLocationProviderClient fusedLocationProviderClient, LocationRequest locationRequest, LocationCallback locationCallback) { mFusedLocationProviderClient = fusedLocationProviderClient; mLocationRequest = locationRequest; mLocationCallback = locationCallback; }