// RackConfig handler /// <summary> /// Save RackConfig in Application SharedPreferences /// </summary> /// <param name="config"></param> public static void SaveConfig(RackConfig config) { var MyRackConfig = Application.Context.GetSharedPreferences("MyRackConfig", FileCreationMode.Private); var MyRackConfigEdit = MyRackConfig.Edit(); MyRackConfigEdit.PutString("Width", Convert.ToString(config.GetWidth())); MyRackConfigEdit.PutString("LayersCount", Convert.ToString(config.GetLayersCount())); MyRackConfigEdit.PutString("LayersInfo", config.GetLayersInfo()); MyRackConfigEdit.Apply(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Create your application here SetContentView(Resource.Layout.Options); //fill view object; buttonSave = FindViewById <Button>(Resource.Id.buttonSave); buttonCancel = FindViewById <Button>(Resource.Id.buttonCancel); buttonIp = FindViewById <Button>(Resource.Id.buttonIp); editTextWidth = FindViewById <EditText>(Resource.Id.editTextWidth); textViewLayersValue = FindViewById <TextView>(Resource.Id.textViewLayersValue); buttonPlus = FindViewById <Button>(Resource.Id.buttonPlus); buttonMin = FindViewById <Button>(Resource.Id.buttonMin); listViewConfigure = FindViewById <ListView>(Resource.Id.listViewConfigure); config = DataHandler.GetConfig(); if (config == null) { config = new RackConfig(0, 1, "0:"); //|6:Bier|3:S } //set start point view editTextWidth.Text = Convert.ToString(config.GetWidth()); textViewLayersValue.Text = Convert.ToString(config.GetLayersCount()); UpdateListViewConfig(); //change the amount of Width editTextWidth.TextChanged += (slender, e) => { string widthText = editTextWidth.Text; if (widthText != "") { config.SetWidth(Convert.ToInt32(widthText)); } }; //change the amount of Layers buttonPlus.Click += (slender, e) => { int LayersCount = config.GetLayersCount(); if (LayersCount < 99) { LayersCount++; config.SetLayersCount(LayersCount); UpdateTextViewLayersCount(LayersCount); config.Layers.Add(new Layer(0, "")); //update list view UpdateListViewConfig(); } }; buttonMin.Click += (slender, e) => { int LayersCount = config.GetLayersCount(); if (LayersCount > 1) { LayersCount--; config.SetLayersCount(LayersCount); UpdateTextViewLayersCount(LayersCount); config.Layers.RemoveAt(LayersCount); //update list view UpdateListViewConfig(); } }; //save the new config if correct and complete buttonSave.Click += (slender, e) => { //check if the current config data complete and valid is, //else show a toast with fail message if (CheckNewConfig()) { //overwrite the config and empty the currently saved data DataHandler.SaveConfig(config); DataHandler.ResetData(); //go back to main activity Intent newActivityMain = new Intent(this, typeof(MainActivity)); StartActivity(newActivityMain); } }; //cancel by going back to main and saving nothing (the original config will be unchanged) buttonCancel.Click += (slender, e) => { GoBackToMain(); }; //go to change ip activity buttonIp.Click += (sender, e) => { if (!warning_saveconfig_first) { warning_saveconfig_first = true; Toast.MakeText(this, "Make sure that the changes to the config are saved before going to conection configere", ToastLength.Long).Show(); } else { GoToIp(); } }; }