|
16 | 16 | package com.ichi2.anki.ui.windows.reviewer.whiteboard |
17 | 17 |
|
18 | 18 | import android.content.Context |
| 19 | +import android.graphics.Rect |
19 | 20 | import android.util.AttributeSet |
20 | 21 | import android.view.LayoutInflater |
21 | 22 | import android.view.MotionEvent |
22 | 23 | import android.view.View |
23 | 24 | import android.view.ViewConfiguration |
24 | 25 | import android.view.animation.DecelerateInterpolator |
25 | 26 | import android.widget.LinearLayout |
| 27 | +import androidx.core.view.ViewCompat |
| 28 | +import androidx.core.view.marginLeft |
| 29 | +import androidx.core.view.marginRight |
26 | 30 | import androidx.core.view.updateLayoutParams |
27 | 31 | import androidx.recyclerview.widget.LinearLayoutManager |
28 | 32 | import com.ichi2.anki.databinding.ViewWhiteboardToolbarBinding |
@@ -66,6 +70,32 @@ class WhiteboardToolbar : LinearLayout { |
66 | 70 | var onBrushLongClick: ((index: Int) -> Unit)? = null |
67 | 71 | var onToolbarVisibilityChanged: ((isShown: Boolean) -> Unit)? = null |
68 | 72 |
|
| 73 | + /** |
| 74 | + * Disables gesture swipe of docked whiteboard toolbar on the side on layout change |
| 75 | + * While this code does attempt to set exclusion rect when ToolbarAlignment.BOTTOM, |
| 76 | + * no effect occurs as bottom screen gestures cannot be opted out of |
| 77 | + * https://developer.android.com/develop/ui/views/touch-and-input/gestures/gesturenav#kotlin |
| 78 | + */ |
| 79 | + private val boundingBox: Rect = Rect() |
| 80 | + private val exclusions = listOf(boundingBox) |
| 81 | + |
| 82 | + override fun onLayout( |
| 83 | + changed: Boolean, |
| 84 | + left: Int, |
| 85 | + top: Int, |
| 86 | + right: Int, |
| 87 | + bottom: Int, |
| 88 | + ) { |
| 89 | + super.onLayout(changed, left, top, right, bottom) |
| 90 | + if (!changed) return |
| 91 | + when (currentAlignment) { |
| 92 | + ToolbarAlignment.LEFT -> boundingBox.set(left - marginLeft, top, right, bottom) |
| 93 | + ToolbarAlignment.RIGHT -> boundingBox.set(left, top, right + marginRight, bottom) |
| 94 | + ToolbarAlignment.BOTTOM -> boundingBox.set(0, 0, 0, 0) |
| 95 | + } |
| 96 | + ViewCompat.setSystemGestureExclusionRects(this, exclusions) |
| 97 | + } |
| 98 | + |
69 | 99 | /** |
70 | 100 | * Updates the internal layout based on the toolbar alignment. |
71 | 101 | * Switches the RecyclerView orientation and the main layout orientation. |
|
0 commit comments