List of usage examples for android.text.format DateUtils FORMAT_SHOW_DATE
int FORMAT_SHOW_DATE
To view the source code for android.text.format DateUtils FORMAT_SHOW_DATE.
Click Source Link
From source file:com.jaspersoft.android.jaspermobile.activities.storage.adapter.FileAdapter.java
private String getFormattedDateModified(File file) { return DateUtils.formatDateTime(getContext(), file.lastModified(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_24HOUR); }
From source file:com.tum.atse.Utils.java
/** * Returns a user-friendly localized data range. * * @param context// w w w . ja v a2 s . co m * @param dateTimeStart * @param dateTimeEnd * @return */ public static String getFormattedDateRange(Context context, DateTime dateTimeStart, DateTime dateTimeEnd) { Calendar cal1 = Calendar.getInstance(); cal1.setTimeInMillis(dateTimeStart.getValue()); Calendar cal2 = Calendar.getInstance(); cal2.setTimeInMillis(dateTimeEnd.getValue()); return DateUtils.formatDateRange(context, cal1.getTimeInMillis(), cal2.getTimeInMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH); }
From source file:com.socialdisasters.other.MessageAdapter.java
public static String formatTimeStampString(Context context, long when, boolean fullFormat) { Time then = new Time(); then.set(when);//from w w w . j av a 2 s.com Time now = new Time(); now.setToNow(); // Basic settings for formatDateTime() we want for all cases. int format_flags = DateUtils.FORMAT_ABBREV_ALL; // If the message is from a different year, show the date and year. if (then.year != now.year) { format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { // If it is from a different day than today, show only the date. format_flags |= DateUtils.FORMAT_SHOW_DATE; } else { // Otherwise, if the message is from today, show the time. format_flags |= DateUtils.FORMAT_SHOW_TIME; } // If the caller has asked for full details, make sure to show the date // and time no matter what we've determined above (but still make showing // the year only happen if it is a different year from today). if (fullFormat) { format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); } return DateUtils.formatDateTime(context, when, format_flags); }
From source file:com.adam.aslfms.util.Util.java
public static String timeFromLocalMillis(Context ctx, long millis) { return DateUtils.formatDateTime(ctx, millis, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE); }
From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java
public static ArrayList<SocialItem> getGooglePlusItems(Context context, String tag, int maximum) { String twitterSearch = "https://www.googleapis.com/plus/v1/activities?orderBy=recent&query=" + tag + "&key=" + Config.PLUS_KEY;/* w w w . j ava 2s . co m*/ Log.d("SUSEConferences", "Google search: " + twitterSearch); ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'"); formatter.setTimeZone(TimeZone.getTimeZone("UTC")); Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_icon); try { JSONObject result = HTTPWrapper.get(twitterSearch); JSONArray items = result.getJSONArray("items"); int len = items.length(); if ((len > 0) && (maximum > 0) && (len > maximum)) len = maximum; for (int i = 0; i < len; i++) { JSONObject jsonItem = items.getJSONObject(i); JSONObject actorItem = jsonItem.getJSONObject("actor"); JSONObject imageItem = actorItem.getJSONObject("image"); JSONObject objectItem = jsonItem.getJSONObject("object"); Bitmap image = HTTPWrapper.getImage(imageItem.getString("url")); String content = Html.fromHtml(objectItem.getString("content")).toString(); Date formattedDate = new Date(); try { formattedDate = formatter.parse(jsonItem.getString("published")); } catch (ParseException e) { e.printStackTrace(); } SocialItem newItem = new SocialItem(SocialItem.GOOGLE, actorItem.getString("displayName"), content, formattedDate, DateUtils .formatDateTime(context, formattedDate.getTime(), DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE), image, icon); newItem.setLink(jsonItem.getString("url")); socialItems.add(newItem); } } catch (IllegalStateException e) { e.printStackTrace(); } catch (SocketException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return socialItems; }
From source file:org.jraf.android.cinetoday.mobile.app.main.MainActivity.java
private void updateLastUpdateDateLabel() { MainPrefs prefs = MainPrefs.get(this); Long lastUpdateDate = prefs.getLastUpdateDate(); if (lastUpdateDate == null) { mBinding.txtStatus.setText(R.string.main_lastUpdateDate_none); } else {/* ww w . jav a2 s . c o m*/ String dateStr = DateUtils.formatDateTime(this, lastUpdateDate, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); mBinding.txtStatus.setText(getString(R.string.main_lastUpdateDate, dateStr)); } }
From source file:com.numenta.core.utils.NotificationUtils.java
/** * Format Notification description based on instance name and timestamp * * @param instanceName// w w w .j a v a 2 s.c o m * @param timestamp * @return Formatted notification description using */ public static String formatSimpleNotificationDescription(String instanceName, long timestamp) { // Formatted Notification description: // $1=metric.instanceName, // $2=timestamp // Gets the standard date formatter for the current locale of // the device String formattedCurrentDate = DateUtils.formatDateTime(HTMApplication.getContext(), timestamp, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); return String.format( HTMApplication.getContext().getString(R.string.simple_notification_description_template), instanceName, formattedCurrentDate); }
From source file:edu.cens.loci.ui.VisitDetailActivity.java
private void updateData(Uri visitUri) { ContentResolver resolver = getContentResolver(); Cursor visitCursor = resolver.query(visitUri, VISIT_LOG_PROJECTION, null, null, null); try {/*from w w w.ja v a 2 s . com*/ if (visitCursor != null && visitCursor.moveToFirst()) { long placeId = visitCursor.getLong(PLACE_ID_INDEX); long enter = visitCursor.getLong(ENTER_INDEX); long exit = visitCursor.getLong(EXIT_INDEX); int type = visitCursor.getInt(TYPE); String extra1 = visitCursor.getString(EXTRA1_INDEX); String extra2 = visitCursor.getString(EXTRA2_INDEX); MyLog.d(LociConfig.D.UI.DEBUG, TAG, String.format("[updateData] placeId=%d enter=%s exit=%s type=%d extra1=%s extra2=%s", placeId, MyDateUtils.getTimeFormatLong(enter), MyDateUtils.getTimeFormatLong(exit), type, extra1, extra2)); // Place name String place_name = ""; int place_state = 0; if (placeId > 0) { String placeSelection = Places._ID + "=" + placeId; Uri placeUri = ContentUris.withAppendedId(Places.CONTENT_URI, placeId); Cursor placeCursor = resolver.query(placeUri, PLACE_PROJECTION, placeSelection, null, null); if (placeCursor != null && placeCursor.moveToFirst()) { place_name = placeCursor.getString(PLACE_NAME_INDEX); place_state = placeCursor.getInt(PLACE_STATE_INDEX); placeCursor.close(); } else { place_name = "Unknown"; } } else { place_name = "Unknown"; } mPlaceName.setText(place_name); // Pull out string in format [relative], [date] CharSequence dateClause = DateUtils.formatDateRange(this, enter, enter, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); mVisitTime.setText(dateClause); // Set the duration mVisitDuration.setText(formatDuration((exit - enter) / 1000)); switch (type) { case Visits.TYPE_GPS: mPlaceTypeIcon.setImageResource(R.drawable.icon_satellite); break; case Visits.TYPE_WIFI: mPlaceTypeIcon.setImageResource(R.drawable.icon_wifi); break; } List<ViewEntry> actions = new ArrayList<ViewEntry>(); // View place Intent viewPlaceIntent = new Intent(Intent.ACTION_VIEW, ContentUris.withAppendedId(Places.CONTENT_URI, placeId)); String placeViewLabel = ""; MyLog.d(LociConfig.D.UI.DEBUG, TAG, String.format("[updateData] placename=%s placestate=%d", place_name, place_state)); switch (place_state) { case Places.STATE_SUGGESTED: placeViewLabel = "Handle Suggested Place"; break; case Places.STATE_REGISTERED: placeViewLabel = "View " + place_name; break; default: placeViewLabel = null;//place_name + " state " + place_state; } if (placeViewLabel != null) { ViewEntry entry = new ViewEntry(LIST_ACTION_VIEW_PLACE, R.drawable.sym_action_map, placeViewLabel, null, null); entry.intent = viewPlaceIntent; actions.add(entry); } // View Wifi APs if (type == Visits.TYPE_WIFI && extra1 != null) { LociWifiFingerprint wifi; String apsAbstract = "Not available"; try { wifi = new LociWifiFingerprint(extra1); apsAbstract = wifi.getWifiInfoSubstring(5); ViewEntry wifiEntry = new ViewEntry(LIST_ACTION_VIEW_WIFIS, R.drawable.ic_settings_wireless, "View Wi-Fi APs", apsAbstract, null); wifiEntry.extra_string = extra1; actions.add(wifiEntry); } catch (JSONException e) { MyLog.e(LociConfig.D.JSON, TAG, "wifi json failed : " + extra1); e.printStackTrace(); } } // Additional Actions if (placeId > 0) { if (place_state == Places.STATE_REGISTERED || place_state == Places.STATE_BLOCKED) { if (type == Visits.TYPE_WIFI && extra1 != null) { ViewEntry entry = new ViewEntry(LIST_ACTION_CHANGE_PLACE, android.R.drawable.ic_menu_edit, "Change Place", null, null); entry.intent = new Intent(Intents.UI.ACTION_INSERT); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY, PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter)); entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY, Places.ENTRY_WIFI_OVERWRITE_WRONG_RECOGNITION); actions.add(entry); } } } else { ViewEntry entry = new ViewEntry(LIST_ACTION_ADD_PLACE, R.drawable.sym_action_add, "Add Place", null, null); entry.intent = new Intent(Intents.UI.ACTION_INSERT); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY, PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1); entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter)); entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY, Places.ENTRY_WIFI_USE_SHORT_VISIT); actions.add(entry); } // View Recognition Results //Log.d(TAG, "recog: " + extra2); if (extra2 != null && !TextUtils.isEmpty(extra2)) { ViewEntry recogEntry = new ViewEntry(LIST_ACTION_VIEW_RECOGNITION, R.drawable.ic_clock_strip_desk_clock, "View Recogntion Results", "", null); recogEntry.extra_string = extra2; actions.add(recogEntry); } ViewAdapter adapter = new ViewAdapter(this, actions); setListAdapter(adapter); //Log.d(TAG, String.format("placeId=%d enter=%s exit=%s", placeId, MyDateUtils.getDateFormatLong(enter), MyDateUtils.getDateFormatLong(exit))); //Log.d(TAG, String.format("extra1=%s", extra1)); //Log.d(TAG, String.format("extra2=%s", extra2)); } } finally { if (visitCursor != null) { visitCursor.close(); } } }
From source file:net.abcdroid.devfest12.ui.MyScheduleFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null) { return;//from w w w. j a v a2s . c o m } long currentTime = UIUtils.getCurrentTime(getActivity()); int firstNowPosition = ListView.INVALID_POSITION; List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>(); cursor.moveToFirst(); long previousBlockStart = -1; long blockStart, blockEnd; while (!cursor.isAfterLast()) { blockStart = cursor.getLong(BlocksQuery.BLOCK_START); blockEnd = cursor.getLong(BlocksQuery.BLOCK_END); if (!UIUtils.isSameDay(previousBlockStart, blockStart)) { sections.add(new SimpleSectionedListAdapter.Section(cursor.getPosition(), DateUtils.formatDateTime(getActivity(), blockStart, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY))); } if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION // if we're currently in this block, or we're not in a block // and this // block is in the future, then this is the scroll position && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) { firstNowPosition = cursor.getPosition(); } previousBlockStart = blockStart; cursor.moveToNext(); } mScheduleAdapter.changeCursor(cursor); SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()]; mAdapter.setSections(sections.toArray(dummy)); if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) { firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition); getListView().setSelectionFromTop(firstNowPosition, getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset)); mScrollToNow = false; } }
From source file:com.google.android.apps.iosched.ui.MyScheduleFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null || cursor == null) { return;//w w w .ja v a 2s . co m } long currentTime = UIUtils.getCurrentTime(getActivity()); int firstNowPosition = ListView.INVALID_POSITION; List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>(); cursor.moveToFirst(); long previousBlockStart = -1; long blockStart, blockEnd; while (!cursor.isAfterLast()) { blockStart = cursor.getLong(BlocksQuery.BLOCK_START); blockEnd = cursor.getLong(BlocksQuery.BLOCK_END); if (!UIUtils.isSameDay(previousBlockStart, blockStart)) { sections.add(new SimpleSectionedListAdapter.Section(cursor.getPosition(), DateUtils.formatDateTime(getActivity(), blockStart, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY))); } if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION // if we're currently in this block, or we're not in a block // and this // block is in the future, then this is the scroll position && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) { firstNowPosition = cursor.getPosition(); } previousBlockStart = blockStart; cursor.moveToNext(); } mScheduleAdapter.changeCursor(cursor); SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()]; mAdapter.setSections(sections.toArray(dummy)); if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) { firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition); getListView().setSelectionFromTop(firstNowPosition, getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset)); mScrollToNow = false; } }