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:de.schildbach.litecoinwallet.ui.WalletBalanceFragment.java
private void updateView() { if (!isAdded()) return;//from w w w . j a v a 2 s . 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 (!showLocalBalance) viewBalanceLocalFrame.setVisibility(View.GONE); 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 = btcShift == 0 ? Constants.CURRENCY_CODE_BTC : Constants.CURRENCY_CODE_MBTC; viewBalanceBtc.setVisibility(View.VISIBLE); viewBalanceBtc.setPrecision(btcPrecision, btcShift); viewBalanceBtc.setPrefix(prefix); viewBalanceBtc.setAmount(balance); if (showLocalBalance) { if (exchangeRate != null) { final BigInteger localValue = WalletUtils.localValue(balance, exchangeRate.rate); viewBalanceLocalFrame.setVisibility(View.VISIBLE); viewBalanceLocal.setPrefix(Constants.PREFIX_ALMOST_EQUAL_TO + exchangeRate.currencyCode); viewBalanceLocal.setAmount(localValue); viewBalanceLocal.setTextColor(getResources().getColor(R.color.fg_less_significant)); } else { viewBalanceLocalFrame.setVisibility(View.INVISIBLE); } } } else { viewBalanceBtc.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } }
From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletBalanceFragment.java
private void updateView() { if (!isAdded()) return;//from w w w . ja v a2 s. 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 (!showLocalBalance) viewBalanceLocalFrame.setVisibility(View.GONE); if (balance != null) { viewBalancePPC.setVisibility(View.VISIBLE); viewBalancePPC.setPrecision(config.getPPCPrecision(), config.getPPCShift()); viewBalancePPC.setPrefix(config.getPPCPrefix()); viewBalancePPC.setAmount(balance); if (showLocalBalance) { if (exchangeRate != null) { final BigInteger localValue = WalletUtils.localValue(balance, exchangeRate.rate); viewBalanceLocalFrame.setVisibility(View.VISIBLE); viewBalanceLocal.setPrefix(Constants.PREFIX_ALMOST_EQUAL_TO + exchangeRate.currencyCode); viewBalanceLocal.setAmount(localValue); viewBalanceLocal.setTextColor(getResources().getColor(R.color.fg_less_significant)); } else { viewBalanceLocalFrame.setVisibility(View.INVISIBLE); } } } else { viewBalancePPC.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } }
From source file:hashengineering.digitalcoin.wallet.ui.WalletBalanceFragment.java
private void updateView() { if (!isAdded()) return;//ww w .ja v a 2 s . co 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 (!showLocalBalance) viewBalanceLocalFrame.setVisibility(View.GONE); if (balance != null) { viewBalanceBtc.setVisibility(View.VISIBLE); viewBalanceBtc.setPrecision(Integer.parseInt( prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Constants.PREFS_DEFAULT_BTC_PRECISION))); viewBalanceBtc.setAmount(balance); if (showLocalBalance) { if (exchangeRate != null) { final BigInteger localValue = WalletUtils.localValue(balance, exchangeRate.rate); viewBalanceLocalFrame.setVisibility(View.VISIBLE); viewBalanceLocal.setPrefix(Constants.PREFIX_ALMOST_EQUAL_TO + exchangeRate.currencyCode); viewBalanceLocal.setAmount(localValue); viewBalanceLocal.setTextColor(getResources().getColor(R.color.fg_less_significant)); } else { viewBalanceLocalFrame.setVisibility(View.INVISIBLE); } } } else { viewBalanceBtc.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } }
From source file:com.battlelancer.seriesguide.service.NotificationService.java
@SuppressLint("CommitPrefEdits") @TargetApi(android.os.Build.VERSION_CODES.KITKAT) @Override// www .j ava 2 s . co m protected void onHandleIntent(Intent intent) { Timber.d("Waking up..."); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); /* * Handle a possible delete intent. */ if (handleDeleteIntent(this, intent)) { return; } /* * Unschedule notification service wake-ups for disabled notifications * and non-supporters. */ if (!NotificationSettings.isNotificationsEnabled(this) || !Utils.hasAccessToX(this)) { Timber.d("Notification service disabled, removing wakup-up alarm"); // cancel any pending alarm AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, OnAlarmReceiver.class); PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0); am.cancel(pi); resetLastEpisodeAirtime(prefs); return; } long wakeUpTime = 0; /* * Get pool of episodes which air from 12 hours ago until eternity which * match the users settings. */ StringBuilder selection = new StringBuilder(SELECTION); boolean isFavsOnly = NotificationSettings.isNotifyAboutFavoritesOnly(this); Timber.d("Do notify about " + (isFavsOnly ? "favorites ONLY" : "ALL")); if (isFavsOnly) { selection.append(" AND ").append(Shows.SELECTION_FAVORITES); } boolean isNoSpecials = DisplaySettings.isHidingSpecials(this); Timber.d("Do " + (isNoSpecials ? "NOT " : "") + "notify about specials"); if (isNoSpecials) { selection.append(" AND ").append(Episodes.SELECTION_NO_SPECIALS); } // always exclude hidden shows selection.append(" AND ").append(Shows.SELECTION_NO_HIDDEN); final long customCurrentTime = TimeTools.getCurrentTime(this); final Cursor upcomingEpisodes = getContentResolver().query(Episodes.CONTENT_URI_WITHSHOW, PROJECTION, selection.toString(), new String[] { String.valueOf(customCurrentTime - 12 * DateUtils.HOUR_IN_MILLIS) }, SORTING); if (upcomingEpisodes != null) { int notificationThreshold = NotificationSettings.getLatestToIncludeTreshold(this); if (DEBUG) { Timber.d("DEBUG MODE: notification threshold is 1 week"); // a week, for debugging (use only one show to get single // episode notifications) notificationThreshold = 10080; // notify again for same episodes resetLastEpisodeAirtime(prefs); } final long nextEpisodeReleaseTime = NotificationSettings.getNextToNotifyAbout(this); // wake user-defined amount of time earlier than next episode release time final long plannedWakeUpTime = TimeTools.getEpisodeReleaseTime(this, nextEpisodeReleaseTime).getTime() - DateUtils.MINUTE_IN_MILLIS * notificationThreshold; /* * Set to -1 as on first run nextTimePlanned will be 0. This assures * we still see notifications of upcoming episodes then. */ int newEpisodesAvailable = -1; // Check if we did wake up earlier than planned if (System.currentTimeMillis() < plannedWakeUpTime) { Timber.d("Woke up earlier than planned, checking for new episodes"); newEpisodesAvailable = 0; long latestTimeNotified = NotificationSettings.getLastNotified(this); // Check if there are any earlier episodes to notify about while (upcomingEpisodes.moveToNext()) { final long releaseTime = upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS); if (releaseTime < nextEpisodeReleaseTime) { if (releaseTime > latestTimeNotified) { /** * This will not get new episodes which would have * aired the same time as the last one we notified * about. Sad, but the best we can do right now. */ newEpisodesAvailable = 1; break; } } else { break; } } } if (newEpisodesAvailable == 0) { // Go to sleep, wake up as planned Timber.d("No new episodes, going to sleep."); wakeUpTime = plannedWakeUpTime; } else { // Get episodes which are within the notification threshold // (user set) and not yet cleared final List<Integer> notifyPositions = new ArrayList<>(); final long latestTimeCleared = NotificationSettings.getLastCleared(this); final long latestTimeToInclude = customCurrentTime + DateUtils.MINUTE_IN_MILLIS * notificationThreshold; int position = -1; upcomingEpisodes.moveToPosition(position); while (upcomingEpisodes.moveToNext()) { position++; final long releaseTime = upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS); if (releaseTime <= latestTimeToInclude) { /* * Only add those after the last one the user cleared. * At most those of the last 24 hours (see query above). */ if (releaseTime > latestTimeCleared) { notifyPositions.add(position); } } else { // Too far into the future, stop! break; } } // Notify if we found any episodes if (notifyPositions.size() > 0) { // store latest air time of all episodes we notified about upcomingEpisodes.moveToPosition(notifyPositions.get(notifyPositions.size() - 1)); long latestAirtime = upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS); if (!AndroidUtils.isHoneycombOrHigher()) { /* * Everything below HC does not have delete intents, so * we just never notify about the same episode twice. */ Timber.d("Delete intent NOT supported, setting last cleared to: " + latestAirtime); prefs.edit().putLong(NotificationSettings.KEY_LAST_CLEARED, latestAirtime).commit(); } Timber.d("Found " + notifyPositions.size() + " new episodes, setting last notified to: " + latestAirtime); prefs.edit().putLong(NotificationSettings.KEY_LAST_NOTIFIED, latestAirtime).commit(); onNotify(upcomingEpisodes, notifyPositions, latestAirtime); } /* * Plan next episode to notify about, calc wake-up alarm as * early as user wants. */ upcomingEpisodes.moveToPosition(-1); while (upcomingEpisodes.moveToNext()) { final long releaseTime = upcomingEpisodes.getLong(NotificationQuery.EPISODE_FIRST_RELEASE_MS); if (releaseTime > latestTimeToInclude) { // store next episode we plan to notify about Timber.d("Storing next episode time to notify about: " + releaseTime); prefs.edit().putLong(NotificationSettings.KEY_NEXT_TO_NOTIFY, releaseTime).commit(); // calc actual wake up time wakeUpTime = TimeTools.getEpisodeReleaseTime(this, releaseTime).getTime() - DateUtils.MINUTE_IN_MILLIS * notificationThreshold; break; } } } upcomingEpisodes.close(); } // Set a default wake-up time if there are no future episodes for now if (wakeUpTime <= 0) { wakeUpTime = System.currentTimeMillis() + 6 * DateUtils.HOUR_IN_MILLIS; Timber.d("No future episodes found, wake up in 6 hours"); } AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, NotificationService.class); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); Timber.d("Going to sleep, setting wake-up alarm to: " + wakeUpTime); if (AndroidUtils.isKitKatOrHigher()) { am.setExact(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } else { am.set(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } }
From source file:de.schildbach.wallet.goldcoin.ui.BlockchainStateFragment.java
private void updateView() { final boolean disclaimer = prefs.getBoolean(Constants.PREFS_KEY_DISCLAIMER, true); final boolean showDisclaimer; final boolean showProgress; if (download != BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK) { showDisclaimer = false;/* w ww. ja v a 2s. c om*/ showProgress = true; if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_STORAGE_PROBLEM) != 0) progressView.setText(R.string.blockchain_state_progress_problem_storage); else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_POWER_PROBLEM) != 0) progressView.setText(R.string.blockchain_state_progress_problem_power); else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_NETWORK_PROBLEM) != 0) progressView.setText(R.string.blockchain_state_progress_problem_network); } else if (bestChainDate != null) { final long blockchainLag = System.currentTimeMillis() - bestChainDate.getTime(); final boolean blockchainUptodate = blockchainLag < Constants.BLOCKCHAIN_UPTODATE_THRESHOLD_MS; showProgress = !blockchainUptodate; showDisclaimer = blockchainUptodate && disclaimer; final String downloading = getString(R.string.blockchain_state_progress_downloading); final String stalled = getString(R.string.blockchain_state_progress_stalled); final String stalledText; if (blockchainLag < 2 * DateUtils.DAY_IN_MILLIS) { final long hours = blockchainLag / DateUtils.HOUR_IN_MILLIS; progressView.setText(getString(R.string.blockchain_state_progress_hours, downloading, hours)); stalledText = getString(R.string.blockchain_state_progress_hours, stalled, hours); } else if (blockchainLag < 2 * DateUtils.WEEK_IN_MILLIS) { final long days = blockchainLag / DateUtils.DAY_IN_MILLIS; progressView.setText(getString(R.string.blockchain_state_progress_days, downloading, days)); stalledText = getString(R.string.blockchain_state_progress_days, stalled, days); } else if (blockchainLag < 90 * DateUtils.DAY_IN_MILLIS) { final long weeks = blockchainLag / DateUtils.WEEK_IN_MILLIS; progressView.setText(getString(R.string.blockchain_state_progress_weeks, downloading, weeks)); stalledText = getString(R.string.blockchain_state_progress_weeks, stalled, weeks); } else { final long months = blockchainLag / (30 * DateUtils.DAY_IN_MILLIS); progressView.setText(getString(R.string.blockchain_state_progress_months, downloading, months)); stalledText = getString(R.string.blockchain_state_progress_months, stalled, months); } delayMessageHandler.removeCallbacksAndMessages(null); delayMessageHandler.postDelayed(new Runnable() { public void run() { progressView.setText(stalledText); } }, Constants.BLOCKCHAIN_DOWNLOAD_THRESHOLD_MS); } else { showDisclaimer = disclaimer; showProgress = false; } final boolean showReplaying = replaying; disclaimerView.setVisibility(showDisclaimer ? View.VISIBLE : View.GONE); progressView.setVisibility(showProgress ? View.VISIBLE : View.GONE); replayingView.setVisibility(showReplaying ? View.VISIBLE : View.GONE); getView().setVisibility( View.VISIBLE /*showDisclaimer || showProgress || showReplaying ? View.VISIBLE : View.GONE*/); }
From source file:de.schildbach.wallet.elysium.ui.BlockchainStateFragment.java
private void updateView() { final boolean disclaimer = prefs.getBoolean(Constants.PREFS_KEY_DISCLAIMER, true); final boolean showDisclaimer; final boolean showProgress; if (download != BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK) { showDisclaimer = false;//from w ww . j a va2 s .c o m showProgress = true; if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_STORAGE_PROBLEM) != 0) progressView.setText(R.string.blockchain_state_progress_problem_storage); else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_POWER_PROBLEM) != 0) progressView.setText(R.string.blockchain_state_progress_problem_power); else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_NETWORK_PROBLEM) != 0) progressView.setText(R.string.blockchain_state_progress_problem_network); } else if (bestChainDate != null) { final long blockchainLag = System.currentTimeMillis() - bestChainDate.getTime(); final boolean blockchainUptodate = blockchainLag < Constants.BLOCKCHAIN_UPTODATE_THRESHOLD_MS; showProgress = !blockchainUptodate; showDisclaimer = blockchainUptodate && disclaimer; final String downloading = getString(R.string.blockchain_state_progress_downloading); final String stalled = getString(R.string.blockchain_state_progress_stalled); final String stalledText; if (blockchainLag < 2 * DateUtils.DAY_IN_MILLIS) { final long hours = blockchainLag / DateUtils.HOUR_IN_MILLIS; progressView.setText(getString(R.string.blockchain_state_progress_hours, downloading, hours)); stalledText = getString(R.string.blockchain_state_progress_hours, stalled, hours); } else if (blockchainLag < 2 * DateUtils.WEEK_IN_MILLIS) { final long days = blockchainLag / DateUtils.DAY_IN_MILLIS; progressView.setText(getString(R.string.blockchain_state_progress_days, downloading, days)); stalledText = getString(R.string.blockchain_state_progress_days, stalled, days); } else if (blockchainLag < 90 * DateUtils.DAY_IN_MILLIS) { final long weeks = blockchainLag / DateUtils.WEEK_IN_MILLIS; progressView.setText(getString(R.string.blockchain_state_progress_weeks, downloading, weeks)); stalledText = getString(R.string.blockchain_state_progress_weeks, stalled, weeks); } else { final long months = blockchainLag / (30 * DateUtils.DAY_IN_MILLIS); progressView.setText(getString(R.string.blockchain_state_progress_months, downloading, months)); stalledText = getString(R.string.blockchain_state_progress_months, stalled, months); } delayMessageHandler.removeCallbacksAndMessages(null); delayMessageHandler.postDelayed(new Runnable() { public void run() { progressView.setText(stalledText); } }, Constants.BLOCKCHAIN_DOWNLOAD_THRESHOLD_MS); } else { showDisclaimer = disclaimer; showProgress = false; } final boolean showReplaying = replaying; disclaimerView.setVisibility(showDisclaimer ? View.VISIBLE : View.GONE); progressView.setVisibility(showProgress ? View.VISIBLE : View.GONE); replayingView.setVisibility(showReplaying ? View.VISIBLE : View.GONE); getView().setVisibility(showDisclaimer || showProgress || showReplaying ? View.VISIBLE : View.GONE); }
From source file:de.schildbach.wallet.ui.WalletBalanceFragment.java
private void updateView() { final boolean showProgress; if (download != BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_OK) { showProgress = true;/*from w ww .j a va 2s. c o m*/ if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_STORAGE_PROBLEM) != 0) viewProgress.setText(R.string.blockchain_state_progress_problem_storage); else if ((download & BlockchainService.ACTION_BLOCKCHAIN_STATE_DOWNLOAD_NETWORK_PROBLEM) != 0) viewProgress.setText(R.string.blockchain_state_progress_problem_network); } else if (bestChainDate != null) { final long blockchainLag = System.currentTimeMillis() - bestChainDate.getTime(); final boolean blockchainUptodate = blockchainLag < Constants.BLOCKCHAIN_UPTODATE_THRESHOLD_MS; showProgress = !blockchainUptodate; final String downloading = getString(R.string.blockchain_state_progress_downloading); final String stalled = getString(R.string.blockchain_state_progress_stalled); final String stalledText; 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)); stalledText = getString(R.string.blockchain_state_progress_hours, stalled, 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)); stalledText = getString(R.string.blockchain_state_progress_days, stalled, 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)); stalledText = getString(R.string.blockchain_state_progress_weeks, stalled, weeks); } else { final long months = blockchainLag / (30 * DateUtils.DAY_IN_MILLIS); viewProgress.setText(getString(R.string.blockchain_state_progress_months, downloading, months)); stalledText = getString(R.string.blockchain_state_progress_months, stalled, months); } delayMessageHandler.removeCallbacksAndMessages(null); delayMessageHandler.postDelayed(new Runnable() { public void run() { viewProgress.setText(stalledText); } }, Constants.BLOCKCHAIN_DOWNLOAD_THRESHOLD_MS); } else { showProgress = false; } if (!showProgress) { viewBalance.setVisibility(View.VISIBLE); if (!showLocalBalance) viewBalanceLocalFrame.setVisibility(View.GONE); if (balance != null) { viewBalanceBtc.setVisibility(View.VISIBLE); viewBalanceBtc.setPrecision(Integer.parseInt(prefs.getString(Constants.PREFS_KEY_BTC_PRECISION, Integer.toString(Constants.BTC_PRECISION)))); viewBalanceBtc.setAmount(balance); if (showLocalBalance) { if (exchangeRate != null) { final BigInteger localValue = WalletUtils.localValue(balance, exchangeRate.rate); viewBalanceLocalFrame.setVisibility(View.VISIBLE); viewBalanceLocal.setPrefix(Constants.PREFIX_ALMOST_EQUAL_TO + exchangeRate.currencyCode); viewBalanceLocal.setAmount(localValue); viewBalanceLocal.setTextColor(getResources().getColor(R.color.fg_less_significant)); } else { viewBalanceLocalFrame.setVisibility(View.INVISIBLE); } } } else { viewBalanceBtc.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } }
From source file:org.telegram.ui.Components.TwilightManager.java
private void updateState(@NonNull Location location) { final TwilightState state = mTwilightState; final long now = System.currentTimeMillis(); final TwilightCalculator calculator = TwilightCalculator.getInstance(); // calculate yesterday's twilight calculator.calculateTwilight(now - DateUtils.DAY_IN_MILLIS, location.getLatitude(), location.getLongitude());/* w w w . j a va 2 s . co m*/ final long yesterdaySunset = calculator.sunset; // calculate today's twilight calculator.calculateTwilight(now, location.getLatitude(), location.getLongitude()); final boolean isNight = (calculator.state == TwilightCalculator.NIGHT); final long todaySunrise = calculator.sunrise; final long todaySunset = calculator.sunset; // calculate tomorrow's twilight calculator.calculateTwilight(now + DateUtils.DAY_IN_MILLIS, location.getLatitude(), location.getLongitude()); final long tomorrowSunrise = calculator.sunrise; // Set next update long nextUpdate = 0; if (todaySunrise == -1 || todaySunset == -1) { // In the case the day or night never ends the update is scheduled 12 hours later. nextUpdate = now + 12 * DateUtils.HOUR_IN_MILLIS; } else { if (now > todaySunset) { nextUpdate += tomorrowSunrise; } else if (now > todaySunrise) { nextUpdate += todaySunset; } else { nextUpdate += todaySunrise; } // add some extra time to be on the safe side. nextUpdate += DateUtils.MINUTE_IN_MILLIS; } // Update the twilight state state.isNight = isNight; state.yesterdaySunset = yesterdaySunset; state.todaySunrise = todaySunrise; state.todaySunset = todaySunset; state.tomorrowSunrise = tomorrowSunrise; state.nextUpdate = nextUpdate; }
From source file:com.jpventura.xyzreader.ui.ArticleDetailFragment.java
private void bindViews() { if (mRootView == null) { return;//from w w w . j a va 2 s . co m } mTitleView = (TextView) mRootView.findViewById(R.id.article_title); mSubitleView = (TextView) mRootView.findViewById(R.id.article_byline); mSubitleView.setMovementMethod(new LinkMovementMethod()); mBodyView = (TextView) mRootView.findViewById(R.id.article_body); if (null == mCursor) { mRootView.setVisibility(View.GONE); mTitleView.setText("N/A"); mSubitleView.setText("N/A"); mBodyView.setText("N/A"); return; } mRootView.setAlpha(0); mRootView.setVisibility(View.VISIBLE); mRootView.animate().alpha(1); mTitleView.setText(mCursor.getString(ArticleLoader.Query.TITLE)); mSubitleView.setText(Html.fromHtml(DateUtils .getRelativeTimeSpanString(mCursor.getLong(ArticleLoader.Query.PUBLISHED_DATE), System.currentTimeMillis(), DateUtils.HOUR_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL) .toString() + " by <font color='#ffffff'>" + mCursor.getString(ArticleLoader.Query.AUTHOR) + "</font>")); mBodyView.setText(Html.fromHtml(mCursor.getString(ArticleLoader.Query.BODY))); Picasso.with(getActivity()).load(mCursor.getString(ArticleLoader.Query.PHOTO_URL)).into(mPhotoView, this); }
From source file:com.example.xyzreader.ui.articledetail.ArticleDetailFragment.java
private void bindViews() { if (mRootView == null || mCursor == null) { return;//from w ww. j a v a2s . co m } final ImageView detailImageView = (ImageView) mRootView.findViewById(R.id.detail_image); final TextView articleTitle = (TextView) mRootView.findViewById(R.id.article_detail_title); final TextView articleByLine = (TextView) mRootView.findViewById(R.id.article_detail_byline); final TextView bodyView = (TextView) mRootView.findViewById(R.id.article_body); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { long itemId = mCursor.getLong(ArticleLoader.Query._ID); String imageTransitionName = mContext.getString(R.string.image_transition_name) + itemId; detailImageView.setTransitionName(imageTransitionName); // Log.d(LOG_TAG, "detail image transition name = '" + imageTransitionName + "'"); } Picasso.with(mContext).load(mCursor.getString(ArticleLoader.Query.PHOTO_URL)).into(detailImageView, new Callback() { @Override public void onSuccess() { // Log.d(LOG_TAG, "successful image load"); mPalette = generatePalette(detailImageView); if (getUserVisibleHint() && isResumed()) { setAppBarColor(); } } @Override public void onError() { // Log.d(LOG_TAG, "image load FAIL"); } }); articleTitle.setText(mCursor.getString(ArticleLoader.Query.TITLE)); String byLine = DateUtils .getRelativeTimeSpanString(mCursor.getLong(ArticleLoader.Query.PUBLISHED_DATE), System.currentTimeMillis(), DateUtils.HOUR_IN_MILLIS, DateUtils.FORMAT_ABBREV_ALL) .toString() + " by " + mCursor.getString(ArticleLoader.Query.AUTHOR); articleByLine.setText(byLine); // Light up the embedded links in the body of the article bodyView.setMovementMethod(LinkMovementMethod.getInstance()); // bodyView.setTypeface(Typeface.createFromAsset(getResources().getAssets(), "Rosario-Regular.ttf")); bodyView.setText(Html.fromHtml(mCursor.getString(ArticleLoader.Query.BODY))); }