Example usage for android.text.format DateUtils FORMAT_ABBREV_MONTH

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

Introduction

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

Prototype

int FORMAT_ABBREV_MONTH

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

Click Source Link

Usage

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

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

/**
 * 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 ww .ja 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: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 {/* www  .j  a  v  a2 s .  co  m*/
        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:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java

@Override
protected void bindHeaderView(View view, Context context, Cursor cursor) {
    HeaderViewHolder holder = (HeaderViewHolder) view.getTag();

    final int jd = cursor.getInt(cursor.getColumnIndex(DbField.JULIAN_DAY.name));
    String title = mJdToTitleArray.get(jd, null);
    if (TextUtils.isEmpty(title)) {

        mTime.setJulianDay(jd);//w w  w. ja v a2  s.  co m
        title = DateUtils.formatDateTime(getContext(), mTime.toMillis(true), DateUtils.FORMAT_SHOW_DATE
                | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_NO_YEAR);

        mJdToTitleArray.put(jd, title);
    }

    //Highlight the current day with a bold title
    if (jd == mCurrentJulianDay)
        holder.title.setTypeface(null, Typeface.BOLD);
    else
        holder.title.setTypeface(null, Typeface.NORMAL);

    holder.title.setText(title);
}

From source file:com.tum.atse.Utils.java

/**
 * Returns a user-friendly localized date.
 *
 * @param context/*w  ww  .jav  a 2 s. c  om*/
 * @param dateTime
 * @return
 */
public static String getFormattedDate(Context context, DateTime dateTime) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(dateTime.getValue());
    return DateUtils.formatDateTime(context, cal.getTimeInMillis(),
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH);
}

From source file:com.tum.atse.Utils.java

/**
 * Returns a user-friendly localized data range.
 *
 * @param context/*from   w  w w .  j av  a 2 s .  c  o  m*/
 * @param dateTimeStart
 * @param dateTimeEnd
 * @return
 */
public static String getFormattedDateRange(Context context, DateTime dateTimeStart, DateTime dateTimeEnd) {
    Calendar cal1 = Calendar.getInstance();
    cal1.setTimeInMillis(dateTimeStart.getValue());

    Calendar cal2 = Calendar.getInstance();
    cal2.setTimeInMillis(dateTimeEnd.getValue());
    return DateUtils.formatDateRange(context, cal1.getTimeInMillis(), cal2.getTimeInMillis(),
            DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH);
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.PlusStreamRowViewBinder.java

public static void bindActivityView(final View rootView, Activity activity, ImageLoader imageLoader,
        boolean singleSourceMode) {
    // Prepare view holder.
    ViewHolder tempViews = (ViewHolder) rootView.getTag();
    final ViewHolder views;
    if (tempViews != null) {
        views = tempViews;/*from w  w  w. j  av  a 2s. c  om*/
    } else {
        views = new ViewHolder();
        rootView.setTag(views);

        // Author and metadata box
        views.authorContainer = rootView.findViewById(R.id.stream_author_container);
        views.userImage = (ImageView) rootView.findViewById(R.id.stream_user_image);
        views.userName = (TextView) rootView.findViewById(R.id.stream_user_name);
        views.time = (TextView) rootView.findViewById(R.id.stream_time);

        // Author's content
        views.content = (TextView) rootView.findViewById(R.id.stream_content);

        // Original share box
        views.originalContainer = rootView.findViewById(R.id.stream_original_container);
        views.originalAuthor = (TextView) rootView.findViewById(R.id.stream_original_author);
        views.originalContent = (TextView) rootView.findViewById(R.id.stream_original_content);

        // Media box
        views.mediaContainer = rootView.findViewById(R.id.stream_media_container);
        views.mediaBackground = (ImageView) rootView.findViewById(R.id.stream_media_background);
        views.mediaOverlay = (ImageView) rootView.findViewById(R.id.stream_media_overlay);
        views.mediaTitle = (TextView) rootView.findViewById(R.id.stream_media_title);
        views.mediaSubtitle = (TextView) rootView.findViewById(R.id.stream_media_subtitle);

        // Interactions box
        views.interactionsContainer = rootView.findViewById(R.id.stream_interactions_container);
        views.plusOnes = (TextView) rootView.findViewById(R.id.stream_plus_ones);
        views.shares = (TextView) rootView.findViewById(R.id.stream_shares);
        views.comments = (TextView) rootView.findViewById(R.id.stream_comments);
    }

    final Context context = rootView.getContext();
    final Resources res = context.getResources();

    // Determine if this is a reshare (affects how activity fields are to be interpreted).
    Activity.PlusObject.Actor originalAuthor = activity.getObject().getActor();
    boolean isReshare = "share".equals(activity.getVerb()) && originalAuthor != null;

    // Author and metadata box
    views.authorContainer.setVisibility(singleSourceMode ? View.GONE : View.VISIBLE);
    views.userName.setText(activity.getActor().getDisplayName());

    // Find user profile image url
    String userImageUrl = null;
    if (activity.getActor().getImage() != null) {
        userImageUrl = activity.getActor().getImage().getUrl();
    }

    // Load image from network in background thread using Volley library
    imageLoader.get(userImageUrl, views.userImage, PLACEHOLDER_USER_IMAGE);

    long thenUTC = activity.getUpdated().getValue() + activity.getUpdated().getTimeZoneShift() * 60000;
    views.time.setText(DateUtils.getRelativeTimeSpanString(thenUTC, System.currentTimeMillis(),
            DateUtils.SECOND_IN_MILLIS, DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_ABBREV_RELATIVE));

    // Author's additional content
    String selfContent = isReshare ? activity.getAnnotation() : activity.getObject().getContent();
    views.content.setMaxLines(singleSourceMode ? 1000 : 5);
    if (!TextUtils.isEmpty(selfContent)) {
        views.content.setVisibility(View.VISIBLE);
        views.content.setText(Html.fromHtml(selfContent));
    } else {
        views.content.setVisibility(View.GONE);
    }

    // Original share box
    if (isReshare) {
        views.originalContainer.setVisibility(View.VISIBLE);

        // Set original author text, highlight author name
        final String author = res.getString(R.string.stream_originally_shared, originalAuthor.getDisplayName());
        final SpannableStringBuilder spannableAuthor = new SpannableStringBuilder(author);
        spannableAuthor.setSpan(new StyleSpan(Typeface.BOLD),
                author.length() - originalAuthor.getDisplayName().length(), author.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        views.originalAuthor.setText(spannableAuthor, TextView.BufferType.SPANNABLE);

        String originalContent = activity.getObject().getContent();
        views.originalContent.setMaxLines(singleSourceMode ? 1000 : 3);
        if (!TextUtils.isEmpty(originalContent)) {
            views.originalContent.setVisibility(View.VISIBLE);
            views.originalContent.setText(Html.fromHtml(originalContent));
        } else {
            views.originalContent.setVisibility(View.GONE);
        }
    } else {
        views.originalContainer.setVisibility(View.GONE);
    }

    // Media box

    // Set media content.
    List<Activity.PlusObject.Attachments> attachments = activity.getObject().getAttachments();
    if (attachments != null && attachments.size() > 0) {
        Activity.PlusObject.Attachments attachment = attachments.get(0);
        String objectType = attachment.getObjectType();
        String imageUrl = attachment.getImage() != null ? attachment.getImage().getUrl() : null;
        if (imageUrl == null && attachment.getThumbnails() != null && attachment.getThumbnails().size() > 0) {
            Thumbnails thumb = attachment.getThumbnails().get(0);
            imageUrl = thumb.getImage() != null ? thumb.getImage().getUrl() : null;
        }

        // Load image from network in background thread using Volley library
        imageLoader.get(imageUrl, views.mediaBackground, PLACEHOLDER_MEDIA_IMAGE);

        boolean overlayStyle = false;

        views.mediaOverlay.setImageDrawable(null);
        if (("photo".equals(objectType) || "video".equals(objectType) || "album".equals(objectType))
                && !TextUtils.isEmpty(imageUrl)) {
            overlayStyle = true;
            views.mediaOverlay
                    .setImageResource("video".equals(objectType) ? R.drawable.ic_stream_media_overlay_video
                            : R.drawable.ic_stream_media_overlay_photo);

        } else if ("article".equals(objectType) || "event".equals(objectType)) {
            overlayStyle = false;
            views.mediaTitle.setText(attachment.getDisplayName());
            if (!TextUtils.isEmpty(attachment.getUrl())) {
                Uri uri = Uri.parse(attachment.getUrl());
                views.mediaSubtitle.setText(uri.getHost());
            } else {
                views.mediaSubtitle.setText("");
            }
        }

        views.mediaContainer.setVisibility(View.VISIBLE);
        views.mediaContainer.setBackgroundResource(
                overlayStyle ? R.color.plus_stream_media_background : android.R.color.black);
        if (overlayStyle) {
            views.mediaBackground.clearColorFilter();
        } else {
            views.mediaBackground.setColorFilter(res.getColor(R.color.plus_media_item_tint));
        }
        views.mediaOverlay.setVisibility(overlayStyle ? View.VISIBLE : View.GONE);
        views.mediaTitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE);
        views.mediaSubtitle.setVisibility(overlayStyle ? View.GONE : View.VISIBLE);
    } else {
        views.mediaContainer.setVisibility(View.GONE);
        views.mediaBackground.setImageDrawable(null);
        views.mediaOverlay.setImageDrawable(null);
    }

    // Interactions box
    final int plusOneCount = (activity.getObject().getPlusoners() != null)
            ? activity.getObject().getPlusoners().getTotalItems().intValue()
            : 0;
    if (plusOneCount > 0) {
        views.plusOnes.setVisibility(View.VISIBLE);
        views.plusOnes.setText(getPlusOneString(plusOneCount));
    } else {
        views.plusOnes.setVisibility(View.GONE);
    }

    final int commentCount = (activity.getObject().getReplies() != null)
            ? activity.getObject().getReplies().getTotalItems().intValue()
            : 0;
    if (commentCount > 0) {
        views.comments.setVisibility(View.VISIBLE);
        views.comments.setText(Integer.toString(commentCount));
    } else {
        views.comments.setVisibility(View.GONE);
    }

    final int resharerCount = (activity.getObject().getResharers() != null)
            ? activity.getObject().getResharers().getTotalItems().intValue()
            : 0;
    if (resharerCount > 0) {
        views.shares.setVisibility(View.VISIBLE);
        views.shares.setText(Integer.toString(resharerCount));
    } else {
        views.shares.setVisibility(View.GONE);
    }

    views.interactionsContainer.setVisibility(
            (plusOneCount > 0 || commentCount > 0 || resharerCount > 0) ? View.VISIBLE : View.GONE);
}

From source file:net.abcdroid.devfest12.ui.MyScheduleFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (getActivity() == null) {
        return;/*from   w ww  .j a  va2 s  .  co  m*/
    }

    long currentTime = UIUtils.getCurrentTime(getActivity());
    int firstNowPosition = ListView.INVALID_POSITION;

    List<SimpleSectionedListAdapter.Section> sections = new ArrayList<SimpleSectionedListAdapter.Section>();
    cursor.moveToFirst();
    long previousBlockStart = -1;
    long blockStart, blockEnd;
    while (!cursor.isAfterLast()) {
        blockStart = cursor.getLong(BlocksQuery.BLOCK_START);
        blockEnd = cursor.getLong(BlocksQuery.BLOCK_END);
        if (!UIUtils.isSameDay(previousBlockStart, blockStart)) {
            sections.add(new SimpleSectionedListAdapter.Section(cursor.getPosition(),
                    DateUtils.formatDateTime(getActivity(), blockStart, DateUtils.FORMAT_ABBREV_MONTH
                            | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY)));
        }
        if (mScrollToNow && firstNowPosition == ListView.INVALID_POSITION
        // if we're currently in this block, or we're not in a block
        // and this
        // block is in the future, then this is the scroll position
                && ((blockStart < currentTime && currentTime < blockEnd) || blockStart > currentTime)) {
            firstNowPosition = cursor.getPosition();
        }
        previousBlockStart = blockStart;
        cursor.moveToNext();
    }

    mScheduleAdapter.changeCursor(cursor);

    SimpleSectionedListAdapter.Section[] dummy = new SimpleSectionedListAdapter.Section[sections.size()];
    mAdapter.setSections(sections.toArray(dummy));

    if (mScrollToNow && firstNowPosition != ListView.INVALID_POSITION) {
        firstNowPosition = mAdapter.positionToSectionedPosition(firstNowPosition);
        getListView().setSelectionFromTop(firstNowPosition,
                getResources().getDimensionPixelSize(R.dimen.list_scroll_top_offset));
        mScrollToNow = false;
    }
}

From source file:com.androzic.track.TrackDetails.java

private void updateTrackDetails() {
    AppCompatActivity activity = (AppCompatActivity) getActivity();
    Resources resources = getResources();

    activity.getSupportActionBar().setTitle(track.name);

    View view = getView();//from www  . j ava2 s . c o  m

    int pointCount = track.getPointCount();
    ((TextView) view.findViewById(R.id.point_count))
            .setText(resources.getQuantityString(R.plurals.numberOfPoints, pointCount, pointCount));

    String distance = StringFormatter.distanceH(track.distance);
    ((TextView) view.findViewById(R.id.distance)).setText(distance);

    Track.TrackPoint ftp = track.getPoint(0);
    Track.TrackPoint ltp = track.getLastPoint();

    String start_coords = StringFormatter.coordinates(" ", ftp.latitude, ftp.longitude);
    ((TextView) view.findViewById(R.id.start_coordinates)).setText(start_coords);
    String finish_coords = StringFormatter.coordinates(" ", ltp.latitude, ltp.longitude);
    ((TextView) view.findViewById(R.id.finish_coordinates)).setText(finish_coords);

    Date start_date = new Date(ftp.time);
    ((TextView) view.findViewById(R.id.start_date))
            .setText(DateFormat.getDateFormat(activity).format(start_date) + " "
                    + DateFormat.getTimeFormat(activity).format(start_date));
    Date finish_date = new Date(ltp.time);
    ((TextView) view.findViewById(R.id.finish_date))
            .setText(DateFormat.getDateFormat(activity).format(finish_date) + " "
                    + DateFormat.getTimeFormat(activity).format(finish_date));

    long elapsed = (ltp.time - ftp.time) / 1000;
    String timeSpan;
    if (elapsed < 24 * 60 * 60 * 3) {
        timeSpan = DateUtils.formatElapsedTime(elapsed);
    } else {
        timeSpan = DateUtils.formatDateRange(activity, ftp.time, ltp.time, DateUtils.FORMAT_ABBREV_MONTH);
    }
    ((TextView) view.findViewById(R.id.time_span)).setText(timeSpan);

    // Gather statistics
    int segmentCount = 0;
    double minElevation = Double.MAX_VALUE;
    double maxElevation = Double.MIN_VALUE;
    double maxSpeed = 0;

    MeanValue mv = new MeanValue();

    for (Track.TrackSegment segment : track.getSegments()) {
        Track.TrackPoint ptp = null;
        if (segment.independent)
            segmentCount++;

        for (Track.TrackPoint tp : segment.getPoints()) {
            if (ptp != null) {
                double d = Geo.distance(tp.latitude, tp.longitude, ptp.latitude, ptp.longitude);
                double speed = d / ((tp.time - ptp.time) / 1000);
                if (speed == Double.POSITIVE_INFINITY)
                    continue;
                mv.addValue(speed);
                if (speed > maxSpeed)
                    maxSpeed = speed;
            }
            ptp = tp;
            if (tp.elevation < minElevation && tp.elevation != 0)
                minElevation = tp.elevation;
            if (tp.elevation > maxElevation)
                maxElevation = tp.elevation;
        }
    }

    double averageSpeed = mv.getMeanValue();

    ((TextView) view.findViewById(R.id.segment_count))
            .setText(resources.getQuantityString(R.plurals.numberOfSegments, segmentCount, segmentCount));

    ((TextView) view.findViewById(R.id.max_elevation)).setText(StringFormatter.elevationH(maxElevation));
    ((TextView) view.findViewById(R.id.min_elevation)).setText(StringFormatter.elevationH(minElevation));

    ((TextView) view.findViewById(R.id.max_speed)).setText(String.format(Locale.getDefault(), "%s: %s",
            resources.getString(R.string.max_speed), StringFormatter.speedH(maxSpeed)));
    ((TextView) view.findViewById(R.id.average_speed)).setText(String.format(Locale.getDefault(), "%s: %s",
            resources.getString(R.string.average_speed), StringFormatter.speedH(averageSpeed)));
}