Search in sources :

Example 91 with TimerTask

use of java.util.TimerTask in project glitch-hq-android by tinyspeck.

the class SkillDetailFragment method InitUpdateSkillRemainingTimer.

private void InitUpdateSkillRemainingTimer() {
    if (m_RemainingTimer != null)
        m_RemainingTimer.cancel();
    m_RemainingTimer = new Timer();
    m_RemainingTimer.scheduleAtFixedRate(new TimerTask() {

        public void run() {
            FragmentActivity act = getActivity();
            if (act != null) {
                act.runOnUiThread(new Runnable() {

                    public void run() {
                        if (m_currentSkill.learning && !m_currentSkill.paused && !m_currentSkill.got && !m_fromUnlearn)
                            UpdateSkillDetailProgress();
                        else if (m_currentSkill.unlearning)
                            UpdateUnlearnDetailProgress();
                    }
                });
            }
        }
    }, 1000, 1000);
}
Also used : FragmentActivity(android.support.v4.app.FragmentActivity) Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 92 with TimerTask

use of java.util.TimerTask in project platform_frameworks_base by android.

the class LocationBasedCountryDetector method detectCountry.

/**
     * Start detecting the country.
     * <p>
     * Queries the location from all location providers, then starts a thread to query the
     * country from GeoCoder.
     */
@Override
public synchronized Country detectCountry() {
    if (mLocationListeners != null) {
        throw new IllegalStateException();
    }
    // Request the location from all enabled providers.
    List<String> enabledProviders = getEnabledProviders();
    int totalProviders = enabledProviders.size();
    if (totalProviders > 0) {
        mLocationListeners = new ArrayList<LocationListener>(totalProviders);
        for (int i = 0; i < totalProviders; i++) {
            String provider = enabledProviders.get(i);
            if (isAcceptableProvider(provider)) {
                LocationListener listener = new LocationListener() {

                    @Override
                    public void onLocationChanged(Location location) {
                        if (location != null) {
                            LocationBasedCountryDetector.this.stop();
                            queryCountryCode(location);
                        }
                    }

                    @Override
                    public void onProviderDisabled(String provider) {
                    }

                    @Override
                    public void onProviderEnabled(String provider) {
                    }

                    @Override
                    public void onStatusChanged(String provider, int status, Bundle extras) {
                    }
                };
                mLocationListeners.add(listener);
                registerListener(provider, listener);
            }
        }
        mTimer = new Timer();
        mTimer.schedule(new TimerTask() {

            @Override
            public void run() {
                mTimer = null;
                LocationBasedCountryDetector.this.stop();
                // Looks like no provider could provide the location, let's try the last
                // known location.
                queryCountryCode(getLastKnownLocation());
            }
        }, getQueryLocationTimeout());
    } else {
        // There is no provider enabled.
        queryCountryCode(getLastKnownLocation());
    }
    return mDetectedCountry;
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Location(android.location.Location)

Example 93 with TimerTask

use of java.util.TimerTask in project openhab1-addons by openhab.

the class HomematicBinding method informCommunicator.

/**
     * Schedules a job with a short delay to populate changed items to openHAB
     * after startup or an item reload.
     *
     * @see BindingChangedDelayedExecutor
     */
private void informCommunicator(HomematicBindingProvider hmProvider, String itemName) {
    final Item item = hmProvider.getItem(itemName);
    final HomematicBindingConfig bindingConfig = hmProvider.getBindingFor(itemName);
    if (bindingConfig != null) {
        delayedExecutor.cancel();
        delayedExecutor.addBindingConfig(item, bindingConfig);
        delayedExecutor.schedule(new TimerTask() {

            @Override
            public void run() {
                delayedExecutor.publishChangedBindings();
            }
        }, 3000);
    }
}
Also used : Item(org.openhab.core.items.Item) HomematicBindingConfig(org.openhab.binding.homematic.internal.config.binding.HomematicBindingConfig) TimerTask(java.util.TimerTask)

Example 94 with TimerTask

use of java.util.TimerTask in project openhab1-addons by openhab.

the class HomematicPublisher method execute.

/**
     * Sends or delays a event to a Homematic server.
     */
public void execute(final Event event) throws HomematicClientException {
    double delay = event.getDelay();
    if (delay > 0.0) {
        synchronized (this) {
            logger.debug("Delaying event for {} seconds: {}", delay, event.getHmValueItem());
            Timer timer = delayedEvents.get(event.getBindingConfig());
            if (timer != null) {
                timer.cancel();
            }
            timer = new Timer();
            delayedEvents.put(event.getBindingConfig(), timer);
            timer.schedule(new TimerTask() {

                @Override
                public void run() {
                    try {
                        delayedEvents.remove(event.getBindingConfig());
                        sendToClient(event);
                    } catch (Exception ex) {
                        logger.error(ex.getMessage(), ex);
                    }
                }
            }, (long) (delay * 1000));
        }
    } else {
        sendToClient(event);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) HomematicClientException(org.openhab.binding.homematic.internal.communicator.client.HomematicClientException)

Example 95 with TimerTask

use of java.util.TimerTask in project antlr4 by antlr.

the class SharedWebDriver method close.

public static void close() {
    if (driver != null) {
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
        timer = new Timer();
        timer.schedule(new TimerTask() {

            @Override
            public void run() {
                driver.quit();
                driver = null;
            }
        }, // close with delay to allow next Test to start
        2000);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Aggregations

TimerTask (java.util.TimerTask)900 Timer (java.util.Timer)653 IOException (java.io.IOException)90 Date (java.util.Date)58 Test (org.junit.Test)57 File (java.io.File)30 ArrayList (java.util.ArrayList)29 Intent (android.content.Intent)25 AtomicLong (java.util.concurrent.atomic.AtomicLong)21 Handler (android.os.Handler)20 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20 HashMap (java.util.HashMap)17 List (java.util.List)14 TextView (android.widget.TextView)13 CountDownLatch (java.util.concurrent.CountDownLatch)13 View (android.view.View)12 Map (java.util.Map)12 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 InputMethodManager (android.view.inputmethod.InputMethodManager)11 Random (java.util.Random)11