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);
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations