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: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.
 *//*from w  w  w.j ava  2 s  .c  o m*/
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

/**
 * Returns a date string in the format specified, which shows an abbreviated date without a
 * year./*from w ww.  j a v  a  2  s  .co m*/
 *
 * @param context      Used by DateUtils to format the date in the current locale
 * @param timeInMillis Time in milliseconds since the epoch (local time)
 *
 * @return The formatted date string
 */
private static String getReadableDateString(Context context, long timeInMillis) {
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_SHOW_WEEKDAY;

    return DateUtils.formatDateTime(context, timeInMillis, flags);
}

From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java

public static ArrayList<SocialItem> getTwitterItems(Context context, String tag, int maximum) {
    String twitterSearch = "http://search.twitter.com/search.json?q=" + tag;
    ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>();

    // TODO Android 2.2 thinks that "Wed, 19 Sep 2012 16:35:43 +0000" is invalid
    // with this formatter
    SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
    formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
    try {//w w w.  j av a 2  s  .c o  m
        Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.twitter_icon);
        JSONObject result = HTTPWrapper.get(twitterSearch);
        JSONArray items = result.getJSONArray("results");
        int len = items.length();
        if ((len > 0) && (maximum > 0) && (len > maximum))
            len = maximum;

        for (int i = 0; i < len; i++) {
            JSONObject jsonItem = items.getJSONObject(i);
            Bitmap image = HTTPWrapper.getImage(jsonItem.getString("profile_image_url"));
            Date formattedDate = new Date();
            try {
                formattedDate = formatter.parse(jsonItem.getString("created_at"));
            } catch (ParseException e) {
                Log.d("SUSEConferences", "Invalid date string: " + jsonItem.getString("created_at"));
                e.printStackTrace();
            }
            String user = jsonItem.getString("from_user");
            SocialItem newItem = new SocialItem(SocialItem.TWITTER, user, jsonItem.getString("text"),
                    formattedDate,
                    DateUtils
                            .formatDateTime(context, formattedDate.getTime(),
                                    DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE
                                            | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE),
                    image, icon);
            String link = "http://twitter.com/" + user + "/status/" + jsonItem.getString("id_str");
            newItem.setLink(link);
            socialItems.add(newItem);
        }
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SocketException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return socialItems;
}

From source file:com.afwsamples.testdpc.common.Util.java

/**
 * Format a friendly datetime for the current locale according to device policy documentation.
 * If the timestamp doesn't represent a real date, it will be interpreted as {@code null}.
 *
 * @return A {@link CharSequence} such as "12:35 PM today" or "June 15, 2033", or {@code null}
 * in the case that {@param timestampMs} equals zero.
 *//*from   www  . j ava  2  s. c o m*/
