com.badlogic.gdx.utils.Timer Java Examples
The following examples show how to use
com.badlogic.gdx.utils.Timer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GameJoltClient.java From gdx-gamesvcs with Apache License 2.0 | 6 votes |
protected void sendOpenSessionEvent() { if (!isSessionActive()) return; Map<String, String> params = new HashMap<String, String>(); addGameIDUserNameUserToken(params); final Net.HttpRequest http = buildJsonRequest("sessions/open/", params); if (http != null) Gdx.net.sendHttpRequest(http, new NoOpResponseListener()); pingTask = Timer.schedule(new Timer.Task() { @Override public void run() { sendKeepSessionOpenEvent(); } }, GJ_PING_INTERVAL, GJ_PING_INTERVAL); }
Example #2
Source File: AndroidContextTest.java From gdx-fireapp with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { PowerMockito.mockStatic(GdxNativesLoader.class); AndroidApplication application = PowerMockito.mock(AndroidApplication.class); Mockito.when(application.getType()).thenReturn(Application.ApplicationType.Android); Gdx.app = application; PowerMockito.mockStatic(Timer.class); PowerMockito.when(Timer.post(any(Timer.Task.class))).then(new Answer() { @Override public Object answer(InvocationOnMock invocation) { ((Timer.Task) invocation.getArgument(0)).run(); return null; } }); GdxFIRApp.setThrowFailureByDefault(false); }
Example #3
Source File: StorageDownloadImageTest.java From gdx-fireapp with Apache License 2.0 | 6 votes |
@Override public void action() { GdxFIRStorage.instance() .downloadImage(StorageUploadImageTest.STORAGE_PATH) .after(GdxFIRAuth.instance().signInAnonymously()) .then(new Consumer<TextureRegion>() { @Override public void accept(TextureRegion textureRegion) { img = textureRegion.getTexture(); Timer.schedule(new Timer.Task() { @Override public void run() { success(); } }, 2f); } }); }
Example #4
Source File: Message.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
@SuppressWarnings("unused") public static void showMsg(final Stage stage, final String text, final boolean modal) { // show in the next frame to allow calling when no OpenGL context is available. Timer.post(new Task() { @Override public void run() { isModal = modal; if (text == null) { hideMsg(); return; } add(stage, text); if (FADE_DURATION > 0) { msg.getColor().a = 0; msg.addAction(Actions.fadeIn(FADE_DURATION, Interpolation.fade)); } } }); }
Example #5
Source File: FutureListenerPromise.java From gdx-fireapp with Apache License 2.0 | 6 votes |
/** * @see FuturePromise#when(Consumer) */ @SuppressWarnings("unchecked") public static <R> FutureListenerPromise<R> whenListener(final Consumer<FutureListenerPromise<R>> consumer) { final FutureListenerPromise<R> promise = new FutureListenerPromise<>(); promise.execution = new Runnable() { @Override public void run() { promise.execution = null; try { consumer.accept(promise); } catch (Exception e) { promise.stackRecognizer.getBottomThenPromise().doFail(e); } } }; if (GdxFIRApp.isAutoSubscribePromises()) { promise.subscribeTask = Timer.post(new AutoSubscribeTask(promise)); } return promise; }
Example #6
Source File: ConverterPromise.java From gdx-fireapp with Apache License 2.0 | 6 votes |
/** * @see FuturePromise#when(Consumer) */ @SuppressWarnings("unchecked") public static <T, R> ConverterPromise<T, R> whenWithConvert(final Consumer<ConverterPromise<T, R>> consumer) { final ConverterPromise<T, R> promise = new ConverterPromise<>(); promise.execution = new Runnable() { @Override public void run() { promise.execution = null; try { consumer.accept(promise); } catch (Exception e) { promise.stackRecognizer.getBottomThenPromise().doFail(e); } } }; if (GdxFIRApp.isAutoSubscribePromises()) { promise.subscribeTask = Timer.post(new AutoSubscribeTask(promise)); } return promise; }
Example #7
Source File: FuturePromise.java From gdx-fireapp with Apache License 2.0 | 6 votes |
public static synchronized <R> FuturePromise<R> when(final Consumer<FuturePromise<R>> consumer) { final FuturePromise<R> promise = new FuturePromise<>(); promise.execution = new Runnable() { @Override public void run() { promise.execution = null; try { consumer.accept(promise); } catch (Exception e) { promise.stackRecognizer.getBottomThenPromise().doFail(e); } } }; if (GdxFIRApp.isAutoSubscribePromises()) { promise.subscribeTask = Timer.post(new AutoSubscribeTask(promise)); } return promise; }
Example #8
Source File: CreateResolutionDialog.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
@Override protected void ok() { final Stage stage = getStage(); Message.showMsg(stage, "Creating resolution...", true); Timer.schedule(new Task() { @Override public void run() { createResolution(); String msg = scaleImages(); if (listener != null) listener.changed(new ChangeEvent(), CreateResolutionDialog.this); Message.hideMsg(); if (msg != null) Message.showMsgDialog(stage, "Error creating resolution", msg); } }, 1); }
Example #9
Source File: CreateProjectDialog.java From bladecoder-adventure-engine with Apache License 2.0 | 6 votes |
@Override protected void ok() { try { Ctx.project.getEditorConfig().setProperty(ANDROID_SDK_PROP, androidSdk.getText()); Ctx.project.saveProject(); } catch (Exception ex) { String msg = ex.getClass().getSimpleName() + " - " + ex.getMessage(); Message.showMsgDialog(getStage(), "Error saving project", msg); } final Stage stage = getStage(); Message.showMsg(getStage(), "Creating project...", true); Timer.schedule(new Task() { @Override public void run() { createProject(stage); } },1); }
Example #10
Source File: Tooltip.java From vis-ui with Apache License 2.0 | 6 votes |
@Override public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) { if (pointer == -1) { Vector2 targetPos = target.localToStageCoordinates(new Vector2()); setX(targetPos.x + (target.getWidth() - getWidth()) / 2); float tooltipY = targetPos.y - getHeight() - 6; float stageHeight = target.getStage().getHeight(); //is there enough space to display above widget? if (stageHeight - tooltipY > stageHeight) setY(targetPos.y + target.getHeight() + 6); //display above widget else setY(tooltipY); //display below displayTask.cancel(); Timer.schedule(displayTask, appearDelayTime); } }
Example #11
Source File: Message.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public static void showMsgDialog(final Stage stage, final String title, final String msg) { Timer.post(new Task() { @Override public void run() { Message.hideMsg(); new Dialog(title, skin).text(msg).button("Close", true).key(Keys.ENTER, true).key(Keys.ESCAPE, false) .show(stage); } }); }
Example #12
Source File: GpgsClient.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
protected void onInitialized() { initialized = true; connectionPending = false; // if Google API has initialized, check if user session is active displayName = ""; boolean sessionActive = isSessionActive(); if (updateEventsTask != null) updateEventsTask.cancel(); if (sessionActive) { oAuthToken = getOAuthToken(); sendNowPlayingEvent(); refreshDisplayname(); updateEventsTask = Timer.schedule(new Timer.Task() { @Override public void run() { recordEvents(); } }, GPGS_CHECKEVENTS_INTERVAL, GPGS_CHECKEVENTS_INTERVAL); } if (gsListener != null) { if (sessionActive) gsListener.gsOnSessionActive(); else gsListener.gsOnSessionInactive(); } }
Example #13
Source File: Message.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") public static void showMsg(final Stage stage, final String text, final float duration) { Timer.post(new Task() { @Override public void run() { isModal = false; if (text == null) { hideMsg(); return; } add(stage, text); if (FADE_DURATION > 0) { msg.getColor().a = 0; msg.addAction(sequence(Actions.fadeIn(FADE_DURATION, Interpolation.fade), Actions.delay(duration, sequence(fadeOut(FADE_DURATION, Interpolation.fade), Actions.removeActor())))); } else { msg.addAction(sequence(Actions.delay(duration, Actions.removeActor()))); } } }); }
Example #14
Source File: CreateAtlasDialog.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
@Override protected void ok() { Message.showMsg(getStage(), "Generating atlas...", true); Timer.schedule(new Task() { @Override public void run() { genAtlas(); } }, 1); }
Example #15
Source File: VoiceManager.java From bladecoder-adventure-engine with Apache License 2.0 | 5 votes |
public void play(String fileName) { stop(); this.fileName = fileName; if (fileName != null) { // Load and play the voice file in background to avoid // blocking the UI loadAssets(); backgroundLoadingTask.cancel(); Timer.schedule(backgroundLoadingTask, 0, 0); } }
Example #16
Source File: Spinner.java From vis-ui with Apache License 2.0 | 5 votes |
@Override public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { if (buttonRepeatTask.isScheduled() == false) { buttonRepeatTask.advance = advance; buttonRepeatTask.cancel(); Timer.schedule(buttonRepeatTask, buttonRepeatInitialTime, buttonRepeatTime); } return true; }
Example #17
Source File: ToastManager.java From vis-ui with Apache License 2.0 | 5 votes |
public void clear () { for (Toast toast : toasts) { toast.getMainTable().remove(); } toasts.clear(); for (Timer.Task task : timersTasks.values()) { task.cancel(); } timersTasks.clear(); updateToastsPositions(); }
Example #18
Source File: ToastManager.java From vis-ui with Apache License 2.0 | 5 votes |
/** * Removes toast from screen. * @return true when toast was removed, false otherwise */ public boolean remove (Toast toast) { boolean removed = toasts.removeValue(toast, true); if (removed) { toast.getMainTable().remove(); Timer.Task timerTask = timersTasks.remove(toast); if (timerTask != null) timerTask.cancel(); updateToastsPositions(); } return removed; }
Example #19
Source File: ToastManager.java From vis-ui with Apache License 2.0 | 5 votes |
/** Displays toast. Toast will be displayed for given amount of seconds. */ public void show (final Toast toast, float timeSec) { Table toastMainTable = toast.getMainTable(); if (toastMainTable.getStage() != null) { remove(toast); } toasts.add(toast); toast.setToastManager(this); toast.fadeIn(); toastMainTable.pack(); root.addActor(toastMainTable); updateToastsPositions(); if (timeSec > 0) { Timer.Task fadeOutTask = new Timer.Task() { @Override public void run () { toast.fadeOut(); timersTasks.remove(toast); } }; timersTasks.put(toast, fadeOutTask); Timer.schedule(fadeOutTask, timeSec); } }
Example #20
Source File: ToastManager.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
public void clear () { for (Toast toast : toasts) { toast.getMainTable().remove(); } toasts.clear(); for (Timer.Task task : timersTasks.values()) { task.cancel(); } timersTasks.clear(); updateToastsPositions(); }
Example #21
Source File: ToastManager.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
/** * Removes toast from screen. * @return true when toast was removed, false otherwise */ public boolean remove (Toast toast) { boolean removed = toasts.removeValue(toast, true); if (removed) { toast.getMainTable().remove(); Timer.Task timerTask = timersTasks.remove(toast); if (timerTask != null) timerTask.cancel(); updateToastsPositions(); } return removed; }
Example #22
Source File: ToastManager.java From gdx-texture-packer-gui with Apache License 2.0 | 5 votes |
/** Displays toast. Toast will be displayed for given amount of seconds. */ public Toast show (final Toast toast, float timeSec) { Table toastMainTable = toast.getMainTable(); if (toastMainTable.getStage() != null) { remove(toast); } toasts.add(toast); toast.setToastManager(this); toast.fadeIn(); toastMainTable.pack(); root.addActor(toastMainTable); updateToastsPositions(); if (timeSec > 0) { Timer.Task fadeOutTask = new Timer.Task() { @Override public void run () { toast.fadeOut(); timersTasks.remove(toast); } }; timersTasks.put(toast, fadeOutTask); Timer.schedule(fadeOutTask, timeSec); } return toast; }
Example #23
Source File: DatabaseListenerValueTest.java From gdx-fireapp with Apache License 2.0 | 5 votes |
@Override public void action() { GdxFIRDatabase.instance() .inReference("/test-listen-value") .onDataChange(String.class) .after(GdxFIRAuth.instance().signInAnonymously()) .then(new Consumer<String>() { @Override public void accept(String s) { Gdx.app.log("App", "new value: " + s); listenCounter.incrementAndGet(); } }); scheduler = Timer.schedule(new Timer.Task() { @Override public void run() { Gdx.app.log("App", "set new value"); GdxFIRDatabase.instance() .inReference("/test-listen-value") .setValue("abc" + Math.random()) .after(GdxFIRAuth.instance().signInAnonymously()) .subscribe(); if (counter.incrementAndGet() >= 4) { if (listenCounter.get() >= 3) { scheduler.cancel(); success(); } } } }, 0.3f, 0.6f); }
Example #24
Source File: BadlogicTest.java From gdx-fireapp with Apache License 2.0 | 5 votes |
@Override public void action() { img = new Texture("badlogic.jpg"); Timer.schedule(new Timer.Task() { @Override public void run() { success(); } }, 1f); }
Example #25
Source File: MockGameServiceClient.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
private void sleep(final Runnable runnable) { if (runnable != null) Timer.schedule(new Timer.Task() { @Override public void run() { runnable.run(); } }, latency); }
Example #26
Source File: MusicManager.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
private void loadTask() { loadAssets(); backgroundLoadingTask.cancel(); Timer.schedule(backgroundLoadingTask, 0, 0); }
Example #27
Source File: RenderedConsole.java From riiablo with Apache License 2.0 | 4 votes |
private void updateCaret() { caretBlinkTask.cancel(); Timer.schedule(caretBlinkTask, CARET_HOLD_DELAY, CARET_BLINK_DELAY); showCaret = true; }