728x90

๊ฐœ๋ฐœ 32

Kotlin constructor ์ •๋ฆฌ

์ž‘์„ฑ์ผ: 2019.12.31 Kotlin์˜ ํด๋ž˜์Šค๋Š” ํ•˜๋‚˜์˜ Primary constructor(์ฃผ ์ƒ์„ฑ์ž)์™€ ํ•˜๋‚˜ ์ด์ƒ์˜ Secondary constructor(๋ถ€ ์ƒ์„ฑ์ž)๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Primary constructor Primary constructor๋Š” ํด๋ž˜์Šค ์ด๋ฆ„ ๋’ค์— ํ‘œ๊ธฐํ•ฉ๋‹ˆ๋‹ค. class Person constructor(firstName: String) { /*...*/ } Primary constructor์— ์–ด๋…ธํ…Œ์ด์…˜์ด๋‚˜ ์ ‘๊ทผ ์ œํ•œ์ž(visibility modifiers)๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ, constructor ํ‚ค์›Œ๋“œ๋Š” ์ƒ๋žต ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. class Person(firstName: String) { /*...*/ } Primary constructor๋Š” ์ฝ”๋“œ ๋ธ”๋Ÿญ์„ ๊ฐ€์งˆ ์ˆ˜ ์—†์œผ๋ฏ€๋กœ,..

Android ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ Part 2

