Skip to content

Instantly share code, notes, and snippets.

View hwd6190128's full-sized avatar
🏠
Working from home

Chang Hung Lun hwd6190128

🏠
Working from home
View GitHub Profile
fun Activity.hasOverlayPermission(): Boolean =
if (Build.VERSION.SDK_INT >= 23) Settings.canDrawOverlays(this) else true
fun Activity.requestOverlayPermission(requestCode: Int) {
if (Build.VERSION.SDK_INT >= 23) {
val intent = Intent(
Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:$packageName"))
startActivityForResult(intent, requestCode)
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
dialog?.window?.setFlags(
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
)
activity?.run {
dialog?.window?.decorView?.systemUiVisibility = this.window.decorView.systemUiVisibility
}
dialog?.setOnShowListener {
// prefer one
private val immersiveRunnable = Runnable {
immersiveMode(this@BaseActivity)
}
companion object {
private const val INITIAL_HIDE_DELAY = 300L
}
@hwd6190128
hwd6190128 / Event.kt
Created December 9, 2020 10:29 — forked from JoseAlcerreca/Event.kt
An event wrapper for data that is exposed via a LiveData that represents an event.
/**
* Used as a wrapper for data that is exposed via a LiveData that represents an event.
*/
open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set // Allow external read but not write
/**
* Returns the content and prevents its use again.