Change overlay icon size according to density

Signed-off-by: Alper Ozturk <alperozturk@lions-macbook.local>
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
Alper Ozturk 2023-10-05 09:53:56 +02:00 committed by alperozturk
parent 6ae12b0e49
commit a0083b9afb
No known key found for this signature in database
GPG key ID: 4E577DC593B59BDF

View file

@ -1,9 +1,12 @@
package com.owncloud.android.utils
import android.content.Context
import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.view.Gravity
import androidx.core.graphics.drawable.DrawableCompat
import com.nextcloud.utils.extensions.isLowDensityScreen
import com.nextcloud.utils.extensions.setLayerSizeWithInsetTop
class DrawableUtil {
@ -13,10 +16,16 @@ class DrawableUtil {
return drawable
}
fun addDrawableAsOverlay(backgroundDrawable: Drawable, overlayDrawable: Drawable, topMargin: Int = 3): LayerDrawable {
fun addDrawableAsOverlay(context: Context, backgroundDrawable: Drawable, overlayDrawable: Drawable): LayerDrawable {
val isLowDensityScreen = context.resources.displayMetrics.isLowDensityScreen()
val overlayIconSize = if (isLowDensityScreen) { 12 } else { 24 }
val overlayIconTopMargin = if (isLowDensityScreen) { 3 } else { 6 }
val layerDrawable = LayerDrawable(arrayOf(backgroundDrawable, overlayDrawable))
layerDrawable.setLayerSizeWithInsetTop(1, overlayIconSize, overlayIconTopMargin)
layerDrawable.setLayerGravity(1, Gravity.CENTER)
layerDrawable.setLayerInsetTop(1, topMargin)
return layerDrawable
}
}