Example usage for android.text.format DateUtils MINUTE_IN_MILLIS

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

Introduction

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

Prototype

long MINUTE_IN_MILLIS

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

Click Source Link

Usage

From source file:org.tigase.mobile.muc.MucAdapter.java

@Override
public void bindView(View view, Context context, Cursor cursor) {
    ViewHolder holder = (ViewHolder) view.getTag();
    if (holder == null) {
        holder = new ViewHolder();
        view.setTag(holder);// w  ww .  j  a  va  2 s  .c o  m
        holder.nickname = (TextView) view.findViewById(R.id.chat_item_nickname);
        holder.body = (TextView) view.findViewById(R.id.chat_item_body);
        holder.bodySelf = (TextView) view.findViewById(R.id.chat_item_body_self);
        holder.timestamp = (TextView) view.findViewById(R.id.chat_item_timestamp);
        holder.avatar = (ImageView) view.findViewById(R.id.user_avatar);
    }

    holder.nickname.setOnClickListener(nickameClickListener);

    final int state = cursor.getInt(cursor.getColumnIndex(ChatTableMetaData.FIELD_STATE));

    // byte[] avatarData =
    // cursor.getBlob(cursor.getColumnIndex(VCardsCacheTableMetaData.FIELD_DATA));
    holder.avatar.setVisibility(View.GONE);

    // final BareJID account =
    // BareJID.bareJIDInstance(cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_ACCOUNT)));
    final String nick = cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_AUTHOR_NICKNAME));

    // JaxmppCore jaxmpp = ((MessengerApplication)
    // context.getApplicationContext()).getMultiJaxmpp().get(account);
    holder.nickname.setText(nick);

    final String bd = cursor.getString(cursor.getColumnIndex(ChatTableMetaData.FIELD_BODY));

    if (nick != null && nick.equals(room.getNickname())) {
        holder.nickname.setTextColor(context.getResources().getColor(R.color.mucmessage_mine_nickname));
        holder.body.setTextColor(context.getResources().getColor(R.color.mucmessage_mine_text));
        holder.bodySelf.setTextColor(context.getResources().getColor(R.color.mucmessage_mine_text));
        holder.timestamp.setTextColor(context.getResources().getColor(R.color.mucmessage_mine_text));
        view.setBackgroundColor(context.getResources().getColor(R.color.mucmessage_mine_background));
    } else {
        int colorRes = getOccupantColor(nick);

        if (bd.contains(room.getNickname())) {
            view.setBackgroundColor(context.getResources().getColor(R.color.mucmessage_his_background_marked));
        } else {
            view.setBackgroundColor(context.getResources().getColor(R.color.mucmessage_his_background));
        }

        holder.nickname.setTextColor(context.getResources().getColor(colorRes));
        holder.body.setTextColor(context.getResources().getColor(R.color.mucmessage_his_text));
        holder.bodySelf.setTextColor(context.getResources().getColor(colorRes));
        holder.timestamp.setTextColor(context.getResources().getColor(R.color.mucmessage_his_text));
    }

    // java.text.DateFormat df = DateFormat.getTimeFormat(context);

    if (bd != null && bd.startsWith("/me ")) {
        holder.body.setVisibility(View.GONE);
        holder.bodySelf.setVisibility(View.VISIBLE);
        String t = bd.substring(4);
        final String txt = EscapeUtils.escape(t);
        holder.bodySelf.setText(Html.fromHtml(
                txt.replace("\n", "<br/>").replace(room.getNickname(), "<b>" + room.getNickname() + "</b>")));

    } else {
        holder.body.setVisibility(View.VISIBLE);
        holder.bodySelf.setVisibility(View.GONE);
        final String txt = EscapeUtils.escape(bd);
        holder.body.setText(Html.fromHtml(
                txt.replace("\n", "<br/>").replace(room.getNickname(), "<b>" + room.getNickname() + "</b>")));
    }

    // webview.setMinimumHeight(webview.getMeasuredHeight());

    // Date t = new
    // Date(cursor.getLong(cursor.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP)));
    // holder.timestamp.setText(df.format(t));
    long ts = cursor.getLong(cursor.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP));
    CharSequence tsStr =
            // DateUtils.isToday(ts)
            // ? DateUtils.getRelativeTimeSpanString(ts, System.currentTimeMillis(),
            // DateUtils.MINUTE_IN_MILLIS) :
            DateUtils.getRelativeDateTimeString(mContext, ts, DateUtils.MINUTE_IN_MILLIS,
                    DateUtils.WEEK_IN_MILLIS, 0);
    holder.timestamp.setText(tsStr);

}

