/**
   * Creates the new RadioGroup based on the Input Type of current LogItem
   *
   * @param options
   */
  public void createRadioGroup(ArrayList<String> options) {
    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.BELOW, R.id.LogItemName);
    group = new RadioGroup(this.getContext());
    group.setLayoutParams(params);
    for (int i = 0; i < options.size(); i++) {
      RadioButton btn = new RadioButton(this.getContext());
      btn.setId(i);
      btn.setText(options.get(i));
      group.addView(btn);
    }
    group.setGravity(Gravity.CENTER_HORIZONTAL);
    rlayout.addView(group);
    // Todo: create Listener to add to database when input.

  }
示例#2
0
  public View generateView(final Context ctx) {
    if (idType.equals(Constantes.DIV)) {
      view = new LinearLayout(ctx);
      ((LinearLayout) view).setOrientation(LinearLayout.HORIZONTAL);

      LinearLayout.LayoutParams pTEXT =
          new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
      LinearLayout.LayoutParams pSEPARADOR =
          new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
      pTEXT.weight = 4;
      pSEPARADOR.weight = 1;
      pSEPARADOR.setMargins(20, 4, 0, 4);

      EditText left = new EditText(ctx);
      left.setLayoutParams(pTEXT);
      left.setBackgroundResource(R.drawable.fondo_edittext);
      left.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);

      EditText right = new EditText(ctx);
      right.setLayoutParams(pTEXT);
      right.setBackgroundResource(R.drawable.fondo_edittext);
      right.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);

      TextView separador = new TextView(ctx);
      separador.setLayoutParams(pSEPARADOR);

      left.setInputType(InputType.TYPE_CLASS_NUMBER);
      right.setInputType(InputType.TYPE_CLASS_NUMBER);

      separador.setText("/");
      separador.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
      editTexts = new ArrayList<>();
      editTexts.add(left);
      editTexts.add(right);

      ((LinearLayout) view).addView(left);
      ((LinearLayout) view).addView(separador);
      ((LinearLayout) view).addView(right);
    }
    if (idType.equals(Constantes.DATE)) {
      final Calendar myCalendar = Calendar.getInstance();
      final EditText fecha = new EditText(ctx);
      fecha.setBackgroundResource(R.drawable.fondo_edittext);
      fecha.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
      fecha.setEnabled(false);
      fecha.setGravity(Gravity.CENTER_VERTICAL);

      ImageButton pick = new ImageButton(ctx);
      pick.setBackgroundResource(R.drawable.button_gray);
      pick.setImageResource(R.drawable.ic_calendarwhite);

      LinearLayout.LayoutParams pButton =
          new LinearLayout.LayoutParams(
              0,
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_DIP, 48, ctx.getResources().getDisplayMetrics()));
      LinearLayout.LayoutParams pText =
          new LinearLayout.LayoutParams(
              0,
              (int)
                  TypedValue.applyDimension(
                      TypedValue.COMPLEX_UNIT_DIP, 48, ctx.getResources().getDisplayMetrics()));
      pButton.weight = 1;
      pText.weight = 4;
      pText.leftMargin =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP, 10, ctx.getResources().getDisplayMetrics());

      final DatePickerDialog.OnDateSetListener date =
          new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker picker, int year, int monthOfYear, int dayOfMonth) {
              // TODO Auto-generated method stub
              myCalendar.set(Calendar.YEAR, year);
              myCalendar.set(Calendar.MONTH, monthOfYear);
              myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
              String myFormat = "yyyy/MM/dd"; // In which you need put here
              SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

              fecha.setText(sdf.format(myCalendar.getTime()));
            }
          };

      pick.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              new DatePickerDialog(
                      ctx,
                      date,
                      myCalendar.get(Calendar.YEAR),
                      myCalendar.get(Calendar.MONTH),
                      myCalendar.get(Calendar.DAY_OF_MONTH))
                  .show();
            }
          });

      view = new LinearLayout(ctx);
      ((LinearLayout) view).setOrientation(LinearLayout.HORIZONTAL);
      ((LinearLayout) view).setGravity(Gravity.CENTER_VERTICAL);

      fecha.setLayoutParams(pText);
      pick.setLayoutParams(pButton);

      editTexts = new ArrayList<>();
      editTexts.add(fecha);

      ((LinearLayout) view).addView(pick);
      ((LinearLayout) view).addView(fecha);
    }
    if (idType.equals(Constantes.RADIO)) {
      view = new RadioGroup(ctx);
      for (VALUE v : values) {
        RadioButton b = new RadioButton(ctx);
        b.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
        b.setText(v.getNameValue());
        ((RadioGroup) view).addView(b);
      }
      LinearLayout.LayoutParams p =
          new LinearLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      p.leftMargin =
          (int)
              TypedValue.applyDimension(
                  TypedValue.COMPLEX_UNIT_DIP, 10, ctx.getResources().getDisplayMetrics());
      ((RadioGroup) view).setGravity(Gravity.LEFT);
      view.setLayoutParams(p);
      ((RadioGroup) view).setOrientation(LinearLayout.HORIZONTAL);
      if (values.size() > 2) ((RadioGroup) view).setOrientation(LinearLayout.VERTICAL);
    }
    if (idType.equals(Constantes.CHECK)) {
      view = new LinearLayout(ctx);
      ((LinearLayout) view).setOrientation(LinearLayout.VERTICAL);
      checkBoxes = new ArrayList<>();
      int count = 0;

      LinearLayout tmp;
      tmp = new LinearLayout(ctx);
      tmp.setOrientation(LinearLayout.HORIZONTAL);
      for (VALUE v : values) {
        CheckBox c = new CheckBox(ctx);
        c.setText(v.getNameValue());
        c.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
        checkBoxes.add(c);
        if (count == 0) {
          tmp.addView(c);
          count++;
          if (checkBoxes.size() == values.size()) {
            ((LinearLayout) view).addView(tmp);
          }
        } else if (count == 1) {
          tmp.addView(c);
          ((LinearLayout) view).addView(tmp);
          tmp = new LinearLayout(ctx);
          tmp.setOrientation(LinearLayout.HORIZONTAL);
          count = 0;
        }
      }
      /*view = new LinearLayout(ctx);
      ((LinearLayout)view).setOrientation(LinearLayout.VERTICAL);
      checkBoxes = new ArrayList<>();
      int count = 0;
      for (VALUE v : values) {
          CheckBox c = new CheckBox(ctx);
          c.setText(v.getNameValue());
          c.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
          checkBoxes.add(c);
          if(values.size() >= 3) {
              LinearLayout tmp = new LinearLayout(ctx);
              tmp.setOrientation(LinearLayout.HORIZONTAL);
              if (count < 2) {
                  tmp.addView(c);
                  count++;
              } else {
                  ((LinearLayout) view).addView(tmp);
                  count = 0;
              }
          }else{
              ((LinearLayout) view).addView(c);
          }
      }*/
    }
    if (idType.equals(Constantes.TEXT) || idType.equals(Constantes.NUM)) {
      view = new EditText(ctx);
      ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
      view.setBackgroundResource(R.drawable.fondo_edittext);
      view.setPadding(10, 5, 10, 5);

      if (idType.equals(Constantes.NUM)) {
        ((TextView) view)
            .setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
      }
      if (idType.equals(Constantes.TEXT)) {
        ((TextView) view).setLines(4);
        ((TextView) view).setGravity(Gravity.LEFT | Gravity.TOP);
      }
    }
    if (idType.equals(Constantes.PHOTO)) {
      LinearLayout.LayoutParams left =
          new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
      LinearLayout.LayoutParams right =
          new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT);
      left.weight = 3;
      right.weight = 2;
      buttons = new ArrayList<>();
      Button take = new Button(ctx);
      Button show = new Button(ctx);

      take.setText("Tomar Foto");
      take.setLayoutParams(left);
      take.setBackgroundResource(R.drawable.custom_button_blue_left);
      take.setTextColor(Color.WHITE);
      show.setText("Ver");
      show.setLayoutParams(right);
      show.setBackgroundResource(R.drawable.custom_button_blue_right);
      show.setTextColor(Color.WHITE);
      show.setEnabled(false);

      buttons.add(take);
      buttons.add(show);

      view = new LinearLayout(ctx);
      ((LinearLayout) view).setOrientation(LinearLayout.HORIZONTAL);
      // ((LinearLayout)view).addView(take);
      // ((LinearLayout)view).addView(show);
    }

    return view;
  }