Example #1
0
  @Override
  public boolean loadAsset() {
    logger.info("Loading image " + descriptor.getUri());
    loaded = false;
    if (image == null) {
      try {
        String path = assetHandler.getAbsolutePath(descriptor.getUri().getPath());
        image = PlayN.assets().getImage(path);
        if (image != null) {
          logger.info(
              "Image loaded OK: {} from {} width {}",
              new Object[] {descriptor.getUri(), path, image.width()});
          return image.isReady();
        } else {
          logger.error("Image NOT loaded: {}", descriptor.getUri());
          return true;
        }
      } catch (Exception e) {
        logger.error("Error loading image: {}", descriptor.getUri(), e);
        return false;
      }
    }
    image.addCallback(
        new ResourceCallback<Image>() {

          @Override
          public void done(Image resource) {
            loaded = true;
          }

          @Override
          public void error(Throwable err) {}
        });
    return loaded;
  }
 /**
  * Creates a new background using the given image. The image is assumed to be divided into a 3x1
  * grid of 3 equal pieces.
  *
  * <p>NOTE: the image must be preloaded since we need to determine the stretching factor. If this
  * cannot be arranged using the application resource strategy, callers may consider setting the
  * background style from the images callback.
  */
 public Scale3Background(Image image) {
   if (!image.isReady()) {
     // complain about this, we don't support asynch images
     PlayN.log().warn("Scale3 image not preloaded: " + image);
   }
   _image = image;
   _s3 = new Scale3(image.width(), image.height());
 }