Convert ContextUtil to Kotlin.

This commit is contained in:
jeffrey-signal
2026-04-28 15:05:22 -04:00
committed by Greyson Parrelli
parent 40c4633d41
commit c6d91dce6e
22 changed files with 53 additions and 67 deletions
@@ -1,3 +1,5 @@
@file:JvmName("ContextUtil")
/*
* Copyright 2023 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
@@ -9,6 +11,10 @@ import android.app.DownloadManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.ContextWrapper
import android.graphics.drawable.Drawable
import android.provider.Settings
import androidx.annotation.DrawableRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.fragment.app.FragmentActivity
fun Context.getDownloadManager(): DownloadManager {
@@ -41,3 +47,16 @@ fun Context.resolveFragmentActivity(): FragmentActivity? {
else -> null
}
}
fun Context.requireDrawable(@DrawableRes drawableResId: Int): Drawable {
return AppCompatResources.getDrawable(this, drawableResId)!!
}
/**
* Gets the system animator duration scale from Settings.Global, defaulting to 1.0 when unavailable.
*
* Implementation "borrowed" from com.airbnb.lottie.utils.DebugLogViewer#getAnimationScale(android.content.Context).
*/
fun Context.getAnimationScale(): Float {
return Settings.Global.getFloat(contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f)
}