Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Anko試食会
Search
watanave
February 05, 2018
Programming
2.4k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Anko試食会
DroidKaigi 2018
watanave
February 05, 2018
More Decks by watanave
See All by watanave
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
5.3k
Flutter実践開発に書かなかったこと
watanave
0
87
Flutterビギナーのための Widget完全攻略
watanave
0
52
決めず、語らずのリーダーシップ
watanave
0
590
複数プロジェクトを横断するゆめみテックリードの戦略
watanave
0
140
Androidエンジニア目線のKMM / iOSエンジニア目線のKMM
watanave
0
370
Why does Activity die soon?
watanave
0
370
Other Decks in Programming
See All in Programming
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
160
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
360
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
900
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
2.9k
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
1.1k
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
5.3k
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
350
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
500
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
霧の中の代数的エフェクト
funnyycat
1
410
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
690
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
180
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
Optimising Largest Contentful Paint
csswizardry
37
3.8k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.5k
Everyday Curiosity
cassininazir
0
260
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
410
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
370
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
380
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
57k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.3k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
Transcript
"OLPࢼ৯ձ %SPJE,BJHJ XBUBOBWF
:PIUB8BUBOBCF $SZQUPO'VUVSF.FEJB *OD UXJUUFS!4VTBO@KBDLP HJUIVC!TVTBO
"OLPJTB,PUMJOMJCSBSZXIJDINBLFT"OESPJEBQQMJDBUJPOEFWFMPQNFOUGBTUFS BOEFBTJFS*UNBLFTZPVSDPEFDMFBOBOEFBTZUPSFBE BOEMFUTZPVGPSHFU BCPVUSPVHIFEHFTPGUIF"OESPJE4%,GPS+BWB
͜Μͳํ w,PUMJOͦͦ͑͜͜Δ w"OLPͬͨ͜ͱͳ͍ w"OLP%4-ͬͯ ढจʹݟ͑Δʜ
ຊͷ"OLPϝχϡʔ w"OLPͷհ w"OLP͍ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰͷ׆༻๏ w7JFX*%ͷ࠾൪
ຊͷ"OLPϝχϡʔ w"OLPͷհ w"OLP͍ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰͷ׆༻๏ w7JFX*%ͷ࠾൪
"OLP "OLP $PNNPOT "OLP -BZPVUT "OLP 42-JUF "OLP $PSPVUJOFT
"OLP-BZPVUT "OLP%4-
"OLP-BZPVUT "OLP%4- 7JFXͷϨΠΞτΛ࡞Δ ಠࣗυϝΠϯݴޠ ͬͱݴͬͯɺ ,PUMJOͷߏจ্ʹΓཱ͍ͬͯΔ
"OLP%4-
None
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>
"OLP%4- 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") } 9.- "OLP%4-
<LinearLayout > <EditText/> <Button/> </LinearLayout> verticalLayout { editText() button("Say Hello")
} 9.- "OLP%4-
<LinearLayout > <EditText/> <Button/> </LinearLayout> verticalLayout { editText() button("Say Hello")
} 9.- "OLP%4-
<LinearLayout > <EditText/> <Button/> </LinearLayout> verticalLayout { editText() button("Say Hello")
} 9.- "OLP%4- งғؾࣅͯΔ
͏গ͠ৄ͘͠
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>
"OLP%4- linearLayout { backgroundColor = Color.DKGRAY textView { text =
"͔͋" textColor = Color.RED } textView { text = "͠Ζ" textColor = Color.WHITE } textView { text = "͖͍Ζ" textColor = Color.YELLOW } }
"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 }
"OLP%4- ϒϨʔεͰ֊Λදݱ linearLayout { backgroundColor = Color.DKGRAY textView { text
= "͔͋" textColor = Color.RED } }
"OLP%4- ϒϨʔεͰ֊Λදݱ linearLayout { backgroundColor = Color.DKGRAY textView { text
= "͔͋" textColor = Color.RED } }
"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 }
"OLP%4- ϒϨʔεͷதͰϓϩύςΟηοτ textView { text = “͔͋" textColor = Color.RED
}
"OLP%4- ϒϨʔεͷதͰϓϩύςΟηοτ view { ϓϩύςΟ = }
"OLP%4- linearLayout { backgroundColor = Color.DKGRAY textView { text =
"͔͋" textColor = Color.RED } textView { text = "͠Ζ" textColor = Color.WHITE } textView { text = "͖͍Ζ" textColor = Color.YELLOW } }
"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) } }
"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) }
"OLP%4- MQBSBNTʹଓ͚ͯϨΠΞτͷઃఆ textView { text = "͔͋" textColor = Color.RED
}.lparams { margin = dip(10) }
"OLP%4- MQBSBNTʹଓ͚ͯϨΠΞτͷઃఆ view { }.lparams { LayoutParamsͷϓϩύςΟ = }
"OLP$PNQPOFOU interface AnkoComponent<in T> { fun createView(ui: AnkoContext<T>): View }
"OLP$PNQPOFOU class MyActivity : AppCompatActivity() { // ུ }
"OLP$PNQPOFOU class MyActivity : AppCompatActivity() { // ུ } class
MyActivityUI : AnkoComponent<MyActivity> { } class MyActivity : AppCompatActivity() { // ུ } class MyActivityUI : AnkoComponent<MyActivity> { }
"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ॻ͘ } }
"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ॻ͘ } }
"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ॻ͘ } }
ຊͷ"OLPϝχϡʔ w"OLPͷհ w"OLP͍ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰͷ׆༻๏ w7JFX*%ͷ࠾൪
"OLPͷ͕͜͜ྑ͍ w 9.-͔Βͷղ์ w ܕ҆શ w ಈతͳϨΠΞτ͕ಘҙ w ϨΠΞτͷ࠶ར༻ੑ͕ߴ͘ͳΔ
"OLPͷ͕͜͜੯͍͠ w ϓϨϏϡʔ͕ʜ w 7JFX*%ͷ࠾൪ʹ͋Γ
"OLP2"
ΧελϜ7JFX ѻ͑Δʁ :&4!
ύϑΥʔϚϯε Ͳ͏ͳͷʁ :&4"
"OLPͰ Ͱ͖ͳ͍ࣄ͋Δʁ Ίͳ͍ϨΠΞτ ଟɺͳ͍
"OLPͰ Ͱ͖ͳ͍ࣄ͋Δʁ ΞϓϦͷϓϩηε֎Ͱ ಈ࡞͢Δॴ# w ΧελϜ௨ϨΠΞτ w "QQ8JEHFUTͷϨΠΞτ
ϓϨϏϡʔਏ͘ͳ͍ʁ 㵰'ͰؤுΔ$
ϓϩδΣΫτͰ࠾༻ͯ͠ Ͳ͏ͩͬͨʁ ͬͱɺఏҊͨ͠ࢲࢥͬͯΔ ྑ͔ͬͨ%
ϓϩδΣΫτͰ࠾༻ͯ͠ Ͳ͏ͩͬͨʁ wֶशίετɺ͋Δ& wωοΫϓϨϏϡʔ͔' w7JFX͕͍·ΘͤΔͷྑ͍( w9.-Ͱফͯ͠ΔͳΒ͏͔͠ͳ͍)
ຊͷ"OLPϝχϡʔ w"OLPͷհ w"OLP͍ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰͷ׆༻๏ w7JFX*%ͷ࠾൪
"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) } }
MJOFBS-BZPVUΛ࡞Δϝιου class AnkoContext(val ctx: Context) { fun linearLayout() : LinearLayout
{ return LinearLayout(ctx) } }
MJOFBS-BZPVUΛ࡞Δϝιου class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } }
MJOFBS-BZPVUΛίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) { ui.linearLayout ({ // do something }) }
%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 }) }
%4-ͬΆ͘ίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) { ui.linearLayout { // do something } } ɹɹ
XJUI inline fun <T, R> with(receiver: T, block: T.() ->
R): R (source) rIUUQTLPUMJOMBOHPSHBQJMBUFTUKWNTUEMJCLPUMJOXJUIIUNM l༩͑ΒΕͨϨγʔόΛϨγʔόͱͯ͠ࢦఆͨ͠ϑΝϯ ΫγϣϯϒϩοΫΛݺͼग़͠ɺͦͷ݁ՌΛฦ͠·͢ɻz
XJUI CMPDLͷείʔϓͰɺ UIJT͕SFDFJWFSʹͳΔ inline fun <T, R> with(receiver: T, block:
T.() -> R): R (source)
%4-ͬΆ͘ίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) { ui.linearLayout { // do something } }
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 } }
୯Ұࣜؔͩͬͨ 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 } })
୯Ұࣜؔ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui, { this.linearLayout { // do something } })
ͬͱ%4-ͬΆ͘ίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui, { this.linearLayout { // do something } })
ͬͱ%4-ͬΆ͘ίʔϧ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { this.linearLayout { // do something } }
ͬͱͬͱ%4-ͬΆ͘ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { // do something } }
ϓϩύςΟͲ͏ͬͯʁ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { } } backgroundColor = Color.DKGRAY
͜Εҧ͏ʁ 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 } }
͜Εҧ͏ʁ 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 } } }
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ʹ͍ͨ͠ʂ } }
ϓϩύςΟͲ͏ͬͯʁ class AnkoContext(val ctx: Context) { fun linearLayout(init: ()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { } }
ϓϩύςΟͲ͏ͬͯʁ class AnkoContext(val ctx: Context) { fun linearLayout(init: LinearLayout.()->Unit) :
LinearLayout { return LinearLayout(ctx) } } fun createView(ui: AnkoContext) = with(ui) { linearLayout { } }
ϓϩύςΟͲ͏ͬͯʁ 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.
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 = "͋Μ͜" }
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 }
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 }
"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 }
ೖΕࢠߏͰ͖ͨ fun createView(ui: AnkoContext) = with(ui) { return linearLayout {
backgroundColor = Color.DKGRAY textView { text = “͋Μ͜" } } }
MQBSBNTΛͲ͏͢Δ͔ fun createView(ui: AnkoContext) = with(ui) { linearLayout { backgroundColor
= Color.DKGRAY textView { text = “͋Μ͜" }.lparams { } } }
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 { } } }
ܕҧ͏ 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 { } } } #
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 AnkoContext(val ctx: Context) { fun linearLayout(init: LinearLayout.()->Unit) :
_LinearLayout { val linearLayout = _LinearLayout(ctx) linearLayout.init() return linearLayout } }
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 } // ུ } 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() } // ུ }
"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) } }
%4- w ҾϥϜμࣜͷΧοίলུه๏ w είʔϓຖͷUIJTࢀরΓସ͑ Ͱग़དྷͯΔ
ࠔͬͨΒ είʔϓͷUIJTΛ ҙࣝ͢Δ
ຊͷ"OLPϝχϡʔ w"OLPͷհ w"OLP͍ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰͷ׆༻๏ w7JFX*%ͷ࠾൪
ܕ҆શ
ܕ҆શ class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>):
View = with(ui) { verticalLayout { textView("0") button("OK") } } }
ܕ҆શ class MyActivityUI : AnkoComponent<MyActivity> { override fun createView(ui: AnkoContext<MyActivity>):
View = with(ui) { verticalLayout { val textView = textView("0") val button = button("OK") } } }
ܕ҆શ 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") } } }
ܕ҆શ 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") } } }
ಈతͳϨΠΞτ
ಈతͳϨΠΞτ linearLayout { (0..num).forEach { imageView(R.drawable.star) } }
ಈతͳϨΠΞτ 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) } } }
ಈతͳϨΠΞτ 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) } } }
ಈతͳϨΠΞτ 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) } } }
ಈతͳϨΠΞτ 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) } } }
ϨΠΞτͷ࠶ར༻
ϨΠΞτͷ࠶ར༻
ϨΠΞτͷ࠶ར༻ ਅΜதʹஔ͢Δ7JFX͚ͩҧ͏
ϨΠΞτͷ࠶ར༻ 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 }
ϨΠΞτͷ࠶ར༻ 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 }
ϨΠΞτͷ࠶ར༻ 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 }
ϨΠΞτͷ࠶ར༻ 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() } }
ϨΠΞτͷ࠶ར༻ 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() } }
ϨΠΞτͷ࠶ར༻
ϨΠΞτͷ࠶ར༻
ϨΠΞτͷ࠶ར༻
ϨΠΞτͷ࠶ར༻ class HourlyWeatherView(context: Context) : _LinearLayout(context) { val hourTextView: TextView
val imageView: ImageView val tempTextView: TextView init { // DSL͔͘ } }
ϨΠΞτͷ࠶ར༻ class HourlyWeatherView(context: Context) : _LinearLayout(context) { val hourTextView: TextView
val imageView: ImageView val tempTextView: TextView init { // DSL͔͘ } }
ϨΠΞτͷ࠶ར༻ class HourlyWeatherView(context: Context) : _LinearLayout(context) { val hourTextView: TextView
val imageView: ImageView val tempTextView: TextView init { // DSL͔͘ } }
ϨΠΞτͷ࠶ར༻ fun ViewManager.hourlyWeatherView() = customView(theme = 0) {} inline fun
ViewManager.hourlyWeatherView(init: HourlyWeatherView.()->Unit) : HourlyWeatherView { return ankoView({ HourlyWeatherView(it) }, theme = 0, init = init) } %4-Ͱ͑ΔΑ͏ʹ
ϨΠΞτͷ࠶ར༻ 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) } } } }
ϨΠΞτͷ࠶ར༻
ຊͷ"OLPϝχϡʔ w"OLPͷհ w"OLP͍ʹͳΔͷ͔ w"OLPղମγϣʔ w"OLPͳΒͰͷ׆༻๏ w7JFX*%ͷ࠾൪
͜Μͳͱ͖7JFX*E͕ཁΔ w 3FMBUJWF-BZPVUͰ૬ରҐஔΛࢦఆ͢Δͱ͖ w 'SBHNFOUͷ$POUBJOFSΛࢦఆ͢Δͱ͖
7JFX*%ͷ࠾൪ wҰݸͣͭఆ࡞Δ w7JFXHFOFSBUF7JFX*E wίʔυͷߦ൪߸
ఆΛ༻ҙ 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 } } } }
ఆΛ༻ҙ 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 } } } }
ఆΛ༻ҙ wγϯϓϧ! w࣮͕໘͍͘͞*
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() } } } }
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() } } } }
7JFXHFOFSBUF7JFX*E w࣮͕ϥΫνϯ! w"DUJWJUZͷ࠶ੜͰ ͕ى͜Δ كʹ *
7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU *E9
7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU .Z'SBHNFOU #VOEMF *E9 PO4BWFE*OTUBODF4UBUF .Z'SBHNFOU $POUBJOFS*E9
7JFXHFOFSBUF7JFX*E #VOEMF "DUJWJUZ͕ഁغ͞Εͯʜ .Z'SBHNFOU $POUBJOFS*E9
7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU .Z'SBHNFOU $POUBJOFS*E9 #VOEMF PO3FTUPSF*OTUBODF4UBUF
7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU .Z'SBHNFOU $POUBJOFS*E9 #VOEMF PO3FTUPSF*OTUBODF4UBUF *E:
7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU .Z'SBHNFOU $POUBJOFS*E9 #VOEMF 'SBHNFOUͷ$POUBJOFS*E͕มΘͬͯΔʂ *E:
7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU 5FYU7JFX 5FYU7JFX *E9 .Z'SBHNFOU $POUBJOFS*E9 #VOEMF *E:
7JFXHFOFSBUF7JFX*E 'SBNF-BZPVU .Z'SBHNFOU 5FYU7JFX 5FYU7JFX *E9 .Z'SBHNFOU $POUBJOFS*E9 #VOEMF *E:
$MBTT$BTU&YDFQUJPO
ίʔυͷߦ൪߸ 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 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
ίʔυͷߦ൪߸ w࣮͕ϥΫνϯ! w7JFX*E͔ͿΔՄೳੑΞϦ*
None