Example usage for android.text.format Time before

List of usage examples for android.text.format Time before

Introduction

In this page you can find the example usage for android.text.format Time before.

Prototype

public boolean before(Time that) 

Source Link

Document

Returns true if the time represented by this Time object occurs before the given time.

Usage

From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java

private static String makePinNotificationContentText(Context context, ContentSet task) {
    boolean isAllDay = TaskFieldAdapters.ALLDAY.get(task);
    Time now = new Time();
    now.setToNow();// w  w w . j  a va 2s .  c o m
    now.minute--;
    Time start = TaskFieldAdapters.DTSTART.get(task);
    Time due = TaskFieldAdapters.DUE.get(task);

    if (start != null && start.toMillis(true) > 0 && (now.before(start) || due == null)) {
        start.allDay = isAllDay;
        String startString = context.getString(R.string.notification_task_start_date,
                NotificationActionUtils.formatTime(context, start));
        return startString;
    }

    if (due != null && due.toMillis(true) > 0) {
        due.allDay = isAllDay;
        String dueString = context.getString(R.string.notification_task_due_date,
                NotificationActionUtils.formatTime(context, due));
        return dueString;
    }

    String description = TaskFieldAdapters.DESCRIPTION.get(task);
    if (description != null) {
        description = description.replaceAll("\\[\\s?\\]", "?").replaceAll("\\[[xX]\\]", "");

    }
    return description;
}

From source file:it.sasabz.android.sasabus.fragments.OrarioFragment.java

/**
 * This method gets the next departure time and returns the
 * index of this element//www  .j a  v a  2 s.  c o  m
 * @param c is the cursor to the list_view
 * @return the index of the next departure time
 */
private int getNextTimePosition(Vector<Passaggio> list) {
    int count = list.size();
    if (count == 0) {
        return -1;
    } else if (count == 1) {
        return 0;
    } else {
        int i = 0;
        boolean found = false;
        while (i <= count - 2 && !found) {
            Time currentTime = new Time();
            Time sasaTime = new Time();
            Time sasaTimeNext = new Time();
            currentTime.setToNow();
            sasaTime = list.get(i).getOrario();
            sasaTimeNext = list.get(i + 1).getOrario();

            if (sasaTime.after(currentTime) || sasaTime.equals(currentTime) || sasaTime.before(currentTime)
                    && (sasaTimeNext.equals(currentTime) || sasaTimeNext.after(currentTime))) {
                found = true;
            } else {
                i++;
            }
        }
        return i;
    }
}

From source file:it.sasabz.android.sasabus.fragments.WayFragment.java

/**
 * This method gets the next departure time and returns the
 * index of this element//from   w  w  w.ja v  a  2s.  c o m
 * @param c is the cursor to the list_view
 * @return the index of the next departure time
 */
private int getNextTimePosition(Vector<Passaggio> list) {
    int count = 0;
    if (list != null) {
        count = list.size();
    }
    if (count == 0) {
        return -1;
    } else if (count == 1) {
        return 0;
    } else {
        int i = 0;
        boolean found = false;
        while (i <= count - 2 && !found) {
            Time currentTime = new Time();
            Time sasaTime = new Time();
            Time sasaTimeNext = new Time();
            currentTime.setToNow();
            sasaTime = list.get(i).getOrario();
            sasaTimeNext = list.get(i + 1).getOrario();

            if (sasaTime.after(currentTime) || sasaTime.equals(currentTime) || sasaTime.before(currentTime)
                    && (sasaTimeNext.equals(currentTime) || sasaTimeNext.after(currentTime))) {
                found = true;
            } else {
                i++;
            }
        }
        return i;
    }
}

From source file:com.granita.tasks.groupings.BaseTaskViewDescriptor.java

protected void setDueDate(TextView view, ImageView dueIcon, Time dueDate, boolean isClosed) {
    if (view != null && dueDate != null) {
        Time now = mNow;/*  w ww  .  j  a va2  s .  co m*/
        if (now == null) {
            now = mNow = new Time();
        }
        if (!now.timezone.equals(TimeZone.getDefault().getID())) {
            now.clear(TimeZone.getDefault().getID());
        }

        if (Math.abs(now.toMillis(false) - System.currentTimeMillis()) > 5000) {
            now.setToNow();
            now.normalize(true);
        }

        dueDate.normalize(true);

        view.setText(new DateFormatter(view.getContext()).format(dueDate, now, DateFormatContext.LIST_VIEW));
        if (dueIcon != null) {
            dueIcon.setVisibility(View.VISIBLE);
        }

        // highlight overdue dates & times, handle allDay tasks separately
        if ((!dueDate.allDay && dueDate.before(now) || dueDate.allDay
                && (dueDate.year < now.year || dueDate.yearDay <= now.yearDay && dueDate.year == now.year))
                && !isClosed) {
            view.setTextAppearance(view.getContext(), R.style.task_list_overdue_text);
        } else {
            view.setTextAppearance(view.getContext(), R.style.task_list_due_text);
        }
    } else if (view != null) {
        view.setText("");
        if (dueIcon != null) {
            dueIcon.setVisibility(View.GONE);
        }
    }
}