List of usage examples for android.text.format DateUtils formatSameDayTime
public static final CharSequence formatSameDayTime(long then, long now, int dateStyle, int timeStyle)
From source file:Main.java
public static CharSequence getSameDayTime(Long time) { return DateUtils.formatSameDayTime(time, System.currentTimeMillis(), DateFormat.SHORT, DateFormat.SHORT); }
From source file:com.afwsamples.testdpc.common.Util.java
/** * Format a friendly datetime for the current locale according to device policy documentation. * If the timestamp doesn't represent a real date, it will be interpreted as {@code null}. * * @return A {@link CharSequence} such as "12:35 PM today" or "June 15, 2033", or {@code null} * in the case that {@param timestampMs} equals zero. *///from w w w .j a va 2s . c o m public static CharSequence formatTimestamp(long timestampMs) { if (timestampMs == 0) { // DevicePolicyManager documentation describes this timestamp as having no effect, // so show nothing for this case as the policy has not been set. return null; } return DateUtils.formatSameDayTime(timestampMs, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_WEEKDAY, DateUtils.FORMAT_SHOW_TIME); }
From source file:ca.mudar.snoozy.ui.widget.HistoryCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { super.bindView(view, context, cursor); /*/*from w w w . j a v a 2 s . c o m*/ Get current cursor values */ final boolean isPowerOn = (1 == cursor.getInt(HistoryQuery.IS_POWER_ON)); final long timestamp = cursor.getLong(HistoryQuery.TIME_STAMP); final boolean isFirst = (1 == cursor.getInt(HistoryQuery.IS_FIRST)); final boolean isLast = (1 == cursor.getInt(HistoryQuery.IS_LAST)); final int batteryLevel = cursor.getInt(HistoryQuery.BATTERY_LEVEL); /* Prepare the data */ final String sPowerStatus = mResources.getString( isPowerOn ? R.string.history_item_power_connected : R.string.history_item_power_disconnected); final String sBatteryLevel = String.format(mResources.getString(R.string.history_item_battery_level), batteryLevel); final int resPowerStatusColor = mResources .getColor(isPowerOn ? R.color.card_row_highlight_color : R.color.card_row_color); String sTimestamp; String sDay; if (DateUtils.isToday(timestamp)) { sDay = mResources.getString(R.string.history_item_day_today); sTimestamp = (String) DateUtils.formatSameDayTime(timestamp, mMillis, 0, DateFormat.SHORT); // sTimestamp = (String) DateUtils.getRelativeTimeSpanString(timestamp,now, 0, 0); } else { sDay = (String) DateUtils.getRelativeTimeSpanString(timestamp, mMillis, DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); // sDay = sDay.substring(0,1).toUpperCase() + sDay.substring(1); sTimestamp = mTimeFormat.format(new Date(timestamp)); } sDay = sDay.substring(0, 1).toUpperCase() + sDay.substring(1); /* Set UI values */ ((TextView) view.findViewById(R.id.history_is_power_on)).setText(sPowerStatus); ((TextView) view.findViewById(R.id.history_is_power_on)).setTextColor(resPowerStatusColor); ((TextView) view.findViewById(R.id.history_timestamp)).setText(sTimestamp); ((TextView) view.findViewById(R.id.history_battery_level)).setText(sBatteryLevel); if (isFirst && isLast) { ((TextView) view.findViewById(R.id.history_day)).setText(sDay); view.findViewById(R.id.history_header).setVisibility(View.VISIBLE); view.setBackgroundResource(R.drawable.bg_cards_top_bottom); } else if (isLast) { ((TextView) view.findViewById(R.id.history_day)).setText(sDay); view.findViewById(R.id.history_header).setVisibility(View.VISIBLE); view.setBackgroundResource(R.drawable.bg_cards_top); } else if (isFirst) { view.findViewById(R.id.history_header).setVisibility(View.GONE); view.setBackgroundResource(R.drawable.bg_cards_bottom); } else { view.findViewById(R.id.history_header).setVisibility(View.GONE); view.setBackgroundResource(R.drawable.bg_cards_middle); } }
From source file:com.androidquery.simplefeed.activity.FriendsActivity.java
@Override protected String makeTitle(long time) { String result = getString(R.string.n_friends); if (time > 0) { result += " - " + DateUtils.formatSameDayTime(time, System.currentTimeMillis(), DateFormat.SHORT, DateFormat.SHORT); }//ww w . j ava 2 s. com return result; }
From source file:be.brunoparmentier.openbikesharing.app.activities.StationsListActivity.java
private void setDBLastUpdateText() { TextView lastUpdate = (TextView) findViewById(R.id.dbLastUpdate); long dbLastUpdate = settings.getLong(PREF_KEY_DB_LAST_UPDATE, -1); if (dbLastUpdate == -1) { lastUpdate.setText(/* ww w . ja v a 2s .c o m*/ String.format(getString(R.string.db_last_update), getString(R.string.db_last_update_never))); } else { lastUpdate.setText(String.format(getString(R.string.db_last_update), DateUtils.formatSameDayTime( dbLastUpdate, System.currentTimeMillis(), DateFormat.DEFAULT, DateFormat.DEFAULT))); } }
From source file:com.androidquery.simplefeed.activity.PlaceActivity.java
@Override protected String makeTitle(long time) { String result = getString(R.string.n_locations); if (time > 0) { result += " - " + DateUtils.formatSameDayTime(time, System.currentTimeMillis(), DateFormat.SHORT, DateFormat.SHORT); }/*from w w w .j a v a2s . c o m*/ return result; }
From source file:com.androidquery.simplefeed.fragments.FeedFragment.java
public String makeTitle(long time) { String result = source.getName(); if (act.isRoot()) { String mode = getModeDisplay(); if (mode != null) { result += " - " + mode; }/* ww w . j a v a 2 s . c om*/ } if (time > 0) { result += " - " + DateUtils.formatSameDayTime(time, System.currentTimeMillis(), DateFormat.SHORT, DateFormat.SHORT); } return result; }