Example #1
0
  public static Bitmap getTileBitmap(TileType type) {

    if (grassRes == null) {
      grassRes = new int[11];
      grassRes[0] = R.drawable.grass0;
      grassRes[1] = R.drawable.grass1;
      grassRes[2] = R.drawable.grass2;
      grassRes[3] = R.drawable.grass3;
      grassRes[4] = R.drawable.grass4;
      grassRes[5] = R.drawable.grass5;
      grassRes[6] = R.drawable.grass6;
      grassRes[7] = R.drawable.grass7;
      grassRes[8] = R.drawable.grass8;
      grassRes[9] = R.drawable.grass9;
      grassRes[10] = R.drawable.grass10;
    }
    if (grass == null) grass = new Bitmap[11];

    int random;

    switch (type) {
      case GRASS:
        random = (int) (Math.random() * 11);
        if (grass[random] == null || (grass[random] != null && grass[random].isRecycled()))
          grass[random] =
              BitmapFactory.decodeResource(
                  ContextProvider.getInstance().getContext().getResources(), grassRes[random]);
        return grass[random];
      case SAND:
        if (sand == null || (sand != null && sand.isRecycled()))
          sand =
              BitmapFactory.decodeResource(
                  ContextProvider.getInstance().getContext().getResources(), R.drawable.tile_sand);
        return sand;
      default:
        random = (int) (Math.random() * 11);
        if (grass[random] == null || (grass[random] != null && grass[random].isRecycled()))
          grass[random] =
              BitmapFactory.decodeResource(
                  ContextProvider.getInstance().getContext().getResources(), grassRes[random]);
        return grass[random];
    }
  }
 /** The destroy method is used to release the pointer to the subscriber service */
 public void destroy() {
   unbindSubscriber(ContextProvider.getInstance().getSubscriber());
 }
  /**
   * initializing the servlet by defining the resolution directory, the alias for the servlet, and
   * the resolution directory alias. Also, the servlet uses the singleton ContextProvider to get the
   * subscriber found by the service to be registered with the servlet.
   */
  public void init() {

    this.setServletAlias(SERVLET_ALIAS);

    bindSubscriber(ContextProvider.getInstance().getSubscriber());
  }