List of usage examples for android.text.format DateUtils FORMAT_SHOW_YEAR
int FORMAT_SHOW_YEAR
To view the source code for android.text.format DateUtils FORMAT_SHOW_YEAR.
Click Source Link
From source file:Main.java
public static String formatToDateFull(Context context, long date) { return DateUtils.formatDateTime(context, date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_ABBREV_WEEKDAY); }
From source file:Main.java
@SuppressWarnings("deprecation") public static String formatTimeStampString(Context context, long when, boolean fullFormat) { Time then = new Time(); then.set(when);//from w ww. j av a2 s .c o m Time now = new Time(); now.setToNow(); // Basic settings for formatDateTime() we want for all cases. int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM; // 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_YEAR | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); } return DateUtils.formatDateTime(context, when, format_flags); }
From source file:Main.java
public static String formatDateTime(Context context, long time) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); Date d = new Date(time); int currentYear = Calendar.getInstance().get(Calendar.YEAR); int year = Integer.parseInt(TextUtils.isDigitsOnly(sdf.format(d)) ? sdf.format(d) : currentYear + ""); if (currentYear == year) { return DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_DATE //| DateUtils.FORMAT_SHOW_WEEKDAY //| DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH //| DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_SHOW_TIME); } else {// w w w . j ava 2s . c om return DateUtils.formatDateTime(context, time, DateUtils.FORMAT_SHOW_DATE //| DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH //| DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_SHOW_TIME); } }
From source file:edu.mit.mobile.android.locast.ver2.events.EventDetail.java
private void loadFromCursor(Cursor c) { if (c.moveToFirst()) { ((TextView) findViewById(R.id.title)).setText(c.getString(c.getColumnIndex(Event._TITLE))); ((TextView) findViewById(R.id.description)).setText(c.getString(c.getColumnIndex(Event._DESCRIPTION))); ((TextView) findViewById(R.id.author)).setText(c.getString(c.getColumnIndex(Event._AUTHOR))); final long start = c.getLong(c.getColumnIndex(Event._START_DATE)), end = c.getLong(c.getColumnIndex(Event._END_DATE)); ((TextView) findViewById(R.id.author)).setText(DateUtils.formatDateRange(this, start, end, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY)); setPointerFromCursor(c);//from w w w . java2 s. c o m mEventOverlay.swapCursor(c); } else { Toast.makeText(this, R.string.error_loading_event, Toast.LENGTH_LONG).show(); Log.e(TAG, "cursor has no content"); finish(); } }
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.socialdisasters.other.MessageAdapter.java
public static String formatTimeStampString(Context context, long when, boolean fullFormat) { Time then = new Time(); then.set(when);// w w w .j a v a2s. c o m 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: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 ww w.jav a 2 s.c om 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:org.jraf.android.piclabel.app.form.FormActivity.java
protected ImageInfo extractImageInfo(File file) { ImageInfo res = new ImageInfo(); ExifInterface exifInterface = null;// w ww . ja va2s . com try { exifInterface = new ExifInterface(file.getPath()); } catch (IOException e) { Log.e(TAG, "extractImageInfo Could not read exif", e); } // Date String dateTimeStr = null; if (exifInterface != null) dateTimeStr = exifInterface.getAttribute(ExifInterface.TAG_DATETIME); if (TextUtils.isEmpty(dateTimeStr)) { // No date in exif: use 'local' date res.dateTime = DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); res.isLocalDateTime = true; } else { res.dateTime = parseExifDateTime(dateTimeStr); if (res.dateTime == null) { // Date in exif could not be parsed: use 'local' date DateUtils.formatDateTime(this, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR); res.isLocalDateTime = true; } } // Location float[] latLon = new float[2]; boolean latLonPresent = exifInterface != null && exifInterface.getLatLong(latLon); if (!latLonPresent) { // No location in exif: use 'local' location res.isLocalLocation = true; latLonPresent = getLatestLocalLocation(latLon); if (latLonPresent) res.location = reverseGeocode(latLon[0], latLon[1]); } else { res.location = reverseGeocode(latLon[0], latLon[1]); } if (res.location == null) { res.reverseGeocodeProblem = true; res.location = ""; } return res; }
From source file:org.openintents.openpgp.util.OpenPgpKeyPreference.java
private void refreshTitleAndSummary() { boolean isConfigured = openPgpApiManager != null && openPgpApiManager.getOpenPgpProviderState() != OpenPgpProviderState.UNCONFIGURED; setEnabled(isConfigured);/*from w ww . j av a2s.com*/ if (this.keyId == NO_KEY) { setTitle(R.string.openpgp_key_title); setSummary(R.string.openpgp_no_key_selected); return; } if (this.keyPrimaryUserId != null && this.keyCreationTime != 0) { Context context = getContext(); UserId userId = OpenPgpUtils.splitUserId(keyPrimaryUserId); if (userId.email != null) { setTitle(context.getString(R.string.openpgp_key_using, userId.email)); } else if (userId.name != null) { setTitle(context.getString(R.string.openpgp_key_using, userId.name)); } else { setTitle(R.string.openpgp_key_using_no_name); } String creationTimeStr = DateUtils.formatDateTime(context, keyCreationTime, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_MONTH); setSummary(context.getString(R.string.openpgp_key_created, creationTimeStr)); } else { setTitle(R.string.openpgp_key_title); setSummary(R.string.openpgp_key_selected); } }
From source file:com.google.android.apps.muzei.gallery.GalleryArtSource.java
private void publishNextArtwork(Uri forceUri) { // schedule next scheduleNext();//from www .j a v a 2s.c o m Cursor chosenUris = getContentResolver().query(GalleryContract.ChosenPhotos.CONTENT_URI, new String[] { BaseColumns._ID }, null, null, null); int numChosenUris = (chosenUris != null) ? chosenUris.getCount() : 0; Artwork currentArtwork = getCurrentArtwork(); String lastToken = (currentArtwork != null) ? currentArtwork.getToken() : null; Uri imageUri; Random random = new Random(); if (forceUri != null) { imageUri = forceUri; } else if (numChosenUris > 0) { while (true) { chosenUris.moveToPosition(random.nextInt(chosenUris.getCount())); imageUri = ContentUris.withAppendedId(GalleryContract.ChosenPhotos.CONTENT_URI, chosenUris.getLong(chosenUris.getColumnIndex(BaseColumns._ID))); if (numChosenUris <= 1 || !imageUri.toString().equals(lastToken)) { break; } } } else { if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Log.w(TAG, "Missing read external storage permission."); return; } Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.MediaColumns._ID }, MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " NOT LIKE '%Screenshots%'", null, null); if (cursor == null) { Log.w(TAG, "Empty cursor."); return; } int count = cursor.getCount(); if (count == 0) { Log.e(TAG, "No photos in the gallery."); return; } while (true) { cursor.moveToPosition(random.nextInt(count)); imageUri = ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cursor.getLong(0)); if (!imageUri.toString().equals(lastToken)) { break; } } cursor.close(); } if (chosenUris != null) { chosenUris.close(); } String token = imageUri.toString(); // Retrieve metadata for item ensureMetadataExists(imageUri); String[] projection = { GalleryContract.MetadataCache.COLUMN_NAME_DATETIME, GalleryContract.MetadataCache.COLUMN_NAME_LOCATION }; Cursor metadata = getContentResolver().query(GalleryContract.MetadataCache.CONTENT_URI, projection, GalleryContract.MetadataCache.COLUMN_NAME_URI + "=?", new String[] { imageUri.toString() }, null); long datetime = 0; String location = null; if (metadata != null && metadata.moveToFirst()) { datetime = metadata .getLong(metadata.getColumnIndex(GalleryContract.MetadataCache.COLUMN_NAME_DATETIME)); location = metadata .getString(metadata.getColumnIndex(GalleryContract.MetadataCache.COLUMN_NAME_LOCATION)); } if (metadata != null) { metadata.close(); } // Publish the actual artwork String title; if (datetime > 0) { title = DateUtils.formatDateTime(this, datetime, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY); } else { title = getString(R.string.gallery_from_gallery); } String byline; if (!TextUtils.isEmpty(location)) { byline = location; } else { byline = getString(R.string.gallery_touch_to_view); } publishArtwork(new Artwork.Builder().imageUri(imageUri).title(title).byline(byline).token(token) .viewIntent(new Intent(Intent.ACTION_VIEW).setDataAndType(imageUri, "image/jpeg")).build()); }