Example usage for android.text.format DateFormat format

List of usage examples for android.text.format DateFormat format

Introduction

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

Prototype

public static CharSequence format(CharSequence inFormat, Calendar inDate) 

Source Link

Document

Given a format string and a java.util.Calendar object, returns a CharSequence containing the requested date.

Usage

From source file:de.ub0r.android.websms.connector.o2.ConnectorO2.java

/**
 * Send SMS./*w w  w . ja v a  2s. c o m*/
 * 
 * @param context
 *            {@link Context}
 * @param command
 *            {@link ConnectorCommand}
 * @param htmlText
 *            html source of previous site
 * @throws IOException
 *             IOException
 */
private void sendToO2(final Context context, final ConnectorCommand command, final String htmlText)
        throws IOException {
    ArrayList<BasicNameValuePair> postData = // .
            new ArrayList<BasicNameValuePair>();
    postData.add(new BasicNameValuePair("SMSTo", Utils.national2international(command.getDefPrefix(),
            Utils.getRecipientsNumber(command.getRecipients()[0]))));
    postData.add(new BasicNameValuePair("SMSText", CharacterTable.encodeString(command.getText())));
    String customSender = command.getCustomSender();
    if (customSender == null) {
        final String sn = Utils.getSenderNumber(context, command.getDefSender());
        final String s = Utils.getSender(context, command.getDefSender());
        if (s != null && !s.equals(sn)) {
            customSender = s;
        }
    }
    if (customSender != null) {
        postData.add(new BasicNameValuePair("SMSFrom", customSender));
        if (customSender.length() == 0) {
            postData.add(new BasicNameValuePair("FlagAnonymous", "1"));
        } else {
            postData.add(new BasicNameValuePair("FlagAnonymous", "0"));
            postData.add(new BasicNameValuePair("FlagDefSender", "1"));
        }
        postData.add(new BasicNameValuePair("FlagDefSender", "0"));
    } else {
        postData.add(new BasicNameValuePair("SMSFrom", ""));
        postData.add(new BasicNameValuePair("FlagDefSender", "1"));
    }
    postData.add(new BasicNameValuePair("Frequency", "5"));
    if (command.getFlashSMS()) {
        postData.add(new BasicNameValuePair("FlagFlash", "1"));
    } else {
        postData.add(new BasicNameValuePair("FlagFlash", "0"));
    }
    String url = URL_SEND;
    final long sendLater = command.getSendLater();
    if (sendLater > 0) {
        url = URL_SCHEDULE;
        final Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(sendLater);
        postData.add(new BasicNameValuePair("StartDateDay", getTwoDigitsFromCal(cal, Calendar.DAY_OF_MONTH)));
        postData.add(new BasicNameValuePair("StartDateMonth", getTwoDigitsFromCal(cal, Calendar.MONTH)));
        postData.add(new BasicNameValuePair("StartDateYear", getTwoDigitsFromCal(cal, Calendar.YEAR)));
        postData.add(new BasicNameValuePair("StartDateHour", getTwoDigitsFromCal(cal, Calendar.HOUR_OF_DAY)));
        postData.add(new BasicNameValuePair("StartDateMin", getTwoDigitsFromCal(cal, Calendar.MINUTE)));
        postData.add(new BasicNameValuePair("EndDateDay", getTwoDigitsFromCal(cal, Calendar.DAY_OF_MONTH)));
        postData.add(new BasicNameValuePair("EndDateMonth", getTwoDigitsFromCal(cal, Calendar.MONTH)));
        postData.add(new BasicNameValuePair("EndDateYear", getTwoDigitsFromCal(cal, Calendar.YEAR)));
        postData.add(new BasicNameValuePair("EndDateHour", getTwoDigitsFromCal(cal, Calendar.HOUR_OF_DAY)));
        postData.add(new BasicNameValuePair("EndDateMin", getTwoDigitsFromCal(cal, Calendar.MINUTE)));
        final String s = DateFormat.format(DATEFORMAT, cal).toString();
        postData.add(new BasicNameValuePair("RepeatStartDate", s));
        postData.add(new BasicNameValuePair("RepeatEndDate", s));
        postData.add(new BasicNameValuePair("RepeatType", "5"));
        postData.add(new BasicNameValuePair("RepeatEndType", "0"));
    }
    String[] st = htmlText.split("<input type=\"Hidden\" ");
    for (String s : st) {
        if (s.startsWith("name=")) {
            String[] subst = s.split("\"", 5);
            if (subst.length >= 4) {
                if (sendLater > 0 && subst[1].startsWith("Repeat")) {
                    continue;
                }
                postData.add(new BasicNameValuePair(subst[1], subst[3]));
            }
        }
    }
    st = null;

    HttpResponse response = Utils.getHttpClient(url, null, postData, TARGET_AGENT, URL_PRESEND, ENCODING,
            O2_SSL_FINGERPRINTS);
    postData = null;
    int resp = response.getStatusLine().getStatusCode();
    if (resp != HttpURLConnection.HTTP_OK) {
        throw new WebSMSException(context, R.string.error_http, "" + resp);
    }
    String check = CHECK_SENT;
    if (sendLater > 0) {
        check = CHECK_SCHED;
    }
    String htmlText1 = null;
    if (sendLater <= 0 && PreferenceManager.getDefaultSharedPreferences(context)
            .getBoolean(Preferences.PREFS_TWEAK, false)) {
        htmlText1 = Utils.stream2str(response.getEntity().getContent(), STRIP_SEND_START,
                Utils.ONLY_MATCHING_LINE, check);
    } else {
        htmlText1 = Utils.stream2str(response.getEntity().getContent(), 0, Utils.ONLY_MATCHING_LINE, check);
    }
    if (htmlText1 == null) {
        throw new WebSMSException("error parsing website");
    } else if (htmlText1.indexOf(check) < 0) {
        // check output html for success message
        Log.w(TAG, htmlText1);
        throw new WebSMSException("error parsing website");
    }
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java

/**
 * Updated toobar subtitle to the date/*from  w w w  .j av  a2s  . co  m*/
 *
 * @param date current date or updated date
 */
private void handleDateChanges(Date date) {
    if (DateCompare.areDatesEqual(new Date(), date)) { // Are Dates Equal Today
        txtDate.setText("Today");
    } else if (DateCompare.areDatesEqualYesterday(new Date(), date)) { // Are Dates Equal Yesterday
        txtDate.setText("Yesterday");
    } else if (DateCompare.areDatesEqualTomorrow(new Date(), date)) { // Are Dates Equal Yesterday
        txtDate.setText("Tomorrow");
    } else {
        txtDate.setText(DateFormat.format("MMM d, EE", date));
    }

}

From source file:com.cloverstudio.spika.MyProfileActivity.java

private void resetProfile() {
    mEtUserName.setText(mUserName);//ww w  .j  av  a  2 s.  c  o  m

    if (mUserGender != null && !"".equals(mUserGender)) {
        if (mUserGender.equals(Const.FEMALE)) {
            mSpinnerGender.setSelection(1);
        }
        if (mUserGender.equals(Const.MALE)) {
            mSpinnerGender.setSelection(0);
        }
    } else {
        mSpinnerGender.setSelection(2);
        mRlGender.setVisibility(View.GONE);
    }

    if (mUserOnlineStatus != null && !"".equals(mUserOnlineStatus)) {
        if (mUserOnlineStatus.equals(Const.ONLINE)) {
            mSpinnerStatus.setSelection(0);
        }
        if (mUserOnlineStatus.equals(Const.AWAY)) {
            mSpinnerStatus.setSelection(1);
        }
        if (mUserOnlineStatus.equals(Const.BUSY)) {
            mSpinnerStatus.setSelection(2);
        }
        if (mUserOnlineStatus.equals(Const.OFFLINE)) {
            mSpinnerStatus.setSelection(3);
        }
    } else {
        mSpinnerStatus.setSelection(3);
    }

    if (mUserAbout != null && !"".equals(mUserAbout)) {
        mEtUserAbout.setText(mUserAbout);
    } else {
        mEtUserAbout.setText(null);
        mRlAbout.setVisibility(View.GONE);
    }

    if (mUserBirthday == NO_BIRTHDAY) {
        mEtUserBirthday.setText(null);
        mRlBirthday.setVisibility(View.GONE);
    } else {
        String birthdayString = DateFormat.format(getString(R.string.hookup_date_format), mUserBirthday * 1000)
                .toString();
        mEtUserBirthday.setText(birthdayString);
    }

    mEtUserEmail.setText(mUserEmail);

    mUserAvatarId = UsersManagement.getLoginUser().getAvatarFileId();
    mUserAvatarThumbId = UsersManagement.getLoginUser().getAvatarThumbFileId();
    Utils.displayImage(mUserAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE,
            R.drawable.user_stub_large, false);
}

From source file:org.andstatus.app.util.MyLog.java

public static String uniqueDateTimeFormatted() {
    long time = uniqueCurrentTimeMS();
    String strTime = DateFormat.format("yyyy-MM-dd-HH-mm-ss", new Date(time)).toString();
    if (strTime.contains("HH")) {
        // see http://stackoverflow.com/questions/16763968/android-text-format-dateformat-hh-is-not-recognized-like-with-java-text-simple
        strTime = DateFormat.format("yyyy-MM-dd-kk-mm-ss", new Date(time)).toString();
    }/*  w  ww . jav a 2 s  .  co  m*/
    return strTime + Long.toString(time);
}

From source file:com.smarthome.deskclock.Alarms.java

static String formatTime(final Context context, Calendar c) {
    String format = get24HourMode(context) ? M24 : M12;
    return (c == null) ? "" : (String) DateFormat.format(format, c);
}

From source file:com.smarthome.deskclock.Alarms.java

/**
 * Shows day and time -- used for lock screen
 *//*ww  w  .j av a 2s.  c  om*/
private static String formatDayAndTime(final Context context, Calendar c) {
    String format = get24HourMode(context) ? DM24 : DM12;
    return (c == null) ? "" : (String) DateFormat.format(format, c);
}

From source file:me.myatminsoe.myansms.MessageListActivity.java

/**
 * {@inheritDoc}/*  www .j  a  v  a 2 s. c om*/
 */
public final boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position,
        final long id) {
    final Context context = this;
    final Message m = Message.getMessage(this, (Cursor) parent.getItemAtPosition(position));
    final Uri target = m.getUri();
    final int read = m.getRead();
    final int type = m.getType();
    Builder builder = new Builder(context);
    builder.setTitle(R.string.message_options_);

    final Contact contact = conv.getContact();
    final String a = contact.getNumber();
    final String n = contact.getName();

    String[] items = longItemClickDialog;
    if (TextUtils.isEmpty(n)) {
        items[WHICH_VIEW_CONTACT] = getString(R.string.add_contact_);
    } else {
        items[WHICH_VIEW_CONTACT] = getString(R.string.view_contact_);
    }
    items[WHICH_CALL] = getString(R.string.call) + " " + contact.getDisplayName();
    if (read == 0) {
        items = items.clone();
        items[WHICH_MARK_UNREAD] = context.getString(R.string.mark_read_);
    }
    if (type == Message.SMS_DRAFT) {
        items = items.clone();
        items[WHICH_FORWARD] = context.getString(R.string.send_draft_);
    }
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @SuppressWarnings("deprecation")
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            Intent i;
            switch (which) {
            case WHICH_VIEW_CONTACT:
                if (n == null) {
                    i = ContactsWrapper.getInstance().getInsertPickIntent(a);
                    Conversation.flushCache();
                } else {
                    final Uri u = MessageListActivity.this.conv.getContact().getUri();
                    i = new Intent(Intent.ACTION_VIEW, u);
                }
                try {
                    MessageListActivity.this.startActivity(i);
                } catch (ActivityNotFoundException e) {
                    Toast.makeText(MessageListActivity.this, R.string.error_unknown, Toast.LENGTH_LONG).show();
                }
                break;
            case WHICH_CALL:
                MessageListActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tel:" + a)));
                break;
            case WHICH_MARK_UNREAD:
                ConversationListActivity.markRead(context, target, 1 - read);
                MessageListActivity.this.markedUnread = true;
                break;
            case WHICH_REPLY:
                MessageListActivity.this.startActivity(
                        ConversationListActivity.getComposeIntent(MessageListActivity.this, a, false));
                break;
            case WHICH_FORWARD:
                int resId;
                if (type == Message.SMS_DRAFT) {
                    resId = R.string.send_draft_;
                    i = ConversationListActivity.getComposeIntent(MessageListActivity.this,
                            MessageListActivity.this.conv.getContact().getNumber(), false);
                } else {
                    resId = R.string.forward_;
                    i = new Intent(Intent.ACTION_SEND);
                    i.setType("text/plain");
                    i.putExtra("forwarded_message", true);
                }
                CharSequence text;
                if (PreferencesActivity.decodeDecimalNCR(context)) {
                    text = Converter.convertDecNCR2Char(m.getBody());
                } else {
                    text = m.getBody();
                }
                i.putExtra(Intent.EXTRA_TEXT, text);
                i.putExtra("sms_body", text);
                context.startActivity(Intent.createChooser(i, context.getString(resId)));
                break;
            case WHICH_COPY_TEXT:
                final ClipboardManager cm = (ClipboardManager) context
                        .getSystemService(Context.CLIPBOARD_SERVICE);
                if (PreferencesActivity.decodeDecimalNCR(context)) {
                    cm.setText(Converter.convertDecNCR2Char(m.getBody()));
                } else {
                    cm.setText(m.getBody());
                }
                break;
            case WHICH_VIEW_DETAILS:
                final int t = m.getType();
                Builder b = new Builder(context);
                b.setTitle(R.string.view_details_);
                b.setCancelable(true);
                StringBuilder sb = new StringBuilder();
                final String a = m.getAddress(context);
                final long d = m.getDate();
                final String ds = DateFormat.format(context.getString(R.string.DATEFORMAT_details), d)
                        .toString();
                String sentReceived;
                String fromTo;
                if (t == Calls.INCOMING_TYPE) {
                    sentReceived = context.getString(R.string.received_);
                    fromTo = context.getString(R.string.from_);
                } else if (t == Calls.OUTGOING_TYPE) {
                    sentReceived = context.getString(R.string.sent_);
                    fromTo = context.getString(R.string.to_);
                } else {
                    sentReceived = "ukwn:";
                    fromTo = "ukwn:";
                }
                sb.append(sentReceived).append(" ");
                sb.append(ds);
                sb.append("\n");
                sb.append(fromTo).append(" ");
                sb.append(a);
                sb.append("\n");
                sb.append(context.getString(R.string.type_));
                if (m.isMMS()) {
                    sb.append(" MMS");
                } else {
                    sb.append(" SMS");
                }
                b.setMessage(sb.toString());
                b.setPositiveButton(android.R.string.ok, null);
                b.show();
                break;
            case WHICH_DELETE:
                ConversationListActivity.deleteMessages(context, target, R.string.delete_message_,
                        R.string.delete_message_question, null);
                break;
            default:
                break;
            }
        }
    });
    builder.show();
    return true;
}

