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:com.vuze.android.remote.activity.RcmActivity.java

@Override
public void onExtraViewVisibilityChange(final View view, int visibility) {
    {/*  w ww .  j ava 2 s. c  om*/
        if (visibility != View.VISIBLE) {
            if (pullRefreshHandler != null) {
                pullRefreshHandler.removeCallbacksAndMessages(null);
                pullRefreshHandler = null;
            }
            return;
        }

        if (pullRefreshHandler != null) {
            pullRefreshHandler.removeCallbacks(null);
            pullRefreshHandler = null;
        }
        pullRefreshHandler = new Handler(Looper.getMainLooper());

        pullRefreshHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (isFinishing()) {
                    return;
                }

                long sinceMS = System.currentTimeMillis() - lastUpdated;
                String since = DateUtils.getRelativeDateTimeString(RcmActivity.this, lastUpdated,
                        DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0).toString();
                String s = getResources().getString(R.string.last_updated, since);

                TextView tvSwipeText = (TextView) view.findViewById(R.id.swipe_text);
                tvSwipeText.setText(s);

                if (pullRefreshHandler == null) {
                    return;
                }
                pullRefreshHandler.postDelayed(this,
                        sinceMS < DateUtils.MINUTE_IN_MILLIS ? DateUtils.SECOND_IN_MILLIS
                                : sinceMS < DateUtils.HOUR_IN_MILLIS ? DateUtils.MINUTE_IN_MILLIS
                                        : DateUtils.HOUR_IN_MILLIS);
            }
        }, 0);
    }
}

From source file:com.adkdevelopment.earthquakesurvival.ui.PagerActivity.java

@Override
public void onConnected(Bundle bundle) {
    mLocationRequest = LocationRequest.create();
    mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    mLocationRequest.setInterval(DateUtils.HOUR_IN_MILLIS);
    mLocationRequest.setFastestInterval(DateUtils.MINUTE_IN_MILLIS);

    String perm = Manifest.permission.ACCESS_FINE_LOCATION;

    if (ContextCompat.checkSelfPermission(this, perm) != PackageManager.PERMISSION_GRANTED) {
        loadPermissions(perm, REQUEST_FINE_LOCATION);
    } else {/*from w  ww . ja  va 2s  .  co  m*/
        LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
        Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
        LocationUtils.setLocation(this, location);
    }
}

From source file:com.todoroo.astrid.adapter.UpdateAdapter.java

private void setupHistoryRow(View view, History history, User user) {
    final AsyncImageView pictureView = (AsyncImageView) view.findViewById(R.id.picture);
    {// w  w  w .j  ava2  s. c  o  m
        if (user.containsNonNullValue(USER_PICTURE)) {
            String pictureUrl = user.getPictureUrl(USER_PICTURE, RemoteModel.PICTURE_THUMB);
            pictureView.setUrl(pictureUrl);
        } else {
            pictureView.setUrl(null);
        }
        pictureView.setVisibility(View.VISIBLE);
    }

    final AsyncImageView commentPictureView = (AsyncImageView) view.findViewById(R.id.comment_picture);
    commentPictureView.setVisibility(View.GONE);

    final TextView nameView = (TextView) view.findViewById(R.id.title);
    {
        nameView.setText(
                getHistoryComment((AstridActivity) fragment.getActivity(), history, user, linkColor, fromView));
        nameView.setTextColor(grayColor);
    }

    final TextView date = (TextView) view.findViewById(R.id.date);
    {
        CharSequence dateString = DateUtils.getRelativeTimeSpanString(history.getValue(History.CREATED_AT),
                DateUtilities.now(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE);
        date.setText(dateString);
    }
}

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

private void bindRcsFileTransferInView(View view, Cursor cursor) {
    final RcsFileTransferInViewHolder holder = (RcsFileTransferInViewHolder) view.getTag();
    holder.getTimestampText()/*  w ww.j av a  2s.c o m*/
            .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_off);
    if (filesize != transferred) {
        holder.getProgressText()
                .setText(sb.append(" : ").append(Utils.getProgressLabel(transferred, filesize)).toString());
    } else {
        imageView.setImageResource(R.drawable.ri_filetransfer_on);
        final Uri file = Uri.parse(cursor.getString(holder.getColumnContentIdx()));
        final RcsService.ReadStatus readStatus = RcsService.ReadStatus
                .valueOf(cursor.getInt(holder.getColumnReadStatusIdx()));
        final String id = cursor.getString(cursor.getColumnIndexOrThrow(HistoryLog.ID));
        if (Utils.isImageType(mimeType)) {
            final String filePath = FileUtils.getPath(mContext, file);
            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 {
                    Bitmap imageBitmap = bitmapCacheInfo.getBitmap();
                    imageView.setImageBitmap(imageBitmap);
                    imageView.setLayoutParams(mImageParams);
                }
                imageView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Utils.showPicture(mActivity, file);
                        markFileTransferAsRead(id, readStatus);
                    }
                });
            }
        } 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);
                    markFileTransferAsRead(id, readStatus);
                }
            });
        }
        holder.getProgressText().setText(sb.append(" (")
                .append(FileUtils.humanReadableByteCount(filesize, true)).append(")").toString());
    }
    holder.getStatusText().setText(getRcsFileTransferStatus(cursor, holder));
}

From source file:com.androidinspain.deskclock.Utils.java

/**
 * Returns string denoting the timezone hour offset (e.g. GMT -8:00)
 *
 * @param useShortForm Whether to return a short form of the header that rounds to the
 *                     nearest hour and excludes the "GMT" prefix
 *///from  w ww. j av a  2s .  com
