List of usage examples for com.google.gwt.user.client Timer Timer
Timer
From source file:com.github.gwtmaterialdesign.client.application.googleinbox.GoogleInboxView.java
License:Apache License
@Inject GoogleInboxView(Binder uiBinder) { initWidget(uiBinder.createAndBindUi(this)); for (InboxDTO dto : DataHelper.getAllTodayInbox()) { inboxColaps.add(new InboxCollapsible(dto)); }/* w ww . j a va 2s . co m*/ for (InboxLinkDTO dto : DataHelper.getAllYesterdayInbox()) { inboxLinkColaps.add(new InboxLinkCollapsible(dto)); } splash.show(); Timer t = new Timer() { @Override public void run() { splash.hide(); } }; t.schedule(4500); }
From source file:com.github.wolfie.meteorcursor.client.ui.VMeteorCursor.java
License:Apache License
public void onPreviewNativeEvent(final NativePreviewEvent event) { final String type = event.getNativeEvent().getType(); if ("mousemove".equals(type) && !disabled) { final int mouseX = event.getNativeEvent().getClientX(); final int mouseY = event.getNativeEvent().getClientY(); final double speed = getDistanceTravelled(mouseX, mouseY, previousMouseX, previousMouseY); // ignore the first cursor move if (previousMouseX != -1 && previousMouseY != -1 && speed > threshold) { // delay the particle a little, so that it doesn't come directly // underneath the cursor. new Timer() { @Override/*from w w w .j a va2s .co m*/ public void run() { // for each double exceeding of the threshold, paint one particle int particleThresholdCounter = threshold; while (particleThresholdCounter < speed) { RootPanel.get().add(new Particle(mouseX, mouseY, speed)); particleThresholdCounter += threshold * 2; } } }.schedule(PATICLE_DELAY_MILLIS); } previousMouseX = mouseX; previousMouseY = mouseY; } }
From source file:com.google.api.explorer.client.base.http.crossdomain.CrossDomainRequest.java
License:Apache License
CrossDomainRequest(final AsyncCallback<ApiResponse> callback, int timeoutMillis) { this.callback = callback; if (timeoutMillis > 0) { this.timer = new Timer() { @Override//from ww w . ja v a2s .c o m public void run() { if (callback != null) { CrossDomainRequest.this.cancel(); callback.onFailure(new TimeoutException()); } } }; timer.schedule(timeoutMillis); } }
From source file:com.google.api.explorer.client.history.PrettyDate.java
License:Apache License
/** * Schedules a repeating timer to continually update the text with the * pretty-date, every minute until the text is more than an hour old, at which * point it stops. The assumption is that nobody will wait for 60+ minutes for * "one hour ago" to turn into "2 hours ago" *//*w ww . jav a2s . co m*/ public static void keepMakingPretty(final Date date, final String prefix, final Element element) { makePretty(date, prefix, element); if (!TIMERS.containsKey(element)) { Timer timer = new Timer() { @Override public void run() { makePretty(date, prefix, element); if (element.getInnerText().contains("hour")) { stopMakingPretty(element); } } }; timer.scheduleRepeating(60000); TIMERS.put(element, timer); } }
From source file:com.google.appinventor.client.editor.EditorManager.java
License:Open Source License
/** * Creates the editor manager./*from w w w . j av a2 s .c o m*/ */ public EditorManager() { openProjectEditors = Maps.newHashMap(); dirtyProjectSettings = new HashSet<ProjectSettings>(); dirtyFileEditors = new HashSet<FileEditor>(); autoSaveTimer = new Timer() { @Override public void run() { // When the timer goes off, save all dirtyProjectSettings and // dirtyFileEditors. Ode.getInstance().lockScreens(true); // Lock out changes saveDirtyEditors(new Command() { @Override public void execute() { Ode.getInstance().lockScreens(false); // I/O finished, unlock } }); } }; }
From source file:com.google.appinventor.client.editor.simple.components.MockComponentsUtil.java
License:Open Source License
/** * Sets the background image for the given widget. * * @param container the MockContainer to refresh when image is loaded * @param widget widget to change background image for * @param image URL/*from w w w . j a v a 2 s .c om*/ */ static void setWidgetBackgroundImage(final MockContainer container, Widget widget, String image) { // Problem: When we change the background image via a Style referencing a "url" // the browser doesn't initially know the size of the image. We need to know it // when the container layout height and/or width is "Automatic." If we query right // away, we will be told the image is 0 x 0 because it isn't loaded yet. // I have not been able to figure out how to get the browser to give us a onLoad (or // similar event) when the image is loaded. If we could get such an event, we can // call refreshForm in the container and win. // // The code below fudges this by setting up a time to fire after 1 second with the // hope that the image will have been loaded by then and its dimensions known. // The code commented out immediately below this code is what I would like to use, // but it doesn't seem to work! -JIS Timer t = new Timer() { @Override public void run() { container.refreshForm(); } }; // widget.addHandler(new LoadHandler() { // @Override // public void onLoad(LoadEvent event) { // container.refreshForm(); // } // }, new Type<LoadHandler>()); setWidgetBackgroundImage(widget, image); t.schedule(1000); // Fire in one second }
From source file:com.google.appinventor.client.editor.youngandroid.YaBlocksEditor.java
License:Open Source License
public void showWhenInitialized() { //check if blocks are initialized if (BlocklyPanel.blocksInited(fullFormName)) { blocksArea.showDifferentForm(fullFormName); loadBlocksEditor();//from ww w.j av a2 s . c o m sendComponentData(); // Send Blockly the component information for generating Yail blocksArea.renderBlockly(); //Re-render Blockly due to firefox bug } else { //timer calls this function again if the blocks are not initialized if (timer == null) { timer = new Timer() { public void run() { showWhenInitialized(); } }; } timer.schedule(200); // Run every 200 milliseconds } }
From source file:com.google.appinventor.client.explorer.commands.ShowProgressBarCommand.java
License:Open Source License
@Override //the main function to be called public void execute(final ProjectNode node) { final Ode ode = Ode.getInstance(); if (counter < 1) { projectNode = node;/*from w w w . j av a2 s . c o m*/ minPB = new ProgressBarDialogBox(); minPB.center(); executeNextCommand(node); } counter++; //call back function - dynamic DialogBox OdeAsyncCallback<RpcResult> callback = new OdeAsyncCallback<RpcResult>(MESSAGES.buildError()) // failure message { @Override public void onSuccess(RpcResult result) { minPB.addMessages(node.getName(), result); if (result.succeeded()) { minPB.hide(); } else if (progressBarShow != 2) { // Build isn't done yet Timer timer = new Timer() { @Override public void run() { execute(node); } }; // TODO(user): Maybe do an exponential backoff here. timer.schedule(WAIT_INTERVAL_MILLIS); } } @Override public void onFailure(Throwable caught) { super.onFailure(caught); executionFailedOrCanceled(); } }; ode.getProjectService().getBuildResult(node.getProjectId(), target, callback); }
From source file:com.google.appinventor.client.explorer.commands.ShowProgressBarForEclipseCommand.java
License:Open Source License
@Override //the main function to be called public void execute(final ProjectNode node) { final Ode ode = Ode.getInstance(); if (counter < 1) { projectNode = node;/*from w w w . java 2 s.c om*/ minPB = new ProgressBarDialogBox(); minPB.center(); executeNextCommand(node); } counter++; //call back function - dynamic DialogBox OdeAsyncCallback<RpcResult> callback = new OdeAsyncCallback<RpcResult>(MESSAGES.buildError()) // failure message { @Override public void onSuccess(RpcResult result) { minPB.addMessages(node.getName(), result); if (result.succeeded()) { minPB.hide(); } else if (progressBarShow != 2) { // Build isn't done yet Timer timer = new Timer() { @Override public void run() { execute(node); } }; // TODO(user): Maybe do an exponential backoff here. timer.schedule(WAIT_INTERVAL_MILLIS); } } @Override public void onFailure(Throwable caught) { super.onFailure(caught); executionFailedOrCanceled(); } }; ode.getProjectService().getEclipseProjectBuildResult(node.getProjectId(), target, this.buildOption, callback); }
From source file:com.google.appinventor.client.explorer.commands.WaitForBuildResultCommand.java
License:Open Source License
@Override public void execute(final ProjectNode node) { final Ode ode = Ode.getInstance(); messagesOutput.clear();/*from w w w . ja va 2s . c om*/ messagesOutput.addMessages(MESSAGES.buildRequestedMessage(node.getName(), buildRequestTime)); OdeAsyncCallback<RpcResult> callback = new OdeAsyncCallback<RpcResult>( // failure message MESSAGES.buildError()) { @Override public void onSuccess(RpcResult result) { messagesOutput.addMessages("Waiting for " + getElapsedMillis() / 1000 + " seconds."); messagesOutput.addMessages(result.getOutput()); messagesOutput.addMessages(result.getError()); Tracking.trackEvent(Tracking.PROJECT_EVENT, Tracking.PROJECT_SUBACTION_BUILD_YA, node.getName(), getElapsedMillis()); if (result.succeeded()) { ode.getTopToolbar().updateKeystoreFileMenuButtons(); executeNextCommand(node); } else if (result.getResult() == 1) { // General build error String errorMsg = result.getError(); // This is not an internal App Inventor bug. The error should be // reported in a yellow info box. ErrorReporter .reportInfo(MESSAGES.buildFailedError() + (errorMsg.isEmpty() ? "" : " " + errorMsg)); executionFailedOrCanceled(); } else if (result.getResult() == 2) { // Yail generation error String formName = extractFormName(result); ErrorReporter.reportError(MESSAGES.errorGeneratingYail(formName)); String blocksFileName = formName + YoungAndroidSourceAnalyzer.CODEBLOCKS_SOURCE_EXTENSION; YoungAndroidBlocksNode blocksNode = findBlocksNode((YoungAndroidProjectNode) node, blocksFileName); if (blocksNode != null) { showProblemBlocks(blocksNode); } executionFailedOrCanceled(); } else { // Build isn't done yet Timer timer = new Timer() { @Override public void run() { execute(node); } }; // TODO(user): Maybe do an exponential backoff here. timer.schedule(WAIT_INTERVAL_MILLIS); } } @Override public void onFailure(Throwable caught) { super.onFailure(caught); executionFailedOrCanceled(); } }; ode.getProjectService().getBuildResult(node.getProjectId(), target, callback); }