From b0528ea102b92358ec91c6d0e37e4508ca5b7cca Mon Sep 17 00:00:00 2001 From: LittleMango <244261996@qq.com> Date: Wed, 13 Nov 2019 10:17:52 +0800 Subject: [PATCH] upgrade Math.pow, Math.min, Math.max api to Kotlin function. --- .../com/littlemango/stacklayoutmanager/DefaultAnimation.kt | 5 +++-- .../littlemango/stacklayoutmanager/StackLayoutManager.kt | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt index 9742e9e..d8b0b81 100644 --- a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt +++ b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/DefaultAnimation.kt @@ -2,6 +2,7 @@ package com.littlemango.stacklayoutmanager import android.view.View import com.littlemango.stacklayoutmanager.StackLayoutManager.ScrollOrientation +import kotlin.math.pow class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int) : StackAnimation(scrollOrientation, visibleCount) { @@ -72,8 +73,8 @@ class DefaultAnimation(scrollOrientation: ScrollOrientation, visibleCount: Int) scale = 1 - ((1 - mOutScale) * firstMovePercent) rotation = mOutRotation * firstMovePercent } else { - val minScale = (Math.pow(mScale.toDouble(), position.toDouble())).toFloat() - val maxScale = (Math.pow(mScale.toDouble(), (position - 1).toDouble())).toFloat() + val minScale = (mScale.toDouble().pow(position.toDouble())).toFloat() + val maxScale = (mScale.toDouble().pow((position - 1).toDouble())).toFloat() scale = minScale + (maxScale - minScale) * firstMovePercent //只对最后一个 item 做透明度变化 if (position == mVisibleCount) { diff --git a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt index 5eef721..5c5ae25 100644 --- a/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt +++ b/StackLayoutManager/src/main/java/com/littlemango/stacklayoutmanager/StackLayoutManager.kt @@ -6,6 +6,8 @@ import android.support.v7.widget.RecyclerView.SCROLL_STATE_DRAGGING import android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE import android.view.View import android.view.ViewGroup +import kotlin.math.max +import kotlin.math.min class StackLayoutManager(scrollOrientation: ScrollOrientation, visibleCount: Int, @@ -427,8 +429,8 @@ class StackLayoutManager(scrollOrientation: ScrollOrientation, private fun getValidOffset(expectOffset: Int): Int { return when(mScrollOrientation) { - ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> Math.max(Math.min(width * (itemCount - 1), expectOffset), 0) - else -> Math.max(Math.min(height * (itemCount - 1), expectOffset), 0) + ScrollOrientation.RIGHT_TO_LEFT, ScrollOrientation.LEFT_TO_RIGHT -> max(min(width * (itemCount - 1), expectOffset), 0) + else -> max(min(height * (itemCount - 1), expectOffset), 0) } }