List of usage examples for java.util Timer schedule
public void schedule(TimerTask task, Date time)
From source file:com.bstek.dorado.web.loader.DoradoLoader.java
public synchronized void load(ServletContext servletContext) throws Exception { if (!preloaded) { throw new IllegalStateException("Can not load dorado services before base configurations loaded."); }/*www . java 2s. co m*/ if (loaded) { throw new IllegalStateException("Dorado services already loaded."); } loaded = true; EngineStartupListenerManager.notifyStartup(); ConsoleStartedMessagesOutputter consoleStartedMessagesOutputter = (ConsoleStartedMessagesOutputter) DoradoContext .getCurrent().getServiceBean("consoleStartedMessagesOutputter"); StringWriter buffer = new StringWriter(); try { consoleStartedMessagesOutputter.output(buffer); } finally { buffer.close(); } DoradoContext.dispose(); Timer timer = new Timer(); timer.schedule(new ConsoleMessageTimerTask(buffer.toString()), 500L); }
From source file:com.example.demo_highlights.slidingmenu.activity.SlidingActivity.java
private void exitBy2Click() { Timer tExit = null; if (isExit == false) { isExit = true; // // Toast.makeText(this, "??", Toast.LENGTH_SHORT).show(); IJettyToast.showQuickToast(SlidingActivity.this, R.string.twice_quit); tExit = new Timer(); tExit.schedule(new TimerTask() { @Override/*from w ww . j a va 2 s. c o m*/ public void run() { isExit = false; // ? } }, 2000); // 2??? } else { finish(); // System.exit(0); } }
From source file:com.snappy.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. */// w ww . j a va 2s . c o m private void generateNotification(Context context, String message, String fromName, Bundle pushExtras, String body) { db = new LocalDB(context); List<LocalMessage> myMessages = db.getAllMessages(); // Open a new activity called GCMMessageView Intent intento = new Intent(this, SplashScreenActivity.class); intento.replaceExtras(pushExtras); // Pass data to the new activity intento.putExtra(Const.PUSH_INTENT, true); intento.setAction(Long.toString(System.currentTimeMillis())); intento.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); // Starts the activity on notification click PendingIntent pIntent = PendingIntent.getActivity(this, 0, intento, PendingIntent.FLAG_UPDATE_CURRENT); // Create the notification with a notification builder NotificationCompat.Builder notification = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.icon_notification).setWhen(System.currentTimeMillis()) .setContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)) .setStyle(new NotificationCompat.BigTextStyle().bigText("Mas mensajes")).setAutoCancel(true) .setDefaults( Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS) .setContentText(body).setContentIntent(pIntent); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(myMessages.size() + " " + this.getString(R.string.push_new_message_message)); for (int i = 0; i < myMessages.size(); i++) { inboxStyle.addLine(myMessages.get(i).getMessage()); } notification.setStyle(inboxStyle); // Remove the notification on click //notification.flags |= Notification.FLAG_AUTO_CANCEL; //notification.defaults |= Notification.DEFAULT_VIBRATE; //notification.defaults |= Notification.DEFAULT_SOUND; //notification.defaults |= Notification.DEFAULT_LIGHTS; NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(R.string.app_name, notification.build()); { // Wake Android Device when notification received PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "GCM_PUSH"); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); } }
From source file:cn.edu.sdu.online.activity.FragmentTabsPager.java
private void exitBy2Click() { Timer tExit = null; if (isExit == false) { isExit = true; // Toast.makeText(this, "??", Toast.LENGTH_SHORT).show(); tExit = new Timer(); tExit.schedule(new TimerTask() { @Override/* w w w.ja v a 2 s .c om*/ public void run() { isExit = false; // ? } }, 2000); // 2??? } else { finish(); } }
From source file:de.baumann.thema.FragmentSound.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.sound, container, false); setHasOptionsMenu(true);//from w w w.ja v a2 s. co m final String[] itemTITLE = { "Ouverture - Hymne" + " (Steven Testelin)" + " | " + getString(R.string.duration) + " 01:49", "Canon and Gigue in D major" + " | " + getString(R.string.duration) + " 00:45", "Epic" + " (Alexey Anisimov)" + " | " + getString(R.string.duration) + " 01:53", "Isn't it" + " | " + getString(R.string.duration) + " 00:01", "Jingle Bells Sms" + " | " + getString(R.string.duration) + " 00:04", "Wet" + " | " + getString(R.string.duration) + " 00:01", }; final String[] itemURL = { Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/hymne.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/canon.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/epic.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/isnt_it.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/jingle_bells_sms.mp3", Environment.getExternalStorageDirectory() + "/Android/data/de.baumann.thema/wet.mp3", }; final String[] itemDES = { "CC license: https://www.jamendo.com/track/1004091/ouverture-hymne", "CC license: https://musopen.org/music/2672/johann-pachelbel/canon-and-gigue-in-d-major/", "CC license: https://www.jamendo.com/track/1344095/epic", "CC license: https://notificationsounds.com/standard-ringtones/isnt-it-524", "CC license: https://notificationsounds.com/message-tones/jingle-bells-sms-523", "CC license: https://notificationsounds.com/notification-sounds/wet-431", }; final String[] itemFN = { "hymne.mp3", "canon.mp3", "epic.mp3", "isnt_it.mp3", "jingle_bells_sms.mp3", "wet.mp3", }; CustomListAdapter_Sound adapter = new CustomListAdapter_Sound(getActivity(), itemTITLE, itemURL, itemDES, itemDES); listView = (ListView) rootView.findViewById(R.id.bookmarks); listView.setAdapter(adapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub String Selecteditem = itemURL[+position]; final MediaPlayer mp = MediaPlayer.create(getActivity(), Uri.parse(Selecteditem)); mp.start(); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { mp.stop(); } }, 5000); } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final String SelecteditemMes = itemTITLE[+position]; final String Selecteditem = itemURL[+position]; final String SelecteditemTitle = itemFN[+position]; final String SelecteditemUrl = itemDES[+position].substring(12); final CharSequence[] options = { getString(R.string.set_ringtone), getString(R.string.set_notification), getString(R.string.set_alarm), getString(R.string.play), getString(R.string.open) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.set_ringtone))) { File directory_al = new File( Environment.getExternalStorageDirectory() + "/Ringtones/"); if (!directory_al.exists()) { directory_al.mkdirs(); } try { InputStream in; OutputStream out; in = new FileInputStream(Selecteditem); out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Ringtones/" + SelecteditemTitle); byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); // write the output file out.flush(); out.close(); MediaScannerConnection.scanFile(getActivity(), new String[] { Environment.getExternalStorageDirectory() + "/Ringtones/" + SelecteditemTitle }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { Intent intent2 = new Intent(Settings.ACTION_SOUND_SETTINGS); intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getActivity().startActivity(intent2); } }); } catch (Exception e) { Log.e("tag", e.getMessage()); } } else if (options[item].equals(getString(R.string.set_notification))) { File directory_al = new File( Environment.getExternalStorageDirectory() + "/Notifications/"); if (!directory_al.exists()) { directory_al.mkdirs(); } try { InputStream in; OutputStream out; in = new FileInputStream(Selecteditem); out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Notifications/" + SelecteditemTitle); byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); // write the output file out.flush(); out.close(); MediaScannerConnection.scanFile(getActivity(), new String[] { Environment.getExternalStorageDirectory() + "/Notifications/" + SelecteditemTitle }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { Intent intent2 = new Intent(Settings.ACTION_SOUND_SETTINGS); intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getActivity().startActivity(intent2); } }); } catch (Exception e) { Log.e("tag", e.getMessage()); } } else if (options[item].equals(getString(R.string.set_alarm))) { File directory_al = new File( Environment.getExternalStorageDirectory() + "/Alarms/"); if (!directory_al.exists()) { directory_al.mkdirs(); } try { InputStream in; OutputStream out; in = new FileInputStream(Selecteditem); out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Alarms/" + SelecteditemTitle); byte[] buffer = new byte[1024]; int read; while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); // write the output file out.flush(); out.close(); MediaScannerConnection.scanFile(getActivity(), new String[] { Environment.getExternalStorageDirectory() + "/Alarms/" + SelecteditemTitle }, null, new MediaScannerConnection.OnScanCompletedListener() { @Override public void onScanCompleted(String path, Uri uri) { Snackbar.make(listView, R.string.set_alarm_suc, Snackbar.LENGTH_LONG).show(); } }); } catch (Exception e) { Log.e("tag", e.getMessage()); } Snackbar.make(listView, getString(R.string.set_alarm_suc), Snackbar.LENGTH_LONG) .show(); } else if (options[item].equals(getString(R.string.play))) { final MediaPlayer mp = MediaPlayer.create(getActivity(), Uri.parse(Selecteditem)); new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.play)) .setMessage(SelecteditemMes).setPositiveButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { mp.stop(); dialog.cancel(); } }) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mp.stop(); dialog.cancel(); } }).show(); mp.start(); } else if (options[item].equals(getString(R.string.open))) { Uri uri = Uri.parse(SelecteditemUrl); // missing 'http://' will cause crashed Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } } }).show(); return true; } }); return rootView; }
From source file:org.sakaiproject.component.impl.SpringCompMgr.java
/** * Initialize the component manager.//from w ww .ja va 2 s .c o m * * @param lateRefresh If <code>true</code> then don't refresh the application context * but leave it up to the caller, this is useful when running tests as it means you * can change the application context before everything gets setup. In production * systems it should be <code>false</code>. */ public void init(boolean lateRefresh) { if (m_ac != null) return; // Make sure a "sakai.home" system property is set. ensureSakaiHome(); checkSecurityPath(); m_ac = new SakaiApplicationContext(); m_ac.setInitialSingletonNames(CONFIGURATION_COMPONENTS); List<String> configLocationList = new ArrayList<String>(); configLocationList.add(DEFAULT_CONFIGURATION_FILE); String localConfigLocation = System.getProperty("sakai.home") + CONFIGURATION_FILE_NAME; File configFile = new File(localConfigLocation); if (configFile.exists()) { configLocationList.add("file:" + localConfigLocation); } m_ac.setConfigLocations(configLocationList.toArray(new String[0])); // load component packages loadComponents(); // if configured (with the system property CLOSE_ON_SHUTDOWN set), // create a shutdown task to close when the JVM closes // (otherwise we will close in removeChildAc() when the last child is gone) if (System.getProperty(CLOSE_ON_SHUTDOWN) != null) { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { close(); } }); } // skip during tests if (!lateRefresh) { try { // get the singletons loaded m_ac.refresh(); m_ac.publishEvent(new SakaiComponentEvent(this, SakaiComponentEvent.Type.STARTED)); } catch (Exception e) { if (Boolean.valueOf(System.getProperty(SHUTDOWN_ON_ERROR, "false"))) { M_log.fatal(e.getMessage(), e); M_log.fatal("Shutting down JVM"); System.exit(1); } else { M_log.error(e.getMessage(), e); } } // dump the configuration values out try { final ServerConfigurationService scs = (ServerConfigurationService) this .get(ServerConfigurationService.class); if (scs != null) { ConfigData cd = scs.getConfigData(); M_log.info("Configuration loaded " + cd.getTotalConfigItems() + " values, " + cd.getRegisteredConfigItems() + " registered"); if (scs.getBoolean("config.dump.to.log", false)) { // output the config logs now and then output then again in 120 seconds M_log.info("Configuration values:\n" + cd.toString()); Timer timer = new Timer(true); timer.schedule(new TimerTask() { @Override public void run() { M_log.info("Configuration values: (delay 1):\n" + scs.getConfigData().toString()); } }, 120 * 1000); timer.schedule(new TimerTask() { @Override public void run() { M_log.info("Configuration values: (delay 2):\n" + scs.getConfigData().toString()); } }, 300 * 1000); } } else { // probably testing so just say we cannot dump the config M_log.warn( "Configuration: Unable to get and dump out the registered server config values because no ServerConfigurationService is available - this is OK if this is part of a test, this is very bad otherwise"); } } catch (Exception e) { M_log.error( "Configuration: Unable to get and dump out the registered server config values (config.dump.to.log): " + e, e); } } }
From source file:im.vector.receiver.VectorUniversalLinkReceiver.java
/** * Start the universal link management when the login process is done. * If there is no active activity, launch the home activity * * @param aContext the context.//from ww w.j a va 2s. com */ private void manageRoomOnActivity(final Context aContext) { final Activity currentActivity = VectorApp.getCurrentActivity(); if (null != currentActivity) { currentActivity.runOnUiThread(new Runnable() { @Override public void run() { manageRoom(aContext); } }); } else { // clear the activity stack to home activity Intent intent = new Intent(aContext, VectorHomeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(VectorHomeActivity.EXTRA_WAITING_VIEW_STATUS, VectorHomeActivity.WAITING_VIEW_START); aContext.startActivity(intent); try { final Timer wakeup = new Timer(); wakeup.schedule(new TimerTask() { @Override public void run() { wakeup.cancel(); manageRoomOnActivity(aContext); } }, 200); } catch (Throwable throwable) { Log.e(LOG_TAG, "## manageRoomOnActivity timer creation failed " + throwable.getMessage()); manageRoomOnActivity(aContext); } } }
From source file:net.czlee.debatekeeper.AlertManager.java
/** * Flashes the screen once. The most atomic flash screen action. * @param flashTime how long in milliseconds to flash the screen for * @param colour colour to flash screen//w ww . ja v a 2 s . c o m * @param lastFlash <code>true</code> if the GUI should be reset after this single flash */ private void startSingleFlashScreen(long flashTime, final int colour, final boolean lastFlash) { if (mFlashScreenListener == null) return; // Flash the screen white and set a timer to turn it back normal after half a second mFlashScreenListener.flashScreenOn(colour); Timer offTimer = new Timer(); offTimer.schedule(new TimerTask() { @Override public void run() { mFlashScreenListener.flashScreenOff(); if (lastFlash) mFlashScreenListener.done(); } }, flashTime); }
From source file:eu.europa.ejusticeportal.dss.applet.DssApplet.java
/** * DssApplet initialisation ://from w ww . j ava2s .co m * <ul> * <li>[0] Register event listener.</li> * <li>[1] Initialize the component allowing the Applet to evaluate JavaScript. </li> * <li>[2] Initialise the password input factory for token. </li> * <li>[3] Initialise the FileChooser implementation. </li> * <li>[4] Check the privilege of the DssApplet. </li> * <li>[5] Get parameters from the browser. </li> * <li>[6] Asynchronous call to server : asynchGetMessages, asynchGetSealedPdf. </li> * <li>[7] Detect the fingerprint and refresh the signing context.</li> * <li>[8] Activate the UI.</li> * </ul> * * @throws RuntimeException if the init() method results by a * RuntimeException, the Applet stop by calling * the initFailure method. * * {@inheritDoc} */ @Override public void init() { //preload libraries preloadLibraries(); init(null, null, true); LOG.info("Managed exit code is " + managedExitCode); Timer t = new Timer("Version Checker", true); t.schedule(new JreVersionChecker(), VERSION_CHECK_DELAY); }
From source file:kr.co.cashqc.MainActivity.java
public void findLocation() { mDialog.show();/* w ww. j av a 2 s .c o m*/ mLocationUtil.start(); TimerTask timerTask = new TimerTask() { public void run() { mHandler.post(new Runnable() { public void run() { try { String address; address = mLocationUtil.getAddress(mLocationUtil.getLastLocation().getLatitude(), mLocationUtil.getLastLocation().getLongitude()); // Log.d("tag", mAddressText.getText().toString() + // " " // + mAddressText.getText().toString().length()); mAddressText.setVisibility(View.VISIBLE); mLatitude = mLocationUtil.getLastLocation().getLatitude(); mLongitude = mLocationUtil.getLastLocation().getLongitude(); mAddressText.setText(address); mGpsFlag = true; mDialog.dismiss(); } catch (NullPointerException e) { Log.d("JAY", "gps exception"); e.printStackTrace(); mAddressText.setText("<- ? ? ."); mDialog.dismiss(); mGpsFlag = false; } } }); } }; if (mLocationUtil.isRunLocationUtil) { mLocationUtil.stop(); } Timer timer = new Timer(); timer.schedule(timerTask, 1000); }