-
-
Save MobiDevelop/1c8af007379c74fcae11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | |
} | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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