Instantly share code, notes, and snippets.

Embed
What would you like to do?
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