List of usage examples for android.text.format DateUtils isToday
public static boolean isToday(long when)
From source file:Main.java
public static String prettifyDate(long timestamp) { SimpleDateFormat dateFormat;/*from w w w. ja v a 2s .co m*/ if (DateUtils.isToday(timestamp)) { dateFormat = new SimpleDateFormat("hh:mm a", Locale.getDefault()); } else { dateFormat = new SimpleDateFormat("dd MMM hh:mm a", Locale.getDefault()); } return dateFormat.format(timestamp); }
From source file:Main.java
public static boolean isToday(long date) { return DateUtils.isToday(date); }
From source file:Main.java
public static String getDateFromName(String fName) { if (fName == null) return fName; String name = extractDateFromFName(fName); // output as time or date CharSequence df;// w w w . j ava 2s. c o m long millis = Long.parseLong(name); if (DateUtils.isToday(millis)) { df = "'today' hh:mmaa"; } else { df = "dd MMM hh:mmaa"; } return (String) DateFormat.format(df, millis); }
From source file:Main.java
/** * Get formatted time.// w ww.j a v a2 s . c o 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:ca.mudar.snoozy.ui.widget.HistoryCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { super.bindView(view, context, cursor); /*// ww w . j a va 2 s . c o m Get current cursor values */ final boolean isPowerOn = (1 == cursor.getInt(HistoryQuery.IS_POWER_ON)); final long timestamp = cursor.getLong(HistoryQuery.TIME_STAMP); final boolean isFirst = (1 == cursor.getInt(HistoryQuery.IS_FIRST)); final boolean isLast = (1 == cursor.getInt(HistoryQuery.IS_LAST)); final int batteryLevel = cursor.getInt(HistoryQuery.BATTERY_LEVEL); /* Prepare the data */ final String sPowerStatus = mResources.getString( isPowerOn ? R.string.history_item_power_connected : R.string.history_item_power_disconnected); final String sBatteryLevel = String.format(mResources.getString(R.string.history_item_battery_level), batteryLevel); final int resPowerStatusColor = mResources .getColor(isPowerOn ? R.color.card_row_highlight_color : R.color.card_row_color); String sTimestamp; String sDay; if (DateUtils.isToday(timestamp)) { sDay = mResources.getString(R.string.history_item_day_today); sTimestamp = (String) DateUtils.formatSameDayTime(timestamp, mMillis, 0, DateFormat.SHORT); // sTimestamp = (String) DateUtils.getRelativeTimeSpanString(timestamp,now, 0, 0); } else { sDay = (String) DateUtils.getRelativeTimeSpanString(timestamp, mMillis, DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); // sDay = sDay.substring(0,1).toUpperCase() + sDay.substring(1); sTimestamp = mTimeFormat.format(new Date(timestamp)); } sDay = sDay.substring(0, 1).toUpperCase() + sDay.substring(1); /* Set UI values */ ((TextView) view.findViewById(R.id.history_is_power_on)).setText(sPowerStatus); ((TextView) view.findViewById(R.id.history_is_power_on)).setTextColor(resPowerStatusColor); ((TextView) view.findViewById(R.id.history_timestamp)).setText(sTimestamp); ((TextView) view.findViewById(R.id.history_battery_level)).setText(sBatteryLevel); if (isFirst && isLast) { ((TextView) view.findViewById(R.id.history_day)).setText(sDay); view.findViewById(R.id.history_header).setVisibility(View.VISIBLE); view.setBackgroundResource(R.drawable.bg_cards_top_bottom); } else if (isLast) { ((TextView) view.findViewById(R.id.history_day)).setText(sDay); view.findViewById(R.id.history_header).setVisibility(View.VISIBLE); view.setBackgroundResource(R.drawable.bg_cards_top); } else if (isFirst) { view.findViewById(R.id.history_header).setVisibility(View.GONE); view.setBackgroundResource(R.drawable.bg_cards_bottom); } else { view.findViewById(R.id.history_header).setVisibility(View.GONE); view.setBackgroundResource(R.drawable.bg_cards_middle); } }
From source file:de.schildbach.wallet.ui.TransactionFragment.java
public void update(final Transaction tx) { final Wallet wallet = ((WalletApplication) activity.getApplication()).getWallet(); final byte[] serializedTx = tx.unsafeBitcoinSerialize(); Address from = null;//ww w. j a va 2 s.c om boolean fromMine = false; try { from = tx.getInputs().get(0).getFromAddress(); fromMine = wallet.isPubKeyHashMine(from.getHash160()); } catch (final ScriptException x) { x.printStackTrace(); } Address to = null; boolean toMine = false; try { to = tx.getOutputs().get(0).getScriptPubKey().getToAddress(); toMine = wallet.isPubKeyHashMine(to.getHash160()); } catch (final ScriptException x) { x.printStackTrace(); } final ContentResolver contentResolver = activity.getContentResolver(); final View view = getView(); final Date time = tx.getUpdateTime(); view.findViewById(R.id.transaction_fragment_time_row) .setVisibility(time != null ? View.VISIBLE : View.GONE); if (time != null) { final TextView viewDate = (TextView) view.findViewById(R.id.transaction_fragment_time); viewDate.setText( (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time)); } try { final BigInteger amountSent = tx.getValueSentFromMe(wallet); view.findViewById(R.id.transaction_fragment_amount_sent_row) .setVisibility(amountSent.signum() != 0 ? View.VISIBLE : View.GONE); if (amountSent.signum() != 0) { final TextView viewAmountSent = (TextView) view.findViewById(R.id.transaction_fragment_amount_sent); viewAmountSent.setText(Constants.CURRENCY_MINUS_SIGN + WalletUtils.formatValue(amountSent)); } } catch (final ScriptException x) { x.printStackTrace(); } final BigInteger amountReceived = tx.getValueSentToMe(wallet); view.findViewById(R.id.transaction_fragment_amount_received_row) .setVisibility(amountReceived.signum() != 0 ? View.VISIBLE : View.GONE); if (amountReceived.signum() != 0) { final TextView viewAmountReceived = (TextView) view .findViewById(R.id.transaction_fragment_amount_received); viewAmountReceived.setText(Constants.CURRENCY_PLUS_SIGN + WalletUtils.formatValue(amountReceived)); } final View viewFromButton = view.findViewById(R.id.transaction_fragment_from_button); final TextView viewFromLabel = (TextView) view.findViewById(R.id.transaction_fragment_from_label); if (from != null) { final String label = AddressBookProvider.resolveLabel(contentResolver, from.toString()); final StringBuilder builder = new StringBuilder(); if (fromMine) builder.append(getString(R.string.transaction_fragment_you)).append(", "); if (label != null) { builder.append(label); } else { builder.append(from.toString()); viewFromLabel.setTypeface(Typeface.MONOSPACE); } viewFromLabel.setText(builder.toString()); final String addressStr = from.toString(); viewFromButton.setOnClickListener(new OnClickListener() { public void onClick(final View v) { EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr); } }); } else { viewFromLabel.setText(null); } final View viewToButton = view.findViewById(R.id.transaction_fragment_to_button); final TextView viewToLabel = (TextView) view.findViewById(R.id.transaction_fragment_to_label); if (to != null) { final String label = AddressBookProvider.resolveLabel(contentResolver, to.toString()); final StringBuilder builder = new StringBuilder(); if (toMine) builder.append(getString(R.string.transaction_fragment_you)).append(", "); if (label != null) { builder.append(label); } else { builder.append(to.toString()); viewToLabel.setTypeface(Typeface.MONOSPACE); } viewToLabel.setText(builder.toString()); final String addressStr = to.toString(); viewToButton.setOnClickListener(new OnClickListener() { public void onClick(final View v) { EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr); } }); } else { viewToLabel.setText(null); } final TextView viewStatus = (TextView) view.findViewById(R.id.transaction_fragment_status); final ConfidenceType confidenceType = tx.getConfidence().getConfidenceType(); if (confidenceType == ConfidenceType.DEAD || confidenceType == ConfidenceType.NOT_IN_BEST_CHAIN) viewStatus.setText(R.string.transaction_fragment_status_dead); else if (confidenceType == ConfidenceType.NOT_SEEN_IN_CHAIN) viewStatus.setText(R.string.transaction_fragment_status_pending); else if (confidenceType == ConfidenceType.BUILDING) viewStatus.setText(R.string.transaction_fragment_status_confirmed); else viewStatus.setText(R.string.transaction_fragment_status_unknown); final TextView viewHash = (TextView) view.findViewById(R.id.transaction_fragment_hash); viewHash.setText(tx.getHash().toString()); final TextView viewLength = (TextView) view.findViewById(R.id.transaction_fragment_length); viewLength.setText(Integer.toString(serializedTx.length)); final ImageView viewQr = (ImageView) view.findViewById(R.id.transaction_fragment_qr); try { // encode transaction URI final ByteArrayOutputStream bos = new ByteArrayOutputStream(serializedTx.length); final GZIPOutputStream gos = new GZIPOutputStream(bos); gos.write(serializedTx); gos.close(); final byte[] gzippedSerializedTx = bos.toByteArray(); final boolean useCompressioon = gzippedSerializedTx.length < serializedTx.length; final StringBuilder txStr = new StringBuilder("btctx:"); txStr.append(useCompressioon ? 'Z' : '-'); txStr.append(Base43.encode(useCompressioon ? gzippedSerializedTx : serializedTx)); final Bitmap qrCodeBitmap = WalletUtils.getQRCodeBitmap(txStr.toString().toUpperCase(Locale.US), 512); viewQr.setImageBitmap(qrCodeBitmap); viewQr.setOnClickListener(new OnClickListener() { public void onClick(final View v) { BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); } catch (final IOException x) { throw new RuntimeException(x); } }
From source file:piuk.blockchain.android.ui.TransactionFragment.java
public void update(final MyTransaction tx) { final MyRemoteWallet wallet = ((WalletApplication) activity.getApplication()).getRemoteWallet(); final byte[] serializedTx = tx.unsafeBitcoinSerialize(); Address from = null;/*w w w . j av a 2 s .c om*/ boolean fromMine = false; try { from = tx.getInputs().get(0).getFromAddress(); fromMine = wallet.isMine(from.toString()); } catch (final ScriptException x) { x.printStackTrace(); } Address to = null; boolean toMine = false; try { to = tx.getOutputs().get(0).getScriptPubKey().getToAddress(); toMine = wallet.isMine(to.toString()); } catch (final ScriptException x) { x.printStackTrace(); } final ContentResolver contentResolver = activity.getContentResolver(); final View view = getView(); final Date time = tx.getUpdateTime(); view.findViewById(R.id.transaction_fragment_time_row) .setVisibility(time != null ? View.VISIBLE : View.GONE); if (time != null) { final TextView viewDate = (TextView) view.findViewById(R.id.transaction_fragment_time); viewDate.setText( (DateUtils.isToday(time.getTime()) ? getString(R.string.transaction_fragment_time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time)); } final BigInteger amountSent = tx.getResult(); view.findViewById(R.id.transaction_fragment_amount_sent_row) .setVisibility(amountSent.signum() != 0 ? View.VISIBLE : View.GONE); if (amountSent.signum() != 0) { final TextView viewAmountSent = (TextView) view.findViewById(R.id.transaction_fragment_amount_sent); viewAmountSent.setText(Constants.CURRENCY_MINUS_SIGN + WalletUtils.formatValue(amountSent)); } final BigInteger amountReceived = tx.getResult(); view.findViewById(R.id.transaction_fragment_amount_received_row) .setVisibility(amountReceived.signum() != 0 ? View.VISIBLE : View.GONE); if (amountReceived.signum() != 0) { final TextView viewAmountReceived = (TextView) view .findViewById(R.id.transaction_fragment_amount_received); viewAmountReceived.setText(Constants.CURRENCY_PLUS_SIGN + WalletUtils.formatValue(amountReceived)); } final View viewFromButton = view.findViewById(R.id.transaction_fragment_from_button); final TextView viewFromLabel = (TextView) view.findViewById(R.id.transaction_fragment_from_label); if (from != null) { String label = null; if (tx instanceof MyTransaction && ((MyTransaction) tx).getTag() != null) label = ((MyTransaction) tx).getTag(); else label = AddressBookProvider.resolveLabel(contentResolver, from.toString()); final StringBuilder builder = new StringBuilder(); if (fromMine) builder.append(getString(R.string.transaction_fragment_you)).append(", "); if (label != null) { builder.append(label); } else { builder.append(from.toString()); viewFromLabel.setTypeface(Typeface.MONOSPACE); } viewFromLabel.setText(builder.toString()); final String addressStr = from.toString(); viewFromButton.setOnClickListener(new OnClickListener() { public void onClick(final View v) { EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr); } }); } else { viewFromLabel.setText(null); } final View viewToButton = view.findViewById(R.id.transaction_fragment_to_button); final TextView viewToLabel = (TextView) view.findViewById(R.id.transaction_fragment_to_label); if (to != null) { String label = null; if (tx instanceof MyTransaction && ((MyTransaction) tx).getTag() != null) label = ((MyTransaction) tx).getTag(); else label = AddressBookProvider.resolveLabel(contentResolver, from.toString()); final StringBuilder builder = new StringBuilder(); if (toMine) builder.append(getString(R.string.transaction_fragment_you)).append(", "); if (label != null) { builder.append(label); } else { builder.append(to.toString()); viewToLabel.setTypeface(Typeface.MONOSPACE); } viewToLabel.setText(builder.toString()); final String addressStr = to.toString(); viewToButton.setOnClickListener(new OnClickListener() { public void onClick(final View v) { EditAddressBookEntryFragment.edit(getFragmentManager(), addressStr); } }); } else { viewToLabel.setText(null); } final TextView viewStatus = (TextView) view.findViewById(R.id.transaction_fragment_status); final ConfidenceType confidenceType = tx.getConfidence().getConfidenceType(); if (confidenceType == ConfidenceType.DEAD || confidenceType == ConfidenceType.NOT_IN_BEST_CHAIN) viewStatus.setText(R.string.transaction_fragment_status_dead); else if (confidenceType == ConfidenceType.NOT_SEEN_IN_CHAIN) viewStatus.setText(R.string.transaction_fragment_status_pending); else if (confidenceType == ConfidenceType.BUILDING) viewStatus.setText(R.string.transaction_fragment_status_confirmed); else viewStatus.setText(R.string.transaction_fragment_status_unknown); final TextView viewHash = (TextView) view.findViewById(R.id.transaction_fragment_hash); viewHash.setText(tx.getHash().toString()); final TextView viewLength = (TextView) view.findViewById(R.id.transaction_fragment_length); viewLength.setText(Integer.toString(serializedTx.length)); final ImageView viewQr = (ImageView) view.findViewById(R.id.transaction_fragment_qr); try { // encode transaction URI final ByteArrayOutputStream bos = new ByteArrayOutputStream(serializedTx.length); final GZIPOutputStream gos = new GZIPOutputStream(bos); gos.write(serializedTx); gos.close(); final byte[] gzippedSerializedTx = bos.toByteArray(); final boolean useCompressioon = gzippedSerializedTx.length < serializedTx.length; final StringBuilder txStr = new StringBuilder("btctx:"); txStr.append(useCompressioon ? 'Z' : '-'); txStr.append(Base43.encode(useCompressioon ? gzippedSerializedTx : serializedTx)); final Bitmap qrCodeBitmap = WalletUtils.getQRCodeBitmap(txStr.toString().toUpperCase(), 512); viewQr.setImageBitmap(qrCodeBitmap); viewQr.setOnClickListener(new OnClickListener() { public void onClick(final View v) { new QrDialog(activity, qrCodeBitmap).show(); } }); } catch (final IOException x) { throw new RuntimeException(x); } }
From source file:org.francho.apps.zgzpolen.service.PollenService.java
/** * is the database udpdated?//from ww w.ja v a 2s . co m * * @return */ private boolean isUpdated() { Cursor c = getContentResolver().query(Pollen.getPollenUri(), null, null, null, null); try { if (c.getCount() < 1) { return false; } } finally { c.close(); } final SharedPreferences prefs = getSharedPreferences(POLLEN_SERVICE_PREFS, Context.MODE_PRIVATE); long lastTimeStamp = prefs.getLong(PREF_POLLEN_DATE, 0); Log.d(TAG, "" + System.currentTimeMillis() + " " + lastTimeStamp + ":" + (System.currentTimeMillis() - lastTimeStamp)); return DateUtils.isToday(lastTimeStamp); }
From source file:at.ac.uniklu.mobile.sportal.util.Utils.java
public static boolean isToday(Date date) { return DateUtils.isToday(date.getTime()); }
From source file:at.ac.uniklu.mobile.sportal.util.Utils.java
public static boolean isTomorrow(Date date) { return DateUtils.isToday(date.getTime() - MILLIS_PER_DAY); }