SlideShare a Scribd company logo
1 of 189
Download to read offline


<?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試食会

More Related Content

What's hot

Single Page Web Apps with Backbone.js and Rails
Single Page Web Apps with Backbone.js and RailsSingle Page Web Apps with Backbone.js and Rails
Single Page Web Apps with Backbone.js and RailsPrateek Dayal
 
Componentization css angular
Componentization css angularComponentization css angular
Componentization css angularDavid Amend
 
网站无障碍阅读知识
网站无障碍阅读知识网站无障碍阅读知识
网站无障碍阅读知识ppanyong
 
Html5 appunti.0
Html5   appunti.0Html5   appunti.0
Html5 appunti.0orestJump
 
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile EventHTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile EventRobert Nyman
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & AnimationNguyen Tuan
 
Creating web api and consuming part 2
Creating web api and consuming part 2Creating web api and consuming part 2
Creating web api and consuming part 2Dipendra Shekhawat
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckAnthony Montalbano
 
Html col tag jf
Html col tag jfHtml col tag jf
Html col tag jfjakeed1
 

What's hot (17)

Single Page Web Apps with Backbone.js and Rails
Single Page Web Apps with Backbone.js and RailsSingle Page Web Apps with Backbone.js and Rails
Single Page Web Apps with Backbone.js and Rails
 
Componentization css angular
Componentization css angularComponentization css angular
Componentization css angular
 
网站无障碍阅读知识
网站无障碍阅读知识网站无障碍阅读知识
网站无障碍阅读知识
 
Profit statement 00
Profit statement 00Profit statement 00
Profit statement 00
 
Html5 appunti.0
Html5   appunti.0Html5   appunti.0
Html5 appunti.0
 
Theme
ThemeTheme
Theme
 
Form
FormForm
Form
 
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile EventHTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
HTML5 and CSS3: Exploring Mobile Possibilities - London Ajax Mobile Event
 
HTML and CSS part 2
HTML and CSS part 2HTML and CSS part 2
HTML and CSS part 2
 
[ HackFest.pl 2012] Testing - what for and how
[ HackFest.pl 2012] Testing - what for and how[ HackFest.pl 2012] Testing - what for and how
[ HackFest.pl 2012] Testing - what for and how
 
05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation05.Blend Expression, Transformation & Animation
05.Blend Expression, Transformation & Animation
 
Insertcustomer
InsertcustomerInsertcustomer
Insertcustomer
 
Creating web api and consuming part 2
Creating web api and consuming part 2Creating web api and consuming part 2
Creating web api and consuming part 2
 
Your Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages SuckYour Custom WordPress Admin Pages Suck
Your Custom WordPress Admin Pages Suck
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
 
Html Tags
Html TagsHtml Tags
Html Tags
 
Html col tag jf
Html col tag jfHtml col tag jf
Html col tag jf
 

Similar to Anko試食会

Advance Android application development workshop day 2
Advance Android application development workshop day 2Advance Android application development workshop day 2
Advance Android application development workshop day 2cresco
 
Working with Javascript in Rails
Working with Javascript in RailsWorking with Javascript in Rails
Working with Javascript in RailsSeungkyun Nam
 
ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]Somkiat Khitwongwattana
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Mario Jorge Pereira
 
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...Inhacking
 
Infinum Android Talks #16 - How to shoot your self in the foot by Dino Kovac
Infinum Android Talks #16 - How to shoot your self in the foot by Dino KovacInfinum Android Talks #16 - How to shoot your self in the foot by Dino Kovac
Infinum Android Talks #16 - How to shoot your self in the foot by Dino KovacInfinum
 
Workshop 25: React Native - Components
Workshop 25: React Native - ComponentsWorkshop 25: React Native - Components
Workshop 25: React Native - ComponentsVisual Engineering
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Nativejoshcjensen
 
Jetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourJetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourMatthew Clarke
 
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017eMan s.r.o.
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCpootsbook
 
React Native Workshop - React Alicante
React Native Workshop - React AlicanteReact Native Workshop - React Alicante
React Native Workshop - React AlicanteIgnacio Martín
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricksambiescent
 
Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011Johan Nilsson
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Robert DeLuca
 

Similar to Anko試食会 (20)

Advance Android application development workshop day 2
Advance Android application development workshop day 2Advance Android application development workshop day 2
Advance Android application development workshop day 2
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Working with Javascript in Rails
Working with Javascript in RailsWorking with Javascript in Rails
Working with Javascript in Rails
 
