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:gov.wa.wsdot.android.wsdot.service.BorderWaitSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;/*from w w w. j a va2s .co m*/ long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "border_wait" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); try { URL url = new URL(BORDER_WAIT_URL); URLConnection urlConn = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("waittimes"); JSONArray items = result.getJSONArray("items"); List<ContentValues> times = new ArrayList<ContentValues>(); int numItems = items.length(); for (int j = 0; j < numItems; j++) { JSONObject item = items.getJSONObject(j); ContentValues timesValues = new ContentValues(); timesValues.put(BorderWait.BORDER_WAIT_ID, item.getInt("id")); timesValues.put(BorderWait.BORDER_WAIT_TITLE, item.getString("name")); timesValues.put(BorderWait.BORDER_WAIT_UPDATED, item.getString("updated")); timesValues.put(BorderWait.BORDER_WAIT_LANE, item.getString("lane")); timesValues.put(BorderWait.BORDER_WAIT_ROUTE, item.getInt("route")); timesValues.put(BorderWait.BORDER_WAIT_DIRECTION, item.getString("direction")); timesValues.put(BorderWait.BORDER_WAIT_TIME, item.getInt("wait")); if (starred.contains(item.getInt("id"))) { timesValues.put(BorderWait.BORDER_WAIT_IS_STARRED, 1); } times.add(timesValues); } // Purge existing border wait times covered by incoming data resolver.delete(BorderWait.CONTENT_URI, null, null); // Bulk insert all the new travel times resolver.bulkInsert(BorderWait.CONTENT_URI, times.toArray(new ContentValues[times.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "border_wait" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.BORDER_WAIT_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:gov.wa.wsdot.android.wsdot.service.TravelTimesSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;/*from www . j a v a 2s.c o m*/ long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "travel_times" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (5 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); try { URL url = new URL(TRAVEL_TIMES_URL); URLConnection urlConn = url.openConnection(); BufferedInputStream bis = new BufferedInputStream(urlConn.getInputStream()); GZIPInputStream gzin = new GZIPInputStream(bis); InputStreamReader is = new InputStreamReader(gzin); BufferedReader in = new BufferedReader(is); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("traveltimes"); JSONArray items = result.getJSONArray("items"); List<ContentValues> times = new ArrayList<ContentValues>(); int numItems = items.length(); for (int j = 0; j < numItems; j++) { JSONObject item = items.getJSONObject(j); ContentValues timesValues = new ContentValues(); timesValues.put(TravelTimes.TRAVEL_TIMES_TITLE, item.getString("title")); timesValues.put(TravelTimes.TRAVEL_TIMES_CURRENT, item.getInt("current")); timesValues.put(TravelTimes.TRAVEL_TIMES_AVERAGE, item.getInt("average")); timesValues.put(TravelTimes.TRAVEL_TIMES_DISTANCE, item.getString("distance") + " miles"); timesValues.put(TravelTimes.TRAVEL_TIMES_ID, Integer.parseInt(item.getString("routeid"))); timesValues.put(TravelTimes.TRAVEL_TIMES_UPDATED, item.getString("updated")); if (starred.contains(Integer.parseInt(item.getString("routeid")))) { timesValues.put(TravelTimes.TRAVEL_TIMES_IS_STARRED, 1); } times.add(timesValues); } // Purge existing travel times covered by incoming data resolver.delete(TravelTimes.CONTENT_URI, null, null); // Bulk insert all the new travel times resolver.bulkInsert(TravelTimes.CONTENT_URI, times.toArray(new ContentValues[times.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "travel_times" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.TRAVEL_TIMES_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:com.licenta.android.licenseapp.alarm.AlarmFragment.java
@Nullable @Override// w w w . ja va 2s. c o m public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_alarm, container, false); mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mAlarmFab = (FloatingActionButton) rootView.findViewById(R.id.alarm_fab); mAlarmFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { handleAlarm(); } }); setUpAlarmFab(); FloatingActionButton safeFab = (FloatingActionButton) rootView.findViewById(R.id.safe_fab); safeFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCountDownTimer.onFinish(); FacebookUtils.printKeyHash(getActivity()); } }); mTimerText = (TextView) rootView.findViewById(R.id.timer); final long futureTime = Long.parseLong(mPrefs.getString("repeat_interval", "0")); mCountDownTimer = new CountDownTimer(futureTime * DateUtils.MINUTE_IN_MILLIS, DateUtils.SECOND_IN_MILLIS) { public void onTick(long millisUntilFinished) { mTimerText.setText(new SimpleDateFormat("mm:ss").format(new Date(millisUntilFinished))); } public void onFinish() { mTimerText.setText(R.string.timer_default); } }; return rootView; }
From source file:com.actinarium.nagbox.ui.MainActivity.java
@Override public void onSetTaskStatus(Task task, boolean isActive) { if (task.isActive() == isActive) { // Status already set; do nothing return;// ww w . ja v a 2 s . co m } task.setIsActive(isActive); task.setIsSeen(true); if (isActive) { // Schedule next fire time task.lastStartedAt = System.currentTimeMillis(); task.nextFireAt = task.lastStartedAt + task.interval * DateUtils.MINUTE_IN_MILLIS; } NagboxService.updateTaskStatus(this, task); }
From source file:gov.wa.wsdot.android.wsdot.service.HighwayAlertsSyncService.java
@SuppressLint("SimpleDateFormat") @Override//from w ww . j a v a2 s .co m protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null; long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy h:mm a"); /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, projection, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "highway_alerts" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (5 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Tapping the refresh button will force a data refresh. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { try { URL url = new URL(HIGHWAY_ALERTS_URL); URLConnection urlConn = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String jsonFile = ""; String line; while ((line = in.readLine()) != null) { jsonFile += line; } in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("alerts"); JSONArray items = result.getJSONArray("items"); List<ContentValues> alerts = new ArrayList<ContentValues>(); int numItems = items.length(); for (int j = 0; j < numItems; j++) { JSONObject item = items.getJSONObject(j); JSONObject startRoadwayLocation = item.getJSONObject("StartRoadwayLocation"); ContentValues alertData = new ContentValues(); alertData.put(HighwayAlerts.HIGHWAY_ALERT_ID, item.getString("AlertID")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_HEADLINE, item.getString("HeadlineDescription")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_CATEGORY, item.getString("EventCategory")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_PRIORITY, item.getString("Priority")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_LATITUDE, startRoadwayLocation.getString("Latitude")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_LONGITUDE, startRoadwayLocation.getString("Longitude")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_ROAD_NAME, startRoadwayLocation.getString("RoadName")); alertData.put(HighwayAlerts.HIGHWAY_ALERT_LAST_UPDATED, dateFormat .format(new Date(Long.parseLong(item.getString("LastUpdatedTime").substring(6, 19))))); alerts.add(alertData); } // Purge existing highway alerts covered by incoming data resolver.delete(HighwayAlerts.CONTENT_URI, null, null); // Bulk insert all the new highway alerts resolver.bulkInsert(HighwayAlerts.CONTENT_URI, alerts.toArray(new ContentValues[alerts.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "highway_alerts" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.HIGHWAY_ALERTS_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesSchedulesSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;/* w ww. j a va2 s .co m*/ long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy h:mm a"); /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "ferries_schedules" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (30 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); try { URL url = new URL(FERRIES_SCHEDULES_URL); URLConnection urlConn = url.openConnection(); BufferedInputStream bis = new BufferedInputStream(urlConn.getInputStream()); GZIPInputStream gzin = new GZIPInputStream(bis); InputStreamReader is = new InputStreamReader(gzin); BufferedReader in = new BufferedReader(is); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONArray items = new JSONArray(jsonFile); List<ContentValues> schedules = new ArrayList<ContentValues>(); int numItems = items.length(); for (int i = 0; i < numItems; i++) { JSONObject item = items.getJSONObject(i); ContentValues schedule = new ContentValues(); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_ID, item.getInt("RouteID")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_TITLE, item.getString("Description")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_DATE, item.getString("Date")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_ALERT, item.getString("RouteAlert")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_UPDATED, dateFormat .format(new Date(Long.parseLong(item.getString("CacheDate").substring(6, 19))))); if (starred.contains(item.getInt("RouteID"))) { schedule.put(FerriesSchedules.FERRIES_SCHEDULE_IS_STARRED, 1); } schedules.add(schedule); } // Purge existing travel times covered by incoming data resolver.delete(FerriesSchedules.CONTENT_URI, null, null); // Bulk insert all the new travel times resolver.bulkInsert(FerriesSchedules.CONTENT_URI, schedules.toArray(new ContentValues[schedules.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "ferries_schedules" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.FERRIES_SCHEDULES_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:org.pixmob.droidlink.ui.EventCursorAdapter.java
@Override public void bindView(View v, Context context, Cursor cursor) { final int state = cursor.getInt(cursor.getColumnIndexOrThrow(STATE)); final String name = cursor.getString(cursor.getColumnIndexOrThrow(NAME)); String number = cursor.getString(cursor.getColumnIndexOrThrow(NUMBER)); final long date = cursor.getLong(cursor.getColumnIndexOrThrow(CREATED)); if (number != null) { number = PhoneNumberUtils.formatNumber(number); }//from w ww . j a v a 2 s .com final int type = cursor.getInt(cursor.getColumnIndexOrThrow(TYPE)); final Integer typeResourceId = EVENT_ICONS.get(type); final CharSequence eventDate = DateUtils.getRelativeTimeSpanString(date, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE); final String message = cursor.getString(cursor.getColumnIndexOrThrow(MESSAGE)); final String eventName; final String eventNumber; if (number == null) { eventName = context.getString(R.string.unknown_number); eventNumber = EMPTY; } else if (name == null) { eventName = number; eventNumber = EMPTY; } else { eventName = name; eventNumber = number; } TextView tv = (TextView) v.findViewById(R.id.event_name); tv.setText(eventName); tv = (TextView) v.findViewById(R.id.event_number); tv.setText(eventNumber); tv = (TextView) v.findViewById(R.id.event_date); tv.setText(eventDate); tv = (TextView) v.findViewById(R.id.event_message); tv.setText(message); ImageView iv = (ImageView) v.findViewById(R.id.event_icon); if (typeResourceId != null) { iv.setImageResource(typeResourceId); iv.setVisibility(View.VISIBLE); } else { iv.setVisibility(View.INVISIBLE); } iv = (ImageView) v.findViewById(R.id.event_state); if (state == EventsContract.PENDING_DELETE_STATE) { iv.setImageResource(R.drawable.pending_delete); iv.setVisibility(View.VISIBLE); } else if (state == EventsContract.PENDING_UPLOAD_STATE) { iv.setImageResource(R.drawable.pending_upload); iv.setVisibility(View.VISIBLE); } else { iv.setVisibility(View.GONE); } v.setTag(TAG_ID, cursor.getString(cursor.getColumnIndex(_ID))); }
From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java
@BindingAdapter("relativeDateTime") public static void setRelativeDateTime(TextView textView, long datetime) { textView.setText(DateUtils.getRelativeDateTimeString(textView.getContext(), datetime, DateUtils.MINUTE_IN_MILLIS, DateUtils.DAY_IN_MILLIS, 0)); }
From source file:com.battlelancer.seriesguide.util.ShareUtils.java
/** * Launches a calendar insert intent for the given episode. *//*from w ww. j a v a 2s . co m*/ public static void suggestCalendarEvent(Context context, String showTitle, String episodeTitle, long episodeReleaseTime, int showRunTime) { Intent intent = new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI) .putExtra(CalendarContract.Events.TITLE, showTitle) .putExtra(CalendarContract.Events.DESCRIPTION, episodeTitle); long beginTime = TimeTools.getEpisodeReleaseTime(context, episodeReleaseTime).getTime(); long endTime = beginTime + showRunTime * DateUtils.MINUTE_IN_MILLIS; intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime); intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime); if (!Utils.tryStartActivity(context, intent, false)) { Toast.makeText(context, context.getString(R.string.addtocalendar_failed), Toast.LENGTH_SHORT).show(); Utils.trackCustomEvent(context, TAG, "Calendar", "Failed"); } }
From source file:com.davidmiguel.gobees.hive.HiveInfoFragment.java
@Override public void showInfo(Hive hive) { // Last revision lastRevision.setText(DateUtils.getRelativeTimeSpanString(hive.getLastRevision().getTime(), (new Date()).getTime(), DateUtils.MINUTE_IN_MILLIS)); // Notes/* w w w .j a v a 2 s. com*/ if (Strings.isNullOrEmpty(hive.getNotes())) { notes.setText(getString(R.string.no_notes)); } else { notes.setText(hive.getNotes()); } }