protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); string dbPath; List <TideDB> tides; List <String> tidelist = new List <String>(); Tides newtide = new Tides(); // Check for database and create object dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TidesDB.s3db"); if (!File.Exists(dbPath)) { using (Stream inStream = Assets.Open("TidesDB.s3db")) using (Stream outStream = File.Create(dbPath)) inStream.CopyTo(outStream); } TideDbAccess tideDb = new TideDbAccess(dbPath); WsDbAccess wsDb = new WsDbAccess(dbPath); TideRest tideRest = new TideRest(); string inputLocation = Intent.GetStringExtra("Location"); string inputDate = Intent.GetStringExtra("Date"); tides = tideDb.RetrieveTide(inputLocation, inputDate); if (tides.Count <= 0) { //loading from web service if we didn't get any entries string location = wsDb.GetId(inputLocation).Id.ToString(); var tidedata = tideRest.GetTide(location, inputDate.Replace("/", string.Empty)); List <Tides> tlist = tideRest.XmlToTide(tidedata, inputLocation); foreach (Tides t in tlist) { //saving to db tideDb.AddEntry(t); } //now we'll reload the database so we have one with valid values and resume as normal tideDb = new TideDbAccess(dbPath); tides = tideDb.RetrieveTide(inputLocation, inputDate); } foreach (TideDB tide in tides) { tidelist.Add(tide.Day + ", " + tide.Date + " at " + tide.Time + System.Environment.NewLine + tide.HL + " tide of " + tide.Cen); } ListAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, tidelist); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); string dbPath; List <string> spinList = new List <string>(); string spinSelected = ""; // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); //move db from assets to file system dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TidesDB.s3db"); if (!File.Exists(dbPath)) { using (Stream inStream = Assets.Open("TidesDB.s3db")) using (Stream outStream = File.Create(dbPath)) inStream.CopyTo(outStream); } //create object from db layer for population WsDbAccess weatherStation = new WsDbAccess(dbPath); /////creating tables in database incase they do not exist on device //weatherStation.Create(); //TideDbAccess tdba = new TideDbAccess(dbPath); //tdba.Create(); //place locales from db into spinner value list and update spinner with values foreach (WeatherStation ws in weatherStation.GetStations()) { spinList.Add(ws.Name); if (spinSelected == "") { spinSelected = ws.Name; } } Spinner spinner = FindViewById <Spinner>(Resource.Id.SpinSelect); var spinCont = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleSpinnerItem, spinList); spinCont.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); spinner.Adapter = spinCont; //store selected item selected spinner.ItemSelected += (sender, e) => { spinSelected = spinner.GetItemAtPosition(e.Position).ToString(); }; //datepicker var datePicker = FindViewById <DatePicker>(Resource.Id.datePick); //do it to it!! var button = FindViewById <Button>(Resource.Id.submit); button.Click += delegate { var go = new Android.Content.Intent(this, typeof(TideList)); go.PutExtra("Location", spinSelected); go.PutExtra("Date", datePicker.DateTime.ToString("yyyy/MM/dd")); StartActivity(go); }; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); string dbPath; List <TideDB> tides; List <String> tidelist = new List <String>(); Tides newtide = new Tides(); // Check for database and create object dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TidesDB.s3db"); if (!File.Exists(dbPath)) { using (Stream inStream = Assets.Open("TidesDB.s3db")) using (Stream outStream = File.Create(dbPath)) inStream.CopyTo(outStream); } TideDbAccess tideDb = new TideDbAccess(dbPath); WsDbAccess wsDb = new WsDbAccess(dbPath); TideRest tideRest = new TideRest(); Location startLoc = new Location("Current"); Location endLoc = new Location("Station"); List <WeatherStation> stationlist = new List <WeatherStation>(); float distance = 10000000000; string inputLocation = "none"; stationlist = wsDb.GetStationData(); String inputDate = new SimpleDateFormat("yyyy/MM/dd").Format(new Date()); var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; //string inputLocation = Intent.GetStringExtra("Location"); //string inputDate = Intent.GetStringExtra("Date"); // GetPositionAsynch will either get position information or timeout locator.GetPositionAsync(timeoutMilliseconds: 10000) // After getting position info or timing out, execution will continue here // t represents a Task object (GetPositionAsync returns a Task object) .ContinueWith(t => { // t.Result is a Position object startLoc.Latitude = t.Result.Latitude; startLoc.Longitude = t.Result.Longitude; // Specify the thread to continue on- it's the UI thread foreach (WeatherStation station in stationlist) { endLoc = new Location("Station"); endLoc.Longitude = station.Lon; endLoc.Latitude = station.Lat; if (startLoc.DistanceTo(endLoc) < distance) { distance = startLoc.DistanceTo(endLoc); inputLocation = station.Name; } } tides = tideDb.RetrieveTide(inputLocation, inputDate); if (tides.Count <= 0) { //loading from web service if we didn't get any entries string location = wsDb.GetId(inputLocation).Id.ToString(); var tidedata = tideRest.GetTide(location, inputDate.Replace("/", string.Empty)); List <Tides> tlist = tideRest.XmlToTide(tidedata, inputLocation); foreach (Tides ti in tlist) { //saving to db tideDb.AddEntry(ti); } //now we'll reload the database so we have one with valid values and resume as normal tideDb = new TideDbAccess(dbPath); tides = tideDb.RetrieveTide(inputLocation, inputDate); } tidelist.Add("Tides For " + inputLocation); foreach (TideDB tide in tides) { tidelist.Add(tide.Day + ", " + tide.Date + " at " + tide.Time + System.Environment.NewLine + tide.HL + " tide of " + tide.Cen); } ListAdapter = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, tidelist); }, TaskScheduler.FromCurrentSynchronizationContext()); }