Skip to content

Instantly share code, notes, and snippets.

@GRizzi91
GRizzi91 / ExpandableStackView.kt
Created August 3, 2021 17:32
ExpandableStackView
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()
@GRizzi91
GRizzi91 / ExpandableStackViewAdapter.kt
Created August 4, 2021 06:27
ExpandableStackViewAdapter
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()
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,
@Preview
@Composable
fun DrawSquare() {
Canvas(modifier = Modifier.size(200.dp)) {
drawRect(
color = Color.Red,
size = size
)
}
}
@Preview
@Composable
fun DrawSquare() {
Canvas(
modifier = Modifier
.height(100.dp)
.width(200.dp)
) {
drawRect(
color = Color.Red,
@Preview
@Composable
fun DrawSquare() {
Canvas(
modifier = Modifier
.height(100.dp)
.width(200.dp)
) {
drawRect(
color = Color.Red,
fun DrawScope.drawGameElement(
squareColor : Color,
borderColor : Color,
offset : Offset,
size : Size
) {
drawRect(
squareColor,
topLeft = offset,
size = size
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 ->
@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) {