From source file:de.schildbach.wallet.ui.AlertDialogsFragment.java

private boolean handleServerTime(final long serverTime) {
    if (serverTime > 0) {
        final long diffMinutes = Math
                .abs((System.currentTimeMillis() - serverTime) / DateUtils.MINUTE_IN_MILLIS);

        if (diffMinutes >= 60) {
            log.info("according to \"" + versionUrl + "\", system clock is off by " + diffMinutes + " minutes");
            handler.post(new Runnable() {
                @Override/*  w w  w. j a  v  a  2  s .c  o m*/
                public void run() {
                    if (isAdded())
                        createTimeskewAlertDialog(diffMinutes).show();
                }
            });
            return true;
        }
    }
    return false;
}

From source file:com.battlelancer.seriesguide.ui.StatsFragment.java

private String getTimeDuration(long duration) {
    long days = duration / DateUtils.DAY_IN_MILLIS;
    duration %= DateUtils.DAY_IN_MILLIS;
    long hours = duration / DateUtils.HOUR_IN_MILLIS;
    duration %= DateUtils.HOUR_IN_MILLIS;
    long minutes = duration / DateUtils.MINUTE_IN_MILLIS;

    StringBuilder result = new StringBuilder();
    if (days != 0) {
        result.append(getResources().getQuantityString(R.plurals.days_plural, (int) days, (int) days));
    }/*from   w  w w. j a  v  a2  s.c om*/
    if (hours != 0) {
        if (days != 0) {
            result.append(" ");
        }
        result.append(getResources().getQuantityString(R.plurals.hours_plural, (int) hours, (int) hours));
    }
    if (minutes != 0 || (days == 0 && hours == 0)) {
        if (days != 0 || hours != 0) {
            result.append(" ");
        }
        result.append(getResources().getQuantityString(R.plurals.minutes_plural, (int) minutes, (int) minutes));
    }

    return result.toString();
}

From source file:com.android.dialer.calllog.PhoneCallDetailsHelper.java

/**
 * Get the call date/time of the call. For the call log this is relative to the current time.
 * e.g. 3 minutes ago. For voicemail, see {@link #getGranularDateTime(PhoneCallDetails)}
 *
 * @param details Call details to use.//from   w w w  . j a  v a 2s . c om
 * @return String representing when the call occurred.
 */
public CharSequence getCallDate(PhoneCallDetails details) {
    if (details.callTypes[0] == Calls.VOICEMAIL_TYPE) {
        return getGranularDateTime(details);
    }

    return DateUtils.getRelativeTimeSpanString(details.date, getCurrentTimeMillis(), DateUtils.MINUTE_IN_MILLIS,
            DateUtils.FORMAT_ABBREV_RELATIVE);
}

From source file:com.ohso.omgubuntu.ArticleActivity.java

