aboutsummaryrefslogtreecommitdiff
path: root/core-ui
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-10-19 22:30:16 -0700
committerAllan Wang <me@allanwang.ca>2019-10-19 22:31:14 -0700
commit7007e61879bf33c09115b5d8bc16f27af2731045 (patch)
tree19bc5e07f16ce1b6b9d13c711fed5160e25bc3ad /core-ui
parent63f920c3257e955da1ef63c91f8b5e2de5478e55 (diff)
downloadkau-7007e61879bf33c09115b5d8bc16f27af2731045.tar.gz
kau-7007e61879bf33c09115b5d8bc16f27af2731045.tar.bz2
kau-7007e61879bf33c09115b5d8bc16f27af2731045.zip
Convert java math to kotlin math
Diffstat (limited to 'core-ui')
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt8
-rw-r--r--core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt9
2 files changed, 11 insertions, 6 deletions
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
index 474d40a..7669a2a 100644
--- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/views/CutoutView.kt
@@ -33,6 +33,8 @@ import ca.allanwang.kau.utils.dimenPixelSize
import ca.allanwang.kau.utils.getFont
import ca.allanwang.kau.utils.parentViewGroup
import ca.allanwang.kau.utils.toBitmap
+import kotlin.math.max
+import kotlin.math.min
/**
* A view which punches out some text from an opaque color block, allowing you to see through it.
@@ -133,7 +135,7 @@ class CutoutView @JvmOverloads constructor(
if (drawable!!.intrinsicHeight <= 0 || drawable!!.intrinsicWidth <= 0) throw IllegalArgumentException("Drawable's intrinsic size cannot be less than 0")
val targetWidth = width / PHI
val targetHeight = height / PHI
- bitmapScaling = Math.min(targetHeight / drawable!!.intrinsicHeight, targetWidth / drawable!!.intrinsicWidth)
+ bitmapScaling = min(targetHeight / drawable!!.intrinsicHeight, targetWidth / drawable!!.intrinsicWidth)
cutoutX = (width - drawable!!.intrinsicWidth * bitmapScaling) / 2
cutoutY = (height - drawable!!.intrinsicHeight * bitmapScaling) / 2
}
@@ -143,9 +145,9 @@ class CutoutView @JvmOverloads constructor(
*/
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
parentViewGroup.getWindowVisibleDisplayFrame(parentFrame)
- val minHeight = Math.max(minHeight, heightPercentage * parentFrame.height())
+ val minHeight = max(minHeight, heightPercentage * parentFrame.height())
val trueHeightMeasureSpec = if (minHeight > 0)
- MeasureSpec.makeMeasureSpec(Math.max(minHeight.toInt(), measuredHeight), MeasureSpec.EXACTLY)
+ MeasureSpec.makeMeasureSpec(max(minHeight.toInt(), measuredHeight), MeasureSpec.EXACTLY)
else heightMeasureSpec
super.onMeasure(widthMeasureSpec, trueHeightMeasureSpec)
}
diff --git a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt
index 6095a32..ab0e464 100644
--- a/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt
+++ b/core-ui/src/main/kotlin/ca/allanwang/kau/ui/widgets/ElasticDragDismissFrameLayout.kt
@@ -34,6 +34,9 @@ import ca.allanwang.kau.utils.navigationBarColor
import ca.allanwang.kau.utils.scaleXY
import ca.allanwang.kau.utils.statusBarColor
import ca.allanwang.kau.utils.withAlpha
+import kotlin.math.abs
+import kotlin.math.log10
+import kotlin.math.min
/**
* A [FrameLayout] which responds to nested scrolls to create drag-dismissable layouts.
@@ -136,7 +139,7 @@ class ElasticDragDismissFrameLayout @JvmOverloads constructor(
}
override fun onStopNestedScroll(child: View) {
- if (Math.abs(totalDrag) >= dragDismissDistance) {
+ if (abs(totalDrag) >= dragDismissDistance) {
dispatchDismissCallback()
} else { // settle back to natural position
@@ -192,7 +195,7 @@ class ElasticDragDismissFrameLayout @JvmOverloads constructor(
}
// how far have we dragged relative to the distance to perform a dismiss
// (0–1 where 1 = dismiss distance). Decreasing logarithmically as we approach the limit
- var dragFraction = Math.log10((1 + Math.abs(totalDrag) / dragDismissDistance).toDouble()).toFloat()
+ var dragFraction = log10((1 + abs(totalDrag) / dragDismissDistance).toDouble()).toFloat()
// calculate the desired translation given the drag fraction
var dragTo = dragFraction * dragDismissDistance * dragElacticity
@@ -221,7 +224,7 @@ class ElasticDragDismissFrameLayout @JvmOverloads constructor(
}
dispatchDragCallback(
dragFraction, dragTo,
- Math.min(1f, Math.abs(totalDrag) / dragDismissDistance), totalDrag
+ min(1f, abs(totalDrag) / dragDismissDistance), totalDrag
)
}