-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathInAppLayoutService.kt
More file actions
97 lines (81 loc) · 2.89 KB
/
InAppLayoutService.kt
File metadata and controls
97 lines (81 loc) · 2.89 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.iterable.iterableapi
import android.graphics.Rect
import android.view.Gravity
import android.view.Window
import android.view.WindowManager
internal class InAppLayoutService {
internal enum class InAppLayout {
TOP,
BOTTOM,
CENTER,
FULLSCREEN
}
fun getInAppLayout(padding: Rect): InAppLayout {
return getInAppLayout(InAppPadding.fromRect(padding))
}
fun getInAppLayout(padding: InAppPadding): InAppLayout {
if (padding.top == 0 && padding.bottom == 0) {
return InAppLayout.FULLSCREEN
} else if (padding.top > 0 && padding.bottom <= 0) {
return InAppLayout.TOP
} else if (padding.top <= 0 && padding.bottom > 0) {
return InAppLayout.BOTTOM
} else {
return InAppLayout.CENTER
}
}
fun getVerticalLocation(padding: Rect): Int {
return getVerticalLocation(InAppPadding.fromRect(padding))
}
fun getVerticalLocation(padding: InAppPadding): Int {
val layout = getInAppLayout(padding)
when (layout) {
InAppLayout.TOP -> return Gravity.TOP
InAppLayout.BOTTOM -> return Gravity.BOTTOM
InAppLayout.CENTER -> return Gravity.CENTER_VERTICAL
InAppLayout.FULLSCREEN -> return Gravity.CENTER_VERTICAL
}
}
fun configureWindowFlags(window: Window?, layout: InAppLayout) {
if (window == null) {
return
}
if (layout == InAppLayout.FULLSCREEN) {
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
} else if (layout != InAppLayout.TOP) {
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
)
}
}
fun setWindowToFullScreen(window: Window?) {
window?.setLayout(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT
)
}
fun applyWindowGravity(window: Window?, padding: Rect, source: String?) {
if (window == null) {
return
}
val verticalGravity = getVerticalLocation(padding)
val params = window.attributes
when (verticalGravity) {
Gravity.CENTER_VERTICAL -> params.gravity = Gravity.CENTER
Gravity.TOP -> params.gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
Gravity.BOTTOM -> params.gravity = Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL
else -> params.gravity = Gravity.CENTER
}
window.attributes = params
if (source != null) {
IterableLogger.d(
"InAppLayoutService",
"Applied window gravity from " + source + ": " + params.gravity
)
}
}
}