protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { if (requestCode == SETUP_REQUEST_CODE) { if (resultCode == Result.Ok) { // Get result data var dataJson = data?.GetStringExtra("data"); if (!String.IsNullOrWhiteSpace(dataJson)) { using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader( new System.IO.StringReader(dataJson))) { var locData = LocationData.FromJson(jsonTextReader); if (locData.locationType == LocationType.Search) { // Add location to adapter and select it Favorites = new ReadOnlyCollection <LocationData>(Favorites.Append(locData).ToList()); var item = new ComboBoxItem(locData.name, locData.query); var idx = locAdapter.Count - 1; locAdapter.Insert(item, idx); locSpinner.SetSelection(idx); } else { // GPS; set to first selection locSpinner.SetSelection(0); } } } } } }
public override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your fragment here if (location == null && savedInstanceState != null) { using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader( new System.IO.StringReader(savedInstanceState.GetString("data", null)))) { location = LocationData.FromJson(jsonTextReader); } } }
public static LocationData GetLocationData(int appWidgetId) { var prefs = GetPreferences(appWidgetId); var locDataJson = prefs.GetString(KEY_LOCATIONDATA, null); if (String.IsNullOrWhiteSpace(locDataJson)) { return(null); } else { using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader(new System.IO.StringReader(locDataJson))) { return(LocationData.FromJson(jsonTextReader)); } } }
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 (savedInstanceState != null) { BGAlpha = savedInstanceState.GetInt("alpha", 255); } mLocListnr = new 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); } }; loaded = true; }
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; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_main); // Create your application here Toolbar toolbar = FindViewById <Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); DrawerLayout drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); Android.Support.V7.App.ActionBarDrawerToggle toggle = new Android.Support.V7.App.ActionBarDrawerToggle( this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close); drawer.AddDrawerListener(toggle); toggle.SyncState(); NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view); navigationView.SetNavigationItemSelectedListener(this); // Back stack listener SupportFragmentManager.BackStackChanged += delegate { RefreshNavViewCheckedItem(); }; Fragment fragment = SupportFragmentManager.FindFragmentById(Resource.Id.fragment_container); // Alerts if (WeatherWidgetService.ACTION_SHOWALERTS.Equals(Intent?.Action)) { Fragment newFragment = WeatherNowFragment.NewInstance(Intent.Extras); if (fragment == null) { fragment = newFragment; // Navigate to WeatherNowFragment // Make sure we exit if location is not home SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.fragment_container, fragment, "notification") .Commit(); } else { // Navigate to WeatherNowFragment // Make sure we exit if location is not home SupportFragmentManager.BeginTransaction() .Add(Resource.Id.fragment_container, newFragment) .AddToBackStack(null) .Commit(); } } // Check if fragment exists if (fragment == null) { if (Intent.HasExtra("data")) { fragment = WeatherNowFragment.NewInstance(Intent.Extras); } else { fragment = new WeatherNowFragment(); } // Navigate to WeatherNowFragment SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.fragment_container, fragment, "home") .Commit(); } if ((bool)Intent?.HasExtra("shortcut-data")) { using (var jsonTextReader = new Newtonsoft.Json.JsonTextReader( new System.IO.StringReader(Intent.GetStringExtra("shortcut-data")))) { var locData = LocationData.FromJson(jsonTextReader); // Navigate to WeatherNowFragment Fragment newFragment = WeatherNowFragment.NewInstance(locData); SupportFragmentManager.BeginTransaction() .Replace(Resource.Id.fragment_container, newFragment, "shortcut") .Commit(); // Disable navigation toggle.DrawerIndicatorEnabled = false; drawer.SetDrawerLockMode(DrawerLayout.LockModeLockedClosed); } } navigationView.SetCheckedItem(Resource.Id.nav_weathernow); Task.Run(Shortcuts.ShortcutCreator.UpdateShortcuts); }
private static async Task Load() { // Create DB tables #if !__ANDROID_WEAR__ await locationDB.CreateTableAsync <LocationData>(); await locationDB.CreateTableAsync <Favorites>(); #endif await weatherDB.CreateTableAsync <Weather>(); await weatherDB.CreateTableAsync <WeatherAlerts>(); // Migrate old data if available if (GetDBVersion() < CurrentDBVersion) { #if !__ANDROID_WEAR__ switch (GetDBVersion()) { // Move data from json to db case 0: if (await locationDB.Table <LocationData>().CountAsync() == 0) { await DBUtils.MigrateDataJsonToDB(locationDB, weatherDB); } break; // Add and set tz_long column in db case 1: if (await locationDB.Table <LocationData>().CountAsync() > 0) { await DBUtils.SetLocationData(locationDB); } break; default: break; } #endif SetDBVersion(CurrentDBVersion); } #if !__ANDROID_WEAR__ if (!String.IsNullOrWhiteSpace(LastGPSLocation)) { try { using (var jsonTextReader = new JsonTextReader(new StringReader(LastGPSLocation))) { lastGPSLocData = LocationData.FromJson(jsonTextReader); } } catch (Exception ex) { Logger.WriteLine(LoggerLevel.Error, ex, "SimpleWeather: Settings.Load(): LastGPSLocation"); } finally { if (lastGPSLocData == null || String.IsNullOrWhiteSpace(lastGPSLocData.tz_long)) { lastGPSLocData = new LocationData(); } } } #else if (!String.IsNullOrWhiteSpace(LastGPSLocation)) { try { using (var jsonTextReader = new JsonTextReader(new StringReader(LastGPSLocation))) { lastGPSLocData = LocationData.FromJson(jsonTextReader); } } catch (Exception ex) { Logger.WriteLine(LoggerLevel.Error, ex, "SimpleWeather: Settings.Load(): LastGPSLocation"); } finally { if (lastGPSLocData == null || String.IsNullOrWhiteSpace(lastGPSLocData.tz_long)) { lastGPSLocData = new LocationData(); } } } #endif }