|
|
@ -40,7 +40,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
private var mMiddleY = 0f |
|
|
|
private var mMiddleY = 0f |
|
|
|
private var mDegrees = 0f |
|
|
|
private var mDegrees = 0f |
|
|
|
private var mTouchToCornerDis = 0f |
|
|
|
private var mTouchToCornerDis = 0f |
|
|
|
private var mColorMatrixFilter: ColorMatrixColorFilter = ColorMatrixColorFilter( |
|
|
|
private var mColorMatrixFilter = ColorMatrixColorFilter( |
|
|
|
ColorMatrix( |
|
|
|
ColorMatrix( |
|
|
|
floatArrayOf( |
|
|
|
floatArrayOf( |
|
|
|
1f, 0f, 0f, 0f, 0f, |
|
|
|
1f, 0f, 0f, 0f, 0f, |
|
|
@ -55,7 +55,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
|
|
|
|
|
|
|
|
// 是否属于右上左下 |
|
|
|
// 是否属于右上左下 |
|
|
|
private var mIsRtOrLb = false |
|
|
|
private var mIsRtOrLb = false |
|
|
|
private var mMaxLength = 0f |
|
|
|
private var mMaxLength = hypot(viewWidth.toDouble(), viewHeight.toDouble()).toFloat() |
|
|
|
// 背面颜色组 |
|
|
|
// 背面颜色组 |
|
|
|
private var mBackShadowColors: IntArray |
|
|
|
private var mBackShadowColors: IntArray |
|
|
|
// 前面颜色组 |
|
|
|
// 前面颜色组 |
|
|
@ -71,15 +71,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
private var mFrontShadowDrawableVLR: GradientDrawable |
|
|
|
private var mFrontShadowDrawableVLR: GradientDrawable |
|
|
|
private var mFrontShadowDrawableVRL: GradientDrawable |
|
|
|
private var mFrontShadowDrawableVRL: GradientDrawable |
|
|
|
|
|
|
|
|
|
|
|
private val mPaint: Paint = Paint() |
|
|
|
private val mPaint: Paint = Paint().apply { style = Paint.Style.FILL } |
|
|
|
|
|
|
|
|
|
|
|
private var curBitmap: Bitmap? = null |
|
|
|
private var curBitmap: Bitmap? = null |
|
|
|
private var prevBitmap: Bitmap? = null |
|
|
|
private var prevBitmap: Bitmap? = null |
|
|
|
private var nextBitmap: Bitmap? = null |
|
|
|
private var nextBitmap: Bitmap? = null |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
mMaxLength = hypot(viewWidth.toDouble(), viewWidth.toDouble()).toFloat() |
|
|
|
|
|
|
|
mPaint.style = Paint.Style.FILL |
|
|
|
|
|
|
|
//设置颜色数组 |
|
|
|
//设置颜色数组 |
|
|
|
val color = intArrayOf(0x333333, -0x4fcccccd) |
|
|
|
val color = intArrayOf(0x333333, -0x4fcccccd) |
|
|
|
mFolderShadowDrawableRL = GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, color) |
|
|
|
mFolderShadowDrawableRL = GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, color) |
|
|
@ -117,7 +115,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
|
|
|
|
|
|
|
|
override fun setViewSize(width: Int, height: Int) { |
|
|
|
override fun setViewSize(width: Int, height: Int) { |
|
|
|
super.setViewSize(width, height) |
|
|
|
super.setViewSize(width, height) |
|
|
|
mMaxLength = hypot(viewWidth.toDouble(), viewWidth.toDouble()).toFloat() |
|
|
|
mMaxLength = hypot(viewWidth.toDouble(), viewHeight.toDouble()).toFloat() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { |
|
|
|
override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { |
|
|
@ -126,7 +124,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun setTouchPoint(x: Float, y: Float, invalidate: Boolean) { |
|
|
|
override fun setTouchPoint(x: Float, y: Float, invalidate: Boolean) { |
|
|
|
super.setTouchPoint(x, y, invalidate) |
|
|
|
super.setTouchPoint(x, y, false) |
|
|
|
//触摸y中间位置吧y变成屏幕高度 |
|
|
|
//触摸y中间位置吧y变成屏幕高度 |
|
|
|
if ((startY > viewHeight * 0.33 && startY < viewHeight * 0.66) |
|
|
|
if ((startY > viewHeight * 0.33 && startY < viewHeight * 0.66) |
|
|
|
|| mDirection == Direction.PREV |
|
|
|
|| mDirection == Direction.PREV |
|
|
@ -139,6 +137,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
) { |
|
|
|
) { |
|
|
|
touchY = 1f |
|
|
|
touchY = 1f |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
pageView.invalidate() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun setDirection(direction: Direction) { |
|
|
|
override fun setDirection(direction: Direction) { |
|
|
@ -219,18 +218,22 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
override fun onDraw(canvas: Canvas) { |
|
|
|
if (mDirection === Direction.NEXT) { |
|
|
|
when (mDirection) { |
|
|
|
calcPoints() |
|
|
|
Direction.NEXT -> { |
|
|
|
drawCurrentPageArea(canvas, curBitmap, mPath0) |
|
|
|
calcPoints() |
|
|
|
drawNextPageAreaAndShadow(canvas, nextBitmap) |
|
|
|
drawCurrentPageArea(canvas, curBitmap) |
|
|
|
drawCurrentPageShadow(canvas) |
|
|
|
drawNextPageAreaAndShadow(canvas, nextBitmap) |
|
|
|
drawCurrentBackArea(canvas, curBitmap) |
|
|
|
drawCurrentPageShadow(canvas) |
|
|
|
} else { |
|
|
|
drawCurrentBackArea(canvas, curBitmap) |
|
|
|
calcPoints() |
|
|
|
} |
|
|
|
drawCurrentPageArea(canvas, prevBitmap, mPath0) |
|
|
|
Direction.PREV -> { |
|
|
|
drawNextPageAreaAndShadow(canvas, curBitmap) |
|
|
|
calcPoints() |
|
|
|
drawCurrentPageShadow(canvas) |
|
|
|
drawCurrentPageArea(canvas, prevBitmap) |
|
|
|
drawCurrentBackArea(canvas, prevBitmap) |
|
|
|
drawNextPageAreaAndShadow(canvas, curBitmap) |
|
|
|
|
|
|
|
drawCurrentPageShadow(canvas) |
|
|
|
|
|
|
|
drawCurrentBackArea(canvas, prevBitmap) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -258,7 +261,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
val left: Int |
|
|
|
val left: Int |
|
|
|
val right: Int |
|
|
|
val right: Int |
|
|
|
if (mIsRtOrLb) { |
|
|
|
if (mIsRtOrLb) { |
|
|
|
left = mBezierStart1.x.toInt() - 1 |
|
|
|
left = (mBezierStart1.x - 1).toInt() |
|
|
|
right = (mBezierStart1.x + f3 + 1).toInt() |
|
|
|
right = (mBezierStart1.x + f3 + 1).toInt() |
|
|
|
mFolderShadowDrawable = mFolderShadowDrawableLR |
|
|
|
mFolderShadowDrawable = mFolderShadowDrawableLR |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -337,17 +340,16 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
var mCurrentPageShadow: GradientDrawable |
|
|
|
var mCurrentPageShadow: GradientDrawable |
|
|
|
if (mIsRtOrLb) { |
|
|
|
if (mIsRtOrLb) { |
|
|
|
leftX = mBezierControl1.x.toInt() |
|
|
|
leftX = mBezierControl1.x.toInt() |
|
|
|
rightX = mBezierControl1.x.toInt() + 25 |
|
|
|
rightX = (mBezierControl1.x + 25).toInt() |
|
|
|
mCurrentPageShadow = mFrontShadowDrawableVLR |
|
|
|
mCurrentPageShadow = mFrontShadowDrawableVLR |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
leftX = mBezierControl1.x.toInt() - 25 |
|
|
|
leftX = (mBezierControl1.x - 25).toInt() |
|
|
|
rightX = mBezierControl1.x.toInt() + 1 |
|
|
|
rightX = (mBezierControl1.x + 1).toInt() |
|
|
|
mCurrentPageShadow = mFrontShadowDrawableVRL |
|
|
|
mCurrentPageShadow = mFrontShadowDrawableVRL |
|
|
|
} |
|
|
|
} |
|
|
|
var rotateDegrees: Float = |
|
|
|
var rotateDegrees = Math.toDegrees( |
|
|
|
Math.toDegrees( |
|
|
|
atan2(mTouchX - mBezierControl1.x, mBezierControl1.y - mTouchY).toDouble() |
|
|
|
atan2(mTouchX - mBezierControl1.x, mBezierControl1.y - mTouchY).toDouble() |
|
|
|
).toFloat() |
|
|
|
).toFloat() |
|
|
|
|
|
|
|
canvas.rotate(rotateDegrees, mBezierControl1.x, mBezierControl1.y) |
|
|
|
canvas.rotate(rotateDegrees, mBezierControl1.x, mBezierControl1.y) |
|
|
|
mCurrentPageShadow.setBounds( |
|
|
|
mCurrentPageShadow.setBounds( |
|
|
|
leftX, (mBezierControl1.y - mMaxLength).toInt(), |
|
|
|
leftX, (mBezierControl1.y - mMaxLength).toInt(), |
|
|
@ -372,24 +374,25 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
|
|
|
|
|
|
|
|
if (mIsRtOrLb) { |
|
|
|
if (mIsRtOrLb) { |
|
|
|
leftX = mBezierControl2.y.toInt() |
|
|
|
leftX = mBezierControl2.y.toInt() |
|
|
|
rightX = mBezierControl2.y.toInt() + 25 |
|
|
|
rightX = (mBezierControl2.y + 25).toInt() |
|
|
|
mCurrentPageShadow = mFrontShadowDrawableHTB |
|
|
|
mCurrentPageShadow = mFrontShadowDrawableHTB |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
leftX = mBezierControl2.y.toInt() - 25 |
|
|
|
leftX = (mBezierControl2.y - 25).toInt() |
|
|
|
rightX = mBezierControl2.y.toInt() + 1 |
|
|
|
rightX = (mBezierControl2.y + 1).toInt() |
|
|
|
mCurrentPageShadow = mFrontShadowDrawableHBT |
|
|
|
mCurrentPageShadow = mFrontShadowDrawableHBT |
|
|
|
} |
|
|
|
} |
|
|
|
rotateDegrees = Math.toDegrees( |
|
|
|
rotateDegrees = Math.toDegrees( |
|
|
|
atan2(mBezierControl2.y - mTouchY, mBezierControl2.x - mTouchX).toDouble() |
|
|
|
atan2(mBezierControl2.y - mTouchY, mBezierControl2.x - mTouchX).toDouble() |
|
|
|
).toFloat() |
|
|
|
).toFloat() |
|
|
|
canvas.rotate(rotateDegrees, mBezierControl2.x, mBezierControl2.y) |
|
|
|
canvas.rotate(rotateDegrees, mBezierControl2.x, mBezierControl2.y) |
|
|
|
val temp: Float = |
|
|
|
val temp = |
|
|
|
if (mBezierControl2.y < 0) mBezierControl2.y - viewHeight else mBezierControl2.y |
|
|
|
if (mBezierControl2.y < 0) (mBezierControl2.y - viewHeight).toDouble() |
|
|
|
val hmg = hypot(mBezierControl2.x.toDouble(), temp.toDouble()).toInt() |
|
|
|
else mBezierControl2.y.toDouble() |
|
|
|
|
|
|
|
val hmg = hypot(mBezierControl2.x.toDouble(), temp) |
|
|
|
if (hmg > mMaxLength) |
|
|
|
if (hmg > mMaxLength) |
|
|
|
mCurrentPageShadow.setBounds( |
|
|
|
mCurrentPageShadow.setBounds( |
|
|
|
(mBezierControl2.x - 25).toInt() - hmg, leftX, |
|
|
|
(mBezierControl2.x - 25 - hmg).toInt(), leftX, |
|
|
|
(mBezierControl2.x + mMaxLength).toInt() - hmg, rightX |
|
|
|
(mBezierControl2.x + mMaxLength - hmg).toInt(), rightX |
|
|
|
) |
|
|
|
) |
|
|
|
else |
|
|
|
else |
|
|
|
mCurrentPageShadow.setBounds( |
|
|
|
mCurrentPageShadow.setBounds( |
|
|
@ -400,6 +403,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
canvas.restore() |
|
|
|
canvas.restore() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
private fun drawNextPageAreaAndShadow( |
|
|
|
private fun drawNextPageAreaAndShadow( |
|
|
|
canvas: Canvas, |
|
|
|
canvas: Canvas, |
|
|
|
bitmap: Bitmap? |
|
|
|
bitmap: Bitmap? |
|
|
@ -447,10 +451,10 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
canvas.restore() |
|
|
|
canvas.restore() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// |
|
|
|
private fun drawCurrentPageArea( |
|
|
|
private fun drawCurrentPageArea( |
|
|
|
canvas: Canvas, |
|
|
|
canvas: Canvas, |
|
|
|
bitmap: Bitmap?, |
|
|
|
bitmap: Bitmap? |
|
|
|
path: Path |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
bitmap ?: return |
|
|
|
bitmap ?: return |
|
|
|
mPath0.reset() |
|
|
|
mPath0.reset() |
|
|
@ -461,11 +465,12 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi |
|
|
|
mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y) |
|
|
|
mPath0.quadTo(mBezierControl2.x, mBezierControl2.y, mBezierStart2.x, mBezierStart2.y) |
|
|
|
mPath0.lineTo(mCornerX.toFloat(), mCornerY.toFloat()) |
|
|
|
mPath0.lineTo(mCornerX.toFloat(), mCornerY.toFloat()) |
|
|
|
mPath0.close() |
|
|
|
mPath0.close() |
|
|
|
|
|
|
|
|
|
|
|
canvas.save() |
|
|
|
canvas.save() |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
|
|
|
canvas.clipOutPath(path) |
|
|
|
canvas.clipOutPath(mPath0) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
canvas.clipPath(path, Region.Op.XOR) |
|
|
|
canvas.clipPath(mPath0, Region.Op.XOR) |
|
|
|
} |
|
|
|
} |
|
|
|
canvas.drawBitmap(bitmap, 0f, 0f, null) |
|
|
|
canvas.drawBitmap(bitmap, 0f, 0f, null) |
|
|
|
canvas.restore() |
|
|
|
canvas.restore() |
|
|
|