Java Code Examples for com.hippo.yorozuya.MathUtils#lerp()
The following examples show how to use
com.hippo.yorozuya.MathUtils#lerp() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddDeleteDrawable.java From MHViewer with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); float canvasRotate; if (mVerticalMirror) { canvasRotate = MathUtils.lerp(270, 135f, mProgress); } else { canvasRotate = MathUtils.lerp(0f, 135f, mProgress); } canvas.save(); canvas.translate(bounds.centerX(), bounds.centerY()); canvas.rotate(canvasRotate); canvas.drawPath(mPath, mPaint); canvas.restore(); }
Example 2
Source File: AddDeleteDrawable.java From EhViewer with Apache License 2.0 | 6 votes |
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); float canvasRotate; if (mVerticalMirror) { canvasRotate = MathUtils.lerp(270, 135f, mProgress); } else { canvasRotate = MathUtils.lerp(0f, 135f, mProgress); } canvas.save(); canvas.translate(bounds.centerX(), bounds.centerY()); canvas.rotate(canvasRotate); canvas.drawPath(mPath, mPaint); canvas.restore(); }
Example 3
Source File: SearchBar.java From MHViewer with Apache License 2.0 | 5 votes |
@Override public void draw(@NonNull Canvas canvas) { if (mInAnimation) { final int state = canvas.save(); int bottom = MathUtils.lerp(mBaseHeight, mHeight, mProgress); mRect.set(0, 0, mWidth, bottom); canvas.clipRect(mRect); super.draw(canvas); canvas.restoreToCount(state); } else { super.draw(canvas); } }
Example 4
Source File: BatteryDrawable.java From MHViewer with Apache License 2.0 | 5 votes |
/** * How to draw:<br> * |------------------------------|<br> * |\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|<br> * |------------------------------|---|<br> * |/////////////////| |//|\\\|<br> * |/////////////////| |//|\\\|<br> * |------------------------------|---|<br> * |\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|<br> * |------------------------------| */ @Override public void draw(Canvas canvas) { if (mElect == -1) { return; } mElectRect.right = MathUtils.lerp(mStart, mStop, mElect / 100.0f); canvas.drawRect(mTopRect, mPaint); canvas.drawRect(mBottomRect, mPaint); canvas.drawRect(mRightRect, mPaint); canvas.drawRect(mHeadRect, mPaint); canvas.drawRect(mElectRect, mPaint); }
Example 5
Source File: SearchBar.java From EhViewer with Apache License 2.0 | 5 votes |
@Override public void draw(@NonNull Canvas canvas) { if (mInAnimation) { final int state = canvas.save(); int bottom = MathUtils.lerp(mBaseHeight, mHeight, mProgress); mRect.set(0, 0, mWidth, bottom); canvas.clipRect(mRect); super.draw(canvas); canvas.restoreToCount(state); } else { super.draw(canvas); } }
Example 6
Source File: BatteryDrawable.java From EhViewer with Apache License 2.0 | 5 votes |
/** * How to draw:<br> * |------------------------------|<br> * |\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|<br> * |------------------------------|---|<br> * |/////////////////| |//|\\\|<br> * |/////////////////| |//|\\\|<br> * |------------------------------|---|<br> * |\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\|<br> * |------------------------------| */ @Override public void draw(Canvas canvas) { if (mElect == -1) { return; } mElectRect.right = MathUtils.lerp(mStart, mStop, mElect / 100.0f); canvas.drawRect(mTopRect, mPaint); canvas.drawRect(mBottomRect, mPaint); canvas.drawRect(mRightRect, mPaint); canvas.drawRect(mHeadRect, mPaint); canvas.drawRect(mElectRect, mPaint); }
Example 7
Source File: DownloadManager.java From MHViewer with Apache License 2.0 | 4 votes |
@Override public void run() { DownloadInfo info = mCurrentTask; if (info != null) { long newSpeed = mBytesRead / 2; if (oldSpeed != -1) { newSpeed = (long) MathUtils.lerp(oldSpeed, newSpeed, 0.75f); } oldSpeed = newSpeed; info.speed = newSpeed; // Calculate remaining if (info.total <= 0) { info.remaining = -1; } else if (newSpeed == 0) { info.remaining = 300L * 24L * 60L * 60L * 1000L; // 300 days } else { int downloadingCount = 0; long downloadingContentLengthSum = 0; long totalSize = 0; for (int i = 0, n = Math.max(mContentLengthMap.size(), mReceivedSizeMap.size()); i < n; i++) { long contentLength = mContentLengthMap.valueAt(i); long receivedSize = mReceivedSizeMap.valueAt(i); downloadingCount++; downloadingContentLengthSum += contentLength; totalSize += contentLength - receivedSize; } if (downloadingCount != 0) { totalSize += downloadingContentLengthSum * (info.total - info.downloaded - downloadingCount) / downloadingCount; info.remaining = totalSize / newSpeed * 1000; } } if (mDownloadListener != null) { mDownloadListener.onDownload(info); } List<DownloadInfo> list = getInfoListForLabel(info.label); if (list != null) { for (DownloadInfoListener l: mDownloadInfoListeners) { l.onUpdate(info, list); } } } mBytesRead = 0; if (!mStop) { SimpleHandler.getInstance().postDelayed(this, 2000); } }
Example 8
Source File: DrawerArrowDrawable.java From MHViewer with Apache License 2.0 | 4 votes |
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); // Interpolated widths of arrow bars final float arrowSize = MathUtils.lerp(mBarSize, mTopBottomArrowSize, mProgress); final float middleBarSize = MathUtils.lerp(mBarSize, mMiddleArrowSize, mProgress); // Interpolated size of middle bar final float middleBarCut = Math.round(MathUtils.lerp(0, mMaxCutForBarSize, mProgress)); // The rotation of the top and bottom bars (that make the arrow head) final float rotation = MathUtils.lerp(0, ARROW_HEAD_ANGLE, mProgress); // The whole canvas rotates as the transition happens final float canvasRotate = MathUtils.lerp(-180, 0, mProgress); final float arrowWidth = Math.round(arrowSize * Math.cos(rotation)); final float arrowHeight = Math.round(arrowSize * Math.sin(rotation)); mPath.rewind(); final float topBottomBarOffset = MathUtils.lerp(mBarGap + mBarThickness, -mMaxCutForBarSize, mProgress); final float arrowEdge = -middleBarSize / 2; // draw middle bar mPath.moveTo(arrowEdge + middleBarCut, 0); mPath.rLineTo(middleBarSize - middleBarCut * 2, 0); // bottom bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // top bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); mPath.close(); canvas.save(); // Rotate the whole canvas if spinning, if not, rotate it 180 to get // the arrow pointing the other way for RTL. canvas.translate(bounds.centerX(), bounds.centerY()); if (mSpin) { canvas.rotate(canvasRotate * (mVerticalMirror ? -1 : 1)); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
Example 9
Source File: DownloadManager.java From EhViewer with Apache License 2.0 | 4 votes |
@Override public void run() { DownloadInfo info = mCurrentTask; if (info != null) { long newSpeed = mBytesRead / 2; if (oldSpeed != -1) { newSpeed = (long) MathUtils.lerp(oldSpeed, newSpeed, 0.75f); } oldSpeed = newSpeed; info.speed = newSpeed; // Calculate remaining if (info.total <= 0) { info.remaining = -1; } else if (newSpeed == 0) { info.remaining = 300L * 24L * 60L * 60L * 1000L; // 300 days } else { int downloadingCount = 0; long downloadingContentLengthSum = 0; long totalSize = 0; for (int i = 0, n = Math.max(mContentLengthMap.size(), mReceivedSizeMap.size()); i < n; i++) { long contentLength = mContentLengthMap.valueAt(i); long receivedSize = mReceivedSizeMap.valueAt(i); downloadingCount++; downloadingContentLengthSum += contentLength; totalSize += contentLength - receivedSize; } if (downloadingCount != 0) { totalSize += downloadingContentLengthSum * (info.total - info.downloaded - downloadingCount) / downloadingCount; info.remaining = totalSize / newSpeed * 1000; } } if (mDownloadListener != null) { mDownloadListener.onDownload(info); } List<DownloadInfo> list = getInfoListForLabel(info.label); if (list != null) { for (DownloadInfoListener l: mDownloadInfoListeners) { l.onUpdate(info, list); } } } mBytesRead = 0; if (!mStop) { SimpleHandler.getInstance().postDelayed(this, 2000); } }
Example 10
Source File: DrawerArrowDrawable.java From EhViewer with Apache License 2.0 | 4 votes |
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); // Interpolated widths of arrow bars final float arrowSize = MathUtils.lerp(mBarSize, mTopBottomArrowSize, mProgress); final float middleBarSize = MathUtils.lerp(mBarSize, mMiddleArrowSize, mProgress); // Interpolated size of middle bar final float middleBarCut = Math.round(MathUtils.lerp(0, mMaxCutForBarSize, mProgress)); // The rotation of the top and bottom bars (that make the arrow head) final float rotation = MathUtils.lerp(0, ARROW_HEAD_ANGLE, mProgress); // The whole canvas rotates as the transition happens final float canvasRotate = MathUtils.lerp(-180, 0, mProgress); final float arrowWidth = Math.round(arrowSize * Math.cos(rotation)); final float arrowHeight = Math.round(arrowSize * Math.sin(rotation)); mPath.rewind(); final float topBottomBarOffset = MathUtils.lerp(mBarGap + mBarThickness, -mMaxCutForBarSize, mProgress); final float arrowEdge = -middleBarSize / 2; // draw middle bar mPath.moveTo(arrowEdge + middleBarCut, 0); mPath.rLineTo(middleBarSize - middleBarCut * 2, 0); // bottom bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // top bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); mPath.close(); canvas.save(); // Rotate the whole canvas if spinning, if not, rotate it 180 to get // the arrow pointing the other way for RTL. canvas.translate(bounds.centerX(), bounds.centerY()); if (mSpin) { canvas.rotate(canvasRotate * (mVerticalMirror ? -1 : 1)); } canvas.drawPath(mPath, mPaint); canvas.restore(); }