List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance()
From source file:com.uic.sandeep.phonepark.googleacitvityrecognition.ActivityRecognitionIntentService.java
/** * Called when a new activity detection update is available. *//*ww w . ja va 2 s .c o m*/ @Override protected void onHandleIntent(Intent intent) { // Get a handle to the repository mPrefs = getApplicationContext().getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE); // Get a date formatter, and catch errors in the returned timestamp try { mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance(); } catch (Exception e) { Log.e(Constants.APP_NAME, getString(R.string.date_format_error)); } // Format the timestamp according to the pattern, then localize the pattern mDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss:SSS"); mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern()); mNotificationManagerWrapper = EventDetectionNotificationManager.getInstance(this); mLocationManagerWrapper = LocationManagerWrapper.getInstance(this); // If the intent contains an update if (ActivityRecognitionResult.hasResult(intent)) { // Get the update ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); // Get the most probable activity from the list of activities in the update DetectedActivity mostProbableActivity = result.getMostProbableActivity(); // Get the confidence percentage for the most probable activity int confidenceOfMostProbableActivity = mostProbableActivity.getConfidence(); int confidenceOfOnFoot = result.getActivityConfidence(DetectedActivity.ON_FOOT); int confidenceOfInVehicle = result.getActivityConfidence(DetectedActivity.IN_VEHICLE); // Get the type of activity int mostProbableActivityType = mostProbableActivity.getType(); Location curLocation = null; /*if ( // If the current type is "moving" isMoving(activityType) && // The activity has changed from the previous activity activityChanged(activityType) // The confidence level for the current activity is > 50% && (confidence >= 50)) { // Notify the user mNotificationManagerWrapper.sendTextNotification("Please enable the GPS."); } if(isFromOnFoottoInVehicle(mostProbableActivity)){ //request a location fix curLocation=mLocationManagerWrapper.getLatestLocation(); } if(isFromInVehicletoOnFoot(mostProbableActivity)){ //request a location fix curLocation= mLocationManagerWrapper.getLatestLocation(); } // Save the current state Editor editor = mPrefs.edit(); editor.putInt(Constants.KEY_PREVIOUS_ACTIVITY_TYPE, activityType); editor.commit(); // Log the update logActivityRecognitionResult(result, curLocation);*/ sendActivityUpdateToMainActivity(mostProbableActivityType, getNameFromType(mostProbableActivityType), confidenceOfMostProbableActivity, confidenceOfOnFoot, confidenceOfInVehicle); } }
From source file:org.jenkinsci.plugins.gitbucket.GitBucketPushTrigger.java
public void onPost(final GitBucketPushRequest req) { getDescriptor().queue.execute(new Runnable() { private boolean polling() { try { StreamTaskListener listener = new StreamTaskListener(getLogFile()); try { PrintStream logger = listener.getLogger(); long start = System.currentTimeMillis(); logger.println("Started on " + DateFormat.getDateTimeInstance().format(new Date())); boolean result = job.poll(listener).hasChanges(); logger.println("Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start)); if (result) { logger.println("Changes found"); } else { logger.println("No changes"); }/* w w w .j a v a2s.c o m*/ return result; } catch (Error e) { e.printStackTrace(listener.error("Failed to record SCM polling")); LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e); throw e; } catch (RuntimeException e) { e.printStackTrace(listener.error("Failed to record SCM polling")); LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e); throw e; } finally { listener.closeQuietly(); } } catch (IOException e) { LOGGER.log(Level.SEVERE, "Failed to record SCM polling", e); } return false; } public void run() { LOGGER.log(Level.INFO, "{0} triggered.", job.getName()); if (polling()) { String name = " #" + job.getNextBuildNumber(); GitBucketPushCause cause = createGitBucketPushCause(req); Action[] actions = createActions(req); if (job.scheduleBuild(job.getQuietPeriod(), cause, actions)) { LOGGER.log(Level.INFO, "SCM changes detected in {0}. Triggering {1}", new String[] { job.getName(), name }); } else { LOGGER.log(Level.INFO, "SCM changes detected in {0}. Job is already in the queue.", job.getName()); } } } private GitBucketPushCause createGitBucketPushCause(GitBucketPushRequest req) { GitBucketPushCause cause; String triggeredByUser = req.getPusher().getName(); try { cause = new GitBucketPushCause(triggeredByUser, getLogFile()); } catch (IOException ex) { cause = new GitBucketPushCause(triggeredByUser); } return cause; } private Action[] createActions(GitBucketPushRequest req) { List<Action> actions = new ArrayList<Action>(); if (passThroughGitCommit) { Commit lastCommit = req.getLastCommit(); actions.add(new RevisionParameterAction(lastCommit.getId(), false)); } return actions.toArray(new Action[0]); } }); }
From source file:com.pingstersapp.LocationService.Utils.java
/** * Returns the title for reporting about a list of {@link Location} objects. * * @param context The {@link Context}./* w w w .ja v a 2 s.c o m*/ */ static String getLocationResultTitle(Context context, List<Location> locations) { String numLocationsReported = java.lang.Integer.toString(locations.size()); return numLocationsReported + ": " + DateFormat.getDateTimeInstance().format(new Date()); }
From source file:com.github.mjdetullio.jenkins.plugins.multibranch.SyncBranchesTrigger.java
/** * {@inheritDoc}/* w ww . j a v a2s .c o m*/ */ @Override public void run() { /* * The #start(Item, boolean) method provides the job so this will be null * only when invoked directly before starting. */ if (job == null) { return; } try { StreamTaskListener listener = new StreamTaskListener(getLogFile()); long start = System.currentTimeMillis(); listener.getLogger().println("Started on " + DateFormat.getDateTimeInstance().format(new Date())); job.syncBranches(listener); listener.getLogger() .println("Done. Took " + Util.getTimeSpanString(System.currentTimeMillis() - start)); listener.close(); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Failed to record sync branches log for " + job, e); } }
From source file:com.google.android.gms.location.sample.locationupdatespendingintent.Utils.java
/** * Returns the title for reporting about a list of {@link Location} objects. * * @param context The {@link Context}.//from www.ja va2 s . co m */ static String getLocationResultTitle(Context context, List<Location> locations) { String numLocationsReported = context.getResources().getQuantityString(R.plurals.num_locations_reported, locations.size(), locations.size()); return numLocationsReported + ": " + DateFormat.getDateTimeInstance().format(new Date()); }
From source file:io.lightlink.excel.ExcelImportExportTest.java
public void test() throws IOException { int COLUMNS_CNT = 30; int ROWS_CNT = 10000; List<String> headers = new ArrayList<String>(); List<String> columns = new ArrayList<String>(); for (int i = 0; i < COLUMNS_CNT; i++) { columns.add("col_" + i); headers.add("Name " + i); }/*w w w .j a v a 2 s . c om*/ ClassLoader cl = Thread.currentThread().getContextClassLoader(); InputStream templateStream = cl.getResource("io/lightlink/excel/ExcelImportExportTest.xlsx").openStream(); InputStream templateStream2 = cl.getResource("io/lightlink/excel/ExcelImportExportTest.xlsx").openStream(); HashMap<String, Object> data = new HashMap<String, Object>(); HashMap<String, Object> p = new HashMap<String, Object>(); p.put("firstName", "My firstName"); p.put("lastName", "My lastName"); p.put("minHireDate", new Date(0).toString()); p.put("maxHireDate", new Date().toString()); p.put("minSalary", "1200"); p.put("maxSalary", "5000"); data.put("p", p); data.put("date", new Date().toString()); data.put("headers", headers); data.put("columns", columns); List<Map<String, Object>> resultSet = new ArrayList<Map<String, Object>>(); for (int i = 0; i < ROWS_CNT; i++) { HashMap<String, Object> line = new HashMap<String, Object>(); for (String column : columns) { line.put(column, column + "_" + i); } resultSet.add(line); if (i % 1000 == 0) { System.out.println(i + " : " + Runtime.getRuntime().totalMemory() / 1000000 + "Mb used"); } } data.put("resultSet", resultSet); String fName = "ExcelImportExportTest-OUT.xlsx"; OutputStream outFile = new FileOutputStream(fName); long l = System.currentTimeMillis(); new StreamingExcelTransformer().doExport(templateStream, outFile, new WritingExcelStreamVisitor(data, DateFormat.getDateTimeInstance())); outFile.close(); // System.out.println(COLUMNS_CNT + "x" + ROWS_CNT + " generated in " + (System.currentTimeMillis() - l) / 1000f + "sec"); // resultSet = null; // data = null; // for debug InputStream fileToRead = new FileInputStream(fName); HashMap<String, MappingBean> outData = new HashMap<String, MappingBean>(); // read definition DefinitionReadingExcelStreamVisitor definitionReadingExcelStreamVisitor = new DefinitionReadingExcelStreamVisitor(); new StreamingExcelTransformer().doExport(templateStream2, new NullOutputStream(), definitionReadingExcelStreamVisitor); Map<String, MappingBean> targets = definitionReadingExcelStreamVisitor.getTargets(); // read data DataReadingExcelStreamVisitor dataReadingExcelStreamVisitor = new DataReadingExcelStreamVisitor(targets); new StreamingExcelTransformer().doExport(fileToRead, new NullOutputStream(), dataReadingExcelStreamVisitor); Map<String, Object> loadedData = dataReadingExcelStreamVisitor.getData(); compareAssertMap("", data, loadedData); fileToRead.close(); new File(fName).delete(); }
From source file:org.craftercms.security.authentication.impl.AuthenticationCookie.java
/** * Returns the cookie as a string value. *///from ww w . j a v a 2 s .c o m public String toCookieValue() { return ticket + COOKIE_SEP + DateFormat.getDateTimeInstance().format(profileOutdatedAfter); }
From source file:com.updetector.google.activityrecognition.ActivityRecognitionIntentService.java
/** * Called when a new activity detection update is available. */// ww w .j a va2s . com @Override protected void onHandleIntent(Intent intent) { // Get a handle to the repository mPrefs = getApplicationContext().getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE); // Get a date formatter, and catch errors in the returned timestamp try { mDateFormat = (SimpleDateFormat) DateFormat.getDateTimeInstance(); } catch (Exception e) { Log.e(Constants.APP_NAME, getString(R.string.date_format_error)); } // Format the timestamp according to the pattern, then localize the pattern mDateFormat.applyPattern("yyyy-MM-dd HH:mm:ss:SSS"); mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern()); mNotificationManagerWrapper = DetectionNotificationManager.getInstance(this); mLocationManagerWrapper = LocationManagerWrapper.getInstance(this); // If the intent contains an update if (ActivityRecognitionResult.hasResult(intent)) { // Get the update ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); // Get the most probable activity from the list of activities in the update DetectedActivity mostProbableActivity = result.getMostProbableActivity(); // Get the confidence percentage for the most probable activity int confidenceOfMostProbableActivity = mostProbableActivity.getConfidence(); int confidenceOfOnFoot = result.getActivityConfidence(DetectedActivity.ON_FOOT); int confidenceOfInVehicle = result.getActivityConfidence(DetectedActivity.IN_VEHICLE); // Get the type of activity int mostProbableActivityType = mostProbableActivity.getType(); Location curLocation = null; /*if ( // If the current type is "moving" isMoving(activityType) && // The activity has changed from the previous activity activityChanged(activityType) // The confidence level for the current activity is > 50% && (confidence >= 50)) { // Notify the user mNotificationManagerWrapper.sendTextNotification("Please enable the GPS."); } if(isFromOnFoottoInVehicle(mostProbableActivity)){ //request a location fix curLocation=mLocationManagerWrapper.getLatestLocation(); } if(isFromInVehicletoOnFoot(mostProbableActivity)){ //request a location fix curLocation= mLocationManagerWrapper.getLatestLocation(); } // Save the current state Editor editor = mPrefs.edit(); editor.putInt(Constants.KEY_PREVIOUS_ACTIVITY_TYPE, activityType); editor.commit(); // Log the update logActivityRecognitionResult(result, curLocation);*/ sendActivityUpdateToMainActivity(mostProbableActivityType, getNameFromType(mostProbableActivityType), confidenceOfMostProbableActivity, confidenceOfOnFoot, confidenceOfInVehicle); } }
From source file:com.ubergeek42.WeechatAndroid.utils.UntrustedCertificateDialog.java
public String getCertificateDescription() { String fingerprint;//from w w w . j a va 2 s .c om try { fingerprint = new String(Hex.encodeHex(DigestUtils.sha256(certificate.getEncoded()))); } catch (CertificateEncodingException e) { fingerprint = getString(R.string.ssl_cert_dialog_unknown_fingerprint); } return getString(R.string.ssl_cert_dialog_description, certificate.getSubjectDN().getName(), certificate.getIssuerDN().getName(), DateFormat.getDateTimeInstance().format(certificate.getNotBefore()), DateFormat.getDateTimeInstance().format(certificate.getNotAfter()), fingerprint); }
From source file:de.iteratec.iteraplan.model.history.HistoryRevisionEntity.java
@Override public String toString() { return "IteraHistoryRevisionEntity(id = " + getId() + ", revisionDate = " + DateFormat.getDateTimeInstance().format(getRevisionDate()) + ", user = " + getUsername() + ")"; }