Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<activity android:name=".AnimationsActivity"></activity>
<activity android:name=".ArtboardActivity"></activity>
<activity android:name=".BuggyActivity"></activity>
<activity android:name=".LoopActivity"></activity>
</application>

</manifest>
69 changes: 69 additions & 0 deletions app/src/main/java/app/rive/runtime/example/LoopActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package app.rive.runtime.example

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.widget.AppCompatToggleButton
import app.rive.runtime.kotlin.RiveAnimationView
import app.rive.runtime.kotlin.core.Rive
import kotlin.math.absoluteValue

class LoopActivity : AppCompatActivity() {

val animationView by lazy(LazyThreadSafetyMode.NONE) {
findViewById<RiveAnimationView>(R.id.loopy)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Rive.init()
setContentView(R.layout.loopy)

findViewById<AppCompatButton>(R.id.reset).setOnClickListener { _->
animationView.reset()
}
findViewById<AppCompatButton>(R.id.play_oneshot).setOnClickListener { _->
animationView.play(animationName = "oneshot")
}
findViewById<AppCompatButton>(R.id.play_loop).setOnClickListener { _->
animationView.play(animationName = "loop")
}
findViewById<AppCompatButton>(R.id.play_pingpong).setOnClickListener { _->
animationView.play(animationName = "pingpong")
}

findViewById<AppCompatButton>(R.id.loop_oneshot).setOnClickListener { _->
animationView.loop(animationName = "oneshot")
}
findViewById<AppCompatButton>(R.id.loop_loop).setOnClickListener { _->
animationView.loop(animationName = "loop")
}
findViewById<AppCompatButton>(R.id.loop_pingpong).setOnClickListener { _->
animationView.loop(animationName = "pingpong")
}

findViewById<AppCompatButton>(R.id.oneshot_oneshot).setOnClickListener { _->
animationView.oneshot(animationName = "oneshot")
}
findViewById<AppCompatButton>(R.id.oneshot_loop).setOnClickListener { _->
animationView.oneshot(animationName = "loop")
}
findViewById<AppCompatButton>(R.id.oneshot_pingpong).setOnClickListener { _->
animationView.oneshot(animationName = "pingpong")
}

findViewById<AppCompatButton>(R.id.pingpong_oneshot).setOnClickListener { _->
animationView.pingpong(animationName = "oneshot")
}
findViewById<AppCompatButton>(R.id.pingpong_loop).setOnClickListener { _->
animationView.pingpong(animationName = "loop")
}
findViewById<AppCompatButton>(R.id.pingpong_pingpong).setOnClickListener { _->
animationView.pingpong(animationName = "pingpong")
}
}

override fun onDestroy() {
super.onDestroy()
animationView.reset()
}
}
6 changes: 6 additions & 0 deletions app/src/main/java/app/rive/runtime/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ class MainActivity : AppCompatActivity() {
)
}

findViewById<Button>(R.id.go_loopy).setOnClickListener {
startActivity(
Intent(this, LoopActivity::class.java)
)
}

}
}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/example_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/go_artboards" />

<Button
android:id="@+id/go_loopy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Control Loops"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/go_buggy" />
</androidx.constraintlayout.widget.ConstraintLayout>
171 changes: 171 additions & 0 deletions app/src/main/res/layout/loopy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">


<app.rive.runtime.kotlin.RiveAnimationView
android:id="@+id/loopy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:riveAutoPlay="false"
app:riveResource="@raw/loopy" />


<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintTop_toBottomOf="@+id/loopy">

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reset"
android:textSize="10dp" />


</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/animationOneShot"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:text="Animation: \nRotate\n 90"
android:textSize="10dp" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/play_oneshot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:textSize="10dp" />


<androidx.appcompat.widget.AppCompatButton
android:id="@+id/oneshot_oneshot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Oneshot"
android:textSize="10dp" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/loop_oneshot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loop"
android:textSize="10dp" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/pingpong_oneshot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pingpong"
android:textSize="10dp" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/animationLooop"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Animation: \nLoop\ndown up"
android:textSize="10dp" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/play_loop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:textSize="10dp" />


<androidx.appcompat.widget.AppCompatButton
android:id="@+id/oneshot_loop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Oneshot"
android:textSize="10dp" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/loop_loop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loop"
android:textSize="10dp" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/pingpong_loop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pingpong"
android:textSize="10dp" />
</LinearLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="Animation: \nPing Pong\n Ltr"
android:textSize="10dp" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/play_pingpong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Play"
android:textSize="10dp" />


<androidx.appcompat.widget.AppCompatButton
android:id="@+id/oneshot_pingpong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Oneshot"
android:textSize="10dp" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/loop_pingpong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loop"
android:textSize="10dp" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/pingpong_pingpong"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pingpong"
android:textSize="10dp" />
</LinearLayout>
</LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
Binary file added app/src/main/res/raw/loopy.riv
Binary file not shown.
18 changes: 18 additions & 0 deletions kotlin/src/main/java/app/rive/runtime/kotlin/RiveAnimationView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class RiveAnimationView(context: Context, attrs: AttributeSet?) : View(context,
private var loop: Loop = Loop.LOOP
private var alignment: Alignment = Alignment.CENTER
private var drawable: RiveDrawable = RiveDrawable(fit, alignment, loop);
private var resourceId: Int? = null;

init {
context.theme.obtainStyledAttributes(
Expand Down Expand Up @@ -55,16 +56,33 @@ class RiveAnimationView(context: Context, attrs: AttributeSet?) : View(context,
drawable.play(animationNames = animationNames, animationName = animationName)
}

fun loop(animationNames: List<String>? = null, animationName: String? = null) {
drawable.loop(animationNames = animationNames, animationName = animationName)
}

fun oneshot(animationNames: List<String>? = null, animationName: String? = null) {
drawable.oneshot(animationNames = animationNames, animationName = animationName)
}

fun pingpong(animationNames: List<String>? = null, animationName: String? = null) {
drawable.pingpong(animationNames = animationNames, animationName = animationName)
}

fun reset() {
drawable.reset()
resourceId?.let {
setRiveResource(it)
}
}

val isPlaying: Boolean
get() = drawable.isPlaying

fun setRiveResource(@RawRes resId: Int) {
resourceId = resId
val file = File(resources.openRawResource(resId).readBytes())
setAnimationFile(file)

}

fun setAnimationFile(file: File) {
Expand Down
Loading