์ž‘์„ฑ์ผ: 2019.12.13 ์›๋ฌธ Functional Programming for Android Developers — Part 2์„ ๋ฒˆ์—ญํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ด์ „ ํŒŒํŠธ์—์„œ Purity, Side effects, Ordering์— ๋Œ€ํ•ด ๋ฐฐ์› ๊ณ , ์ด๋ฒˆ ํŒŒํŠธ์—์„œ๋Š” immutability์™€ Concurrency์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. Part 1์„ ์•„์ง ์ฝ์ง€ ์•Š์•˜๋‹ค๋ฉด, ์—ฌ๊ธฐ์—์„œ ํ™•์ธํ•˜์„ธ์š”. Immutability Immutability๋Š” ๊ฐ’์ด ํ•œ ๋ฒˆ ์ƒ์„ฑ๋˜๋ฉด ์ ˆ๋Œ€ ๋ฐ”๋€” ์ˆ˜ ์—†๋‹ค๋Š” ๊ฐœ๋…์ž…๋‹ˆ๋‹ค. ์•„๋ž˜์™€ ๊ฐ™์€ Car ํด๋ž˜์Šค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค: Java public final class Car { private String name; public Car(final String name) { this.name = name; } pu..

Android ๊ฐœ๋ฐœ์ž๋ฅผ ์œ„ํ•œ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ Part 1

์ž‘์„ฑ์ผ: 2019.12.05 ์›๋ฌธ Functional Programming for Android Developers — Part 1์„ ๋ฒˆ์—ญํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ์ด ์‹œ๋ฆฌ์ฆˆ์—์„œ๋Š”, Functional Programming (FP)์˜ ๊ธฐ์ดˆ์™€ ์ž๋ฐ”(good old Java)์™€ ์ฝ”ํ‹€๋ฆฐ(new awesome Kotlin)์—์„œ ์–ด๋–ป๊ฒŒ ์“ฐ๋Š”์ง€๋ฅผ ๋ฐฐ์šฐ๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ตœ๋Œ€ํ•œ ์ด๋ก ์ ์ธ ์ „๋ฌธ ์šฉ์–ด๋Š” ํ”ผํ•ด์„œ ์‹ค์šฉ์ ์ธ ๊ฐœ๋…์„ ๋‹ค๋ฃจ๊ฒ ์Šต๋‹ˆ๋‹ค. FP๋Š” ๋งค์šฐ ํฐ ์ฃผ์ œ๋ผ์„œ Android ์ฝ”๋“œ์—์„œ ์œ ์šฉํ•˜๊ฒŒ ์“ธ ์ˆ˜ ์žˆ๋Š” ๊ฐœ๋…๊ณผ ๋ฐฉ๋ฒ• ์ •๋„๋งŒ ๋‹ค๋ฃจ๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. Android์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๊ฐœ๋…๋„ ์กฐ๊ธˆ ๋‚˜์˜ค๊ธด ํ•˜๊ฒ ์ง€๋งŒ ์ตœ๋Œ€ํ•œ ๊ด€๋ จ์žˆ๋Š” ๋‚ด์šฉ๋งŒ ๋‹ค๋ฃจ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ์ค€๋น„๋˜์…จ๋‚˜์š”? Let’s go! Functional Programming์ด๋ž€ ๋ฌด์—‡์ด๊ณ , ..

[Android] Kotlin Delegates in Android: Android ๊ฐœ๋ฐœ์— Properties Delegate ํ™œ์šฉํ•˜๊ธฐ

์ž‘์„ฑ์ผ: 2019.12.02 ์›๋ฌธ Kotlin Delegates in Android: Utilizing the power of Delegated Properties in Android development์„ ๋ฒˆ์—ญํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. Delegate์— ๋Œ€ํ•œ ์„ค๋ช…๊ณผ ํ•จ๊ป˜ Android ๊ฐœ๋ฐœ์—์„œ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ์ฝ”๋“œ๋“ค์„ ์˜ˆ์ œ๋กœ ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•ด์ค๋‹ˆ๋‹ค. ์ค‘๋ณต๋˜๋Š” ์ฝ”๋“œ๋“ค์„ Delegate๋ฅผ ํ†ตํ•ด ๊ฐœ์„ ํ•ด๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™๋„ค์š” ๐Ÿ™‚ Kotlin์€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์— ๋„์›€์ด ๋˜๋Š” ๊ธฐ๋Šฅ์„ ๊ฐ€์ง„ ์•„์ฃผ ๋ฉ‹์ง„ ์–ธ์–ด์ž…๋‹ˆ๋‹ค. ๊ทธ ์ค‘ ํ•˜๋‚˜๊ฐ€ Delegate Propertis์ž…๋‹ˆ๋‹ค. ์ด ๊ธ€์—์„œ Delegate๊ฐ€ ์•ˆ๋“œ๋กœ์ด๋“œ ๊ฐœ๋ฐœ์— ์–ด๋–ค ๋„์›€์ด ๋˜๋Š”์ง€ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. Basics Fragment arguments SharedPreferences del..

[Android] Kotlin Extension Function์„ ์‚ฌ์šฉํ•˜์—ฌ ๋”๋ธ” ํด๋ฆญ ๋ฐฉ์ง€ํ•˜๊ธฐ

์ž‘์„ฑ์ผ: 2019.11.28 ์ฝ”ํ‹€๋ฆฐ ํ™•์žฅ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด View ๋”๋ธ” ํด๋ฆญ ๋ฐฉ์ง€๋ฅผ ์‰ฝ๊ฒŒ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ณดํ†ต ๋”๋ธ” ํด๋ฆญ ๋ฐฉ์ง€๋ฅผ ์œ„ํ•ด ํŠน์ • ์‹œ๊ฐ„์„ ์ •ํ•ด๋‘๊ณ  ํ•œ ๋ฒˆ ํด๋ฆญ ํ›„ ํ•ด๋‹น ์‹œ๊ฐ„ ์ด๋‚ด์˜ ํด๋ฆญ ์ด๋ฒคํŠธ๋Š” ๋ฌด์‹œํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ง์ ‘ ์ „์—ญ Util ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ RxBinding์˜ throttle์„ ์ด์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์Šต๋‹ˆ๋‹ค. Util ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์€ onClick()๋งˆ๋‹ค boilerplate๊ฐ€ ์ƒ๊ธฐ๊ฒŒ ๋˜๊ณ , ๊นœ๋นกํ•˜๊ณ  ์ถ”๊ฐ€๋ฅผ ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ๋„ ์ƒ๊ธฐ๊ธฐ ์‰ฝ์Šต๋‹ˆ๋‹ค. backButton.setOnClickListener { if (ExampleUtils.isDoubleClick()) return@setOnClickListener onBackPressed() } RxBinding ์‚ฌ์šฉ ๋˜ํ•œ ..

[Android] Jetpack - LiveData

์ž‘์„ฑ์ผ: 2019.07.01 LiveData๋ฅผ ํ”„๋กœ์ ํŠธ์— importํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ํ”„๋กœ์ ํŠธ์— ์ปดํฌ๋„ŒํŠธ ์ถ”๊ฐ€ํ•˜๊ธฐ ์ฐธ๊ณ  LiveData Observable Data Holder Class Lifecycle-aware Activity, Fragment, Service ๊ฐ™์€ ์•ฑ ์ปดํฌ๋„ŒํŠธ์˜ Lifecycle๊ณผ ์—ฐ๊ด€ ํ™œ์„ฑํ™”(active) ์ƒํƒœ(STARTED ๋˜๋Š” RESUMED)์ธ Observer์—๊ฒŒ๋งŒ ์—…๋ฐ์ดํŠธ๋ฅผ ์•Œ๋ฆผ LifecycleOwner์˜ Lifecycle์ด DESTROYED ์ƒํƒœ๊ฐ€ ๋˜๋ฉด Observer๋ฅผ ์ œ๊ฑฐ leak์— ๋Œ€ํ•œ ๊ฑฑ์ •์—†์ด ์•ˆ์ „ํ•˜๊ฒŒ LiveData๋ฅผ observe ๊ฐ€๋Šฅ Activity์™€ Fragment์—์„œ ํŠนํžˆ ์œ ์šฉ LiveData ์‚ฌ์šฉ๋ฒ•์— ๋Œ€ํ•œ ๋” ๋งŽ์€ ์ •๋ณด๋Š” Work with LiveData o..

[Android] 100% ์ดˆ๋ณด์ž๋ฅผ ์œ„ํ•œ RxJava(RxJava for 100% beginners)-part 1

์ž‘์„ฑ์ผ: 2018.03.07 ์ด ๊ธ€์€ ์›๋ฌธ์„ ๋ฒˆ์—ญํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. RxJava for 100% beginners(part 1) ์š”์ฆˆ์Œ ๋งŽ์€ Android ๊ฐœ๋ฐœ์ž๋“ค์ด “Reactive Programming/RxJava”์˜ ์กด์žฌ๋ฅผ ์ž˜ ์•Œ๊ณ  ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ตœ๊ทผ Android Weekly์—๋Š” ๋งค ์ฃผ RxJava์™€ ๊ด€๋ จ๋œ ๋ธ”๋กœ๊ทธ ํฌ์ŠคํŠธ๊ฐ€ ํ•ญ์ƒ ์žˆ๊ธฐ๋„ ํ–ˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ, RxJava์˜ ๋ฌธ๋ฒ•์— ์‚ฌ์šฉ๋œ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ์— ๋Œ€ํ•ด ์ž˜ ๋ชจ๋ฅด๋Š” ์ดˆ๋ณด์ž์—๊ฒŒ๋Š” ์กฐ๊ธˆ ์–ด๋ ค์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Scala์—์„œ๋Š”, RxJava์˜ map(), filter(), flatmap() ๋“ฑ๊ณผ ์œ ์‚ฌํ•œ ์˜คํผ๋ ˆ์ดํ„ฐ๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ด์ „์— Scalar๋‚˜ (RxJava๊ฐ€ ๊ฐœ๋…๊ณผ ๋ฌธ๋ฒ•์„ ์ฐจ์šฉํ•œ) ๋‹ค๋ฅธ ํ•จ์ˆ˜ํ˜• ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•ด๋ดค๋‹ค๋ฉด, ์•„์˜ˆ ์จ๋ณด์ง€ ์•Š..

[Android] ๋ ˆ์ด์•„์›ƒ ๊ณ„์ธต ์„ฑ๋Šฅ ์ตœ์ ํ™”(Optimizing Layout Hierarchies)

์ž‘์„ฑ์ผ: 2018.03.07 ์›๋ฌธ: Optimizing Layout Hierarchies์„ ๋ฒˆ์—ญํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค. ๋ฒ ์ด์ง ๋ ˆ์ด์•„์›ƒ ๊ตฌ์กฐ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๊ฐ€์žฅ ํšจ๊ณผ์ ์ธ ๋ ˆ์ด์•„์›ƒ์ด ๋œ๋‹ค๋Š” ๊ฒƒ์€ ํ”ํ•œ ์˜คํ•ด์ž…๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜, ๋‹น์‹ ์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ถ”๊ฐ€ํ•œ ๊ฐ ์œ„์ ฏ๊ณผ ๋ ˆ์ด์•„์›ƒ์€ ์ดˆ๊ธฐํ™”, ๋ฐฐ์น˜, ๊ทธ๋ ค์ง€๋Š” ๊ณผ์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ค‘์ฒฉ๋œ LinearLayout์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์€ ์ง€๋‚˜์น˜๊ฒŒ ๊นŠ์€ ๋ทฐ ๊ณ„์ธต์„ ์ดˆ๋ž˜ํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฒŒ๋‹ค๊ฐ€, layout_weight๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ช‡ ๊ฐœ์˜ LinearLayout์„ ์ค‘์ฒฉํ•˜๋Š” ๊ฒƒ์€ ๊ฐ child๊ฐ€ ํ•œ๋ฒˆ ๋” ์ธก์ •๋˜๊ธฐ ๋•Œ๋ฌธ์— ํŠนํžˆ ๋น„์šฉ์ด ๋†’์Šต๋‹ˆ๋‹ค. ListView๋‚˜ GridView๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ์ฒ˜๋Ÿผ inflate๊ฐ€ ๋ฐ˜๋ณต๋˜๋Š” ๊ฒฝ์šฐ ํŠนํžˆ ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ธ€์„ ํ†ตํ•ด ๋ ˆ์ด์•„์›ƒ์„ ๊ฒ€ํ† ํ•˜๊ณ  ์ตœ์ ํ™”ํ•˜๊ธฐ..

[Design Pattern] Strategy Pattern

์ž‘์„ฑ์ผ: 2018.01.22 Strategy pattern ์ผ๋ช…, ์ „๋žตํŒจํ„ด ๋ชฉ์  ๊ฐ๊ฐ์„ ์บก์Šํ™”ํ•˜์—ฌ ๋ณ€ํ™” ๊ฐ€๋Šฅํ•˜๊ฒŒ ๋งŒ๋“  ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ์ง‘ํ•ฉ์„ ์ •์˜ํ•œ๋‹ค. ์ธํ„ฐํŽ˜์ด์Šค์— ์ถ”์ƒ ๋ฉ”์†Œ๋“œ๋ฅผ ์ •์˜ํ•˜๊ณ , ์ž์„ธํ•œ ๊ตฌํ˜„์€ ํŒŒ์ƒ๋œ ํด๋ž˜์Šค์— ํ•œ๋‹ค. Strategy ํŒจํ„ด์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ๊ทธ๊ฒƒ์„ ์‚ฌ์šฉํ•˜๋Š” ํด๋ผ์ด์–ธํŠธ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ๋ณ€ํ™”ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ค€๋‹ค. โž” OCP OCP(Open-Closed Principle;๊ฐœ๋ฐฉ ํ์‡„ ์›์น™) ํ™•์žฅ์—๋Š” ์—ด๋ ค์žˆ๊ณ , ์ˆ˜์ •์—๋Š” ๋‹ซํ˜€ ์žˆ์–ด์•ผ ํ•œ๋‹ค๋Š” ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ํ•ต์‹ฌ ์›์น™ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ ํด๋ผ์ด์–ธํŠธ๋Š” ๋ณ€ํ™”์™€ ๊ด€๋ จํ•ด์„œ ์‹ ๊ฒฝ์“ฐ์ง€ ์•Š์•„์•ผ ํ•œ๋‹ค. โž” ํŒŒ์ƒ๋œ ํด๋ž˜์Šค ์ˆ˜๊ฐ€ ๋ณ€ํ–ˆ์„ ๊ฒฝ์šฐ, ํŒŒ์ƒ๋œ ํด๋ž˜์Šค์˜ ๊ตฌํ˜„์ด ๋ฐ”๋€Œ์—ˆ์„ ๊ฒฝ์šฐ์— ๋Œ€ํ•œ ์˜ํ–ฅ์ด ์—†์–ด์•ผ ํ•œ๋‹ค. ๊ตฌ์กฐ 2๊ฐ€์ง€ ๊ตฌํ˜„ ๋ฐฉ๋ฒ• Abstract base class..

[Android] Bitmap์— ์ƒ‰์ƒ ์ž…ํžˆ๊ธฐ

์ž‘์„ฑ์ผ: 2017.12.10 ๋น„ํŠธ๋งต์— ์ƒ‰์ƒ์„ ๋ฎ์–ด ์”Œ์šฐ๋Š” ๋ฐฉ๋ฒ• -> ๊ฐ™์€ ์ด๋ฏธ์ง€๋ฅผ ์—ฌ๋Ÿฌ ์ƒ‰์œผ๋กœ ์‚ฌ์šฉํ•ด์•ผ ํ•  ๋•Œ ์œ ์šฉํ•˜๋‹ค. ์˜ˆ์‹œ๋Š”, ํฐ์ƒ‰ ์•„์ด์ฝ˜์„ ๋‹ค๋ฅธ ์ƒ‰์œผ๋กœ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ. (์•„์ด์ฝ˜์ด ํฐ์ƒ‰์ด๋ผ ์ž„์‹œ๋กœ ๋ฐฐ๊ฒฝ์ƒ‰์„ ์คŒ.) //1. Drawable -> Bitmap Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.email_xxl).copy(Bitmap.Config.ARGB_8888, true); //2. ColorFilter ๋งŒ๋“ค๊ธฐ Paint paint = new Paint(); ColorFilter colorFilter = new PorterDuffColorFilter(Color.DKGRAY, PorterDuff.Mode.SRC..