Fix Android Studio OSC layout preview (again)

The layout preview/editor doesn't instantiate an Application instance, therefore accessing `displayMetrics` from the app context would lead to a crash, and the view being mocked in the preview.
Additionally a default grid value is defined for `AlignmentGridView` to avoid a crash because of an invalid iteration step in the drawing loop.
This commit is contained in:
lynxnb 2023-03-28 11:03:23 +02:00 committed by Niccolò Betto
parent 3cbbdeda33
commit 816599749b
2 changed files with 3 additions and 4 deletions

View File

@ -5,8 +5,8 @@
package emu.skyline.input.onscreen
import android.content.res.Resources
import android.util.TypedValue
import emu.skyline.SkylineApplication
enum class EditMode {
None,
@ -39,10 +39,9 @@ class OnScreenEditInfo {
val isEditing get() = editMode != EditMode.None
companion object {
/**
* The size of the grid, calculated from the value of 8dp
*/
val GridSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8f, SkylineApplication.context.resources.displayMetrics).toInt()
var GridSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8f, Resources.getSystem().displayMetrics).toInt()
}
}

View File

@ -16,7 +16,7 @@ import android.view.View
* A view that draws a grid, used for aligning on-screen controller buttons
*/
class AlignmentGridView @JvmOverloads constructor(context : Context, attrs : AttributeSet? = null, defStyleAttr : Int = 0) : View(context, attrs, defStyleAttr) {
var gridSize = 0
var gridSize = 16
set(value) {
field = value
invalidate()