Skip to content

Commit

Permalink
Update CurveView
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaoyuang committed Jul 17, 2020
1 parent c899e03 commit 19aa6b0
Show file tree
Hide file tree
Showing 32 changed files with 23 additions and 18 deletions.
Binary file removed .DS_Store
Binary file not shown.
Binary file removed app/.DS_Store
Binary file not shown.
Binary file removed app/src/.DS_Store
Binary file not shown.
Binary file removed app/src/androidTest/.DS_Store
Binary file not shown.
Binary file removed app/src/androidTest/kotlin/.DS_Store
Binary file not shown.
Binary file removed app/src/androidTest/kotlin/com/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file removed app/src/main/.DS_Store
Binary file not shown.
Binary file removed app/src/main/kotlin/.DS_Store
Binary file not shown.
Binary file removed app/src/main/kotlin/com/.DS_Store
Binary file not shown.
Binary file removed app/src/main/kotlin/com/w10group/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,18 @@ class CurveView : View {
invalidate()
}

override fun onDraw(canvas: Canvas) {
if (time.isNotEmpty() && value.isNotEmpty()) with(canvas) {
drawXText()
drawYText()
drawUnit()
drawDottedLine()
drawCurve()
drawWindow()
}
override fun onDraw(canvas: Canvas) = canvas whenTimeAndValueNotEmpty {
drawXText()
drawYText()
drawUnit()
drawDottedLine()
drawCurve()
drawWindow()
}

private inline infix fun Canvas.whenTimeAndValueNotEmpty(block: Canvas.() -> Unit) {
if (time.isNotEmpty() && value.isNotEmpty())
block()
}

// 第一步:绘制 X 轴坐标参数(时间)
Expand All @@ -181,10 +184,11 @@ class CurveView : View {
val x2 = x1 * 4 - dp16
val x3 = x1 * 7 - dp24
val x4 = fWidth - dp32
drawText(time1, x1, y, mTextPaint)
drawText(time2, x2, y, mTextPaint)
drawText(time3, x3, y, mTextPaint)
drawText(time4, x4, y, mTextPaint)
infix fun String.drawTextX(x: Float) = drawText(this, x, y, mTextPaint)
time1 drawTextX x1
time2 drawTextX x2
time3 drawTextX x3
time4 drawTextX x4
}

// 第二步:绘制 Y 轴坐标参数(查询频数)
Expand All @@ -201,10 +205,11 @@ class CurveView : View {
val y2 = y1 * 2
val y3 = y1 * 3
val y4 = y1 * 4
drawText(value4, x, y1, mTextPaint)
drawText(value3, x, y2, mTextPaint)
drawText(value2, x, y3, mTextPaint)
drawText(value1, x, y4, mTextPaint)
infix fun String.drawTextY(y: Float) = drawText(this, x, y, mTextPaint)
value4 drawTextY y1
value3 drawTextY y2
value2 drawTextY y3
value1 drawTextY y4
}

// 第三步:绘制右上角查询频数单位
Expand Down Expand Up @@ -284,7 +289,7 @@ class CurveView : View {
val windowX = if (x < width shr 1) x + binaryOffset else x - windowWidth - offset
val windowY = if (y < height shr 1) y + binaryOffset else y - windowHeight - offset

// 画竖线
// 绘制竖线
drawLine(x, startY, x, endY, mVerticalLinePaint)
// 绘制白边蓝心圆
mTouchPaint.color = white
Expand Down
Binary file removed app/src/main/res/.DS_Store
Binary file not shown.
Binary file removed app/src/main/res/drawable-hdpi/.DS_Store
Binary file not shown.
Binary file removed app/src/main/res/drawable-mdpi/.DS_Store
Binary file not shown.
Binary file removed app/src/main/res/drawable-xhdpi/.DS_Store
Binary file not shown.
Binary file removed app/src/main/res/drawable-xxhdpi/.DS_Store
Binary file not shown.
Binary file removed app/src/main/res/drawable-xxxhdpi/.DS_Store
Binary file not shown.
Binary file removed app/src/main/res/drawable/.DS_Store
Binary file not shown.
Binary file removed app/src/test/.DS_Store
Binary file not shown.
Binary file removed app/src/test/java/.DS_Store
Binary file not shown.
Binary file removed app/src/test/java/com/.DS_Store
Binary file not shown.
Binary file removed app/src/test/java/com/w10group/.DS_Store
Binary file not shown.
Binary file removed data/.DS_Store
Binary file not shown.
Binary file removed data/src/.DS_Store
Binary file not shown.
Binary file removed data/src/androidMain/.DS_Store
Binary file not shown.
Binary file removed data/src/androidMain/assets/.DS_Store
Binary file not shown.
Binary file removed gradle/.DS_Store
Binary file not shown.

0 comments on commit 19aa6b0

Please sign in to comment.