private void setUpRemindDaySpinner() {
      remindDaysSpinner = (Spinner) v.findViewById(R.id.spinnerRemindDate);

      List<String> remindDayList = new ArrayList<String>();
      remindDayList.add(TimeUtils.NONE);
      remindDayList.add(TimeUtils.ONE_DAY);
      remindDayList.add(TimeUtils.TWO_DAYS);
      remindDayList.add(TimeUtils.THREE_DAYS);
      remindDayList.add(TimeUtils.ONE_WEEK);

      ArrayAdapter<String> adapter =
          new ArrayAdapter<String>(
              getActivity(), android.R.layout.simple_spinner_item, remindDayList);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      remindDaysSpinner.setAdapter(adapter);
      remindDaysSpinner.setOnItemSelectedListener(this);

      remindDaysSpinner.setSelection(adapter.getPosition(reminder.getRemindDate()));
    }
    private void setUpReminderTextFields() {
      // Set the default values for text fields
      editTitle = (EditText) v.findViewById(R.id.editTextTitle);
      editDueDate = (EditText) v.findViewById(R.id.editTextDueDate);
      editAmount = (EditText) v.findViewById(R.id.editTextAmount);
      editPaid = (EditText) v.findViewById(R.id.editTextPaid);

      editTitle.setText(reminder.getTitle());
      if (reminder.getDueDate() == null || reminder.getDueDate() == "")
        editDueDate.setText(defaultCurDate);
      else editDueDate.setText(reminder.getDueDate());
      editAmount.setText("" + String.format("%.2f", reminder.getBilledAmount()));
      editPaid.setText("" + String.format("%.2f", reminder.getPaidAmount()));
    }
    private void saveReminder() {
      int id = reminder.getId();

      String newTitle = editTitle.getText().toString();
      String newDueDate = editDueDate.getText().toString();
      SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
      try {
        sdf.parse(newDueDate);
      } catch (ParseException e) {
        return;
      }
      double newBilledAmount = Double.parseDouble(editAmount.getText().toString());
      double newPaidAmount = Double.parseDouble(editPaid.getText().toString());
      boolean repeatAlarm = repeatAlarmBox.isChecked();

      DBManager dbManager = new DBManager(context);
      AlarmManagerBroadcastReceiver alarm = new AlarmManagerBroadcastReceiver();

      int repeatedFrequency = TimeUtils.days2sec(TimeUtils.getDaysInMonth());

      // ID is -1 if expense was just created??
      if (id <= 0) {
        if (repeatAlarm)
          alarm.setRepeatedDateAlarm(
              context, id, newDueDate, repeatedFrequency, "Reminder: " + newTitle + " is due! ");
        else
          alarm.setOneTimeDateAlarm(context, id, newDueDate, "Reminder: " + newTitle + " is due! ");

        if (newRemindDate != TimeUtils.NONE)
          alarm.setOneTimeDateAlarm(
              context,
              id + 42,
              TimeUtils.getRemindDate(newDueDate, newRemindDate),
              "Reminder: "
                  + newTitle
                  + " is due in "
                  + String.valueOf(TimeUtils.remindDateStr2Int(newRemindDate))
                  + " ");

        dbManager.addReminder(
            newTitle, newBilledAmount, newPaidAmount, newDueDate, newRemindDate, repeatAlarm);
      } else {
        if (newDueDate != dbManager.getReminders().get(id - 1).getDueDate()) {
          alarm.cancelAlarm(context, id);
          if (repeatAlarm)
            alarm.setRepeatedDateAlarm(
                context, id, newDueDate, repeatedFrequency, "Reminder: " + newTitle + " is due! ");
          else
            alarm.setOneTimeDateAlarm(
                context, id, newDueDate, "Reminder: " + newTitle + " is due! ");
        }
        if (newRemindDate != dbManager.getReminders().get(id - 1).getRemindDate()) {
          alarm.cancelAlarm(context, id + 42);
          if (newRemindDate != TimeUtils.NONE)
            alarm.setOneTimeDateAlarm(
                context,
                id + 42,
                TimeUtils.getRemindDate(newDueDate, newRemindDate),
                "Reminder: "
                    + newTitle
                    + " is due in "
                    + String.valueOf(TimeUtils.remindDateStr2Int(newRemindDate))
                    + " ");
        }

        dbManager.editReminder(
            id, newTitle, newBilledAmount, newPaidAmount, newDueDate, newRemindDate, repeatAlarm);
      }
    }
 private void setUpReminderDateFields(View v) {
   setUpRemindDaySpinner();
   setUpDatePicker(v);
   repeatAlarmBox = (CheckBox) v.findViewById(R.id.checkboxRepeatedAlarm);
   repeatAlarmBox.setChecked(reminder.isRemindAgain());
 }
    private void addItem(final Reminder reminder) {
      final int reminderID = reminder.getId();
      String title = reminder.getTitle();
      String billedAmt = String.valueOf(reminder.getBilledAmount());
      String paidAmt = String.valueOf(reminder.getPaidAmount());
      String unpaidAmt = String.valueOf(Double.valueOf(billedAmt) - Double.valueOf(paidAmt));
      String dueDate = reminder.getDueDate();

      int days = Integer.parseInt(TimeUtils.getDateDiffStr(dueDate));

      // Instantiate a new "row" view.
      final ViewGroup newView =
          (ViewGroup)
              LayoutInflater.from(context)
                  .inflate(R.layout.layoutchange_list_item, mContainerView, false);

      newView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              flipCard(reminder);
              return true;
            }
          });

      // Set the text in the new row to a random country.
      TextView reminderTitleView = (TextView) newView.findViewById(R.id.reminderTitle);
      reminderTitleView.setText(title);
      reminderTitleView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              flipCard(reminder);
              return true;
            }
          });

      TextView reminderAmtView = (TextView) newView.findViewById(R.id.reminderAmtInfo);
      reminderAmtView.setText("$" + unpaidAmt + " out of " + billedAmt + " unpaid");
      reminderAmtView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              flipCard(reminder);
              return true;
            }
          });

      TextView reminderDateView = (TextView) newView.findViewById(R.id.reminderDateInfo);
      if (days <= 1) reminderDateView.setText(days + " day unitl " + dueDate);
      else reminderDateView.setText(days + " days unitl " + dueDate);
      reminderDateView.setOnLongClickListener(
          new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
              flipCard(reminder);
              return true;
            }
          });

      // Set a click listener for the "X" button in the row that will remove the row.
      newView
          .findViewById(R.id.delete_button)
          .setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  AlarmManagerBroadcastReceiver alarm = new AlarmManagerBroadcastReceiver();
                  alarm.cancelAlarm(context, reminderID);

                  dbManager.deleteReminder(reminderID);

                  // Remove the row from its parent (the container view).
                  // Because mContainerView has android:animateLayoutChanges set to true,
                  // this removal is automatically animated.
                  mContainerView.removeView(newView);

                  // If there are no rows remaining, show the empty view.
                  if (mContainerView.getChildCount() == 0) emptyText.setVisibility(View.VISIBLE);
                }
              });

      // Because mContainerView has android:animateLayoutChanges set to true,
      // adding this view is automatically animated.
      mContainerView.addView(newView, 0);
    }