public static String getGMTHourOffset(TimeZone timezone, boolean useShortForm) {
    final int gmtOffset = timezone.getRawOffset();
    final long hour = gmtOffset / DateUtils.HOUR_IN_MILLIS;
    final long min = (Math.abs(gmtOffset) % DateUtils.HOUR_IN_MILLIS) / DateUtils.MINUTE_IN_MILLIS;

    if (useShortForm) {
        return String.format(Locale.ENGLISH, "%+d", hour);
    } else {
        return String.format(Locale.ENGLISH, "GMT %+d:%02d", hour, min);
    }
}

From source file:com.novoda.downloadmanager.lib.DownloadNotifier.java

/**
 * Return given duration in a human-friendly format. For example, "4
 * minutes" or "1 second". Returns only largest meaningful unit of time,
 * from seconds up to hours.//from w  ww  .ja  v a  2  s  . c  om
 */
public CharSequence formatDuration(long millis) {
    final Resources res = mContext.getResources();
    if (millis >= DateUtils.HOUR_IN_MILLIS) {
        final int hours = (int) ((millis + 1800000) / DateUtils.HOUR_IN_MILLIS);
        return res.getQuantityString(R.plurals.dl__duration_hours, hours, hours);
    } else if (millis >= DateUtils.MINUTE_IN_MILLIS) {
        final int minutes = (int) ((millis + 30000) / DateUtils.MINUTE_IN_MILLIS);
        return res.getQuantityString(R.plurals.dl__duration_minutes, minutes, minutes);
    } else {
        final int seconds = (int) ((millis + 500) / DateUtils.SECOND_IN_MILLIS);
        return res.getQuantityString(R.plurals.dl__duration_seconds, seconds, seconds);
    }
}

From source file:de.schildbach.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    final long lastUsedAgo = config.getLastUsedAgo();

    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else//w  w  w.j a  v  a 2  s .co  m
        alarmInterval = AlarmManager.INTERVAL_DAY;

    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
            lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent alarmIntent = PendingIntent.getService(context, 0,
            new Intent(context, BlockchainServiceImpl.class), 0);
    alarmManager.cancel(alarmIntent);

    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY,
            alarmIntent);
}

From source file:com.andrada.sitracker.ui.fragment.PublicationInfoFragment.java

private void updateRating() {
    String ratingString = currentRecord.getRating();
    if (!TextUtils.isEmpty(ratingString) && ratingString.split("\\*").length == 2) {
        float rating = Float.valueOf(ratingString.split("\\*")[0]);
        int ratingCount = Integer.valueOf(ratingString.split("\\*")[1]);
        mRatingContainer.setVisibility(View.VISIBLE);
        mPubRating.setText(String.valueOf(rating));
        mPubRatingCount.setText(String.valueOf(ratingCount));

        //Handle personal rating
        if (!TextUtils.isEmpty(currentRecord.getVoteCookie()) && currentRecord.getVoteDate() != null) {
            mRatingBar.setRating(currentRecord.getMyVote());
            mVotedOnField.setVisibility(View.VISIBLE);
            String formattedVoteDate = DateUtils
                    .getRelativeTimeSpanString(currentRecord.getVoteDate().getTime(), new Date().getTime(),
                            DateUtils.MINUTE_IN_MILLIS)
                    .toString();//from ww w  .  j  a v a2  s .c o  m
            mVotedOnField.setText(getString(R.string.publication_rating_vote_date, formattedVoteDate));
        } else {
            mRatingBar.setRating(rating);
            mVotedOnField.setVisibility(View.GONE);
        }
        mRatingVisible = true;

    } else {
        mRatingContainer.setVisibility(View.GONE);
        mRatingVisible = false;
    }
}

From source file:de.langerhans.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(@Nonnull final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    final long lastUsedAgo = config.getLastUsedAgo();

    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else//from ww  w . j ava2  s .  c  o m
        alarmInterval = AlarmManager.INTERVAL_DAY;

    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
            lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final Intent startIntent = new Intent(context, AutosyncReceiver.class);
    startIntent.setAction("de.langerhans.wallet.AUTOSYNC_ACTION");
    final PendingIntent alarmIntent = PendingIntent.getBroadcast(context, 0, startIntent, 0);
    alarmManager.cancel(alarmIntent);

    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY,
            alarmIntent);
}

From source file:biz.wiz.android.wallet.WalletApplication.java

public static void scheduleStartBlockchainService(@Nonnull final Context context) {
    final Configuration config = new Configuration(PreferenceManager.getDefaultSharedPreferences(context));
    final long lastUsedAgo = config.getLastUsedAgo();

    // apply some backoff
    final long alarmInterval;
    if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_JUST_MS)
        alarmInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
    else if (lastUsedAgo < Constants.LAST_USAGE_THRESHOLD_RECENTLY_MS)
        alarmInterval = AlarmManager.INTERVAL_HALF_DAY;
    else//from  w ww.  j a v  a 2 s.  c om
        alarmInterval = AlarmManager.INTERVAL_DAY;

    log.info("last used {} minutes ago, rescheduling blockchain sync in roughly {} minutes",
            lastUsedAgo / DateUtils.MINUTE_IN_MILLIS, alarmInterval / DateUtils.MINUTE_IN_MILLIS);

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final PendingIntent alarmIntent = PendingIntent.getService(context, 0,
            new Intent(context, BlockchainServiceImpl.class), 0);
    alarmManager.cancel(alarmIntent);

    // workaround for no inexact set() before KitKat
    final long now = System.currentTimeMillis();
    alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now + alarmInterval, AlarmManager.INTERVAL_DAY,
            alarmIntent);
}