public ExPrinterWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.setMargins(7, 5, 7, 5); String appearance = prompt.getAppearanceHint(); String[] attrs = appearance.split(":"); final String intentName = (attrs.length < 2 || attrs[1].length() == 0) ? "org.opendatakit.sensors.ZebraPrinter" : attrs[1]; final String buttonText; final String errorString; String v = mPrompt.getSpecialFormQuestionText("buttonText"); buttonText = (v != null) ? v : context.getString(R.string.launch_printer); v = mPrompt.getSpecialFormQuestionText("noPrinterErrorString"); errorString = (v != null) ? v : context.getString(R.string.no_printer); // set button formatting mLaunchIntentButton = new Button(getContext()); mLaunchIntentButton.setId(QuestionWidget.newUniqueId()); mLaunchIntentButton.setText(buttonText); mLaunchIntentButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mLaunchIntentButton.setPadding(20, 20, 20, 20); mLaunchIntentButton.setLayoutParams(params); mLaunchIntentButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { try { Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex()); firePrintingActivity(intentName); } catch (ActivityNotFoundException e) { Collect.getInstance().getFormController().setIndexWaitingForData(null); Toast.makeText(getContext(), errorString, Toast.LENGTH_SHORT).show(); } } }); // finish complex layout addView(mLaunchIntentButton); }
public SelectOneAutoAdvanceWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); LayoutInflater inflater = LayoutInflater.from(getContext()); // 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>(); listener = (AdvanceToNextListener) context; String s = null; if (prompt.getAnswerValue() != null) { s = ((Selection) prompt.getAnswerValue().getValue()).getValue(); } // use this for recycle Bitmap b = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.expander_ic_right); if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { RelativeLayout thisParentLayout = (RelativeLayout) inflater.inflate(R.layout.quick_select_layout, null); LinearLayout questionLayout = (LinearLayout) thisParentLayout.getChildAt(0); ImageView rightArrow = (ImageView) thisParentLayout.getChildAt(1); 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()); rightArrow.setImageBitmap(b); 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(), "", 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); } questionLayout.addView(mediaLayout); addView(thisParentLayout); } } }
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); }
@SuppressWarnings("unchecked") public SelectMultiWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mPrompt = prompt; mCheckboxes = new ArrayList<CheckBox>(); // 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(); } setOrientation(LinearLayout.VERTICAL); Vector<Selection> ve = new Vector<Selection>(); if (prompt.getAnswerValue() != null) { ve = (Vector<Selection>) prompt.getAnswerValue().getValue(); } if (mItems != null) { for (int i = 0; i < mItems.size(); i++) { // no checkbox group so id by answer + offset CheckBox c = new CheckBox(getContext()); c.setTag(Integer.valueOf(i)); c.setId(QuestionWidget.newUniqueId()); c.setText(prompt.getSelectChoiceText(mItems.get(i))); c.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); c.setFocusable(!prompt.isReadOnly()); c.setEnabled(!prompt.isReadOnly()); for (int vi = 0; vi < ve.size(); vi++) { // match based on value, not key if (mItems.get(i).getValue().equals(ve.elementAt(vi).getValue())) { c.setChecked(true); break; } } mCheckboxes.add(c); // when clicked, check for readonly before toggling c.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (!mCheckboxInit && mPrompt.isReadOnly()) { if (buttonView.isChecked()) { buttonView.setChecked(false); Collect.getInstance() .getActivityLogger() .logInstanceAction( this, "onItemClick.deselect", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } else { buttonView.setChecked(true); Collect.getInstance() .getActivityLogger() .logInstanceAction( this, "onItemClick.select", mItems.get((Integer) buttonView.getTag()).getValue(), mPrompt.getIndex()); } } } }); 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), c, audioURI, imageURI, videoURI, bigImageURI); addView(mediaLayout); // Last, add the dividing line between elements (except for the last element) ImageView divider = new ImageView(getContext()); divider.setBackgroundResource(android.R.drawable.divider_horizontal_bright); if (i != mItems.size() - 1) { addView(divider); } } } mCheckboxInit = false; }
public GeoPointWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); mWaitingForData = false; mUseMaps = false; String appearance = prompt.getAppearanceHint(); if ("maps".equalsIgnoreCase(appearance)) { try { // use google maps it exists on the device Class.forName("com.google.android.maps.MapActivity"); mUseMaps = true; } catch (ClassNotFoundException e) { mUseMaps = false; } } setOrientation(LinearLayout.VERTICAL); mStringAnswer = new TextView(getContext()); mAnswerDisplay = new TextView(getContext()); mAnswerDisplay.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize); mAnswerDisplay.setGravity(Gravity.CENTER); Spannable locButtonText; boolean viewButtonEnabled; String s = prompt.getAnswerText(); if (s != null && !("".equals(s))) { setBinaryData(s); locButtonText = StringUtils.getStringSpannableRobust(getContext(), R.string.replace_location); viewButtonEnabled = true; } else { locButtonText = StringUtils.getStringSpannableRobust(getContext(), R.string.get_location); viewButtonEnabled = false; } mGetLocationButton = new Button(getContext()); WidgetUtils.setupButton( mGetLocationButton, locButtonText, mAnswerFontsize, !prompt.isReadOnly()); mGetLocationButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { Intent i; if (mUseMaps) { i = new Intent(getContext(), GeoPointMapActivity.class); } else { i = new Intent(getContext(), GeoPointActivity.class); } ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.LOCATION_CAPTURE); mWaitingForData = true; } }); // setup 'view location' button mViewButton = new Button(getContext()); WidgetUtils.setupButton( mViewButton, StringUtils.getStringSpannableRobust(getContext(), R.string.show_location), mAnswerFontsize, viewButtonEnabled); // launch appropriate map viewer mViewButton.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { String s = mStringAnswer.getText().toString(); String[] sa = s.split(" "); double gp[] = new double[4]; gp[0] = Double.valueOf(sa[0]); gp[1] = Double.valueOf(sa[1]); gp[2] = Double.valueOf(sa[2]); gp[3] = Double.valueOf(sa[3]); Intent i = new Intent(getContext(), GeoPointMapActivity.class); i.putExtra(LOCATION, gp); getContext().startActivity(i); } }); addView(mGetLocationButton); if (mUseMaps) { addView(mViewButton); } addView(mAnswerDisplay); }