<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/
apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="jp.watanave.ankosamples.XMLActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SAY hello"/>
</LinearLayout>
verticalLayout {
editText()
button("Say Hello")
}
<LinearLayout xmlns:android="http://schemas.android.com/
apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="jp.watanave.ankosamples.XMLActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SAY hello"/>
</LinearLayout>
verticalLayout {
editText()
button("Say Hello")
}
<LinearLayout >
<EditText/>
<Button/>
</LinearLayout>
verticalLayout {
editText()
button("Say Hello")
}
<LinearLayout >
<EditText/>
<Button/>
</LinearLayout>
verticalLayout {
editText()
button("Say Hello")
}
<LinearLayout >
<EditText/>
<Button/>
</LinearLayout>
verticalLayout {
editText()
button("Say Hello")
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@android:color/darker_gray"
tools:context="jp.watanave.ankosamples.XMLActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/red"
android:textColor="#FF0000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/white"
android:textColor="#FFFFFF"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/yellow"
android:textColor="#FFFB00"/>
</LinearLayout>
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
textView {
text = “ "
textColor = Color.RED
}
textView {
text = “ "
textColor = Color.RED
}
view {
=
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.WHITE
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.YELLOW
}.lparams {
margin = dip(10)
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.WHITE
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.YELLOW
}.lparams {
margin = dip(10)
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.WHITE
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.YELLOW
}.lparams {
margin = dip(10)
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.WHITE
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.YELLOW
}.lparams {
margin = dip(10)
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.WHITE
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.YELLOW
}.lparams {
margin = dip(10)
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.WHITE
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.YELLOW
}.lparams {
margin = dip(10)
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.WHITE
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.YELLOW
}.lparams {
margin = dip(10)
}
}
textView {
text = " "
textColor = Color.RED
}.lparams {
margin = dip(10)
}
textView {
text = " "
textColor = Color.RED
}.lparams {
margin = dip(10)
}
view {
}.lparams {
LayoutParams =
}
interface AnkoComponent<in T> {
fun createView(ui: AnkoContext<T>): View
}
class MyActivity : AppCompatActivity() {
//
}
class MyActivity : AppCompatActivity() {
//
}
class MyActivityUI : AnkoComponent<MyActivity> {
}
class MyActivity : AppCompatActivity() {
//
}
class MyActivityUI : AnkoComponent<MyActivity> {
}
class MyActivity : AppCompatActivity() {
//
}
class MyActivityUI : AnkoComponent<MyActivity> {
}
class MyActivity : AppCompatActivity() {
//
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View {
// DSL
}
}
class MyActivity : AppCompatActivity() {
//
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View {
// DSL
}
}
class MyActivity : AppCompatActivity() {
//
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View {
// DSL
}
}
class MyActivity : AppCompatActivity() {
//
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View {
// DSL
}
}
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View {
// DSL
}
}
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View {
// DSL
}
}
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MyActivityUI().setContentView(this)
}
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View {
// DSL
}
}
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MyActivityUI().setContentView(this)
}
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View {
// DSL
}
}
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
MyActivityUI().setContentView(this)
}
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View {
// DSL
}
}
!
"
#
$
%
&
'
(
)
*
*
( ) ->
val lambda:( ) -> = { ->
// doSomething
}
val result = lambda(arg)
val lambda : (String)->Int = { str ->
val count = str.count()
count //
}
val result = lambda(“DroidKaigi2018")
// 14
( ) ->
val lambda : (String)->Int = { str ->
val count = str.count()
count //
}
val result = lambda(“DroidKaigi2018")
// 14
val array = (0..10)
array.forEach({ num ->
print(num)
})
val array = (0..10)
array.forEach({ num ->
print(num)
})
val array = (0..10)
array.forEach(
print(num)
})
({ num ->
val array = (0..10)
array.forEach(
print(num)
}
)( { num ->
val array = (0..10)
array.forEach() { num ->
print(num)
}
val array = (0..10)
array.forEach() { num ->
print(num)
}
val array = (0..10)
array.forEach() { num ->
print(num)
}
val array = (0..10)
array.forEach() { num ->
print(num)
}
val array = (0..10)
array.forEach() { num ->
print(num)
}
val array = (0..10)
array.forEach { num ->
print(num)
}
array.forEach { num ->
print(num)
}
array.forEach { num ->
print(num)
}
linearLayout {
// doSomething
}
"
linearLayout {
// doSomething
}
linearLayout
this
class MyClass {
fun createTextView() : TextView {
return TextView(context)
}
}
class MyClass {
fun createTextView(argLambda: ()->Unit) : TextView {
return TextView(context)
}
}
class MyClass {
fun createTextView(argLambda: ()->Unit) : TextView {
return TextView(context)
}
fun doSomething() {
createTextView ({
// do something
})
}
}
class MyClass {
fun createTextView(argLambda: ()->Unit) : TextView {
return TextView(context)
}
fun doSomething() {
createTextView ({
// do something
})
}
}
class MyClass {
fun createTextView(argLambda: ()->Unit) : TextView {
return TextView(context)
}
fun doSomething() {
createTextView ({
// do something
})
}
}
class MyClass {
fun createTextView(argLambda: (TextView)->Unit) : TextView {
return TextView(context)
}
fun doSomething() {
createTextView {
// do something
}
}
}
class MyClass {
fun createTextView(argLambda: (TextView)->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
fun doSomething() {
createTextView {
// do something
}
}
}
class MyClass {
fun createTextView(argLambda: (TextView)->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
fun doSomething() {
createTextView { textView ->
textView.text = " "
}
}
}
class MyClass {
fun createTextView(argLambda: (TextView)->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
fun doSomething() {
createTextView { textView ->
textView.text = " "
}
}
}
class MyClass {
fun createTextView(argLambda: (TextView)->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
fun doSomething() {
createTextView { textView ->
textView.text = " "
}
}
}
class MyClass {
fun createTextView(argLambda: (TextView)->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
fun doSomething() {
createTextView { textView ->
textView.text = " "
}
}
}
createTextView { textView ->
textView.text = “ "
}
createTextView { textView ->
textView.text = " "
}
textView {
text = " "
}
createTextView { textView ->
textView.text = " "
}
textView {
this.text = " "
this is TextView // true
}
fun createTextView(argLambda: (TextView)->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
.( ) ->
( ) ->
+
this .( ) ->
( ) ->
+
fun createTextView(argLambda: (TextView)->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
.( ) ->
( ) ->
+
fun createTextView(argLambda: (TextView)->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
.( ) ->
( ) ->
+
fun createTextView(argLambda: (TextView)->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
.( ) ->
( ) ->
+
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
argLambda(view)
return view
}
.( ) ->
( ) ->
+
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
class MyClass {
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
createTextView {
text = " "
this is TextView // true
}
}
}
class MyClass {
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
createTextView {
text = " "
this is TextView // true
}
}
}
class MyClass {
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
createTextView {
text = " "
this is TextView // true
}
}
}
+
fun lparams() {
// do something
}
+
fun TextView.lparams() {
// do something
}
class MyClass {
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
val textView = createTextView {
text = " "
}
textView.lparams()
}
}
class MyClass {
fun TextView.lparams() {
this is TextView // true
}
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
val textView = createTextView {
text = " "
}
textView.lparams()
}
}
class MyClass {
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
val textView = createTextView {
text = " "
}
textView.lparams()
}
}
class MyClass {
fun TextView.lparams() {
this is TextView // true
}
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
val textView = createTextView {
text = " "
}
textView.lparams()
}
}
class MyClass {
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
val textView = createTextView {
text = " "
}
textView.lparams()
}
}
class MyClass {
fun TextView.lparams() {
// do something
}
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
val textView = createTextView {
text = " "
}
textView.lparams()
}
}
class MyClass {
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
val textView = createTextView {
text = " "
}
textView.lparams()
}
}
class MyClass {
fun TextView.lparams() {
// do something
}
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
val textView = createTextView {
text = " "
}
textView.lparams()
}
}
class MyClass {
fun TextView.lparams() {
// do something
}
fun createTextView(argLambda: TextView.()->Unit) : TextView {
val view = TextView(context)
view.argLambda()
return view
}
fun doSomething() {
val textView = createTextView {
text = " "
}
textView.lparams()
}
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
}
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
}
override fun createView(ui: AnkoContext<MyActivity>): View
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
}
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
}
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
}
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
}
inline fun <T, R> with(receiver: T, block: T.() -> R): R (source)
inline fun <T, R> with(receiver: T, block: T.() -> R): R (source)
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
return ui.linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
textView {
text = " "
textColor = Color.WHITE
}
textView {
text = " "
textColor = Color.YELLOW
}
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
} .( ) ->
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
.( ) ->
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}
//
}
}
inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout {
val context = this.ctx
val view = LinearLayout(context)
view.init()
(context as Activity).setContentView(view)
return view
}
_LinearLayout
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams(width, height)
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams(width, height)
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams(width, height)
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams(width, height)
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams(width, height)
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams(width, height)
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams(width, height)
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams()
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams()
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams()
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams()
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams()
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams()
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams()
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
val layoutParams = LinearLayout.LayoutParams()
layoutParams.init()
this.layoutParams = layoutParams
return this
}
}
class _FrameLayout(context: Context) : FrameLayout(context) {
fun TextView.lparams(init: FrameLayout.LayoutParams.() -> Unit): TextView {
class _RelativeLayout(context: Context) : RelativeLayout(context) {
fun TextView.lparams(init: RelativeLayout.LayoutParams.() -> Unit): TextView {
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
class _FrameLayout(context: Context) : FrameLayout(context) {
fun TextView.lparams(init: FrameLayout.LayoutParams.() -> Unit): TextView {
class _RelativeLayout(context: Context) : RelativeLayout(context) {
fun TextView.lparams(init: RelativeLayout.LayoutParams.() -> Unit): TextView {
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
class _LinearLayout(context: Context) : LinearLayout(context) {
fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
class _FrameLayout(context: Context) : FrameLayout(context) {
fun TextView.lparams(init: FrameLayout.LayoutParams.() -> Unit): TextView {
class _RelativeLayout(context: Context) : RelativeLayout(context) {
fun TextView.lparams(init: RelativeLayout.LayoutParams.() -> Unit): TextView {
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
weight = 1.0f
// this LayoutParams ,
}
//
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
weight = 1.0f
}
//
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
weight = 1.0f
}
//
}
linearLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
weight = 1.0f
}
//
}
relativeLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
centerInParent()
}
//
}
relativeLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
centerInParent()
}
//
}
relativeLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
centerInParent()
}
//
}
relativeLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
centerInParent()
}
//
}
relativeLayout {
backgroundColor = Color.DKGRAY
textView {
text = " "
textColor = Color.RED
}.lparams {
centerInParent()
}
//
}
<TextView
android:layout_centerInParent="true"/>
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
verticalLayout {
editText {
id = View.generateViewId()
}
button("OK") {
id = View.generateViewId()
}
}
}
}
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
verticalLayout {
editText {
id = View.generateViewId()
}
button("OK") {
id = View.generateViewId()
}
}
}
}
inline fun generateViewId(): Int = Throwable().stackTrace.first().lineNumber
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
verticalLayout {
editText {
id = generateViewId()
}
button("OK") {
id = generateViewId()
}
}
}
}
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
inline fun generateViewId(): Int = Throwable().stackTrace.first().lineNumber
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
verticalLayout {
editText {
id = generateViewId()
}
button("OK") {
id = generateViewId()
}
}
}
}
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
inline fun viewIdFromLineNumber(): Int =
Throwable().stackTrace.first().lineNumber
class MyActivityUI : AnkoComponent<MyActivity> {
override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) {
verticalLayout {
editText {
id = viewIdFromLineNumber()
}
button("OK") {
id = viewIdFromLineNumber()
}
}
}
}
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-
-
linearLayout {
(0..5).forEach {
textView {
id = viewIdFromLineNumber()
}
}
}
Anko試食会

