public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (isChecked) {
      if (mDueTime.hour == 0 && mDueTime.minute == 0) {
        mDueTime.monthDay--;

        // Do not allow an event to have an end time before the start time.
        if (mDueTime.before(mStartTime)) {
          mDueTime.set(mStartTime);
        }
      }
    } else {
      if (mDueTime.hour == 0 && mDueTime.minute == 0) {
        mDueTime.monthDay++;
      }
    }

    mShowStart = true;
    long startMillis = mStartTime.normalize(true);
    setDate(mStartDateButton, startMillis, mShowStart);
    setTime(mStartTimeButton, startMillis, mShowStart);

    mShowDue = true;
    long dueMillis = mDueTime.normalize(true);
    setDate(mDueDateButton, dueMillis, mShowDue);
    setTime(mDueTimeButton, dueMillis, mShowDue);

    updateTimeVisibility(!isChecked);
  }
  private float getBalance(Calendar cellDate) {
    float balance = 0;

    Time selectedDate = new Time();
    selectedDate.set(cellDate.getTimeInMillis());

    Time inputDate = new Time();

    for (Finance_Input input : inputs) {
      inputDate.set(input.getOccurs().toMillis(false));
      boolean onetime = false;
      while ((inputDate.before(selectedDate) || inputDate.equals(selectedDate))
          && !onetime
          && input.getAmount() > 0) {
        if (input.getType().equals(Finance_Constants.INCOME)) {
          balance += input.getAmount();
        } else {
          balance -= input.getAmount();
        }
        inputDate = Finance_Util.adjustDate(input.getOccurstype(), inputDate);
        if (input.getOccurstype().equals(Finance_Constants.OCCURTYPE_ONETIME)) {
          onetime = true;
        }
      }
    }

    return balance;
  }
Example #3
0
        @Override
        public void populateView(
            View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags) {
          TextView title = (TextView) view.findViewById(android.R.id.title);
          if (title != null) {
            String text = cursor.getString(5);
            title.setText(text);
          }

          Integer status = cursor.getInt(11);

          TextView dueDateField = (TextView) view.findViewById(R.id.task_due_date);
          if (dueDateField != null) {
            Time dueDate = Common.DUE_ADAPTER.get(cursor);

            if (dueDate != null) {
              if (mNow == null) {
                mNow = new Time();
              }
              mNow.clear(TimeZone.getDefault().getID());
              mNow.setToNow();

              if (status == null || status < Tasks.STATUS_COMPLETED) {

                dueDateField.setText(makeDueDate(dueDate));

                // highlight overdue dates & times
                if (dueDate.before(mNow)) {
                  dueDateField.setTextColor(Color.RED);
                } else {
                  dueDateField.setTextColor(Color.argb(255, 0x80, 0x80, 0x80));
                }
              } else {
                Long completed = cursor.getLong(12);
                if (completed != null) {
                  Time complTime = new Time(Time.TIMEZONE_UTC);
                  complTime.set(completed);

                  dueDateField.setText(makeDueDate(complTime));

                  // highlight if the task has been completed after the due date
                  if (dueDate.after(complTime)) {
                    dueDateField.setTextColor(Color.RED);
                  } else {
                    dueDateField.setTextColor(Color.argb(255, 0x80, 0x80, 0x80));
                  }
                } else {
                  // TODO: what do we show then there is no completed date?
                }
              }
            } else {
              dueDateField.setText("");
            }
          }

          View colorbar = view.findViewById(R.id.colorbar);
          if (colorbar != null) {
            colorbar.setBackgroundColor(cursor.getInt(6));
          }
        }
    public void onDateSet(DatePicker view, int year, int month, int monthDay) {
      // Cache the member variables locally to avoid inner class overhead.
      Time startTime = mStartTime;
      Time dueTime = mDueTime;

      // Cache the start and due millis so that we limit the number
      // of calls to normalize() and toMillis(), which are fairly
      // expensive.
      long startMillis;
      long dueMillis;
      if (mView == mStartDateButton) {
        // The start date was changed.
        int yearDuration = dueTime.year - startTime.year;
        int monthDuration = dueTime.month - startTime.month;
        int monthDayDuration = dueTime.monthDay - startTime.monthDay;

        startTime.year = year;
        startTime.month = month;
        startTime.monthDay = monthDay;
        startMillis = startTime.normalize(true);
        mShowStart = true;

        // Also update the end date to keep the duration constant.
        dueTime.year = year + yearDuration;
        dueTime.month = month + monthDuration;
        dueTime.monthDay = monthDay + monthDayDuration;
        dueMillis = dueTime.normalize(true);
        mShowDue = true;
      } else {
        // The end date was changed.
        startMillis = startTime.toMillis(true);
        dueTime.year = year;
        dueTime.month = month;
        dueTime.monthDay = monthDay;
        dueMillis = dueTime.normalize(true);
        mShowDue = true;

        if (mShowStart) {
          // Do not allow an event to have an end time before the start time.
          if (dueTime.before(startTime)) {
            dueTime.set(startTime);
            dueMillis = startMillis;
          }
        } else {
          // if start time is not shown, default it to be the same as due time
          startTime.set(dueTime);
          mShowStart = true;
        }
      }

      // update all 4 buttons in case visibility has changed
      setDate(mStartDateButton, startMillis, mShowStart);
      setTime(mStartTimeButton, startMillis, mShowStart);
      setDate(mDueDateButton, dueMillis, mShowDue);
      setTime(mDueTimeButton, dueMillis, mShowDue);
      updateCalendarPanel();
    }