Example usage for java.util Timer schedule

List of usage examples for java.util Timer schedule

Introduction

In this page you can find the example usage for java.util Timer schedule.

Prototype

public void schedule(TimerTask task, Date time) 

Source Link

Document

Schedules the specified task for execution at the specified time.

Usage

From source file:org.matrix.androidsdk.fragments.MatrixMessageListFragment.java

/**
 * The media upload fails.//from w w  w.  j  a v  a2s  . c  o m
 *
 * @param serverResponseCode the response code.
 * @param serverErrorMessage the error message.
 * @param messageRow         the messageRow
 */
private void commonMediaUploadError(int serverResponseCode, final String serverErrorMessage,
        final MessageRow messageRow) {
    // warn the user that the media upload fails
    if (serverResponseCode == 500) {
        Timer relaunchTimer = new Timer();
        mPendingRelaunchTimersByEventId.put(messageRow.getEvent().eventId, relaunchTimer);
        relaunchTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                if (mPendingRelaunchTimersByEventId.containsKey(messageRow.getEvent().eventId)) {
                    mPendingRelaunchTimersByEventId.remove(messageRow.getEvent().eventId);

                    Handler handler = new Handler(Looper.getMainLooper());
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            resend(messageRow.getEvent());
                        }
                    });
                }
            }
        }, 1000);
    } else {
        messageRow.getEvent().mSentState = Event.SentState.UNDELIVERABLE;
        onMessageSendingFailed(messageRow.getEvent());

        if (null != getActivity()) {
            Toast.makeText(getActivity(), (null != serverErrorMessage) ? serverErrorMessage
                    : getString(R.string.message_failed_to_upload), Toast.LENGTH_LONG).show();
        }
    }
}

From source file:self.philbrown.droidQuery.$.java

/**
 * Schedule a task for single execution after a specified delay.
 * @param function the task to schedule. Receives no args. Note that the function will be
 * run on the thread on this method was called.
 * @param delay amount of time in milliseconds before execution.
 * @return the created Timer/* www .  j  av  a  2 s.  c  o m*/
 */
public static Timer setTimeout(final Function function, long delay) {
    Timer t = new Timer();
    final Handler h = new Handler();
    t.schedule(new TimerTask() {

        @Override
        public void run() {
            h.post(new Runnable() {
                @Override
                public void run() {
                    function.invoke(null);
                }
            });

        }

    }, delay);
    return t;
}

From source file:com.xilinx.ultrascale.gui.MainScreen_video.java

