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
Taehwan-IO18_Extended_in_Suwon.pdf
Search
TaeHwan
June 25, 2018
Education
2
14k
Taehwan-IO18_Extended_in_Suwon.pdf
GDG Google I/O Extended in Suwon.
TaeHwan
June 25, 2018
Tweet
Share
More Decks by TaeHwan
See All by TaeHwan
Compose 함수 나누는 조건은?
taehwandev
0
1.6k
Android MVVM 패턴의 접근법 - 2023 드로이드 나이츠
taehwandev
1
1.7k
안드로이드의 변화 - IO Extended 2023 - 송도
taehwandev
0
580
What’s new in Android?(Google IO ex 23-GDG Pangyo)
taehwandev
0
860
Jetpack Compose 상태 및 사이드 효과
taehwandev
0
1.1k
GDG DevFest2022 Songdo - KMM(Kotlin Multiplatform Mobile)
taehwandev
0
590
Kotlin Night 2022 - 코틀린 어노테이션으로 할 수 있는 것(GDG Seoul)
taehwandev
2
1.6k
Android module 개발 - Now in android 참고
taehwandev
3
17k
Android Compose Component - mapping.
taehwandev
2
4.7k
Other Decks in Education
See All in Education
いにしえの国産データベース~桐~って知っていますか?
masakiokuda
2
140
郷土教育モデル事業(香川県小豆島町).pdf
bandg
0
100
Visualisation Techniques - Lecture 8 - Information Visualisation (4019538FNR)
signer
PRO
0
2.3k
Data Presentation - Lecture 5 - Information Visualisation (4019538FNR)
signer
PRO
0
2.4k
The Prison Industrial Complex by Billy Dee
oripsolob
0
830
日本電子専門学校ネットワークセキュリティ科_学科紹介.pdf
ccyc
0
810
教員向け生成AI基礎講座(2025年3月28日 東京大学メタバース工学部 ジュニア講座)
luiyoshida
0
250
IMU-00 Pi
kanaya
0
260
子どものためのプログラミング道場『CoderDojo』〜法人提携例〜 / Partnership with CoderDojo Japan
coderdojojapan
4
15k
R6愛南町事前復興フォーラムリーフレット
bousaichiribu
0
210
生成AI時代教育とICT支援員への期待
o_ob
0
240
CV_1_Introduction
hachama
0
190
Featured
See All Featured
Building Adaptive Systems
keathley
41
2.5k
Building Applications with DynamoDB
mza
94
6.3k
Side Projects
sachag
452
42k
Code Review Best Practice
trishagee
67
18k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
7
640
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.4k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
510
Build your cross-platform service in a week with App Engine
jlugia
229
18k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.7k
Docker and Python
trallard
44
3.3k
The Invisible Side of Design
smashingmag
299
50k
Transcript
Kotlin / Android KTX Android Jetpack Tae-hwan
ࣗѐ ! GDG Seoul ! RGP Korea ਃӝਃ উ٘۽٘
ѐߊ ! Է ݆ ѐߊо غ ࠶۽Ӓ http://thdev.tech / http://thdev.net ! Udemy ౣܽ ъ
Android Jetpack Foundation, Architecture, Behavior, UI
Android Jetpack Jetpack Android ѐߊী ਃೠ ߈ੋ ۄ࠳۞ܻ ݽ
о٘ - Foundation, Architecture, Behavior, UI Jetpack : https://developer.android.com/jetpack/
Android Jetpack Jetpack
Android Jetpack AndroidX ӝઓ ۄ࠳۞ܻٜ Package name ా Jetpackীࢲח androidx.*
ಁఃܳ ࢎਊ Compile version 28ࠗఠ ࢎਊ оמ AndroidX Release Note AndroidX convert ܻ Ӗ - thdev Google Jetpack Sample - Android Sunflower (alpha)
New Project ࢤࢿ Target API 28۽ ࢸೡ ҃
Android Jetpack ViewModel - AS 3.2 Previewীࢲ ࢤࢿೞӝ
Android Jetpack ViewModel - AS 3.2 Previewীࢲ ࢤࢿೞӝ
Android Jetpack ViewModel - ViewModel ਊ package ҳઑ
Android Jetpack New androidx package compileSdkVersion Android 28 ࢚ ࢎਊ
оמ dependencies { implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.0.0-alpha1' implementation 'androidx.constraintlayout:constraintlayout:1.1.0' implementation ‘androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.0-alpha3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3' }
Android Jetpack Jetpack - MainFragment.kt class MainFragment : Fragment() {
companion object { fun newInstance() = MainFragment() } private lateinit var viewModel: MainViewModel override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java) // TODO: Use the ViewModel } }
Android Jetpack Jetpack - ViewModel.kt class MainViewModel : ViewModel() {
// TODO: Implement the ViewModel override fun onCleared() { super.onCleared() // todo release } }
Kotlin Kotlin णೞח ߑߨ
Kotlin Kotlin णೞח ߑߨ? Reference ଵҊೞӝ : https://kotlinlang.org/docs/reference/ ଼ Kotlin
in Action - ೠӖ/ޙ ழפ ౣܽ: ରࣁ উ٘۽٘ ѐߊܳ ਤೠ ৡۄੋ ъ Kotlin Bootcamp for Programmers - Udacity ઁ ъ ౣܽ दೞӝ - Udemy
Kotlin Kotlin णೞח ߑߨ? - Java ࢿ - Kotlin ஶߡ
ೞӝ(بҳীࢲ ઁҕೞח ஶߡఠ/Kotlin ࢎীࢲ ઁҕೞח ஶߡఠ ഝਊ) - Java۽ ࢿೞҊ, ࠂࢎ ࠢৈ֍ӝܳ ా೧ ஶߡఠೞҊ, ઑӘঀ ࣻ೧ ࠄ - Kotlin ӝࠄ ޙߨ(Lambda, fun, class ١) ࣼ റ ೞաঀ ਊ೧ࠄ Repeat. ࣼ೧ ݅ఀ ٘ ח ߑߨਸ णٙೞҊ, Extension ࢎਊ ١ਸ ӓ ഝਊ೧ࠄ
Kotlin ഥࢎী ਊ? ѐੋ ࠶۽Ӓ ࣗѐ https://thdev.tech/kotlin/android/2018/01/02/Kotlin-Learning-and-Introduction.html ഥࢎ ࠶۽Ӓ ࣗѐ
https://rgpkorea.github.io/posts/yogiyo-kotlin/
Kotlin Android KTX ঌইࠁӝ ী
Kotlin Android KTX ঌইࠁӝ ী - ҳࢿ Lambdas അ Kotlin
Extension Higher-Order Function
Kotlin Lambdas Button button = findViewById(R.id.btn); button.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) { // TODO } });
Kotlin Lambdas Button button = findViewById(R.id.btn); button.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) { // TODO } }); // kotlin val button = findViewById<Button>(R.id.btn) button.setOnClickListener { // TODO } ଵҊ : https://thdev.tech/kotlin/2018/03/17/Kotlin-Lambdas.html
Kotlin Kotlin Extension Extension ਗې ېझীࢲ ઁҕೞח ӝמੋ Ѫۢ ഛ
ೣࣻܳ ٜ݅ ࣻ .
Kotlin Kotlin Extension val name: String? = null if (name.isNullOrEmpty())
{ // ... } val name ߸ࣻо null ژח “”ੋ ҃ܳ ഛੋೞৈ ߹ب ܻܳ ೠ. ೞ݅ String class/CharSequence class উীח isNullOrEmpty() ݫࣗ٘ח ઓೞ ঋח. @kotlin.internal.InlineOnly public inline fun CharSequence?.isNullOrEmpty(): Boolean { contract { returns(false) implies (this@isNullOrEmpty != null) } return this == null || this.length == 0 } ଵҊ : https://kotlinlang.org/docs/reference/extensions.html
Kotlin Higher-Order Function Higher-Order Functions ೣࣻܳ ߸ࣻ۽ ֈѹѢա, ܳ ߈ജೞח
Ѫਸ ݈פ.
Kotlin Higher-Order Function Higher-Order Functions ೣࣻܳ ߸ࣻ۽ ֈѹѢա, ܳ ߈ജೞח
Ѫਸ ݈פ. fun print(body: () -> String) { println(body()) } print { “Ѣ ۱೧” } >> body: () -> T body : ߸ࣻ ܴ () -> String : () ۄݫఠо হח ݫࢲ٘ܳ ೞҊ, -> String return ఋੑਸ פ. ଵҊ : https://thdev.tech/kotlin/2017/10/02/Kotlin-Higher-Order-Function.html
Kotlin Android KTX
Kotlin Android KTX What is Android KTX? Jetpack family Android
- Kotlin ࢎਊ ಞܳ ذח extensions AndroidX ಁః۽ ઁҕ implementation ‘androidx.core:core-ktx:1.0.0-alpha1’ Android Open Source Project Apache License, Version 2.0 API : https://github.com/android/android-ktx API reference documentation : https://android.github.io/android-ktx/core-ktx/ Android Jetpack: sweetening Kotlin development with Android KTX (Google I/O '18)
Kotlin Android KTX Modules androidx.core:core-ktx androidx.fragment:fragment-ktx androidx.sqlite:sqlite-ktx androidx.lifecycle:lifecycle-viewmodel-ktx android.arch.navigation:navigation-common-ktx android.arch.work:work-runtime-ktx
More modules : https://developer.android.com/kotlin/ktx
Kotlin Android KTX ਃ٘ > kotlin sharedPreferences.edit() .putBoolean("key", value) .apply()
> Android KTX sharedPreferences.edit { putBoolean("key", value) }
Kotlin Android KTX ਃ٘ > Android KTX sharedPreferences.edit { putBoolean("key",
value) } > ղࠗ ٘ @SuppressLint("ApplySharedPref") inline fun SharedPreferences.edit( commit: Boolean = false, action: SharedPreferences.Editor.() -> Unit ) { val editor = edit() action(editor) if (commit) { editor.commit() } else { editor.apply() } }
Kotlin Android KTX ٘ ୷ড જ Ѫ݅ ইפ Kotlinਸ ೞݶ
٘ ୷ডਸ ݆ ೠ Ӓѱ ޖઑѤ જ Ѫ ইפ
Kotlin Android KTX ٘ ୷ড if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
{ // Something } ਤ ٘ܳ ۰ ݅ٚ ഛ ೣࣻ inline fun onApi(level: Int, body: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } } onApi(Build.VERSION_CODES.P) { // Something }
Kotlin Android KTX ٘ ୷ড if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
{ // Something } else { // Something } ਤ ٘ܳ ۰ ݅ٚ ഛ ೣࣻ inline fun onApi(level: Int, body: () -> Unit, bodyElse: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } else { bodyElse() } }
Kotlin Android KTX ٘ ୷ড onApi(Build.VERSION_CODES.P, { // if
Something }) { // else Something } ਤ ٘ܳ ۰ ݅ٚ ഛ ೣࣻ inline fun onApi(level: Int, body: () -> Unit, bodyElse: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } else { bodyElse() } }
Kotlin Android KTX ٘ ୷ড if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
{ // Something } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { // Something } else { // Something } ਤ ٘ܳ ۰ ݅ٚ ഛ ೣࣻ inline fun onApi(level: Int, body: () -> Unit, levelTwo: Int, bodyTwo: () -> Unit, bodyElse: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } else if (Build.VERSION.SDK_INT >= levelTwo) { bodyTwo() } else { bodyElse() } }
Kotlin Android KTX ٘ ୷ড onApi(Build.VERSION_CODES.P, { // if
Something }, Build.VERSION_CODES.KITKAT, { // else if Something }) { // else Something } ਤ ٘ܳ ۰ ݅ٚ ഛ ೣࣻ inline fun onApi(level: Int, body: () -> Unit, levelTwo: Int, bodyTwo: () -> Unit, bodyElse: () -> Unit) { if (Build.VERSION.SDK_INT >= level) { body() } else if (Build.VERSION.SDK_INT >= levelTwo) { bodyTwo() } else { bodyElse() } }
Kotlin Android KTX KEEP-110 KEEP > Kotlin Evolution Enhancement Process
KEEP-110 ۽ંܳ ా೧ Javaীࢲب Kotlin ಞࢿਸ ֫ @ExtensionFunction/@ExtensionProperty - Kotlin ഛ ೣࣻܳ ઁҕ @DefaultValue - Kotlin ٣ಫ ۄݫఠ ӝמ ઁҕ @KtName - function ۄݫఠী Kotlinীࢲ ࠗܳ ܴਸ ߹ب оמ > ই ֤ੋ ઁ۽ য֢ప࣌ ܴ ߸҃ؼ ࣻ GitHub : https://github.com/Kotlin/KEEP
KEEP-110 @ExtensionFunction/@ExtensionProperty @ExtensionFunction public static String getNonNullName(@Nullable String name) {
return name != null ? name : ""; } Kotlin ഐ val name: String? = null println(name.getNonNullName()) > Kotlinীࢲח ইې৬ э ࢿ fun String?.getNonNullName() = this?.takeIf { it.isNotEmpty() } ?: ""
KEEP-110 @KtName - ۄݫఠ ܴ public static void setPadding(
@KtName("left") int left, @KtName("top") int top, @KtName("right") int right, @KtName("bottom") int bottom) { /* todo... */ } Kotlinীࢲ ࠗܳٸ setPadding(left = 0, top = 15, right = 0, bottom = 0) > ࣽࢲо ߸҃غযب ޙઁо হ setPadding(right = 0, bottom = 0, left = 0, top = 15)
KEEP-110 @DefaultValue - ӝࠄч public static void setPadding( @KtName("left")
@DefaultValue("paddingLeft") int left, @KtName("top") @DefaultValue("paddingTop") int top, @KtName("right") @DefaultValue("paddingRight") int right, @KtName("bottom") @DefaultValue("paddingBottom") int bottom) { /* todo... */ } Kotlinীࢲ ࠗܳٸ setPadding(top = 15) left, right, bottom = defaultValue۽ ୡӝച
хࢎפ http://thdev.tech taehwan@thdev.net GDG Seoul ӂకജ ޙೞप ѱ թਵ࣑ݶ,