List of usage examples for android.text.format Time setToNow
public void setToNow()
From source file:com.android.mms.ui.MessageUtils.java
public static String getTimeDividerString(Context context, long when) { Time then = new Time(); then.set(when);/* w w w . j av a2 s. co m*/ Time now = new Time(); now.setToNow(); // Basic settings for formatDateTime() we want for all cases. int formatFlags = 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) { formatFlags |= 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. formatFlags |= DateUtils.FORMAT_SHOW_DATE; Date curDate = new Date(); Date cur = new Date(curDate.getYear(), curDate.getMonth(), curDate.getDate(), 0, 0, 0); long oneDay = 24 * 60 * 60 * 1000; long elapsedTime = cur.getTime() - when; if (elapsedTime < oneDay && elapsedTime > 0) { return context.getResources().getString(R.string.str_ipmsg_yesterday); } } else { return context.getString(R.string.str_ipmsg_today); } return DateUtils.formatDateTime(context, when, formatFlags); }
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 w ww .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.android.mms.ui.MessageUtils.java
public static String formatTimeStampString(Context context, long when, boolean fullFormat) { Time then = new Time(); then.set(when);// w ww . j a va 2 s .c om Time now = new Time(); now.setToNow(); // Basic settings for formatDateTime() we want for all cases. int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | /// M: Fix ALPS00419488 to show 12:00, so mark DateUtils.FORMAT_ABBREV_ALL //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. format_flags |= DateUtils.FORMAT_SHOW_DATE; } else { // Otherwise, if the message is from today, show the time. format_flags |= DateUtils.FORMAT_SHOW_TIME; } // If the caller has asked for full details, make sure to show the date // and time no matter what we've determined above (but still make showing // the year only happen if it is a different year from today). if (fullFormat) { format_flags |= (DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME); } String dateTime = sOpMessageUtilsExt.formatTimeStampString(context, when, format_flags); if (dateTime != null) { return dateTime; } return DateUtils.formatDateTime(context, when, format_flags); }
From source file:nz.ac.otago.psyanlab.common.designer.ExperimentDesignerActivity.java
@Override public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { case REQUEST_EDIT_STAGE: { switch (resultCode) { case RESULT_OK: ArrayList<PropIdPair> props = data.getParcelableArrayListExtra(Args.EXPERIMENT_PROPS); long sceneId = data.getLongExtra(Args.SCENE_ID, -1); int height = data.getIntExtra(Args.STAGE_HEIGHT, -1); int width = data.getIntExtra(Args.STAGE_WIDTH, -1); int orientation = data.getIntExtra(Args.STAGE_ORIENTATION, Scene.ORIENTATION_LANDSCAPE); updateStageInScene(sceneId, props, orientation, width, height); break; default:/*from www . j av a 2 s . c om*/ break; } break; } case REQUEST_ASSET_IMPORT: { switch (resultCode) { case RESULT_OK: String[] paths = data.getStringArrayExtra(Args.PICKED_PATHS); Time t = new Time(); t.setToNow(); mExperiment.assets.put(ModelUtils.findUnusedKey(mExperiment.assets), Asset.getFactory().newAsset(paths[0])); mAssetAdapter.notifyDataSetChanged(); break; default: break; } break; } case REQUEST_SOURCE_IMPORT: { switch (resultCode) { case RESULT_OK: String[] paths = data.getStringArrayExtra(Args.PICKED_PATHS); Time t = new Time(); t.setToNow(); Source newSource = new Source(); newSource.setExternalFile(new File(paths[0])); mExperiment.sources.put(ModelUtils.findUnusedKey(mExperiment.sources), newSource); mSourceAdapter.notifyDataSetChanged(); break; default: break; } } default: break; } }
From source file:de.vanita5.twittnuker.util.Utils.java
@SuppressWarnings("deprecation") public static String formatToLongTimeString(final Context context, final long timestamp) { if (context == null) return null; final Time then = new Time(); then.set(timestamp);//from ww w. java2 s . c o m final Time now = new Time(); now.setToNow(); int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM; format_flags |= DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME; return DateUtils.formatDateTime(context, timestamp, format_flags); }
From source file:de.vanita5.twittnuker.util.Utils.java
@SuppressWarnings("deprecation") public static String formatTimeStampString(final Context context, final long timestamp) { if (context == null) return null; final Time then = new Time(); then.set(timestamp);//w ww. ja va2 s.com final Time now = new Time(); now.setToNow(); int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_CAP_AMPM; if (then.year != now.year) { format_flags |= DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_DATE; } else if (then.yearDay != now.yearDay) { format_flags |= DateUtils.FORMAT_SHOW_DATE; } else { format_flags |= DateUtils.FORMAT_SHOW_TIME; } return DateUtils.formatDateTime(context, timestamp, format_flags); }
From source file:ru.otdelit.astrid.opencrx.sync.OpencrxSyncProvider.java
protected void performSync() { labelMap = new HashMap<String, String>(); lastSync = new Time(); preferences.recordSyncStart();// w w w .j a v a2s . c om Log.i(OpencrxUtils.TAG, "Starting sync!"); try { // load user information JSONObject user = invoker.userUpdateOpencrx(); saveUserData(user); String userCrxId = user.getString("crxid_user"); Time cur = new Time(); String lastServerSync = Preferences.getStringValue(OpencrxUtilities.PREF_SERVER_LAST_SYNC); try { if (lastServerSync != null) { lastSync.parse(lastServerSync); } else { // very long time ago lastSync.set(1, 1, 1980); } } catch (TimeFormatException ex) { lastSync.set(1, 1, 1980); } String lastNotificationId = Preferences.getStringValue(OpencrxUtilities.PREF_SERVER_LAST_NOTIFICATION); String lastActivityId = Preferences.getStringValue(OpencrxUtilities.PREF_SERVER_LAST_ACTIVITY); // read dashboards updateCreators(); // read contacts updateContacts(); // read labels updateResources(userCrxId); // read activity process graph graph = invoker.getActivityProcessGraph(); ArrayList<OpencrxTaskContainer> remoteTasks = new ArrayList<OpencrxTaskContainer>(); JSONArray tasks = invoker.tasksShowListOpencrx(graph); for (int i = 0; i < tasks.length(); i++) { JSONObject task = tasks.getJSONObject(i); OpencrxTaskContainer remote = parseRemoteTask(task); // update reminder flags for incoming remote tasks to prevent annoying if (remote.task.hasDueDate() && remote.task.getValue(Task.DUE_DATE) < DateUtilities.now()) remote.task.setFlag(Task.REMINDER_FLAGS, Task.NOTIFY_AFTER_DEADLINE, false); dataService.findLocalMatch(remote); remoteTasks.add(remote); } // TODO: delete Log.i(OpencrxUtils.TAG, "Matching local to remote..."); matchLocalTasksToRemote(remoteTasks); // TODO: delete Log.i(OpencrxUtils.TAG, "Matching local to remote finished"); // TODO: delete Log.i(OpencrxUtils.TAG, "Synchronizing tasks..."); SyncData<OpencrxTaskContainer> syncData = populateSyncData(remoteTasks); try { synchronizeTasks(syncData); } finally { syncData.localCreated.close(); syncData.localUpdated.close(); } // TODO: delete Log.i(OpencrxUtils.TAG, "Synchronizing tasks finished"); cur.setToNow(); Preferences.setString(OpencrxUtilities.PREF_SERVER_LAST_SYNC, cur.format2445()); preferences.recordSuccessfulSync(); Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_EVENT_REFRESH); ContextManager.getContext().sendBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ); // store lastIds in Preferences Preferences.setString(OpencrxUtilities.PREF_SERVER_LAST_NOTIFICATION, lastNotificationId); Preferences.setString(OpencrxUtilities.PREF_SERVER_LAST_ACTIVITY, lastActivityId); labelMap = null; lastSync = null; // TODO: delete Log.i(OpencrxUtils.TAG, "Sync successfull"); } catch (IllegalStateException e) { // occurs when application was closed } catch (Exception e) { handleException("opencrx-sync", e, true); //$NON-NLS-1$ } }
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 www .j a v a2 s . c om 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; } } } }