Chapter 5 - Layouts
Chapter 5 - LayoutsChapter 5 - Layouts
Chapter 5 - Layouts
 
ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]ListView and Custom ListView on Android Development [Thai]
ListView and Custom ListView on Android Development [Thai]
 
Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015 Android por onde começar? Mini Curso Erbase 2015
Android por onde começar? Mini Curso Erbase 2015
 
Android 2
Android 2Android 2
Android 2
 
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...SE2016 Android Mikle Anokhin "Speed up application development with data bind...
SE2016 Android Mikle Anokhin "Speed up application development with data bind...
 
Infinum Android Talks #16 - How to shoot your self in the foot by Dino Kovac
Infinum Android Talks #16 - How to shoot your self in the foot by Dino KovacInfinum Android Talks #16 - How to shoot your self in the foot by Dino Kovac
Infinum Android Talks #16 - How to shoot your self in the foot by Dino Kovac
 
Workshop 25: React Native - Components
Workshop 25: React Native - ComponentsWorkshop 25: React Native - Components
Workshop 25: React Native - Components
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
 
Jetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning TourJetpack Compose - A Lightning Tour
Jetpack Compose - A Lightning Tour
 
Sencha Touch
Sencha TouchSencha Touch
Sencha Touch
 
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
eMan Dev Meetup: Kotlin For Android (part 03/03) 18.5.2017
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
React Native Workshop - React Alicante
React Native Workshop - React AlicanteReact Native Workshop - React Alicante
React Native Workshop - React Alicante
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricks
 
Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011Custom UI Components at Android Only 2011
Custom UI Components at Android Only 2011
 
Broadleaf Presents Thymeleaf
Broadleaf Presents ThymeleafBroadleaf Presents Thymeleaf
Broadleaf Presents Thymeleaf
 
Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React Crossing platforms with JavaScript & React
Crossing platforms with JavaScript & React
 

Recently uploaded

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 

Recently uploaded (20)

SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 

Anko試食会

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. <?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>
  • 19.
  • 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 }
  • 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) }
  • 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 } }
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55. !
  • 56.
  • 57. "
  • 58.
  • 59.
  • 60.
  • 61. #
  • 62.
  • 63. $
  • 64.
  • 65. %
  • 67. *
  • 68.
  • 69.
  • 70.
  • 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
  • 75.
  • 76.
  • 77. val array = (0..10) array.forEach({ num -> print(num) })
  • 78.
  • 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) }
  • 83.
  • 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 } "
  • 91.
  • 92.
  • 93. this
  • 94. class MyClass { fun createTextView() : TextView { return TextView(context) } }
  • 95. class MyClass { fun createTextView(argLambda: ()->Unit) : TextView { return TextView(context) } }
  • 96. class MyClass { fun createTextView(argLambda: ()->Unit) : TextView { return TextView(context) } fun doSomething() { createTextView ({ // do something }) } }
  • 97. 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 }) } }
  • 98. class MyClass { fun createTextView(argLambda: (TextView)->Unit) : TextView { return TextView(context) } fun doSomething() { createTextView { // do something } } }
  • 99. class MyClass { fun createTextView(argLambda: (TextView)->Unit) : TextView { val view = TextView(context) argLambda(view) return view } fun doSomething() { createTextView { // do something } } }
  • 100. class MyClass { fun createTextView(argLambda: (TextView)->Unit) : TextView { val view = TextView(context) argLambda(view) return view } fun doSomething() { createTextView { textView -> textView.text = " " } } }
  • 101. class MyClass { fun createTextView(argLambda: (TextView)->Unit) : TextView { val view = TextView(context) argLambda(view) return view } fun doSomething() { createTextView { textView -> textView.text = " " } } }
  • 102. class MyClass { fun createTextView(argLambda: (TextView)->Unit) : TextView { val view = TextView(context) argLambda(view) return view } fun doSomething() { createTextView { textView -> textView.text = " " } } }
  • 103. 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 = “ " }
  • 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 }
  • 107.
  • 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 { fun createTextView(argLambda: TextView.()->Unit) : TextView { val view = TextView(context) view.argLambda() return view } fun doSomething() { createTextView { text = " " this is TextView // true } } }
  • 116. 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 } } }
  • 117.
  • 118.
  • 119.
  • 120. + fun lparams() { // do something } + fun TextView.lparams() { // do something }
  • 121. 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() } }
  • 122. 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() } }
  • 123. 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() } }
  • 124. 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() } }
  • 125.
  • 126.
  • 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 }
  • 148.
  • 149.
  • 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"/>
  • 169.
  • 170.
  • 171.
  • 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() } } } }
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 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() } } }