This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@HiltViewModel | |
class GameViewModel @Inject constructor() : ViewModel() { | |
private val field = Field() | |
private val stateFlow = MutableStateFlow(field.getActualField()) | |
val state : StateFlow<Array<IntArray>> = stateFlow | |
init { | |
viewModelScope.launch { | |
while (!field.isGameEnded) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val state : State<Array<IntArray>> = gameViewModel.state.collectAsState() | |
Canvas( | |
modifier = Modifier | |
.fillMaxHeight(0.8f) | |
.aspectRatio(0.5f) | |
.border(1.dp, Color.Black) | |
) { | |
val squareDim = size.height / state.value.size | |
state.value.forEachIndexed { y, it -> | |
it.forEachIndexed { x, value -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun DrawScope.drawGameElement( | |
squareColor : Color, | |
borderColor : Color, | |
offset : Offset, | |
size : Size | |
) { | |
drawRect( | |
squareColor, | |
topLeft = offset, | |
size = size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Preview | |
@Composable | |
fun DrawSquare() { | |
Canvas( | |
modifier = Modifier | |
.height(100.dp) | |
.width(200.dp) | |
) { | |
drawRect( | |
color = Color.Red, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Preview | |
@Composable | |
fun DrawSquare() { | |
Canvas( | |
modifier = Modifier | |
.height(100.dp) | |
.width(200.dp) | |
) { | |
drawRect( | |
color = Color.Red, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Preview | |
@Composable | |
fun DrawSquare() { | |
Canvas(modifier = Modifier.size(200.dp)) { | |
drawRect( | |
color = Color.Red, | |
size = size | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun drawLine( | |
color: Color, | |
start: Offset, | |
end: Offset, | |
strokeWidth: Float = Stroke.HairlineWidth, | |
cap: StrokeCap = Stroke.DefaultCap, | |
pathEffect: PathEffect? = null, | |
/*FloatRange(from = 0.0, to = 1.0)*/ | |
alpha: Float = 1.0f, | |
colorFilter: ColorFilter? = null, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ExpandableStackViewAdapter( | |
private val models: List<String>, | |
private val context: Context | |
) : BaseAdapter() { | |
override fun getCount(): Int = models.size | |
override fun getItem(position: Int): String = models[position] | |
override fun getItemId(position: Int): Long = position.toLong() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun setAdapter(adapter: BaseAdapter) { | |
val scene = MotionScene(this) | |
val startSetId = View.generateViewId() | |
val startSet = ConstraintSet() | |
startSet.clone(this) | |
val endSetId = View.generateViewId() | |
val endSet = ConstraintSet() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun ConstraintSet.setCardElevation(cardView: CardView, elevation: Float) { | |
getConstraint(cardView.id)?.let { | |
it.mCustomConstraints["CardElevation"] = ConstraintAttribute( | |
"CardElevation", | |
ConstraintAttribute.AttributeType.DIMENSION_TYPE, | |
elevation | |
) | |
} | |
} |
NewerOlder