private void setContents(Article article) {
    CharSequence date = DateUtils.getRelativeTimeSpanString(article.getDate(), new Date().getTime(),
            DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
    StringBuilder content = new StringBuilder();
    content.append(/*  w ww .j a  v a 2 s. co  m*/
            "<!DOCTYPE html><head><link rel='stylesheet' type='text/css' href='style.css'></head><body>");
    content.append("<h1 id='article-title'>" + article.getTitle() + "</h1>");
    content.append("<div class='metadata'>");
    content.append("<span class='author'>" + article.getAuthor() + "</span>");
    content.append("<span class='date'>" + date + "</span></div>");
    content.append("<div class='post'>");
    content.append(article.getContent());
    content.append("<h2 class='internal-comments-link'><a href='internal://app-comments'>"
            + getResources().getString(R.string.activity_article_comment_text)
            + "</a></h2></div></body></html>");
    webview.loadDataWithBaseURL("file:///android_asset/", content.toString(), "text/html", "UTF-8",
            getResources().getString(R.string.base_url) + article.getPath());
}

From source file:com.gsma.rcs.ri.messaging.adapter.TalkCursorAdapter.java

private void bindRcsGroupChatEvent(View view, Cursor cursor) {
    BasicViewHolder holder = (BasicViewHolder) view.getTag();
    holder.getTimestampText()/*  ww w  .  j av a  2 s .  c  o  m*/
            .setText(DateUtils.getRelativeTimeSpanString(cursor.getLong(holder.getColumnTimestampIdx()),
                    System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE));
    String event = RiApplication.sGroupChatEvents[cursor.getInt(holder.getColumnStatusIdx())];
    holder.getStatusText().setText(mActivity.getString(R.string.label_groupchat_event, event));
}

From source file:com.androidinspain.deskclock.timer.TimerSetupView.java

public long getTimeInMillis() {
    final int seconds = mInput[1] * 10 + mInput[0];
    final int minutes = mInput[3] * 10 + mInput[2];
    final int hours = mInput[5] * 10 + mInput[4];
    return seconds * DateUtils.SECOND_IN_MILLIS + minutes * DateUtils.MINUTE_IN_MILLIS
            + hours * DateUtils.HOUR_IN_MILLIS;
}

From source file:com.android.calendar.alerts.AlarmScheduler.java

/**
 * Queries for all the reminders of the events in the instancesCursor, and schedules
 * the alarm for the next upcoming reminder.
 *///w  w  w. j  a v  a  2  s  .co m
private static void queryNextReminderAndSchedule(Cursor instancesCursor, Context context,
        ContentResolver contentResolver, AlarmManagerInterface alarmManager, int batchSize,
        long currentMillis) {
    if (AlertService.DEBUG) {
        int eventCount = instancesCursor.getCount();
        if (eventCount == 0) {
            Log.d(TAG, "No events found starting within 1 week.");
        } else {
            Log.d(TAG, "Query result count for events starting within 1 week: " + eventCount);
        }
    }

    // Put query results of all events starting within some interval into map of event ID to
    // local start time.
    Map<Integer, List<Long>> eventMap = new HashMap<Integer, List<Long>>();
    Time timeObj = new Time();
    long nextAlarmTime = Long.MAX_VALUE;
    int nextAlarmEventId = 0;
    instancesCursor.moveToPosition(-1);
    while (!instancesCursor.isAfterLast()) {
        int index = 0;
        eventMap.clear();
        StringBuilder eventIdsForQuery = new StringBuilder();
        eventIdsForQuery.append('(');
        while (index++ < batchSize && instancesCursor.moveToNext()) {
            int eventId = instancesCursor.getInt(INSTANCES_INDEX_EVENTID);
            long begin = instancesCursor.getLong(INSTANCES_INDEX_BEGIN);
            boolean allday = instancesCursor.getInt(INSTANCES_INDEX_ALL_DAY) != 0;
            long localStartTime;
            if (allday) {
                // Adjust allday to local time.
                localStartTime = Utils.convertAlldayUtcToLocal(timeObj, begin, Time.getCurrentTimezone());
            } else {
                localStartTime = begin;
            }
            List<Long> startTimes = eventMap.get(eventId);
            if (startTimes == null) {
                startTimes = new ArrayList<Long>();
                eventMap.put(eventId, startTimes);
                eventIdsForQuery.append(eventId);
                eventIdsForQuery.append(",");
            }
            startTimes.add(localStartTime);

            // Log for debugging.
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                timeObj.set(localStartTime);
                StringBuilder msg = new StringBuilder();
                msg.append("Events cursor result -- eventId:").append(eventId);
                msg.append(", allDay:").append(allday);
                msg.append(", start:").append(localStartTime);
                msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")");
                Log.d(TAG, msg.toString());
            }
        }
        if (eventIdsForQuery.charAt(eventIdsForQuery.length() - 1) == ',') {
            eventIdsForQuery.deleteCharAt(eventIdsForQuery.length() - 1);
        }
        eventIdsForQuery.append(')');

        // Query the reminders table for the events found.
        Cursor cursor = null;
        try {
            cursor = contentResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION,
                    REMINDERS_WHERE + eventIdsForQuery, null, null);

            // Process the reminders query results to find the next reminder time.
            cursor.moveToPosition(-1);
            while (cursor.moveToNext()) {
                int eventId = cursor.getInt(REMINDERS_INDEX_EVENT_ID);
                int reminderMinutes = cursor.getInt(REMINDERS_INDEX_MINUTES);
                List<Long> startTimes = eventMap.get(eventId);
                if (startTimes != null) {
                    for (Long startTime : startTimes) {
                        long alarmTime = startTime - reminderMinutes * DateUtils.MINUTE_IN_MILLIS;
                        if (alarmTime > currentMillis && alarmTime < nextAlarmTime) {
                            nextAlarmTime = alarmTime;
                            nextAlarmEventId = eventId;
                        }

                        if (Log.isLoggable(TAG, Log.DEBUG)) {
                            timeObj.set(alarmTime);
                            StringBuilder msg = new StringBuilder();
                            msg.append("Reminders cursor result -- eventId:").append(eventId);
                            msg.append(", startTime:").append(startTime);
                            msg.append(", minutes:").append(reminderMinutes);
                            msg.append(", alarmTime:").append(alarmTime);
                            msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")");
                            Log.d(TAG, msg.toString());
                        }
                    }
                }
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }

    // Schedule the alarm for the next reminder time.
    if (nextAlarmTime < Long.MAX_VALUE) {
        scheduleAlarm(context, nextAlarmEventId, nextAlarmTime, currentMillis, alarmManager);
    }
}

