List of usage examples for java.text DateFormat getTimeInstance
public static final DateFormat getTimeInstance()
From source file:com.zpci.firstsignhairclipdemo.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.diag);/*from w ww. j a va2 s . c o m*/ mBtAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBtAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } messageListView = (ListView) findViewById(R.id.listMessage); listAdapter = new ArrayAdapter<String>(this, R.layout.message_detail); messageListView.setAdapter(listAdapter); messageListView.setDivider(null); btnConnectDisconnect = (Button) findViewById(R.id.btn_select); btnSend = (Button) findViewById(R.id.sendButton); edtMessage = (EditText) findViewById(R.id.sendText); // top level select either demo mode or diag mode dm1 = (Button) findViewById(R.id.DemoModeButton); dm2 = (Button) findViewById(R.id.DiagModeButton); // make other controls invisible until mode is selected c1 = (Button) findViewById(R.id.Command1Button); c2 = (Button) findViewById(R.id.Command2Button); sb1 = (Button) findViewById(R.id.Sens1Button); sb2 = (Button) findViewById(R.id.Sens2Button); sb3 = (Button) findViewById(R.id.Sens3Button); stxt = (TextView) findViewById(R.id.textSensy); Log.d(TAG, "stext = " + stxt); alonb = (Button) findViewById(R.id.DemoAlarmOnButton); aloffb = (Button) findViewById(R.id.DemoAlarmOffButton); Log.d(TAG, "demomode = " + demomode); c1.setVisibility(View.INVISIBLE); c2.setVisibility(View.INVISIBLE); btnSend.setVisibility(View.INVISIBLE); edtMessage.setVisibility(View.INVISIBLE); messageListView.setVisibility(View.INVISIBLE); sb1.setVisibility(View.GONE); sb2.setVisibility(View.GONE); sb3.setVisibility(View.GONE); stxt.setVisibility(View.GONE); alonb.setVisibility(View.GONE); aloffb.setVisibility(View.GONE); service_init(); // Handler Disconnect & Connect button btnConnectDisconnect.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!mBtAdapter.isEnabled()) { Log.i(TAG, "onClick - BT not enabled yet"); Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } else { if (btnConnectDisconnect.getText().equals("Connect")) { //Connect button pressed, open DeviceListActivity class, with popup windows that scan for devices Intent newIntent = new Intent(MainActivity.this, DeviceListActivity.class); startActivityForResult(newIntent, REQUEST_SELECT_DEVICE); } else { //Disconnect button pressed if (mDevice != null) { mService.disconnect(); } } } } }); // Handler Send button btnSend.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText editText = (EditText) findViewById(R.id.sendText); String message = editText.getText().toString(); byte[] value; try { //send data to service value = message.getBytes("UTF-8"); mService.writeRXCharacteristic(value); //Update the log with time stamp String currentDateTimeString = DateFormat.getTimeInstance().format(new Date()); listAdapter.add("[" + currentDateTimeString + "] TX: " + message); messageListView.smoothScrollToPosition(listAdapter.getCount() - 1); edtMessage.setText(""); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); }
From source file:com.jalotsav.apppermissionruntime.MainActivity.java
@Override public void onLocationChanged(Location location) { Log.d(TAG, "Firing onLocationChanged"); mCurrentLocation = location;//from w ww. j ava 2 s . c o m mLastUpdateTime = DateFormat.getTimeInstance().format(new Date()); updateUI(); }
From source file:org.openqa.grid.internal.TestSession.java
private void setThreadDisplayName() { DateFormat dfmt = DateFormat.getTimeInstance(); String name = "Forwarding " + this + " to " + slot.getRemoteURL() + " at " + dfmt.format(Calendar.getInstance().getTime()); Thread.currentThread().setName(name); }
From source file:org.opendatakit.common.utils.WebUtils.java
/** * Parse a string into a datetime value. Tries the common Http formats, the * iso8601 format (used by Javarosa), the default formatting from * Date.toString(), and a time-only format. * * @param value//w w w. ja va2s . c o m * @return */ public static final Date parseDate(String value) { if (value == null || value.length() == 0) return null; String[] iso8601Pattern = new String[] { PATTERN_ISO8601 }; String[] localizedParsePatterns = new String[] { // try the common HTTP date formats that have time zones PATTERN_RFC1123, PATTERN_RFC1036, PATTERN_DATE_TOSTRING }; String[] localizedNoTzParsePatterns = new String[] { // ones without timezones... (will assume UTC) PATTERN_ASCTIME }; String[] tzParsePatterns = new String[] { PATTERN_ISO8601, PATTERN_ISO8601_DATE, PATTERN_ISO8601_TIME }; String[] noTzParsePatterns = new String[] { // ones without timezones... (will assume UTC) PATTERN_ISO8601_WITHOUT_ZONE, PATTERN_NO_DATE_TIME_ONLY, PATTERN_YYYY_MM_DD_DATE_ONLY_NO_TIME_DASH, PATTERN_GOOGLE_DOCS }; Date d = null; // iso8601 parsing is sometimes off-by-one when JR does it... d = parseDateSubset(value, iso8601Pattern, null, TimeZone.getTimeZone("GMT")); if (d != null) return d; // try to parse with the JavaRosa parsers d = DateUtils.parseDateTime(value); if (d != null) return d; d = DateUtils.parseDate(value); if (d != null) return d; d = DateUtils.parseTime(value); if (d != null) return d; // try localized and english text parsers (for Web headers and interactive // filter spec.) d = parseDateSubset(value, localizedParsePatterns, Locale.ENGLISH, TimeZone.getTimeZone("GMT")); if (d != null) return d; d = parseDateSubset(value, localizedParsePatterns, null, TimeZone.getTimeZone("GMT")); if (d != null) return d; d = parseDateSubset(value, localizedNoTzParsePatterns, Locale.ENGLISH, TimeZone.getTimeZone("GMT")); if (d != null) return d; d = parseDateSubset(value, localizedNoTzParsePatterns, null, TimeZone.getTimeZone("GMT")); if (d != null) return d; // try other common patterns that might not quite match JavaRosa parsers d = parseDateSubset(value, tzParsePatterns, null, TimeZone.getTimeZone("GMT")); if (d != null) return d; d = parseDateSubset(value, noTzParsePatterns, null, TimeZone.getTimeZone("GMT")); if (d != null) return d; // try the locale- and timezone- specific parsers { DateFormat formatter = DateFormat.getDateTimeInstance(); ParsePosition pos = new ParsePosition(0); d = formatter.parse(value, pos); if (d != null && pos.getIndex() == value.length()) { return d; } } { DateFormat formatter = DateFormat.getDateInstance(); ParsePosition pos = new ParsePosition(0); d = formatter.parse(value, pos); if (d != null && pos.getIndex() == value.length()) { return d; } } { DateFormat formatter = DateFormat.getTimeInstance(); ParsePosition pos = new ParsePosition(0); d = formatter.parse(value, pos); if (d != null && pos.getIndex() == value.length()) { return d; } } throw new IllegalArgumentException("Unable to parse the date: " + value); }
From source file:org.pentaho.platform.repository.subscription.SubscriptionExecute.java
private void execute(final String jobName, final Map<String, Object> parametersMap, final IPentahoSession userSession) { try {/*from w w w . ja v a2 s . c o m*/ LocaleHelper.setLocale(Locale.getDefault()); logId = "Pro Subscription:" + jobName; //$NON-NLS-1$ Date now = new Date(); SubscriptionExecute.logger.info(Messages.getString("SubscriptionExecute.INFO_TRIGGER_TIME", jobName, //$NON-NLS-1$ DateFormat.getDateInstance().format(now), DateFormat.getTimeInstance().format(now))); String solutionName = (String) parametersMap.get("solution"); //$NON-NLS-1$ String actionPath = (String) parametersMap.get("path"); //$NON-NLS-1$ String actionName = (String) parametersMap.get("action"); //$NON-NLS-1$ String subscriptionDestination = (String) parametersMap.get("SUB_DESTINATION"); String instanceId = null; String processId = this.getClass().getName(); if (solutionName == null) { error(Messages.getErrorString("SubscriptionExecute.ERROR_0001_SOLUTION_NAME_MISSING")); //$NON-NLS-1$ return; } if (actionPath == null) { error(Messages.getErrorString("SubscriptionExecute.ERROR_0002_ACTION_PATH_MISSING")); //$NON-NLS-1$ return; } if (actionName == null) { error(Messages.getErrorString("SubscriptionExecute.ERROR_0003_ACTION_NAME_MISSING")); //$NON-NLS-1$ return; } if (SubscriptionExecute.debug) { if (SubscriptionExecute.debug) { debug(Messages.getString("SubscriptionExecute.DEBUG_EXECUTION_INFO", //$NON-NLS-1$ solutionName + "/" + actionPath + "/" + actionName)); //$NON-NLS-1$ //$NON-NLS-2$ } } boolean ignoreSubscriptionOutput = "true" //$NON-NLS-1$ .equalsIgnoreCase((String) parametersMap.get("SUB_IGNORE_OUTPUT")); //$NON-NLS-1$ String subscriptionId = (String) parametersMap.get("SUB_ID"); //$NON-NLS-1$ String subscriptionName = (String) parametersMap.get("SUB_NAME"); //$NON-NLS-1$ IOutputHandler outputHandler = null; if (ignoreSubscriptionOutput) { outputHandler = new SimpleOutputHandler((OutputStream) null, false); } else { String contentPath = SubscriptionHelper.getSubscriptionOutputLocation(solutionName, actionPath, actionName); outputHandler = new CoreContentRepositoryOutputHandler(contentPath, subscriptionId, solutionName, userSession); ((CoreContentRepositoryOutputHandler) outputHandler) .setWriteMode(IContentItem.WRITEMODE_KEEPVERSIONS); } parametersMap.put("useContentRepository", Boolean.TRUE); //$NON-NLS-1$ String contentUrlPattern = PentahoSystem.getApplicationContext().getFullyQualifiedServerURL(); if (!contentUrlPattern.endsWith("/")) { //$NON-NLS-1$ contentUrlPattern += "/"; //$NON-NLS-1$ } contentUrlPattern += "GetContent?id={0}"; //$NON-NLS-1$ parametersMap.put("content-handler-pattern", contentUrlPattern); //$NON-NLS-1$ SimpleParameterProvider parameterProvider = new SimpleParameterProvider(parametersMap); IParameterProvider sessionParams = new PentahoSessionParameterProvider(userSession); int lastDot = actionName.lastIndexOf('.'); String type = actionName.substring(lastDot + 1); IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, userSession); IContentGenerator generator = pluginManager.getContentGeneratorForType(type, userSession); if (generator == null) { BaseRequestHandler requestHandler = new BaseRequestHandler(userSession, null, outputHandler, parameterProvider, null); requestHandler.setParameterProvider(IParameterProvider.SCOPE_SESSION, sessionParams); requestHandler.setInstanceId(instanceId); requestHandler.setProcessId(processId); requestHandler.setAction(actionPath, actionName); requestHandler.setSolutionName(solutionName); IRuntimeContext rt = null; try { rt = requestHandler.handleActionRequest(0, 0); if (isValidEmailAddress(subscriptionDestination)) { emailContent(outputHandler, subscriptionName, solutionName, actionName, instanceId, subscriptionDestination); } else if (!ignoreSubscriptionOutput && !outputHandler.contentDone()) { if ((rt != null) && (rt.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) { StringBuffer buffer = new StringBuffer(); PentahoSystem.get(IMessageFormatter.class, userSession) .formatSuccessMessage("text/html", rt, buffer, false); //$NON-NLS-1$ writeMessage(buffer.toString(), outputHandler, subscriptionName, solutionName, actionName, instanceId, userSession); } else { // we need an error message... StringBuffer buffer = new StringBuffer(); PentahoSystem.get(IMessageFormatter.class, userSession) .formatFailureMessage("text/html", rt, buffer, requestHandler.getMessages()); //$NON-NLS-1$ writeMessage(buffer.toString(), outputHandler, subscriptionName, solutionName, actionName, instanceId, userSession); } } } finally { if (rt != null) { rt.dispose(); } } } else { generator.setOutputHandler(outputHandler); generator.setItemName(actionName); generator.setInstanceId(instanceId); generator.setSession(userSession); Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>(); parameterProviders.put(IParameterProvider.SCOPE_REQUEST, parameterProvider); parameterProviders.put(IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(userSession)); generator.setParameterProviders(parameterProviders); try { generator.createContent(); // we succeeded if (isValidEmailAddress(subscriptionDestination)) { emailContent(outputHandler, subscriptionName, solutionName, actionName, instanceId, subscriptionDestination); } else if (!ignoreSubscriptionOutput && !outputHandler.contentDone()) { String message = Messages.getString("SubscriptionExecute.DEBUG_FINISHED_EXECUTION", //$NON-NLS-1$ jobName); writeMessage(message.toString(), outputHandler, subscriptionName, solutionName, actionName, instanceId, userSession); } } catch (Exception e) { e.printStackTrace(); // we need an error message... if (!ignoreSubscriptionOutput && !outputHandler.contentDone()) { String message = Messages.getString("PRO_SUBSCRIPTREP.EXCEPTION_WITH_SCHEDULE", jobName); //$NON-NLS-1$ writeMessage(message.toString(), outputHandler, subscriptionName, solutionName, actionName, instanceId, userSession); } } } if (SubscriptionExecute.debug) { SubscriptionExecute.logger .debug(Messages.getString("SubscriptionExecute.DEBUG_FINISHED_EXECUTION", jobName)); //$NON-NLS-1$ } } catch (Throwable t) { SubscriptionExecute.logger.error("Error Executing Job", t); //$NON-NLS-1$ } }
From source file:com.elekso.potfix.MainActivity.java
private void createNotification() { // BEGIN_INCLUDE(notificationCompat) NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // END_INCLUDE(notificationCompat) // BEGIN_INCLUDE(intent) //Create Intent to launch this Activity again if the notification is clicked. Intent i = new Intent(this, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(intent);//from w w w. jav a 2 s.c o m // END_INCLUDE(intent) // BEGIN_INCLUDE(ticker) // Sets the ticker text builder.setTicker(getResources().getString(R.string.custom_notification)); // Sets the small icon for the ticker builder.setSmallIcon(R.drawable.icon4_1); // END_INCLUDE(ticker) // BEGIN_INCLUDE(buildNotification) // Cancel the notification when clicked builder.setAutoCancel(true); // Build the notification Notification notification = builder.build(); // END_INCLUDE(buildNotification) // BEGIN_INCLUDE(customLayout) // Inflate the notification layout as RemoteViews RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.notification); // Set text on a TextView in the RemoteViews programmatically. final String time = DateFormat.getTimeInstance().format(new Date()).toString(); final String text = getResources().getString(R.string.collapsed, time); contentView.setTextViewText(R.id.textView, text); /* Workaround: Need to set the content view here directly on the notification. * NotificationCompatBuilder contains a bug that prevents this from working on platform * versions HoneyComb. * See https://code.google.com/p/android/issues/detail?id=30495 */ notification.contentView = contentView; // Add a big content view to the notification if supported. // Support for expanded notifications was added in API level 16. // (The normal contentView is shown when the notification is collapsed, when expanded the // big content view set here is displayed.) if (Build.VERSION.SDK_INT >= 16) { // Inflate and set the layout for the expanded notification view RemoteViews expandedView = new RemoteViews(getPackageName(), R.layout.notification_expanded); notification.bigContentView = expandedView; } // END_INCLUDE(customLayout) // START_INCLUDE(notify) // Use the NotificationManager to show the notification NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); nm.notify(0, notification); // END_INCLUDE(notify) }
From source file:com.tonyandr.caminoguideoff.map.MapActivity.java
private void infoDialog() { String message = ""; if (mPrefs.contains("location-string")) { String[] loc_string = mPrefs.getString("location-string", "").split(","); if (loc_string.length > 1) { message = "Your current location:\n\n" + "Latitude: " + Double.parseDouble(loc_string[0]) + "\n" + "Longitude: " + Double.parseDouble(loc_string[1]) + "\n\n" + "Last update: " + DateFormat.getTimeInstance().format(new Date(Long.parseLong(loc_string[2]))); }//from w w w . j av a 2 s .c om } else { message = "Your current location:\n\nCannot find you, sorry :(\n\nHave you enabled GPS?"; } AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Info"); builder.setMessage(message); builder.setNegativeButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); Dialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); }
From source file:com.teeptrak.controller.MainActivity.java
private void printMessage(String aMsg, boolean aInsertDate) { String dateTime = DateFormat.getTimeInstance().format(new Date()); if (aInsertDate) { mMsgListAdapter.add("[" + dateTime + "] " + aMsg); } else {//from w ww .j a va 2s. c o m mMsgListAdapter.add(" " + aMsg); } mMsgList.smoothScrollToPosition(mMsgListAdapter.getCount() - 1); }
From source file:org.codesearch.indexer.server.manager.IndexingManager.java
/** * schedules a job for the given repositories causing them to be indexed * once at the time/*w ww . j av a2s . c om*/ * * @param repositories the repositories that are to be indexed * @param repositoryGroups the repo groups containing the repositories * @throws SchedulerException */ public void startJobForRepositories(List<String> repositories, List<String> repositoryGroups, boolean clear) throws SchedulerException { JobKey jobKey = new JobKey("manual-job-" + DateFormat.getTimeInstance().format(new Date().getTime()), IndexingJob.GROUP_NAME); List<RepositoryDto> repos = new LinkedList<RepositoryDto>(); for (String currentRepoName : repositories) { repos.add(configReader.getRepositoryByName(currentRepoName)); } for (String currentRepoGroup : repositoryGroups) { for (String currentRepo : configReader.getRepositoriesForGroup(currentRepoGroup)) { RepositoryDto newRepo = configReader.getRepositoryByName(currentRepo); if (!repos.contains(newRepo)) { repos.add(newRepo); } } } JobDataMap jdm = new JobDataMap(); jdm.put(IndexingJob.FIELD_REPOSITORIES, repos); jdm.put(IndexingJob.FIELD_TERMINATED, false); jdm.put(IndexingJob.FIELD_CLEAR_INDEX, clear); JobDetail jobDetail = JobBuilder.newJob(IndexingJob.class).withIdentity(jobKey).usingJobData(jdm).build(); Trigger jobTrigger = TriggerBuilder.newTrigger().forJob(jobKey).startNow().build(); scheduler.addJob(jobDetail, true); scheduler.scheduleJob(jobTrigger); LOG.info("Starting manual indexing job for"); }
From source file:com.wirelessmoves.cl.MainActivity.java
@Override public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); /* save variables */ savedInstanceState.putLong("NumberOfSignalStrengthUpdates", NumberOfSignalStrengthUpdates); savedInstanceState.putLong("LastCellId", LastCellId); savedInstanceState.putLong("NumberOfCellChanges", NumberOfCellChanges); savedInstanceState.putLong("LastLacId", LastLacId); savedInstanceState.putLong("NumberOfLacChanges", NumberOfLacChanges); savedInstanceState.putLongArray("PreviousCells", PreviousCells); savedInstanceState.putInt("PreviousCellsIndex", PreviousCellsIndex); savedInstanceState.putLong("NumberOfUniqueCellChanges", NumberOfUniqueCellChanges); savedInstanceState.putBoolean("outputDebugInfo", outputDebugInfo); savedInstanceState.putDouble("CurrentLocationLong", CurrentLocationLong); savedInstanceState.putDouble("CurrentLocationLat", CurrentLocationLat); /* save the trace data still in the write buffer into a file */ saveDataToFile(FileWriteBufferStr,// ww w .java 2 s . co m "---in save instance, " + DateFormat.getTimeInstance().format(new Date()) + "\r\n"); FileWriteBufferStr = ""; }