public static CharSequence formatTimestamp(long timestampMs) {
    if (timestampMs == 0) {
        // DevicePolicyManager documentation describes this timestamp as having no effect,
        // so show nothing for this case as the policy has not been set.
        return null;
    }

    return DateUtils.formatSameDayTime(timestampMs, System.currentTimeMillis(), DateUtils.FORMAT_SHOW_WEEKDAY,
            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);//from w ww  .  j  a v a  2 s.c  om
        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:edu.mit.mobile.android.locast.ver2.events.EventDetail.java

private void loadFromCursor(Cursor c) {
    if (c.moveToFirst()) {
        ((TextView) findViewById(R.id.title)).setText(c.getString(c.getColumnIndex(Event._TITLE)));
        ((TextView) findViewById(R.id.description)).setText(c.getString(c.getColumnIndex(Event._DESCRIPTION)));
        ((TextView) findViewById(R.id.author)).setText(c.getString(c.getColumnIndex(Event._AUTHOR)));
        final long start = c.getLong(c.getColumnIndex(Event._START_DATE)),
                end = c.getLong(c.getColumnIndex(Event._END_DATE));

        ((TextView) findViewById(R.id.author)).setText(DateUtils.formatDateRange(this, start, end,
                DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR
                        | DateUtils.FORMAT_SHOW_WEEKDAY));

        setPointerFromCursor(c);//from w  w  w .  jav a 2s  . com

        mEventOverlay.swapCursor(c);
    } else {
        Toast.makeText(this, R.string.error_loading_event, Toast.LENGTH_LONG).show();
        Log.e(TAG, "cursor has no content");
        finish();
    }
}

From source file:de.incoherent.suseconferenceclient.app.SocialWrapper.java

public static ArrayList<SocialItem> getGooglePlusItems(Context context, String tag, int maximum) {
    String twitterSearch = "https://www.googleapis.com/plus/v1/activities?orderBy=recent&query=" + tag + "&key="
            + Config.PLUS_KEY;//w  w  w. j a v  a 2  s .com
    Log.d("SUSEConferences", "Google search: " + twitterSearch);
    ArrayList<SocialItem> socialItems = new ArrayList<SocialItem>();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
    formatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.google_icon);

    try {
        JSONObject result = HTTPWrapper.get(twitterSearch);
        JSONArray items = result.getJSONArray("items");
        int len = items.length();
        if ((len > 0) && (maximum > 0) && (len > maximum))
            len = maximum;

        for (int i = 0; i < len; i++) {
            JSONObject jsonItem = items.getJSONObject(i);
            JSONObject actorItem = jsonItem.getJSONObject("actor");
            JSONObject imageItem = actorItem.getJSONObject("image");
            JSONObject objectItem = jsonItem.getJSONObject("object");
            Bitmap image = HTTPWrapper.getImage(imageItem.getString("url"));
            String content = Html.fromHtml(objectItem.getString("content")).toString();
            Date formattedDate = new Date();
            try {
                formattedDate = formatter.parse(jsonItem.getString("published"));
            } catch (ParseException e) {
                e.printStackTrace();
            }

            SocialItem newItem = new SocialItem(SocialItem.GOOGLE, actorItem.getString("displayName"), content,
                    formattedDate,
                    DateUtils
                            .formatDateTime(context, formattedDate.getTime(),
                                    DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_NUMERIC_DATE
                                            | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE),
                    image, icon);
            newItem.setLink(jsonItem.getString("url"));
            socialItems.add(newItem);
        }
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (SocketException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return socialItems;
}

From source file:edu.cens.loci.ui.VisitDetailActivity.java

private void updateData(Uri visitUri) {
    ContentResolver resolver = getContentResolver();
    Cursor visitCursor = resolver.query(visitUri, VISIT_LOG_PROJECTION, null, null, null);
    try {//from www  .  j a  v  a  2  s.c  om
        if (visitCursor != null && visitCursor.moveToFirst()) {
            long placeId = visitCursor.getLong(PLACE_ID_INDEX);
            long enter = visitCursor.getLong(ENTER_INDEX);
            long exit = visitCursor.getLong(EXIT_INDEX);
            int type = visitCursor.getInt(TYPE);
            String extra1 = visitCursor.getString(EXTRA1_INDEX);
            String extra2 = visitCursor.getString(EXTRA2_INDEX);

            MyLog.d(LociConfig.D.UI.DEBUG, TAG,
                    String.format("[updateData] placeId=%d enter=%s exit=%s type=%d extra1=%s extra2=%s",
                            placeId, MyDateUtils.getTimeFormatLong(enter), MyDateUtils.getTimeFormatLong(exit),
                            type, extra1, extra2));

            // Place name
            String place_name = "";
            int place_state = 0;

            if (placeId > 0) {
                String placeSelection = Places._ID + "=" + placeId;
                Uri placeUri = ContentUris.withAppendedId(Places.CONTENT_URI, placeId);
                Cursor placeCursor = resolver.query(placeUri, PLACE_PROJECTION, placeSelection, null, null);

                if (placeCursor != null && placeCursor.moveToFirst()) {
                    place_name = placeCursor.getString(PLACE_NAME_INDEX);
                    place_state = placeCursor.getInt(PLACE_STATE_INDEX);
                    placeCursor.close();
                } else {
                    place_name = "Unknown";
                }
            } else {
                place_name = "Unknown";
            }
            mPlaceName.setText(place_name);

            // Pull out string in format [relative], [date]
            CharSequence dateClause = DateUtils.formatDateRange(this, enter, enter, DateUtils.FORMAT_SHOW_TIME
                    | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY | DateUtils.FORMAT_SHOW_YEAR);

            mVisitTime.setText(dateClause);

            // Set the duration
            mVisitDuration.setText(formatDuration((exit - enter) / 1000));

            switch (type) {
            case Visits.TYPE_GPS:
                mPlaceTypeIcon.setImageResource(R.drawable.icon_satellite);
                break;
            case Visits.TYPE_WIFI:
                mPlaceTypeIcon.setImageResource(R.drawable.icon_wifi);
                break;
            }

            List<ViewEntry> actions = new ArrayList<ViewEntry>();

            // View place
            Intent viewPlaceIntent = new Intent(Intent.ACTION_VIEW,
                    ContentUris.withAppendedId(Places.CONTENT_URI, placeId));
            String placeViewLabel = "";

            MyLog.d(LociConfig.D.UI.DEBUG, TAG,
                    String.format("[updateData] placename=%s placestate=%d", place_name, place_state));

            switch (place_state) {
            case Places.STATE_SUGGESTED:
                placeViewLabel = "Handle Suggested Place";
                break;
            case Places.STATE_REGISTERED:
                placeViewLabel = "View " + place_name;
                break;
            default:
                placeViewLabel = null;//place_name + " state " + place_state;
            }

            if (placeViewLabel != null) {
                ViewEntry entry = new ViewEntry(LIST_ACTION_VIEW_PLACE, R.drawable.sym_action_map,
                        placeViewLabel, null, null);
                entry.intent = viewPlaceIntent;
                actions.add(entry);
            }

            // View Wifi APs
            if (type == Visits.TYPE_WIFI && extra1 != null) {

                LociWifiFingerprint wifi;
                String apsAbstract = "Not available";

                try {
                    wifi = new LociWifiFingerprint(extra1);
                    apsAbstract = wifi.getWifiInfoSubstring(5);
                    ViewEntry wifiEntry = new ViewEntry(LIST_ACTION_VIEW_WIFIS, R.drawable.ic_settings_wireless,
                            "View Wi-Fi APs", apsAbstract, null);
                    wifiEntry.extra_string = extra1;

                    actions.add(wifiEntry);
                } catch (JSONException e) {
                    MyLog.e(LociConfig.D.JSON, TAG, "wifi json failed : " + extra1);
                    e.printStackTrace();
                }
            }

            // Additional Actions
            if (placeId > 0) {
                if (place_state == Places.STATE_REGISTERED || place_state == Places.STATE_BLOCKED) {
                    if (type == Visits.TYPE_WIFI && extra1 != null) {
                        ViewEntry entry = new ViewEntry(LIST_ACTION_CHANGE_PLACE,
                                android.R.drawable.ic_menu_edit, "Change Place", null, null);
                        entry.intent = new Intent(Intents.UI.ACTION_INSERT);
                        entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY,
                                PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY);
                        entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1);
                        entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter));
                        entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY,
                                Places.ENTRY_WIFI_OVERWRITE_WRONG_RECOGNITION);
                        actions.add(entry);
                    }
                }
            } else {
                ViewEntry entry = new ViewEntry(LIST_ACTION_ADD_PLACE, R.drawable.sym_action_add, "Add Place",
                        null, null);
                entry.intent = new Intent(Intents.UI.ACTION_INSERT);
                entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_KEY,
                        PlacesList.LIST_ORDER_TYPE_WIFI_SIMILARITY);
                entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_KEY, extra1);
                entry.intent.putExtra(Intents.UI.LIST_ORDER_EXTRA_WIFI_TIME_KEY, String.valueOf(enter));
                entry.intent.putExtra(Intents.UI.PLACE_ENTRY_TYPE_EXTRA_KEY, Places.ENTRY_WIFI_USE_SHORT_VISIT);
                actions.add(entry);
            }

            // View Recognition Results
            //Log.d(TAG, "recog: " + extra2);
            if (extra2 != null && !TextUtils.isEmpty(extra2)) {
                ViewEntry recogEntry = new ViewEntry(LIST_ACTION_VIEW_RECOGNITION,
                        R.drawable.ic_clock_strip_desk_clock, "View Recogntion Results", "", null);
                recogEntry.extra_string = extra2;
                actions.add(recogEntry);
            }

            ViewAdapter adapter = new ViewAdapter(this, actions);
            setListAdapter(adapter);

            //Log.d(TAG, String.format("placeId=%d enter=%s exit=%s", placeId, MyDateUtils.getDateFormatLong(enter), MyDateUtils.getDateFormatLong(exit)));
            //Log.d(TAG, String.format("extra1=%s", extra1));
            //Log.d(TAG, String.format("extra2=%s", extra2));
        }

    } finally {
        if (visitCursor != null) {
            visitCursor.close();
        }
    }
}