Skip to content

Instantly share code, notes, and snippets.

@MobiDevelop
Created July 7, 2013 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MobiDevelop/1c8af007379c74fcae11 to your computer and use it in GitHub Desktop.
Save MobiDevelop/1c8af007379c74fcae11 to your computer and use it in GitHub Desktop.
package com.example.preloader.client;
import com.badlogic.gdx.backends.gwt.GwtApplication;
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
import com.example.preloader.PreloaderInterface;
/**An implementatation of PreloaderInterface which forwards the request to
* the GwtApplication's preloader. */
public class GwtPreloaderInterface implements PreloaderInterface {
GwtApplication application;
public GwtPreloaderInterface(GwtApplication application) {
this.application = application;
}
@Override
public void preloadBundle (final String bundle, final Callback callback) {
application.getPreloader().preload(bundle + ".txt", new PreloaderCallback() {
@Override
public void update (PreloaderState state) {
if (state.hasEnded()) {
callback.onBundlePreloaded(bundle);
}
}
@Override
public void error (String file) {
}
});
}
}
package com.example.preloader;
/**An implementatation of PreloaderInterface which returns immediately. This
* implementation should be used where a Preloader is not required. */
public class NullPreloaderInterface implements PreloaderInterface {
@Override
public void preloadBundle (final String bundle, final Callback callback) {
callback.onBundlePreloaded(bundle);
}
}
package com.example.preloader;
/** Provides a way to interact with the preloader, if one exists. */
public interface PreloaderInterface {
/**Request that the named bundle be preloaded.
*
* @param bundle the name of the bundle
* @param callback to be called upon preload completion
*/
public void preloadBundle(String bundle, Callback callback);
/** Allows the PreloaderInterface to communicate back to the caller. */
public interface Callback {
/**Called when the named bundle has been preloaded.
*
* @param bundle the name of the bundle
*/
void onBundlePreloaded(String bundle);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment