/ComposeWidthActivity.kt Secret
Created
July 18, 2022 05:28
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
package com.leonidivankin.draftandroid.articles.benchmark | |
import android.os.Bundle | |
import android.util.Log | |
import androidx.activity.compose.setContent | |
import androidx.appcompat.app.AppCompatActivity | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.foundation.layout.height | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.unit.dp | |
class ComposeWidthActivity : AppCompatActivity() { | |
var time = 0L | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
title = "compose, width" | |
val colors = listOf( | |
0xFFF44336, | |
0xFFE91E63, | |
0xFF9C27B0, | |
0xFF673AB7, | |
0xFF3F51B5, | |
0xFF2196F3, | |
0xFF03A9F4, | |
0xFF00BCD4, | |
0xFF009688, | |
0xFF4CAF50, | |
0xFF8BC34A, | |
0xFFCDDC39, | |
0xFFFFEB3B, | |
0xFFFFC107, | |
0xFFFF9800, | |
0xFFFF5722 | |
) | |
time = System.currentTimeMillis() | |
setContent { MyBox(colors) } | |
} | |
override fun onResume() { | |
super.onResume() | |
Log.d("Benchmark", "ComposeWidthActivity onResume: ${System.currentTimeMillis() - time}") | |
} | |
override fun onWindowFocusChanged(hasFocus: Boolean) { | |
super.onWindowFocusChanged(hasFocus) | |
if (hasFocus) { | |
Log.d( | |
"Benchmark", | |
"ComposeWidthActivity onWindowFocusChanged: ${System.currentTimeMillis() - time}" | |
) | |
} | |
} | |
} | |
@Composable | |
private fun MyBox(list: List<Long>) { | |
Column { | |
repeat(49) { | |
Box( | |
Modifier | |
.fillMaxWidth() | |
.height(8.dp) | |
.background(color = Color(list[it % list.size])) | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment