Java Code Examples for java.util.Timer.schedule()

The following are Jave code examples for showing how to use schedule() of the java.util.Timer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: yaacc-code   File: LocalBackgoundMusicPlayer.java   View Source Code Vote up 6 votes
@Override
protected void doResume() {
    commandExecutionTimer = new Timer();
    commandExecutionTimer.schedule(new TimerTask() {

        @Override
        public void run() {
            Intent intent = new Intent();
            intent.setAction(BackgroundMusicBroadcastReceiver.ACTION_PLAY);
            getContext().sendBroadcast(intent);

        }
    }, 600L);
    int timeLeft = getBackgroundService().getDuration() - getBackgroundService().getCurrentPosition();
    Log.d(this.getClass().getName(), "TimeLeft after resume: " + timeLeft + " duration: " + getBackgroundService().getDuration() + " curPos: " + getBackgroundService().getCurrentPosition());
    startTimer(timeLeft + getSilenceDuration());
}
 
Example 2
Project: BrewBook   File: Splash.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            finish();

            startActivity(new Intent(Splash.this, LoginActivity.class));
        }
    };
    Timer opening = new Timer( );
    opening.schedule(task,2000);
}
 
Example 3
Project: PicShow-zhaipin   File: InitStartActivity.java   View Source Code Vote up 6 votes
public void startMp4(File f) {
    mVideoFragment = VideoFragment.newInstance(f.getPath(), true);
    transaction.add(R.id.init_frame, mVideoFragment, "initVideo").commit();
    exitTimer = new Timer();
    exitTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            videoTime--;
            InitStartActivity.this.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (exitInit != null) {
                        exitInit.setText(mWeApplication.getResources().getString(R.string.exit_init) + videoTime);
                        if (videoTime <= 0) {
                            HomeActivity.show(InitStartActivity.this);
                            InitStartActivity.this.finish();
                        }
                    }
                }
            });

        }
    }, 0, 1 * 1000);
}
 
Example 4
Project: openrasp   File: AlarmHttpAppender.java   View Source Code Vote up 6 votes
@Override
public void activateOptions() {
    connectionTimeout = connectionTimeout < DEFAULT_CONNECTION_TIMEOUT ? DEFAULT_CONNECTION_TIMEOUT : connectionTimeout;
    readTimeout = readTimeout < DEFAULT_READ_TIMEOUT ? DEFAULT_READ_TIMEOUT : readTimeout;
    cacheFlushTime = cacheFlushTime < DEFAULT_CACHE_FLUSH_TIME ? DEFAULT_CACHE_FLUSH_TIME : cacheFlushTime;
    maxCacheSize = maxCacheSize < EventCache.DEFAULT_MAX_SIZE ? EventCache.DEFAULT_MAX_SIZE : maxCacheSize;
    eventCache.setSize(maxCacheSize);
    Timer timer = new Timer("async-http-appender-daemon",true);
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            sendEventsAsync();
        }
    }, cacheFlushTime, cacheFlushTime);

}
 
Example 5
Project: Amme   File: Stats.java   View Source Code Vote up 6 votes
public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
    String en = SQL.getValue(event.getGuild(),"joinchannel");
    Timer timer = new Timer();
    Date date=new Date();
    if (!event.getAuthor().isBot() && event.getAuthor().getId() != event.getJDA().getSelfUser().getId()) {
        count++;
    }

    timer.schedule(new TimerTask(){
        public void run(){
            if (!en.equals("0")) {
                event.getJDA().getTextChannelById(en).sendMessage("Today i count " + count + " Messages!").queue();
            }
        }
    },date, 24*60*60*1000);



}
 
Example 6
Project: Hydrograph   File: HydrographEngineCommunicatorSocket.java   View Source Code Vote up 6 votes
/**
 * Client onMessage get called to kill the job 
 * @param message
 * @param session
 */
