|
|
|
@ -8,6 +8,7 @@ import android.content.Context
|
|
|
|
|
import android.graphics.Bitmap
|
|
|
|
|
import android.graphics.PointF
|
|
|
|
|
import android.graphics.Rect
|
|
|
|
|
import android.util.Size
|
|
|
|
|
import android.view.View
|
|
|
|
|
import androidx.annotation.ColorInt
|
|
|
|
|
import androidx.annotation.DimenRes
|
|
|
|
@ -15,6 +16,7 @@ import network.loki.messenger.R
|
|
|
|
|
import org.session.libsession.utilities.getColorFromAttr
|
|
|
|
|
import android.view.inputmethod.InputMethodManager
|
|
|
|
|
import androidx.core.graphics.applyCanvas
|
|
|
|
|
import kotlin.math.roundToInt
|
|
|
|
|
|
|
|
|
|
fun View.contains(point: PointF): Boolean {
|
|
|
|
|
return hitRect.contains(point.x.toInt(), point.y.toInt())
|
|
|
|
@ -68,8 +70,23 @@ fun View.hideKeyboard() {
|
|
|
|
|
imm.hideSoftInputFromWindow(this.windowToken, 0)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun View.drawToBitmap(config: Bitmap.Config = Bitmap.Config.ARGB_8888): Bitmap =
|
|
|
|
|
Bitmap.createBitmap(width, height, config).applyCanvas {
|
|
|
|
|
|
|
|
|
|
fun View.drawToBitmap(config: Bitmap.Config = Bitmap.Config.ARGB_8888, longestWidth: Int = 2000): Bitmap {
|
|
|
|
|
val size = Size(measuredWidth, measuredHeight).coerceAtMost(longestWidth)
|
|
|
|
|
val scale = size.width / measuredWidth.toFloat()
|
|
|
|
|
|
|
|
|
|
return Bitmap.createBitmap(size.width, size.height, config).applyCanvas {
|
|
|
|
|
scale(scale, scale)
|
|
|
|
|
translate(-scrollX.toFloat(), -scrollY.toFloat())
|
|
|
|
|
draw(this)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun Size.coerceAtMost(longestWidth: Int): Size =
|
|
|
|
|
(width.toFloat() / height).let { aspect ->
|
|
|
|
|
if (aspect > 1) {
|
|
|
|
|
width.coerceAtMost(longestWidth).let { Size(it, (it / aspect).roundToInt()) }
|
|
|
|
|
} else {
|
|
|
|
|
height.coerceAtMost(longestWidth).let { Size((it * aspect).roundToInt(), it) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|