private void btnNextQuestion_Click (object sender, EventArgs e) { Dismiss (); if (currentQuestion <= (QuestionAnswer.questionList.Count-1)) { Bundle msg = new Bundle (); msg.PutInt ("currentQuestion", currentQuestion + 1); msg.PutBoolean ("anwser", QuestionAnswer.answerList[currentQuestion]); FragmentTransaction transaction = FragmentManager.BeginTransaction (); dialog_Signup signUpDialog = new dialog_Signup (); signUpDialog.Arguments = msg; signUpDialog.Cancelable = false; signUpDialog.Show (transaction, "dialog fragment"); } }
private async void ClickFunction() { //get imei var telephonyManager = (TelephonyManager) GetSystemService(TelephonyService); string imei = telephonyManager.DeviceId; //if no imei use androidid if (String.IsNullOrEmpty (imei)) { imei = Settings.Secure.GetString (ContentResolver,Settings.Secure.AndroidId); } Console.Error.WriteLine ("imei:"+imei); //if imei not empty proceed if (!String.IsNullOrEmpty (imei)) { try { var json_validateEventCode = await Task.Factory.StartNew (() => Webservice.ws_validateEventCode (et_eventCode.Text, imei, uid)); Webservice.validateEventCode data = JsonConvert.DeserializeObject<Webservice.validateEventCode> (json_validateEventCode); //hide loading and show send button pb.Visibility = ViewStates.Invisible; btn_send.Visibility = ViewStates.Visible; if (data.success == 1) { //disable button to prevent double click RunOnUiThread (() => { btn_send.Enabled = false; }); //database save quizdata QuizDB quizDB = new QuizDB (); quizDB.completion_Stat = 0; quizDB.event_Code = event_code; quizDB.user_id = uid; quizDB.event_Id = data.event_id; try { DB_access.saveData (quizDB); } catch { } //loop and store question and answer into list foreach (var temp in data.quizs) { if (temp.answer == 0) { QuestionAnswer.answerList.Add (false); } else { QuestionAnswer.answerList.Add (true); } QuestionAnswer.questionList.Add (temp.question); } //bundle to be sent for question fragment Bundle msg = new Bundle (); msg.PutInt ("currentQuestion", 1); msg.PutBoolean ("anwser", QuestionAnswer.answerList [0]); msg.PutString ("user_id", uid); msg.PutInt ("event_id", data.event_id); msg.PutString ("imei", imei); FragmentTransaction transaction = FragmentManager.BeginTransaction (); dialog_Signup signUpDialog = new dialog_Signup (); signUpDialog.Arguments = msg; signUpDialog.Cancelable = false; signUpDialog.Show (transaction, "dialog fragment"); } else if (data.success == 0) { Snackbar snackbar = Snackbar .Make (btn_send, "Kod penyertaan salah. Sila semak semula.", Snackbar.LengthLong) .SetAction ("OK", delegate { }); View snackbarView = snackbar.View; TextView tv = (TextView)snackbarView.FindViewById (Resource.Id.snackbar_text); tv.SetTextColor (Color.White); snackbar.Show (); } else if (data.success == 3) { AlertDialog.Builder alert = new AlertDialog.Builder (this); alert.SetTitle ("Quiz telah ditutup!"); alert.SetCancelable (false); alert.SetPositiveButton ("OK", (senderAlert, args) => { Finish (); }); RunOnUiThread (() => { alert.Show (); }); } else if (data.success == 2) { Snackbar snackbar = Snackbar .Make (btn_send, "Hanya satu penyertaan bagi setiap akaun/gajet", Snackbar.LengthLong) .SetAction ("OK", delegate { }); View snackbarView = snackbar.View; TextView tv = (TextView)snackbarView.FindViewById (Resource.Id.snackbar_text); tv.SetTextColor (Color.White); snackbar.Show (); } } catch (Exception ex) { Console.Error.WriteLine ("ex" + ex); AlertDialog.Builder alert = new AlertDialog.Builder (this); alert.SetTitle ("Ralat! Sila cuba sebentar lagi. "); alert.SetCancelable (false); alert.SetPositiveButton ("OK", (senderAlert, args) => { }); RunOnUiThread (() => { alert.Show (); }); //hide loading and show send button pb.Visibility = ViewStates.Invisible; btn_send.Visibility = ViewStates.Visible; } } else { //if no imei/android,cannot proceed Snackbar snackbar = Snackbar .Make (btn_send, "Ralat! Gajet anda tiada imei/androidid", Snackbar.LengthLong) .SetAction ("OK", delegate { }); View snackbarView = snackbar.View; TextView tv = (TextView)snackbarView.FindViewById (Resource.Id.snackbar_text); tv.SetTextColor (Color.White); snackbar.Show (); } }