mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-27 01:35:28 +03:00
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:
parent
3cbbdeda33
commit
816599749b
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user