Skip to content

Instantly share code, notes, and snippets.

@tonsky

tonsky/MainActivity.kt

Last active Jan 27, 2020
Embed
What would you like to do?
package com.example.onair
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.*
import androidx.ui.core.Text
import androidx.ui.core.dp
import androidx.ui.core.setContent
import androidx.ui.foundation.Clickable
import androidx.ui.foundation.ColoredRect
import androidx.ui.foundation.DrawImage
import androidx.ui.foundation.VerticalScroller
import androidx.ui.foundation.shape.RectangleShape
import androidx.ui.graphics.Color
import androidx.ui.layout.*
import androidx.ui.material.Button
import androidx.ui.material.MaterialTheme
import androidx.ui.res.imageResource
import androidx.ui.text.TextStyle
import androidx.ui.tooling.preview.Preview
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
DefaultPreview()
}
}
}
@Composable
fun Line(s: String) {
val lastSlash = s.lastIndexOf('/')
val path = s.substring(0, lastSlash)
val name = s.substring(lastSlash + 1, s.length)
Padding(padding = 2.dp) {
Row {
ColoredRect(color = Color.DarkGray, width = 16.dp, height = 16.dp)
WidthSpacer(width = 10.dp)
Text(text = name, softWrap = false)
WidthSpacer(width = 10.dp)
Text(text = path, softWrap = false, style = TextStyle(color = Color.Gray))
}
}
}
@Preview
@Composable
fun DefaultPreview() {
val lines = +state { paths }
MaterialTheme {
Column {
Padding(padding = 5.dp) {
Row {
Clickable(onClick = { lines.value = paths.shuffled() }) { Text(text = "Shuffle") }
WidthSpacer(width = 10.dp)
}
}
VerticalScroller {
Column {
val t0 = System.nanoTime()
lines.value.forEach {
Line(it)
}
println(">>> Recompose lines took ${(System.nanoTime() - t0) / 1000000.0}ms")
}
}
}
}
}
val paths = listOf<String>("./deps.edn",
"./target/classes/onair/frontend/indent/Indent.class",
"./target/classes/onair/frontend/indent/Indenter.class",
"./target/classes/onair/frontend/strings/FixingLayoutTypoTolerantMatcher.class",
"./target/classes/onair/frontend/strings/FList.class",
"./target/classes/onair/frontend/strings/CharArrayCharSequence.class",
"./target/classes/onair/frontend/strings/NameUtil\$Matcher.class",
"./target/classes/onair/frontend/strings/TypoTolerantMatcher\$Error.class",
"./target/classes/onair/frontend/strings/TypoTolerantMatcher.class",
"./target/classes/onair/frontend/strings/NameUtil.class",
"./target/classes/onair/frontend/strings/CharSequenceWithStringHash.class",
"./target/classes/onair/frontend/strings/TypoTolerantMatcher\$Fragment.class",
"./target/classes/onair/frontend/strings/MatcherWithFallback.class",
"./target/classes/onair/frontend/strings/NameUtilCore.class",
"./target/classes/onair/frontend/strings/NameUtil\$MatcherBuilder.class",
"./target/classes/onair/frontend/strings/TypoTolerantMatcher\$ErrorState.class",
"./target/classes/onair/frontend/strings/TypoTolerantMatcher\$Range.class",
"./target/classes/onair/frontend/strings/StringSearcher.class",
"./target/classes/onair/frontend/strings/MinusculeMatcherImpl.class",
"./target/classes/onair/frontend/strings/Segment.class",
"./target/classes/onair/frontend/strings/MinusculeMatcher.class",
"./target/classes/onair/frontend/strings/TypoTolerantMatcher\$MissError.class",
"./target/classes/onair/frontend/strings/TypoTolerantMatcher\$TypoError.class",
"./target/classes/onair/frontend/strings/CharSequenceBackedByArray.class",
"./target/classes/onair/frontend/strings/StringUtil$2.class",
"./target/classes/onair/frontend/strings/TextRange.class",
"./target/classes/onair/frontend/strings/Matcher.class",
"./target/classes/onair/frontend/strings/CharArrayUtil.class",
"./target/classes/onair/frontend/strings/TypoTolerantMatcher\$SwapError.class",
"./target/classes/onair/frontend/strings/FixingLayoutMatcher.class",
"./target/classes/onair/frontend/strings/StringUtil$1.class",
"./target/classes/onair/frontend/strings/StringUtil\$BombedCharSequence.class",
"./target/classes/onair/frontend/strings/TypoTolerantMatcher\$Session.class",
"./target/classes/onair/frontend/strings/FList$1.class",
"./target/classes/onair/frontend/strings/StringUtilRt.class",
"./target/classes/onair/frontend/strings/NameUtil\$MatchingCaseSensitivity.class",
"./target/classes/onair/frontend/strings/ProcessCanceledException.class",
"./target/classes/onair/frontend/strings/StringUtil.class",
"./target/classes/onair/frontend/ast/ASTContainer\$Job.class",
"./target/classes/onair/frontend/ast/Future.class",
"./target/classes/onair/frontend/ast/ASTContainer.class",
"./target/classes/onair/frontend/ast/ParserPool.class",
"./target/classes/onair/frontend/ast/JSitterText.class",
"./target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst",
"./target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst",
"./target/maven-archiver/pom.properties",
"./target/frontend-0.1-SNAPSHOT.jar",
"./resources/.DS_Store",
"./resources/icons/directory-closed.svg",
"./resources/icons/directory-open.svg",
"./resources/Fira Code/variable_ttf/FiraCode-VF.ttf",
"./resources/Fira Code/ttf/FiraCode-Medium.ttf",
"./resources/Fira Code/ttf/FiraCode-Regular.ttf",
"./resources/Fira Code/ttf/FiraCode-Retina.ttf",
"./resources/Fira Code/ttf/FiraCode-Bold.ttf",
"./resources/Fira Code/ttf/FiraCode-Light.ttf",
"./pom.xml",
"./.gitignore",
"./frontend.iml",
"./.cpcache/927574275.libs",
"./.cpcache/927574275.cp",
"./src/test/clj/onair/bench/fixtures.clj",
"./src/test/clj/onair/tests/fsd.clj",
"./src/test/clj/onair/tests/kernel.clj",
"./src/main/java/onair/frontend/indent/Indent.java",
"./src/main/java/onair/frontend/indent/Indenter.java",
"./src/main/java/onair/frontend/strings/TextRange.java",
"./src/main/java/onair/frontend/strings/Matcher.java",
"./src/main/java/onair/frontend/strings/ProcessCanceledException.java",
"./src/main/java/onair/frontend/strings/TypoTolerantMatcher.java",
"./src/main/java/onair/frontend/strings/NameUtilCore.java",
"./src/main/java/onair/frontend/strings/CharArrayCharSequence.java",
"./src/main/java/onair/frontend/strings/Segment.java",
"./src/main/java/onair/frontend/strings/FixingLayoutTypoTolerantMatcher.java",
"./src/main/java/onair/frontend/strings/FixingLayoutMatcher.java",
"./src/main/java/onair/frontend/strings/CharSequenceBackedByArray.java",
"./src/main/java/onair/frontend/strings/StringUtil.java",
"./src/main/java/onair/frontend/strings/CharArrayUtil.java",
"./src/main/java/onair/frontend/strings/StringSearcher.java",
"./src/main/java/onair/frontend/strings/MinusculeMatcher.java",
"./src/main/java/onair/frontend/strings/CharSequenceWithStringHash.java",
"./src/main/java/onair/frontend/strings/FList.java",
"./src/main/java/onair/frontend/strings/NameUtil.java",
"./src/main/java/onair/frontend/strings/MinusculeMatcherImpl.java",
"./src/main/java/onair/frontend/strings/MatcherWithFallback.java",
"./src/main/java/onair/frontend/strings/StringUtilRt.java",
"./src/main/java/onair/frontend/ast/Future.java",
"./src/main/java/onair/frontend/ast/JSitterText.java",
"./src/main/java/onair/frontend/ast/ASTContainer.java",
"./src/main/java/onair/frontend/ast/ParserPool.java",
"./src/main/clj/onair/frontend/editors.clj",
"./src/main/clj/onair/frontend/layout.clj",
"./src/main/clj/onair/frontend/ui/tree.clj",
"./src/main/clj/onair/frontend/ui/render.clj",
"./src/main/clj/onair/frontend/ui/core.clj",
"./src/main/clj/onair/frontend/ui/navigation.clj",
"./src/main/clj/onair/frontend/ui/keyboard.clj",
"./src/main/clj/onair/frontend/ui/list.clj",
"./src/main/clj/onair/frontend/poly.clj",
"./src/main/clj/onair/frontend/file_tree.clj",
"./src/main/clj/onair/frontend/blob.clj",
"./src/main/clj/onair/frontend/reducers.clj",
"./src/main/clj/onair/frontend/db.clj",
"./src/main/clj/onair/frontend/workspace.clj",
"./src/main/clj/onair/frontend/patterns.clj",
"./src/main/clj/onair/frontend/interop.clj",
"./src/main/clj/onair/frontend/tags.clj",
"./src/main/clj/onair/frontend/fsd.clj",
"./src/main/clj/onair/frontend/layout/window.clj",
"./src/main/clj/onair/frontend/layout/buffer.clj",
"./src/main/clj/onair/frontend/layout/stack.clj",
"./src/main/clj/onair/frontend/layout/sidebar.clj",
"./src/main/clj/onair/frontend/layout/core.clj",
"./src/main/clj/onair/frontend/layout/layout-actions.edn",
"./src/main/clj/onair/frontend/utils.cljc",
"./src/main/clj/onair/frontend/spec/layout.clj",
"./src/main/clj/onair/frontend/spec/db.clj",
"./src/main/clj/onair/frontend/spec/patterns.clj",
"./src/main/clj/onair/frontend/spec/tags.clj",
"./src/main/clj/onair/frontend/spec/transition.clj",
"./src/main/clj/onair/frontend/spec/core.clj",
"./src/main/clj/onair/frontend/spec/protocol/text_search.clj",
"./src/main/clj/onair/frontend/spec/protocol/blob.clj",
"./src/main/clj/onair/frontend/spec/protocol/workspace.clj",
"./src/main/clj/onair/frontend/spec/protocol/fsd.clj",
"./src/main/clj/onair/frontend/spec/protocol/tx.clj",
"./src/main/clj/onair/frontend/spec/protocol/core.clj",
"./src/main/clj/onair/frontend/spec/protocol/document.clj",
"./src/main/clj/onair/frontend/spec/protocol/snapshot.clj",
"./src/main/clj/onair/frontend/spec/document.clj",
"./src/main/clj/onair/frontend/spec/keymap.clj",
"./src/main/clj/onair/frontend/spec/triggers.clj",
"./src/main/clj/onair/frontend/spec/plugin.clj",
"./src/main/clj/onair/frontend/navigation/navigation-actions.edn",
"./src/main/clj/onair/frontend/navigation/global_text_search.clj",
"./src/main/clj/onair/frontend/navigation/core.clj",
"./src/main/clj/onair/frontend/navigation/README",
"./src/main/clj/onair/frontend/navigation/palette.clj",
"./src/main/clj/onair/frontend/navigation/goto_file.clj",
"./src/main/clj/onair/frontend/core.clj",
"./src/main/clj/onair/frontend/ot.clj",
"./src/main/clj/onair/frontend/kernel.clj",
"./src/main/clj/onair/frontend/extensions.clj",
"./src/main/clj/onair/frontend/reload.clj",
"./src/main/clj/onair/frontend/README",
"./src/main/clj/onair/frontend/lang.clj",
"./src/main/clj/onair/frontend/document.clj",
"./src/main/clj/onair/frontend/actions.clj",
"./src/main/clj/onair/frontend/themes.clj",
"./src/main/clj/onair/frontend/main.clj",
"./src/main/clj/onair/frontend/rentity.clj",
"./src/main/clj/onair/frontend/keymap.clj",
"./src/main/clj/onair/frontend/triggers.clj",
"./src/main/clj/onair/frontend/snapshot.clj",
"./src/main/clj/onair/frontend/user.clj",
"./src/main/clj/onair/frontend/plugins.clj",
"./src/main/clj/onair/frontend/editor/text_search.clj",
"./src/main/clj/onair/frontend/editor/view.clj",
"./src/main/clj/onair/frontend/editor/highlighting.clj",
"./src/main/clj/onair/frontend/editor/render.clj",
"./src/main/clj/onair/frontend/editor/core.clj",
"./src/main/clj/onair/frontend/editor/controller.clj",
"./src/main/clj/onair/frontend/editor/instructions.clj",
"./src/main/clj/onair/frontend/editor/editor-actions.edn",
"./src/main/clj/onair/frontend/editor/composite.clj")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment