MCPcopy Create free account
hub / github.com/Snapchat/Valdi / EdgeEffectWrapper

Class EdgeEffectWrapper

valdi/src/java/com/snap/valdi/views/EdgeEffectWrapper.kt:16–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16class EdgeEffectWrapper(private val context: Context, private val edge: Edge) {
17
18 private var edgeEffect: EdgeEffect? = null
19
20 val isFinished: Boolean
21 get() = edgeEffect?.isFinished ?: true
22
23 private var lastDistance = 0f
24 private var isPulling = false
25 private var isReleasing = true
26 private var effectWidth = 0
27 private var effectHeight = 0
28
29 private fun prepareCanvas(canvas: Canvas, boundsWidth: Int, boundsHeight: Int) {
30 when (edge) {
31 Edge.LEFT -> {
32 canvas.rotate(270f)
33 canvas.translate(-boundsHeight.toFloat(), 0f)
34 }
35 Edge.TOP -> {
36 }
37 Edge.RIGHT -> {
38 canvas.rotate(90f)
39 canvas.translate(0f, -boundsWidth.toFloat())
40 }
41 Edge.BOTTOM -> {
42 canvas.rotate(180f)
43 canvas.translate(-boundsWidth.toFloat(), -boundsHeight.toFloat())
44 }
45 }
46 }
47
48 private fun getEdge(): EdgeEffect {
49 if (edgeEffect == null) {
50 edgeEffect = EdgeEffect(context)
51 edgeEffect!!.setSize(effectWidth, effectHeight)
52 }
53 return edgeEffect!!
54 }
55
56 fun draw(canvas: Canvas, boundsWidth: Int, boundsHeight: Int): Boolean {
57 val unwrappedEdgeEffect = edgeEffect ?: return false
58
59 val restore = canvas.save()
60 prepareCanvas(canvas, boundsWidth, boundsHeight)
61 val shouldKeepDrawing = unwrappedEdgeEffect.draw(canvas)
62 canvas.restoreToCount(restore)
63 if (!shouldKeepDrawing || unwrappedEdgeEffect.isFinished) {
64 finish()
65 }
66 return shouldKeepDrawing
67 }
68
69 fun setSize(width: Int, height: Int) {
70 val effectiveWidth: Int
71 val effectiveHeight: Int
72
73 when (edge) {

Callers 1

ValdiScrollViewClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected