Example usage for android.text.format DateUtils FORMAT_ABBREV_ALL

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

Introduction

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

Prototype

int FORMAT_ABBREV_ALL

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

Click Source Link

Usage

From source file:Main.java

public static String formatDate(Context context, long date) {
    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_DATE
            | DateUtils.FORMAT_SHOW_TIME;
    return DateUtils.formatDateTime(context, date, format_flags);
}

From source file:Main.java

public static String formatDateRange(Context context, Date start, Date end) {
    if (start != null && end != null) {
        return DateUtils.formatDateRange(context, start.getTime(), end.getTime(), DateUtils.FORMAT_ABBREV_ALL);
    }//from w ww. j av a2 s.  c  om
    return "";
}

From source file:Main.java

/**
 *
 * @param context//  ww  w. ja  v  a 2 s .co m
 * @return string label
 */
public static String getRefreshTime(Context context) {
    String label = DateUtils.formatDateTime(context, System.currentTimeMillis(),
            DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);

    return label;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static String formatTimeStampString(Context context, long when, boolean fullFormat) {
    Time then = new Time();
    then.set(when);//  w  ww.  j  a  v a2s .c  om

    Time now = new Time();
    now.setToNow();

    // Basic settings for formatDateTime() we want for all cases.
    int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL
            | DateUtils.FORMAT_CAP_AMPM;

    // If the message is from a different year, show the date and year.
    if (then.year != now.year) {
        format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE;
    } else if (then.yearDay != now.yearDay) {
        // If it is from a different day than today, show only the date.
        format_flags |= DateUtils.FORMAT_SHOW_DATE;
    } else {
        // Otherwise, if the message is from today, show the time.
        format_flags |= DateUtils.FORMAT_SHOW_TIME;
    }

    // If the caller has asked for full details, make sure to show the date
    // and time no matter what we've determined above (but still make
    // showing
    // the year only happen if it is a different year from today).
    if (fullFormat) {
        format_flags |= (DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
    }

    return DateUtils.formatDateTime(context, when, format_flags);
}

From source file:Main.java

/**
 * Get formatted time./*  w  ww  .j  av  a  2s  .  co m*/
 *
 * @param publishedTime The published time in millis.
 *
 * @return The formatted time.
 */
static public String getFormattedTime(long publishedTime) {
    // This is copied from RecentCallsListActivity.java

    long now = System.currentTimeMillis();

    // Set the date/time field by mixing relative and absolute times.
    int flags = DateUtils.FORMAT_ABBREV_ALL;

    if (!DateUtils.isToday(publishedTime)) {
        // DateUtils.getRelativeTimeSpanString doesn't consider the nature
        // days comparing with DateUtils.getRelativeDayString. Override the
        // real date to implement the requirement.

        Time time = new Time();
        time.set(now);
        long gmtOff = time.gmtoff;
        int days = Time.getJulianDay(publishedTime, gmtOff) - Time.getJulianDay(now, gmtOff);

        // Set the delta from now to get the correct display
        publishedTime = now + days * DateUtils.DAY_IN_MILLIS;
    } else if (publishedTime > now && (publishedTime - now) < DateUtils.HOUR_IN_MILLIS) {
        // Avoid e.g. "1 minute left" when publish time is "07:00" and
        // current time is "06:58"
        publishedTime += DateUtils.MINUTE_IN_MILLIS;
    }

    return (DateUtils.getRelativeTimeSpanString(publishedTime, now, DateUtils.MINUTE_IN_MILLIS, flags))
            .toString();
}

From source file:com.calgen.udacity.lego.ui.Utils.java

/**
 * @param mCursor needed to fetch data/*www.  j a va 2  s. co m*/
 * @param context needed to fetch string resources
 * @return modified string as [date] by [author]
 */
public static String getModifiedByline(Cursor mCursor, Context context) {
    return String.format(context.getString(R.string.by_line),
            DateUtils
                    .getRelativeTimeSpanString(mCursor.getLong(ArticleLoader.Query.PUBLISHED_DATE),
                            System.currentTimeMillis(), DateUtils.HOUR_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL)
                    .toString(),
            mCursor.getString(ArticleLoader.Query.AUTHOR));
}

From source file:com.google.samples.apps.iosched.util.TimeUtils.java

/**
 * Format a {@code date} honoring the app preference for using Conference or device timezone.
 * {@code Context} is used to lookup the shared preference settings.
 *///  w w w . j  a va  2s .  com
public static String formatShortDate(Context context, Date date) {
    StringBuilder sb = new StringBuilder();
    Formatter formatter = new Formatter(sb);
    return DateUtils.formatDateRange(context, formatter, date.getTime(), date.getTime(),
            DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_NO_YEAR,
            SettingsUtils.getDisplayTimeZone(context).getID()).toString();
}

From source file:org.dronix.android.unisannio.fragment.TabOne.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.tabone, container, false);
    mPullRefreshListView = (PullToRefreshListView) view.findViewById(R.id.pull_refresh_list);

    // Set a listener to be invoked when the list should be refreshed.
    mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
        @Override/*from  w w w .j  av a2  s . c  o  m*/
        public void onRefresh(PullToRefreshBase<ListView> refreshView) {
            mPullRefreshListView.setLastUpdatedLabel(DateUtils.formatDateTime(getActivity(),
                    System.currentTimeMillis(),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL));

            new NewsRetriever().execute();
        }
    });

    ListView actualListView = mPullRefreshListView.getRefreshableView();

    news = new ArrayList<News>();
    news.add(new News("", getString(R.string.pull)));

    mAdapter = new LazyAdapter(getActivity(), news);

    actualListView.setAdapter(mAdapter);
    return view;
}

From source file:ca.rmen.android.poetassistant.wotd.WotdLoader.java

@Override
public ResultListData<WotdEntry> loadInBackground() {
    Log.d(TAG, "loadInBackground()");

    List<WotdEntry> data = new ArrayList<>(100);

    Cursor cursor = mDictionary.getRandomWordCursor();
    if (cursor == null || cursor.getCount() == 0)
        return emptyResult();

    try {//  www .j a  v  a2s  .c om
        Set<String> favorites = mFavorites.getFavorites();
        Calendar calendar = Wotd.getTodayUTC();
        Calendar calendarDisplay = Wotd.getTodayUTC();
        calendarDisplay.setTimeZone(TimeZone.getDefault());
        Settings.Layout layout = Settings.getLayout(mPrefs);
        for (int i = 0; i < 100; i++) {
            Random random = new Random();
            random.setSeed(calendar.getTimeInMillis());
            String date = DateUtils.formatDateTime(getContext(), calendarDisplay.getTimeInMillis(),
                    DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL);
            int position = random.nextInt(cursor.getCount());
            if (cursor.moveToPosition(position)) {
                String word = cursor.getString(0);
                @ColorRes
                int color = (i % 2 == 0) ? R.color.row_background_color_even : R.color.row_background_color_odd;
                data.add(new WotdEntry(word, date, ContextCompat.getColor(getContext(), color),
                        favorites.contains(word), layout == Settings.Layout.EFFICIENT));
            }
            calendar.add(Calendar.DAY_OF_YEAR, -1);
            calendarDisplay.add(Calendar.DAY_OF_YEAR, -1);

        }

    } finally {
        cursor.close();
    }
    return new ResultListData<>(getContext().getString(R.string.wotd_list_header), false, data);
}

From source file:org.dronix.android.unisannio.fragment.AvvisiIngFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.tabone, container, false);

    TextView title = (TextView) view.findViewById(R.id.title);
    title.setText(getString(R.string.avvisi_ingengeria));

    mPullRefreshListView = (PullToRefreshListView) view.findViewById(R.id.pull_refresh_list);

    // Set a listener to be invoked when the list should be refreshed.
    mPullRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
        @Override/*from  w w  w .  ja  v  a  2  s  .c  om*/
        public void onRefresh(PullToRefreshBase<ListView> refreshView) {
            mPullRefreshListView.setLastUpdatedLabel(DateUtils.formatDateTime(getActivity(),
                    System.currentTimeMillis(),
                    DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL));

            new NewsRetriever().execute();
        }
    });

    ListView actualListView = mPullRefreshListView.getRefreshableView();

    news = new ArrayList<NewsIng>();
    news.add(new NewsIng(getString(R.string.pull), "", null, null, ""));

    mAdapter = new NewsIngAdapter(getActivity(), news);

    actualListView.setAdapter(mAdapter);

    actualListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Intent i = new Intent(getActivity(), NewsDetailActivity.class);
            i.putExtra("newsing", news.get(--position));
            startActivity(i);
        }
    });

    return view;
}