Example usage for android.text.format DateUtils FORMAT_SHOW_WEEKDAY

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

Introduction

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

Prototype

int FORMAT_SHOW_WEEKDAY

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

Click Source Link

Usage

From source file:com.dgsd.android.ShiftTracker.Fragment.EditShiftFragment.java

@Override
public void onDateSelected(int typeCode, int julianDay) {
    if (getActivity() == null)
        return;//from   w  ww  . j  a  v a 2 s.c  o m

    final long millis = TimeUtils.getStartMillisForJulianDay(julianDay);
    String formatted = DateUtils.formatDateRange(getActivity(), millis, millis,
            DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_DATE);

    if (typeCode == TYPE_CODE_START) {
        mStartDate.setTag(julianDay);
        mStartDate.setText(formatted);
    } else {
        mEndDate.setTag(julianDay);
        mEndDate.setText(formatted);
    }
}

From source file:im.neon.adapters.VectorMessagesAdapter.java

/**
 * Converts a difference of days to a string.
 * @param date the date to display/*from  w ww .j  a v  a  2s  .c o  m*/
 * @param nbrDays the number of days between the reference days
 * @return the date text
 */
private String dateDiff(Date date, long nbrDays) {
    if (nbrDays == 0) {
        return mContext.getResources().getString(R.string.today);
    } else if (nbrDays == 1) {
        return mContext.getResources().getString(R.string.yesterday);
    } else if (nbrDays < 7) {
        return (new SimpleDateFormat("EEEE", AdapterUtils.getLocale(mContext))).format(date);
    } else {
        int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_ABBREV_ALL
                | DateUtils.FORMAT_SHOW_WEEKDAY;

        Formatter f = new Formatter(new StringBuilder(50), AdapterUtils.getLocale(mContext));
        return DateUtils.formatDateRange(mContext, f, date.getTime(), date.getTime(), flags).toString();
    }
}

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 .java2  s. co 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);
            }
        }

    };
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    MenuItem item;/*ww w  .  j a v  a  2s.c om*/

    // If the trackball is held down, then the context menu pops up and
    // we never get onKeyUp() for the long-press. So check for it here
    // and change the selection to the long-press state.
    /*if (mSelectionMode != SELECTION_LONGPRESS) {
    mSelectionMode = SELECTION_LONGPRESS;
    invalidate();
    }*/

    final long startMillis = getSelectedTimeInMillis();
    int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_CAP_NOON_MIDNIGHT | DateUtils.FORMAT_SHOW_WEEKDAY;
    final String title = DayUtils.formatDateRange(mContext, startMillis, startMillis, flags);
    menu.setHeaderTitle(title);

    int numSelectedEvents = mSelectedEvents.size();
    if (mNumDays == 1) {
        // Day view.

        // If there is a selected event, then allow it to be viewed and
        // edited.
        if (numSelectedEvents >= 1) {
            item = menu.add(0, MENU_EVENT_VIEW, 0, "View event");
            item.setOnMenuItemClickListener(mContextMenuHandler);
            item.setIcon(android.R.drawable.ic_menu_info_details);
        }
    } else {
        // Week view.

        // If there is a selected event, then allow it to be viewed and
        // edited.
        if (numSelectedEvents >= 1) {
            item = menu.add(0, MENU_EVENT_VIEW, 0, "View event");
            item.setOnMenuItemClickListener(mContextMenuHandler);
            item.setIcon(android.R.drawable.ic_menu_info_details);
        }

        item = menu.add(0, MENU_DAY, 0, "Show day");
        item.setOnMenuItemClickListener(mContextMenuHandler);
        item.setIcon(android.R.drawable.ic_menu_day);
        item.setAlphabeticShortcut('d');
    }
}