下面列出了android.text.format.Time#before ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
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;
}
@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;
}
@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;
}
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);
}
}
}