/** * Add a Views containing the question text, audio (if applicable), and image (if applicable). To * satisfy the RelativeLayout constraints, we add the audio first if it exists, then the TextView * to fit the rest of the space, then the image if applicable. */ protected void addQuestionText(FormEntryPrompt p) { String imageURI = p.getImageText(); String audioURI = p.getAudioText(); String videoURI = p.getSpecialFormQuestionText("video"); // shown when image is clicked String bigImageURI = p.getSpecialFormQuestionText("big-image"); String promptText = p.getLongText(); // Add the text view. Textview always exists, regardless of whether there's text. mQuestionText = new TextView(getContext()); mQuestionText.setText(promptText == null ? "" : promptText); mQuestionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mQuestionFontsize); mQuestionText.setTypeface(null, Typeface.BOLD); mQuestionText.setPadding(0, 0, 0, 7); mQuestionText.setId(QuestionWidget.newUniqueId()); // assign random id // Wrap to the size of the parent view mQuestionText.setHorizontallyScrolling(false); if (promptText == null || promptText.length() == 0) { mQuestionText.setVisibility(GONE); } // Create the layout for audio, image, text mediaLayout = new MediaLayout(getContext()); mediaLayout.setAVT(p.getIndex(), "", mQuestionText, audioURI, imageURI, videoURI, bigImageURI); addView(mediaLayout, mLayout); }
public SelectOneWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); // SurveyCTO-added support for dynamic select content (from .csv files) XPathFuncExpr xPathFuncExpr = ExternalDataUtil.getSearchXPathExpression(prompt.getAppearanceHint()); if (xPathFuncExpr != null) { mItems = ExternalDataUtil.populateExternalChoices(prompt, xPathFuncExpr); } else { mItems = prompt.getSelectChoices(); } buttons = new ArrayList<RadioButton>(); // Layout holds the vertical list of buttons LinearLayout buttonLayout = new LinearLayout(context); String s = null; if (prompt.getAnswerValue() != null) { s = ((Selection) prompt.getAnswerValue().getValue()).getValue(); } if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { RadioButton r = new RadioButton(getContext()); r.setText(prompt.getSelectChoiceText(mItems.get(i))); r.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); r.setTag(Integer.valueOf(i)); r.setId(QuestionWidget.newUniqueId()); r.setEnabled(!prompt.isReadOnly()); r.setFocusable(!prompt.isReadOnly()); buttons.add(r); if (mItems.get(i).getValue().equals(s)) { r.setChecked(true); } r.setOnCheckedChangeListener(this); String audioURI = null; audioURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO); String imageURI; if (mItems.get(i) instanceof ExternalSelectChoice) { imageURI = ((ExternalSelectChoice) mItems.get(i)).getImage(); } else { imageURI = prompt.getSpecialFormSelectChoiceText( mItems.get(i), FormEntryCaption.TEXT_FORM_IMAGE); } String videoURI = null; videoURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "video"); String bigImageURI = null; bigImageURI = prompt.getSpecialFormSelectChoiceText(mItems.get(i), "big-image"); MediaLayout mediaLayout = new MediaLayout(getContext()); mediaLayout.setAVT( prompt.getIndex(), "." + Integer.toString(i), r, audioURI, imageURI, videoURI, bigImageURI); if (i != mItems.size() - 1) { // Last, add the dividing line (except for the last element) ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); mediaLayout.addDivider(divider); } buttonLayout.addView(mediaLayout); } } buttonLayout.setOrientation(LinearLayout.VERTICAL); // The buttons take up the right half of the screen LayoutParams buttonParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); addView(buttonLayout, buttonParams); }
public void playVideo() { mediaLayout.playVideo(); }
public void playAudio() { mediaLayout.playAudio(); }