List of usage examples for android.text.format DateUtils HOUR_IN_MILLIS
long HOUR_IN_MILLIS
To view the source code for android.text.format DateUtils HOUR_IN_MILLIS.
Click Source Link
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)); }//w ww. java 2 s. com 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.meiste.greg.ptw.tab.Questions.java
@Override public void onResume() { super.onResume(); final IntentFilter filter = new IntentFilter(PTW.INTENT_ACTION_SCHEDULE); filter.addAction(PTW.INTENT_ACTION_RACE_ALARM); filter.addAction(PTW.INTENT_ACTION_HISTORY); getActivity().registerReceiver(mBroadcastReceiver, filter); if ((mRaceSelected != null) && mRaceSelected.inProgress()) { QuestionAlarm.clearNotification(getActivity().getApplicationContext()); }//from ww w .j a v a2 s. c om // Check if user changed their account status mChanged |= mSetupNeeded != GAE.isAccountSetupNeeded(getActivity()); // Check if user has switched accounts mChanged |= mAccountSetupTime != Util.getAccountSetupTime(getActivity()); if (mSubFragmentTime > 0) { // Check if user submitted answers on a different device mChanged |= mSubFragmentTime < PlayerHistory.getTime(getActivity()); // Check if app has been running for awhile and should be refreshed mChanged |= (System.currentTimeMillis() - mSubFragmentTime) > DateUtils.HOUR_IN_MILLIS; } if (mRaceNext != null) { if (mSubFragmentTime > 0) { // See if race questions are now available but weren't previously mChanged |= (mSubFragmentTime < mRaceNext.getQuestionTimestamp()) && mRaceNext.inProgress(); } // Check if questions form needs to disappear because race started mChanged |= !mRaceNext.isFuture(); } if (mChanged) { Util.log("Questions: onResume: notifyChanged"); resetRaceSelected(); } }
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; }/*from w ww. j ava2s . c o m*/ 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.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.kncwallet.wallet.ui.ReceiveFragment.java
private void updateBalanceView() { if (!isAdded()) return;/*from w ww.j av a 2s .c o m*/ final boolean showProgress; if (bestChainDate != null) { final long blockchainLag = System.currentTimeMillis() - bestChainDate.getTime(); final boolean blockchainUptodate = blockchainLag < Constants.BLOCKCHAIN_UPTODATE_THRESHOLD_MS; final boolean downloadOk = download == BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK; showProgress = !(blockchainUptodate || !replaying); final String downloading = getString(downloadOk ? R.string.blockchain_state_progress_downloading : R.string.blockchain_state_progress_stalled); if (blockchainLag < 2 * DateUtils.DAY_IN_MILLIS) { final long hours = blockchainLag / DateUtils.HOUR_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_hours, downloading, hours)); } else if (blockchainLag < 2 * DateUtils.WEEK_IN_MILLIS) { final long days = blockchainLag / DateUtils.DAY_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_days, downloading, days)); } else if (blockchainLag < 90 * DateUtils.DAY_IN_MILLIS) { final long weeks = blockchainLag / DateUtils.WEEK_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_weeks, downloading, weeks)); } else { final long months = blockchainLag / (30 * DateUtils.DAY_IN_MILLIS); viewProgress.setText(getString(R.string.blockchain_state_progress_months, downloading, months)); } } else { showProgress = false; } if (!showProgress) { viewBalance.setVisibility(View.VISIBLE); if (balance != null) { final String precision = prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION); final int btcPrecision = precision.charAt(0) - '0'; final int btcShift = precision.length() == 3 ? precision.charAt(2) - '0' : 0; final String prefix = DenominationUtil.getCurrencyCode(btcShift); viewBalanceBtc.setVisibility(View.VISIBLE); viewBalanceBtc.setPrecision(btcPrecision, btcShift); viewBalanceBtc.setSuffix(prefix); viewBalanceBtc.setAmount(balance); } else { viewBalanceBtc.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } if (exchangeRate != null && exchangeRate.rate != null && balance != null) { final BigInteger localValue = WalletUtils.localValue(balance, exchangeRate.rate); viewBalanceLocal.setSuffix(exchangeRate.currencyCode); viewBalanceLocal.setAmount(localValue); viewBalanceLocal.setTextColor(getResources().getColor(R.color.knc_highlight)); } }
From source file:com.kncwallet.wallet.ui.HomeFragment.java
private void updateBalanceView() { if (!isAdded()) return;/*from w w w . j a v a2 s.c om*/ final boolean showProgress; if (bestChainDate != null) { final long blockchainLag = System.currentTimeMillis() - bestChainDate.getTime(); final boolean blockchainUptodate = blockchainLag < Constants.BLOCKCHAIN_UPTODATE_THRESHOLD_MS; final boolean downloadOk = download == BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK; showProgress = !(blockchainUptodate || !replaying); final String downloading = getString(downloadOk ? R.string.blockchain_state_progress_downloading : R.string.blockchain_state_progress_stalled); if (blockchainLag < 2 * DateUtils.DAY_IN_MILLIS) { final long hours = blockchainLag / DateUtils.HOUR_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_hours, downloading, hours)); } else if (blockchainLag < 2 * DateUtils.WEEK_IN_MILLIS) { final long days = blockchainLag / DateUtils.DAY_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_days, downloading, days)); } else if (blockchainLag < 90 * DateUtils.DAY_IN_MILLIS) { final long weeks = blockchainLag / DateUtils.WEEK_IN_MILLIS; viewProgress.setText(getString(R.string.blockchain_state_progress_weeks, downloading, weeks)); } else { final long months = blockchainLag / (30 * DateUtils.DAY_IN_MILLIS); viewProgress.setText(getString(R.string.blockchain_state_progress_months, downloading, months)); } } else { showProgress = false; } if (!showProgress) { viewBalance.setVisibility(View.VISIBLE); if (balance != null) { final String precision = prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION); final int btcPrecision = precision.charAt(0) - '0'; final int btcShift = precision.length() == 3 ? precision.charAt(2) - '0' : 0; final String prefix = DenominationUtil.getCurrencyCode(btcShift); if (viewBalanceLocal.getVisibility() != View.VISIBLE) { viewBalanceBtc.setVisibility(View.VISIBLE); } viewBalanceBtc.setPrecision(btcPrecision, btcShift); viewBalanceBtc.setSuffix(prefix); viewBalanceBtc.setAmount(balance); } else { viewBalanceBtc.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } if (exchangeRate != null && exchangeRate.rate != null && balance != null) { final BigInteger localValue = WalletUtils.localValue(balance, exchangeRate.rate); viewBalanceLocal.setSuffix(exchangeRate.currencyCode); viewBalanceLocal.setAmount(localValue); viewBalanceLocal.setTextColor(getResources().getColor(R.color.knc_highlight)); } }
From source file:com.stasbar.knowyourself.timer.CountingTimerView.java
/** * Update the time to display. Separates that time into the hours, minutes, seconds and * hundredths. If update is true, the view is invalidated so that it will draw again. * * @param time new time to display - in milliseconds * @param showHundredths flag to show hundredths resolution *///from www . j av a2 s .c o m // TODO:showHundredths S/B attribute or setter - i.e. unchanging over object life public void setTime(long time, boolean showHundredths) { final int oldLength = getDigitsLength(); boolean neg = false, showNeg = false; if (time < 0) { time = -time; neg = showNeg = true; } int hours = (int) (time / DateUtils.HOUR_IN_MILLIS); int remainder = (int) (time % DateUtils.HOUR_IN_MILLIS); int minutes = (int) (remainder / DateUtils.MINUTE_IN_MILLIS); remainder = (int) (remainder % DateUtils.MINUTE_IN_MILLIS); int seconds = (int) (remainder / DateUtils.SECOND_IN_MILLIS); remainder = (int) (remainder % DateUtils.SECOND_IN_MILLIS); int hundredths = remainder / 10; if (hours > 999) { hours = 0; } // The time can be between 0 and -1 seconds, but the "truncated" equivalent time of hours // and minutes and seconds could be zero, so since we do not show fractions of seconds // when counting down, do not show the minus sign. // TODO:does it matter that we do not look at showHundredths? if (hours == 0 && minutes == 0 && seconds == 0) { showNeg = false; } // If not showing hundredths, round up to the next second. if (!showHundredths) { if (!neg && hundredths != 0) { seconds++; if (seconds == 60) { seconds = 0; minutes++; if (minutes == 60) { minutes = 0; hours++; } } } } // Hours may be empty. final UiDataModel uiDataModel = UiDataModel.getUiDataModel(); if (hours > 0) { final int hoursLength = hours >= 10 ? 2 : 1; mHours = uiDataModel.getFormattedNumber(showNeg, hours, hoursLength); } else { mHours = null; } // Minutes are never empty and forced to two digits when hours exist. final boolean showNegMinutes = showNeg && hours == 0; final int minutesLength = minutes >= 10 || hours > 0 ? 2 : 1; mMinutes = uiDataModel.getFormattedNumber(showNegMinutes, minutes, minutesLength); // Seconds are always two digits mSeconds = uiDataModel.getFormattedNumber(seconds, 2); // Hundredths are optional but forced to two digits when displayed. if (showHundredths) { mHundredths = uiDataModel.getFormattedNumber(hundredths, 2); } else { mHundredths = null; } int newLength = getDigitsLength(); if (oldLength != newLength) { if (oldLength > newLength) { resetTextSize(); } mRemeasureText = true; } setContentDescription(getTimeStringForAccessibility(hours, minutes, seconds, showNeg, getResources())); postInvalidateOnAnimation(); }
From source file:com.vuze.android.remote.AppPreferences.java
public boolean shouldShowRatingReminder() { if (AndroidUtils.DEBUG) { Log.d(TAG, "# Opens: " + getNumOpens() + "\n" + "FirstInstalledOn: " + ((System.currentTimeMillis() - getFirstInstalledOn()) / DateUtils.HOUR_IN_MILLIS) + "hr\n" + "LastUpdatedOn: " + ((System.currentTimeMillis() - getLastUpdatedOn()) / DateUtils.HOUR_IN_MILLIS) + "hr\n" + "AskedRatingOn: " + ((System.currentTimeMillis() - getAskedRatingOn()) / DateUtils.HOUR_IN_MILLIS) + "hr\n"); }/*w w w. j a va 2 s . c om*/ if (!getNeverAskRatingAgain() && getNumOpens() > RATING_REMINDER_MIN_LAUNCHES && System.currentTimeMillis() - getFirstInstalledOn() > RATING_REMINDER_MIN_INSTALL_MS && System.currentTimeMillis() - getLastUpdatedOn() > RATING_REMINDER_MIN_UPDATE_MS && System.currentTimeMillis() - getAskedRatingOn() > RATING_REMINDER_MIN_INTERVAL_MS) { return true; } return false; }
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 {//ww w.j a v a 2 s .c o m LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this); Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient); LocationUtils.setLocation(this, location); } }
From source file:com.vuze.android.remote.activity.RcmActivity.java
@Override public void onExtraViewVisibilityChange(final View view, int visibility) { {//from w w w . j a va 2 s.c o m 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); } }