blob: e9a872b9b0317d4a24f4be702d98394733c38c2f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
package ca.allanwang.kau.swipe
import android.app.Activity
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.ViewGroup
import ca.allanwang.kau.logging.KL
/**
* Created by Mr.Jude on 2015/8/3.
* 每个滑动页面的管理
*/
class SwipeBackPage(activity: Activity) : SwipeBackPageContract by SwipeBackLayout(activity) {
var activity: Activity? = activity
var slider: RelativeSlider
/**
* initializing is the equivalent to onCreate
* since that is when the page is created
*/
init {
activity.window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
activity.window.decorView.setBackgroundColor(Color.TRANSPARENT)
swipeBackLayout.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
slider = RelativeSlider(this)
}
fun onPostCreate() {
handleLayout()
}
override var swipeEnabled: Boolean
get() = swipeBackLayout.swipeEnabled
set(value) {
swipeBackLayout.swipeEnabled = value
handleLayout()
}
private fun handleLayout() {
KL.d("Handle layout")
if (swipeEnabled) swipeBackLayout.attachToActivity(activity!!)
else swipeBackLayout.removeFromActivity(activity!!)
}
//触发关闭Activity百分比
fun setClosePercent(percent: Float): SwipeBackPage {
swipeBackLayout.scrollThreshold=percent
return this
}
}
interface SwipeBackPageContract {
var swipeEnabled: Boolean
var scrimColor:Int
val swipeBackLayout: SwipeBackLayout
var scrollThreshold:Float
var disallowIntercept:Boolean
fun setEdgeSize(swipeEdge: Int)
fun setEdgeSizePercent(swipeEdgePercent: Float)
fun addListener(listener: SwipeListener)
fun removeListener(listener: SwipeListener)
fun scrollToFinishActivity()
}
|