public void showQuestionOnCard(Survey.Question question, String answerOrNull) throws UnrecognizedAnswerTypeException { mQuestion = question; mPromptView.setText(mQuestion.getPrompt()); final InputMethodManager inputMethodManager = (InputMethodManager) mCardView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); final Survey.QuestionType questionType = question.getType(); if (Survey.QuestionType.TEXT == questionType) { mChoiceView.setVisibility(View.GONE); mEditAnswerView.setVisibility(View.VISIBLE); if (null != answerOrNull) { mEditAnswerView.setText(answerOrNull); } else { mEditAnswerView.setText(""); } if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { mEditAnswerView.requestFocus(); inputMethodManager.showSoftInput(mEditAnswerView, 0); } else { // Landscape soft keyboard will obscure the question inputMethodManager.hideSoftInputFromWindow(mCardView.getWindowToken(), 0); } } else if (Survey.QuestionType.MULTIPLE_CHOICE == questionType) { inputMethodManager.hideSoftInputFromWindow(mCardView.getWindowToken(), 0); mChoiceView.setVisibility(View.VISIBLE); mEditAnswerView.setVisibility(View.GONE); final ChoiceAdapter answerAdapter = new ChoiceAdapter(question.getChoices(), LayoutInflater.from(getContext())); mChoiceView.setAdapter(answerAdapter); mChoiceView.clearChoices(); if (null != answerOrNull) { for (int i = 0; i < answerAdapter.getCount(); i++) { final String item = answerAdapter.getItem(i); if (item.equals(answerOrNull)) { mChoiceView.setItemChecked(i, true); } } } } else { throw new UnrecognizedAnswerTypeException( "No way to display question type " + questionType); } mCardView.invalidate(); }
private void showQuestion(int paramInt) { Object localObject = getSurveyState(); List localList = ((UpdateDisplayState.DisplayState.SurveyState)localObject).getSurvey().getQuestions(); label56: int i; Survey.Question localQuestion; if ((paramInt == 0) || (localList.size() == 0)) { this.mPreviousButton.setEnabled(false); if (paramInt < localList.size() - 1) { break label181; } this.mNextButton.setEnabled(false); i = this.mCurrentQuestion; this.mCurrentQuestion = paramInt; localQuestion = (Survey.Question)localList.get(paramInt); localObject = ((UpdateDisplayState.DisplayState.SurveyState)localObject).getAnswers().get(Integer.valueOf(localQuestion.getId())); if (i >= paramInt) { break label192; } } for (;;) { try { this.mCardHolder.moveTo(localQuestion, (String)localObject, CardCarouselLayout.Direction.FORWARD); if (localList.size() <= 1) { break label234; } this.mProgressTextView.setText("" + (paramInt + 1) + " of " + localList.size()); return; } catch (CardCarouselLayout.UnrecognizedAnswerTypeException localUnrecognizedAnswerTypeException) { label181: label192: goToNextQuestion(); return; } this.mPreviousButton.setEnabled(true); break; this.mNextButton.setEnabled(true); break label56; if (i > paramInt) { this.mCardHolder.moveTo(localQuestion, (String)localObject, CardCarouselLayout.Direction.BACKWARD); } else { this.mCardHolder.replaceTo(localQuestion, (String)localObject); } } label234: this.mProgressTextView.setText(""); }
private void saveAnswer(Survey.Question paramQuestion, String paramString) { getSurveyState().getAnswers().put(Integer.valueOf(paramQuestion.getId()), paramString.toString()); }