Building on Tivo

by Arthur van Hoff and Adam Doppelt





Listing One



import com.tivo.hme.sdk.*;

public class HelloWorld extends Application {

    protected void init(Context context) {

        root.setResource(createText("default-36-bold.font",

                                    "0xffffff", "Hello, world!"));

    }

}





Listing Two

public class TicTacToe extends Application

{

    View piecesView;

    Resource images[] = new Resource[2];

    int gridX, gridY;

    ...

    protected void init(Context context)

    {

        piecesView = new View(root, 0, 0, width, height);

        gridX = (width  - 300) / 2;

        gridY = (height - 300) / 2;

        View grid = new View(root, gridX, gridY, 300, 300);

        grid.setResource("grid.png");

        images[0] = createText("default-72-bold.font", "0xffffff", "X");

        images[1] = createText("default-72-bold.font", "0xffffff", "O");

    }

 ...





Listing Three



public boolean handleKeyPress(int code, long rawcode)

{

    if (code >= KEY_NUM1 && code <= KEY_NUM9) {

        int pos = code - KEY_NUM1;

        makeMove(pos % 3, pos / 3);

        return true;

    }

    play("bonk.snd");

    return false;

}





Listing Four

Resource animation = getResource("*1000");

for (int x = 0; x < 3; ++x) {

  for (int y = 0; y < 3; ++y) {

    View v = pieces[x][y];                    

    if (v != null) {

      if (victory) {

        v.setLocation(v.x + (x - 1) * 400, v.y + (y - 1) * 300, animation);

      }

      v.setTransparency(1, animation);

        ...

    }

  }

}













2



