Theme switching
This commit is contained in:
@@ -3,6 +3,7 @@ package com.meloda.fast.util
|
||||
import android.content.ClipData
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.net.NetworkCapabilities
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
@@ -28,6 +29,15 @@ object AndroidUtils {
|
||||
|
||||
fun dp(px: Int) = dp(px.toFloat())
|
||||
|
||||
fun isDarkTheme(): Boolean {
|
||||
val currentNightMode =
|
||||
AppGlobal.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
return when (currentNightMode) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
fun hasConnection(): Boolean {
|
||||
val network = AppGlobal.connectivityManager.activeNetwork ?: return false
|
||||
val activeNetwork =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.meloda.fast.util
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import androidx.annotation.ColorInt
|
||||
import com.meloda.fast.R
|
||||
|
||||
@@ -11,4 +12,19 @@ object ColorUtils {
|
||||
return AndroidUtils.getThemeAttrColor(context, R.attr.colorAccent)
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
fun getColorPrimary(context: Context): Int {
|
||||
return AndroidUtils.getThemeAttrColor(context, R.attr.colorPrimary)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun darkenColor(color: Int, darkFactor: Float = 0.75f): Int {
|
||||
var newColor = color
|
||||
val hsv = FloatArray(3)
|
||||
Color.colorToHSV(newColor, hsv)
|
||||
hsv[2] *= darkFactor
|
||||
newColor = Color.HSVToColor(hsv)
|
||||
return newColor
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,15 +17,6 @@ object Utils {
|
||||
return context.getString(R.string.error, t.message.toString())
|
||||
}
|
||||
|
||||
fun isDarkTheme(): Boolean {
|
||||
val currentNightMode =
|
||||
AppGlobal.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
return when (currentNightMode) {
|
||||
Configuration.UI_MODE_NIGHT_YES -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
fun serialize(source: Any?): ByteArray? {
|
||||
try {
|
||||
val bos = BytesOutputStream()
|
||||
|
||||
Reference in New Issue
Block a user