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.matthewmitchell.peercoin_android_wallet.ui.WalletBalanceFragment.java
private void updateView() { if (!isAdded()) return;//w w w . j ava2s .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;/* www . 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) { 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.github.gorbin.asne.linkedin.LinkedInSocialNetwork.java
/** * Check is social network connected/* ww w .j a va 2 s .co m*/ * @return true if connected to LinkedIn social network and false if not */ @Override public boolean isConnected() { String accessToken = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_TOKEN, null); String requestToken = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_REQUEST_TOKEN, null); long expiresDate = mSharedPreferences.getLong(SAVE_STATE_KEY_EXPIRES_DATE, 0); boolean notExpired = expiresDate > 0 && Calendar.getInstance().getTimeInMillis() - DateUtils.DAY_IN_MILLIS < expiresDate; return accessToken != null && requestToken != null && notExpired; }
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;/*from w w w . ja v a 2s.co 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( 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 w w . j a v a 2 s .com*/ 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;//w ww . j a v a 2 s. 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:com.xandy.calendar.event.CreateEventDialogFragment.java
private void createAllDayEvent() { mModel.mStart = mDateInMillis;/*from w w w .j av a 2 s . com*/ mModel.mEnd = mDateInMillis + DateUtils.DAY_IN_MILLIS; mModel.mTitle = mEventTitle.getText().toString(); mModel.mAllDay = true; mModel.mCalendarId = mCalendarId; mModel.mOwnerAccount = mCalendarOwner; if (mEditEventHelper.saveEvent(mModel, null, 0)) { Toast.makeText(getActivity(), R.string.creating_event, Toast.LENGTH_SHORT).show(); } }
From source file:org.voidsink.anewjkuapp.fragment.CalendarFragment.java
private void loadMoreData() { if (this.isVisible() && !getLoaderManager().hasRunningLoaders()) { now = System.currentTimeMillis(); // if someone changed the time since last click // increase in month steps Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(then);// ww w. j a v a 2 s . c o m then += cal.getActualMaximum(Calendar.DAY_OF_MONTH) * DateUtils.DAY_IN_MILLIS; // set button text setButtonLoadText(); Analytics.eventLoadMoreEvents(getContext(), then - now); loadData(); } }
From source file:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java
@Override public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/* w w w . ja v a2 s .c om*/ Context context = getContext(); App.getApiManager().getEarthquakeService().getData().enqueue(new Callback<EarthquakeObject>() { @Override public void onResponse(Call<EarthquakeObject> call, Response<EarthquakeObject> response) { EarthquakeObject earthquake = response.body(); Vector<ContentValues> cVVector = new Vector<>(earthquake.getFeatures().size()); double currentBiggest = 0.0; ContentValues notifyValues = null; for (Feature each : earthquake.getFeatures()) { ContentValues earthquakeValues = new ContentValues(); earthquakeValues.put(EarthquakeColumns.PLACE, each.getProperties().getPlace()); earthquakeValues.put(EarthquakeColumns.ID_EARTH, each.getId()); earthquakeValues.put(EarthquakeColumns.MAG, each.getProperties().getMag()); earthquakeValues.put(EarthquakeColumns.TYPE, each.getProperties().getType()); earthquakeValues.put(EarthquakeColumns.ALERT, each.getProperties().getAlert()); earthquakeValues.put(EarthquakeColumns.TIME, each.getProperties().getTime()); earthquakeValues.put(EarthquakeColumns.URL, each.getProperties().getUrl()); earthquakeValues.put(EarthquakeColumns.DETAIL, each.getProperties().getDetail()); earthquakeValues.put(EarthquakeColumns.DEPTH, each.getGeometry().getCoordinates().get(2)); earthquakeValues.put(EarthquakeColumns.LONGITUDE, each.getGeometry().getCoordinates().get(0)); earthquakeValues.put(EarthquakeColumns.LATITUDE, each.getGeometry().getCoordinates().get(1)); LatLng latLng = new LatLng(each.getGeometry().getCoordinates().get(1), each.getGeometry().getCoordinates().get(0)); LatLng location = LocationUtils.getLocation(context); earthquakeValues.put(EarthquakeColumns.DISTANCE, LocationUtils.getDistance(latLng, location)); cVVector.add(earthquakeValues); if (each.getProperties().getMag() != null && each.getProperties().getMag() > currentBiggest) { currentBiggest = each.getProperties().getMag(); notifyValues = new ContentValues(earthquakeValues); notifyValues.put(EarthquakeColumns.PLACE, Utilities.formatEarthquakePlace(each.getProperties().getPlace())); } } int inserted = 0; // add to database ContentResolver resolver = context.getContentResolver(); if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = resolver.bulkInsert(EarthquakeColumns.CONTENT_URI, cvArray); } // Set the date to day minus one to delete old data from the database Date date = new Date(); date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS); int deleted = resolver.delete(EarthquakeColumns.CONTENT_URI, EarthquakeColumns.TIME + " <= ?", new String[] { String.valueOf(date.getTime()) }); Log.v(TAG, "Service Complete. " + inserted + " Inserted, " + deleted + " deleted"); sendNotification(notifyValues); } @Override public void onFailure(Call<EarthquakeObject> call, Throwable t) { Log.e(TAG, "onFailure: " + t.toString()); } }); App.getNewsManager().getNewsService().getNews().enqueue(new Callback<Rss>() { @Override public void onResponse(Call<Rss> call, Response<Rss> response) { Channel news = response.body().getChannel(); Vector<ContentValues> cVVector = new Vector<>(news.getItem().size()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.getDefault()); Date date = new Date(); for (Item each : news.getItem()) { ContentValues weatherValues = new ContentValues(); try { date = simpleDateFormat.parse(each.getPubDate()); } catch (ParseException e) { Log.e(TAG, "e:" + e); } weatherValues.put(NewsColumns.DATE, date.getTime()); weatherValues.put(NewsColumns.TITLE, each.getTitle()); weatherValues.put(NewsColumns.DESCRIPTION, Html.toHtml(new SpannedString(each.getDescription()))); weatherValues.put(NewsColumns.URL, each.getLink()); weatherValues.put(NewsColumns.GUID, each.getGuid().getContent()); cVVector.add(weatherValues); } int inserted = 0; // add to database ContentResolver resolver = getContext().getContentResolver(); if (cVVector.size() > 0) { // Student: call bulkInsert to add the weatherEntries to the database here ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = resolver.bulkInsert(NewsColumns.CONTENT_URI, cvArray); } // Set the date to day minus two to delete old data from the database date = new Date(); date.setTime(date.getTime() - DateUtils.DAY_IN_MILLIS * 3); int deleted = resolver.delete(NewsColumns.CONTENT_URI, NewsColumns.DATE + " <= ?", new String[] { String.valueOf(date.getTime()) }); } @Override public void onFailure(Call<Rss> call, Throwable t) { Log.e(TAG, "onFailure: " + t.toString()); } }); // TODO: 4/22/16 possible refactoring //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String lastNotificationKey = context.getString(R.string.sharedprefs_key_last_countupdate); long lastSync = prefs.getLong(lastNotificationKey, DateUtils.DAY_IN_MILLIS); if (System.currentTimeMillis() - lastSync >= Utilities.getSyncIntervalPrefs(context) * DateUtils.SECOND_IN_MILLIS) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.US); Date date = new Date(System.currentTimeMillis()); String startTime[] = new String[] { simpleDateFormat.format(date.getTime() - DateUtils.YEAR_IN_MILLIS), simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS * 30), simpleDateFormat.format(date.getTime() - DateUtils.WEEK_IN_MILLIS), simpleDateFormat.format(date.getTime() - DateUtils.DAY_IN_MILLIS) }; String endTime = simpleDateFormat.format(date); int iterator = 1; while (iterator < CountColumns.ALL_COLUMNS.length) { final int round = iterator; App.getApiManager().getEarthquakeService().getEarthquakeStats(startTime[round - 1], endTime) .enqueue(new Callback<CountEarthquakes>() { @Override public void onResponse(Call<CountEarthquakes> call, Response<CountEarthquakes> response) { ContentValues count = new ContentValues(); count.put(CountColumns.ALL_COLUMNS[round], response.body().getCount()); ContentResolver contentResolver = context.getContentResolver(); Cursor cursor = contentResolver.query(CountColumns.CONTENT_URI, null, null, null, null); if (cursor != null) { if (cursor.getCount() < 1) { long inserted = ContentUris .parseId(contentResolver.insert(CountColumns.CONTENT_URI, count)); //Log.d(TAG, "inserted:" + inserted); } else { int updated = contentResolver.update(CountColumns.CONTENT_URI, count, CountColumns._ID + " = ?", new String[] { "1" }); //Log.d(TAG, "updated: " + updated); } cursor.close(); } } @Override public void onFailure(Call<CountEarthquakes> call, Throwable t) { Log.e(TAG, "Error: " + t); } }); iterator++; } //refreshing last sync prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).apply(); } // notify PagerActivity that data has been updated context.getContentResolver().notifyChange(EarthquakeColumns.CONTENT_URI, null, false); context.getContentResolver().notifyChange(NewsColumns.CONTENT_URI, null, false); context.getContentResolver().notifyChange(CountColumns.CONTENT_URI, null, false); updateWidgets(); }
From source file:com.infine.android.devoxx.ui.ScheduleFragment.java
private void setupDay(LayoutInflater inflater, long startMillis) { Day day = new Day(); // Setup data day.index = mDays.size();/*from www . ja va 2s . co m*/ day.timeStart = startMillis; day.timeEnd = startMillis + DateUtils.DAY_IN_MILLIS; day.blocksUri = ScheduleContract.Blocks.buildBlocksBetweenDirUri(day.timeStart, day.timeEnd); // Setup views day.rootView = (ViewGroup) inflater.inflate(R.layout.blocks_content, null); day.scrollView = (ObservableScrollView) day.rootView.findViewById(R.id.blocks_scroll); day.scrollView.setOnScrollListener(this); day.blocksView = (BlocksLayout) day.rootView.findViewById(R.id.blocks); day.nowView = day.rootView.findViewById(R.id.blocks_now); // day.blocksView.setDrawingCacheEnabled(true); // day.blocksView.setAlwaysDrawnWithCacheEnabled(true); TimeZone.setDefault(UIUtils.CONFERENCE_TIME_ZONE); day.label = DateUtils.formatDateTime(getActivity(), startMillis, TIME_FLAGS); mWorkspace.addView(day.rootView); mDays.add(day); }