/**
   * This is called immediately after the surface is first created. Implementations of this should
   * start up whatever rendering code they desire. Note that only one thread can ever draw into a
   * {@link Surface}, so you should not draw into the Surface here if your normal rendering will be
   * in another thread.
   *
   * @param holder The SurfaceHolder whose surface is being created.
   */
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
    Rect surface = holder.getSurfaceFrame();
    width = surface.width();
    height = surface.height();

    x = width / 2;
    y = circleRadius;

    loop = new Loop(this);
    loop.isRunning(true);
    loop.start();
  }
Ejemplo n.º 2
0
  /**
   * This is called immediately before a surface is being destroyed. After returning from this call,
   * you should no longer try to access this surface. If you have a rendering thread that directly
   * accesses the surface, you must ensure that thread is no longer touching the Surface before
   * returning from this function.
   *
   * @param holder The SurfaceHolder whose surface is being destroyed.
   */
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
    boolean retry = true;

    loop.isRunning(false);
    while (retry) {
      try {
        loop.join();
        retry = false;
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
Ejemplo n.º 3
0
  /**
   * This is called immediately after the surface is first created. Implementations of this should
   * start up whatever rendering code they desire. Note that only one thread can ever draw into a
   * {@link Surface}, so you should not draw into the Surface here if your normal rendering will be
   * in another thread.
   *
   * @param holder The SurfaceHolder whose surface is being created.
   */
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
    Rect surface = holder.getSurfaceFrame();
    width = surface.width();
    height = surface.height();

    x = width / 2;
    y = circleRadius;

    loop = new Loop(this);
    loop.isRunning(true);
    loop.start();

    Log.d("ANAS", "++++++++++++++SURFACE CREATED    LOOP: " + loop.getState());
  }
Ejemplo n.º 4
0
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
    // simply copied from sample application LunarLander:
    // we have to tell thread to shut down & wait for it to finish, or else
    // it might touch the Surface after we return and explode

    boolean retry = true;
    loop.isRunning(false);
    while (retry) {
      try {
        loop.join();
        retry = false;
      } catch (InterruptedException e) {
        // we will try it again and again...
      }
    }
  }