[go: nahoru, domu]

ktx module for dynamicanimation

- Module setup
- Extensions for dynamic animation API

Extensions update

- Removed extensions for instantiating SpringAnimation and attaching SpringForce.
- Merged two extensions for creating SpringAnimation into one with default value for finalPosition.

Test: Not done yet because extensions need to be finalise.

Change-Id: I863f73500187e537e8bbb13d4d5236b5756afc96
diff --git a/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt b/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
index e62d10c..c5a83bd 100644
--- a/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
+++ b/buildSrc/src/main/kotlin/androidx/build/LibraryVersions.kt
@@ -34,6 +34,7 @@
     val COLLECTION = Version("1.1.0-alpha01")
     val COORDINATORLAYOUT = Version("1.1.0-alpha01")
     val CORE = Version("1.1.0-alpha01")
+    val DYNAMICANIMATION_KTX = Version("1.0.0-alpha01")
     val FRAGMENT = Version("1.1.0-alpha01")
     val FUTURES = Version("1.0.0-alpha02")
     val GRIDLAYOUT = Version("1.1.0-alpha01")
diff --git a/dynamic-animation/ktx/api/1.0.0-alpha01.txt b/dynamic-animation/ktx/api/1.0.0-alpha01.txt
new file mode 100644
index 0000000..01c8728
--- /dev/null
+++ b/dynamic-animation/ktx/api/1.0.0-alpha01.txt
@@ -0,0 +1,12 @@
+// Signature format: 2.0
+package androidx.dynamicanimation.animation {
+
+  public final class DynamicAnimationKt {
+    ctor public DynamicAnimationKt();
+    method public static <K extends android.view.View> androidx.dynamicanimation.animation.FlingAnimation flingAnimationOf(K, androidx.dynamicanimation.animation.FloatPropertyCompat<K> property);
+    method public static <K extends android.view.View> androidx.dynamicanimation.animation.SpringAnimation springAnimationOf(K, androidx.dynamicanimation.animation.FloatPropertyCompat<K> property, float finalPosition = Float.NaN);
+    method public static androidx.dynamicanimation.animation.SpringAnimation withSpringForceProperties(androidx.dynamicanimation.animation.SpringAnimation, kotlin.jvm.functions.Function1<? super androidx.dynamicanimation.animation.SpringForce,kotlin.Unit> func);
+  }
+
+}
+
diff --git a/dynamic-animation/ktx/build.gradle b/dynamic-animation/ktx/build.gradle
new file mode 100644
index 0000000..d2c0d63
--- /dev/null
+++ b/dynamic-animation/ktx/build.gradle
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import androidx.build.LibraryGroups
+import androidx.build.LibraryVersions
+
+import static androidx.build.dependencies.DependenciesKt.JUNIT
+import static androidx.build.dependencies.DependenciesKt.KOTLIN_STDLIB
+import static androidx.build.dependencies.DependenciesKt.TEST_RULES
+import static androidx.build.dependencies.DependenciesKt.TEST_RUNNER
+import static androidx.build.dependencies.DependenciesKt.TRUTH
+
+plugins {
+    id("SupportAndroidLibraryPlugin")
+    id("org.jetbrains.kotlin.android")
+}
+
+android {
+
+    buildTypes {
+        debug {
+            testCoverageEnabled = false // Breaks Kotlin compiler.
+        }
+    }
+
+}
+
+dependencies {
+    api(KOTLIN_STDLIB)
+    api(project(":dynamicanimation"))
+
+    androidTestImplementation(JUNIT)
+    androidTestImplementation(TEST_RUNNER)
+    androidTestImplementation(TEST_RULES)
+    androidTestImplementation(TRUTH)
+}
+
+supportLibrary {
+    name = "Dynamic animation Kotlin Extensions"
+    publish = true
+    mavenVersion = LibraryVersions.DYNAMICANIMATION_KTX
+    mavenGroup = LibraryGroups.DYNAMICANIMATION
+    inceptionYear = "2018"
+    description = "Kotlin extensions for 'dynamicanimation' artifact"
+    useMetalava = true
+}
diff --git a/dynamic-animation/ktx/src/main/AndroidManifest.xml b/dynamic-animation/ktx/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..2db6f1d
--- /dev/null
+++ b/dynamic-animation/ktx/src/main/AndroidManifest.xml
@@ -0,0 +1,17 @@
+<!--
+  ~ Copyright 2018 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<manifest package="androidx.dynamicanimation.ktx"/>
\ No newline at end of file
diff --git a/dynamic-animation/ktx/src/main/java/androidx/dynamicanimation/animation/DynamicAnimation.kt b/dynamic-animation/ktx/src/main/java/androidx/dynamicanimation/animation/DynamicAnimation.kt
new file mode 100644
index 0000000..7a25b3e
--- /dev/null
+++ b/dynamic-animation/ktx/src/main/java/androidx/dynamicanimation/animation/DynamicAnimation.kt
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package androidx.dynamicanimation.animation
+
+import android.view.View
+
+/**
+ * Creates [FlingAnimation] for view.
+ *
+ * @param property View property to be animated.
+ * @return [FlingAnimation]
+ */
+inline fun <K : View> K.flingAnimationOf(property: FloatPropertyCompat<K>): FlingAnimation {
+    return FlingAnimation(this, property)
+}
+
+/**
+ * Creates [SpringAnimation] for view.
+ * If finalPosition is not [Float.NaN] then create [SpringAnimation] with
+ * [SpringForce.mFinalPosition].
+ *
+ * @param property View property to be animated.
+ * @param finalPosition [SpringForce.mFinalPosition] Final position of spring.
+ * @return [SpringAnimation]
+ */
+inline fun <K : View> K.springAnimationOf(
+    property: FloatPropertyCompat<K>,
+    finalPosition: Float = Float.NaN
+): SpringAnimation {
+    return if (finalPosition.isNaN()) {
+        SpringAnimation(this, property)
+    } else {
+        SpringAnimation(this, property, finalPosition)
+    }
+}
+
+/**
+ * Updates or applies spring force properties like [SpringForce.mDampingRatio],
+ * [SpringForce.mFinalPosition] and stiffness on SpringAnimation.
+ *
+ * If [SpringAnimation.mSpring] is null in case [SpringAnimation] is created without final position
+ * it will be created and attached to [SpringAnimation]
+ *
+ * @param func lambda with receiver on [SpringForce]
+ * @return [SpringAnimation]
+ */
+inline fun SpringAnimation.withSpringForceProperties(
+    func: SpringForce.() -> Unit
+): SpringAnimation {
+    if (spring == null) {
+        spring = SpringForce()
+    }
+    spring.func()
+    return this
+}
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
index 7af8f7b..d4a2bca 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -63,6 +63,7 @@
 includeProject(":documentfile", "documentfile")
 includeProject(":drawerlayout", "drawerlayout")
 includeProject(":dynamicanimation", "dynamic-animation")
+includeProject(":dynamicanimation-ktx", "dynamic-animation/ktx")
 includeProject(":emoji", "emoji/core")
 includeProject(":emoji-bundled", "emoji/bundled")
 includeProject(":emoji-appcompat", "emoji/appcompat")