示例#1
0
  public TriggerWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);
    mPrompt = prompt;

    this.setOrientation(LinearLayout.VERTICAL);

    mTriggerButton = new CheckBox(getContext());
    mTriggerButton.setId(QuestionWidget.newUniqueId());
    mTriggerButton.setText(getContext().getString(R.string.trigger));
    mTriggerButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    // mActionButton.setPadding(20, 20, 20, 20);
    mTriggerButton.setEnabled(!prompt.isReadOnly());

    mTriggerButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (mTriggerButton.isChecked()) {
              mStringAnswer.setText(mOK);
              Collect.getInstance()
                  .getActivityLogger()
                  .logInstanceAction(TriggerWidget.this, "triggerButton", "OK", mPrompt.getIndex());
            } else {
              mStringAnswer.setText(null);
              Collect.getInstance()
                  .getActivityLogger()
                  .logInstanceAction(
                      TriggerWidget.this, "triggerButton", "null", mPrompt.getIndex());
            }
          }
        });

    mStringAnswer = new TextView(getContext());
    mStringAnswer.setId(QuestionWidget.newUniqueId());
    mStringAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mStringAnswer.setGravity(Gravity.CENTER);

    String s = prompt.getAnswerText();
    if (s != null) {
      if (s.equals(mOK)) {
        mTriggerButton.setChecked(true);
      } else {
        mTriggerButton.setChecked(false);
      }
      mStringAnswer.setText(s);
    }

    // finish complex layout
    this.addView(mTriggerButton);
    // this.addView(mStringAnswer);
  }
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.question_fragment, container, false);

    TextView questionName = (TextView) view.findViewById(R.id.question_name);
    final CheckBox questionOne = (CheckBox) view.findViewById(R.id.answer_one);
    final CheckBox questionTwo = (CheckBox) view.findViewById(R.id.answer_two);
    final CheckBox questionThree = (CheckBox) view.findViewById(R.id.answer_three);
    final CheckBox questionFour = (CheckBox) view.findViewById(R.id.answer_four);
    final CheckBox questionFive = (CheckBox) view.findViewById(R.id.answer_five);

    MainActivity activity = ((MainActivity) getActivity());
    if (activity.getQuestions().size() != 0) {
      currentQuestion = activity.getQuestions().get(13);
    } else {
      currentQuestion = new Question("Frage unbekannt");
    }

    if (activity.getTextSize().equals(TextSize.MIDDLE)) {
      questionOne.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_middle));
      questionTwo.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_middle));
      questionThree.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_middle));
      questionFour.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_middle));
      questionFive.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_middle));
      questionName.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.info_title_size_middle));
    } else if (activity.getTextSize().equals(TextSize.SMALL)) {
      questionOne.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size));
      questionTwo.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size));
      questionThree.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size));
      questionFour.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size));
      questionFive.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size));
      questionName.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.info_title_size));
    } else if (activity.getTextSize().equals(TextSize.BIG)) {
      questionOne.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_big));
      questionTwo.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_big));
      questionThree.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_big));
      questionFour.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_big));
      questionFive.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.default_button_text_size_big));
      questionName.setTextSize(
          TypedValue.COMPLEX_UNIT_PX,
          activity.getResources().getDimension(R.dimen.info_title_size_big));
    }

    int color = activity.convertColorString();
    if (color != 0) {
      questionOne.setButtonDrawable(R.drawable.checkbox_selector_magenta);
      questionTwo.setButtonDrawable(R.drawable.checkbox_selector_magenta);
      questionThree.setButtonDrawable(R.drawable.checkbox_selector_magenta);
      questionFour.setButtonDrawable(R.drawable.checkbox_selector_magenta);
      questionFive.setButtonDrawable(R.drawable.checkbox_selector_magenta);
    } else {
      questionOne.setButtonDrawable(R.drawable.checkbox_selector_green);
      questionTwo.setButtonDrawable(R.drawable.checkbox_selector_green);
      questionThree.setButtonDrawable(R.drawable.checkbox_selector_green);
      questionFour.setButtonDrawable(R.drawable.checkbox_selector_green);
      questionFive.setButtonDrawable(R.drawable.checkbox_selector_green);
    }

    questionName.setText(currentQuestion.getQuestionName());
    for (int i = 0; i < currentQuestion.getAnswers().size(); i++) {
      if (i == 0) {
        questionOne.setText(currentQuestion.getAnswers().get(0).getAnswerName());
      }
      if (i == 1) {
        questionTwo.setText(currentQuestion.getAnswers().get(1).getAnswerName());
      }
      if (i == 2) {
        questionThree.setText(currentQuestion.getAnswers().get(2).getAnswerName());
      }
      if (i == 3) {
        questionFour.setText(currentQuestion.getAnswers().get(3).getAnswerName());
      }
      if (i == 4) {
        questionFive.setText(currentQuestion.getAnswers().get(4).getAnswerName());
      }
    }

    int length = currentQuestion.getAnswers().size();
    if (length == 4) {
      questionFive.setVisibility(View.GONE);
    } else if (length == 3) {
      questionFive.setVisibility(View.GONE);
      questionFour.setVisibility(View.GONE);
    } else if (length == 2) {
      questionFive.setVisibility(View.GONE);
      questionFour.setVisibility(View.GONE);
      questionThree.setVisibility(View.GONE);
    }

    questionOne.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (questionOne.isChecked()) {
              ((MainActivity) getActivity())
                  .setAnswerActive(1, currentQuestion.getQuestionName(), true);
              questionTwo.setChecked(false);
              questionThree.setChecked(false);
              questionFour.setChecked(false);
              questionFive.setChecked(false);
            } else {
              ((MainActivity) getActivity())
                  .setAnswerActive(1, currentQuestion.getQuestionName(), false);
            }
          }
        });

    questionTwo.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (questionTwo.isChecked()) {
              ((MainActivity) getActivity())
                  .setAnswerActive(2, currentQuestion.getQuestionName(), true);
              questionOne.setChecked(false);
              questionThree.setChecked(false);
              questionFour.setChecked(false);
              questionFive.setChecked(false);
            } else {
              ((MainActivity) getActivity())
                  .setAnswerActive(1, currentQuestion.getQuestionName(), false);
            }
          }
        });

    questionThree.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (questionThree.isChecked()) {
              ((MainActivity) getActivity())
                  .setAnswerActive(3, currentQuestion.getQuestionName(), true);
              questionTwo.setChecked(false);
              questionOne.setChecked(false);
              questionFour.setChecked(false);
              questionFive.setChecked(false);
            } else {
              ((MainActivity) getActivity())
                  .setAnswerActive(1, currentQuestion.getQuestionName(), false);
            }
          }
        });

    questionFour.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (questionFour.isChecked()) {
              ((MainActivity) getActivity())
                  .setAnswerActive(4, currentQuestion.getQuestionName(), true);
              questionTwo.setChecked(false);
              questionThree.setChecked(false);
              questionOne.setChecked(false);
              questionFive.setChecked(false);
            } else {
              ((MainActivity) getActivity())
                  .setAnswerActive(1, currentQuestion.getQuestionName(), false);
            }
          }
        });

    questionFive.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (questionFive.isChecked()) {
              ((MainActivity) getActivity())
                  .setAnswerActive(5, currentQuestion.getQuestionName(), true);
              questionTwo.setChecked(false);
              questionThree.setChecked(false);
              questionOne.setChecked(false);
              questionFour.setChecked(false);
            } else {
              ((MainActivity) getActivity())
                  .setAnswerActive(1, currentQuestion.getQuestionName(), false);
            }
          }
        });

    return view;
  }
示例#3
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;
  }
示例#4
0
  @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;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");

    scroll = new ScrollView(this);
    setContentView(scroll);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    layout.setPadding(10, 10, 10, 10);
    scroll.addView(
        layout,
        new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    viewNetwork = new Button(this);
    viewNetwork.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    viewNetwork.setText(getResources().getString(R.string.view_network_button));
    viewNetwork.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            final String[] networkTreeCopy = networkTree;
            AlertDialog.Builder builder = new AlertDialog.Builder(AddPrinterActivity.this);
            // builder.setTitle(R.string.network);
            builder.setItems(
                networkTreeCopy,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, final int which) {
                    dialog.dismiss();
                    String selected = networkTreeCopy[which];
                    selected = selected.trim();
                    if (!selected.startsWith("\\\\")) return;
                    selected = selected.substring(2);
                    if (selected.indexOf("\\") == -1) return;
                    String server = selected.substring(0, selected.indexOf("\\"));
                    String share = selected.substring(selected.indexOf("\\") + 1);
                    share = share.split("\\s+")[0];
                    AddPrinterActivity.this.server.setText(server);
                    AddPrinterActivity.this.printer.setText(share);
                    AddPrinterActivity.this.name.setText(server + "-" + share);
                    String workgroup = "";
                    for (int i = 0; i < which; i++) {
                      if (networkTreeCopy[i].indexOf("\\") == -1) workgroup = networkTreeCopy[i];
                    }
                    if (workgroup.length() > 0) AddPrinterActivity.this.domain.setText(workgroup);
                  }
                });
            builder.setNegativeButton(
                R.string.close,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface d, int s) {
                    d.dismiss();
                    if (user.getText().toString().length() == 0
                        || password.getText().toString().length() == 0)
                      Toast.makeText(
                              AddPrinterActivity.this,
                              R.string.login_password_hint,
                              Toast.LENGTH_LONG)
                          .show();
                  }
                });
            builder.setPositiveButton(
                R.string.view_network_button_scan_again,
                new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface d, int s) {
                    d.dismiss();
                    updateNetworkTree();
                    if (user.getText().toString().length() == 0
                        || password.getText().toString().length() == 0)
                      Toast.makeText(
                              AddPrinterActivity.this,
                              R.string.login_password_hint,
                              Toast.LENGTH_LONG)
                          .show();
                  }
                });
            AlertDialog alert = builder.create();
            alert.setOwnerActivity(AddPrinterActivity.this);
            alert.show();
          }
        });
    layout.addView(viewNetwork);

    TextView text = null;

    text = new TextView(this);
    text.setText(R.string.name_desc);
    text.setTextSize(20);
    layout.addView(text);

    name = new EditText(this);
    name.setHint(R.string.name_hint);
    name.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(name);

    text = new TextView(this);
    text.setText(R.string.server_desc);
    text.setTextSize(20);
    layout.addView(text);

    server = new EditText(this);
    server.setHint(R.string.server_hint);
    server.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(server);

    text = new TextView(this);
    text.setText(R.string.printer_desc);
    text.setTextSize(20);
    layout.addView(text);

    printer = new EditText(this);
    printer.setHint(R.string.printer_hint);
    printer.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(printer);

    text = new TextView(this);
    text.setText(R.string.model_desc);
    text.setTextSize(20);
    layout.addView(text);

    model = new EditText(this);
    model.setHint(R.string.model_button_reading);
    model.setEnabled(false);
    model.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    model.addTextChangedListener(
        new TextWatcher() {
          public void afterTextChanged(Editable s) {
            if (s.length() >= 1 && modelList != null) {
              // selectModel.setEnabled(true);
              selectModel.setText(getResources().getString(R.string.model_button_search));
            } else {
              // selectModel.setEnabled(false);
              selectModel.setText(getResources().getString(R.string.model_button_type));
            }
          }

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

          public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });
    layout.addView(model);

    selectModel = new Button(this);
    selectModel.setText(getResources().getString(R.string.model_button_reading));
    selectModel.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (!model.isEnabled()) {
              model.setEnabled(true);
              model.setText("");
              return;
            }
            String search = model.getText().toString().toLowerCase();
            final ArrayList<CharSequence> values = new ArrayList<CharSequence>();
            AlertDialog.Builder builder = new AlertDialog.Builder(AddPrinterActivity.this);
            builder.setTitle(R.string.select_printer_model);
            for (String s : modelList.keySet()) {
              if (s.toLowerCase().indexOf(search) != -1) {
                Log.d(TAG, "Found model: " + s);
                values.add(s);
              }
            }
            if (values.size() == 0) {
              builder.setMessage(R.string.no_models_found);
              builder.setPositiveButton(
                  R.string.ok,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface d, int s) {
                      d.dismiss();
                    }
                  });
            } else {
              builder.setItems(
                  values.toArray(new CharSequence[0]),
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      model.setText(values.get(which));
                      model.setEnabled(false);
                      selectModel.setText(getResources().getString(R.string.model_button_clear));
                    }
                  });
            }
            AlertDialog alert = builder.create();
            alert.setOwnerActivity(AddPrinterActivity.this);
            alert.show();
          }
        });
    selectModel.setEnabled(false);
    layout.addView(selectModel);

    text = new TextView(this);
    text.setText(R.string.domain_desc);
    text.setTextSize(20);
    layout.addView(text);

    domain = new EditText(this);
    domain.setHint(R.string.domain_hint);
    domain.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(domain);

    text = new TextView(this);
    text.setText(R.string.user_desc);
    text.setTextSize(20);
    layout.addView(text);

    user = new EditText(this);
    user.setHint(R.string.user_hint);
    user.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    layout.addView(user);

    text = new TextView(this);
    text.setText(R.string.password_desc);
    text.setTextSize(20);
    text.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f));

    CheckBox showPassword = new CheckBox(this);
    showPassword.setText(R.string.show_password);
    showPassword.setTextSize(20);
    showPassword.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0.0f));
    showPassword.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            int selection = password.getSelectionStart();
            if (isChecked) {
              password.setInputType(
                  InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
              password.setTransformationMethod(null);
            } else {
              password.setInputType(
                  InputType.TYPE_CLASS_TEXT
                      | InputType.TYPE_TEXT_VARIATION_PASSWORD
                      | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
              password.setTransformationMethod(PasswordTransformationMethod.getInstance());
            }
            password.setSelection(selection);
          }
        });

    LinearLayout layout2 = new LinearLayout(this);
    layout2.setOrientation(LinearLayout.HORIZONTAL);
    layout2.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    layout2.addView(text);
    layout2.addView(showPassword);

    layout.addView(layout2);

    password = new EditText(this);
    password.setHint(R.string.password_hint);
    password.setInputType(
        InputType.TYPE_CLASS_TEXT
            | InputType.TYPE_TEXT_VARIATION_PASSWORD
            | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    password.setTransformationMethod(PasswordTransformationMethod.getInstance());
    layout.addView(password);

    text = new TextView(this);
    text.setText("");
    layout.addView(text);

    addPrinter = new Button(this);
    addPrinter.setEnabled(false);
    addPrinter.setText(
        getResources().getString(R.string.add_printer_button)
            + " - "
            + getResources().getString(R.string.model_button_reading));
    addPrinter.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (name.getText().length() == 0
                || server.getText().length() == 0
                || printer.getText().length() == 0
                || model.isEnabled()
                || model.getText().length() == 0) {
              AlertDialog.Builder builder = new AlertDialog.Builder(AddPrinterActivity.this);
              builder.setTitle(R.string.error);
              builder.setMessage(R.string.error_empty_fields);
              builder.setPositiveButton(
                  R.string.ok,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface d, int s) {
                      d.dismiss();
                    }
                  });
              AlertDialog alert = builder.create();
              alert.setOwnerActivity(AddPrinterActivity.this);
              alert.show();
              return;
            }
            progressCircle.show();
            new Thread(
                    new Runnable() {
                      public void run() {
                        Cups.addPrinter(
                            AddPrinterActivity.this,
                            name.getText().toString(),
                            server.getText().toString(),
                            printer.getText().toString(),
                            modelList.get(model.getText().toString()),
                            domain.getText().toString().toUpperCase(),
                            user.getText().toString(),
                            password.getText().toString());
                        Cups.updatePrintersInfo(AddPrinterActivity.this);
                        runOnUiThread(
                            new Runnable() {
                              public void run() {
                                progressCircle.dismiss();
                                Toast.makeText(
                                        AddPrinterActivity.this,
                                        R.string.printer_added_successfully,
                                        Toast.LENGTH_LONG)
                                    .show();
                                finish();
                              }
                            });
                      }
                    })
                .start();
          }
        });
    layout.addView(addPrinter);

    progressCircle = new ProgressDialog(this);
    progressCircle.setMessage(getResources().getString(R.string.please_wait));

    updateNetworkTree();

    Uri uri = getIntent() != null ? getIntent().getData() : null;
    if (uri != null
        && uri.getScheme() != null
        && uri.getHost() != null
        && getResources().getString(R.string.add_printer_scheme).equals(uri.getScheme())
        && getResources().getString(R.string.add_printer_host).equals(uri.getHost())) {
      name.setText(uri.getQueryParameter("n"));
      server.setText(uri.getQueryParameter("s"));
      printer.setText(uri.getQueryParameter("p"));
      model.setText(uri.getQueryParameter("m"));
      domain.setText(uri.getQueryParameter("d"));
      user.setText(uri.getQueryParameter("u"));
      password.setText(uri.getQueryParameter("pw"));
    }

    updateModelList();
  }