From source file:io.github.hidroh.materialistic.AppUtils.java

public static String getAbbreviatedTimeSpan(long timeMillis) {
    long span = Math.max(System.currentTimeMillis() - timeMillis, 0);
    if (span >= DateUtils.YEAR_IN_MILLIS) {
        return (span / DateUtils.YEAR_IN_MILLIS) + ABBR_YEAR;
    }/*  w w  w . j a va  2 s .c om*/
    if (span >= DateUtils.WEEK_IN_MILLIS) {
        return (span / DateUtils.WEEK_IN_MILLIS) + ABBR_WEEK;
    }
    if (span >= DateUtils.DAY_IN_MILLIS) {
        return (span / DateUtils.DAY_IN_MILLIS) + ABBR_DAY;
    }
    if (span >= DateUtils.HOUR_IN_MILLIS) {
        return (span / DateUtils.HOUR_IN_MILLIS) + ABBR_HOUR;
    }
    return (span / DateUtils.MINUTE_IN_MILLIS) + ABBR_MINUTE;
}

From source file:com.gsma.rcs.ri.messaging.adapter.TalkCursorAdapter.java

private void bindRcsFileTransferOutView(View view, Cursor cursor) {
    RcsFileTransferOutViewHolder holder = (RcsFileTransferOutViewHolder) view.getTag();
    holder.getTimestampText()/*from w w w  .ja  v  a 2 s .c  om*/
            .setText(DateUtils.getRelativeTimeSpanString(cursor.getLong(holder.getColumnTimestampIdx()),
                    System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE));
    String mimeType = cursor.getString(holder.getColumnMimetypeIdx());
    StringBuilder sb = new StringBuilder(cursor.getString(holder.getColumnFilenameIdx()));
    long filesize = cursor.getLong(holder.getColumnFilesizeIdx());
    long transferred = cursor.getLong(holder.getColumnTransferredIdx());
    final ImageView imageView = holder.getFileImageView();
    imageView.setOnClickListener(null);
    imageView.setLayoutParams(mImageParamsDefault);
    imageView.setImageResource(R.drawable.ri_filetransfer_on);
    if (filesize != transferred) {
        holder.getProgressText()
                .setText(sb.append(" : ").append(Utils.getProgressLabel(transferred, filesize)).toString());
    } else {
        holder.getProgressText().setText(sb.append(" (")
                .append(FileUtils.humanReadableByteCount(filesize, true)).append(")").toString());
    }
    final Uri file = Uri.parse(cursor.getString(holder.getColumnContentIdx()));
    if (Utils.isImageType(mimeType)) {
        String filePath = FileUtils.getPath(mContext, file);
        Bitmap imageBitmap = null;
        if (filePath != null) {
            LruCache<String, BitmapCacheInfo> memoryCache = bitmapCache.getMemoryCache();
            BitmapCacheInfo bitmapCacheInfo = memoryCache.get(filePath);
            if (bitmapCacheInfo == null) {
                ImageBitmapLoader loader = new ImageBitmapLoader(mContext, memoryCache, MAX_IMAGE_WIDTH,
                        MAX_IMAGE_HEIGHT, new BitmapLoader.SetViewCallback() {
                            @Override
                            public void loadView(BitmapCacheInfo cacheInfo) {
                                imageView.setImageBitmap(cacheInfo.getBitmap());
                                imageView.setLayoutParams(mImageParams);
                            }
                        });
                loader.execute(filePath);
            } else {
                imageBitmap = bitmapCacheInfo.getBitmap();
            }
            if (imageBitmap != null) {
                imageView.setImageBitmap(imageBitmap);
                imageView.setLayoutParams(mImageParams);
            }
            imageView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Utils.showPicture(mActivity, file);
                }
            });
        }
    } else if (Utils.isAudioType(mimeType)) {
        imageView.setImageResource(R.drawable.headphone);
        imageView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Utils.playAudio(mActivity, file);
            }
        });
    }
    holder.getStatusText().setText(getRcsFileTransferStatus(cursor, holder));
    boolean undeliveredExpiration = cursor.getInt(holder.getColumnExpiredDeliveryIdx()) == 1;
    holder.getStatusText().setCompoundDrawablesWithIntrinsicBounds(
            undeliveredExpiration ? R.drawable.chat_view_undelivered : 0, 0, 0, 0);
}