use of java.util.TimerTask in project AndroidTraining by mixi-inc.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Handler handler = new Handler();
final Timer timer = new Timer();
// 5秒ごとにレベルを変更するタスク
final Drawable levelListDrawable = findViewById(R.id.LevelListButton).getBackground();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
final int level = levelListDrawable.getLevel();
handler.post(new Runnable() {
@Override
public void run() {
if (level == 0) {
levelListDrawable.setLevel(1);
} else {
levelListDrawable.setLevel(0);
}
}
});
}
}, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
// クロスフェードを開始する
final TransitionDrawable transition = (TransitionDrawable) findViewById(R.id.TransitionView).getBackground();
transition.startTransition(TRANSITION_DURATION);
// 5秒ごとにレベルを変更し、クリップの範囲を変化させるタスク
final ClipDrawable clipDrawable = (ClipDrawable) findViewById(R.id.ClipView).getBackground();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
clipDrawable.setLevel(clipDrawable.getLevel() + 1000);
}
});
}
}, TIMER_TASK_DELAY, TIMER_TASK_PERIOD);
// スケールのレベルを変更する
ScaleDrawable scale = (ScaleDrawable) findViewById(R.id.ScaleView).getBackground();
scale.setLevel(1);
}
use of java.util.TimerTask in project ACS by ACS-Community.
the class GCJMXClient method main.
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Must provide 2 arguments: <classname> <interval-in-ms>");
}
final GCJMXClient client = new GCJMXClient(args[0]);
try {
client.connect();
} catch (Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
ObjectName objName = null;
try {
objName = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
} catch (MalformedObjectNameException e1) {
System.err.println("bad name?");
System.exit(1);
}
final ObjectName objNameF = objName;
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
MBeanServerConnection con = client.getRemote();
try {
con.invoke(objNameF, "gc", null, null);
System.out.println("Called gc() on remote VM");
} catch (Exception e) {
System.err.println("Couldn't call gc() on remote VM");
}
}
};
timer.scheduleAtFixedRate(task, new Date(), Integer.parseInt(args[1]));
}
use of java.util.TimerTask in project UltimateAndroid by cymcsg.
the class SliderLayout method recoverCycle.
/**
* when paused cycle, this method can weak it up.
*/
private void recoverCycle() {
if (!mAutoRecover || !mAutoCycle) {
return;
}
if (!mCycling) {
if (mResumingTask != null && mResumingTimer != null) {
mResumingTimer.cancel();
mResumingTask.cancel();
}
mResumingTimer = new Timer();
mResumingTask = new TimerTask() {
@Override
public void run() {
startAutoCycle();
}
};
mResumingTimer.schedule(mResumingTask, 6000);
}
}
use of java.util.TimerTask in project EnrichmentMapApp by BaderLab.
the class ComputeSimilarityTaskParallel method run.
@Override
public void run(TaskMonitor tm) throws InterruptedException {
int cpus = Runtime.getRuntime().availableProcessors();
ExecutorService executor = Executors.newFixedThreadPool(cpus);
boolean distinct = map.getParams().getCreateDistinctEdges();
Map<SimilarityKey, GenesetSimilarity> similarities = startComputeSimilarities(tm, executor, distinct, !distinct);
// Support cancellation
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
if (cancelled) {
executor.shutdownNow();
}
}
}, 0, 1000);
executor.shutdown();
executor.awaitTermination(3, TimeUnit.HOURS);
timer.cancel();
if (!cancelled)
consumer.accept(similarities);
}
use of java.util.TimerTask in project cubrid-manager by CUBRID.
the class QuickBuilderDialog method startTimerForUpdateProposal.
private void startTimerForUpdateProposal() {
TimerTask proposalUpdateNotifyTask = new TimerTask() {
public void run() {
ColumnProposal proposalTemp = ColumnProposalAdvisor.getInstance().findProposal(databaseInfo);
if (proposalTemp == null) {
return;
}
if (proposalUpdateTimer != null) {
proposalUpdateTimer.cancel();
proposalUpdateTimer = null;
}
proposal = proposalTemp;
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (updateNoticeBanner != null) {
updateNoticeBanner.dispose();
updateNoticeBanner = null;
}
if (searchView != null) {
searchView.setInput(proposal);
}
shell.layout(true, true);
}
});
}
};
proposalUpdateTimer = new Timer(true);
proposalUpdateTimer.schedule(proposalUpdateNotifyTask, 500);
}
Aggregations