Skip to content

Instantly share code, notes, and snippets.

@LeonidIvankin
Created July 18, 2022 05:27
Show Gist options
  • Save LeonidIvankin/48ade4ab6d6cde33a6e1d2f5b7aff95c to your computer and use it in GitHub Desktop.
Save LeonidIvankin/48ade4ab6d6cde33a6e1d2f5b7aff95c to your computer and use it in GitHub Desktop.
package com.leonidivankin.draftandroid.articles.benchmark
import android.graphics.Color
import android.os.Bundle
import android.util.Log
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
class CodeDepthActivity : AppCompatActivity() {
var time = 0L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
title = "code, depth"
val myDensity = 3
val colors = listOf(
"#F44336",
"#E91E63",
"#9C27B0",
"#673AB7",
"#3F51B5",
"#2196F3",
"#03A9F4",
"#00BCD4",
"#009688",
"#4CAF50",
"#8BC34A",
"#CDDC39",
"#FFEB3B",
"#FFC107",
"#FF9800",
"#FF5722",
)
.map { Color.parseColor(it) }
time = System.currentTimeMillis()
val head = FrameLayout(this)
head.setBackgroundColor(colors[0])
head.setPadding(4 * myDensity, 4 * myDensity, 4 * myDensity, 4 * myDensity)
var tail = head
for (i in 1..48) {
val layout = FrameLayout(this)
layout.setBackgroundColor(colors[i % colors.size])
layout.setPadding(4 * myDensity, 4 * myDensity, 4 * myDensity, 4 * myDensity)
tail.addView(layout)
tail = layout
}
setContentView(head)
}
override fun onResume() {
super.onResume()
Log.d("Benchmark", "CodeDepthActivity onResume: ${System.currentTimeMillis() - time}")
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) {
Log.d(
"Benchmark",
"CodeDepthActivity onWindowFocusChanged: ${System.currentTimeMillis() - time}"
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment