Java Code Examples for android.text.format.DateUtils#getRelativeDateTimeString()

The following examples show how to use android.text.format.DateUtils#getRelativeDateTimeString() . 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: DoorbellEntryAdapter.java    From doorbell with Apache License 2.0 5 votes vote down vote up
@Override
protected void onBindViewHolder(DoorbellEntryViewHolder holder, int position, DoorbellEntry model) {
    // Display the timestamp
    CharSequence prettyTime = DateUtils.getRelativeDateTimeString(mApplicationContext,
            model.getTimestamp(), DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0);
    holder.time.setText(prettyTime);

    // Display the image
    if (model.getImage() != null) {
        StorageReference imageRef = mFirebaseStorage.getReferenceFromUrl(model.getImage());

        GlideApp.with(mApplicationContext)
                .load(imageRef)
                .placeholder(R.drawable.ic_image)
                .into(holder.image);
    }

    // Display the metadata
    if (model.getAnnotations() != null) {
        ArrayList<String> keywords = new ArrayList<>(model.getAnnotations().keySet());

        int limit = Math.min(keywords.size(), 3);
        holder.metadata.setText(TextUtils.join("\n", keywords.subList(0, limit)));
    } else {
        holder.metadata.setText("no annotations yet");
    }
}
 
Example 2
Source File: DisplayUtils.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static CharSequence getRelativeDateTimeString (
        Context c, long time, long minResolution, long transitionResolution, int flags
        ){
    
    CharSequence dateString = "";
    
    // in Future
    if (time > System.currentTimeMillis()){
        return DisplayUtils.unixTimeToHumanReadable(time);
    } 
    // < 60 seconds -> seconds ago
    else if ((System.currentTimeMillis() - time) < 60 * 1000) {
        return c.getString(R.string.file_list_seconds_ago);
    } else {
        // Workaround 2.x bug (see https://github.com/owncloud/android/issues/716)
        if (    Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && 
                (System.currentTimeMillis() - time) > 24 * 60 * 60 * 1000   ) {
            Date date = new Date(time);
            date.setHours(0);
            date.setMinutes(0);
            date.setSeconds(0);
            dateString = DateUtils.getRelativeDateTimeString(
                    c, date.getTime(), minResolution, transitionResolution, flags
            );
        } else {
            dateString = DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);
        }
    }
    
    return dateString.toString().split(",")[0];
}
 
Example 3
Source File: SessionManagerActivity.java    From sniffer154 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
	switch (view.getId()) {
	case R.id.textDate:
		Long time = cursor.getLong(columnIndex);
		CharSequence cs = DateUtils
				.getRelativeDateTimeString(SessionManagerActivity.this,
						time, DateUtils.MINUTE_IN_MILLIS,
						DateUtils.WEEK_IN_MILLIS, 0);
		((TextView) view).setText(cs);
		return true;
	default:
		return false;
	}
}
 
Example 4
Source File: DateFormatter.java    From opentasks with Apache License 2.0 3 votes vote down vote up
/**
 * Routes between old and current version of {@link DateUtils#getRelativeDateTimeString(Context, long, long, long, int)}
 * in order to work around the framework bug introduced in Android 6 for this method:
 * not using the user's 12/24 hours settings for the time format.
 * <p>
 * The reported bugs:
 * <p>
 * <a href="https://github.com/dmfs/opentasks/issues/396">opentasks/396</a>
 * <p>
 * <a href="https://issuetracker.google.com/issues/37127319">google/37127319</a>
 */
private CharSequence routingGetRelativeDateTimeString(Context c, long time, long minResolution,
                                                      long transitionResolution, int flags)
{
    return isDefaultLocale12HourFormat() ?
            oldGetRelativeDateTimeString(c, time, minResolution, transitionResolution, flags)
            : DateUtils.getRelativeDateTimeString(c, time, minResolution, transitionResolution, flags);
}