Skip to content

Instantly share code, notes, and snippets.

@theapache64
theapache64 / launcTime.sh
Last active August 18, 2022 13:09
To measure average Activity startup time
# To measure lauch time
fun launchTime(){
# Config
LAUNCH_COUNT=10
REGEX='TotalTime: (\d+)'
# The two params are configurable via argument
DEFAULT_PACKAGE_NAME='com.your.packagename'
import androidx.compose.desktop.SwingPanel
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@theapache64
theapache64 / FileWatcher.kt
Created April 24, 2022 17:35
To watch file changes
import java.io.File
import java.nio.file.*
class FileWatcher(watchFile: String) {
private val folderPath: Path
private val watchFile: String
init {
val filePath = Paths.get(watchFile)
val isRegularFile = Files.isRegularFile(filePath)
Column {
val list = remember { mutableStateListOf<String>("A") }
val listState = rememberLazyListState()
LaunchedEffect(list.size) {
listState.animateScrollToItem(list.lastIndex)
}
Button(onClick = {
list.add(System.currentTimeMillis().toString())
}) {
Text(text = "ADD")
Column {
var flag by remember { mutableStateOf(false) }
val transition = updateTransition(targetState = flag, label = "My Animation")
// Method #1
LaunchedEffect(transition.currentState == transition.targetState) {
if (transition.currentState == transition.targetState) {
println("Animation finished (1)")
}
}
// Method #2
private val BottomRectangle = GenericShape { size, _ ->
// 1)
moveTo(0f, size.height * 0.6f)
// 2)
lineTo(size.width, size.height * 0.6f)
// ViewState (ViewModel to UI - to render UI)
sealed class $component$ViewState{
}
// Interactors (UI to ViewModel)
sealed class $component$Interactor{
}
@Preview
@Composable
fun MyColumn() {
var isBigText by remember {
mutableStateOf(false)
}
Column(
modifier = Modifier
.padding(10.dp)
import android.app.Activity
import android.content.pm.ActivityInfo
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.foundation.layout.Column
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.tooling.preview.Preview
import kotlinx.coroutines.delay
@Preview
@Composable
fun RecompositionTest() {