List of usage examples for java.util Timer schedule
public void schedule(TimerTask task, Date time)
From source file:Main.java
public static void delayToActivity(final Context context, final Class<?> cls, long delay) { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override//from w w w. j a v a2s. com public void run() { context.startActivity(new Intent(context, cls)); } }, delay); }
From source file:Main.java
public static void showInputMethodManager(final EditText editText) { Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { InputMethodManager inputManager = (InputMethodManager) editText.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(editText, 0); }//ww w . ja v a 2 s . c o m }, 200); }
From source file:Main.java
public static Timer setTimeOut(final Runnable runnable, int delayMillis) { final Handler handler = new Handler(); final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override/*from www . jav a 2 s . c o m*/ public void run() { handler.post(runnable); timer.cancel(); } }, delayMillis); return timer; }
From source file:Main.java
public static void showSoftInput(final Context context, final EditText et) { Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { InputMethodManager inputManager = (InputMethodManager) context .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(et, 0); }/*from w w w. jav a 2 s . com*/ }, 998); }
From source file:xtrememp.update.SoftwareUpdate.java
public static void scheduleCheckForUpdates(long delay) { Timer timer = new Timer(); timer.schedule(new CheckForUpdatesTask(), delay); }
From source file:com.offbynull.portmapper.common.ProcessUtils.java
/** * Run a process and dump the stdout stream to a string. * @param timeout maximum amount of time the process can take to run * @param command command/*from ww w . j a v a 2 s . c om*/ * @param args arguments * @return stdout from the process dumped to a string * @throws IOException if the process encounters an error * @throws NullPointerException if any arguments are {@code null} or contains {@code null} * @throws IllegalArgumentException any numeric argument is negative */ public static String runProcessAndDumpOutput(long timeout, String command, String... args) throws IOException { Validate.notNull(command); Validate.noNullElements(args); Validate.inclusiveBetween(0L, Long.MAX_VALUE, timeout); String[] pbCmd = new String[args.length + 1]; pbCmd[0] = command; System.arraycopy(args, 0, pbCmd, 1, args.length); ProcessBuilder builder = new ProcessBuilder(pbCmd); final AtomicBoolean failedFlag = new AtomicBoolean(); Timer timer = new Timer("Process timeout timer", true); Process proc = null; try { proc = builder.start(); final Process finalProc = proc; timer.schedule(new TimerTask() { @Override public void run() { failedFlag.set(true); finalProc.destroy(); } }, timeout); String ret = IOUtils.toString(proc.getInputStream()); if (failedFlag.get()) { throw new IOException("Process failed"); } return ret; } finally { if (proc != null) { proc.destroy(); } timer.cancel(); timer.purge(); } }
From source file:deincraftlauncher.start.StartMinecraft.java
private static void checkAlive(Process launch, Modpack pack) { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override/* w w w.jav a 2 s.c o m*/ public void run() { if (!launch.isAlive()) { Platform.runLater(() -> { System.out.println("minecraft stopped, process is dead!"); pack.setPackstarted(false); pack.setStartState(PackViewHandler.StartState.Normal); pack.setStartText("Spielen"); }); } else { checkAlive(launch, pack); } } }, 3000); }
From source file:deincraftlauncher.start.StartMinecraft.java
public static void startMC(Modpack pack) { try {//from w w w . j ava 2 s .c om System.out.println("trying to start minecraft"); GameInfos infos = new GameInfos(pack.getName(), new File(pack.getPath()), new GameVersion(pack.getMCVersion(), pack.getGameType()), new GameTweak[] { GameTweak.FORGE }); System.out.println("GameInfos done"); System.out.println("Zugangsdaten: " + settings.getUsername() + settings.getPassword()); Authenticator authenticator = new Authenticator(Authenticator.MOJANG_AUTH_URL, AuthPoints.NORMAL_AUTH_POINTS); AuthResponse rep = authenticator.authenticate(AuthAgent.MINECRAFT, settings.getUsername(), settings.getPassword(), ""); AuthInfos authInfos = new AuthInfos(rep.getSelectedProfile().getName(), rep.getAccessToken(), rep.getSelectedProfile().getId()); System.out.println("authinfos done"); //AuthInfos authInfos = new AuthInfos(settings.getUsername(), MCAuthentication.getToken(settings.getUsername(), settings.getPassword()), MCAuthentication.getUUID(settings.getUsername(), settings.getPassword())); ExternalLaunchProfile profile = MinecraftLauncher.createExternalProfile(infos, getFolder(pack), authInfos); List<String> vmArgs = profile.getVmArgs(); vmArgs.add(String.valueOf("-Xms" + settings.getRAM() + "m")); //System.out.println("vm args: " + vmArgs); profile.setVmArgs(vmArgs); ExternalLauncher launcher = new MCLauncher(profile); System.out.println("profile and launcher done " + launcher.getProfile()); Process launch = launcher.launch(); BufferedReader stdout = new BufferedReader(new InputStreamReader(launch.getInputStream())); String line; while ((line = stdout.readLine()) != null) { System.out.println(line); } Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { Platform.runLater(() -> { System.out.println("minecraft started, changing start state"); pack.setStartState(PackViewHandler.StartState.Loading); pack.setStartText("gestartet"); }); } }, 8000); checkAlive(launch, pack); } catch (LaunchException | AuthenticationException | IOException ex) { Logger.getLogger(StartMinecraft.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.ikon.util.ExecutionUtils.java
/** * Execute command line: implementation//from w w w .ja v a2 s . com */ private static ExecutionResult runCmdImpl(final String cmd[], final long timeout) throws SecurityException, InterruptedException, IOException { log.debug("runCmdImpl({}, {})", Arrays.toString(cmd), timeout); ExecutionResult ret = new ExecutionResult(); long start = System.currentTimeMillis(); final ProcessBuilder pb = new ProcessBuilder(cmd); final Process process = pb.start(); Timer t = new Timer("Process Execution Timeout"); t.schedule(new TimerTask() { @Override public void run() { process.destroy(); log.warn("Process killed due to timeout."); log.warn("CommandLine: {}", Arrays.toString(cmd)); } }, timeout); try { ret.setStdout(IOUtils.toString(process.getInputStream())); ret.setStderr(IOUtils.toString(process.getErrorStream())); } catch (IOException e) { // Ignore } process.waitFor(); t.cancel(); ret.setExitValue(process.exitValue()); // Check return code if (ret.getExitValue() != 0) { log.warn("Abnormal program termination: {}", ret.getExitValue()); log.warn("CommandLine: {}", Arrays.toString(cmd)); log.warn("STDERR: {}", ret.getStderr()); } else { log.debug("Normal program termination"); } process.destroy(); log.debug("Elapse time: {}", FormatUtil.formatSeconds(System.currentTimeMillis() - start)); return ret; }
From source file:net.frygo.findmybuddy.GCMIntentService.java
private static void generateNotification(Context context, String message) { Random rand = new Random(); int x = rand.nextInt(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, customlistview.class); notificationIntent.putExtra("alert", message); message = message + " would like to add you as friend"; PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(x, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title); mWakelock.acquire();/*ww w.j av a2 s.c o m*/ // 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); }