コード例 #1
0
  /** Add a TextView containing the hierarchy of groups to which the question belongs. */
  private void AddGroupText(PromptElement p) {
    StringBuffer s = new StringBuffer("");
    String t = "";
    int i;

    // list all groups in one string
    for (GroupElement g : p.getGroups()) {
      i = g.getRepeatCount() + 1;
      t = g.getGroupText();
      if (t != null) {
        s.append(t);
        if (g.isRepeat() && i > 0) {
          s.append(" (" + i + ")");
        }
        s.append(" > ");
      }
    }

    // build view
    if (s.length() > 0) {
      TextView tv = new TextView(getContext());
      tv.setText(s.substring(0, s.length() - 3));
      tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, TEXTSIZE - 7);
      tv.setPadding(0, 0, 0, 5);
      mView.addView(tv);
    }
  }
コード例 #2
0
  /** Add a TextView containing the question text. */
  private void AddQuestionText(PromptElement p) {
    TextView tv = new TextView(getContext());
    tv.setText(p.getQuestionText());
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, TEXTSIZE);
    tv.setTypeface(null, Typeface.BOLD);

    tv.setPadding(0, 0, 0, 5);

    // wrap to the widget of view
    tv.setHorizontallyScrolling(false);
    mView.addView(tv);
  }
コード例 #3
0
  public void buildView(PromptElement prompt) {
    // font size
    setTextSize(TypedValue.COMPLEX_UNIT_PX, GlobalConstants.APPLICATION_FONTSIZE);

    // capitalize the first letter of the sentence
    setKeyListener(new TextKeyListener(Capitalize.SENTENCES, false));

    // needed to make long read only text scroll
    setHorizontallyScrolling(false);
    setSingleLine(false);

    String s = prompt.getAnswerText();
    if (s != null) {
      setText(s);
    }
    if (prompt.isReadOnly()) {
      setBackgroundDrawable(null);
      setFocusable(false);
      setClickable(false);
    }
  }
コード例 #4
0
  /** Add a TextView containing the help text. */
  private void AddHelpText(PromptElement p) {
    String s = p.getHelpText();

    if (s != null && !s.equals("")) {
      TextView tv = new TextView(getContext());
      tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, TEXTSIZE - 5);
      tv.setPadding(0, 0, 0, 7);
      // wrap to the widget of view
      tv.setHorizontallyScrolling(false);
      tv.setText(s);
      tv.setTypeface(null, Typeface.ITALIC);

      mView.addView(tv);
    }
  }
コード例 #5
0
  @SuppressWarnings("unchecked")
  public void buildView(final PromptElement prompt) {
    mItems = prompt.getSelectItems();

    setOrientation(LinearLayout.VERTICAL);

    Vector ve = new Vector();
    if (prompt.getAnswerValue() != null) {
      ve = (Vector) prompt.getAnswerObject();
    }

    if (prompt.getSelectItems() != null) {
      OrderedHashtable h = prompt.getSelectItems();
      Enumeration en = h.keys();
      String k = null;
      String v = null;

      // counter for offset
      int i = 0;

      while (en.hasMoreElements()) {

        k = (String) en.nextElement();
        v = (String) h.get(k);

        // no checkbox group so id by answer + offset
        CheckBox c = new CheckBox(getContext());

        // when clicked, check for readonly before toggling
        c.setOnCheckedChangeListener(
            new CompoundButton.OnCheckedChangeListener() {
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!mCheckboxInit && prompt.isReadonly()) {
                  if (buttonView.isChecked()) {
                    buttonView.setChecked(false);
                  } else {
                    buttonView.setChecked(true);
                  }
                }
              }
            });

        c.setId(CHECKBOX_ID + i);
        c.setText(k);
        c.setTextSize(TypedValue.COMPLEX_UNIT_PT, GlobalConstants.APPLICATION_FONTSIZE);

        for (int vi = 0; vi < ve.size(); vi++) {
          // match based on value, not key
          if (v.equals(((Selection) ve.elementAt(vi)).getValue())) {
            c.setChecked(true);
            break;
          }
        }

        c.setFocusable(!prompt.isReadonly());
        c.setEnabled(!prompt.isReadonly());
        addView(c);
        i++;
      }
    }

    mCheckboxInit = false;
  }