Java Code Examples for android.text.format.DateUtils#FORMAT_NO_MIDNIGHT

The following examples show how to use android.text.format.DateUtils#FORMAT_NO_MIDNIGHT . 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: Utils.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public static String formatTime(Context context, long when) {
	// TODO: DateUtils should make this easier
	Time then = new Time();
	then.set(when);
	Time now = new Time();
	now.setToNow();

	int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL;

	if (then.year != now.year) {
		flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
	} else if (then.yearDay != now.yearDay) {
		flags |= DateUtils.FORMAT_SHOW_DATE;
	} else {
		flags |= DateUtils.FORMAT_SHOW_TIME;
	}

	return DateUtils.formatDateTime(context, when, flags);
}
 
Example 2
Source File: Utils.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public static String formatTime(Context context, long when) {
	// TODO: DateUtils should make this easier
	Time then = new Time();
	then.set(when);
	Time now = new Time();
	now.setToNow();

	int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL;

	if (then.year != now.year) {
		flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
	} else if (then.yearDay != now.yearDay) {
		flags |= DateUtils.FORMAT_SHOW_DATE;
	} else {
		flags |= DateUtils.FORMAT_SHOW_TIME;
	}

	return DateUtils.formatDateTime(context, when, flags);
}
 
Example 3
Source File: Utils.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
public static String formatTime(Context context, long when) {
	// TODO: DateUtils should make this easier
	Time then = new Time();
	then.set(when);
	Time now = new Time();
	now.setToNow();

	int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL;

	if (then.year != now.year) {
		flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
	} else if (then.yearDay != now.yearDay) {
		flags |= DateUtils.FORMAT_SHOW_DATE;
	} else {
		flags |= DateUtils.FORMAT_SHOW_TIME;
	}

	return DateUtils.formatDateTime(context, when, flags);
}
 
Example 4
Source File: LocationService.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
public void tryToSaveTrack() {
    mLastTrack = getTrack();
    if (mLastTrack.points.size() == 0)
        return;

    long startTime = mLastTrack.points.get(0).time;
    long stopTime = mLastTrack.getLastPoint().time;
    long period = stopTime - startTime;
    int flags = DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT;

    if (period < DateUtils.WEEK_IN_MILLIS)
        flags |= DateUtils.FORMAT_SHOW_TIME;

    if (period < DateUtils.WEEK_IN_MILLIS * 4)
        flags |= DateUtils.FORMAT_SHOW_WEEKDAY;

    //TODO Try to 'guess' starting and ending location name
    mLastTrack.description = DateUtils.formatDateRange(this, startTime, stopTime, flags) +
            " \u2014 " + StringFormatter.distanceH(mLastTrack.getDistance());
    flags |= DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    mLastTrack.name = DateUtils.formatDateRange(this, startTime, stopTime, flags);

    if (period < TOO_SMALL_PERIOD) {
        sendBroadcast(new Intent(BROADCAST_TRACK_SAVE)
                .putExtra("saved", false)
                .putExtra("reason", "period"));
        clearTrack();
        return;
    }

    if (mLastTrack.getDistance() < TOO_SMALL_DISTANCE) {
        sendBroadcast(new Intent(BROADCAST_TRACK_SAVE)
                .putExtra("saved", false)
                .putExtra("reason", "distance"));
        clearTrack();
        return;
    }
    saveTrack();
}
 
Example 5
Source File: MainActivity.java    From samples with MIT License 4 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    final long min;
    switch (item.getItemId()) {
        case R.id.min_0:
            min = 0l;
            break;
        case R.id.min_min:
            min = DateUtils.MINUTE_IN_MILLIS;
            break;
        case R.id.min_hour:
            min = DateUtils.HOUR_IN_MILLIS;
            break;
        case R.id.min_day:
            min = DateUtils.DAY_IN_MILLIS;
            break;
        default:
            min = -1;
            break;
    }

    if (min >= 0) {
        item.setChecked(true);
        mAdapter.setMinResolution(min);
        return true;
    }

    item.setChecked(!item.isChecked());
    final int flag;
    switch (item.getItemId()) {
        case R.id.FORMAT_SHOW_TIME:
            flag = DateUtils.FORMAT_SHOW_TIME;
            break;
        case R.id.FORMAT_SHOW_WEEKDAY:
            flag = DateUtils.FORMAT_SHOW_WEEKDAY;
            break;
        case R.id.FORMAT_SHOW_YEAR:
            flag = DateUtils.FORMAT_SHOW_YEAR;
            break;
        case R.id.FORMAT_NO_YEAR:
            flag = DateUtils.FORMAT_NO_YEAR;
            break;
        case R.id.FORMAT_SHOW_DATE:
            flag = DateUtils.FORMAT_SHOW_DATE;
            break;
        case R.id.FORMAT_NO_MONTH_DAY:
            flag = DateUtils.FORMAT_NO_MONTH_DAY;
            break;
        case R.id.FORMAT_NO_NOON:
            flag = DateUtils.FORMAT_NO_NOON;
            break;
        case R.id.FORMAT_NO_MIDNIGHT:
            flag = DateUtils.FORMAT_NO_MIDNIGHT;
            break;
        case R.id.FORMAT_ABBREV_TIME:
            flag = DateUtils.FORMAT_ABBREV_TIME;
            break;
        case R.id.FORMAT_ABBREV_WEEKDAY:
            flag = DateUtils.FORMAT_ABBREV_WEEKDAY;
            break;
        case R.id.FORMAT_ABBREV_MONTH:
            flag = DateUtils.FORMAT_ABBREV_MONTH;
            break;
        case R.id.FORMAT_NUMERIC_DATE:
            flag = DateUtils.FORMAT_NUMERIC_DATE;
            break;
        case R.id.FORMAT_ABBREV_RELATIVE:
            flag = DateUtils.FORMAT_ABBREV_RELATIVE;
            break;
        case R.id.FORMAT_ABBREV_ALL:
            flag = DateUtils.FORMAT_ABBREV_ALL;
            break;
        default:
            throw new UnsupportedOperationException("unknown id");
    }

    if (item.isChecked()) {
        mAdapter.addFlag(flag);
    } else {
        mAdapter.removeFlag(flag);
    }

    return true;
}