@OnMessage
public void onMessage(String message, Session session) {
	logger.info("Trying to kill the job");
	final Timer timer = new Timer();
	TimerTask task = new TimerTask() {
		@Override
		public void run() {
			if (execution != null) {
				logger.info("Job killed successfully");
				execution.kill();
				timer.cancel();
			}
		}
			
	};
	timer.schedule(task, 0l, 600);
}
 
Example 7
Project: PaoMovie   File: LoadingActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
	// TODO Auto-generated method stub
	super.onCreate(savedInstanceState);
	if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
		// 透明状态栏
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
		// 透明导航栏
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
	}
	setContentView(R.layout.loading);
	final Intent intent = new Intent(this, App.class);
	intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	Timer timer = new Timer();
	TimerTask task = new TimerTask() {
		@Override
		public void run() {
			startActivity(intent);
			finish();
		}
	};
	timer.schedule(task, 1000);// 此处的Delay可以是3*1000,代表三秒
}
 
Example 8
Project: ScreenCut   File: ScreenCut.java   View Source Code Vote up 6 votes
private void saveFile(final File file) {
    isDraw = false;
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            try {
                image = robot.createScreenCapture(getNormalRect());
                String name = file.getName();
                ImageIO.write(image, name.substring(name.indexOf(".") + 1), file);
            } catch (IOException ex) {
                Logger.getLogger(ScreenCut.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                dispose();
            }
        }
    }, 50);
}
 
Example 9
Project: dswork   File: AuthFilter.java   View Source Code Vote up 6 votes
public void init(FilterConfig config) throws ServletException
{
	SYSTEM_REFRESH = getToLong(config.getInitParameter("refreshTime"), 3600000L);
	PAGE_NOACCESS = getToString(config.getInitParameter("forbiddenPage"), "");
	splitToSet(getToString(config.getInitParameter("ignorePage"), ""), PAGE_IGNORE);
	splitToSet(PAGE_NOACCESS, PAGE_IGNORE);
	CHECK_FIX = getToString(config.getInitParameter("fixSuffix"), "");
	isCheckParam = getToBoolean(config.getInitParameter("checkParam"), false);
	if(CHECK_FIX.length() > 0)
	{
		CHECK_FIX = "," + CHECK_FIX + ",";
		isCheckAllFix = false;
	}
	else
	{
		isCheckAllFix = true;
	}
	_timer = new Timer(true);
	// Timer.schedule(TimerTask task, Date date, long period)// 从date开始,每period毫秒执行task.
	_timer.schedule(_timerTask, 0, SYSTEM_REFRESH);// 从服务器启动开始运行,每period毫秒执行
}
 
Example 10
Project: CXJPadProject   File: SobotBaseActivity.java   View Source Code Vote up 6 votes
/**
 * 录音的时间控制
 */
public void startVoiceTimeTask(final Handler handler) {
	voiceTimerLong = 0;
	stopVoiceTimeTask();
	voiceTimer = new Timer();
	voiceTimerTask = new TimerTask() {
		@Override
		public void run() {
			// 需要做的事:发送消息
			sendVoiceTimeTask(handler);
		}
	};
	// 500ms进行定时任务
	voiceTimer.schedule(voiceTimerTask, 0, 500);

}
 
Example 11
Project: TestDemo1-github   File: TestThread.java   View Source Code Vote up 6 votes
public void init() throws ServletException{
	
	TimerTask task = new TimerTask() {
           @Override
           public void run() {
               System.out.println("task begin:" + getCurrentTime());
               try {
               	//需要执行的任务
               	
               	for (int i = 0; i < 10; i++) {
       				System.out.println("执行任务次数:"+i);
       				
       			}
               	
                   Thread.sleep(1000 * 20);//延迟20秒再执行下一步
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
               System.out.println("task end:" + getCurrentTime());
           }
       };
       Timer timer = new Timer();
       timer.schedule(task, buildTime(), 1000 * 60 * 60 * 24);
}
 
Example 12
Project: live_master   File: WatchLiveActivity.java   View Source Code Vote up 5 votes
private void openKeyboard() {

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

            }
        }, 200);
    }
 
