List of usage examples for android.text.format Time toMillis
public long toMillis(boolean ignoreDst)
From source file:com.android.bluetooth.map.BluetoothMapContent.java
private String setWhereFilterPeriod(BluetoothMapAppParams ap, FilterInfo fi) { String where = ""; if ((ap.getFilterPeriodBegin() != -1)) { if (fi.msgType == FilterInfo.TYPE_SMS) { where = " AND date >= " + ap.getFilterPeriodBegin(); } else if (fi.msgType == FilterInfo.TYPE_MMS) { where = " AND date >= " + (ap.getFilterPeriodBegin() / 1000L); } else {/* w w w . j av a2 s.co m*/ Time time = new Time(); try { time.parse(ap.getFilterPeriodBeginString().trim()); where += " AND timeStamp >= " + time.toMillis(false); } catch (TimeFormatException e) { Log.d(TAG, "Bad formatted FilterPeriodBegin, Ignore" + ap.getFilterPeriodBeginString()); } } } if ((ap.getFilterPeriodEnd() != -1)) { if (fi.msgType == FilterInfo.TYPE_SMS) { where += " AND date <= " + ap.getFilterPeriodEnd(); } else if (fi.msgType == FilterInfo.TYPE_MMS) { where += " AND date <= " + (ap.getFilterPeriodEnd() / 1000L); } else { Time time = new Time(); try { time.parse(ap.getFilterPeriodEndString().trim()); where += " AND timeStamp <= " + time.toMillis(false); } catch (TimeFormatException e) { Log.d(TAG, "Bad formatted FilterPeriodEnd, Ignore" + ap.getFilterPeriodEndString()); } } } return where; }
From source file:com.android.mms.ui.MessageUtils.java
public static String formatTimeStampStringExtend(Context context, long when) { Time then = new Time(); then.set(when);//from ww w. ja v a 2 s . c o m Time now = new Time(); now.setToNow(); // Basic settings for formatDateTime() we want for all cases. int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM; // If the message is from a different year, show the date and year. if (then.year != now.year) { format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { // If it is from a different day than today, show only the date. if ((now.yearDay - then.yearDay) == 1) { return context.getString(R.string.str_ipmsg_yesterday); } else { format_flags |= DateUtils.FORMAT_SHOW_DATE; } } else if ((now.toMillis(false) - then.toMillis(false)) < 60000) { return context.getString(R.string.time_now); } else { // Otherwise, if the message is from today, show the time. format_flags |= DateUtils.FORMAT_SHOW_TIME; } sOpMessageUtilsExt.formatTimeStampStringExtend(context, when, format_flags); return DateUtils.formatDateTime(context, when, format_flags); }
From source file:com.demo.digit_dayview.EventResourceFromJson.java
@Override public List<Event> get(int startJulianDay, int numDays, Predicate continueLoading) { // Get the data from our separate thread try {/*from ww w . ja v a 2 s . c o m*/ new RetrieveFromJSON().execute().get(); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ExecutionException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Debug statements /* Log.d("event array", event_name_list.toString()); Log.d("start times", start_time_list.toString()); Log.d("end times", end_time_list.toString()); Log.d("test", event_name_list.get(0)); Log.d("test2", start_time_list.get(2)); Log.d("sizeof array", "size: " + event_name_list.size()); */ List<Event> events = Lists.newArrayList(); int startHours, endHours, startMinutes, endMinutes; for (int i = 0; i < numDays; i++) { // Make new time for the day Time scratch = new Time(); Event e; // Start adding the list of events from JSON for (int j = 0; j < event_name_list.size(); j++) { // Create the event e = new Event(); e.setAllDay(false); e.setEndDay(startJulianDay + i); e.setId(j + 1L); // Calculating the height of event by time Double endTime = Double.parseDouble(end_time_list.get(j)); Double startTime = Double.parseDouble(start_time_list.get(j)); // Check whether or not there is a dot character // first for end time, then for start time if (end_time_list.get(j).contains(".")) { String[] time = end_time_list.get(j).split("\\."); // Make into hours and minutes from the time array endHours = Integer.parseInt(time[0]); endMinutes = Integer.parseInt(time[1]); // Append . in minutes String myMinute = "." + endMinutes; // Parse the minute string Double calculatedMinute = Double.parseDouble(myMinute) * 60; //Log.d("the end time", "j:" + j + " " + (int) (endHours * 60 + calculatedMinute)); // Set the end time from the minutes and hours e.setEndTime((int) (endHours * 60 + calculatedMinute)); } else { endHours = Integer.parseInt(end_time_list.get(j)); e.setEndTime(endHours * 60 - 1); //Log.d("the end time without min", "j:" + j + " " + (endHours * 60)); } e.setStartDay(startJulianDay + i); if (start_time_list.get(j).contains(".")) { // Same idea as above in check list String[] time = start_time_list.get(j).split("\\."); startHours = Integer.parseInt(time[0]); startMinutes = Integer.parseInt(time[1]); String myMinute = "." + startMinutes; Double calculatedMinute = Double.parseDouble(myMinute) * 60; e.setStartTime((int) (startHours * 60 + calculatedMinute)); //Log.d("the start time (Y-coord)", "j:" + j + " " + (int) (startHours * 60 + calculatedMinute)); } else { startHours = Integer.parseInt(start_time_list.get(j)); e.setStartTime(startHours * 60); //Log.d("the start time without min (Y-coord)", "j:" + j + " " + (startHours * 60)); } Log.d("Y coordinate in time", start_time_list.get(j)); e.setColor(randomColour()); // At the first event of the day, start the day if (j == 0) scratch.setJulianDay(startJulianDay + i); // Allocate the times scratch.hour = startHours; scratch.minute = e.getStartTime() % 60; e.setStartMillis(scratch.toMillis(false)); scratch.hour = endHours; scratch.minute = e.getEndTime() % 60; e.setEndMillis(scratch.toMillis(false)); Log.d("height in time", ("" + (endTime - startTime))); e.setTitle(event_name_list.get(j)); //Log.d("event name", event_name_list.get(j)); events.add(e); } } Collections.sort(events, new Comparator<Event>() { @Override public int compare(Event lhs, Event rhs) { long l = lhs.getStartMillis() - rhs.getStartMillis(); if (l < 0) { return -1; } else if (l > 0) { return 1; } else return 0; } }); return events; }
From source file:com.jogden.spunkycharts.traditionalchart.TraditionalChartFragmentAdapter.java
private void _populateQueues(final int cursorStartPos) { Thread thisThread = new Thread() { public void run() { /* can't bail(risk deadlocking on the count-down latch) */ _populateLck.lock();//from w ww .j ava 2 s.c o m try { if (cursorStartPos > 0) /* back one because moveToNext() ) */ _myCursor.moveToPosition(cursorStartPos - 1); else _myCursor.moveToPosition(-1); int mergeNum = _chartFreq.value / DataClientInterface.TIME_GRANULARITY; /* reset _lastPutTime */ _lastPutTime = null; // DEBUG DataContentService.dumpDatabaseTableToLogCat(_symbol, _thisConsumer); /* start on a clean seg , i.e mod freq == 0 */ boolean cleanStart = true; Time time = new Time(); while (_myCursor.moveToNext()) { time.set(_myCursor.getLong(0)); if (time.minute % mergeNum == 0) break; cleanStart = false; } _myCursor.moveToPrevious(); OHLC[] prices = new OHLC[mergeNum]; int[] vols = new int[mergeNum]; time.set(0); int modCount = 0; // issue will null time if cursor is done here !! // we throw a *LogicError if its a problem later. while (_myCursor.moveToNext() && !this.isInterrupted()) { prices[modCount] = new OHLC(_myCursor.getFloat(1), _myCursor.getFloat(2), _myCursor.getFloat(3), _myCursor.getFloat(4)); vols[modCount] = _myCursor.getInt(5); if (modCount == 0) time.set(_myCursor.getLong(0)); if (modCount + 1 >= mergeNum) { OHLC mPrices = _mergePrices(prices); int mVols = _mergeVolumes(vols); //_timeStampQueue.put( time.format("%H:%M") ); /* time must come first since it may fill gaps in price/vol */ _putTime(time); _ohlcQueue.put(mPrices); _volumeQueue.put(mVols); modCount = 0;/* Log.d("Data-Consumer-Populate", mPrices.toString +" " + String.valueOf(mVols) + " " + time );*/ } else ++modCount; } /* don't forget about an unclean end */ if (modCount != 0) { // _timeStampQueue.put( time.format("%H:%M") ); /* time must come first since it may fill gaps in price/vol */ _putTime(time); _ohlcQueue.put(_mergePrices(Arrays.copyOf(prices, modCount))); _volumeQueue.put(_mergeVolumes(Arrays.copyOf(vols, modCount))); /* Log.d("Data-Consumer-Populate", _lastPriceSeg.toString() +" " + String.valueOf(_lastVolSeg) + " " + time );*/ } if (time.toMillis(true) == 0) throw new TraditionalChartLogicError("attempt to evaluate a null time in PopulateQueues; " + "its possible there were no granular segs after cleaning " + "the non-logically aligned front segs, and thus no valid time."); _lastSegTime.setToNow(); _lastSegTime.hour = time.hour; _lastSegTime.minute = time.minute; // _updateTime.setToNow(); _streamReady.set(true); /* unclean start needs extra counts to avoid deadlock */ for (int i = 0; !cleanStart && i < 2; ++i) _updateLtch.countDown(); } catch (InterruptedException e) { _clear(); } catch (RuntimeException e) { _clear(); throw e; } finally { _activeThreads.remove(this); _populateLck.unlock(); } } }; _activeThreads.add(thisThread); thisThread.start(); }
From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { final ViewHolder h = (ViewHolder) view.getTag(); final Time validTo = FormatUtil.timeFrom3339(cursor.getString(iValidTo)); final int status = getValidityStatus(cursor.getInt(iStatus), validTo); view.setTag(R.id.swipe_enabled, (status == Tickets.STATUS_EXPIRED)); AnimationUtil.setFlipAnimation(h.vIndicator, h.animator, getPrimaryIndicatorImage(status), getSecondaryIndicatorImage(status), c); h.vStatus.setText(getValidityString(status, validTo)); h.vStatus.setTextColor(getValidityColor(status)); h.vCity.setText(cursor.getString(iCity)); h.vTicket.setBackgroundResource(getTicketBackground(status)); if (cursor.getLong(iId) == mActiveId) { final int position = cursor.getPosition(); if (status != Tickets.STATUS_WAITING) { h.vValidFrom.setText(FormatUtil.formatDate3339(cursor.getString(iValidFrom))); h.vValidFrom.setTextColor(getActiveDetailColor(status)); h.vValidTo.setText(FormatUtil.formatDate3339(cursor.getString(iValidTo))); h.vValidTo.setTextColor(getActiveDetailColor(status)); h.vValidToLabel.setTextColor(getActiveDetailColor(status)); h.vCode.setText(cursor.getString(iHash)); h.vCode.setTextColor(getActiveDetailColor(status)); h.vCodeLabel.setTextColor(getActiveDetailColor(status)); h.vShowSms.setTextColor(getShowSmsColor(status)); h.vValidFromLabel.setText(R.string.tickets_valid_from); h.vValidFromLabel.setVisibility(View.VISIBLE); h.vCodeLabel.setVisibility(View.VISIBLE); h.vShowSms.setVisibility(View.VISIBLE); } else {/*from w w w. j a va2s. co m*/ h.vValidFromLabel.setText(R.string.tickets_waiting_info); h.vValidToLabel.setVisibility(View.INVISIBLE); h.vCodeLabel.setVisibility(View.INVISIBLE); h.vShowSms.setVisibility(View.INVISIBLE); } if (status == Tickets.STATUS_EXPIRED || status == Tickets.STATUS_WAITING) { h.vDelete.setImageResource(getDeleteImage(status)); h.vDelete.setContentDescription(c.getString(R.string.desc_delete_ticket)); if (status == Tickets.STATUS_EXPIRED) { h.vDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.forceDismiss(position); } }); } else { // waiting gets deleted, not archived h.vDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { deleteTicket(position); } }); } } else { h.vDelete.setImageResource(getCollapseImage(status)); h.vDelete.setContentDescription(c.getString(R.string.desc_collapse_ticket)); h.vDelete.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mFragment.collapseUncollapseTicket(mActiveId, mShowSms); } }); } h.vValidFromLabel.setTextColor(getActiveDetailColor(status)); h.vCollapse.setImageResource(getCollapseImage(status)); h.vSeparator1.setBackgroundResource(getSeparatorImage(status)); h.vSeparator2.setBackgroundResource(getSeparatorImage(status)); h.vSeparator3.setBackgroundResource(getSeparatorImage(status)); } else { h.vWhenExpired.setText(getValidToText(status, validTo.toMillis(false))); h.vWhenExpired.setVisibility(View.VISIBLE); } }
From source file:jmri.enginedriver.throttle.java
private void speakWords(int msgNo, int whichThrottle) { boolean result = false; String speech = ""; if (!prefTtsWhen.equals(PREF_TT_WHEN_NONE)) { if (myTts != null) { switch (msgNo) { case TTS_MSG_VOLUME_THROTTLE: if (!prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_NONE)) { if (whichLastVolume != whichThrottle) { result = true;/*from w ww. j av a 2s. c o m*/ whichLastVolume = whichThrottle; speech = getApplicationContext().getResources().getString(R.string.TtsVolumeThrottle) + " " + (whichThrottle + 1); } if ((prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO)) || (prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO_SPEED))) { speech = speech + ", " + getApplicationContext().getResources().getString(R.string.TtsLoco) + " " + (getConsistAddressString(whichThrottle)); } if ((prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_SPEED)) || (prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO_SPEED))) { speech = speech + ", " + getApplicationContext().getResources().getString(R.string.TtsSpeed) + " " + (getScaleSpeed(whichThrottle) + 1); } } break; case TTS_MSG_GAMEPAD_THROTTLE: if (!prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_NONE)) { if (whichLastGamepad1 != whichThrottle) { result = true; whichLastGamepad1 = whichThrottle; speech = getApplicationContext().getResources().getString(R.string.TtsGamepadThrottle) + " " + (whichThrottle + 1); } if ((prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO)) || (prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO_SPEED))) { speech = speech + ", " + getApplicationContext().getResources().getString(R.string.TtsLoco) + " " + (getConsistAddressString(whichThrottle)); } if ((prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_SPEED)) || (prefTtsThrottleResponse.equals(PREF_TTS_THROTTLE_RESPONSE_LOCO_SPEED))) { speech = speech + ", " + getApplicationContext().getResources().getString(R.string.TtsSpeed) + " " + (getScaleSpeed(whichThrottle) + 1); } } break; case TTS_MSG_GAMEPAD_GAMEPAD_TEST: if ((prefTtsGamepadTest)) { result = true; speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTest); } break; case TTS_MSG_GAMEPAD_GAMEPAD_TEST_COMPLETE: if ((prefTtsGamepadTestComplete)) { result = true; speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTestComplete); } break; case TTS_MSG_GAMEPAD_GAMEPAD_TEST_SKIPPED: if ((prefTtsGamepadTestComplete)) { result = true; speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTestSkipped); } break; case TTS_MSG_GAMEPAD_GAMEPAD_TEST_FAIL: if ((prefTtsGamepadTestComplete)) { result = true; speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTestFail); } break; case TTS_MSG_GAMEPAD_GAMEPAD_TEST_RESET: if ((prefTtsGamepadTestComplete)) { result = true; speech = getApplicationContext().getResources().getString(R.string.TtsGamepadTestReset); } break; } if (result) { Time currentTime = new Time(); currentTime.setToNow(); // //don't repeat what was last spoken withing 6 seconds if (((currentTime.toMillis(true) >= (lastTtsTime.toMillis(true) + 6000)) || (!speech.equals(lastTts)))) { //myTts.speak(speech, TextToSpeech.QUEUE_FLUSH, null); myTts.speak(speech, TextToSpeech.QUEUE_ADD, null); lastTtsTime = currentTime; } lastTts = speech; } } } }