List of usage examples for android.text.format DateUtils DAY_IN_MILLIS
long DAY_IN_MILLIS
To view the source code for android.text.format DateUtils DAY_IN_MILLIS.
Click Source Link
From source file:com.android.calendar.alerts.AlarmScheduler.java
/** * Queries events starting within a fixed interval from now. *//* ww w . j ava 2s . c o m*/ private static Cursor queryUpcomingEvents(Context context, ContentResolver contentResolver, long currentMillis) { Time time = new Time(); time.normalize(false); long localOffset = time.gmtoff * 1000; final long localStartMin = currentMillis; final long localStartMax = localStartMin + EVENT_LOOKAHEAD_WINDOW_MS; final long utcStartMin = localStartMin - localOffset; final long utcStartMax = utcStartMin + EVENT_LOOKAHEAD_WINDOW_MS; if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) { //If permission is not granted then just return. Log.d(TAG, "Manifest.permission.READ_CALENDAR is not granted"); return null; } // Expand Instances table range by a day on either end to account for // all-day events. Uri.Builder uriBuilder = Instances.CONTENT_URI.buildUpon(); ContentUris.appendId(uriBuilder, localStartMin - DateUtils.DAY_IN_MILLIS); ContentUris.appendId(uriBuilder, localStartMax + DateUtils.DAY_IN_MILLIS); // Build query for all events starting within the fixed interval. StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append("("); queryBuilder.append(INSTANCES_WHERE); queryBuilder.append(") OR ("); queryBuilder.append(INSTANCES_WHERE); queryBuilder.append(")"); String[] queryArgs = new String[] { // allday selection "1", /* visible = ? */ String.valueOf(utcStartMin), /* begin >= ? */ String.valueOf(utcStartMax), /* begin <= ? */ "1", /* allDay = ? */ // non-allday selection "1", /* visible = ? */ String.valueOf(localStartMin), /* begin >= ? */ String.valueOf(localStartMax), /* begin <= ? */ "0" /* allDay = ? */ }; Cursor cursor = contentResolver.query(uriBuilder.build(), INSTANCES_PROJECTION, queryBuilder.toString(), queryArgs, null); return cursor; }
From source file:ro.expectations.expenses.ui.transactions.TransactionsAdapter.java
@Override public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position);//from w ww . j av a2 s . c om long fromAccountId = mCursor.getLong(TransactionsFragment.COLUMN_FROM_ACCOUNT_ID); long toAccountId = mCursor.getLong(TransactionsFragment.COLUMN_TO_ACCOUNT_ID); if (fromAccountId > 0 && toAccountId > 0) { processTransfer(holder, position); } else { if (fromAccountId > 0) { processDebit(holder, position); } else { processCredit(holder, position); } } // Set the row background ListHelper.setItemBackground(mContext, holder.itemView, isItemSelected(position), holder.mTransactionIconBackground, holder.mSelectedIconBackground); // Set the description StringBuilder description = new StringBuilder(); long categoryId = mCursor.getLong(TransactionsFragment.COLUMN_CATEGORY_ID); if (categoryId == -1) { description.append(mContext.getString(R.string.multiple_categories)); } else { String category = mCursor.getString(TransactionsFragment.COLUMN_CATEGORY_NAME); if (category != null && !category.isEmpty()) { description.append(category); } } String parentCategory = mCursor.getString(TransactionsFragment.COLUMN_PARENT_CATEGORY_NAME); if (parentCategory != null && !parentCategory.isEmpty()) { description.insert(0, " "); description.insert(0, parentCategory); } StringBuilder additionalDescription = new StringBuilder(); String payeeName = mCursor.getString(TransactionsFragment.COLUMN_PAYEE_NAME); if (payeeName != null && !payeeName.isEmpty()) { additionalDescription.append(payeeName); } String note = mCursor.getString(TransactionsFragment.COLUMN_NOTE); if (note != null && !note.isEmpty()) { if (additionalDescription.length() > 0) { additionalDescription.append(": "); } additionalDescription.append(note); } if (description.length() > 0 && additionalDescription.length() > 0) { additionalDescription.insert(0, " ("); additionalDescription.append(")"); } if (additionalDescription.length() > 0) { description.append(additionalDescription.toString()); } if (description.length() == 0) { if (fromAccountId > 0 && toAccountId > 0) { description.append(mContext.getString(R.string.default_transfer_description)); } else { long fromAmount = mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT); if (fromAmount > 0) { description.append(mContext.getString(R.string.default_debit_description)); } else { description.append(mContext.getString(R.string.default_credit_description)); } } } holder.mDescription.setText(description.toString()); // Set the transaction date long transactionDate = mCursor.getLong(TransactionsFragment.COLUMN_OCCURED_AT); if (transactionDate == 0) { transactionDate = mCursor.getLong(TransactionsFragment.COLUMN_CREATED_AT); } holder.mDate.setText(DateUtils.getRelativeTimeSpanString(transactionDate, System.currentTimeMillis(), DateUtils.DAY_IN_MILLIS)); // Set the icon if (fromAccountId > 0 && toAccountId > 0) { holder.mTransactionIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_transfer_black_24dp, R.color.colorWhite)); } else { holder.mTransactionIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_question_mark_black_24dp, R.color.colorWhite)); } GradientDrawable bgShape = (GradientDrawable) holder.mTransactionIconBackground.getBackground(); bgShape.setColor(0xFF000000 | ContextCompat.getColor(mContext, R.color.colorPrimary)); }
From source file:com.bushstar.htmlcoin_android_wallet.ui.WalletBalanceFragment.java
private void updateView() { if (!isAdded()) return;//from www .jav 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 (!showLocalBalance) viewBalanceLocalFrame.setVisibility(View.GONE); if (balance != null) { viewBalanceHTML5.setVisibility(View.VISIBLE); viewBalanceHTML5.setPrecision(config.getHTML5Precision(), config.getHTML5Shift()); viewBalanceHTML5.setPrefix(config.getHTML5Prefix()); viewBalanceHTML5.setAmount(balance); if (showLocalBalance) { viewBalanceLocalFrame.setVisibility(View.INVISIBLE); } } else { viewBalanceHTML5.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } }
From source file:cc.mintcoin.wallet.ui.WalletBalanceFragment.java
private void updateView() { if (!isAdded()) return;//from w ww . ja v a2s . 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) { viewBalanceBtc.setVisibility(View.VISIBLE); viewBalanceBtc.setPrecision(config.getBtcPrecision(), config.getBtcShift()); viewBalanceBtc.setPrefix(config.getBtcPrefix()); 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.feathercoin.wallet.feathercoin.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 www . 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(showDisclaimer || showProgress || showReplaying ? View.VISIBLE : View.GONE); }
From source file:com.rimbit.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) { viewBalanceRBT.setVisibility(View.VISIBLE); viewBalanceRBT.setPrecision(config.getRBTPrecision(), config.getRBTShift()); viewBalanceRBT.setPrefix(config.getRBTPrefix()); viewBalanceRBT.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 { viewBalanceRBT.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } }
From source file:com.hamradiocoin.wallet.ui.WalletBalanceFragment.java
private void updateView() { if (!isAdded()) return;/* ww w. j av a 2 s . co m*/ final boolean showProgress; if (bestChainDate != null) { final long blockchainLag = System.currentTimeMillis() - bestChainDate.getTime(); final boolean blockchainUptodate = blockchainLag < 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(config.getBtcPrecision(), config.getBtcShift()); viewBalanceBtc.setPrefix(config.getBtcPrefix()); 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());//from w ww .j a va2s .com 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.matthewmitchell.nubits_android_wallet.ui.WalletBalanceFragment.java
private void updateView() { if (!isAdded()) return;// w w w .j av a 2 s . com 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) { viewBalanceNBT.setVisibility(View.VISIBLE); viewBalanceNBT.setPrecision(config.getNBTPrecision(), config.getNBTShift()); viewBalanceNBT.setPrefix(config.getNBTPrefix()); viewBalanceNBT.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 { viewBalanceNBT.setVisibility(View.INVISIBLE); } viewProgress.setVisibility(View.GONE); } else { viewProgress.setVisibility(View.VISIBLE); viewBalance.setVisibility(View.INVISIBLE); } }
From source file:de.schildbach.litecoinwallet.ui.WalletBalanceFragment.java
private void updateView() { if (!isAdded()) return;/*from ww w. j av 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); } }