#249 fix app crashes on startup in RTL (right to left) mode
This commit is contained in:
parent
3e6a3f88b3
commit
69705ddfc7
@ -9,6 +9,7 @@ import android.util.DisplayMetrics
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import org.cryptomator.presentation.R
|
import org.cryptomator.presentation.R
|
||||||
|
import timber.log.Timber
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
|
|
||||||
@ -43,13 +44,27 @@ class VaultListCoordinatorLayout : CoordinatorLayout {
|
|||||||
val floatingActionButton = findViewById<View>(R.id.fab_vault)
|
val floatingActionButton = findViewById<View>(R.id.fab_vault)
|
||||||
val centerXOfHint = (vaultCreationHint.left + vaultCreationHint.right) / 2f
|
val centerXOfHint = (vaultCreationHint.left + vaultCreationHint.right) / 2f
|
||||||
val bottomOfHint = vaultCreationHint.bottom.toFloat()
|
val bottomOfHint = vaultCreationHint.bottom.toFloat()
|
||||||
val leftOfFloatingActionButton = floatingActionButton.left.toFloat()
|
|
||||||
val topOfFloatingActionButton = floatingActionButton.top.toFloat()
|
val topOfFloatingActionButton = floatingActionButton.top.toFloat()
|
||||||
arcFrom(centerXOfHint + dpToPixels(10f), bottomOfHint + dpToPixels(5f)) //
|
|
||||||
.to(leftOfFloatingActionButton - dpToPixels(3f), topOfFloatingActionButton + dpToPixels(5f)) //
|
when (val layoutDirection = resources.configuration.layoutDirection) {
|
||||||
.spanningAnAngleOf(60.0f) //
|
View.LAYOUT_DIRECTION_LTR -> {
|
||||||
.build() //
|
arcFrom(centerXOfHint + dpToPixels(10f), bottomOfHint + dpToPixels(5f), layoutDirection) //
|
||||||
.draw(canvas, strokeLineWithWidthOf1f())
|
.to(floatingActionButton.left.toFloat() - dpToPixels(3f), topOfFloatingActionButton + dpToPixels(5f)) //
|
||||||
|
.spanningAnAngleOf(60.0f) //
|
||||||
|
.build() //
|
||||||
|
.draw(canvas, strokeLineWithWidthOf1f())
|
||||||
|
}
|
||||||
|
View.LAYOUT_DIRECTION_RTL -> {
|
||||||
|
arcFrom(floatingActionButton.right.toFloat() - dpToPixels(3f), bottomOfHint + dpToPixels(5f), layoutDirection) //
|
||||||
|
.to(centerXOfHint + dpToPixels(10f), topOfFloatingActionButton + dpToPixels(5f)) //
|
||||||
|
.spanningAnAngleOf(60.0f) //
|
||||||
|
.build() //
|
||||||
|
.draw(canvas, strokeLineWithWidthOf1f())
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Timber.tag("VaultListCoordinatorLay").e("Layout direction not supported, skip drawing arc")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun strokeLineWithWidthOf1f(): Paint {
|
private fun strokeLineWithWidthOf1f(): Paint {
|
||||||
@ -65,7 +80,7 @@ class VaultListCoordinatorLayout : CoordinatorLayout {
|
|||||||
return dp * pixelsPerDp
|
return dp * pixelsPerDp
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ArcBuilder(val x1: Float, val y1: Float) {
|
private class ArcBuilder(val x1: Float, val y1: Float, val layoutDirection: Int) {
|
||||||
var angle = 0f
|
var angle = 0f
|
||||||
var x2 = 0f
|
var x2 = 0f
|
||||||
var y2 = 0f
|
var y2 = 0f
|
||||||
@ -94,6 +109,7 @@ class VaultListCoordinatorLayout : CoordinatorLayout {
|
|||||||
private val bottom: Float
|
private val bottom: Float
|
||||||
private val start: Float
|
private val start: Float
|
||||||
private val angle: Float = b.angle
|
private val angle: Float = b.angle
|
||||||
|
private val layoutDirection: Int = b.layoutDirection
|
||||||
|
|
||||||
fun draw(canvas: Canvas, paint: Paint) {
|
fun draw(canvas: Canvas, paint: Paint) {
|
||||||
val rect = RectF()
|
val rect = RectF()
|
||||||
@ -106,23 +122,51 @@ class VaultListCoordinatorLayout : CoordinatorLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
start = 180f - angle
|
|
||||||
val sin = sin(TWO_PI * angle / 360).toFloat()
|
val sin = sin(TWO_PI * angle / 360).toFloat()
|
||||||
val cos = cos(TWO_PI * angle / 360).toFloat()
|
val cos = cos(TWO_PI * angle / 360).toFloat()
|
||||||
val widthCorrection = 1f / cos
|
val widthCorrection = 1f / cos
|
||||||
val heightCorrection = 1f / sin
|
val heightCorrection = 1f / sin
|
||||||
val w = (b.x2 - b.x1) * 2 * widthCorrection
|
val w = (b.x2 - b.x1) * 2 * widthCorrection
|
||||||
val h = (b.y2 - b.y1) * 2 * heightCorrection
|
val h = (b.y2 - b.y1) * 2 * heightCorrection
|
||||||
left = b.x1
|
|
||||||
right = b.x1 + w
|
start = when (layoutDirection) {
|
||||||
|
View.LAYOUT_DIRECTION_LTR -> {
|
||||||
|
180f - angle
|
||||||
|
}
|
||||||
|
View.LAYOUT_DIRECTION_RTL -> {
|
||||||
|
0f
|
||||||
|
}
|
||||||
|
else -> throw IllegalStateException("Not supported layout direction")
|
||||||
|
}
|
||||||
|
|
||||||
|
left = when (layoutDirection) {
|
||||||
|
View.LAYOUT_DIRECTION_LTR -> {
|
||||||
|
b.x1
|
||||||
|
}
|
||||||
|
View.LAYOUT_DIRECTION_RTL -> {
|
||||||
|
b.x2 - w
|
||||||
|
}
|
||||||
|
else -> throw IllegalStateException("Not supported layout direction")
|
||||||
|
}
|
||||||
|
|
||||||
|
right = when (layoutDirection) {
|
||||||
|
View.LAYOUT_DIRECTION_LTR -> {
|
||||||
|
b.x1 + w
|
||||||
|
}
|
||||||
|
View.LAYOUT_DIRECTION_RTL -> {
|
||||||
|
b.x2
|
||||||
|
}
|
||||||
|
else -> throw IllegalStateException("Not supported layout direction")
|
||||||
|
}
|
||||||
|
|
||||||
top = b.y1 - h / 2
|
top = b.y1 - h / 2
|
||||||
bottom = b.y1 + h / 2
|
bottom = b.y1 + h / 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun arcFrom(x1: Float, y1: Float): ArcBuilder {
|
private fun arcFrom(x1: Float, y1: Float, layoutDirection: Int): ArcBuilder {
|
||||||
return ArcBuilder(x1, y1)
|
return ArcBuilder(x1, y1, layoutDirection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user