예제 #1
0
  public void rotateBy(float delta) {
    angle += delta;

    if (backCards.getIndex() == -1) {
      if (angle >= MAX_TIP_ANGLE) angle = MAX_TIP_ANGLE;
    }

    if (angle > 180) angle = 180;
    else if (angle < 0) angle = 0;
  }
예제 #2
0
  public void reloadTexture(int frontIndex, View frontView, int backIndex, View backView) {
    synchronized (this) {
      if (frontView != null) {
        if (backCards.getView() == frontView) {
          frontCards.setView(-1, null);
          swapCards();
        }
      }

      if (backView != null) {
        if (frontCards.getView() == backView) {
          backCards.setView(-1, null);
          swapCards();
        }
      }

      boolean frontChanged = frontCards.setView(frontIndex, frontView);
      boolean backChanged = backCards.setView(backIndex, backView);

      if (AphidLog.ENABLE_DEBUG)
        AphidLog.d(
            "reloading texture: %s and %s; old views: %s, %s, front changed %s, back changed %s",
            frontView,
            backView,
            frontCards.getView(),
            backCards.getView(),
            frontChanged,
            backChanged);

      if (frontIndex == activeIndex) {
        if (angle >= 180) angle -= 180;
        else if (angle < 0) angle += 180;
      } else if (backIndex == activeIndex) {
        if (angle < 0) angle += 180;
      }

      //			AphidLog.i("View changed: front (%d, %s), back (%d, %s), angle %s, activeIndex %d",
      // frontIndex, frontView, backIndex, backView, angle, activeIndex);
    }
  }
예제 #3
0
 void refreshPage(int pageIndex) {
   if (frontCards.getIndex() == pageIndex) frontCards.markForceReload();
   if (backCards.getIndex() == pageIndex) backCards.markForceReload();
 }
예제 #4
0
 void refreshPageView(View view) {
   if (frontCards.getView() == view) frontCards.markForceReload();
   if (backCards.getView() == view) backCards.markForceReload();
 }
예제 #5
0
 private void applyTexture(FlipRenderer renderer, GL10 gl) {
   frontCards.buildTexture(renderer, gl);
   backCards.buildTexture(renderer, gl);
 }
예제 #6
0
 private void resetAxises() {
   frontCards.getTopCard().setAxis(Card.AXIS_TOP);
   frontCards.getBottomCard().setAxis(Card.AXIS_TOP);
   backCards.getBottomCard().setAxis(Card.AXIS_TOP);
   backCards.getTopCard().setAxis(Card.AXIS_BOTTOM);
 }
예제 #7
0
  public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouchEvent) {
    float delta;

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        lastY = event.getY();
        lastX = event.getX();
        return isOnTouchEvent;
      case MotionEvent.ACTION_MOVE:
        if (orientationVertical) {
          delta = lastY - event.getY();
        } else {
          delta = lastX - event.getX();
        }
        if (Math.abs(delta) > controller.getTouchSlop())
          setState(STATE_TOUCH); // XXX: initialize views?
        if (state == STATE_TOUCH) {
          forward = delta > 0; // We only want to know the direction of the last movement
          controller.showFlipAnimation();
          final float angleDelta;
          if (orientationVertical) {
            angleDelta = 180 * delta / controller.getContentHeight() * MOVEMENT_RATE;
          } else {
            angleDelta = 180 * delta / controller.getContentWidth() * MOVEMENT_RATE;
          }
          angle += angleDelta;
          if (backCards.getIndex() == -1) {
            if (angle >= MAX_TIP_ANGLE) angle = MAX_TIP_ANGLE;
          } else if (backCards.getIndex() == 0) {
            if (angle <= 180 - MAX_TIP_ANGLE) angle = 180 - MAX_TIP_ANGLE;
          }
          if (angle < 0) {
            if (frontCards.getIndex() > 0) {
              activeIndex = frontCards.getIndex() - 1; // xxx
              controller.flippedToView(activeIndex);
            } else {
              swapCards();
              frontCards.setView(-1, null);
              if (-angle >= MAX_TIP_ANGLE) angle = -MAX_TIP_ANGLE;
              angle += 180;
            }
          }
          if (orientationVertical) {
            lastY = event.getY();
          } else {
            lastX = event.getX();
          }
          controller.getSurfaceView().requestRender();
          return true;
        }

        return isOnTouchEvent;
      case MotionEvent.ACTION_UP:
      case MotionEvent.ACTION_CANCEL:
        if (state == STATE_TOUCH) {
          if (orientationVertical) {
            delta = lastY - event.getY();
            rotateBy(180 * delta / controller.getContentHeight() * MOVEMENT_RATE);
          } else {
            delta = lastX - event.getX();
            rotateBy(180 * delta / controller.getContentWidth() * MOVEMENT_RATE);
          }
          if (frontCards.getIndex() == -1) // If at the first or last card
          forward = true;
          else if (backCards.getIndex() == -1) forward = false;
          setState(STATE_AUTO_ROTATE);
          controller.getSurfaceView().requestRender();
        }
        return isOnTouchEvent;
    }

    return false;
  }
예제 #8
0
 public void invalidateTexture() {
   frontCards.abandonTexture();
   backCards.abandonTexture();
 }
예제 #9
0
  public synchronized void draw(FlipRenderer renderer, GL10 gl) {
    applyTexture(renderer, gl);

    if (!TextureUtils.isValidTexture(frontCards.getTexture())
        && !TextureUtils.isValidTexture(backCards.getTexture())) return;

    if (!visible) return;

    switch (state) {
      case STATE_INIT:
        {
          /*if (false) { //XXX: debug only
          	if (angle >= 180)
          		forward = false;
          	else if (angle <= 0)
          		forward = true;

          	rotateBy((forward ? TIP_SPEED : -TIP_SPEED));
          	if (angle > 90 && angle <= 180 - MAX_TIP_ANGLE) {
          		forward = true;
          	} else if (angle < 90 && angle >= MAX_TIP_ANGLE) {
          		forward = false;
          	}
          }*/
        }
        break;
      case STATE_TOUCH:
        break;
      case STATE_AUTO_ROTATE:
        {
          animatedFrame++;
          rotateBy((forward ? ACCELERATION : -ACCELERATION) * animatedFrame);

          if (angle >= 180 || angle <= 0) {
            setState(STATE_INIT);
            if (angle >= 180) { // flip to next page
              if (backCards.getIndex() != -1) {
                activeIndex = backCards.getIndex();
                controller.postFlippedToView(activeIndex);
              } else angle = 180;
            }
            controller.postHideFlipAnimation();
          } else controller.getSurfaceView().requestRender();
        }
        break;
      default:
        AphidLog.e("Invalid state: " + state);
        break;
    }

    if (angle < 90) { // render front view over back view
      frontCards.getTopCard().setAngle(0);
      frontCards.getTopCard().draw(gl);

      backCards.getBottomCard().setAngle(0);
      backCards.getBottomCard().draw(gl);

      frontCards.getBottomCard().setAngle(angle);
      frontCards.getBottomCard().draw(gl);
    } else { // render back view first
      frontCards.getTopCard().setAngle(0);
      frontCards.getTopCard().draw(gl);

      backCards.getTopCard().setAngle(180 - angle);
      backCards.getTopCard().draw(gl);

      backCards.getBottomCard().setAngle(0);
      backCards.getBottomCard().draw(gl);
    }
  }