示例#6
0
  public void displayAccounts() {
    accounts = b2evolution.DB.getAccounts(this);
    HashMap<?, ?> notificationOptions = b2evolution.DB.getNotificationOptions(this);
    boolean sound = false, vibrate = false, light = false, taglineValue = false;
    String tagline = "";

    if (notificationOptions != null) {
      if (notificationOptions.get("sound").toString().equals("1")) {
        sound = true;
      }
      if (notificationOptions.get("vibrate").toString().equals("1")) {
        vibrate = true;
      }
      if (notificationOptions.get("light").toString().equals("1")) {
        light = true;
      }
      if (notificationOptions.get("tagline_flag").toString().equals("1")) {
        taglineValue = true;
      }
      tagline = notificationOptions.get("tagline").toString();
    }

    if (accounts.size() > 0) {
      ScrollView sv = new ScrollView(this);
      sv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
      sv.setBackgroundColor(Color.parseColor("#FFFFFFFF"));
      LinearLayout layout = new LinearLayout(this);

      layout.setPadding(14, 14, 14, 14);
      layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

      layout.setOrientation(LinearLayout.VERTICAL);
      layout.setGravity(Gravity.LEFT);

      final LinearLayout cbLayout = new LinearLayout(this);

      cbLayout.setLayoutParams(
          new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

      cbLayout.setOrientation(LinearLayout.VERTICAL);

      LinearLayout.LayoutParams section1Params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

      section1Params.setMargins(0, 0, 0, 20);

      LinearLayout section1 = new LinearLayout(this);
      section1.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg));
      section1.setLayoutParams(section1Params);
      section1.setOrientation(LinearLayout.VERTICAL);

      LinearLayout.LayoutParams headerParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      headerParams.setMargins(1, 1, 1, 0);
      TextView textView = new TextView(this);
      textView.setLayoutParams(headerParams);
      textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      textView.setTypeface(Typeface.DEFAULT_BOLD);
      textView.setPadding(0, 4, 0, 4);
      textView.setShadowLayer(1, 0, 2, Color.parseColor("#FFFFFFFF"));
      textView.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg_header));
      textView.setText("  " + getResources().getText(R.string.comment_notifications));

      section1.addView(textView);

      LinearLayout.LayoutParams cbParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      cbParams.setMargins(4, 0, 0, 6);

      for (int i = 0; i < accounts.size(); i++) {

        HashMap<?, ?> curHash = (HashMap<?, ?>) accounts.get(i);
        String curBlogName = curHash.get("blogName").toString();
        String accountID = curHash.get("id").toString();
        int runService = Integer.valueOf(curHash.get("runService").toString());
        accountNames.add(i, curBlogName);

        final CheckBox checkBox = new CheckBox(this);
        checkBox.setTextColor(Color.parseColor("#444444"));
        checkBox.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        checkBox.setText(EscapeUtils.unescapeHtml(curBlogName));
        checkBox.setId(Integer.valueOf(accountID));
        checkBox.setLayoutParams(cbParams);

        if (runService == 1) {
          checkBox.setChecked(true);
        }

        cbLayout.addView(checkBox);
      }

      if (cbLayout.getChildCount() > 0) {
        section1.addView(cbLayout);
      }

      // add spinner and buttons
      TextView textView2 = new TextView(this);
      LinearLayout.LayoutParams labelParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      labelParams.setMargins(8, 0, 0, 0);
      textView2.setLayoutParams(labelParams);
      textView2.setTextColor(Color.parseColor("#444444"));
      textView2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      textView2.setText(getResources().getText(R.string.notifications_interval));

      section1.addView(textView2);

      final Spinner sInterval = new Spinner(this);
      LinearLayout.LayoutParams spinnerParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      spinnerParams.setMargins(4, 0, 4, 10);
      sInterval.setLayoutParams(spinnerParams);
      ArrayAdapter<Object> sIntervalArrayAdapter =
          new ArrayAdapter<Object>(
              this,
              R.layout.spinner_textview,
              new String[] {
                "5 Minutes",
                "10 Minutes",
                "15 Minutes",
                "30 Minutes",
                "1 Hour",
                "3 Hours",
                "6 Hours",
                "12 Hours",
                "Daily"
              });
      sIntervalArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      sInterval.setAdapter(sIntervalArrayAdapter);
      String interval = b2evolution.DB.getInterval(this);

      if (interval != "") {
        sInterval.setSelection(sIntervalArrayAdapter.getPosition(interval));
      }

      section1.addView(sInterval);

      final LinearLayout nOptionsLayout = new LinearLayout(this);

      nOptionsLayout.setLayoutParams(
          new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

      nOptionsLayout.setOrientation(LinearLayout.VERTICAL);

      CheckBox soundCB = new CheckBox(this);
      soundCB.setTag("soundCB");
      soundCB.setTextColor(Color.parseColor("#444444"));
      soundCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      soundCB.setText(getResources().getText(R.string.notification_sound));
      soundCB.setLayoutParams(cbParams);
      soundCB.setChecked(sound);

      nOptionsLayout.addView(soundCB);

      CheckBox vibrateCB = new CheckBox(this);
      vibrateCB.setTag("vibrateCB");
      vibrateCB.setTextColor(Color.parseColor("#444444"));
      vibrateCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      vibrateCB.setText(getResources().getText(R.string.notification_vibrate));
      vibrateCB.setLayoutParams(cbParams);
      vibrateCB.setChecked(vibrate);

      nOptionsLayout.addView(vibrateCB);

      CheckBox lightCB = new CheckBox(this);
      lightCB.setTag("lightCB");
      lightCB.setTextColor(Color.parseColor("#444444"));
      lightCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      lightCB.setText(getResources().getText(R.string.notification_blink));
      lightCB.setLayoutParams(cbParams);
      lightCB.setChecked(light);

      nOptionsLayout.addView(lightCB);

      section1.addView(nOptionsLayout);

      layout.addView(section1);

      final LinearLayout section2 = new LinearLayout(this);
      section2.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg));
      section2.setOrientation(LinearLayout.VERTICAL);
      LinearLayout.LayoutParams section2Params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      section2Params.setMargins(0, 0, 0, 20);
      section2.setLayoutParams(section2Params);
      section2.setPadding(0, 0, 0, 10);

      TextView section2lbl = new TextView(this);
      section2lbl.setLayoutParams(headerParams);
      section2lbl.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      section2lbl.setTypeface(Typeface.DEFAULT_BOLD);
      section2lbl.setShadowLayer(1, 0, 2, Color.parseColor("#FFFFFFFF"));
      section2lbl.setPadding(0, 4, 0, 4);
      section2lbl.setText("  " + getResources().getText(R.string.post_signature));
      section2lbl.setBackgroundDrawable(getResources().getDrawable(R.drawable.content_bg_header));

      section2.addView(section2lbl);

      CheckBox taglineCB = new CheckBox(this);
      taglineCB.setTag("taglineCB");
      taglineCB.setTextColor(Color.parseColor("#444444"));
      taglineCB.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      taglineCB.setText(getResources().getText(R.string.add_tagline));
      taglineCB.setLayoutParams(cbParams);
      taglineCB.setChecked(taglineValue);

      section2.addView(taglineCB);

      EditText taglineET = new EditText(this);
      LinearLayout.LayoutParams taglineParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      taglineParams.setMargins(4, 0, 4, 4);
      taglineET.setLayoutParams(taglineParams);
      if (tagline != null) {
        if (tagline.equals("")) {
          if (BlackBerryUtils.getInstance().isBlackBerry())
            taglineET.setText(getResources().getText(R.string.posted_from_blackberry));
          else taglineET.setText(getResources().getText(R.string.posted_from));
        } else {
          taglineET.setText(tagline);
        }
      }
      taglineET.setMinLines(2);
      section2.addView(taglineET);

      layout.addView(section2);

      final LinearLayout section3 = new LinearLayout(this);
      section3.setOrientation(LinearLayout.HORIZONTAL);
      section3.setGravity(Gravity.RIGHT);
      LinearLayout.LayoutParams section3Params =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      section3Params.setMargins(0, 0, 0, 20);
      section3.setLayoutParams(section3Params);

      final Button cancel = new Button(this);

      LinearLayout.LayoutParams cancelParams =
          new LinearLayout.LayoutParams(
              LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
      cancelParams.setMargins(0, 0, 10, 0);
      cancel.setLayoutParams(cancelParams);
      cancel.setBackgroundDrawable(getResources().getDrawable(R.drawable.b2evo_button_small));
      cancel.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
      cancel.setText(getResources().getText(R.string.cancel));
      cancel.setOnClickListener(
          new Button.OnClickListener() {
            public void onClick(View v) {
              finish();
            }
          });
      section3.addView(cancel);

      final Button save = new Button(this);

      save.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
      save.setBackgroundDrawable(getResources().getDrawable(R.drawable.b2evo_button_small));
      save.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
      save.setText(getResources().getText(R.string.save));

      save.setOnClickListener(
          new Button.OnClickListener() {
            public void onClick(View v) {

              boolean sound = false, vibrate = false, light = false, tagValue = false;
              checkCtr = 0;

              int listItemCount = cbLayout.getChildCount();
              for (int i = 0; i < listItemCount; i++) {
                CheckBox cbox = (CheckBox) cbLayout.getChildAt(i);
                int id = cbox.getId();
                if (cbox.isChecked()) {
                  checkCtr++;
                  b2evolution.DB.updateNotificationFlag(id, true);
                  Log.i("CommentService", "Service enabled for " + cbox.getText());
                } else {
                  b2evolution.DB.updateNotificationFlag(id, false);
                }
              }

              int noOptionsItemCount = nOptionsLayout.getChildCount();
              for (int i = 0; i < noOptionsItemCount; i++) {
                CheckBox cbox = (CheckBox) nOptionsLayout.getChildAt(i);
                if (cbox.getTag().equals("soundCB")) {
                  sound = cbox.isChecked();
                } else if (cbox.getTag().equals("vibrateCB")) {
                  vibrate = cbox.isChecked();
                } else if (cbox.getTag().equals("lightCB")) {
                  light = cbox.isChecked();
                }
              }

              CheckBox tagFlag = (CheckBox) section2.getChildAt(1);
              tagValue = tagFlag.isChecked();

              EditText taglineET = (EditText) section2.getChildAt(2);
              String taglineText = taglineET.getText().toString();

              b2evolution.DB.updateNotificationSettings(
                  sInterval.getSelectedItem().toString(),
                  sound,
                  vibrate,
                  light,
                  tagValue,
                  taglineText);

              if (checkCtr > 0) {

                String updateInterval = sInterval.getSelectedItem().toString();
                int UPDATE_INTERVAL = 3600000;

                // configure time interval
                if (updateInterval.equals("5 Minutes")) {
                  UPDATE_INTERVAL = 300000;
                } else if (updateInterval.equals("10 Minutes")) {
                  UPDATE_INTERVAL = 600000;
                } else if (updateInterval.equals("15 Minutes")) {
                  UPDATE_INTERVAL = 900000;
                } else if (updateInterval.equals("30 Minutes")) {
                  UPDATE_INTERVAL = 1800000;
                } else if (updateInterval.equals("1 Hour")) {
                  UPDATE_INTERVAL = 3600000;
                } else if (updateInterval.equals("3 Hours")) {
                  UPDATE_INTERVAL = 10800000;
                } else if (updateInterval.equals("6 Hours")) {
                  UPDATE_INTERVAL = 21600000;
                } else if (updateInterval.equals("12 Hours")) {
                  UPDATE_INTERVAL = 43200000;
                } else if (updateInterval.equals("Daily")) {
                  UPDATE_INTERVAL = 86400000;
                }

                Intent intent = new Intent(Preferences.this, CommentBroadcastReceiver.class);
                PendingIntent pIntent = PendingIntent.getBroadcast(Preferences.this, 0, intent, 0);

                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

                alarmManager.setRepeating(
                    AlarmManager.RTC_WAKEUP,
                    System.currentTimeMillis() + (5 * 1000),
                    UPDATE_INTERVAL,
                    pIntent);

              } else {
                Intent stopIntent = new Intent(Preferences.this, CommentBroadcastReceiver.class);
                PendingIntent stopPIntent =
                    PendingIntent.getBroadcast(Preferences.this, 0, stopIntent, 0);
                AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
                alarmManager.cancel(stopPIntent);

                Intent service = new Intent(Preferences.this, CommentService.class);
                stopService(service);
              }

              finish();
            }
          });

      section3.addView(save);
      layout.addView(section3);

      sv.addView(layout);

      setContentView(sv);
    }
  }
  @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;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.activity_edit_alert);

    viewHeader = (TextView) findViewById(R.id.view_alert_header);

    buttonSave = (Button) findViewById(R.id.edit_alert_save);
    buttonRemove = (Button) findViewById(R.id.edit_alert_remove);
    buttonTest = (Button) findViewById(R.id.edit_alert_test);
    buttonalertMp3 = (Button) findViewById(R.id.Button_alert_mp3_file);
    buttonPreSnooze = (Button) findViewById(R.id.edit_alert_pre_snooze);

    alertText = (EditText) findViewById(R.id.edit_alert_text);
    alertThreshold = (EditText) findViewById(R.id.edit_alert_threshold);
    alertMp3File = (EditText) findViewById(R.id.edit_alert_mp3_file);

    checkboxAllDay = (CheckBox) findViewById(R.id.check_alert_time);

    layoutTimeBetween = (LinearLayout) findViewById(R.id.time_between);
    timeInstructions = (LinearLayout) findViewById(R.id.time_instructions);
    timeInstructionsStart = (TextView) findViewById(R.id.time_instructions_start);
    timeInstructionsEnd = (TextView) findViewById(R.id.time_instructions_end);

    viewTimeStart = (TextView) findViewById(R.id.view_alert_time_start);
    viewTimeEnd = (TextView) findViewById(R.id.view_alert_time_end);
    editSnooze = (EditText) findViewById(R.id.edit_snooze);
    reraise = (EditText) findViewById(R.id.reraise);

    viewAlertOverrideText = (TextView) findViewById(R.id.view_alert_override_silent);
    checkboxAlertOverride = (CheckBox) findViewById(R.id.check_override_silent);
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    addListenerOnButtons();

    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
      viewHeader.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonSave.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonRemove.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonTest.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonalertMp3.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonSave.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      buttonPreSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      alertText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      alertThreshold.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      alertMp3File.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

      checkboxAllDay.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

      viewTimeStart.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      viewTimeEnd.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      editSnooze.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      reraise.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      viewAlertOverrideText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);

      ((TextView) findViewById(R.id.view_alert_text)).setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_threshold))
          .setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_default_snooze))
          .setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_mp3_file))
          .setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_time)).setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
      ((TextView) findViewById(R.id.view_alert_time_between))
          .setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
    }
    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    doMgdl = (prefs.getString("units", "mgdl").compareTo("mgdl") == 0);

    if (!doMgdl) {
      alertThreshold.setInputType(InputType.TYPE_CLASS_NUMBER);
      alertThreshold.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
      alertThreshold.setKeyListener(DigitsKeyListener.getInstance(false, true));
    }

    uuid = getExtra(savedInstanceState, "uuid");
    String status;
    if (uuid == null) {
      // This is a new alert
      above = Boolean.parseBoolean(getExtra(savedInstanceState, "above"));
      checkboxAllDay.setChecked(true);
      checkboxAlertOverride.setChecked(true);

      audioPath = "";
      alertMp3File.setText(shortPath(audioPath));
      alertMp3File.setKeyListener(null);
      defaultSnooze = SnoozeActivity.getDefaultSnooze(above);
      buttonRemove.setVisibility(View.GONE);
      // One can not snooze an alert that is still not in the database...
      buttonPreSnooze.setVisibility(View.GONE);
      status = "Adding " + (above ? "high" : "low") + " alert";
      startHour = 0;
      startMinute = 0;
      endHour = 23;
      endMinute = 59;
      alertReraise = 1;
    } else {
      // We are editing an alert
      AlertType at = AlertType.get_alert(uuid);
      if (at == null) {
        Log.wtf(TAG, "Error editing alert, when that alert does not exist...");
        Intent returnIntent = new Intent();
        setResult(RESULT_CANCELED, returnIntent);
        finish();
        return;
      }

      above = at.above;
      alertText.setText(at.name);
      alertThreshold.setText(unitsConvert2Disp(doMgdl, at.threshold));
      checkboxAllDay.setChecked(at.all_day);
      checkboxAlertOverride.setChecked(at.override_silent_mode);
      defaultSnooze = at.default_snooze;
      if (defaultSnooze == 0) {
        SnoozeActivity.getDefaultSnooze(above);
      }

      audioPath = at.mp3_file;
      alertMp3File.setText(shortPath(audioPath));

      status = "editing " + (above ? "high" : "low") + " alert";
      startHour = AlertType.time2Hours(at.start_time_minutes);
      startMinute = AlertType.time2Minutes(at.start_time_minutes);
      endHour = AlertType.time2Hours(at.end_time_minutes);
      endMinute = AlertType.time2Minutes(at.end_time_minutes);
      alertReraise = at.minutes_between;

      if (uuid.equals(AlertType.LOW_ALERT_55)) {
        // This is the 55 alert, can not be edited
        alertText.setKeyListener(null);
        alertThreshold.setKeyListener(null);
        buttonalertMp3.setEnabled(false);
        checkboxAllDay.setEnabled(false);
        checkboxAlertOverride.setEnabled(false);
        reraise.setEnabled(false);
      }
    }
    reraise.setText(String.valueOf(alertReraise));
    alertMp3File.setKeyListener(null);
    viewHeader.setText(status);
    setDefaultSnoozeSpinner();
    setPreSnoozeSpinner();
    enableAllDayControls();
    enableVibrateControls();
  }
  @SuppressWarnings("unchecked")
  public SelectMultiWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);
    mPrompt = prompt;
    mCheckboxes = new Vector<CheckBox>();
    mItems = prompt.getSelectChoices();

    setOrientation(LinearLayout.VERTICAL);

    Vector<Selection> ve = new Vector<Selection>();
    if (prompt.getAnswerValue() != null) {
      ve = (Vector<Selection>) getCurrentAnswer().getValue();
    }

    // Is this safe enough from collisions?
    buttonIdBase = Math.abs(prompt.getIndex().toString().hashCode());

    if (prompt.getSelectChoices() != null) {
      for (int i = 0; i < mItems.size(); i++) {
        // no checkbox group so id by answer + offset
        final CheckBox c = new CheckBox(getContext());

        c.setId(buttonIdBase + i);
        c.setText(stylize(prompt.getSelectChoiceText(mItems.get(i))));
        c.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
        c.setFocusable(!prompt.isReadOnly());
        c.setEnabled(!prompt.isReadOnly());

        int padding = (int) Math.floor(context.getResources().getDimension(R.dimen.select_padding));

        c.setPadding(c.getPaddingLeft(), 0, padding, 0);
        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;
          }
        }

        // Note: This gets fired during setup as well, so this listener should only
        // be added after everything about the checkbox is set up

        // when clicked, check for readonly before toggling
        c.setOnCheckedChangeListener(
            new CompoundButton.OnCheckedChangeListener() {
              /*
               * (non-Javadoc)
               * @see android.widget.CompoundButton.OnCheckedChangeListener#onCheckedChanged(android.widget.CompoundButton, boolean)
               */
              @Override
              public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (!mCheckboxInit && mPrompt.isReadOnly()) {
                  if (buttonView.isChecked()) {
                    buttonView.setChecked(false);
                  } else {
                    buttonView.setChecked(true);
                  }
                }
                widgetEntryChanged();
              }
            });

        mCheckboxes.add(c);

        String audioURI = null;
        audioURI =
            prompt.getSpecialFormSelectChoiceText(mItems.get(i), FormEntryCaption.TEXT_FORM_AUDIO);

        String imageURI = null;
        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(c, audioURI, imageURI, videoURI, bigImageURI);
        addView(mediaLayout);

        mediaLayout.setPadding(0, padding, 0, padding);

        mediaLayout.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                c.performClick();
              }
            });

        // 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;
  }