private void videoplayButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_videoplayButtonActionPerformed

    // TODO add your handling code here:
    if (videoplayButton.getText().equalsIgnoreCase("Start")) {
        if (screenMode == 2 && ddrledState == 0) {// check for gencheck with card ddr.
            JOptionPane.showMessageDialog(this, "DDR4 not calibrated. Could not start the test.");
            return;
        }// w  w  w  .  j a  v a2  s  . c  o m
        // conditional check for min and max
        if (pathFied.getText().length() == 0) {
            Object[] options1 = { "Ok" };
            int s = JOptionPane.showOptionDialog(null, "Please choose Video file path", " ",
                    JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options1, null);
            return;
        }
        if (Integer.parseInt(mincoeff.getValue().toString()) > Integer
                .parseInt(maxcoeff.getValue().toString())) {
            Object[] options1 = { "Ok" };
            int s = JOptionPane.showOptionDialog(null, "Min Threshold should always be less than Max Threshold",
                    " ", JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE, null, options1, null);
            return;
        }
        // showing the videos panel

        //videoFrame.setLocationRelativeTo(this);
        videoFrame.setVisible(true);
        frame1.setVisible(true);
        frame2.setVisible(true);
        rxMediaPlayer.getMediaPlayer().playMedia("v4l2:///dev/video0");

        di.startVideoTest(0, 7, Integer.parseInt(mincoeff.getValue().toString()),
                Integer.parseInt(maxcoeff.getValue().toString()), invertcheckbox.isSelected() ? 1 : 0, 7680);

        Timer timers = new java.util.Timer();
        timers.schedule(new TimerTask() {
            @Override
            public void run() {
                txMediaPlayer.getMediaPlayer().playMedia(pathFied.getText());
                txMediaPlayer.getMediaPlayer().setRepeat(true);
            }
        }, 2000);

        //            txMediaPlayer.setRate((float) 16.0);
        messageLog2.append(">> Test Started\n");
        videoPauseButton.setEnabled(true);
        videoPauseButton.setText("Pause");
        videoplayButton.setText("Stop");
        pathFied.setEnabled(false);
        browseButton.setEnabled(false);
        //            mincoeff.setEnabled(false);
        //            maxcoeff.setEnabled(false);
        //            invertcheckbox.setEnabled(false);
        testStarted = true;

        //BGWorker worker1 = new BGWorker("./run_receive_vlc.sh");
        //worker1.execute();
        //            pworker = new ProcessWorker("./run_receive_vlc.sh");
        //            pworker.execute();
        //            try {
        //                Thread.sleep(500);
        //            } catch (InterruptedException ex) {
        //                Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
        //            }
        //            worker = new BGWorker("./util/run_vlc.sh" + " start " + pathFied.getText());
        //            worker.execute();
        //            try {
        //                Thread.sleep(500);
        //            } catch (InterruptedException ex) {
        //                Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
        //            }
    } else {
        testStarted = false;
        videoplayButton.setText("Wait");
        videoPauseButton.setEnabled(false);
        di.stopVideoTest(0, 7, 7680);
        //            if (worker1 != null){
        //                worker1.cancel(true);
        //                worker1 = null;
        //            }
        //            
        //            if(worker != null){
        //                worker.cancel(true);
        //                worker = null;
        //            }
        //            BGWorker worker1 = new BGWorker("./util/run_vlc.sh exit");
        //            worker1.execute();

        //pworker.p.destroy();
        txMediaPlayer.getMediaPlayer().stop();
        rxMediaPlayer.getMediaPlayer().stop();
        videoFrame.setVisible(false);
        frame1.setVisible(false);
        frame2.setVisible(false);

        pathFied.setEnabled(true);
        browseButton.setEnabled(true);
        //            mincoeff.setEnabled(true);
        //            maxcoeff.setEnabled(true);
        //            invertcheckbox.setEnabled(true);

        axiTxTextField4.setText("0.000");
        axiRxTextField4.setText("0.000");
        //            ddrRxTextField.setText("0.000");
        //            ddrTxTextField.setText("0.000");

        pcieTxTextField4.setText("0.000");
        pcieRxTextField4.setText("0.000");
        messageLog2.append(">> Test Stopped\n");
        //            try {
        //                Thread.sleep(15000);
        //            } catch (InterruptedException ex) {
        //                Logger.getLogger(MainScreen.class.getName()).log(Level.SEVERE, null, ex);
        //            }
        // disable button until the vlc rec window close.
        videoplayButton.setEnabled(false);
        Timer timers = new java.util.Timer();
        timers.schedule(new TimerTask() {
            @Override
            public void run() {
                enablePlayButton();
            }
        }, 3000);
    }

}

From source file:net.bashtech.geobot.ReceiverBot.java

private void secondaryTO(final String channel, final String name, final int duration, FilterType type,
        String message) {/*from   w w  w  .ja v  a2s.c o  m*/

    String line = "FILTER: Issuing a timeout on " + name + " in " + channel + " for " + type.toString() + " ("
            + duration + ")";
    logMain(line);
    line = "FILTER: Affected Message: " + message;
    logMain(line);

    int iterations = BotManager.getInstance().multipleTimeout;

    for (int i = 0; i < iterations; i++) {
        Timer timer = new Timer();
        int delay = 1000 * i;
        timer.schedule(new TimerTask() {
            public void run() {
                ReceiverBot.this.sendCommand(channel, ".timeout " + name + " " + duration);
            }
        }, delay);
    }

}

From source file:net.bashtech.geobot.ReceiverBot.java

private void secondaryBan(final String channel, final String name, FilterType type) {

    String line = "RB: Issuing a ban on " + name + " in " + channel + " for " + type.toString();
    logMain(line);//  ww w. j av  a  2s . co m

    int iterations = BotManager.getInstance().multipleTimeout;
    for (int i = 0; i < iterations; i++) {
        Timer timer = new Timer();
        int delay = 1000 * i;
        System.out.println("Delay: " + delay);
        timer.schedule(new TimerTask() {
            public void run() {
                ReceiverBot.this.sendCommand(channel, ".ban " + name);
            }
        }, delay);
    }

}