private void RegisterBtn_Click(object sender, EventArgs e) { EditText emailTxt = FindViewById <EditText>(Resource.Id.emailTxt); EditText passwordTxt = FindViewById <EditText>(Resource.Id.passwordTxt); EditText confirmPasswordTxt = FindViewById <EditText>(Resource.Id.confirmPasswordTxt); RadioButton rdo1 = FindViewById <RadioButton>(Resource.Id.RescuerRdo); RadioButton rdo2 = FindViewById <RadioButton>(Resource.Id.VictimRdo); var model = new RegisterViewModel { Email = emailTxt.Text, Password = passwordTxt.Text, ConfirmPassword = confirmPasswordTxt.Text, Role = rdo1.Checked? "admin" : "user" }; var result = ApiCallService.CreateRequest(model, Constants.ApiUrl + "user/register"); using (var reader = new StreamReader(result.GetResponseStream())) { string responseStr = reader.ReadToEnd(); var user = JsonConvert.DeserializeObject <UserModel>(responseStr); Context mContext = Application.Context; AppPreferences ap = new AppPreferences(mContext); //string key = "123123"; ap.saveUserIdKey(user.Id.ToString()); StartActivity(typeof(MainActivity)); } }
private void LoginSbmit_Click(object sender, EventArgs e) { EditText emailTxt = FindViewById <EditText>(Resource.Id.emailTxt); EditText passwordTxt = FindViewById <EditText>(Resource.Id.passwordTxt); var userlogin = new LoginModel { Email = emailTxt.Text, Password = passwordTxt.Text }; //var response = ApiCallService.CreateRequest(userlogin, Constants.ApiUrl + "user/login"); var result = ApiCallService.CreateRequest(userlogin, Constants.ApiUrl + "user/login"); // Will block until the task is completed... //HttpWebResponse result = response.GetAwaiter().GetResult(); using (var reader = new StreamReader(result.GetResponseStream())) { //Stream responseStream = response.GetResponseStream(); //string responseStr = reader.ReadToEnd(); //Console.WriteLine(responseStr); ////return XmlUtils.Deserialize<TResponse>(reader); string responseStr = reader.ReadToEnd(); var user = JsonConvert.DeserializeObject <UserModel>(responseStr); Context mContext = Application.Context; AppPreferences ap = new AppPreferences(mContext); //string key = "123123"; ap.saveUserIdKey(user.Id.ToString()); StartActivity(typeof(MainActivity)); } }
private void BtnSubmitDistress_Click(object sender, EventArgs e) { _mContext = Android.App.Application.Context; _ap = new AppPreferences(_mContext); string key = _ap.getUserIdKey(); if (string.IsNullOrEmpty(key)) { Toast.MakeText(this.ApplicationContext, "Please login", ToastLength.Short).Show(); StartActivity(typeof(LoginActivity)); } var model = new DisasterLocationModel { UserId = new Guid(key), Lat = Convert.ToDecimal(pos.Latitude), Lng = Convert.ToDecimal(pos.Longitude), Description = txtDescription.Text, Status = DisasterLocationStatusEnum.Unresponded, DatePosted = DateTime.Now }; var result = ApiCallService.CreateRequest(model, Constants.ApiUrl + "disasterlocation/adddisaster"); using (var reader = new StreamReader(result.GetResponseStream())) { string responseStr = reader.ReadToEnd(); //var user = JsonConvert.DeserializeObject<UserModel>(responseStr); Toast.MakeText(this.ApplicationContext, "Distress sent", ToastLength.Short).Show(); StartActivity(typeof(DistressActivity)); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); _mContext = Android.App.Application.Context; _ap = new AppPreferences(_mContext); string key = _ap.getUserIdKey(); _loginNavButton = FindViewById <Button>(Resource.Id.loginNav); _registerNavButton = FindViewById <Button>(Resource.Id.registerNav); _newsNavButton = FindViewById <Button>(Resource.Id.newsNav); _mapNavButton = FindViewById <Button>(Resource.Id.mapNav); _logOutNavButton = FindViewById <Button>(Resource.Id.logoutNav); _distressNavButton = FindViewById <Button>(Resource.Id.distressNav); if (string.IsNullOrEmpty(key)) { _loginNavButton.Visibility = ViewStates.Visible; _registerNavButton.Visibility = ViewStates.Visible; _newsNavButton.Visibility = ViewStates.Gone; _mapNavButton.Visibility = ViewStates.Gone; _distressNavButton.Visibility = ViewStates.Gone; _logOutNavButton.Visibility = ViewStates.Gone; } else { _loginNavButton.Visibility = ViewStates.Gone; _registerNavButton.Visibility = ViewStates.Gone; _newsNavButton.Visibility = ViewStates.Visible; _mapNavButton.Visibility = ViewStates.Visible; _distressNavButton.Visibility = ViewStates.Visible; _logOutNavButton.Visibility = ViewStates.Visible; } _loginNavButton.Click += LoginNavButton_Click; _registerNavButton.Click += RegisterNavButton_Click; _newsNavButton.Click += NewsNavButton_Click; _mapNavButton.Click += MapNavButton_Click; _distressNavButton.Click += _distressNavButton_Click; _logOutNavButton.Click += LogOutNavButton_Click; }
private void PostSubmit_Click(object sender, EventArgs e) { EditText titleTxt = FindViewById <EditText>(Resource.Id.titleTxt); EditText messageTxt = FindViewById <EditText>(Resource.Id.messageTxt); Context mContext = Android.App.Application.Context; AppPreferences ap = new AppPreferences(mContext); string key = ap.getUserIdKey(); Guid userId = Guid.Empty; try { userId = new Guid(key); } catch (Exception) { Toast.MakeText(this.ApplicationContext, "Please login", ToastLength.Short).Show(); } var model = new NewsModel { UserId = userId, Title = titleTxt.Text, Message = messageTxt.Text, DatePosted = DateTime.Now }; var result = ApiCallService.CreateRequest(model, Constants.ApiUrl + "news/postnews"); using (var reader = new StreamReader(result.GetResponseStream())) { string responseStr = reader.ReadToEnd(); if (responseStr == String.Empty) { Toast.MakeText(this.ApplicationContext, "Post failed!", ToastLength.Short).Show(); } else { Toast.MakeText(this.ApplicationContext, "Post success!", ToastLength.Short).Show(); StartActivity(typeof(NewsActivity)); } } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Distress); // Create your application here _mContext = Android.App.Application.Context; _ap = new AppPreferences(_mContext); _userId = _ap.getUserIdKey(); _disressListView = FindViewById <ListView>(Resource.Id.disressListView); _disressListView.ChoiceMode = ChoiceMode.Single; _disressListView.Adapter = new DistressAdapter(this, GetDistress()); RegisterForContextMenu(_disressListView); _disressListView.ItemClick += DisressListView_ItemClick; _btnAllDistress = FindViewById <Button>(Resource.Id.btnAllDistress); _btnMyResponse = FindViewById <Button>(Resource.Id.btnMyResponse); _btnAllDistress.Click += _btnAllDistress_Click; _btnMyResponse.Click += _btnMyResponse_Click; }
protected override void OnStop() { AppPreferences ap = new AppPreferences(mContext); ap.saveAccessKey(spinner_mode.SelectedItemPosition); base.OnStop(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById<Button>(Resource.Id.MyButton); var label = FindViewById<TextView>(Resource.Id.tv1); button.Click += delegate { count++; label.Text = $"你點擊了 {count} 次"; //button.Text = string.Format("{0} clicks!", count++); }; ad = FindViewById<ImageView>(Resource.Id.AD); ad.SetImageResource(Resource.Drawable.pikachu); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.DefaultAdapter; // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { Toast.MakeText(this, "Bluetooth is not available", ToastLength.Long).Show(); Finish(); return; } //---------------------SPINNER------------------------------- spinner_mode = FindViewById<Spinner>(Resource.Id.spinner1); AppPreferences ap = new AppPreferences(mContext); int spinnerPos = ap.getAccessKey(); spinner_mode.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected); var adapter = ArrayAdapter.CreateFromResource( this, Resource.Array.Connect_Mode_Array, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); spinner_mode.Adapter = adapter; if (spinner_mode != null) { spinner_mode.SetSelection(ap.getAccessKey()); } }