From source file:net.phase.wallet.Currency.java

private String getTimeStampString(Date d) {
    String result = DateFormat.getDateFormat(context).format(d);

    result += " " + DateFormat.format("h:mmaa", d).toString();

    return result;
}

From source file:com.pukulab.puku0x.gscalendar.CalendarActivity.java

@Override
public void onDayClick(final long dayInMillis) {
    // Reset the previously selected TextView to his previous Typeface
    if (mSelectedTextView != null) {
        mSelectedTextView.setTypeface(mSelectedTypeface);
        mSelectedTextView.setBackgroundColor(getResources().getColor(android.R.color.background_light));
    }/*from   w w  w  .  ja  va2  s .  c  o m*/

    final TextView day = mCalendarView.getTextViewForDate(dayInMillis);
    if (day != null) {
        // Remember the selected TextView and it's font
        mSelectedTypeface = day.getTypeface();
        mSelectedTextView = day;

        // Show the selected TextView as bold
        day.setTypeface(Typeface.DEFAULT_BOLD);
        day.setBackgroundColor(getResources().getColor(R.color.theme_color_transparent));
    }

    // ?
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(dayInMillis);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    mDisplayedDate = calendar.getTime();

    // 
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        //actionBar.setDisplayHomeAsUpEnabled(true);
        //actionBar.setTitle(mDisplayedUser.name);
        actionBar.setSubtitle(DateFormat.format(getString(R.string.date_year_month_day), mDisplayedDate));
    }

    // ?
    mDailyScheduleList.clear();

    for (ScheduleData d : mScheduleDataList) {
        if (d.date.equals(mDisplayedDate)) {
            // 
            //TextView tv_date = (TextView) findViewById(R.id.tv_schedule_date);
            //tv_date.setText(DateFormat.format(getString(R.string.date_month_day_week), d.date));
            // ????
            if (!d.scheduleList.isEmpty()) {
                mDailyScheduleList.addAll(d.scheduleList);
            }
        }
    }
    mDailyScheduleaListAdapter.notifyDataSetChanged();
}

From source file:com.chuxin.family.widgets.CxImagePager.java

private static String createName(long dateTaken) {
    return DateFormat.format("yyyy-MM-dd_kk.mm.ss", dateTaken).toString();
}