List of usage examples for android.text.format DateUtils MINUTE_IN_MILLIS
long MINUTE_IN_MILLIS
To view the source code for android.text.format DateUtils MINUTE_IN_MILLIS.
Click Source Link
From source file:com.roamprocess1.roaming4world.syncadapter.SyncAdapter.java
private void updateOfflineMissedCalls() { String from_summary = "", noc = "", from_detailed = "", lt = "", ct = ""; Cursor c;//from w ww. j ava2 s. c o m String time = "", value; try { dbContacts = new DBContacts(mcontext); // dbContacts.openToWrite(); dbContacts.openToRead(); c = dbContacts.fetch_details_from_MIssedCall_Offline_Table(); if (c.getCount() > 0) { c.moveToFirst(); value = c.getString(2); time = "&time=" + value; // time = "&time=" + "1408434902"; } c.close(); dbContacts.close(); Log.d("webService App Resume", "called"); HttpParams p = new BasicHttpParams(); p.setParameter("user", "1"); HttpClient httpclient = new DefaultHttpClient(p); String url = "http://ip.roaming4world.com/esstel/app_resume_info.php?contact=" + prefs.getString(stored_user_country_code, "NoValue") + prefs.getString(stored_user_mobile_no, "NoValue") + time; Log.d("url", url + " #"); HttpGet httpget = new HttpGet(url); ResponseHandler<String> responseHandler; String responseBody; responseHandler = new BasicResponseHandler(); responseBody = httpclient.execute(httpget, responseHandler); dbContacts.openToWrite(); JSONObject json = new JSONObject(responseBody); Log.d("response11", json + " #"); if (json.getString("verify_from_pc").equals("true")) { Intent i = new Intent(mcontext, DesktopVerificationcode_Activity.class); i.putExtra("verify_code", json.getString("verify_code")); i.putExtra("countdown_time", json.getString("countdown_time")); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mcontext.startActivity(i); } prefs.edit().putString(stored_min_call_credit, json.getString("min_call_credit")).commit(); prefs.edit().putString(stored_user_bal, json.getString("user_bal")).commit(); prefs.edit().putString(stored_server_ipaddress, json.getString("server_ip")).commit(); Log.d("stored_server_ip address", json.getString("server_ip") + " #"); Log.d("stored_user_bal", json.getString("user_bal") + " #"); if (json.getString("valid").equals("true")) { JSONArray summary = json.getJSONArray("summary"); JSONArray detailed = json.getJSONArray("detailed"); for (int i = 0; i < summary.length(); i++) { JSONObject summarydata = summary.getJSONObject(i); from_summary = summarydata.getString("from"); noc = summarydata.getString("noc"); lt = summarydata.getString("lt"); Log.d("from_summary", from_summary + " #"); Log.d("noc", noc + " #"); Log.d("lt", lt + " #"); dbContacts.insert_MIssedCall_Offline_detail_in_db(from_summary, lt, noc); /* mBuilder.setSmallIcon(R.drawable.notification_icon); mBuilder.setContentTitle("Missed call (" + noc +")"); mBuilder.setContentText(from_summary + " " + lt); mBuilder.setContentIntent(resultPendingIntent); mNotificationManager.notify(Integer.parseInt(lt), mBuilder.build()); */ String count = "Missed call (" + noc + ")"; CharSequence dateText = DateUtils.getRelativeTimeSpanString(Long.parseLong(lt) * 1000, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); String num_date = from_summary + " last on " + dateText.toString(); showNotification(count, num_date, Integer.parseInt(lt)); } for (int i = 0; i < detailed.length(); i++) { JSONObject detaileddata = detailed.getJSONObject(i); from_detailed = detaileddata.getString("from"); ct = detaileddata.getString("ct"); Log.d("from_detailed", from_detailed + " #"); Log.d("ct", ct + " #"); dbContacts.insert_MIssedCall_detail_in_db(from_detailed, ct); } dbContacts.close(); } } catch (Throwable t) { t.printStackTrace(); } }
From source file:com.androzic.vnspeech.MapFragment.java
private void onUpdateNavigationStatus() { if (!application.isNavigating()) return;//from w w w .j a v a 2s. co m if (!map.isFollowing()) map.refreshMap(); long now = System.currentTimeMillis(); double distance = application.navigationService.navDistance; double bearing = application.navigationService.navBearing; long turn = application.navigationService.navTurn; double vmg = application.navigationService.navVMG; int ete = application.navigationService.navETE; String[] dist = StringFormatter.distanceC(distance, StringFormatter.precisionFormat); String eteString = (ete == Integer.MAX_VALUE) ? getString(R.string.never) : (String) DateUtils.getRelativeTimeSpanString(now + (ete + 1) * 60000, now, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); String extra = StringFormatter.speedH(vmg) + " | " + eteString; String trnsym = ""; if (turn > 0) { trnsym = "R"; } else if (turn < 0) { trnsym = "L"; turn = -turn; } bearing = application.fixDeclination(bearing); distanceValue.setText(dist[0]); distanceUnit.setText(dist[1]); bearingValue.setText(StringFormatter.angleC(bearing)); turnValue.setText(StringFormatter.angleC(turn) + trnsym); waypointExtra.setText(extra); if (application.navigationService.isNavigatingViaRoute()) { View rootView = getView(); boolean hasNext = application.navigationService.hasNextRouteWaypoint(); if (distance < application.navigationService.navProximity * 3 && !animationSet) { AnimationSet animation = new AnimationSet(true); animation.addAnimation(new AlphaAnimation(1.0f, 0.3f)); animation.addAnimation(new AlphaAnimation(0.3f, 1.0f)); animation.setDuration(500); animation.setRepeatCount(10); rootView.findViewById(R.id.waypointinfo).startAnimation(animation); if (!hasNext) { rootView.findViewById(R.id.routeinfo).startAnimation(animation); } animationSet = true; } else if (animationSet) { rootView.findViewById(R.id.waypointinfo).setAnimation(null); if (!hasNext) { rootView.findViewById(R.id.routeinfo).setAnimation(null); } animationSet = false; } if (application.navigationService.navXTK == Double.NEGATIVE_INFINITY) { xtkValue.setText("--"); xtkUnit.setText("--"); } else { String xtksym = application.navigationService.navXTK == 0 ? "" : application.navigationService.navXTK > 0 ? "R" : "L"; String[] xtks = StringFormatter.distanceC(Math.abs(application.navigationService.navXTK)); xtkValue.setText(xtks[0] + xtksym); xtkUnit.setText(xtks[1]); } double navDistance = application.navigationService.navRouteDistanceLeft(); int eta = application.navigationService.navRouteETE(navDistance); if (eta < Integer.MAX_VALUE) eta += application.navigationService.navETE; String etaString = (eta == Integer.MAX_VALUE) ? getString(R.string.never) : (String) DateUtils.getRelativeTimeSpanString(now + (eta + 1) * 60000, now, DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); extra = StringFormatter.distanceH(navDistance + distance, 1000) + " | " + etaString; routeExtra.setText(extra); } }
From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java
/** * Measures the space needed for various parts of the view after * loading new events. This can change if there are all-day events. *//* w w w. j a v a 2 s.c om*/ private void remeasure(int width, int height) { // First, clear the array of earliest start times, and the array // indicating presence of an all-day event. for (int day = 0; day < mNumDays; day++) { mEarliestStartHour[day] = 25; // some big number mHasAllDayEvent[day] = false; } // The min is where 24 hours cover the entire visible area mMinCellHeight = Math.max((height - DAY_HEADER_HEIGHT) / 24, (int) MIN_EVENT_HEIGHT); if (mCellHeight < mMinCellHeight) { mCellHeight = mMinCellHeight; } // Calculate mAllDayHeight mFirstCell = DAY_HEADER_HEIGHT; mGridAreaHeight = height - mFirstCell; mNumHours = mGridAreaHeight / (mCellHeight + HOUR_GAP); mEventGeometry.setHourHeight(mCellHeight); final long minimumDurationMillis = (long) (MIN_EVENT_HEIGHT * DateUtils.MINUTE_IN_MILLIS / (mCellHeight / 60.0f)); Event.computePositions(mEvents, minimumDurationMillis); // Compute the top of our reachable view mMaxViewStartY = HOUR_GAP + 24 * (mCellHeight + HOUR_GAP) - mGridAreaHeight; if (mViewStartY > mMaxViewStartY) { mViewStartY = mMaxViewStartY; computeFirstHour(); } if (mFirstHour == -1) { initFirstHour(); mFirstHourOffset = 0; } // When we change the base date, the number of all-day events may // change and that changes the cell height. When we switch dates, // we use the mFirstHourOffset from the previous view, but that may // be too large for the new view if the cell height is smaller. if (mFirstHourOffset >= mCellHeight + HOUR_GAP) { mFirstHourOffset = mCellHeight + HOUR_GAP - 1; } mViewStartY = mFirstHour * (mCellHeight + HOUR_GAP) - mFirstHourOffset; }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
private String getSubTitle() { String dateStr = DateUtils.formatDateTime(this, mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_TIME); if (mWorkingNote.hasClockAlert()) { long time = System.currentTimeMillis(); String alertStr = ""; if (time > mWorkingNote.getAlertDate()) { alertStr = getString(R.string.note_alert_expired); } else {/* w w w .j a v a2 s. com*/ alertStr = (String) DateUtils.getRelativeTimeSpanString(mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS); } //emoji return dateStr + " | ???" + alertStr; } return dateStr; }
From source file:org.onebusaway.android.ui.ArrivalsListHeader.java
private void refreshError() { final long now = System.currentTimeMillis(); final long responseTime = mController.getLastGoodResponseTime(); AlertList alerts = mController.getAlertList(); mHasWarning = false;//w ww. jav a 2 s. c om mHasError = false; if (mResponseError != null) { alerts.remove(mResponseError); } if ((responseTime) != 0 && ((now - responseTime) >= 2 * DateUtils.MINUTE_IN_MILLIS)) { CharSequence relativeTime = DateUtils.getRelativeTimeSpanString(responseTime, now, DateUtils.MINUTE_IN_MILLIS, 0); CharSequence s = mContext.getString(R.string.stop_info_old_data, relativeTime); mResponseError = new ResponseError(s); alerts.insert(mResponseError, 0); } // If there is a warning or error alert, and show the alert icon in the header for (int i = 0; i < alerts.getCount(); i++) { AlertList.Alert a = alerts.getItem(i); if (a.getType() == AlertList.Alert.TYPE_WARNING) { mHasWarning = true; } if (a.getType() == AlertList.Alert.TYPE_ERROR) { mHasError = true; } } if (mHasError) { //UIHelp.showViewWithAnimation(mAlertView, mShortAnimationDuration); mAlertView.setVisibility(View.VISIBLE); mAlertView.setColorFilter(mResources.getColor(R.color.alert_icon_error)); mAlertView.setContentDescription(mResources.getString(R.string.alert_content_description_error)); } else if (mHasWarning) { //UIHelp.showViewWithAnimation(mAlertView, mShortAnimationDuration); mAlertView.setVisibility(View.VISIBLE); mAlertView.setColorFilter(mResources.getColor(R.color.alert_icon_warning)); mAlertView.setContentDescription(mResources.getString(R.string.alert_content_description_warning)); } else { // Don't show the header icon for info-level or no alerts //UIHelp.hideViewWithAnimation(mAlertView, mShortAnimationDuration); mAlertView.setVisibility(View.GONE); mAlertView.setContentDescription(""); } }
From source file:com.google.samples.apps.iosched.ui.SessionDetailFragment.java
private boolean isSessionLive() { long currentTimeMillis = UIUtils.getCurrentTime(getActivity()); long startEndDrift = DateUtils.MINUTE_IN_MILLIS * 10; long driftStart = mSessionStart - startEndDrift; long driftEnd = mSessionEnd - startEndDrift; return currentTimeMillis > driftStart && currentTimeMillis < driftEnd; }
From source file:com.android.calendar.AllInOneActivity.java
private void updateSecondaryTitleFields(long visibleMillisSinceEpoch) { mShowWeekNum = Utils.getShowWeekNumber(this); mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); if (visibleMillisSinceEpoch != -1) { int weekNum = Utils.getWeekNumberFromTime(visibleMillisSinceEpoch, this); mWeekNum = weekNum;// www .j ava 2s . c om } if (mShowWeekNum && (mCurrentView == ViewType.WEEK) && mIsTabletConfig && mWeekTextView != null) { String weekString = getResources().getQuantityString(R.plurals.weekN, mWeekNum, mWeekNum); mWeekTextView.setText(weekString); mWeekTextView.setVisibility(View.VISIBLE); } else if (visibleMillisSinceEpoch != -1 && mWeekTextView != null && mCurrentView == ViewType.DAY && mIsTabletConfig) { Time time = new Time(mTimeZone); time.set(visibleMillisSinceEpoch); int julianDay = Time.getJulianDay(visibleMillisSinceEpoch, time.gmtoff); time.setToNow(); int todayJulianDay = Time.getJulianDay(time.toMillis(false), time.gmtoff); String dayString = Utils.getDayOfWeekString(julianDay, todayJulianDay, visibleMillisSinceEpoch, this); mWeekTextView.setText(dayString); mWeekTextView.setVisibility(View.VISIBLE); } else if (mWeekTextView != null && (!mIsTabletConfig || mCurrentView != ViewType.DAY)) { mWeekTextView.setVisibility(View.GONE); } if (mHomeTime != null && (mCurrentView == ViewType.DAY || mCurrentView == ViewType.WEEK || mCurrentView == ViewType.AGENDA) && !TextUtils.equals(mTimeZone, Time.getCurrentTimezone())) { Time time = new Time(mTimeZone); time.setToNow(); long millis = time.toMillis(true); boolean isDST = time.isDst != 0; int flags = DateUtils.FORMAT_SHOW_TIME; if (DateFormat.is24HourFormat(this)) { flags |= DateUtils.FORMAT_24HOUR; } // Formats the time as String timeString = (new StringBuilder(Utils.formatDateRange(this, millis, millis, flags))).append(" ") .append(TimeZone.getTimeZone(mTimeZone).getDisplayName(isDST, TimeZone.SHORT, Locale.getDefault())) .toString(); mHomeTime.setText(timeString); mHomeTime.setVisibility(View.VISIBLE); // Update when the minute changes mHomeTime.removeCallbacks(mHomeTimeUpdater); mHomeTime.postDelayed(mHomeTimeUpdater, DateUtils.MINUTE_IN_MILLIS - (millis % DateUtils.MINUTE_IN_MILLIS)); } else if (mHomeTime != null) { mHomeTime.setVisibility(View.GONE); } }
From source file:com.vuze.android.remote.fragment.FilesFragment.java
@Override public void onExtraViewVisibilityChange(final View view, int visibility) { if (pullRefreshHandler != null) { pullRefreshHandler.removeCallbacksAndMessages(null); pullRefreshHandler = null;/*from w w w . j av a 2s . c o m*/ } if (visibility != View.VISIBLE) { return; } pullRefreshHandler = new Handler(Looper.getMainLooper()); pullRefreshHandler.postDelayed(new Runnable() { @Override public void run() { FragmentActivity activity = getActivity(); if (activity == null) { return; } long sinceMS = System.currentTimeMillis() - lastUpdated; String since = DateUtils.getRelativeDateTimeString(activity, lastUpdated, DateUtils.SECOND_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, 0).toString(); String s = activity.getResources().getString(R.string.last_updated, since); TextView tvSwipeText = (TextView) view.findViewById(R.id.swipe_text); tvSwipeText.setText(s); if (pullRefreshHandler != null) { pullRefreshHandler.postDelayed(this, sinceMS < DateUtils.MINUTE_IN_MILLIS ? DateUtils.SECOND_IN_MILLIS : sinceMS < DateUtils.HOUR_IN_MILLIS ? DateUtils.MINUTE_IN_MILLIS : DateUtils.HOUR_IN_MILLIS); } } }, 0); }
From source file:com.ludoscity.findmybikes.activities.NearbyActivity.java
private Runnable createUpdateRefreshRunnableCode() { return new Runnable() { private boolean mPagerReady = false; private NumberFormat mNumberFormat = NumberFormat.getInstance(); /*private final long startTime = System.currentTimeMillis(); private long lastRunTime;//from ww w . jav a 2 s .com private long lastUpdateTime = System.currentTimeMillis(); //Update should be run automatically ? */ @Override public void run() { long now = System.currentTimeMillis(); if (mRedrawMarkersTask == null && getListPagerAdapter().isViewPagerReady() && (!mPagerReady || mRefreshTabs)) { //When restoring, we don't need to setup everything from here if (!mStationMapFragment.isRestoring()) { //TODO figure out how to properly determine restoration setupTabPages(); if (isLookingForBike()) //onPageSelected is called by framework on B tab restoration onPageSelected(StationListPagerAdapter.BIKE_STATIONS); } mPagerReady = true; } //Update not already in progress if (mPagerReady && mDownloadWebTask == null && mRedrawMarkersTask == null && mFindNetworkTask == null) { long runnableLastRefreshTimestamp = DBHelper.getLastUpdateTimestamp(getApplicationContext()); long difference = now - runnableLastRefreshTimestamp; StringBuilder pastStringBuilder = new StringBuilder(); StringBuilder futureStringBuilder = new StringBuilder(); if (DBHelper.isBikeNetworkIdAvailable(getApplicationContext())) { //First taking care of past time... if (difference < DateUtils.MINUTE_IN_MILLIS) pastStringBuilder.append(getString(R.string.moments)); else pastStringBuilder.append(getString(R.string.il_y_a)) .append(mNumberFormat.format(difference / DateUtils.MINUTE_IN_MILLIS)) .append(" ").append(getString(R.string.min_abbreviated)); } //mStatusTextView.setText(Long.toString(difference / DateUtils.MINUTE_IN_MILLIS) +" "+ getString(R.string.minsAgo) + " " + getString(R.string.fromCitibik_es) ); //long differenceInMinutes = difference / DateUtils.MINUTE_IN_MILLIS; //from : http://stackoverflow.com/questions/25355611/how-to-get-time-difference-between-two-dates-in-android-app //long differenceInSeconds = difference / DateUtils.SECOND_IN_MILLIS; // formatted will be HH:MM:SS or MM:SS //String formatted = DateUtils.formatElapsedTime(differenceInSeconds); //... then about next update if (Utils.Connectivity.isConnected(getApplicationContext())) { getListPagerAdapter().setRefreshEnableAll(true); if (!mSearchFAB.isEnabled()) { mSearchFAB.show(); mSearchFAB.setEnabled(true); if (mOnboardingSnackBar != null && mOnboardingSnackBar.getView().getTag() != null) if (!checkOnboarding(eONBOARDING_LEVEL.ONBOARDING_LEVEL_FULL, eONBOARDING_STEP.ONBOARDING_STEP_SEARCH_SHOWCASE)) checkOnboarding(eONBOARDING_LEVEL.ONBOARDING_LEVEL_LIGHT, eONBOARDING_STEP.ONBOARDING_STEP_MAIN_CHOICE_HINT); mStatusBar.setBackgroundColor( ContextCompat.getColor(NearbyActivity.this, R.color.theme_primary_dark)); } if (DBHelper.isBikeNetworkIdAvailable(getApplicationContext())) { if (!DBHelper.getAutoUpdate(getApplicationContext())) { futureStringBuilder.append(getString(R.string.pull_to_refresh)); } else { //Should come from something keeping tabs on time, maybe this runnable itself long wishedUpdateTime = runnableLastRefreshTimestamp + NearbyActivity.this.getApplicationContext().getResources() .getInteger(R.integer.update_auto_interval_minute) * 1000 * 60; //comes from Prefs //Debug //long wishedUpdateTime = runnableLastRefreshTimestamp + 15 * 1000; //comes from Prefs if (now >= wishedUpdateTime) { mDownloadWebTask = new DownloadWebTask(); mDownloadWebTask.execute(); } else { futureStringBuilder.append(getString(R.string.nextUpdate)).append(" "); long differenceSecond = (wishedUpdateTime - now) / DateUtils.SECOND_IN_MILLIS; // formatted will be HH:MM:SS or MM:SS futureStringBuilder.append(DateUtils.formatElapsedTime(differenceSecond)); } } if (difference >= NearbyActivity.this.getApplicationContext().getResources() .getInteger(R.integer.outdated_data_time_minute) * 60 * 1000 && !mDataOutdated) { mDataOutdated = true; if (mDownloadWebTask == null) { //Auto update didn't kick in. If task cancels it will execute same code then mRefreshMarkers = true; refreshMap(); mStatusBar.setBackgroundColor( ContextCompat.getColor(NearbyActivity.this, R.color.theme_accent)); getListPagerAdapter().setOutdatedDataAll(true); } } } } else { futureStringBuilder.append(getString(R.string.no_connectivity)); getListPagerAdapter().setRefreshEnableAll(false); mSearchFAB.setEnabled(false); mSearchFAB.hide(); if (getListPagerAdapter() .getHighlightedStationForPage(StationListPagerAdapter.BIKE_STATIONS) != null && mOnboardingSnackBar != null && mOnboardingSnackBar.getView().getTag() != null && !((String) mOnboardingSnackBar.getView().getTag()) .equalsIgnoreCase("NO_CONNECTIVITY")) checkOnboarding(eONBOARDING_LEVEL.ONBOARDING_LEVEL_LIGHT, eONBOARDING_STEP.ONBOARDING_STEP_MAIN_CHOICE_HINT); mStatusBar.setBackgroundColor( ContextCompat.getColor(NearbyActivity.this, R.color.theme_accent)); } if (mDownloadWebTask == null) mStatusTextView.setText(String.format(getString(R.string.status_string), pastStringBuilder.toString(), futureStringBuilder.toString())); //pulling the trigger on auto select if (mDownloadWebTask == null && mRedrawMarkersTask == null && mFindNetworkTask == null && !mClosestBikeAutoSelected && getListPagerAdapter() .isRecyclerViewReadyForItemSelection(StationListPagerAdapter.BIKE_STATIONS) && mStationMapFragment.isMapReady()) { //Requesting raw string with availability String rawClosest = getListPagerAdapter().retrieveClosestRawIdAndAvailability(true); getListPagerAdapter().highlightStationforId(true, Utils.extractClosestAvailableStationIdFromProcessedString(rawClosest)); getListPagerAdapter().smoothScrollHighlightedInViewForPage( StationListPagerAdapter.BIKE_STATIONS, isAppBarExpanded()); final StationItem closestBikeStation = getListPagerAdapter() .getHighlightedStationForPage(StationListPagerAdapter.BIKE_STATIONS); mStationMapFragment.setPinOnStation(true, closestBikeStation.getId()); getListPagerAdapter().notifyStationAUpdate(closestBikeStation.getLocation(), mCurrentUserLatLng); hideSetupShowTripDetailsWidget(); getListPagerAdapter().setupBTabStationARecap(closestBikeStation, mDataOutdated); if (isLookingForBike()) { if (mTripDetailsWidget.getVisibility() == View.INVISIBLE) { mDirectionsLocToAFab.show(); } mAutoSelectBikeFab.hide(); mStationMapFragment.setMapPaddingRight(0); if (mStationMapFragment.getMarkerBVisibleLatLng() == null) { mStationListViewPager.setCurrentItem(StationListPagerAdapter.DOCK_STATIONS, true); mFavoritesSheetFab.showFab(); //if onboarding not happening... if (!checkOnboarding(eONBOARDING_LEVEL.ONBOARDING_LEVEL_FULL, eONBOARDING_STEP.ONBOARDING_STEP_SEARCH_SHOWCASE) && !checkOnboarding(eONBOARDING_LEVEL.ONBOARDING_LEVEL_LIGHT, eONBOARDING_STEP.ONBOARDING_STEP_MAIN_CHOICE_HINT)) { //...open favorites sheet final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (!mFavoritePickerFAB.isShowRunning()) { mFavoritesSheetFab.showSheet(); } else handler.postDelayed(this, 10); } }, 50); } } else { animateCameraToShowUserAndStation(closestBikeStation); } } //Bug on older API levels. Dismissing by hand fixes it. // First biggest bug happened here. Putting defensive code //TODO: investigate how state is maintained, Snackbar is destroyed by framework on screen orientation change //TODO: Refactor this spgathetti is **TOP** priosity //and probably long background state. if (mFindBikesSnackbar != null) { mFindBikesSnackbar.dismiss(); } Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { if (mDataOutdated) { mFindBikesSnackbar = Utils.Snackbar.makeStyled(mCoordinatorLayout, R.string.auto_bike_select_outdated, Snackbar.LENGTH_LONG, ContextCompat.getColor(NearbyActivity.this, R.color.theme_accent)); } else if (!closestBikeStation.isLocked() && closestBikeStation.getFree_bikes() > DBHelper .getCriticalAvailabilityMax(NearbyActivity.this)) { mFindBikesSnackbar = Utils.Snackbar.makeStyled(mCoordinatorLayout, R.string.auto_bike_select_found, Snackbar.LENGTH_LONG, ContextCompat.getColor(NearbyActivity.this, R.color.snackbar_green)); } else { mFindBikesSnackbar = Utils.Snackbar.makeStyled(mCoordinatorLayout, R.string.auto_bike_select_none, Snackbar.LENGTH_LONG, ContextCompat.getColor(NearbyActivity.this, R.color.theme_accent)); } if (mOnboardingSnackBar == null) mFindBikesSnackbar.show(); } }, 500); mClosestBikeAutoSelected = true; //launch twitter task if not already running, pass it the raw String if (Utils.Connectivity.isConnected(getApplicationContext()) && //data network available mUpdateTwitterTask == null && //not already tweeting rawClosest.length() > 32 + StationRecyclerViewAdapter.AOK_AVAILABILITY_POSTFIX.length() && //validate format - 32 is station ID length (rawClosest.contains(StationRecyclerViewAdapter.AOK_AVAILABILITY_POSTFIX) || rawClosest.contains(StationRecyclerViewAdapter.BAD_AVAILABILITY_POSTFIX)) && //validate content !mDataOutdated) { mUpdateTwitterTask = new UpdateTwitterStatusTask(); mUpdateTwitterTask.execute(rawClosest); } } //Checking if station is closest bike if (mDownloadWebTask == null && mRedrawMarkersTask == null && mFindNetworkTask == null && mStationMapFragment.isMapReady()) { if (!isStationAClosestBike()) { if (mStationMapFragment.getMarkerBVisibleLatLng() == null) { mClosestBikeAutoSelected = false; } else if (isLookingForBike() && !mClosestBikeAutoSelected) { mStationMapFragment.setMapPaddingRight( (int) getResources().getDimension(R.dimen.map_fab_padding)); mAutoSelectBikeFab.show(); animateCameraToShowUserAndStation(getListPagerAdapter() .getHighlightedStationForPage(StationListPagerAdapter.BIKE_STATIONS)); } } } } //UI will be refreshed every second int nextTimeMillis = 1000; if (!mPagerReady) //Except on init nextTimeMillis = 100; mUpdateRefreshHandler.postDelayed(mUpdateRefreshRunnableCode, nextTimeMillis); } }; }
From source file:com.tct.mail.browse.ConversationItemView.java
private String getElapseTime() { long time = mHeader.conversation.dateMs; long now = System.currentTimeMillis(); long elapseTime = now - time; String displayTime;/*ww w . j a va 2s .c o m*/ if (elapseTime < 0) { // abnormal time, this may occur when user change system time to a wrong time displayTime = (String) DateUtils.getRelativeTimeSpanString(mContext, time); } else if (elapseTime < DateUtils.MINUTE_IN_MILLIS) { // within one minute displayTime = mContext.getString(R.string.conversation_time_elapse_just_now); } else if (elapseTime < DateUtils.HOUR_IN_MILLIS) { //with in one hour int min = (int) (elapseTime / DateUtils.MINUTE_IN_MILLIS); displayTime = String.format(mContext.getString(R.string.conversation_time_elapse_minute), min); } else if (elapseTime < DateUtils.DAY_IN_MILLIS) { //within one day displayTime = (String) DateUtils.getRelativeTimeSpanString(mContext, time); } else { //beyond one day displayTime = (String) DateUtils.getRelativeTimeSpanString(mContext, time); } return displayTime; }