-
Notifications
You must be signed in to change notification settings - Fork 30
/
RView.kt
36 lines (31 loc) · 897 Bytes
/
RView.kt
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
@file:JvmName("RichUtils")
@file:JvmMultifileClass
package pyxis.uzuki.live.richutilskt.utils
import android.os.Build
import android.view.View
import android.view.ViewGroup
import java.util.concurrent.atomic.AtomicInteger
/**
* Convert ViewGroup's Children to List<Child>
*/
fun ViewGroup.convertChildrenList() : List<View> = (0 until childCount).map { getChildAt(it) }.toList()
private val nextGeneratedId = AtomicInteger(1)
/**
* Generate View ID
*
* @return generated View ID
*/
fun generateViewId(): Int {
if (Build.VERSION.SDK_INT > 17) {
return View.generateViewId()
} else {
while (true) {
val result = nextGeneratedId.get()
var newValue = result + 1
if (newValue > 0x00FFFFFF) newValue = 1
if (nextGeneratedId.compareAndSet(result, newValue)) {
return result
}
}
}
}