Exemplo n.º 1
1
  public void onResume() {
    Gdx.app = this;
    Gdx.input = input;
    Gdx.audio = audio;
    Gdx.files = files;
    Gdx.graphics = graphics;

    input.registerSensorListeners();

    // FIXME restore conditional execution if lifecycle errors will occur when GLSurfaceView used.
    // GLSurfaceView is guaranteed to work with this condition on, but GLSurfaceViewCupcake requires
    // it off,
    // so I disabled it.
    // if (!firstResume) // mentioned condition
    if (graphics != null && graphics.view != null) {
      if (graphics.view instanceof GLSurfaceViewAPI18)
        ((GLSurfaceViewAPI18) graphics.view).onResume();
      else if (graphics.view instanceof GLSurfaceView) ((GLSurfaceView) graphics.view).onResume();
      else throw new RuntimeException("unimplemented");
    }

    if (!firstResume) {
      audio.resume();
      graphics.resume();
    } else firstResume = false;
  }
Exemplo n.º 2
0
  public void onPause() {
    if (AndroidLiveWallpaperService.DEBUG)
      Log.d(AndroidLiveWallpaperService.TAG, " > AndroidLiveWallpaper - onPause()");

    // IMPORTANT!
    // jw: graphics.pause is never called, graphics.pause works on most devices but not on all..
    // for example on Samsung Galaxy Tab (GT-P6800) on android 4.0.4 invoking graphics.pause causes
    // "Fatal Signal 11"
    // near mEglHelper.swap() in GLSurfaceView while processing next onPause event.
    // See related issue:
    // http://code.google.com/p/libgdx/issues/detail?id=541
    // the problem with graphics.pause occurs while using OpenGL 2.0 and original GLSurfaceView
    // while rotating device in lwp preview
    // in my opinion it is a bug of android not libgdx, even example Cubic live wallpaper from
    // Android SDK crashes on affected devices.......... and on some configurations of android
    // emulator too.
    //
    // My wallpaper was rejected on Samsung Apps because of this issue, so I decided to disable
    // graphics.pause..
    // also I moved audio lifecycle methods from AndroidGraphicsLiveWallpaper into this class

    // graphics.pause();
    // if (AndroidLiveWallpaperService.DEBUG) Log.d(AndroidLiveWallpaperService.TAG, " >
    // AndroidLiveWallpaper - onPause() application paused!");
    audio.pause();

    input.unregisterSensorListeners();
    // erase pointer ids. this sucks donkeyballs...
    int[] realId = input.realId;
    for (int i = 0; i < realId.length; i++) realId[i] = -1;
    // erase touched state. this also sucks donkeyballs...
    boolean[] touched = input.touched;
    for (int i = 0; i < touched.length; i++) touched[i] = false;

    if (graphics != null && graphics.view != null) {
      if (graphics.view instanceof GLSurfaceViewCupcake)
        ((GLSurfaceViewCupcake) graphics.view).onPause();
      else if (graphics.view instanceof GLSurfaceViewAPI18)
        ((GLSurfaceViewAPI18) graphics.view).onPause();
      else if (graphics.view instanceof android.opengl.GLSurfaceView)
        ((android.opengl.GLSurfaceView) graphics.view).onPause();
      else throw new RuntimeException("unimplemented");
    }

    if (AndroidLiveWallpaperService.DEBUG)
      Log.d(AndroidLiveWallpaperService.TAG, " > AndroidLiveWallpaper - onPause() done!");
  }
Exemplo n.º 3
0
  public void onTouch(MotionEvent event, AndroidInput input) {
    final int action = event.getAction() & MotionEvent.ACTION_MASK;
    int pointerIndex =
        (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK)
            >> MotionEvent.ACTION_POINTER_ID_SHIFT;
    int pointerId = event.getPointerId(pointerIndex);

    int x = 0, y = 0;
    int realPointerIndex = 0;

    long timeStamp = System.nanoTime();
    synchronized (input) {
      switch (action) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_DOWN:
          realPointerIndex =
              input
                  .getFreePointerIndex(); // get a free pointer index as reported by Input.getX()
                                          // etc.
          if (realPointerIndex >= AndroidInput.NUM_TOUCHES) break;
          input.realId[realPointerIndex] = pointerId;
          x = (int) event.getX(pointerIndex);
          y = (int) event.getY(pointerIndex);
          postTouchEvent(input, TouchEvent.TOUCH_DOWN, x, y, realPointerIndex, timeStamp);
          input.touchX[realPointerIndex] = x;
          input.touchY[realPointerIndex] = y;
          input.deltaX[realPointerIndex] = 0;
          input.deltaY[realPointerIndex] = 0;
          input.touched[realPointerIndex] = true;
          break;

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_OUTSIDE:
        case MotionEvent.ACTION_CANCEL:
          realPointerIndex = input.lookUpPointerIndex(pointerId);
          if (realPointerIndex == -1) break;
          if (realPointerIndex >= AndroidInput.NUM_TOUCHES) break;
          input.realId[realPointerIndex] = -1;
          x = (int) event.getX(pointerIndex);
          y = (int) event.getY(pointerIndex);
          postTouchEvent(input, TouchEvent.TOUCH_UP, x, y, realPointerIndex, timeStamp);
          input.touchX[realPointerIndex] = x;
          input.touchY[realPointerIndex] = y;
          input.deltaX[realPointerIndex] = 0;
          input.deltaY[realPointerIndex] = 0;
          input.touched[realPointerIndex] = false;
          break;

        case MotionEvent.ACTION_MOVE:
          int pointerCount = event.getPointerCount();
          for (int i = 0; i < pointerCount; i++) {
            pointerIndex = i;
            pointerId = event.getPointerId(pointerIndex);
            x = (int) event.getX(pointerIndex);
            y = (int) event.getY(pointerIndex);
            realPointerIndex = input.lookUpPointerIndex(pointerId);
            if (realPointerIndex == -1) continue;
            if (realPointerIndex >= AndroidInput.NUM_TOUCHES) break;
            postTouchEvent(input, TouchEvent.TOUCH_DRAGGED, x, y, realPointerIndex, timeStamp);
            input.deltaX[realPointerIndex] = x - input.touchX[realPointerIndex];
            input.deltaY[realPointerIndex] = y - input.touchY[realPointerIndex];
            input.touchX[realPointerIndex] = x;
            input.touchY[realPointerIndex] = y;
          }
          break;
      }
    }
    Gdx.app.getGraphics().requestRendering();
  }