Java Code Examples for android.text.format.Time#before()

The following examples show how to use android.text.format.Time#before() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultBefore.java    From opentasks with Apache License 2.0 6 votes vote down vote up
@Override
public Time getCustomDefault(ContentSet currentValues, Time genericDefault)
{
    Time reference = mReferenceAdapter != null ? mReferenceAdapter.get(currentValues) : null;
    boolean useReference = reference != null && !genericDefault.before(reference);
    Time value = new Time(useReference ? reference : genericDefault);
    if (value.allDay)
    {
        value.set(value.monthDay - (useReference ? 1 : 0), value.month, value.year);
    }
    else
    {
        value.minute--;
        value.normalize(false);
        value.second = 0;
        value.minute = 0;
    }
    return value;
}
 
Example 2
Source File: Utils.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
public static boolean isInOneMonth(long when) {
    Time time = new Time();
    time.set(when + DAY_30);
    Time now = new Time();
    now.setToNow();
    if (time.before(now)) {
        return false;
    }
    return true;
}
 
Example 3
Source File: BeforeOrShiftTime.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public Time apply(ContentSet currentValues, Time oldValue, Time newValue)
{
    Time reference = mReferenceAdapter.get(currentValues);
    if (reference != null && newValue != null)
    {
        if (oldValue != null && !newValue.before(reference))
        {
            // try to shift the reference value
            long diff = newValue.toMillis(false) - oldValue.toMillis(false);
            if (diff > 0)
            {
                boolean isAllDay = reference.allDay;
                reference.set(reference.toMillis(false) + diff);

                // ensure the event is still allday if is was allday before.
                if (isAllDay)
                {
                    reference.set(reference.monthDay, reference.month, reference.year);
                }
                mReferenceAdapter.set(currentValues, reference);
            }
        }
        if (!newValue.before(reference))
        {
            // constraint is still violated, so set reference to its default value
            reference.set(mDefault.getCustomDefault(currentValues, newValue));
            mReferenceAdapter.set(currentValues, reference);
        }
    }
    return newValue;
}
 
Example 4
Source File: NotBefore.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public Time apply(ContentSet currentValues, Time oldValue, Time newValue)
{
    Time notBeforeThisTime = mTimeAdapter.get(currentValues);
    if (notBeforeThisTime != null && newValue != null)
    {
        if (newValue.before(notBeforeThisTime))
        {
            newValue.set(notBeforeThisTime);
        }
    }
    return newValue;
}
 
Example 5
Source File: BaseTaskViewDescriptor.java    From opentasks with Apache License 2.0 4 votes vote down vote up
protected void setDueDate(TextView view, ImageView dueIcon, Time dueDate, boolean isClosed)
{
    if (view != null && dueDate != null)
    {
        Time now = mNow;
        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);
        }
    }
}