Skip to content

Instantly share code, notes, and snippets.

@LeonidIvankin
Created July 18, 2022 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeonidIvankin/808fd9ac925cf8f53260726f6e54ef09 to your computer and use it in GitHub Desktop.
Save LeonidIvankin/808fd9ac925cf8f53260726f6e54ef09 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 android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
class CodeWidthActivity : AppCompatActivity() {
var time = 0L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
title = "code, width"
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 linearLayout = LinearLayout(this)
linearLayout.orientation = LinearLayout.VERTICAL
for (i in 0..48) {
val layout = FrameLayout(this)
layout.layoutParams =
FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 8 * myDensity)
layout.setBackgroundColor(colors[i % colors.size])
linearLayout.addView(layout)
}
setContentView(linearLayout)
}
override fun onResume() {
super.onResume()
Log.d("Benchmark", "CodeWidthActivity onResume: ${System.currentTimeMillis() - time}")
}
override fun onWindowFocusChanged(hasFocus: Boolean) {
super.onWindowFocusChanged(hasFocus)
if (hasFocus) {
Log.d(
"Benchmark",
"CodeWidthActivity onWindowFocusChanged: ${System.currentTimeMillis() - time}"
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment