Example usage for android.text.format DateUtils FORMAT_ABBREV_WEEKDAY

List of usage examples for android.text.format DateUtils FORMAT_ABBREV_WEEKDAY

Introduction

In this page you can find the example usage for android.text.format DateUtils FORMAT_ABBREV_WEEKDAY.

Prototype

int FORMAT_ABBREV_WEEKDAY

To view the source code for android.text.format DateUtils FORMAT_ABBREV_WEEKDAY.

Click Source Link

Usage

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

public static String formatToDateNoYear(Context context, long date) {
    return DateUtils.formatDateTime(context, date,
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_MONTH
                    | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_24HOUR | DateUtils.FORMAT_SHOW_TIME
                    | DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_ABBREV_WEEKDAY);
}

From source file:Main.java

/**
 * Returns a String formatted in the default locale of the device. Looks like "Ddd, Mmm dd, H:MMTT - H:MMTT
 * @param context the {@link android.content.Context} that this is running within.
 * @param start the starting date and time of this entry.
 * @param end the ending date and time of this entry.
 */// w w w .j  a v a  2  s . c  om
public static String buildTimeEntryDateAndTime(Context context, Calendar start, Calendar end) {
    return DateUtils.formatDateRange(context, start.getTimeInMillis(), end.getTimeInMillis(),
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_SHOW_TIME
                    | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY
                    | DateUtils.FORMAT_NO_YEAR);
}

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 .j  a  va2 s .  com
                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.gdgdevfest.android.apps.devfestbcn.ui.MapFragment.java

/**
 * Create an {@link AsyncQueryHandler} for use with the
 * {@link MapInfoWindowAdapter}.//from   w w w  .j a  v a 2  s . c  o  m
 */
private AsyncQueryHandler createInfowindowHandler(ContentResolver contentResolver) {
    return new AsyncQueryHandler(contentResolver) {
        StringBuilder mBuffer = new StringBuilder();
        Formatter mFormatter = new Formatter(mBuffer, Locale.getDefault());

        @Override
        protected void onQueryComplete(int token, Object cookie, Cursor cursor) {

            MarkerModel model = mMarkers.get(cookie);

            mInfoAdapter.clearData();

            if (model == null || cursor == null) {
                // query did not complete or incorrect data was loaded
                return;
            }

            final long time = UIUtils.getCurrentTime(getActivity());

            switch (token) {
            case SessionAfterQuery._TOKEN: {
                extractSession(cursor, model, time);
            }
                break;
            case SandboxCompaniesAtQuery._TOKEN: {
                extractSandbox(cursor, model, time);
            }
            }

            // update the displayed window
            model.marker.showInfoWindow();
        }

        private void extractSandbox(Cursor cursor, MarkerModel model, long time) {
            // get tracks data from cache: icon and color
            TrackModel track = mTracks.get(model.track);
            int color = (track != null) ? track.color : 0;
            int iconResId = 0;
            if (track != null) {
                iconResId = getResources().getIdentifier("track_" + ParserUtils.sanitizeId(track.name),
                        "drawable", getActivity().getPackageName());
            }

            if (cursor != null && cursor.getCount() > 0) {
                cursor.moveToFirst();

                StringBuilder sb = new StringBuilder();
                int count = 0;
                final int maxCompaniesDisplay = getResources()
                        .getInteger(R.integer.sandbox_company_list_max_display);
                while (!cursor.isAfterLast() && count < maxCompaniesDisplay) {
                    if (sb.length() > 0) {
                        sb.append(", ");
                    }
                    sb.append(cursor.getString(SandboxCompaniesAtQuery.COMPANY_NAME));
                    count++;
                    cursor.moveToNext();
                }
                if (count >= maxCompaniesDisplay && !cursor.isAfterLast()) {
                    // Additional sandbox companies to display
                    sb.append(", &hellip;");
                }

                mInfoAdapter.setSandbox(model.marker, model.label, color, iconResId,
                        sb.length() > 0 ? sb.toString() : null);

            } else {
                // No active sandbox companies
                mInfoAdapter.setSandbox(model.marker, model.label, color, iconResId, null);
            }

            model.marker.showInfoWindow();
        }

        private static final long SHOW_UPCOMING_TIME = 24 * 60 * 60 * 1000; // 24 hours

        private void extractSession(Cursor cursor, MarkerModel model, long time) {

            if (cursor != null && cursor.getCount() > 0) {
                cursor.moveToFirst();

                String currentTitle = null;
                String nextTitle = null;
                String nextTime = null;

                final long blockStart = cursor.getLong(SessionAfterQuery.BLOCK_START);
                final long blockEnd = cursor.getLong(SessionAfterQuery.BLOCK_END);
                boolean inProgress = time >= blockStart && time <= blockEnd;

                if (inProgress) {
                    // A session is running, display its name and optionally
                    // the next session
                    currentTitle = cursor.getString(SessionAfterQuery.SESSION_TITLE);

                    //move to the next entry
                    cursor.moveToNext();
                }

                if (!cursor.isAfterLast()) {
                    //There is a session coming up next, display only it if it's within 24 hours of the current time
                    final long nextStart = cursor.getLong(SessionAfterQuery.BLOCK_START);

                    if (nextStart < time + SHOW_UPCOMING_TIME) {
                        nextTitle = cursor.getString(SessionAfterQuery.SESSION_TITLE);
                        mBuffer.setLength(0);

                        boolean showWeekday = !DateUtils.isToday(blockStart)
                                && !UIUtils.isSameDayDisplay(UIUtils.getCurrentTime(getActivity()), blockStart,
                                        getActivity());

                        nextTime = DateUtils.formatDateRange(getActivity(), mFormatter, blockStart, blockStart,
                                DateUtils.FORMAT_SHOW_TIME | (showWeekday
                                        ? DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_WEEKDAY
                                        : 0),
                                PrefUtils.getDisplayTimeZone(getActivity()).getID()).toString();
                    }
                }

                // populate the info window adapter
                mInfoAdapter.setSessionData(model.marker, model.label, currentTitle, nextTitle, nextTime,
                        inProgress);

            } else {
                // No entries, display name of room only
                mInfoAdapter.setMarker(model.marker, model.label);
            }
        }

    };
}