Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Anko試食会

61df7fd4bc6f622ca13afb007789fc23?s=47 watanave
February 05, 2018

 Anko試食会

DroidKaigi 2018

61df7fd4bc6f622ca13afb007789fc23?s=128

watanave

February 05, 2018
Tweet

Transcript

  1. "OLPࢼ৯ձ %SPJE,BJHJ XBUBOBWF

  2. :PIUB8BUBOBCF $SZQUPO'VUVSF.FEJB *OD UXJUUFS!4VTBO@KBDLP HJUIVC!TVTBO

  3. "OLPJTB,PUMJOMJCSBSZXIJDINBLFT"OESPJEBQQMJDBUJPOEFWFMPQNFOUGBTUFS BOEFBTJFS*UNBLFTZPVSDPEFDMFBOBOEFBTZUPSFBE BOEMFUTZPVGPSHFU BCPVUSPVHIFEHFTPGUIF"OESPJE4%,GPS+BWB

  4. ͜Μͳํ΁ w,PUMJO͸ͦͦ͜͜࢖͑Δ w"OLP࢖ͬͨ͜ͱͳ͍ w"OLP%4-ͬͯ
 ढจʹݟ͑Δʜ

  5. ຊ೔ͷ"OLPϝχϡʔ w"OLPͷ঺հ w"OLP͸࢖͍෺ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰ͸ͷ׆༻๏ w7JFX*%ͷ࠾൪

  6. ຊ೔ͷ"OLPϝχϡʔ w"OLPͷ঺հ w"OLP͸࢖͍෺ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰ͸ͷ׆༻๏ w7JFX*%ͷ࠾൪

  7. "OLP "OLP $PNNPOT "OLP -BZPVUT "OLP 42-JUF "OLP $PSPVUJOFT

  8. "OLP-BZPVUT "OLP%4-

  9. "OLP-BZPVUT "OLP%4- 7JFXͷϨΠΞ΢τΛ࡞Δ ಠࣗυϝΠϯݴޠ ͬͱݴͬͯ΋ɺ ,PUMJOͷߏจ্ʹ੒Γཱ͍ͬͯΔ

  10. "OLP%4-

  11. None
  12. 9.- <?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>
  13. "OLP%4- verticalLayout { editText() button("Say Hello") }

  14. <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") } 9.- "OLP%4-
  15. <LinearLayout > <EditText/> <Button/> </LinearLayout> verticalLayout { editText() button("Say Hello")

    } 9.- "OLP%4-
  16. <LinearLayout > <EditText/> <Button/> </LinearLayout> verticalLayout { editText() button("Say Hello")

    } 9.- "OLP%4-
  17. <LinearLayout > <EditText/> <Button/> </LinearLayout> verticalLayout { editText() button("Say Hello")

    } 9.- "OLP%4- งғؾ͸ࣅͯΔ
  18. ΋͏গ͠ৄ͘͠

  19. 9.- <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>
  20. "OLP%4- linearLayout { backgroundColor = Color.DKGRAY textView { text =

    "͔͋" textColor = Color.RED } textView { text = "͠Ζ" textColor = Color.WHITE } textView { text = "͖͍Ζ" textColor = Color.YELLOW } }
  21. "OLP%4- 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 }
  22. "OLP%4- ϒϨʔεͰ֊૚Λදݱ linearLayout { backgroundColor = Color.DKGRAY textView { text

    = "͔͋" textColor = Color.RED } }
  23. "OLP%4- ϒϨʔεͰ֊૚Λදݱ linearLayout { backgroundColor = Color.DKGRAY textView { text

    = "͔͋" textColor = Color.RED } }
  24. "OLP%4- 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 }
  25. "OLP%4- ϒϨʔεͷதͰϓϩύςΟηοτ textView { text = “͔͋" textColor = Color.RED

    }
  26. "OLP%4- ϒϨʔεͷதͰϓϩύςΟηοτ view { ϓϩύςΟ = ஋ }

  27. "OLP%4- linearLayout { backgroundColor = Color.DKGRAY textView { text =

    "͔͋" textColor = Color.RED } textView { text = "͠Ζ" textColor = Color.WHITE } textView { text = "͖͍Ζ" textColor = Color.YELLOW } }
  28. "OLP%4- 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) } }
  29. "OLP%4- 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) }
  30. "OLP%4- MQBSBNTʹଓ͚ͯϨΠΞ΢τͷઃఆ textView { text = "͔͋" textColor = Color.RED

    }.lparams { margin = dip(10) }
  31. "OLP%4- MQBSBNTʹଓ͚ͯϨΠΞ΢τͷઃఆ view { }.lparams { LayoutParamsͷϓϩύςΟ = ஋ }

  32. "OLP$PNQPOFOU interface AnkoComponent<in T> { fun createView(ui: AnkoContext<T>): View }

  33. "OLP$PNQPOFOU class MyActivity : AppCompatActivity() { // ུ }

  34. "OLP$PNQPOFOU class MyActivity : AppCompatActivity() { // ུ } class

    MyActivityUI : AnkoComponent<MyActivity> { } class MyActivity : AppCompatActivity() { // ུ } class MyActivityUI : AnkoComponent<MyActivity> { }
  35. "OLP$PNQPOFOU 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ॻ͘ } }
  36. "OLP$PNQPOFOU 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ॻ͘ } }
  37. "OLP$PNQPOFOU 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ॻ͘ } }
  38. ຊ೔ͷ"OLPϝχϡʔ w"OLPͷ঺հ w"OLP͸࢖͍෺ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰ͸ͷ׆༻๏ w7JFX*%ͷ࠾൪

  39. "OLPͷ͕͜͜ྑ͍ w 9.-͔Βͷղ์ w ܕ҆શ w ಈతͳϨΠΞ΢τ͕ಘҙ w ϨΠΞ΢τͷ࠶ར༻ੑ͕ߴ͘ͳΔ

  40. "OLPͷ͕͜͜੯͍͠ w ϓϨϏϡʔ͕ʜ w 7JFX*%ͷ࠾൪ʹ೉͋Γ

  41. "OLP2"

  42. ΧελϜ7JFX͸ ѻ͑Δʁ :&4!

  43. ύϑΥʔϚϯε͸ Ͳ͏ͳͷʁ :&4"

  44. "OLPͰ Ͱ͖ͳ͍ࣄ͋Δʁ ૊Ίͳ͍ϨΠΞ΢τ͸ ଟ෼ɺͳ͍

  45. "OLPͰ Ͱ͖ͳ͍ࣄ͋Δʁ ΞϓϦͷϓϩηε֎Ͱ ಈ࡞͢Δॴ͸# w ΧελϜ௨஌ϨΠΞ΢τ w "QQ8JEHFUTͷϨΠΞ΢τ

  46. ϓϨϏϡʔਏ͘ͳ͍ʁ 㵰'ͰؤுΔ$

  47. ϓϩδΣΫτͰ࠾༻ͯ͠ Ͳ͏ͩͬͨʁ ͬͱɺఏҊͨ͠ࢲ͸ࢥͬͯΔ ྑ͔ͬͨ%

  48. ϓϩδΣΫτͰ࠾༻ͯ͠ Ͳ͏ͩͬͨʁ wֶशίετ͸ɺ΍΍͋Δ& wωοΫ͸ϓϨϏϡʔ͔΋' w7JFX͕࢖͍·ΘͤΔͷ͸ྑ͍( w9.-Ͱফ໣ͯ͠ΔͳΒ࢖͏͔͠ͳ͍)

  49. ຊ೔ͷ"OLPϝχϡʔ w"OLPͷ঺հ w"OLP͸࢖͍෺ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰ͸ͷ׆༻๏ w7JFX*%ͷ࠾൪

  50. "OLPղମγϣʔ 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) } }
  51. MJOFBS-BZPVUΛ࡞Δϝιου class AnkoContext(val ctx: Context) { fun linearLayout() : LinearLayout

    { return LinearLayout(ctx) } }
  52. MJOFBS-BZPVUΛ࡞Δϝιου class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } }
  53. MJOFBS-BZPVUΛίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) { ui.linearLayout ({ // do something }) }
  54. %4-ͬΆ͘ίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) { ui.linearLayout ({ // do something }) } fun createView(ui: AnkoContext) { ui.linearLayout ({ // do something }) }
  55. %4-ͬΆ͘ίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) { ui.linearLayout { // do something } } ɹɹ
  56. XJUI inline fun <T, R> with(receiver: T, block: T.() ->

    R): R (source) rIUUQTLPUMJOMBOHPSHBQJMBUFTUKWNTUEMJCLPUMJOXJUIIUNM l༩͑ΒΕͨϨγʔόΛϨγʔόͱͯ͠ࢦఆͨ͠ϑΝϯ ΫγϣϯϒϩοΫΛݺͼग़͠ɺͦͷ݁ՌΛฦ͠·͢ɻz
  57. XJUI CMPDLͷείʔϓͰ͸ɺ UIJT͕SFDFJWFSʹͳΔ inline fun <T, R> with(receiver: T, block:

    T.() -> R): R (source)
  58. %4-ͬΆ͘ίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) { ui.linearLayout { // do something } }
  59. XJUI࢖ͬͯΈΔ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) { with(ui, { this.linearLayout { // do something } }) } ui { this.linearLayout { // do something } }
  60. ୯Ұࣜؔ਺ͩͬͨ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) { with(ui, { this.linearLayout { // do something } }) } with(ui, { this.linearLayout { // do something } })
  61. ୯Ұࣜؔ਺ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui, { this.linearLayout { // do something } })
  62. ΋ͬͱ%4-ͬΆ͘ίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui, { this.linearLayout { // do something } })
  63. ΋ͬͱ%4-ͬΆ͘ίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { this.linearLayout { // do something } }
  64. ΋ͬͱ΋ͬͱ%4-ͬΆ͘ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { // do something } }
  65. ϓϩύςΟ͸Ͳ͏΍ͬͯʁ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { } } backgroundColor = Color.DKGRAY
  66. ͜Ε͸ҧ͏ʁ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { linearLayout -> linearLayout.backgroundColor = Color.DKGRAY } }
  67. ͜Ε΋ҧ͏ʁ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { linearLayout -> with(linearLayout) { this.backgroundColor = Color.DKGRAY } } }
  68. JOJUͷUIJTΛ-JOFBS-BZPVUʹ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { // ͜ͷείʔϓͷthisΛLinearLayoutʹ͍ͨ͠ʂ } }
  69. ϓϩύςΟ͸Ͳ͏΍ͬͯʁ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { } }
  70. ϓϩύςΟ͸Ͳ͏΍ͬͯʁ class AnkoContext(val ctx: Context) { fun linearLayout(init: LinearLayout.()->Unit) :

    LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { } }
  71. ϓϩύςΟ͸Ͳ͏΍ͬͯʁ class AnkoContext(val ctx: Context) { fun linearLayout(init: LinearLayout.()->Unit) :

    LinearLayout { val linearLayout = LinearLayout(ctx) linearLayout.init() return linearLayout } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { backgroundColor = Color.DKGRAY } } this.
  72. 5FYU7JFXΛ഑ஔ͍ͨ͠ class AnkoContext(val ctx: Context) { fun linearLayout(init: LinearLayout.()->Unit) :

    LinearLayout { val linearLayout = LinearLayout(ctx) linearLayout.init() return linearLayout } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { backgroundColor = Color.DKGRAY } } textView { text = "͋Μ͜" }
  73. 5FYU7JFX΋࣮૷ͯ͠ΈΔ fun linearLayout(init: LinearLayout.()->Unit) : LinearLayout { val linearLayout =

    LinearLayout(ctx) linearLayout.init() return linearLayout } fun textView(init: TextView.()->Unit) : TextView { val textView = TextView(ctx) textView.init() return textView }
  74. 5FYU7JFX΋࣮૷ͯ͠ΈΔ class AnkoContext(val ctx: Context) { fun linearLayout(init: LinearLayout.()->Unit) :

    LinearLayout { val linearLayout = LinearLayout(ctx) linearLayout.init() return linearLayout } } fun ViewGroup.textView(init: TextView.()->Unit) : TextView { val textView = TextView(this.context) textView.init() return textView }
  75. "EE7JFXͯ͠ͳ͔ͬͨ class AnkoContext(val ctx: Context) { fun linearLayout(init: LinearLayout.()->Unit) :

    LinearLayout { val linearLayout = LinearLayout(ctx) linearLayout.init() (ctx as Activity).setContentView(linearLayout) return linearLayout } } fun ViewGroup.textView(init: TextView.()->Unit) : TextView { val textView = TextView(this.context) textView.init() this.addView(textView) return textView }
  76. ೖΕࢠߏ଄Ͱ͖ͨ fun createView(ui: AnkoContext) = with(ui) { return linearLayout {

    backgroundColor = Color.DKGRAY textView { text = “͋Μ͜" } } }
  77. MQBSBNTΛͲ͏͢Δ͔ fun createView(ui: AnkoContext) = with(ui) { linearLayout { backgroundColor

    = Color.DKGRAY textView { text = “͋Μ͜" }.lparams { } } }
  78. 5FYU7JFXΛ֦ு fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams

    = LinearLayout.LayoutParams(width, height) layoutParams.init() this.layoutParams = layoutParams return this } fun createView(ui: AnkoContext) = with(ui) { linearLayout { backgroundColor = Color.DKGRAY textView { text = “͋Μ͜" }.lparams { } } }
  79. ܕҧ͏໰୊ fun TextView.lparams(init: LinearLayout.LayoutParams.() -> Unit): TextView { val layoutParams

    = LinearLayout.LayoutParams(width, height) layoutParams.init() this.layoutParams = layoutParams return this } fun createView(ui: AnkoContext) = with(ui) { relativeLayout { backgroundColor = Color.DKGRAY textView { text = “͋Μ͜" }.lparams { } } } #
  80. 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 } } @ΫϥεΛ࡞Δ
  81. @ΫϥεΛฦ͢ class AnkoContext(val ctx: Context) { fun linearLayout(init: LinearLayout.()->Unit) :

    _LinearLayout { val linearLayout = _LinearLayout(ctx) linearLayout.init() return linearLayout } }
  82. 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 {
  83. 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 } // ུ }
  84. relativeLayout { backgroundColor = Color.DKGRAY textView { text = "͔͋"

    textColor = Color.RED }.lparams { centerInParent() } // ུ } relativeLayout { backgroundColor = Color.DKGRAY textView { text = "͔͋" textColor = Color.RED }.lparams { centerInParent() } // ུ }
  85. "OLP%4- 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) } }
  86. %4-͸ w Ҿ਺ϥϜμࣜͷΧοίলུه๏ w είʔϓຖͷUIJTࢀর੾Γସ͑ Ͱग़དྷͯΔ

  87. ࠔͬͨΒ είʔϓͷUIJTΛ ҙࣝ͢Δ

  88. ຊ೔ͷ"OLPϝχϡʔ w"OLPͷ঺հ w"OLP͸࢖͍෺ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰ͸ͷ׆༻๏ w7JFX*%ͷ࠾൪

  89. ܕ҆શ

  90. ܕ҆શ class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>):

    View = with(ui) { verticalLayout { textView("0") button("OK") } } }
  91. ܕ҆શ class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>):

    View = with(ui) { verticalLayout { val textView = textView("0") val button = button("OK") } } }
  92. ܕ҆શ class MyActivityUI : AnkoComponent<MyActivity> { var textView: TextView? var

    button: Button? override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { verticalLayout { textView = textView("0") button = button("OK") } } }
  93. ܕ҆શ class MyActivityUI : AnkoComponent<MyActivity> { lateinit var textView: TextView

    private set lateinit var button: Button private set override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { verticalLayout { textView = textView("0") button = button("OK") } } }
  94. ಈతͳϨΠΞ΢τ

  95. ಈతͳϨΠΞ΢τ linearLayout { (0..num).forEach { imageView(R.drawable.star) } }

  96. ಈతͳϨΠΞ΢τ class MyActivityUI(private val theme: Int, private val buttonTheme: Int)

    : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { owner.setTheme(theme) verticalLayout { textView("0") button(“OK") themedButton("Cancel", buttonTheme) } } }
  97. ಈతͳϨΠΞ΢τ class MyActivityUI(private val theme: Int, private val buttonTheme: Int)

    : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { owner.setTheme(theme) verticalLayout { textView("0") button(“OK") themedButton("Cancel", buttonTheme) } } }
  98. ಈతͳϨΠΞ΢τ class MyActivityUI(private val theme: Int, private val buttonTheme: Int)

    : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { owner.setTheme(theme) verticalLayout { textView("0") button(“OK") themedButton("Cancel", buttonTheme) } } }
  99. ಈతͳϨΠΞ΢τ class MyActivityUI(private val theme: Int, private val buttonTheme: Int)

    : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { owner.setTheme(theme) verticalLayout { textView("0") button(“OK") themedButton("Cancel", buttonTheme) } } }
  100. ϨΠΞ΢τͷ࠶ར༻

  101. ϨΠΞ΢τͷ࠶ར༻

  102. ϨΠΞ΢τͷ࠶ར༻ ਅΜதʹ഑ஔ͢Δ7JFX͚ͩҧ͏

  103. ϨΠΞ΢τͷ࠶ར༻ interface SampleUI<in T> : AnkoComponent<T> { override fun createView(ui:

    AnkoContext<T>): View = with(ui) { relativeLayout { imageView(R.drawable.zebra) { scaleType = ImageView.ScaleType.FIT_XY }.lparams(width = matchParent, height = matchParent) createInnerView().lparams { centerInParent() } } } fun _RelativeLayout.createInnerView() : View }
  104. ϨΠΞ΢τͷ࠶ར༻ interface SampleUI<in T> : AnkoComponent<T> { override fun createView(ui:

    AnkoContext<T>): View = with(ui) { relativeLayout { imageView(R.drawable.zebra) { scaleType = ImageView.ScaleType.FIT_XY }.lparams(width = matchParent, height = matchParent) createInnerView().lparams { centerInParent() } } } fun _RelativeLayout.createInnerView() : View }
  105. ϨΠΞ΢τͷ࠶ར༻ interface SampleUI<in T> : AnkoComponent<T> { override fun createView(ui:

    AnkoContext<T>): View = with(ui) { relativeLayout { imageView(R.drawable.zebra) { scaleType = ImageView.ScaleType.FIT_XY }.lparams(width = matchParent, height = matchParent) createInnerView().lparams { centerInParent() } } } fun _RelativeLayout.createInnerView() : View }
  106. ϨΠΞ΢τͷ࠶ར༻ class Sample1UI: SampleUI<Context> { override fun _RelativeLayout.createInnerView() : View

    = with(this) { button("Button") } } class Sample2UI: SampleUI<Context> { override fun _RelativeLayout.createInnerView() : View = with(this) { textView("text") } } class Sample3UI: SampleUI<Context> { override fun _RelativeLayout.createInnerView() : View = with(this) { progressBar() } }
  107. ϨΠΞ΢τͷ࠶ར༻ class Sample1UI: SampleUI<Context> { override fun _RelativeLayout.createInnerView() : View

    = with(this) { button("Button") } } class Sample2UI: SampleUI<Context> { override fun _RelativeLayout.createInnerView() : View = with(this) { textView("text") } } class Sample3UI: SampleUI<Context> { override fun _RelativeLayout.createInnerView() : View = with(this) { progressBar() } }
  108. ϨΠΞ΢τͷ࠶ར༻

  109. ϨΠΞ΢τͷ࠶ར༻

  110. ϨΠΞ΢τͷ࠶ར༻

  111. ϨΠΞ΢τͷ࠶ར༻ class HourlyWeatherView(context: Context) : _LinearLayout(context) { val hourTextView: TextView

    val imageView: ImageView val tempTextView: TextView init { // DSL͔͘ } }
  112. ϨΠΞ΢τͷ࠶ར༻ class HourlyWeatherView(context: Context) : _LinearLayout(context) { val hourTextView: TextView

    val imageView: ImageView val tempTextView: TextView init { // DSL͔͘ } }
  113. ϨΠΞ΢τͷ࠶ར༻ class HourlyWeatherView(context: Context) : _LinearLayout(context) { val hourTextView: TextView

    val imageView: ImageView val tempTextView: TextView init { // DSL͔͘ } }
  114. ϨΠΞ΢τͷ࠶ར༻ fun ViewManager.hourlyWeatherView() = customView(theme = 0) {} inline fun

    ViewManager.hourlyWeatherView(init: HourlyWeatherView.()->Unit) : HourlyWeatherView { return ankoView({ HourlyWeatherView(it) }, theme = 0, init = init) } %4-Ͱ࢖͑ΔΑ͏ʹ
  115. ϨΠΞ΢τͷ࠶ར༻ class WeatherActivityUI: AnkoComponent<WeatherActivity> { var hourlyWeatherViews = arrayListOf<HourlyWeatherView>() override

    fun createView(ui: AnkoContext<WeatherActivity>): View = with(ui) { linearLayout { hourlyWeatherView().let { hourlyWeatherViews(it) } hourlyWeatherView().let { hourlyWeatherViews(it) } hourlyWeatherView().let { hourlyWeatherViews(it) } hourlyWeatherView().let { hourlyWeatherViews(it) } hourlyWeatherView().let { hourlyWeatherViews(it) } } } }
  116. ϨΠΞ΢τͷ࠶ར༻

  117. ຊ೔ͷ"OLPϝχϡʔ w"OLPͷ঺հ w"OLP͸࢖͍෺ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰ͸ͷ׆༻๏ w7JFX*%ͷ࠾൪

  118. ͜Μͳͱ͖7JFX*E͕ཁΔ w 3FMBUJWF-BZPVUͰ૬ରҐஔΛࢦఆ͢Δͱ͖ w 'SBHNFOUͷ$POUBJOFSΛࢦఆ͢Δͱ͖

  119. 7JFX*%ͷ࠾൪ wҰݸͣͭఆ਺࡞Δ w7JFXHFOFSBUF7JFX*E  wίʔυͷߦ൪߸

  120. ఆ਺Λ༻ҙ class MyActivityUI : AnkoComponent<MyActivity> { private object Ids {

    val editText = 1 val button = 2 } override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { verticalLayout { editText { id = Ids.editText } button("OK") { id = Ids.button } } } }
  121. ఆ਺Λ༻ҙ class MyActivityUI : AnkoComponent<MyActivity> { private object Ids {

    val editText = 1 val button = 2 } override fun createView(ui: AnkoContext<MyActivity>): View = with(ui) { verticalLayout { editText { id = Ids.editText } button("OK") { id = Ids.button } } } }
  122. ఆ਺Λ༻ҙ wγϯϓϧ! w࣮૷͕໘౗͍͘͞*

  123. 7JFXHFOFSBUF7JFX*E class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>):

    View = with(ui) { verticalLayout { editText { id = View.generateViewId() } button("OK") { id = View.generateViewId() } } } }
  124. 7JFXHFOFSBUF7JFX*E class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>):

    View = with(ui) { verticalLayout { editText { id = View.generateViewId() } button("OK") { id = View.generateViewId() } } } }
  125. 7JFXHFOFSBUF7JFX*E w࣮૷͕ϥΫνϯ! w"DUJWJUZͷ࠶ੜ੒Ͱ
 ໰୊͕ى͜Δ كʹ *

  126. 7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU *E9

  127. 7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU .Z'SBHNFOU #VOEMF *E9 PO4BWFE*OTUBODF4UBUF .Z'SBHNFOU $POUBJOFS*E9

  128. 7JFXHFOFSBUF7JFX*E #VOEMF "DUJWJUZ͕ഁغ͞Εͯʜ .Z'SBHNFOU $POUBJOFS*E9

  129. 7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU .Z'SBHNFOU $POUBJOFS*E9 #VOEMF PO3FTUPSF*OTUBODF4UBUF

  130. 7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU .Z'SBHNFOU $POUBJOFS*E9 #VOEMF PO3FTUPSF*OTUBODF4UBUF *E:

  131. 7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU .Z'SBHNFOU $POUBJOFS*E9 #VOEMF 'SBHNFOUͷ$POUBJOFS*E͕มΘͬͯΔʂ *E:

  132. 7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU 5FYU7JFX 5FYU7JFX *E9 .Z'SBHNFOU $POUBJOFS*E9 #VOEMF *E:

  133. 7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU 5FYU7JFX 5FYU7JFX *E9 .Z'SBHNFOU $POUBJOFS*E9 #VOEMF *E:

    $MBTT$BTU&YDFQUJPO
  134. ίʔυͷߦ൪߸ 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
  135. ίʔυͷߦ൪߸ 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
  136. ίʔυͷߦ൪߸ 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
  137. ίʔυͷߦ൪߸ w࣮૷͕ϥΫνϯ! w7JFX*E͔ͿΔՄೳੑΞϦ*

  138. None