Skip to content

Instantly share code, notes, and snippets.

@LeonidIvankin
Created July 18, 2022 05:28
Show Gist options
  • Save LeonidIvankin/604ecdea027321df09d11778ce7d6bef to your computer and use it in GitHub Desktop.
Save LeonidIvankin/604ecdea027321df09d11778ce7d6bef to your computer and use it in GitHub Desktop.
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