Example #1
0
  // Key events
  public boolean onKey(View v, int keyCode, KeyEvent event) {

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
      // Log.v("SDL", "key down: " + keyCode);
      SDLActivity.onNativeKeyDown(keyCode);
      return true;
    } else if (event.getAction() == KeyEvent.ACTION_UP) {
      // Log.v("SDL", "key up: " + keyCode);
      SDLActivity.onNativeKeyUp(keyCode);
      return true;
    }

    return false;
  }
Example #2
0
  // Called when the surface is resized
  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    // Log.v("SDL", "surfaceChanged()");

    int sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565 by default
    switch (format) {
      case PixelFormat.A_8:
        Log.v("SDL", "pixel format A_8");
        break;
      case PixelFormat.LA_88:
        Log.v("SDL", "pixel format LA_88");
        break;
      case PixelFormat.L_8:
        Log.v("SDL", "pixel format L_8");
        break;
      case PixelFormat.RGBA_4444:
        Log.v("SDL", "pixel format RGBA_4444");
        sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444
        break;
      case PixelFormat.RGBA_5551:
        Log.v("SDL", "pixel format RGBA_5551");
        sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551
        break;
      case PixelFormat.RGBA_8888:
        Log.v("SDL", "pixel format RGBA_8888");
        sdlFormat = 0x86462004; // SDL_PIXELFORMAT_RGBA8888
        break;
      case PixelFormat.RGBX_8888:
        Log.v("SDL", "pixel format RGBX_8888");
        sdlFormat = 0x86262004; // SDL_PIXELFORMAT_RGBX8888
        break;
      case PixelFormat.RGB_332:
        Log.v("SDL", "pixel format RGB_332");
        sdlFormat = 0x84110801; // SDL_PIXELFORMAT_RGB332
        break;
      case PixelFormat.RGB_565:
        Log.v("SDL", "pixel format RGB_565");
        sdlFormat = 0x85151002; // SDL_PIXELFORMAT_RGB565
        break;
      case PixelFormat.RGB_888:
        Log.v("SDL", "pixel format RGB_888");
        // Not sure this is right, maybe SDL_PIXELFORMAT_RGB24 instead?
        sdlFormat = 0x86161804; // SDL_PIXELFORMAT_RGB888
        break;
      default:
        Log.v("SDL", "pixel format unknown " + format);
        break;
    }
    SDLActivity.onNativeResize(width, height, sdlFormat);

    // Now start up the C app thread
    if (mSDLThread == null) {
      mSDLThread = new Thread(new SDLMain(), "SDLThread");
      mSDLThread.start();
    }
  }
Example #3
0
  // Touch events
  public boolean onTouch(View v, MotionEvent event) {

    int action = event.getAction();
    float x = event.getX();
    float y = event.getY();
    float p = event.getPressure();

    // TODO: Anything else we need to pass?
    SDLActivity.onNativeTouch(action, x, y, p);
    return true;
  }
Example #4
0
  // Called when we lose the surface
  public void surfaceDestroyed(SurfaceHolder holder) {
    // Log.v("SDL", "surfaceDestroyed()");

    // Send a quit message to the application
    SDLActivity.nativeQuit();

    // Now wait for the SDL thread to quit
    if (mSDLThread != null) {
      try {
        mSDLThread.join();
      } catch (Exception e) {
        Log.v("SDL", "Problem stopping thread: " + e);
      }
      mSDLThread = null;

      // Log.v("SDL", "Finished waiting for SDL thread");
    }

    enableSensor(Sensor.TYPE_ACCELEROMETER, false);
  }
Example #5
0
 public void onSensorChanged(SensorEvent event) {
   if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
     SDLActivity.onNativeAccel(event.values[0], event.values[1], event.values[2]);
   }
 }
Example #6
0
  public void run() {
    // Runs SDL_main()
    SDLActivity.nativeInit();

    // Log.v("SDL", "SDL thread terminated");
  }
Example #7
0
 public static void setActivityTitle(String title) {
   // Called from SDLMain() thread and can't directly affect the view
   mSingleton.sendCommand(COMMAND_CHANGE_TITLE, title);
 }