-
-
Save LeonidIvankin/06020dc278669e72431fbb2b97b3b3b0 to your computer and use it in GitHub Desktop.
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.appcompat.app.AppCompatActivity | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.graphics.Color | |
import androidx.compose.ui.platform.ComposeView | |
import androidx.compose.ui.unit.dp | |
import com.leonidivankin.draftandroid.R | |
class HybridDepthActivity : AppCompatActivity() { | |
var time = 0L | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
title = "hybrid: xml+compose, depth" | |
val colors = listOf( | |
0xFFF44336, | |
0xFFE91E63, | |
0xFF9C27B0, | |
0xFF673AB7, | |
0xFF3F51B5, | |
0xFF2196F3, | |
0xFF03A9F4, | |
0xFF00BCD4, | |
0xFF009688, | |
0xFF4CAF50, | |
0xFF8BC34A, | |
0xFFCDDC39, | |
0xFFFFEB3B, | |
0xFFFFC107, | |
0xFFFF9800, | |
0xFFFF5722 | |
) | |
time = System.currentTimeMillis() | |
setContentView(R.layout.activity_hybrid_depth) | |
findViewById<ComposeView>(R.id.hybridDepthComposeView).setContent { MyBox(25, colors) } | |
} | |
override fun onResume() { | |
super.onResume() | |
Log.d("Benchmark", "HybridDepthActivity onResume: ${System.currentTimeMillis() - time}") | |
} | |
override fun onWindowFocusChanged(hasFocus: Boolean) { | |
super.onWindowFocusChanged(hasFocus) | |
if (hasFocus) { | |
Log.d( | |
"Benchmark", | |
"HybridDepthActivity onWindowFocusChanged: ${System.currentTimeMillis() - time}" | |
) | |
} | |
} | |
} | |
@Composable | |
private fun MyBox(index: Int, list: List<Long>) { | |
Box( | |
Modifier | |
.fillMaxSize() | |
.background(color = Color(list[index % list.size])) | |
.padding(4.dp) | |
) { | |
if (index < 49) MyBox(index + 1, list) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment