本文整理汇总了Java中android.text.format.DateUtils.getRelativeTimeSpanString方法的典型用法代码示例。如果您正苦于以下问题:Java DateUtils.getRelativeTimeSpanString方法的具体用法?Java DateUtils.getRelativeTimeSpanString怎么用?Java DateUtils.getRelativeTimeSpanString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.format.DateUtils
的用法示例。
在下文中一共展示了DateUtils.getRelativeTimeSpanString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildFolderStatus
import android.text.format.DateUtils; //导入方法依赖的package包/类
private String buildFolderStatus(FolderInfoHolder folder) {
String folderStatus;
if (folder.loading) {
folderStatus = getString(R.string.status_loading);
} else if (folder.status != null) {
folderStatus = folder.status;
} else if (folder.lastChecked != 0) {
long now = System.currentTimeMillis();
int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
CharSequence formattedDate;
if (Math.abs(now - folder.lastChecked) > DateUtils.WEEK_IN_MILLIS) {
formattedDate = getString(R.string.preposition_for_date,
DateUtils.formatDateTime(context, folder.lastChecked, flags));
} else {
formattedDate = DateUtils.getRelativeTimeSpanString(folder.lastChecked,
now, DateUtils.MINUTE_IN_MILLIS, flags);
}
folderStatus = getString(folder.pushActive
? R.string.last_refresh_time_format_with_push
: R.string.last_refresh_time_format,
formattedDate);
} else {
folderStatus = null;
}
return folderStatus;
}
示例2: getApplicationVersion
import android.text.format.DateUtils; //导入方法依赖的package包/类
/**
* Build the application version to be shown. In particular, this ensures the debug build
* versions are more useful.
*/
public static String getApplicationVersion(Context context, String version) {
if (ChromeVersionInfo.isOfficialBuild()) {
return version;
}
// For developer builds, show how recently the app was installed/updated.
PackageInfo info;
try {
info = context.getPackageManager().getPackageInfo(
context.getPackageName(), 0);
} catch (NameNotFoundException e) {
return version;
}
CharSequence updateTimeString = DateUtils.getRelativeTimeSpanString(
info.lastUpdateTime, System.currentTimeMillis(), 0);
return context.getString(R.string.version_with_update_time, version,
updateTimeString);
}
示例3: onBindViewHolder
import android.text.format.DateUtils; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(DiaryEntryAdapter.ViewHolder viewHolder, int position) {
DiaryEntry entry = mDiaryEntries.get(position);
viewHolder.text1.setText(entry.getText1());
viewHolder.text2.setText(entry.getText2());
viewHolder.text3.setText(entry.getText3());
viewHolder.text4.setText(entry.getText4());
viewHolder.text5.setText(entry.getText5());
// Convert timestamp to useful string description based on age
long now = System.currentTimeMillis();
CharSequence ago = DateUtils.getRelativeTimeSpanString(
entry.getCreationTimestamp(),
now,
DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_ALL);
viewHolder.time.setText(ago);
}
示例4: getOperation
import android.text.format.DateUtils; //导入方法依赖的package包/类
public String getOperation(Context context) {
synchronized (lock) {
if (loadingAccountDescription != null ||
sendingAccountDescription != null ||
loadingHeaderFolderId != null ||
processingAccountDescription != null) {
return getActionInProgressOperation(context);
}
}
long nextPollTime = MailService.getNextPollTime();
if (nextPollTime != -1) {
CharSequence relativeTimeSpanString = DateUtils.getRelativeTimeSpanString(
nextPollTime, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0);
return context.getString(R.string.status_next_poll, relativeTimeSpanString);
} else if (QMail.isDebug() && MailService.isSyncDisabled()) {
if (MailService.hasNoConnectivity()) {
return context.getString(R.string.status_no_network);
} else if (MailService.isSyncNoBackground()) {
return context.getString(R.string.status_no_background);
} else if (MailService.isSyncBlocked()) {
return context.getString(R.string.status_syncing_blocked);
} else if (MailService.isPollAndPushDisabled()) {
return context.getString(R.string.status_poll_and_push_disabled);
} else {
return context.getString(R.string.status_syncing_off);
}
} else if (MailService.isSyncDisabled()) {
return context.getString(R.string.status_syncing_off);
} else {
return "";
}
}
示例5: getChildView
import android.text.format.DateUtils; //导入方法依赖的package包/类
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
ViewHolderNotes viewHolderNotes;
if (convertView == null) {
convertView = inflater.inflate (R.layout.custom_row_notes, parent, false);
viewHolderNotes = new ViewHolderNotes (convertView);
convertView.setTag (viewHolderNotes);
} else {
viewHolderNotes = (ViewHolderNotes) convertView.getTag ();
}
NoteUtil noteUtil = new NoteUtil (mContext);
JSONArray jsonArrayNotesTag = null;
try {
jsonArrayNotesTag = noteUtil.getNotesForATag (mSectionID, noteUtil
.getDistinctTags (mSectionID).getJSONObject (groupPosition).toString ());
JSONObject jsonObject;
String noteText = mContext.getString (R.string.lorem_ipsum_str), noteDateStamp = mContext.getString (R.string.lorem_ipsum_str), titleText = mContext.getString (R.string.lorem_ipsum_str);
long noteTimeInMillis;
jsonObject = jsonArrayNotesTag.getJSONObject (childPosition);
noteText = jsonObject.getString (GlobalData.NOTE_BODY);
noteTimeInMillis = jsonObject.getLong (GlobalData.NOTE_TIME_MILLIS);
noteDateStamp = (String) DateUtils.getRelativeTimeSpanString (noteTimeInMillis, System.currentTimeMillis (), 3, DateUtils.FORMAT_ABBREV_RELATIVE);
titleText = jsonObject.getString (GlobalData.NOTE_TITLE);
viewHolderNotes.notes.setText (noteText);
viewHolderNotes.date.setText (noteDateStamp);
viewHolderNotes.title.setText (titleText);
} catch (JSONException e) {
e.printStackTrace ();
}
viewHolderNotes.popupMenuDots.setVisibility (View.INVISIBLE);
return convertView;
}
示例6: manipulateDateFormat
import android.text.format.DateUtils; //导入方法依赖的package包/类
public static String manipulateDateFormat(String post_date) {
if (post_date == null)
return ""; //if no date is returned by the API then set corresponding date view to empty
if (post_date.equals("0001-01-01T00:00:00Z")) //because Times of India is always returning this in time stamp which is Jan1,1 (wrong information they are sending)
return "";
SimpleDateFormat existingUTCFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = null;
try {
date = existingUTCFormat.parse(post_date);
} catch (ParseException e) {
e.printStackTrace();
}
if (date != null) {
// Converting timestamp into x ago format
CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(
Long.parseLong(String.valueOf(date.getTime())),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
return timeAgo + "";
} else {
return post_date;
}
}
示例7: getTimeAgo
import android.text.format.DateUtils; //导入方法依赖的package包/类
@NonNull public static CharSequence getTimeAgo(@Nullable String toParse) {
try {
Date parsedDate = getInstance().dateFormat.parse(toParse);
long now = System.currentTimeMillis();
return DateUtils.getRelativeTimeSpanString(parsedDate.getTime(), now, DateUtils.SECOND_IN_MILLIS);
} catch (Exception e) {
e.printStackTrace();
}
return "N/A";
}
示例8: getRelativeTimeSpanString
import android.text.format.DateUtils; //导入方法依赖的package包/类
public static CharSequence getRelativeTimeSpanString(Context context, long time) {
long now = System.currentTimeMillis();
long range = Math.abs(now - time);
if (range < NOW_TIME_RANGE) {
return context.getString(R.string.now_time_range);
}
return DateUtils.getRelativeTimeSpanString(time, now, DateUtils.MINUTE_IN_MILLIS);
}
示例9: manipulateDateFormat
import android.text.format.DateUtils; //导入方法依赖的package包/类
public static String manipulateDateFormat(String post_date) {
if (post_date == null)
return ""; //if no date is returned by the API then set corresponding date view to empty
if (post_date.equals("0001-01-01T00:00:00Z")) //because Times of India is always returning this in time stamp which is Jan1,1 (wrong information they are sending)
return "";
SimpleDateFormat existingUTCFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date date = null;
if(!post_date.equals("")) {
try {
date = existingUTCFormat.parse(post_date);
} catch (ParseException e) {
e.printStackTrace();
}
}
if (date != null) {
// Converting timestamp into x ago format
CharSequence timeAgo = DateUtils.getRelativeTimeSpanString(
Long.parseLong(String.valueOf(date.getTime())),
System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
return timeAgo + "";
} else {
return post_date;
}
}
示例10: onBindViewHolder
import android.text.format.DateUtils; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(ItemViewHolder holder, int position) {
HostViewHolder hostHolder = (HostViewHolder) holder;
HostBean host = hosts.get(position);
hostHolder.host = host;
if (host == null) {
// Well, something bad happened. We can't continue.
Log.e("HostAdapter", "Host bean is null!");
hostHolder.nickname.setText("Error during lookup");
} else {
hostHolder.nickname.setText(host.getNickname());
}
switch (this.getConnectedState(host)) {
case STATE_UNKNOWN:
hostHolder.icon.setImageState(new int[] { }, true);
hostHolder.icon.setContentDescription(null);
if (Build.VERSION.SDK_INT >= 16) {
hideFromAccessibility(hostHolder.icon, true);
}
break;
case STATE_CONNECTED:
hostHolder.icon.setImageState(new int[] { android.R.attr.state_checked }, true);
hostHolder.icon.setContentDescription(getString(R.string.image_description_connected));
if (Build.VERSION.SDK_INT >= 16) {
hideFromAccessibility(hostHolder.icon, false);
}
break;
case STATE_DISCONNECTED:
hostHolder.icon.setImageState(new int[] { android.R.attr.state_expanded }, true);
hostHolder.icon.setContentDescription(getString(R.string.image_description_disconnected));
if (Build.VERSION.SDK_INT >= 16) {
hideFromAccessibility(hostHolder.icon, false);
}
break;
default:
Log.e("HostAdapter", "Unknown host state encountered: " + getConnectedState(host));
}
@StyleRes final int chosenStyleFirstLine;
@StyleRes final int chosenStyleSecondLine;
if (HostDatabase.COLOR_RED.equals(host.getColor())) {
chosenStyleFirstLine = R.style.ListItemFirstLineText_Red;
chosenStyleSecondLine = R.style.ListItemSecondLineText_Red;
} else if (HostDatabase.COLOR_GREEN.equals(host.getColor())) {
chosenStyleFirstLine = R.style.ListItemFirstLineText_Green;
chosenStyleSecondLine = R.style.ListItemSecondLineText_Green;
} else if (HostDatabase.COLOR_BLUE.equals(host.getColor())) {
chosenStyleFirstLine = R.style.ListItemFirstLineText_Blue;
chosenStyleSecondLine = R.style.ListItemSecondLineText_Blue;
} else {
chosenStyleFirstLine = R.style.ListItemFirstLineText;
chosenStyleSecondLine = R.style.ListItemSecondLineText;
}
hostHolder.nickname.setTextAppearance(context, chosenStyleFirstLine);
hostHolder.caption.setTextAppearance(context, chosenStyleSecondLine);
CharSequence nice = context.getString(R.string.bind_never);
if (host.getLastConnect() > 0) {
nice = DateUtils.getRelativeTimeSpanString(host.getLastConnect() * 1000);
}
hostHolder.caption.setText(nice);
}
示例11: getRelativeTimeSpanString
import android.text.format.DateUtils; //导入方法依赖的package包/类
public CharSequence getRelativeTimeSpanString(long time, long now, long minResolution)
{
return DateUtils.getRelativeTimeSpanString(time, now, minResolution);
}
示例12: setPhoneCallDetails
import android.text.format.DateUtils; //导入方法依赖的package包/类
/** Fills the call details views with content. */
public void setPhoneCallDetails(PhoneCallDetailsViews views, PhoneCallDetails details) {
// Display up to a given number of icons.
views.callTypeIcons.clear();
int count = details.callTypes.length;
for (int index = 0; index < count && index < MAX_CALL_TYPE_ICONS; ++index) {
views.callTypeIcons.add(details.callTypes[index]);
}
views.callTypeIcons.setVisibility(View.VISIBLE);
// Show the total call count only if there are more than the maximum
// number of icons.
Integer callCount;
if (count > MAX_CALL_TYPE_ICONS) {
callCount = count;
} else {
callCount = null;
}
// The date of this call, relative to the current time.
CharSequence dateText =
DateUtils.getRelativeTimeSpanString(details.date,
getCurrentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE);
// Set the call count and date.
setCallCountAndDate(views, callCount, dateText);
// Display number and display name
CharSequence displayName;
if (!TextUtils.isEmpty(details.name)) {
displayName = details.name;
} else {
// Try to fallback on number treat
if (!TextUtils.isEmpty(details.number)) {
displayName = SipUri.getDisplayedSimpleContact(details.number.toString());
// SipUri.getCanonicalSipContact(details.number.toString(),
// false);
} else {
displayName = mResources.getString(R.string.unknown);
}
if (!TextUtils.isEmpty(details.numberLabel)) {
SpannableString text = new SpannableString(details.numberLabel + " " + displayName);
text.setSpan(new StyleSpan(Typeface.BOLD), 0, details.numberLabel.length(),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
displayName = text;
}
}
views.nameView.setText(displayName);
if (!TextUtils.isEmpty(details.formattedNumber)) {
views.numberView.setText(details.formattedNumber);
} else if (!TextUtils.isEmpty(details.number)) {
views.numberView.setText(details.number);
} else {
// In this case we can assume that display name was set to unknown
views.numberView.setText(displayName);
}
}
示例13: converteTimestamp
import android.text.format.DateUtils; //导入方法依赖的package包/类
private CharSequence converteTimestamp(String mileSegundos){
return DateUtils.getRelativeTimeSpanString(Long.parseLong(mileSegundos),System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
}
示例14: onBindViewHolder
import android.text.format.DateUtils; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(@NonNull final TwoLinesViewHolder holder,
@NonNull final Cursor cursor, final int position) {
final SpannableStringBuilder primary = new SpannableStringBuilder();
final String cachedName = cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.CACHED_NAME));
final String number = cursor.getString(cursor.getColumnIndexOrThrow(CallLog.Calls.NUMBER));
SpannableStringBuilderCompat.append(primary, (cachedName != null ? cachedName : number),
new StyleSpan(Typeface.BOLD), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
primary.append(" ");
final long duration = cursor.getLong(cursor.getColumnIndexOrThrow(CallLog.Calls.DURATION));
if (duration > 0) {
final CharSequence formattedDuration = DateUtils.formatElapsedTime(duration);
primary.append(formattedDuration);
}
holder.setText1(primary);
final SpannableStringBuilder summary = new SpannableStringBuilder();
final int type = cursor.getInt(cursor.getColumnIndexOrThrow(CallLog.Calls.TYPE));
switch (type) {
case CallLog.Calls.INCOMING_TYPE:
SpannableStringBuilderCompat.append(summary, "←", new ForegroundColorSpan(Color.BLUE),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
summary.append(" ");
break;
case CallLog.Calls.OUTGOING_TYPE:
SpannableStringBuilderCompat.append(summary, "→", new ForegroundColorSpan(Color.GREEN),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
summary.append(" ");
break;
case CallLog.Calls.MISSED_TYPE:
case CallLog.Calls.REJECTED_TYPE:
SpannableStringBuilderCompat.append(summary, "☇", new ForegroundColorSpan(Color.RED),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
summary.append(" ");
break;
case CallLog.Calls.BLOCKED_TYPE:
SpannableStringBuilderCompat.append(summary, "☓", new ForegroundColorSpan(Color.BLACK),
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
summary.append(" ");
break;
}
final long date = cursor.getLong(cursor.getColumnIndexOrThrow(CallLog.Calls.DATE));
final CharSequence relativeDate = DateUtils.getRelativeTimeSpanString(date,
System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
summary.append(relativeDate);
holder.setText2(summary);
}
示例15: onBindViewHolder
import android.text.format.DateUtils; //导入方法依赖的package包/类
public void onBindViewHolder(SnippetArticle article) {
super.onBindViewHolder();
// No longer listen for offline status changes to the old article.
if (mArticle != null) mArticle.setOfflineStatusChangeRunnable(null);
mArticle = article;
updateLayout();
mHeadlineTextView.setText(mArticle.mTitle);
// DateUtils.getRelativeTimeSpanString(...) calls through to TimeZone.getDefault(). If this
// has never been called before it loads the current time zone from disk. In most likelihood
// this will have been called previously and the current time zone will have been cached,
// but in some cases (eg instrumentation tests) it will cause a strict mode violation.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
long time = SystemClock.elapsedRealtime();
CharSequence relativeTimeSpan = DateUtils.getRelativeTimeSpanString(
mArticle.mPublishTimestampMilliseconds, System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS);
RecordHistogram.recordTimesHistogram("Android.StrictMode.SnippetUIBuildTime",
SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
// We format the publisher here so that having a publisher name in an RTL language
// doesn't mess up the formatting on an LTR device and vice versa.
String publisherAttribution = String.format(PUBLISHER_FORMAT_STRING,
BidiFormatter.getInstance().unicodeWrap(mArticle.mPublisher), relativeTimeSpan);
mPublisherTextView.setText(publisherAttribution);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
// The favicon of the publisher should match the TextView height.
int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
mPublisherTextView.measure(widthSpec, heightSpec);
mPublisherFaviconSizePx = mPublisherTextView.getMeasuredHeight();
mArticleSnippetTextView.setText(mArticle.mPreviewText);
// If there's still a pending thumbnail fetch, cancel it.
cancelImageFetch();
// If the article has a thumbnail already, reuse it. Otherwise start a fetch.
// mThumbnailView's visibility is modified in updateLayout().
if (mThumbnailView.getVisibility() == View.VISIBLE) {
if (mArticle.getThumbnailBitmap() != null) {
mThumbnailView.setImageBitmap(mArticle.getThumbnailBitmap());
} else {
mThumbnailView.setImageResource(R.drawable.ic_snippet_thumbnail_placeholder);
mImageCallback = new FetchImageCallback(this, mArticle);
mNewTabPageManager.getSuggestionsSource()
.fetchSuggestionImage(mArticle, mImageCallback);
}
}
// Set the favicon of the publisher.
try {
fetchFaviconFromLocalCache(new URI(mArticle.mUrl), true);
} catch (URISyntaxException e) {
setDefaultFaviconOnView();
}
mOfflineBadge.setVisibility(View.GONE);
if (SnippetsConfig.isOfflineBadgeEnabled()) {
Runnable offlineChecker = new Runnable() {
@Override
public void run() {
if (mArticle.getOfflinePageOfflineId() != null || mArticle.mIsDownloadedAsset) {
mOfflineBadge.setVisibility(View.VISIBLE);
}
}
};
mArticle.setOfflineStatusChangeRunnable(offlineChecker);
offlineChecker.run();
}
mRecyclerView.onSnippetBound(itemView);
}