• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.airbnb.lottie.samples
2 
3 import android.graphics.PointF
4 import android.os.Bundle
5 import androidx.customview.widget.ViewDragHelper
6 import androidx.appcompat.app.AppCompatActivity
7 import android.view.View
8 import com.airbnb.lottie.LottieProperty
9 import com.airbnb.lottie.model.KeyPath
10 import com.airbnb.lottie.value.LottieRelativePointValueCallback
11 import kotlinx.android.synthetic.main.activity_bullseye.*
12 
13 class BullseyeActivity : AppCompatActivity() {
14 
onCreatenull15     override fun onCreate(savedInstanceState: Bundle?) {
16         super.onCreate(savedInstanceState)
17         setContentView(R.layout.activity_bullseye)
18 
19         val largeValueCallback = LottieRelativePointValueCallback(PointF(0f, 0f))
20         animationView.addValueCallback(KeyPath("First"), LottieProperty.TRANSFORM_POSITION, largeValueCallback)
21 
22         val mediumValueCallback = LottieRelativePointValueCallback(PointF(0f, 0f))
23         animationView.addValueCallback(KeyPath("Fourth"), LottieProperty.TRANSFORM_POSITION, mediumValueCallback)
24 
25         val smallValueCallback = LottieRelativePointValueCallback(PointF(0f, 0f))
26         animationView.addValueCallback(KeyPath("Seventh"), LottieProperty.TRANSFORM_POSITION, smallValueCallback)
27 
28         var totalDx = 0f
29         var totalDy = 0f
30 
31         val viewDragHelper = ViewDragHelper.create(containerView, object : ViewDragHelper.Callback() {
32             override fun tryCaptureView(child: View, pointerId: Int) = child == targetView
33 
34             override fun clampViewPositionVertical(child: View, top: Int, dy: Int): Int {
35                 return top
36             }
37 
38             override fun clampViewPositionHorizontal(child: View, left: Int, dx: Int): Int {
39                 return left
40             }
41 
42             override fun onViewPositionChanged(changedView: View, left: Int, top: Int, dx: Int, dy: Int) {
43                 totalDx += dx
44                 totalDy += dy
45                 smallValueCallback.setValue(getPoint(totalDx, totalDy, 1.2f))
46                 mediumValueCallback.setValue(getPoint(totalDx, totalDy, 1f))
47                 largeValueCallback.setValue(getPoint(totalDx, totalDy, 0.75f))
48             }
49         })
50 
51         containerView.viewDragHelper = viewDragHelper
52     }
53 
getPointnull54     private fun getPoint(dx: Float, dy: Float, factor: Float) = PointF(dx * factor, dy * factor)
55 }