mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-15 13:37:29 +01:00
Remove usage of alpha color selectors (fixes #2957)
Doesn't work properly in API < 23
This commit is contained in:
@@ -9,11 +9,13 @@ import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.net.ConnectivityManager
|
||||
import android.net.Uri
|
||||
import android.os.PowerManager
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import androidx.core.app.NotificationCompat
|
||||
@@ -22,6 +24,7 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.nononsenseapps.filepicker.FilePickerActivity
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.widget.CustomLayoutPickerActivity
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/**
|
||||
* Display a toast in this context.
|
||||
@@ -96,12 +99,22 @@ fun Context.hasPermission(permission: String) = ContextCompat.checkSelfPermissio
|
||||
* Returns the color for the given attribute.
|
||||
*
|
||||
* @param resource the attribute.
|
||||
* @param alphaFactor the alpha number [0,1].
|
||||
*/
|
||||
fun Context.getResourceColor(@AttrRes resource: Int): Int {
|
||||
@ColorInt fun Context.getResourceColor(@AttrRes resource: Int, alphaFactor: Float = 1f): Int {
|
||||
val typedArray = obtainStyledAttributes(intArrayOf(resource))
|
||||
val attrValue = typedArray.getColor(0, 0)
|
||||
val color = typedArray.getColor(0, 0)
|
||||
typedArray.recycle()
|
||||
return attrValue
|
||||
|
||||
if (alphaFactor < 1f) {
|
||||
val alpha = (Color.alpha(color) * alphaFactor).roundToInt()
|
||||
val red = Color.red(color)
|
||||
val green = Color.green(color)
|
||||
val blue = Color.blue(color)
|
||||
return Color.argb(alpha, red, green, blue)
|
||||
}
|
||||
|
||||
return color
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user