public void reloadTexture(int frontIndex, View frontView, int backIndex, View backView) {
    synchronized (this) {
      boolean frontChanged =
          frontCards.loadView(frontIndex, frontView, controller.getAnimationBitmapFormat());
      boolean backChanged =
          backCards.loadView(backIndex, backView, controller.getAnimationBitmapFormat());

      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 (AphidLog.ENABLE_DEBUG) {
        AphidLog.d(
            "reloadTexture: activeIndex %d, front %d, back %d, angle %.1f",
            getPageIndexFromAngle(accumulatedAngle), frontIndex, backIndex, accumulatedAngle);
      }
    }
  }
  boolean refreshPageView(View view) {
    boolean match = false;
    if (frontCards.getView() == view) {
      frontCards.resetWithIndex(frontCards.getIndex());
      match = true;
    }
    if (backCards.getView() == view) {
      backCards.resetWithIndex(backCards.getIndex());
      match = true;
    }

    return match;
  }
Ejemplo n.º 3
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);
    }
  }
  public synchronized void draw(FlipRenderer renderer, GL10 gl) {
    frontCards.buildTexture(renderer, gl);
    backCards.buildTexture(renderer, gl);

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

    if (!visible) {
      return;
    }

    switch (state) {
      case STATE_INIT:
      case STATE_TOUCH:
        break;
      case STATE_AUTO_ROTATE:
        {
          animatedFrame++;
          float delta = (forward ? ACCELERATION : -ACCELERATION) * animatedFrame % 180;

          float oldAngle = accumulatedAngle;

          accumulatedAngle += delta;

          if (oldAngle < 0) { // bouncing back after flip backward and over the first page
            Assert.assertTrue(forward);
            if (accumulatedAngle >= 0) {
              accumulatedAngle = 0;
              setState(STATE_INIT);
            }
          } else {
            if (frontCards.getIndex() == maxIndex - 1
                && oldAngle
                    > frontCards.getIndex()
                        * 180) { // bouncing back after flip forward and over the last page
              Assert.assertTrue(!forward);
              if (accumulatedAngle <= frontCards.getIndex() * 180) {
                setState(STATE_INIT);
                accumulatedAngle = frontCards.getIndex() * 180;
              }
            } else {
              if (forward) {
                Assert.assertTrue(
                    "index of backCards should not be -1 when automatically flipping forward",
                    backCards.getIndex() != -1);
                if (accumulatedAngle >= backCards.getIndex() * 180) { // moved to the next page
                  accumulatedAngle = backCards.getIndex() * 180;
                  setState(STATE_INIT);
                  controller.postFlippedToView(backCards.getIndex());

                  swapCards();
                  backCards.resetWithIndex(frontCards.getIndex() + 1);
                }
              } else { // backward
                if (accumulatedAngle <= frontCards.getIndex() * 180) { // firstCards restored
                  accumulatedAngle = frontCards.getIndex() * 180;
                  setState(STATE_INIT);
                }
              }
            }
          } // ends of `if (oldAngle < 0) {} else {}`

          if (state == STATE_INIT) {
            controller.postHideFlipAnimation();
          } else {
            controller.getSurfaceView().requestRender();
          }
        }
        break;
      default:
        AphidLog.e("Invalid state: " + state);
        break;
    }

    float angle = getDisplayAngle();
    if (angle < 0) {
      frontCards.getTopCard().setAxis(Card.AXIS_BOTTOM);
      frontCards.getTopCard().setAngle(-angle);
      frontCards.getTopCard().draw(gl);

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

      // no need to draw backCards here
    } else {
      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().setAxis(Card.AXIS_TOP);
        frontCards.getBottomCard().setAngle(angle);
        frontCards.getBottomCard().draw(gl);
      } else { // render back view first
        frontCards.getTopCard().setAngle(0);
        frontCards.getTopCard().draw(gl);

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

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

    if ((frontCards.getView() == null || TextureUtils.isValidTexture(frontCards.getTexture()))
        && (backCards.getView() == null || TextureUtils.isValidTexture(backCards.getTexture())))
      firstDrawFinished = true;
  }
Ejemplo n.º 5
0
 void refreshPageView(View view) {
   if (frontCards.getView() == view) frontCards.markForceReload();
   if (backCards.getView() == view) backCards.markForceReload();
 }