Пример #1
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));
          }
        }
Пример #2
0
    @Override
    public void onVisibilityChanged(boolean visible) {
      super.onVisibilityChanged(visible);

      if (visible) {
        registerTimeReceiver();

        mTime.clear(TimeZone.getDefault().getID());
        mTime.setToNow();
      } else {
        unregisterReceiver();
      }
      updateTimer();
    }
    @Override
    public void onVisibilityChanged(boolean visible) {
      super.onVisibilityChanged(visible);

      if (visible) {
        registerReceiver();

        // Update time zone in case it changed while we weren't visible.
        mTime.clear(TimeZone.getDefault().getID());
        mTime.setToNow();
      } else {
        unregisterReceiver();
      }

      // Whether the timer should be running depends on whether we're visible (as well as
      // whether we're in ambient mode), so we may need to start or stop the timer.
      updateTimer();
    }
Пример #4
0
  /**
   * Format the given due date. The result depends on the current date and on the all-day flag of
   * the due date.
   *
   * <p>If the due date it today the format will contain "today" instead of the date. Allday dates
   * won't contain a time.
   *
   * @param dueDate The due date to format.
   * @return A string with the formatted due date.
   */
  public String format(Time dueDate) {
    mNow.clear(TimeZone.getDefault().getID());
    mNow.setToNow();

    if (!dueDate.allDay) {
      dueDate.switchTimezone(TimeZone.getDefault().getID());
    }

    // normalize time to ensure yearDay is set properly
    dueDate.normalize(false);

    if (dueDate.year == mNow.year && dueDate.yearDay == mNow.yearDay) {
      if (dueDate.allDay) {
        return mContext.getString(R.string.today);
      } else {
        return mContext.getString(R.string.today)
            + ", "
            + mTimeFormatter.format(new Date(dueDate.toMillis(false)));
      }
    } else {
      return mDateFormatter.format(new Date(dueDate.toMillis(false)));
    }
  }
 @Override
 public void onReceive(Context context, Intent intent) {
   mTime.clear(intent.getStringExtra("time-zone"));
   mTime.setToNow();
 }