Example #1
0
        public override View OnCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle)
        {
            View         view         = layoutInflater.Inflate(Resource.Layout.fragment_onechoice_questionario, viewGroup, false);
            TextView     textView     = view.FindViewById <TextView>(Resource.Id.title_text_view);
            RadioGroup   radioGroup   = view.FindViewById <RadioGroup>(Resource.Id.options_group);
            LinearLayout linearLayout = view.FindViewById <LinearLayout>(Resource.Id.options_layout);

            textView.Text     = _questao.getTitulo();
            textView.Selected = true;
            int             respostaSelected = QuestionarioManager.GetInstance().LastRespostaSelected(_page);
            List <Resposta> respostas        = _questao.Respostas;


            for (int i = 0; i < _questao.Respostas.Count; i++)
            {
                int id = i;
                QuestionarioWidgetGenerator.CreateRadioButton(radioGroup, _page, id, respostas[i].Descricao, respostaSelected == id);
            }

            LinearLayout          layout = view.FindViewById <LinearLayout>(Resource.Id.root_options_layout);
            EditNewRespostaLayout editNewRespostaLayout = new EditNewRespostaLayout(view.Context);
            LayoutParams          lparams = new LayoutParams(-1, -2);

            lparams.SetMargins(14, 0, 0, 0);

            layout.AddView(editNewRespostaLayout, lparams);

            return(view);
        }
        private void OpenFinishSurveyActivity()
        {
            QuestionarioManager questionaryManager = QuestionarioManager.GetInstance();

            questionaryManager.FinishQuestionario(DateTime.Now.Ticks);
            //Location location = getLastBestLocation();
            //if (location != null)
            //{
            //    questionaryManager.updateGpsPosition(location.getLatitude(), location.getLongitude());
            //}
            //questionaryManager.updateBatteryPct(getBatteryPct());
            try
            {
                //SurveyDataSource surveyDataSource = new SurveyDataSource(this);
                //surveyDataSource.open();
                //surveyDataSource.add(questionaryManager.generateEntity(this.survey.getId()));
                //surveyDataSource.close();
                //startActivityForResult(new Intent(this, FinishSurveyActivity.class), SURVEY_ACTIVITY_REQUEST);
            }
            catch (Exception e)
            {
                Log.Error(TAG, "N\u00e3o foi poss\u00edvel salvar a pesquisa.", e);
                Toast.MakeText(this, "Erro ao salvar a pesquisa. Contacte o suporte.", 0).Show();
            }
        }
        public void NextPage(View view)
        {
            int current = _viewPager.CurrentItem;

            if (!QuestionarioManager.GetInstance().ProceedToNext(current))
            {
                Toast.MakeText(this, "Escolha pelo menos uma op\u00e7\u00e3o.", 0).Show();
            }
            else if (current >= _numberPages - 1)
            {
                OpenFinishSurveyActivity();
            }
            else if (current < _viewPager.Adapter.Count)
            {
                int           nextPage = current + SURVEY_ACTIVITY_REQUEST;
                List <Logica> logica   = _questionario[0].Logica;
                if (logica != null && logica.Count > 0)
                {
                    nextPage = QuestionarioManager.GetInstance().NextPage(current, logica);
                }
                if (nextPage == int.MaxValue)
                {
                    OpenFinishSurveyActivity();
                }
                else if (nextPage != -1)
                {
                    _backwardStack.Push(current);
                    _viewPager.SetCurrentItem(nextPage, _questionario[0].Fluxo.PassarAutomatico);
                    _currentPage          = nextPage;
                    _progressBar.Progress = nextPage + SURVEY_ACTIVITY_REQUEST;
                    _progressText.Text    = ("Perg. " + (nextPage + SURVEY_ACTIVITY_REQUEST) + " de " + _numberPages);
                    UpdateFooterBar();
                }
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.activity_questionario);
            TAG = Application.PackageName.ToString();
            try
            {
                QuestionarioManager questionarioManager = QuestionarioManager.GetInstance();
                questionarioManager.SetQuestionarioActivity(this);
                string json = "";

                AssetManager assets = this.Assets;
                using (StreamReader sr = new StreamReader(assets.Open("Questionario.json")))
                {
                    json = sr.ReadToEnd();
                }

                var questionario = JsonConvert.DeserializeObject <List <Questionario> >(json);

                if (bundle != null)
                {
                    //_questionario = (Questionario)bundle.GetSerializable("questionario");
                    _questionario  = questionario;//JsonConvert.DeserializeObject<List<Questionario>>(bundle.GetSerializable("questionario").ToString());
                    _numberPages   = bundle.GetInt("numberPages");
                    _currentPage   = bundle.GetInt("currentPage");
                    _backwardStack = (Stack <int>)bundle.GetSerializable("backwardStack");
                }
                else
                {
                    //_questionario = (Questionario)_intent.GetSerializableExtra("questionario");
                    _questionario  = questionario;//JsonConvert.DeserializeObject<List<Questionario>>(_intent.GetSerializableExtra("questionario").ToString());
                    _numberPages   = _questionario[0].Questoes.Count;
                    _currentPage   = _numberPages > 0 ? 0 : -1;
                    _backwardStack = new Stack <int>();
                    questionarioManager.SetStartQuestionario(DateTime.Now.Ticks);
                }

                SetupToolBar(_questionario[0].Descricao);
                Init();
                SetupFooterBar();
                UpdateFooterBar();
            }
            catch (Exception e)
            {
                Log.Error(TAG, e.Message, e);
                Toast.MakeText(Application.Context, Resource.String.cannot_load_survey_msg, 0).Show();
                Finish();
            }
        }
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            //base.OnActivityResult(requestCode, resultCode, data);

            if (requestCode == SURVEY_ACTIVITY_REQUEST && resultCode.HasFlag(Result.FirstUser) && data.HasExtra("reloadQuestionario"))
            {
                QuestionarioManager.GetInstance().Clear();
                if (data.GetBooleanExtra("reloadQuestionario", false))
                {
                    Finish();
                    return;
                }
                SetResult(Result.Ok);
                Finish();
            }
        }
Example #6
0
        public static RadioButton CreateRadioButton(RadioGroup radioGroup, int page, int id, string text, bool flag)
        {
            RadioButton radioButton = new RadioButton(radioGroup.Context);

            radioButton.Id       = id;
            radioButton.Text     = text;
            radioButton.TextSize = 18;
            radioButton.Checked  = flag;
            //radioButton.SetOnClickListener(new View.IOnClickListener() { });
            radioButton.Click += (sender, e) =>
            {
                View v = (View)sender;
                QuestionarioManager.GetInstance().UpdateFirstRespostaSelected(page, v.Id);
            };

            if (flag)
            {
                radioButton.Checked = true;
            }

            radioGroup.AddView(radioButton, -2, -2);
            return(radioButton);
        }