Example 13
Project: GitHub   File: MainActivity.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    bnp = (NumberProgressBar)findViewById(R.id.numberbar1);
    bnp.setOnProgressBarListener(this);
    timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    bnp.incrementProgressBy(1);
                }
            });
        }
    }, 1000, 100);
}
 
Example 14
Project: Coconut-IDE   File: SaveTabsProcess.java   View Source Code Vote up 5 votes
private void schedule(Runnable r) {
    TimerTask task = new TimerTask() {
        public void run() {
            r.run();
        }
    };
    Timer timer = new Timer();
    timer.schedule(task, (long) 5000, (long) 5000);
}
 
Example 15
Project: OCast-Java   File: App.java   View Source Code Vote up 5 votes
private void moviePlaying(ApplicationController app, MediaController media) {
    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            media.stop( () -> stopApplication(app),errorLog);
        }
    }, PLAY_DURATION);
}
 
Example 16
Project: Coconut-IDE   File: TreeUpdater.java   View Source Code Vote up 5 votes
private void scheduleHighlight() {
    Timer timer = new Timer();
    TimerTask timerTask = new TimerTask() {
        @Override
        public void run() {
            HighlightCell.highlight();
        }
    };
    timer.schedule(timerTask, 50);
}
 
Example 17
Project: GCSApp   File: AddPhonePresenter.java   View Source Code Vote up 5 votes
public void timecount() {
    timer = new Timer();
    timerTask = new TimerTask() {
        @Override
        public void run() {
            if (stopTimer) {
                timer.cancel();
            } else {
                delegate.getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        secondcount--;
                        delegate.getSmsView().setClickable(false);
                        delegate.getSmsView().setText("已发送(" + secondcount + "S)");
                        if (secondcount == 0) {
                            secondcount = 60;
                            delegate.getSmsView().setClickable(true);
                            delegate.getSmsView().setText("获取验证码");
                            delegate.getSmsView().setClickable(true);
                            timer.cancel();
                        }
                    }
                });
            }

        }
    };
    timer.schedule(timerTask, 1000, 1000);
}
 
Example 18
Project: AliZhiBoHao   File: LiveCameraActivity.java   View Source Code Vote up 5 votes
/**
 * 轮询获取评论
 */
public void getComment() {
    timer_comment = new Timer();
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            Message message = mUIEventHandler.obtainMessage();
            message.what = UI_EVENT_GET_COMMENT;
            mUIEventHandler.sendMessage(message);
        }
    };
    timer_comment.schedule(task, 1000, 3000);
}
 
Example 19
Project: GCSApp   File: RegisterPresenter.java   View Source Code Vote up 5 votes
public void timecount() {
    timer = new Timer();
    timerTask = new TimerTask() {
        @Override
        public void run() {
            if (stopTimer) {
                timer.cancel();
            } else {
                delegate.getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        secondcount--;
                        delegate.getSmsView().setClickable(false);
                        delegate.getSmsView().setText("已发送(" + secondcount + "S)");
                        if (secondcount == 0) {
                            secondcount = 60;
                            delegate.getSmsView().setClickable(true);
                            delegate.getSmsView().setText("获取验证码");
                            delegate.getSmsView().setClickable(true);
                            timer.cancel();
                        }
                    }
                });
            }

        }
    };
    timer.schedule(timerTask, 1000, 1000);
}
 
Example 20
Project: COE1186   File: TrainModelGUI.java   View Source Code Vote up 4 votes
public void initializeAdvertisementTimer(){
		adTimer = new Timer();

		TimerTask updateAd = new updateAdvertisement();
    adTimer.schedule(updateAd, 0, 5000);// Toggle advertisement every 5 seconds
}