List of usage examples for android.text.format DateUtils formatDateTime
public static String formatDateTime(Context context, long millis, int flags)
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
private void initNoteScreen() { mNoteEditor.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId)); if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { switchToListMode(mWorkingNote.getContent()); } else {// w ww . j a v a 2 s. com mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)); mNoteEditor.setSelection(mNoteEditor.getText().length()); } setNoteTheme(); String dateStr = DateUtils.formatDateTime(this, mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR); mToolbar.setTitle(dateStr); /** * TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker * is not ready */ mToolbar.setSubtitle(getSubTitle()); }
From source file:com.philliphsu.bottomsheetpickers.date.BottomSheetDatePickerDialog.java
private void setCurrentView(final int viewIndex) { long millis = mCalendar.getTimeInMillis(); switch (viewIndex) { case MONTH_AND_DAY_VIEW: mDayPickerView.onDateChanged();//w w w. j a v a 2s . c o m if (mCurrentView != viewIndex) { updateHeaderSelectedView(MONTH_AND_DAY_VIEW); mAnimator.setDisplayedChild(MONTH_AND_DAY_VIEW); mCurrentView = viewIndex; } int flags = DateUtils.FORMAT_SHOW_DATE; String dayString = DateUtils.formatDateTime(getActivity(), millis, flags); mAnimator.setContentDescription(mDayPickerDescription + ": " + dayString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectDay); break; case YEAR_VIEW: mYearPickerView.onDateChanged(); if (mCurrentView != viewIndex) { updateHeaderSelectedView(YEAR_VIEW); mAnimator.setDisplayedChild(YEAR_VIEW); mCurrentView = viewIndex; } CharSequence yearString = YEAR_FORMAT.format(millis); mAnimator.setContentDescription(mYearPickerDescription + ": " + yearString); Utils.tryAccessibilityAnnounce(mAnimator, mSelectYear); break; } }
From source file:org.dmfs.webcal.fragments.CalendarItemFragment.java
@Override public View onCreateItemView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View returnView = inflater.inflate(R.layout.fragment_calendar_item, container, false); // TODO: don't put the progress indicator into the header view View progressView = inflater.inflate(R.layout.progress_indicator, null, false); mProgressBar = (ProgressBar) progressView.findViewById(android.R.id.progress); mListView = (ListView) returnView.findViewById(android.R.id.list); mListView.addHeaderView(progressView); mListView.setOnItemClickListener(this); mListView.setHeaderDividersEnabled(false); mListAdapter = new EventListAdapter(inflater.getContext(), null); mListView.setAdapter(mSectionAdapter = new SectionTitlesAdapter(inflater.getContext(), mListAdapter, new SectionIndexer() { @Override/*from w w w .ja va 2s . c o m*/ public String getSectionTitle(int index) { Time start = new Time(TimeZone.getDefault().getID()); start.set(index & 0x00ff, (index >> 8) & 0x00ff, (index >> 16) & 0x0ffff); return DateUtils.formatDateTime(getActivity(), start.toMillis(true), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY); } @Override public int getSectionIndex(Object object) { Cursor cursor = (Cursor) object; Time start = new Time( cursor.getString(cursor.getColumnIndex(WebCalReaderContract.Events.TIMZONE))); start.set(cursor.getLong(cursor.getColumnIndex(WebCalReaderContract.Events.DTSTART))); boolean allday = cursor .getInt(cursor.getColumnIndex(WebCalReaderContract.Events.IS_ALLDAY)) == 1; start.allDay = allday; // we return an encoded date as index return (start.year << 16) + (start.month << 8) + start.monthDay; } }, R.layout.events_preview_list_section_header)); FragmentManager fm = getChildFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); mTitleFragment = (CalendarTitleFragment) fm.findFragmentById(R.id.calendar_title_fragment_container); if (mTitleFragment == null) { mTitleFragment = CalendarTitleFragment.newInstance(); ft.replace(R.id.calendar_title_fragment_container, mTitleFragment); } if (!ft.isEmpty()) { ft.commit(); } LoaderManager lm = getLoaderManager(); lm.initLoader(LOADER_CALENDAR_ITEM, null, this); lm.initLoader(LOADER_SUBSCRIBED_CALENDAR, null, this); lm.initLoader(LOADER_SUBSCRIPTION, null, this); // set this to true, so the menu is cleared automatically when leaving the fragment, otherwise the star icon will stay visible setHasOptionsMenu(true); return returnView; }
From source file:com.battlelancer.seriesguide.ui.MovieDetailsFragment.java
private void populateMovieViews() { /**/*from w ww . j a v a2s.c om*/ * Take title, overview and poster from TMDb as they are localized. * Everything else from trakt. */ Movie traktMovie = mMovieDetails.traktMovie(); com.uwetrottmann.tmdb.entities.Movie tmdbMovie = mMovieDetails.tmdbMovie(); mMovieTitle.setText(tmdbMovie.title); mMovieDescription.setText(tmdbMovie.overview); // release date and runtime: "July 17, 2009 | 95 min" StringBuilder releaseAndRuntime = new StringBuilder(); if (traktMovie.released != null && traktMovie.released.getTime() != 0) { releaseAndRuntime.append(DateUtils.formatDateTime(getActivity(), traktMovie.released.getTime(), DateUtils.FORMAT_SHOW_DATE)); releaseAndRuntime.append(" | "); } releaseAndRuntime.append(getString(R.string.runtime_minutes, tmdbMovie.runtime)); mMovieReleaseDate.setText(releaseAndRuntime.toString()); // check-in button final String title = tmdbMovie.title; // fall back to local title for tvtag check-in if we currently don't have the original one final String originalTitle = TextUtils.isEmpty(tmdbMovie.original_title) ? title : tmdbMovie.original_title; mCheckinButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // display a check-in dialog MovieCheckInDialogFragment f = MovieCheckInDialogFragment.newInstance(mTmdbId, title, originalTitle); f.show(getFragmentManager(), "checkin-dialog"); fireTrackerEvent("Check-In"); } }); CheatSheet.setup(mCheckinButton); // watched button (only supported when connected to trakt) if (TraktCredentials.get(getActivity()).hasCredentials()) { final boolean isWatched = traktMovie.watched != null && traktMovie.watched; Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(mWatchedButton, 0, isWatched ? Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatched) : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatch), 0, 0); mWatchedButton.setText(isWatched ? R.string.action_unwatched : R.string.action_watched); CheatSheet.setup(mWatchedButton, isWatched ? R.string.action_unwatched : R.string.action_watched); mWatchedButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // disable button, will be re-enabled on data reload once action completes v.setEnabled(false); if (isWatched) { MovieTools.unwatchedMovie(getActivity(), mTmdbId); fireTrackerEvent("Unwatched movie"); } else { MovieTools.watchedMovie(getActivity(), mTmdbId); fireTrackerEvent("Watched movie"); } } }); mWatchedButton.setEnabled(true); } else { mWatchedButton.setVisibility(View.GONE); } // collected button final boolean isInCollection = traktMovie.inCollection != null && traktMovie.inCollection; Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(mCollectedButton, 0, isInCollection ? R.drawable.ic_collected : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollect), 0, 0); mCollectedButton .setText(isInCollection ? R.string.action_collection_remove : R.string.action_collection_add); CheatSheet.setup(mCollectedButton, isInCollection ? R.string.action_collection_remove : R.string.action_collection_add); mCollectedButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // disable button, will be re-enabled on data reload once action completes v.setEnabled(false); if (isInCollection) { MovieTools.removeFromCollection(getActivity(), mTmdbId); fireTrackerEvent("Uncollected movie"); } else { MovieTools.addToCollection(getActivity(), mTmdbId); fireTrackerEvent("Collected movie"); } } }); mCollectedButton.setEnabled(true); // watchlist button final boolean isInWatchlist = traktMovie.inWatchlist != null && traktMovie.inWatchlist; Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(mWatchlistedButton, 0, isInWatchlist ? R.drawable.ic_listed : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableList), 0, 0); mWatchlistedButton.setText(isInWatchlist ? R.string.watchlist_remove : R.string.watchlist_add); CheatSheet.setup(mWatchlistedButton, isInWatchlist ? R.string.watchlist_remove : R.string.watchlist_add); mWatchlistedButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // disable button, will be re-enabled on data reload once action completes v.setEnabled(false); if (isInWatchlist) { MovieTools.removeFromWatchlist(getActivity(), mTmdbId); fireTrackerEvent("Unwatchlist movie"); } else { MovieTools.addToWatchlist(getActivity(), mTmdbId); fireTrackerEvent("Watchlist movie"); } } }); mWatchlistedButton.setEnabled(true); // show button bar mButtonContainer.setVisibility(View.VISIBLE); // ratings mRatingsTmdbValue.setText(TmdbTools.buildRatingValue(tmdbMovie.vote_average)); mRatingsTraktUserValue.setText(TraktTools.buildUserRatingString(getActivity(), traktMovie.rating_advanced)); if (traktMovie.ratings != null) { mRatingsTraktVotes.setText(TraktTools.buildRatingVotesString(getActivity(), traktMovie.ratings.votes)); mRatingsTraktValue.setText(TraktTools.buildRatingPercentageString(traktMovie.ratings.percentage)); } mRatingsContainer.setVisibility(View.VISIBLE); // genres Utils.setValueOrPlaceholder(mMovieGenres, TmdbTools.buildGenresString(tmdbMovie.genres)); // trakt comments link mCommentsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getActivity(), TraktShoutsActivity.class); i.putExtras(TraktShoutsActivity.createInitBundleMovie(title, mTmdbId)); ActivityCompat.startActivity(getActivity(), i, ActivityOptionsCompat .makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle()); fireTrackerEvent("Comments"); } }); // load poster, cache on external storage if (!TextUtils.isEmpty(tmdbMovie.poster_path)) { ServiceUtils.getPicasso(getActivity()).load(mImageBaseUrl + tmdbMovie.poster_path) .into(mMoviePosterBackground); } }
From source file:com.battlelancer.seriesguide.ui.ShowFragment.java
private void populateShow() { if (mShowCursor == null) { return;//from w w w . j a v a 2 s .c o m } // title mShowTitle = mShowCursor.getString(ShowQuery.TITLE); mShowPoster = mShowCursor.getString(ShowQuery.POSTER); // status if (mShowCursor.getInt(ShowQuery.STATUS) == 1) { mTextViewStatus.setTextColor(getResources().getColor( Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.textColorSgGreen))); mTextViewStatus.setText(getString(R.string.show_isalive)); } else { mTextViewStatus.setTextColor(Color.GRAY); mTextViewStatus.setText(getString(R.string.show_isnotalive)); } // release time String releaseDay = mShowCursor.getString(ShowQuery.RELEASE_DAY); long releaseTime = mShowCursor.getLong(ShowQuery.RELEASE_TIME_MS); String releaseCountry = mShowCursor.getString(ShowQuery.RELEASE_COUNTRY); if (!TextUtils.isEmpty(releaseDay)) { String[] values = TimeTools.formatToShowReleaseTimeAndDay(getActivity(), releaseTime, releaseCountry, releaseDay); mTextViewReleaseTime.setText(values[1] + " " + values[0]); } else { mTextViewReleaseTime.setText(null); } // runtime mTextViewRuntime.setText(getString(R.string.runtime_minutes, mShowCursor.getInt(ShowQuery.RUNTIME))); // network mTextViewNetwork.setText(mShowCursor.getString(ShowQuery.NETWORK)); // favorite button final boolean isFavorite = mShowCursor.getInt(ShowQuery.IS_FAVORITE) == 1; mButtonFavorite.setEnabled(true); Utils.setCompoundDrawablesRelativeWithIntrinsicBounds(mButtonFavorite, 0, Utils.resolveAttributeToResourceId(getActivity().getTheme(), isFavorite ? R.attr.drawableStar : R.attr.drawableStar0), 0, 0); mButtonFavorite.setText(isFavorite ? R.string.context_unfavorite : R.string.context_favorite); CheatSheet.setup(mButtonFavorite, isFavorite ? R.string.context_unfavorite : R.string.context_favorite); mButtonFavorite.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // disable until action is complete v.setEnabled(false); ShowTools.get(v.getContext()).storeIsFavorite(getShowTvdbId(), !isFavorite); } }); // overview mTextViewOverview.setText(mShowCursor.getString(ShowQuery.OVERVIEW)); // country for release time calculation // show "unknown" if country is not supported mTextViewReleaseCountry.setText( TimeTools.isUnsupportedCountry(releaseCountry) ? getString(R.string.unknown) : releaseCountry); // original release String firstRelease = mShowCursor.getString(ShowQuery.FIRST_RELEASE); Utils.setValueOrPlaceholder(mTextViewFirstRelease, TimeTools.getShowReleaseYear(firstRelease, releaseTime, releaseCountry)); // content rating Utils.setValueOrPlaceholder(mTextViewContentRating, mShowCursor.getString(ShowQuery.CONTENT_RATING)); // genres Utils.setValueOrPlaceholder(mTextViewGenres, Utils.splitAndKitTVDBStrings(mShowCursor.getString(ShowQuery.GENRES))); // TVDb rating String tvdbRating = mShowCursor.getString(ShowQuery.TVDB_RATING); if (!TextUtils.isEmpty(tvdbRating)) { mTextViewTvdbRating.setText(tvdbRating); } // last edit long lastEditRaw = mShowCursor.getLong(ShowQuery.LAST_EDIT_MS); if (lastEditRaw > 0) { mTextViewLastEdit.setText(DateUtils.formatDateTime(getActivity(), lastEditRaw * 1000, DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME)); } else { mTextViewLastEdit.setText(R.string.unknown); } // IMDb button String imdbId = mShowCursor.getString(ShowQuery.IMDBID); ServiceUtils.setUpImdbButton(imdbId, mButtonImdb, TAG, getActivity()); // TVDb button ServiceUtils.setUpTvdbButton(getShowTvdbId(), mButtonTvdb, TAG); // trakt button ServiceUtils.setUpTraktButton(getShowTvdbId(), mButtonTrakt, TAG); // web search button ServiceUtils.setUpWebSearchButton(mShowTitle, mButtonWebSearch, TAG); // shout button mButtonComments.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getActivity(), TraktShoutsActivity.class); i.putExtras(TraktShoutsActivity.createInitBundleShow(mShowTitle, getShowTvdbId())); ActivityCompat.startActivity(getActivity(), i, ActivityOptionsCompat .makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle()); fireTrackerEvent("Shouts"); } }); // poster, full screen poster button final View posterContainer = getView().findViewById(R.id.containerShowPoster); final ImageView posterView = (ImageView) posterContainer.findViewById(R.id.imageViewShowPoster); Utils.loadPoster(getActivity(), posterView, mShowPoster); posterContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent fullscreen = new Intent(getActivity(), FullscreenImageActivity.class); fullscreen.putExtra(FullscreenImageActivity.InitBundle.IMAGE_PATH, TheTVDB.buildScreenshotUrl(mShowPoster)); ActivityCompat.startActivity(getActivity(), fullscreen, ActivityOptionsCompat .makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle()); } }); // background ImageView background = (ImageView) getView().findViewById(R.id.imageViewShowPosterBackground); Utils.loadPosterBackground(getActivity(), background, mShowPoster); onLoadTraktRatings(true); }
From source file:com.android.datetimepicker.date.DatePickerDialog.java
private void updateDisplay(boolean announce) { if (mDayOfWeekView != null) { mDayOfWeekView/*from w w w . j av a 2 s.c o m*/ .setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()) .toUpperCase(Locale.getDefault())); } mSelectedMonthTextView.setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault()) .toUpperCase(Locale.getDefault())); mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime())); mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime())); // Accessibility. long millis = mCalendar.getTimeInMillis(); mAnimator.setDateMillis(millis); int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR; String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags); mMonthAndDayView.setContentDescription(monthAndDayText); if (announce) { flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR; String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags); Utils.tryAccessibilityAnnounce(mAnimator, fullDateText); } }
From source file:hide.com.android.datetimepicker.date.DatePickerDialog.java
@SuppressLint("DefaultLocale") private void updateDisplay(boolean announce) { if (mDayOfWeekView != null) { mDayOfWeekView.setText(Utils.getLongDayOfWeekName(mCalendar).toUpperCase()); }/*w w w .ja v a 2s . com*/ mSelectedMonthTextView.setText(Utils.getShortMonthName(mCalendar).toUpperCase()); mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime())); mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime())); // Accessibility. long millis = mCalendar.getTimeInMillis(); mAnimator.setDateMillis(millis); int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR; String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags); mMonthAndDayView.setContentDescription(monthAndDayText); if (announce) { flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR; String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags); Utils.tryAccessibilityAnnounce(mAnimator, fullDateText); } }
From source file:com.redinput.datetimepickercompat.date.DatePickerDialog.java
private void updateDisplay(boolean announce) { if (mDayOfWeekView != null) { mDayOfWeekView.setText(// ww w. ja v a 2s.c o m new DateFormatSymbols(Locale.getDefault()).getWeekdays()[mCalendar.get(Calendar.DAY_OF_WEEK)] .toUpperCase(Locale.getDefault())); } mSelectedMonthTextView .setText(new DateFormatSymbols(Locale.getDefault()).getMonths()[mCalendar.get(Calendar.MONTH)] .toUpperCase(Locale.getDefault())); mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime())); mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime())); // Accessibility. long millis = mCalendar.getTimeInMillis(); mAnimator.setDateMillis(millis); int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR; String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags); mMonthAndDayView.setContentDescription(monthAndDayText); if (announce) { flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR; String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags); Utils.tryAccessibilityAnnounce(mAnimator, fullDateText); } }
From source file:mirko.android.datetimepicker.date.DatePickerDialog.java
private void updateDisplay(boolean announce) { if (mDayOfWeekView != null) { mDayOfWeekView/* www .j a v a 2s . c om*/ .setText(mCalendar.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault()) .toUpperCase(Locale.getDefault())); } if (mSelectedMonthTextView == null) { Log.i(TAG, "mSelectedMonthTextView is null updateDisplay"); } mSelectedMonthTextView.setText(mCalendar.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault()) .toUpperCase(Locale.getDefault())); mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime())); mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime())); // Accessibility. long millis = mCalendar.getTimeInMillis(); mAnimator.setDateMillis(millis); int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR; String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags); mMonthAndDayView.setContentDescription(monthAndDayText); if (announce) { flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR; String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags); Utils.tryAccessibilityAnnounce(mAnimator, fullDateText); } }
From source file:com.adguard.android.contentblocker.MainActivity.java
private void refreshStatistics() { PreferencesService preferencesService = ServiceLocator.getInstance(this).getPreferencesService(); final FilterService filterService = ServiceLocator.getInstance(this).getFilterService(); Date now = preferencesService.getLastUpdateCheck(); // Last update time if (now == null) { List<FilterList> filters = filterService.getFilters(); for (FilterList filter : filters) { if (now == null) { now = filter.getTimeUpdated(); LOG.info("Using first time of {}", filter.getName()); } else { if (filter.getTimeUpdated().after(now)) { now = filter.getTimeUpdated(); LOG.info("Using time of {}", filter.getName()); }/*ww w . j ava2 s . c o m*/ } } if (now == null) { now = new Date(); } } String dateTime = DateUtils.formatDateTime(this, now.getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_TIME); ((TextView) findViewById(R.id.updateTimeTextView)).setText(dateTime); // Enabled filters count int filterListCount = filterService.getEnabledFilterListCount(); ((TextView) findViewById(R.id.filtersCountTextView)).setText(String.format("%d", filterListCount)); // Filter rules count int filterRuleCount = filterService.getFilterRuleCount(); ((TextView) findViewById(R.id.rulesCountTextView)).setText(String.format("%d", filterRuleCount)); if (filterRuleCount == 0) { new ApplyAndRefreshTask(filterService, this).execute(); } }