List of usage examples for android.text.format Time format
public String format(String format)
From source file:org.cinedroid.tasks.impl.RetrievePerformancesTask.java
/** * Removes any times which have passed from the list * /*from ww w . j a va 2s. c o m*/ * @param results */ private void filterPastDates(final FilmDate filmDate) { Time currentTime = new Time(); currentTime.setToNow(); Time performanceDate = new Time(); String date = filmDate.getDate(); performanceDate.parse(date); // Check if the performance date is before the current time. This will only be true in the situation that the filmDate represents // the current day, as the cineworld api does not return dates which have passed. If the object is the current date, the film // performances need filtering. if (currentTime.after(performanceDate)) { for (Iterator<FilmPerformance> i = filmDate.getPerformances().iterator(); i.hasNext();) { String time = i.next().getTime().replace(":", ""); // Get the time with the : removed. performanceDate.parse(String.format("%sT%s00", date, time)); Log.d(TAG, String.format("Checking %s", performanceDate.format("%d %b %H:%M"))); if (currentTime.after(performanceDate)) { Log.d(TAG, String.format("Removed %s", performanceDate.format("%d %b %H:%M"))); i.remove(); } } } Log.d(TAG, String.format("Current Time %s", currentTime.toString())); }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Sends SMS Alarms to the telephone numbers specified in mSMSNumbers[] *//*from w w w . j ava 2s . c o m*/ public void sendSMSAlarm() { if (mSMSAlarm) { Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers.length + " Numbers"); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%Y-%m-%d %H-%M-%S"); SmsManager sm = SmsManager.getDefault(); for (int i = 0; i < mSMSNumbers.length; i++) { Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers[i]); sm.sendTextMessage(mSMSNumbers[i], null, mSMSMsgStr + " - " + dateStr, null, null); } } else { Log.v(TAG, "sendSMSAlarm() - SMS Alarms Disabled - not doing anything!"); Toast toast = Toast.makeText(getApplicationContext(), "SMS Alarms Disabled - not doing anything!", Toast.LENGTH_SHORT); toast.show(); } }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Write data to SD card - writes to data log file unless alarm=true, * in which case writes to alarm log file. *///from w w w . jav a 2 s . c om public void writeToSD(boolean alarm) { Log.v(TAG, "writeToSD(" + alarm + ")"); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%Y-%m-%d"); // Select filename depending on 'alarm' parameter. String fname; if (alarm) fname = "AlarmLog"; else fname = "DataLog"; fname = fname + "_" + dateStr + ".txt"; // Open output directory on SD Card. if (isExternalStorageWritable()) { try { FileWriter of = new FileWriter(getDataStorageDir().toString() + "/" + fname, true); if (sdData != null) { Log.v(TAG, "writing sdData.toString()"); of.append(sdData.toString() + "\n"); } of.close(); } catch (Exception ex) { Log.e(TAG, "writeAlarmToSD - error " + ex.toString()); } } else { Log.e(TAG, "ERROR - Can not Write to External Folder"); } }
From source file:com.android.calendar.alerts.AlarmScheduler.java
/** * Queries for all the reminders of the events in the instancesCursor, and schedules * the alarm for the next upcoming reminder. */// w ww .j a v a 2s . c om private static void queryNextReminderAndSchedule(Cursor instancesCursor, Context context, ContentResolver contentResolver, AlarmManagerInterface alarmManager, int batchSize, long currentMillis) { if (AlertService.DEBUG) { int eventCount = instancesCursor.getCount(); if (eventCount == 0) { Log.d(TAG, "No events found starting within 1 week."); } else { Log.d(TAG, "Query result count for events starting within 1 week: " + eventCount); } } // Put query results of all events starting within some interval into map of event ID to // local start time. Map<Integer, List<Long>> eventMap = new HashMap<Integer, List<Long>>(); Time timeObj = new Time(); long nextAlarmTime = Long.MAX_VALUE; int nextAlarmEventId = 0; instancesCursor.moveToPosition(-1); while (!instancesCursor.isAfterLast()) { int index = 0; eventMap.clear(); StringBuilder eventIdsForQuery = new StringBuilder(); eventIdsForQuery.append('('); while (index++ < batchSize && instancesCursor.moveToNext()) { int eventId = instancesCursor.getInt(INSTANCES_INDEX_EVENTID); long begin = instancesCursor.getLong(INSTANCES_INDEX_BEGIN); boolean allday = instancesCursor.getInt(INSTANCES_INDEX_ALL_DAY) != 0; long localStartTime; if (allday) { // Adjust allday to local time. localStartTime = Utils.convertAlldayUtcToLocal(timeObj, begin, Time.getCurrentTimezone()); } else { localStartTime = begin; } List<Long> startTimes = eventMap.get(eventId); if (startTimes == null) { startTimes = new ArrayList<Long>(); eventMap.put(eventId, startTimes); eventIdsForQuery.append(eventId); eventIdsForQuery.append(","); } startTimes.add(localStartTime); // Log for debugging. if (Log.isLoggable(TAG, Log.DEBUG)) { timeObj.set(localStartTime); StringBuilder msg = new StringBuilder(); msg.append("Events cursor result -- eventId:").append(eventId); msg.append(", allDay:").append(allday); msg.append(", start:").append(localStartTime); msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")"); Log.d(TAG, msg.toString()); } } if (eventIdsForQuery.charAt(eventIdsForQuery.length() - 1) == ',') { eventIdsForQuery.deleteCharAt(eventIdsForQuery.length() - 1); } eventIdsForQuery.append(')'); // Query the reminders table for the events found. Cursor cursor = null; try { cursor = contentResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION, REMINDERS_WHERE + eventIdsForQuery, null, null); // Process the reminders query results to find the next reminder time. cursor.moveToPosition(-1); while (cursor.moveToNext()) { int eventId = cursor.getInt(REMINDERS_INDEX_EVENT_ID); int reminderMinutes = cursor.getInt(REMINDERS_INDEX_MINUTES); List<Long> startTimes = eventMap.get(eventId); if (startTimes != null) { for (Long startTime : startTimes) { long alarmTime = startTime - reminderMinutes * DateUtils.MINUTE_IN_MILLIS; if (alarmTime > currentMillis && alarmTime < nextAlarmTime) { nextAlarmTime = alarmTime; nextAlarmEventId = eventId; } if (Log.isLoggable(TAG, Log.DEBUG)) { timeObj.set(alarmTime); StringBuilder msg = new StringBuilder(); msg.append("Reminders cursor result -- eventId:").append(eventId); msg.append(", startTime:").append(startTime); msg.append(", minutes:").append(reminderMinutes); msg.append(", alarmTime:").append(alarmTime); msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")"); Log.d(TAG, msg.toString()); } } } } } finally { if (cursor != null) { cursor.close(); } } } // Schedule the alarm for the next reminder time. if (nextAlarmTime < Long.MAX_VALUE) { scheduleAlarm(context, nextAlarmEventId, nextAlarmTime, currentMillis, alarmManager); } }
From source file:com.jogden.spunkycharts.traditionalchart.TraditionalChartFragmentAdapter.java
private void _putTime(Time t) throws InterruptedException { if (_lastPutTime == null) { /* if first, ignore everything else */ _lastPutTime = new Time(); } else { /* otherwise fill in the gaps */ long oldTime = _lastPutTime.toMillis(true); long newTime = t.toMillis(true); /* round to avoid getting screwed over a few ms */ int minDiff = Math.round((float) (newTime - oldTime) / (float) (_chartFreq.value * 60000)); Log.d("DataContentService-1", "Old Time: " + _lastPutTime.format("%H:%M:%S") + " , New Time: " + t.format("%H:%M:%S")); while (minDiff > _chartFreq.value) { _lastPutTime.minute += _chartFreq.value; /* the following 'handles' a unique sync issue where the cursor is loaded, * a new granular seg is inserted into the database AND THEN a new * full seg is 'put' into the queues leading to the new full seg being skipped. * 1) this happens around the minute mark (when segs roll) * 2) we could (and may) simply re-load the cursor * 3) not sure how this works with full segs > 1 min *//* w ww.j a v a 2s . c o m*/ if (_chartFreq.value == DataClientInterface.TIME_GRANULARITY && minDiff == (2 * _chartFreq.value)) { _ohlcQueue.put(new OHLC(_penultGranularPriceSeg)); _volumeQueue.put(_penultGranularVolSeg); } else { _ohlcQueue.put(new OHLC(_lastPriceSeg.open)); _volumeQueue.put(0); } _timeStampQueue.put(_lastPutTime.format("%H:%M")); minDiff -= _chartFreq.value; } } _timeStampQueue.put(t.format("%H:%M")); _lastPutTime.set(t); }