/** Called when a drawer animation has successfully completed. */ private void completeAnimation() { mScroller.abortAnimation(); final int finalX = mScroller.getFinalX(); setOffsetPixels(finalX); setDrawerState(finalX == 0 ? STATE_CLOSED : STATE_OPEN); stopLayerTranslation(); }
/** Callback when each frame in the peek drawer animation should be drawn. */ @SuppressLint("NewApi") private void peekDrawerInvalidate() { if (mPeekScroller.computeScrollOffset()) { final int oldX = (int) mOffsetPixels; final int x = mPeekScroller.getCurrX(); if (x != oldX) { setOffsetPixels(x); } if (!mPeekScroller.isFinished()) { postOnAnimation(mPeekRunnable); return; } else if (mPeekDelay > 0) { mPeekStartRunnable = new Runnable() { @Override public void run() { startPeek(); } }; postDelayed(mPeekStartRunnable, mPeekDelay); } } completePeek(); }
private void update() { if (player.updatePlayerPos()) { scroller.scrollToPos(world.scrollStart); } scroller.updateScrolling(); player.updateInertia(); scroller.updateCamera(); world.update(); }
/** Callback when each frame in the drawer animation should be drawn. */ private void postAnimationInvalidate() { if (mScroller.computeScrollOffset(false)) { final int oldX = (int) mOffsetPixels; final int x = mScroller.getCurrX(); if (x != oldX) setOffsetPixels(x); if (x != mScroller.getFinalX()) { postOnAnimation(mDragRunnable); return; } } completeAnimation(); }
void stop() { myCursorInMovement = ZLTextSelectionCursor.None; if (myScroller != null) { myScroller.stop(); myScroller = null; } }
protected void animateOffsetTo(int position, int duration) { final int startX = (int) mOffsetPixels; final int dx = position - startX; if (dx > 0) { setDrawerState(STATE_OPENING); mScroller.startScroll(startX, 0, dx, 0, duration); } else { setDrawerState(STATE_CLOSING); mScroller.startScroll(startX, 0, dx, 0, duration); } startLayerTranslation(); postAnimationInvalidate(); }
/** Called when the peek drawer animation has successfully completed. */ private void completePeek() { mPeekScroller.abortAnimation(); setOffsetPixels(0); setDrawerState(STATE_CLOSED); stopLayerTranslation(); }
/** Callback when each frame in the peek drawer animation should be drawn. */ private void peekDrawerInvalidate() { boolean holdPeek; if (mPeekDelay < 0) holdPeek = true; else holdPeek = false; if (mPeekScroller.computeScrollOffset(holdPeek)) { final int oldX = (int) mOffsetPixels; final int x = mPeekScroller.getCurrX(); if (x != oldX) setOffsetPixels(x); if (!mPeekScroller.isFinished()) { // Log.e("DraggableDrawer", "mPeekScroller is not finished"); postOnAnimation(mPeekRunnable); return; } else if (mPeekDelay > 0) { // Log.e("DraggableDrawer", "mPeekScroller is finished"); mPeekStartRunnable = new Runnable() { @Override public void run() { startPeek(); } }; if (mPeekDelay >= 0) postDelayed(mPeekStartRunnable, mPeekDelay); // else // postDelayed(mPeekStartRunnable, 1000); } } if (mPeekDelay > 0) completePeek(); }
/** * Moves the drawer to the position passed. * * @param position The position the content is moved to. * @param velocity Optional velocity if called by releasing a drag event. * @param animate Whether the move is animated. */ protected void animateOffsetTo(int position, int velocity, boolean animate) { endDrag(); endPeek(); final int startX = (int) mOffsetPixels; final int dx = position - startX; if (dx == 0 || !animate) { setOffsetPixels(position); setDrawerState(position == 0 ? STATE_CLOSED : STATE_OPEN); stopLayerTranslation(); return; } int duration; velocity = Math.abs(velocity); if (velocity > 0) { duration = 4 * Math.round(1000.f * Math.abs((float) dx / velocity)); } else { duration = (int) (600.f * Math.abs((float) dx / mMenuSize)); } duration = Math.min(duration, mMaxAnimationDuration); if (dx > 0) { setDrawerState(STATE_OPENING); mScroller.startScroll(startX, 0, dx, 0, duration); } else { setDrawerState(STATE_CLOSING); mScroller.startScroll(startX, 0, dx, 0, duration); } startLayerTranslation(); postAnimationInvalidate(); }
@Override public void create() { sb = new SpriteBatch(); fsb = new SpriteBatch(); initBackground(); initFonts(); float lum = 0.3f; Gdx.gl.glClearColor(lum, lum, lum, 1.0f); world = new World(); player = new Player(world); scroller = new Scroller(player); scroller.scrollToPos(world.scrollStart); }
void expandTo(int x, int y) { if (isEmpty()) { return; } final ZLTextElementAreaVector vector = myView.myCurrentPage.TextElementMap; final ZLTextElementArea firstArea = vector.getFirstArea(); final ZLTextElementArea lastArea = vector.getLastArea(); if (firstArea != null && y < firstArea.YStart) { if (myScroller != null && myScroller.scrollsForward()) { myScroller.stop(); myScroller = null; } if (myScroller == null) { myScroller = new Scroller(false, x, y); return; } } else if (lastArea != null && y + ZLTextSelectionCursor.getHeight() / 2 + ZLTextSelectionCursor.getAccent() / 2 > lastArea.YEnd) { if (myScroller != null && !myScroller.scrollsForward()) { myScroller.stop(); myScroller = null; } if (myScroller == null) { myScroller = new Scroller(true, x, y); return; } } else { if (myScroller != null) { myScroller.stop(); myScroller = null; } } if (myScroller != null) { myScroller.setXY(x, y); } ZLTextRegion region = myView.findRegion(x, y, ZLTextView.MAX_SELECTION_DISTANCE, ZLTextRegion.AnyRegionFilter); if (region == null && myScroller != null) { region = myView.findRegion(x, y, ZLTextRegion.AnyRegionFilter); } if (region == null) { return; } final ZLTextRegion.Soul soul = region.getSoul(); if (myCursorInMovement == ZLTextSelectionCursor.Right) { if (myLeftMostRegionSoul.compareTo(soul) <= 0) { myRightMostRegionSoul = soul; } else { myRightMostRegionSoul = myLeftMostRegionSoul; myLeftMostRegionSoul = soul; myCursorInMovement = ZLTextSelectionCursor.Left; } } else { if (myRightMostRegionSoul.compareTo(soul) >= 0) { myLeftMostRegionSoul = soul; } else { myLeftMostRegionSoul = myRightMostRegionSoul; myRightMostRegionSoul = soul; myCursorInMovement = ZLTextSelectionCursor.Right; } } if (myCursorInMovement == ZLTextSelectionCursor.Right) { if (hasAPartAfterPage(myView.myCurrentPage)) { myView.scrollPage(true, ZLTextView.ScrollingMode.SCROLL_LINES, 1); myView.Application.getViewWidget().reset(); myView.preparePaintInfo(); } } else { if (hasAPartBeforePage(myView.myCurrentPage)) { myView.scrollPage(false, ZLTextView.ScrollingMode.SCROLL_LINES, 1); myView.Application.getViewWidget().reset(); myView.preparePaintInfo(); } } }
/** Stops ongoing animation of the drawer. */ protected void stopAnimation() { removeCallbacks(mDragRunnable); mScroller.abortAnimation(); stopLayerTranslation(); }