List of usage examples for java.text DateFormat getDateTimeInstance
public static final DateFormat getDateTimeInstance()
From source file:im.getsocial.testapp.ConsoleActivity.java
private Intent getDefaultShareIntent() { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); String subject = String.format("[%s] GetSocial Android Test App Logs", DateFormat.getDateTimeInstance().format(new Date())); intent.putExtra(Intent.EXTRA_SUBJECT, subject); intent.putExtra(Intent.EXTRA_TEXT, getShareText()); return intent; }
From source file:com.example.smarttone.ActivityRecognitionIntentService.java
/** * Called when a new activity detection update is available. */// w ww .j a v a 2 s. com @Override protected void onHandleIntent(Intent intent) { // Get a handle to the repository mPrefs = getApplicationContext().getSharedPreferences(ActivityUtils.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(ActivityUtils.APPTAG, getString(R.string.date_format_error)); } // Format the timestamp according to the pattern, then localize the pattern mDateFormat.applyPattern(DATE_FORMAT_PATTERN); mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern()); // 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 type of activity int activityType = mostProbableActivity.getType(); if (activityType != lastActivity) { final String activity = getNameFromType(activityType); final int volumeLevel = Constants.activityLevels.get(activity); VolumeHandler.setVolLevel(volumeLevel, Constants.ACTIVIY_TASK); lastActivity = activityType; handler.post(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), activity + " - " + volumeLevel, Toast.LENGTH_SHORT) .show(); sendNotification("", "Activity Recognition Profile - " + activity); } }); } /* // Get the confidence percentage for the most probable activity int confidence = mostProbableActivity.getConfidence(); // Check to see if the repository contains a previous activity if (!mPrefs.contains(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE)) { // This is the first type an activity has been detected. Store the type Editor editor = mPrefs.edit(); editor.putInt(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE, activityType); editor.commit(); // If the repository contains a type } else 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 sendNotification(); }*/ } }
From source file:fr.paris.lutece.plugins.seo.service.sitemap.SitemapService.java
/** * Generate Sitemap/*from www .jav a 2s. com*/ * @return The sitemap content */ public static String generateSitemap() { List<FriendlyUrl> list = getSitemapUrls(); Map<String, Object> model = new HashMap<String, Object>(); model.put(MARK_URLS_LIST, list); HtmlTemplate templateList = AppTemplateService.getTemplate(TEMPLATE_SITEMAP_XML, Locale.getDefault(), model); String strXmlSitemap = templateList.getHtml(); String strSiteMapFilePath = AppPathService.getWebAppPath() + FILE_SITEMAP; File fileSiteMap = new File(strSiteMapFilePath); String strResult = "OK"; try { FileUtils.writeStringToFile(fileSiteMap, strXmlSitemap); } catch (IOException e) { AppLogService.error("Error writing Sitemap file : " + e.getMessage(), e.getCause()); strResult = "Error : " + e.getMessage(); } String strDate = DateFormat.getDateTimeInstance().format(new Date()); Object[] args = { strDate, list.size(), strResult }; String strLogFormat = I18nService.getLocalizedString(PROPERTY_SITEMAP_LOG, Locale.getDefault()); String strLog = MessageFormat.format(strLogFormat, args); DatastoreService.setDataValue(SEODataKeys.KEY_SITEMAP_UPDATE_LOG, strLog); return strLog; }
From source file:fr.paris.lutece.plugins.seo.service.RuleFileService.java
/** * Generate the rule file content//from w w w. ja va 2s. c om * @return The file content */ private static String generateFileContent() { HashMap model = new HashMap(); Collection<UrlRewriterRule> listRules = UrlRewriterRuleHome.findAll(); List<FriendlyUrl> listUrl = FriendlyUrlHome.findAll(); model.put(MARK_RULES_LIST, listRules); model.put(MARK_URL_LIST, listUrl); HtmlTemplate t = AppTemplateService.getTemplate(TEMPLATE_FILE, Locale.getDefault(), model); String strResult = "OK"; String strDate = DateFormat.getDateTimeInstance().format(new Date()); Object[] args = { strDate, listRules.size() + listUrl.size(), strResult }; String strLogFormat = I18nService.getLocalizedString(PROPERTY_REWRITE_CONFIG_LOG, Locale.getDefault()); String strLog = MessageFormat.format(strLogFormat, args); DatastoreService.setDataValue(SEODataKeys.KEY_REWRITE_CONFIG_UPDATE, strLog); DatastoreService.setDataValue(SEODataKeys.KEY_CONFIG_UPTODATE, DatastoreService.VALUE_TRUE); return t.getHtml(); }
From source file:com.adaptris.core.services.WaitService.java
/** * <p>/*from www . ja va 2 s. co m*/ * Waits for the configured number of milliseconds. * </p> * * @param msg the message to apply service to * @throws ServiceException wrapping any underlying <code>Exception</code>s */ @Override public void doService(AdaptrisMessage msg) throws ServiceException { try { long waitMs = waitMs(); log.trace("Waiting for [{}] ms; waking up at approx. {}", waitMs, DateFormat.getDateTimeInstance().format(new Date(System.currentTimeMillis() + waitMs))); Thread.sleep(waitMs); } catch (InterruptedException e) { handleInterrupt(e); } }
From source file:org.codekaizen.vtj.text.BpDateFormatTest.java
/** * DOCUMENT ME!//w ww . j a va 2 s.c o m */ public void testFormatting() { DateFormat fmt1 = null; DateFormat fmt2 = null; Date date = null; String s1 = null; String s2 = null; date = new Date(); fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_TIME, null); fmt2 = DateFormat.getDateTimeInstance(); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_ONLY, null); fmt2 = DateFormat.getDateInstance(DateFormat.SHORT); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_TIME_ONLY, null); fmt2 = DateFormat.getTimeInstance(DateFormat.SHORT); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_FULL_DATE, null); fmt2 = DateFormat.getDateInstance(DateFormat.FULL); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); fmt1 = new BpDateFormat(BpDateFormat.JVM_DATE_TIME, Locale.CANADA_FRENCH); fmt2 = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.CANADA_FRENCH); s1 = fmt1.format(date); s2 = fmt2.format(date); assertEquals(s2, s1); }
From source file:com.janacare.walkmeter.ActivityRecognitionIntentService.java
/** * Called when a new activity detection update is available. *//* w w w.j a va 2s .com*/ @Override protected void onHandleIntent(Intent intent) { Log.d("inside onStartUpdates", "got intent"); // Get a handle to the repository mPrefs = getApplicationContext().getSharedPreferences(ActivityUtils.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(ActivityUtils.APPTAG, getString(R.string.date_format_error)); } // Format the timestamp according to the pattern, then localize the pattern mDateFormat.applyPattern(DATE_FORMAT_PATTERN); mDateFormat.applyLocalizedPattern(mDateFormat.toLocalizedPattern()); // If the intent contains an update if (ActivityRecognitionResult.hasResult(intent)) { // Get the update ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); // Log the update logActivityRecognitionResult(result); countOnFootTime(result); // 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 confidence = mostProbableActivity.getConfidence(); // Get the type of activity int activityType = mostProbableActivity.getType(); // Check to see if the repository contains a previous activity if (!mPrefs.contains(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE)) { // This is the first type an activity has been detected. Store the type Editor editor = mPrefs.edit(); editor.putInt(ActivityUtils.KEY_PREVIOUS_ACTIVITY_TYPE, activityType); editor.commit(); // If the repository contains a type } else 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 // Disabling notifications //sendNotification(); } } }
From source file:com.otaupdater.ROMTab.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); cfg = Config.getInstance(getActivity().getApplicationContext()); HashMap<String, Object> item; item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.main_device)); item.put(KEY_SUMMARY, android.os.Build.DEVICE.toLowerCase(Locale.US)); item.put(KEY_ICON, R.drawable.ic_device); DATA.add(item);//from w w w.ja v a 2 s . c om item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.main_rom)); item.put(KEY_SUMMARY, android.os.Build.DISPLAY); item.put(KEY_ICON, R.drawable.ic_info_outline); DATA.add(item); String romVersion = PropUtils.getRomOtaVersion(); if (romVersion == null) romVersion = PropUtils.getRomVersion(); if (PropUtils.isRomOtaEnabled()) { Date romDate = PropUtils.getRomOtaDate(); if (romDate != null) { romVersion += " (" + DateFormat.getDateTimeInstance().format(romDate) + ")"; } item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.rom_version)); item.put(KEY_SUMMARY, romVersion); item.put(KEY_ICON, R.drawable.ic_settings); DATA.add(item); item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.main_otaid)); item.put(KEY_SUMMARY, PropUtils.getRomOtaID()); item.put(KEY_ICON, R.drawable.ic_key); DATA.add(item); item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.updates_avail_title)); if (cfg.hasStoredRomUpdate()) { RomInfo info = cfg.getStoredRomUpdate(); if (info.isUpdate()) { item.put(KEY_SUMMARY, getString(R.string.updates_new, info.name, info.version)); } else { item.put(KEY_SUMMARY, getString(R.string.updates_none)); cfg.clearStoredRomUpdate(); } } else { item.put(KEY_SUMMARY, getString(R.string.updates_none)); } item.put(KEY_ICON, R.drawable.ic_cloud_download); AVAIL_UPDATES_IDX = DATA.size(); DATA.add(item); } else { if (cfg.hasStoredRomUpdate()) cfg.clearStoredRomUpdate(); if (!romVersion.equals(Build.DISPLAY)) { item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.rom_version)); item.put(KEY_SUMMARY, romVersion); item.put(KEY_ICON, R.drawable.ic_settings); DATA.add(item); } item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.rom_unsupported)); item.put(KEY_SUMMARY, getString(R.string.rom_unsupported_summary)); item.put(KEY_ICON, R.drawable.ic_cloud_off); DATA.add(item); } }
From source file:com.otaupdater.KernelTab.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); cfg = Config.getInstance(getActivity().getApplicationContext()); HashMap<String, Object> item; item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.main_device)); item.put(KEY_SUMMARY, android.os.Build.DEVICE.toLowerCase(Locale.US)); item.put(KEY_ICON, R.drawable.ic_device); DATA.add(item);/*from w w w.j a v a 2 s . com*/ item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.main_kernel)); item.put(KEY_SUMMARY, PropUtils.getKernelVersion()); item.put(KEY_ICON, R.drawable.ic_info_outline); DATA.add(item); if (PropUtils.isKernelOtaEnabled()) { String kernelVersion = PropUtils.getKernelOtaVersion(); if (kernelVersion == null) kernelVersion = getString(R.string.kernel_version_unknown); Date kernelDate = PropUtils.getKernelOtaDate(); if (kernelDate != null) { kernelVersion += " (" + DateFormat.getDateTimeInstance().format(kernelDate) + ")"; } item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.kernel_version)); item.put(KEY_SUMMARY, kernelVersion); item.put(KEY_ICON, R.drawable.ic_settings); DATA.add(item); item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.main_otaid)); item.put(KEY_SUMMARY, PropUtils.getKernelOtaID()); item.put(KEY_ICON, R.drawable.ic_key); DATA.add(item); item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.updates_avail_title)); if (cfg.hasStoredKernelUpdate()) { KernelInfo info = cfg.getStoredKernelUpdate(); if (info.isUpdate()) { item.put(KEY_SUMMARY, getString(R.string.updates_new, info.name, info.version)); } else { item.put(KEY_SUMMARY, getString(R.string.updates_none)); cfg.clearStoredKernelUpdate(); } } else { item.put(KEY_SUMMARY, getString(R.string.updates_none)); } item.put(KEY_ICON, R.drawable.ic_cloud_download); AVAIL_UPDATES_IDX = DATA.size(); DATA.add(item); } else { if (cfg.hasStoredKernelUpdate()) cfg.clearStoredKernelUpdate(); item = new HashMap<String, Object>(); item.put(KEY_TITLE, getString(R.string.kernel_unsupported)); item.put(KEY_SUMMARY, getString(R.string.kernel_unsupported_summary)); item.put(KEY_ICON, R.drawable.ic_cloud_off); DATA.add(item); } }
From source file:com.messagesight.mqtthelper.MqttHandler.java
public void deliveryComplete(IMqttDeliveryToken token) { String time = "<" + DateFormat.getDateTimeInstance().format(new Date()) + ">"; String publish = time + ":" + Publish.currTopic + "<P>: " + Publish.currMessage + "\n"; MyActivity.logScreen.append(publish); Toast toast = Toast.makeText(ctx, publish, Toast.LENGTH_SHORT); toast.show();/*w w w. j a v a2 s .c o m*/ }