Anko試食会

  • 5.
  • 13.
    <?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/ apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="jp.watanave.ankosamples.XMLActivity"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="SAY hello"/> </LinearLayout>
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 20.
  • 21.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } }
  • 22.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } }
  • 23.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } }
  • 24.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED }
  • 25.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } }
  • 26.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } }
  • 27.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } }
  • 28.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } }
  • 29.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } textView { text = “ " textColor = Color.RED }
  • 30.
    textView { text =“ " textColor = Color.RED }
  • 31.
  • 32.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } }
  • 33.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { margin = dip(10) } textView { text = " " textColor = Color.WHITE }.lparams { margin = dip(10) } textView { text = " " textColor = Color.YELLOW }.lparams { margin = dip(10) } }
  • 34.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { margin = dip(10) } textView { text = " " textColor = Color.WHITE }.lparams { margin = dip(10) } textView { text = " " textColor = Color.YELLOW }.lparams { margin = dip(10) } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { margin = dip(10) } textView { text = " " textColor = Color.WHITE }.lparams { margin = dip(10) } textView { text = " " textColor = Color.YELLOW }.lparams { margin = dip(10) } }
  • 35.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { margin = dip(10) } textView { text = " " textColor = Color.WHITE }.lparams { margin = dip(10) } textView { text = " " textColor = Color.YELLOW }.lparams { margin = dip(10) } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { margin = dip(10) } textView { text = " " textColor = Color.WHITE }.lparams { margin = dip(10) } textView { text = " " textColor = Color.YELLOW }.lparams { margin = dip(10) } }
  • 36.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { margin = dip(10) } textView { text = " " textColor = Color.WHITE }.lparams { margin = dip(10) } textView { text = " " textColor = Color.YELLOW }.lparams { margin = dip(10) } } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { margin = dip(10) } textView { text = " " textColor = Color.WHITE }.lparams { margin = dip(10) } textView { text = " " textColor = Color.YELLOW }.lparams { margin = dip(10) } } textView { text = " " textColor = Color.RED }.lparams { margin = dip(10) }
  • 37.
    textView { text =" " textColor = Color.RED }.lparams { margin = dip(10) }
  • 38.
  • 39.
    interface AnkoComponent<in T>{ fun createView(ui: AnkoContext<T>): View }
  • 40.
    class MyActivity :AppCompatActivity() { // }
  • 41.
    class MyActivity :AppCompatActivity() { // } class MyActivityUI : AnkoComponent<MyActivity> { }
  • 42.
    class MyActivity :AppCompatActivity() { // } class MyActivityUI : AnkoComponent<MyActivity> { } class MyActivity : AppCompatActivity() { // } class MyActivityUI : AnkoComponent<MyActivity> { }
  • 43.
    class MyActivity :AppCompatActivity() { // } class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View { // DSL } }
  • 44.
    class MyActivity :AppCompatActivity() { // } class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View { // DSL } } class MyActivity : AppCompatActivity() { // } class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View { // DSL } }
  • 45.
    class MyActivity :AppCompatActivity() { // } class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View { // DSL } }
  • 46.
    class MyActivity :AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } } class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View { // DSL } }
  • 47.
    class MyActivity :AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } } class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View { // DSL } }
  • 48.
    class MyActivity :AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MyActivityUI().setContentView(this) } } class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View { // DSL } }
  • 49.
    class MyActivity :AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MyActivityUI().setContentView(this) } } class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View { // DSL } } class MyActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) MyActivityUI().setContentView(this) } } class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View { // DSL } }
  • 55.
  • 57.
  • 61.
  • 63.
  • 65.
  • 66.
  • 67.
  • 71.
  • 72.
    val lambda:( )-> = { -> // doSomething } val result = lambda(arg)
  • 73.
    val lambda :(String)->Int = { str -> val count = str.count() count // } val result = lambda(“DroidKaigi2018") // 14 ( ) ->
  • 74.
    val lambda :(String)->Int = { str -> val count = str.count() count // } val result = lambda(“DroidKaigi2018") // 14
  • 77.
    val array =(0..10) array.forEach({ num -> print(num) })
  • 79.
    val array =(0..10) array.forEach({ num -> print(num) })
  • 80.
    val array =(0..10) array.forEach( print(num) }) ({ num ->
  • 81.
    val array =(0..10) array.forEach( print(num) } )( { num ->
  • 82.
    val array =(0..10) array.forEach() { num -> print(num) }
  • 84.
    val array =(0..10) array.forEach() { num -> print(num) }
  • 85.
    val array =(0..10) array.forEach() { num -> print(num) }
  • 86.
    val array =(0..10) array.forEach() { num -> print(num) } val array = (0..10) array.forEach() { num -> print(num) }
  • 87.
    val array =(0..10) array.forEach { num -> print(num) }
  • 88.
    array.forEach { num-> print(num) }
  • 89.
    array.forEach { num-> print(num) } linearLayout { // doSomething } "
  • 90.
  • 93.
  • 94.
    class MyClass { funcreateTextView() : TextView { return TextView(context) } }
  • 95.
    class MyClass { funcreateTextView(argLambda: ()->Unit) : TextView { return TextView(context) } }
  • 96.
    class MyClass { funcreateTextView(argLambda: ()->Unit) : TextView { return TextView(context) } fun doSomething() { createTextView ({ // do something }) } }
  • 97.
    class MyClass { funcreateTextView(argLambda: ()->Unit) : TextView { return TextView(context) } fun doSomething() { createTextView ({ // do something }) } } class MyClass { fun createTextView(argLambda: ()->Unit) : TextView { return TextView(context) } fun doSomething() { createTextView ({ // do something }) } }
  • 98.
    class MyClass { funcreateTextView(argLambda: (TextView)->Unit) : TextView { return TextView(context) } fun doSomething() { createTextView { // do something } } }
  • 99.
    class MyClass { funcreateTextView(argLambda: (TextView)->Unit) : TextView { val view = TextView(context) argLambda(view) return view } fun doSomething() { createTextView { // do something } } }
  • 100.
    class MyClass { funcreateTextView(argLambda: (TextView)->Unit) : TextView { val view = TextView(context) argLambda(view) return view } fun doSomething() { createTextView { textView -> textView.text = " " } } }
  • 101.
    class MyClass { funcreateTextView(argLambda: (TextView)->Unit) : TextView { val view = TextView(context) argLambda(view) return view } fun doSomething() { createTextView { textView -> textView.text = " " } } }
  • 102.
    class MyClass { funcreateTextView(argLambda: (TextView)->Unit) : TextView { val view = TextView(context) argLambda(view) return view } fun doSomething() { createTextView { textView -> textView.text = " " } } }
  • 103.
    class MyClass { funcreateTextView(argLambda: (TextView)->Unit) : TextView { val view = TextView(context) argLambda(view) return view } fun doSomething() { createTextView { textView -> textView.text = " " } } } createTextView { textView -> textView.text = “ " }
  • 104.
    createTextView { textView-> textView.text = " " } textView { text = " " }
  • 105.
    createTextView { textView-> textView.text = " " } textView { this.text = " " this is TextView // true }
  • 106.
    fun createTextView(argLambda: (TextView)->Unit): TextView { val view = TextView(context) argLambda(view) return view }
  • 108.
    .( ) -> () -> +
  • 109.
    this .( )-> ( ) -> +
  • 110.
    fun createTextView(argLambda: (TextView)->Unit): TextView { val view = TextView(context) argLambda(view) return view } .( ) -> ( ) -> +
  • 111.
    fun createTextView(argLambda: (TextView)->Unit): TextView { val view = TextView(context) argLambda(view) return view } .( ) -> ( ) -> +
  • 112.
    fun createTextView(argLambda: (TextView)->Unit): TextView { val view = TextView(context) argLambda(view) return view } .( ) -> ( ) -> +
  • 113.
    fun createTextView(argLambda: TextView.()->Unit): TextView { val view = TextView(context) argLambda(view) return view } .( ) -> ( ) -> +
  • 114.
    fun createTextView(argLambda: TextView.()->Unit): TextView { val view = TextView(context) view.argLambda() return view }
  • 115.
    class MyClass { funcreateTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { createTextView { text = " " this is TextView // true } } }
  • 116.
    class MyClass { funcreateTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { createTextView { text = " " this is TextView // true } } } class MyClass { fun createTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { createTextView { text = " " this is TextView // true } } }
  • 120.
    + fun lparams() { //do something } + fun TextView.lparams() { // do something }
  • 121.
    class MyClass { funcreateTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { val textView = createTextView { text = " " } textView.lparams() } } class MyClass { fun TextView.lparams() { this is TextView // true } fun createTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { val textView = createTextView { text = " " } textView.lparams() } }
  • 122.
    class MyClass { funcreateTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { val textView = createTextView { text = " " } textView.lparams() } } class MyClass { fun TextView.lparams() { this is TextView // true } fun createTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { val textView = createTextView { text = " " } textView.lparams() } }
  • 123.
    class MyClass { funcreateTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { val textView = createTextView { text = " " } textView.lparams() } } class MyClass { fun TextView.lparams() { // do something } fun createTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { val textView = createTextView { text = " " } textView.lparams() } }
  • 124.
    class MyClass { funcreateTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { val textView = createTextView { text = " " } textView.lparams() } } class MyClass { fun TextView.lparams() { // do something } fun createTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { val textView = createTextView { text = " " } textView.lparams() } } class MyClass { fun TextView.lparams() { // do something } fun createTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { val textView = createTextView { text = " " } textView.lparams() } }
  • 127.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } }
  • 128.
    override fun createView(ui:AnkoContext<MyActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } }
  • 129.
    override fun createView(ui:AnkoContext<MyActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } } override fun createView(ui: AnkoContext<MyActivity>): View linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } }
  • 130.
    override fun createView(ui:AnkoContext<MyActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } }
  • 131.
    override fun createView(ui:AnkoContext<MyActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } } override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } }
  • 132.
    inline fun <T,R> with(receiver: T, block: T.() -> R): R (source)
  • 133.
    inline fun <T,R> with(receiver: T, block: T.() -> R): R (source)
  • 134.
    override fun createView(ui:AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } }
  • 135.
    override fun createView(ui:AnkoContext<MainActivity>): View = with(ui) { return ui.linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } textView { text = " " textColor = Color.WHITE } textView { text = " " textColor = Color.YELLOW } } }
  • 136.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } }
  • 137.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } }
  • 138.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } }
  • 139.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } }
  • 140.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } }
  • 141.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } } .( ) ->
  • 142.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } } .( ) ->
  • 143.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } }
  • 144.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } }
  • 145.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } }
  • 146.
    inline fun AnkoContext<*>.linearLayout(init:LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view } override fun createView(ui: AnkoContext<MainActivity>): View = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED } // } } inline fun AnkoContext<*>.linearLayout(init: LinearLayout.() -> Unit): _LinearLayout { val context = this.ctx val view = LinearLayout(context) view.init() (context as Activity).setContentView(view) return view }
  • 147.
  • 150.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams(width, height) layoutParams.init() this.layoutParams = layoutParams return this } }
  • 151.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams(width, height) layoutParams.init() this.layoutParams = layoutParams return this } }
  • 152.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams(width, height) layoutParams.init() this.layoutParams = layoutParams return this } } class _LinearLayout(context: Context) : LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams(width, height) layoutParams.init() this.layoutParams = layoutParams return this } }
  • 153.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams(width, height) layoutParams.init() this.layoutParams = layoutParams return this } }
  • 154.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams(width, height) layoutParams.init() this.layoutParams = layoutParams return this } } class _LinearLayout(context: Context) : LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams(width, height) layoutParams.init() this.layoutParams = layoutParams return this } }
  • 155.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams() layoutParams.init() this.layoutParams = layoutParams return this } }
  • 156.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams() layoutParams.init() this.layoutParams = layoutParams return this } }
  • 157.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams() layoutParams.init() this.layoutParams = layoutParams return this } }
  • 158.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams() layoutParams.init() this.layoutParams = layoutParams return this } } class _LinearLayout(context: Context) : LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams() layoutParams.init() this.layoutParams = layoutParams return this } }
  • 159.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams() layoutParams.init() this.layoutParams = layoutParams return this } }
  • 160.
    class _LinearLayout(context: Context): LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams() layoutParams.init() this.layoutParams = layoutParams return this } } class _LinearLayout(context: Context) : LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams = LinearLayout.LayoutParams() layoutParams.init() this.layoutParams = layoutParams return this } }
  • 161.
    class _FrameLayout(context: Context): FrameLayout(context) { fun TextView.lparams(init: FrameLayout.LayoutParams.() -> Unit): TextView { class _RelativeLayout(context: Context) : RelativeLayout(context) { fun TextView.lparams(init: RelativeLayout.LayoutParams.() -> Unit): TextView { class _LinearLayout(context: Context) : LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView {
  • 162.
    class _FrameLayout(context: Context): FrameLayout(context) { fun TextView.lparams(init: FrameLayout.LayoutParams.() -> Unit): TextView { class _RelativeLayout(context: Context) : RelativeLayout(context) { fun TextView.lparams(init: RelativeLayout.LayoutParams.() -> Unit): TextView { class _LinearLayout(context: Context) : LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { class _LinearLayout(context: Context) : LinearLayout(context) { fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { class _FrameLayout(context: Context) : FrameLayout(context) { fun TextView.lparams(init: FrameLayout.LayoutParams.() -> Unit): TextView { class _RelativeLayout(context: Context) : RelativeLayout(context) { fun TextView.lparams(init: RelativeLayout.LayoutParams.() -> Unit): TextView {
  • 163.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { weight = 1.0f // this LayoutParams , } // }
  • 164.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { weight = 1.0f } // }
  • 165.
    linearLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { weight = 1.0f } // } linearLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { weight = 1.0f } // }
  • 166.
    relativeLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { centerInParent() } // }
  • 167.
    relativeLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { centerInParent() } // } relativeLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { centerInParent() } // }
  • 168.
    relativeLayout { backgroundColor =Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { centerInParent() } // } relativeLayout { backgroundColor = Color.DKGRAY textView { text = " " textColor = Color.RED }.lparams { centerInParent() } // } <TextView android:layout_centerInParent="true"/>
  • 172.
    class MyActivityUI :AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { verticalLayout { editText { id = View.generateViewId() } button("OK") { id = View.generateViewId() } } } }
  • 173.
    class MyActivityUI :AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { verticalLayout { editText { id = View.generateViewId() } button("OK") { id = View.generateViewId() } } } }
  • 184.
    inline fun generateViewId():Int = Throwable().stackTrace.first().lineNumber class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { verticalLayout { editText { id = generateViewId() } button("OK") { id = generateViewId() } } } } -renamesourcefileattribute SourceFile -keepattributes SourceFile,LineNumberTable
  • 185.
    inline fun generateViewId():Int = Throwable().stackTrace.first().lineNumber class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { verticalLayout { editText { id = generateViewId() } button("OK") { id = generateViewId() } } } } -renamesourcefileattribute SourceFile -keepattributes SourceFile,LineNumberTable
  • 186.
    inline fun viewIdFromLineNumber():Int = Throwable().stackTrace.first().lineNumber class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { verticalLayout { editText { id = viewIdFromLineNumber() } button("OK") { id = viewIdFromLineNumber() } } } } -renamesourcefileattribute SourceFile -keepattributes SourceFile,LineNumberTable
  • 187.
  • 188.
    - linearLayout { (0..5).forEach { textView{ id = viewIdFromLineNumber() } } }