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.3k
Android MVVM 패턴의 접근법 - 2023 드로이드 나이츠
taehwandev
1
1.6k
안드로이드의 변화 - IO Extended 2023 - 송도
taehwandev
0
540
What’s new in Android?(Google IO ex 23-GDG Pangyo)
taehwandev
0
830
Jetpack Compose 상태 및 사이드 효과
taehwandev
0
1.1k
GDG DevFest2022 Songdo - KMM(Kotlin Multiplatform Mobile)
taehwandev
0
560
Kotlin Night 2022 - 코틀린 어노테이션으로 할 수 있는 것(GDG Seoul)
taehwandev
2
1.6k
Android module 개발 - Now in android 참고
taehwandev
3
16k
Android Compose Component - mapping.
taehwandev
2
4.6k
Other Decks in Education
See All in Education
Image Processing 1 : 1.Introduction
hachama
0
480
Web 2.0 Patterns and Technologies - Lecture 8 - Web Technologies (1019888BNR)
signer
PRO
0
2.5k
Казармы и гарнизоны
pnuslide
0
150
TP5_-_UV.pdf
bernhardsvt
0
120
HTML5 and the Open Web Platform - Lecture 3 - Web Technologies (1019888BNR)
signer
PRO
1
2.6k
Tableau トレーニング【株式会社ニジボックス】
nbkouhou
0
23k
Medidas en informática
irocho
0
390
H5P-työkalut
matleenalaakso
4
36k
Introduction - Lecture 1 - Web Technologies (1019888BNR)
signer
PRO
0
4.9k
Ch2_-_Partie_2.pdf
bernhardsvt
0
110
Nodiレクチャー 「CGと数学」講義資料 2024/11/19
masatatsu
1
260
Stratégie de marketing digital - les fondamentaux
martine
0
140
Featured
See All Featured
Designing Experiences People Love
moore
138
23k
The Cost Of JavaScript in 2023
addyosmani
46
7k
Typedesign – Prime Four
hannesfritz
40
2.4k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
530
Embracing the Ebb and Flow
colly
84
4.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Building an army of robots
kneath
302
44k
Producing Creativity
orderedlist
PRO
342
39k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
6
460
Git: the NoSQL Database
bkeepers
PRO
427
64k
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
[email protected]
GDG Seoul ӂకജ ޙೞप ѱ թਵ࣑ݶ,