List of usage examples for android.text.format DateUtils FORMAT_SHOW_TIME
int FORMAT_SHOW_TIME
To view the source code for android.text.format DateUtils FORMAT_SHOW_TIME.
Click Source Link
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 {// www . ja v a 2 s . c o m 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.level28.android.moca.ui.schedule.SessionDetailFragment.java
/** * Update the fragment UI whenever a cursor change happens *//*from w w w . j a v a2 s.c om*/ private void updateUi(final boolean animate) { if (!isUsable()) { return; } // Sanity check if (mCursor != null && !mCursor.isClosed() && mCursor.moveToFirst()) { final CharSequence startTime = DateUtils.formatDateTime(getActivity(), mCursor.getLong(SessionDetailQuery.START), DateUtils.FORMAT_SHOW_TIME); final CharSequence endTime = DateUtils.formatDateTime(getActivity(), mCursor.getLong(SessionDetailQuery.END), DateUtils.FORMAT_SHOW_TIME); final String timeSpec = new StringBuilder(startTime).append(" - ").append(endTime).toString(); mTime.setText(timeSpec); // Set the language flag as a compound drawable of mTime. // This is a very common layout optimization which shaves a bit of // memory and *a lot* of CPU time required to compute the final // layout final int flagResId = getFlagResId(mCursor.getString(SessionDetailQuery.LANG)); mTime.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, flagResId); mTitle.setText(mCursor.getString(SessionDetailQuery.TITLE)); mHosts.setText(mCursor.getString(SessionDetailQuery.HOSTS)); // Check for abstract presence if (mCursor.isNull(SessionDetailQuery.ABSTRACT)) { // No abstract, hide it ViewUtils.setGone(mAbstractContainer, true); } else { // We have an abstract, display it! mAbstract.setText(mCursor.getString(SessionDetailQuery.ABSTRACT)); mAbstractContainer.scrollTo(0, 0); ViewUtils.setGone(mAbstractContainer, false); } // Display session details ViewUtils.setGone(mEmptyText, true); ViewUtils.fadeIn(getActivity(), mScheduleContainer, animate); ViewUtils.setGone(mScheduleContainer, false); mScheduleVisible = true; } else if (mScheduleVisible) { // Display the "select session" message ViewUtils.setGone(mScheduleContainer, true); ViewUtils.fadeIn(getActivity(), mEmptyText, animate); ViewUtils.setGone(mEmptyText, false); mScheduleVisible = false; } }
From source file:org.jraf.android.piclabel.app.form.FormActivity.java
protected ImageInfo extractImageInfo(File file) { ImageInfo res = new ImageInfo(); ExifInterface exifInterface = null;/*from ww w. ja v a2 s . c o m*/ 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:com.hyperaware.conference.android.fragment.SessionDetailFragment.java
private void updateSessionDetail() { tvTopic.setText(agendaItem.getTopic()); host.setTitle(agendaItem.getTopic()); final StringBuilder sb = new StringBuilder(); final Formatter formatter = new Formatter(sb); final long start_ms = TimeUnit.SECONDS.toMillis(agendaItem.getEpochStartTime()); final long end_ms = TimeUnit.SECONDS.toMillis(agendaItem.getEpochEndTime()); sb.setLength(0);/* w w w . ja va 2 s . co m*/ DateUtils.formatDateRange(getActivity(), formatter, start_ms, end_ms, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY, tz.getID()); tvDate.setText(formatter.toString()); sb.setLength(0); DateUtils.formatDateRange(getActivity(), formatter, start_ms, end_ms, DateUtils.FORMAT_SHOW_TIME, tz.getID()); tvTime.setText(formatter.toString()); final String location = agendaItem.getLocation(); if (!Strings.isNullOrEmpty(location)) { tvLocation.setText(agendaItem.getLocation()); } else { tvLocation.setVisibility(View.GONE); } tvDescription.setText(agendaItem.getDescription()); // Only sessions with speakers can have feedback final View feedback = vgActions.findViewById(R.id.tv_session_feedback); if (speakerItems.size() > 0) { feedback.setOnClickListener(new SessionFeedbackOnClickListener()); vgActions.setVisibility(View.VISIBLE); } else { vgActions.setVisibility(View.GONE); } if (speakerItems.size() > 0) { vgSpeakers.setVisibility(View.VISIBLE); vgSpeakers.removeAllViews(); final LayoutInflater inflater = getActivity().getLayoutInflater(); for (final SpeakerItem item : speakerItems) { final View view = inflater.inflate(R.layout.item_session_speaker, vgSpeakers, false); ImageView iv = (ImageView) view.findViewById(R.id.iv_pic); Glide.with(SessionDetailFragment.this).load(item.getImage100()).placeholder(R.drawable.nopic) .into(iv); ((TextView) view.findViewById(R.id.tv_name)).setText(item.getName()); if (host != null) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Fragment next = SpeakerDetailFragment.instantiate(item.getId()); host.pushFragment(next, "speaker_detail"); } }); } vgSpeakers.addView(view); } } }
From source file:nl.atcomputing.spacetravelagency.fragments.PlaceOrderFragment.java
private void setDepartureTime(long departureTime) { CharSequence dateString = DateUtils.formatDateTime(getActivity(), departureTime * 1000, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); TextView tv = (TextView) this.view.findViewById(R.id.departure_time_value); tv.setText(dateString);/*w w w . j a v a2 s . c o m*/ View v = this.view.findViewById(R.id.linearlayout_departure_time); v.setVisibility(View.VISIBLE); }
From source file:org.pixmob.droidlink.ui.EventDetailsFragment.java
private void initFields() { if (eventUri == null) { return;//from w w w .j a va 2 s . c o m } final Cursor cursor = getActivity().getContentResolver().query(eventUri, EVENT_PROJECTION, null, null, null); if (cursor == null) { throw new IllegalArgumentException("Cannot event: " + eventUri); } if (!cursor.moveToNext()) { cursor.close(); throw new IllegalArgumentException("Cannot find event: " + eventUri); } final long date; final int type; final String name; String message; try { date = cursor.getLong(cursor.getColumnIndexOrThrow(CREATED)); type = cursor.getInt(cursor.getColumnIndexOrThrow(TYPE)); name = cursor.getString(cursor.getColumnIndexOrThrow(NAME)); number = cursor.getString(cursor.getColumnIndexOrThrow(NUMBER)); message = cursor.getString(cursor.getColumnIndexOrThrow(MESSAGE)); } finally { cursor.close(); } if (number != null) { number = PhoneNumberUtils.formatNumber(number); } final String dateStr = DateUtils.formatDateTime(getActivity(), date, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); dateView.setText(dateStr); final Integer typeResourceId = EVENT_ICONS.get(type); typeView.setVisibility(typeResourceId == null ? View.GONE : View.VISIBLE); if (typeResourceId != null) { typeView.setImageResource(typeResourceId); } final String eventName; final String eventNumber; if (number == null) { eventName = getActivity().getString(R.string.unknown_number); eventNumber = null; } else if (name == null) { eventName = number; eventNumber = null; } else { eventName = name; eventNumber = number; } nameView.setText(eventName); numberView.setText(eventNumber); if (EventsContract.MISSED_CALL_TYPE == type) { message = getString(R.string.missed_call); } messageView.setText(message); new GetContactPictureTask(this, eventNumber).execute(); }
From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java
private String getTimeText(Shift shift) { String time = mIdToTimeArray.get((int) shift.id); if (!TextUtils.isEmpty(time)) return time; int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24Hour) flags |= DateUtils.FORMAT_24HOUR; mStringBuilder.setLength(0);/*from w w w.j a v a2 s . c o m*/ time = DateUtils.formatDateRange(getContext(), mFormatter, shift.getStartTime(), shift.getEndTime(), flags) .toString(); time += " (" + UIUtils.getDurationAsHours(shift.getDurationInMinutes()) + ")"; mIdToTimeArray.put((int) shift.id, time); return time; }
From source file:org.openintents.openpgp.util.OpenPgpKeyPreference.java
private void refreshTitleAndSummary() { boolean isConfigured = openPgpApiManager != null && openPgpApiManager.getOpenPgpProviderState() != OpenPgpProviderState.UNCONFIGURED; setEnabled(isConfigured);//from w w w . j a va 2 s .co m 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:org.onebusaway.android.report.ui.SimpleArrivalListFragment.java
private void loadArrivalList(ObaArrivalInfo[] info, final ObaReferences refs, long currentTime) { LinearLayout contentLayout = (LinearLayout) getActivity().findViewById(R.id.simple_arrival_content); contentLayout.removeAllViews();//from ww w .ja va 2s. c o m ArrayList<ArrivalInfo> arrivalInfos = ArrivalInfoUtils.convertObaArrivalInfo(getActivity(), info, new ArrayList<String>(), currentTime, false); for (ArrivalInfo stopInfo : arrivalInfos) { final ObaArrivalInfo arrivalInfo = stopInfo.getInfo(); LayoutInflater inflater = LayoutInflater.from(getActivity()); LinearLayout view = (LinearLayout) inflater.inflate(R.layout.arrivals_list_item, null, false); view.setBackgroundColor(getResources().getColor(R.color.material_background)); TextView route = (TextView) view.findViewById(R.id.route); TextView destination = (TextView) view.findViewById(R.id.destination); TextView time = (TextView) view.findViewById(R.id.time); TextView status = (TextView) view.findViewById(R.id.status); TextView etaView = (TextView) view.findViewById(R.id.eta); TextView minView = (TextView) view.findViewById(R.id.eta_min); ViewGroup realtimeView = (ViewGroup) view.findViewById(R.id.eta_realtime_indicator); view.findViewById(R.id.more_horizontal).setVisibility(View.INVISIBLE); view.findViewById(R.id.route_favorite).setVisibility(View.INVISIBLE); String routeShortName = arrivalInfo.getShortName(); route.setText(routeShortName); UIUtils.maybeShrinkRouteName(getActivity(), route, routeShortName); destination.setText(UIUtils.formatDisplayText(arrivalInfo.getHeadsign())); status.setText(stopInfo.getStatusText()); long eta = stopInfo.getEta(); if (eta == 0) { etaView.setText(R.string.stop_info_eta_now); minView.setVisibility(View.GONE); } else { etaView.setText(String.valueOf(eta)); minView.setVisibility(View.VISIBLE); } status.setBackgroundResource(R.drawable.round_corners_style_b_status); GradientDrawable d = (GradientDrawable) status.getBackground(); Integer colorCode = stopInfo.getColor(); int color = getActivity().getResources().getColor(colorCode); if (stopInfo.getPredicted()) { // Show real-time indicator UIUtils.setRealtimeIndicatorColorByResourceCode(realtimeView, colorCode, android.R.color.transparent); realtimeView.setVisibility(View.VISIBLE); } else { realtimeView.setVisibility(View.INVISIBLE); } etaView.setTextColor(color); minView.setTextColor(color); d.setColor(color); // Set padding on status view int pSides = UIUtils.dpToPixels(getActivity(), 5); int pTopBottom = UIUtils.dpToPixels(getActivity(), 2); status.setPadding(pSides, pTopBottom, pSides, pTopBottom); time.setText(DateUtils.formatDateTime(getActivity(), stopInfo.getDisplayTime(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT)); View reminder = view.findViewById(R.id.reminder); reminder.setVisibility(View.GONE); contentLayout.addView(view); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String agencyName = findAgencyNameByRouteId(refs, arrivalInfo.getRouteId()); mCallback.onArrivalItemClicked(arrivalInfo, agencyName); } }); } }
From source file:com.numenta.taurus.service.TaurusNotificationService.java
/** * Format anomaly title// w w w .j a v a2 s . co m * * @param company The company name * @param types The anomaly types triggering the anomaly * @param timestamp The time the anomaly was fired * @return The formatted text suitable for OS notification */ String formatAnomalyTitle(String company, EnumSet<MetricType> types, long timestamp) { Context ctx = getService(); String anomalyTypes = ""; if (!Collections.disjoint(types, MetricType.STOCK_TYPES)) { if (types.contains(MetricType.TwitterVolume)) { anomalyTypes = ctx.getString(R.string.header_stock_twitter); } else { anomalyTypes = ctx.getString(R.string.header_stock); } } else if (types.contains(MetricType.TwitterVolume)) { anomalyTypes = ctx.getString(R.string.header_twitter); } return String.format(ctx.getString(R.string.taurus_notification_description_template), company, DateUtils.formatDateTime(ctx, timestamp, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME), anomalyTypes); }