private void debugBufferedViews() {
   if (AphidLog.ENABLE_DEBUG) {
     AphidLog.d(
         "bufferedViews: %s; buffer index %d, adapter index %d",
         bufferedViews, bufferIndex, adapterIndex);
   }
 }
  // --------------------------------------------------------------------------------------------------------------------
  // Layout
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    if (AphidLog.ENABLE_DEBUG) {
      AphidLog.d("onLayout: %d, %d, %d, %d; child %d", l, t, r, b, bufferedViews.size());
    }

    for (View child : bufferedViews) {
      child.layout(0, 0, r - l, b - t);
    }

    if (changed || contentWidth == 0) {
      int w = r - l;
      int h = b - t;
      surfaceView.layout(0, 0, w, h);

      if (contentWidth != w || contentHeight != h) {
        contentWidth = w;
        contentHeight = h;
      }
    }

    if (bufferedViews.size() >= 1) {
      View frontView = bufferedViews.get(bufferIndex);
      View backView = null;
      if (bufferIndex < bufferedViews.size() - 1) {
        backView = bufferedViews.get(bufferIndex + 1);
      }
      renderer.updateTexture(
          adapterIndex, frontView, backView == null ? -1 : adapterIndex + 1, backView);
    }
  }
  void flippedToView(final int indexInAdapter, boolean isPost) {
    if (AphidLog.ENABLE_DEBUG) {
      AphidLog.d("flippedToView: %d, isPost %s", indexInAdapter, isPost);
    }

    debugBufferedViews();

    if (indexInAdapter >= 0 && indexInAdapter < adapterDataCount) {

      if (indexInAdapter == adapterIndex + 1) { // forward one page
        if (adapterIndex < adapterDataCount - 1) {
          adapterIndex++;
          View old = bufferedViews.get(bufferIndex);
          if (bufferIndex + 1 > sideBufferSize) {
            releaseView(bufferedViews.removeFirst());
          }
          if (adapterIndex + sideBufferSize < adapterDataCount) {
            bufferedViews.addLast(viewFromAdapter(adapterIndex + sideBufferSize, true));
          }
          bufferIndex = bufferedViews.indexOf(old) + 1;
          requestLayout();
          updateVisibleView(bufferIndex);
        }
      } else if (indexInAdapter == adapterIndex - 1) {
        if (adapterIndex > 0) {
          adapterIndex--;
          View old = bufferedViews.get(bufferIndex);
          if (bufferIndex - 1 + sideBufferSize < bufferedViews.size() - 1) {
            releaseView(bufferedViews.removeLast());
          }
          if (adapterIndex - sideBufferSize >= 0) {
            bufferedViews.addFirst(viewFromAdapter(adapterIndex - sideBufferSize, false));
          }
          bufferIndex = bufferedViews.indexOf(old) - 1;
          requestLayout();
          updateVisibleView(bufferIndex);
        }
      } else {
        AphidLog.e(
            "Should not happen: indexInAdapter %d, adapterIndex %d", indexInAdapter, adapterIndex);
      }
    } else {
      Assert.fail("Invalid indexInAdapter: " + indexInAdapter);
    }
    // debugBufferedViews();
  }
 public boolean handleMessage(Message msg) {
   if (msg.what == MSG_SURFACE_CREATED) {
     contentWidth = 0;
     contentHeight = 0;
     requestLayout();
     return true;
   } else {
     AphidLog.w("Unknown msg.what: " + msg.what);
   }
   return false;
 }
示例#5
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);
    }
  }
示例#6
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);
    }
  }