protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.SpeedBetweenNodes); settingsFile = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); settingsFile = Path.Combine(settingsFile, "settings.txt"); settings = JsonConvert.DeserializeObject<SettingsRecord> (File.ReadLines (settingsFile).First()); speedSpinner = FindViewById<Spinner> (Resource.Id.speedSpinner); speedSpinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (speedSpinner_ItemSelected); var adapter = ArrayAdapter.CreateFromResource (this, Resource.Array.speed_array, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem); speedSpinner.Adapter = adapter; speedSpinner_Initialize (); btnApply = FindViewById<Button>(Resource.Id.btnApply2); btnApply.Click += delegate { if (settingsChanged()){ using (TextWriter tw = new StreamWriter(settingsFile,false)){ tw.WriteLine (JsonConvert.SerializeObject (settings)); } if(isLoggerRunning()){ restartLogger(); } } Finish(); }; }
private void CreateSettingsFile() { SettingsRecord settings = new SettingsRecord { useLocationLogging = true, timeBetweenUpdates = MINUTE * 4, timeBetweenUpdatesDense = MINUTE /2, speedLimit = 15 / 3.6 }; using (TextWriter tw = File.CreateText(settingsFile)){ tw.WriteLine (JsonConvert.SerializeObject (settings)); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.LocationUpdateDensity); settingsFile = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); settingsFile = Path.Combine(settingsFile, "settings.txt"); settings = JsonConvert.DeserializeObject<SettingsRecord> (File.ReadLines (settingsFile).First()); //ZA DEBUG ISPIS LOCATIONS FILEA XAMARINU //string locationsFile; //locationsFile = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); //locationsFile = Path.Combine(locationsFile, "locations.txt"); //foreach (string location in File.ReadLines(locationsFile)) { // Console.WriteLine (location); //} //ZAKOMENTIRATI toggleButton = FindViewById<Button>(Resource.Id.btnUseLogging); toggleButton.Text = isLoggerRunning ()?"Zapisivanje lokacija je uključeno":"Zapisivanje lokacija je isključeno"; toggleButton.Click += delegate { if (toggleButton.Text == "Zapisivanje lokacija je isključeno"){ //pokreni snimanje lokaija ako već nije i updateaj settings file if(!isLoggerRunning()) StartService (new Intent (this, typeof(LocationLogger))); SettingsRecord currentSettings = JsonConvert.DeserializeObject<SettingsRecord> (File.ReadLines (settingsFile).First()); currentSettings.useLocationLogging = true; using (TextWriter tw = new StreamWriter(settingsFile,false)){ tw.WriteLine (JsonConvert.SerializeObject (currentSettings)); } toggleButton.Text = "Zapisivanje lokacija je uključeno"; } else { //zaustavi pozadinsko zapisivanje i updateaj settings file StopService (new Intent (this, typeof(LocationLogger))); SettingsRecord currentSettings = JsonConvert.DeserializeObject<SettingsRecord> (File.ReadLines (settingsFile).First()); currentSettings.useLocationLogging = false; using (TextWriter tw = new StreamWriter(settingsFile,false)){ tw.WriteLine (JsonConvert.SerializeObject (currentSettings)); } toggleButton.Text = "Zapisivanje lokacija je isključeno"; } }; normalSpinner = FindViewById<Spinner> (Resource.Id.normalSpinner); normalSpinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (normalSpinner_ItemSelected); var adapter = ArrayAdapter.CreateFromResource (this, Resource.Array.normal_density_array, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem); normalSpinner.Adapter = adapter; normalSpinner_Initialize (); denseSpinner = FindViewById<Spinner> (Resource.Id.denseSpinner); denseSpinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (denseSpinner_ItemSelected); adapter = ArrayAdapter.CreateFromResource (this, Resource.Array.high_density_array, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem); denseSpinner.Adapter = adapter; denseSpinner_Initialize (); btnApply = FindViewById<Button>(Resource.Id.btnApply1); btnApply.Click += delegate { if (settingsChanged()){ using (TextWriter tw = new StreamWriter(settingsFile,false)){ tw.WriteLine (JsonConvert.SerializeObject (settings)); } if(isLoggerRunning()){ restartLogger(); } } Finish(); }; }