목록분류 전체보기 (134)
Foggy day
private fun setViewPager2Height(){ viewPager2.setPageTransformer { page, position -> updatePagerHeightForChild(page, viewPager2) } } private fun updatePagerHeightForChild(view: View, pager: ViewPager2) { view.post { val wMeasureSpec = View.MeasureSpec.makeMeasureSpec(view.width, View.MeasureSpec.EXACTLY) val hMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) view.me..
코루틴의 순차적, 동시적 작업들을 컨트롤 할 수 있게 해주는 것이 Defferd 객체인데 이는 JOB을 상속받았다. 1. 코루틴 순차적 실행 class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) //코루틴은 비동기일지라도 순차적으로 실행된다. //예를 들어 firstFunction과 secondFunction 함수가 retrofit 호출일지라도 //먼저 실행한 firstFunction 함수의 콜백이 도달해서 완전..
runBlocking { // Dispatchers.Default 는 코루틴이 GlobalScope 에서 실행될 경우에 // 사용되며 공통으로 사용되는 백그라운드 스레드 풀을 이용합니다. // 즉, launch(Dispatchers.Default) {…} 와 GlobalScope.launch {…} 는 // 동일한 디스패처를 사용합니다. //코루틴을 cancel시키기 위해서는 suspend function call 이 필요함 //yield와 delay()가 suspend function 역할을 함 val startTime = System.currentTimeMillis() val job = launch(Dispatchers.Default) { try { var nextPrintTime = startTim..
class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) introduce() hungry.start() age() //GlobalScope.launch는 thread와 비슷한 기능 // launch는 코루틴의 빌더이며 빌더를 사용하기 위해서는 scope가 필요하다 // GlobalScope는 scope중의 하나 //delay는 suspend 함수로 일시중단같은 개념, suspend 함수는 scope 안에서거나 백그..
class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val human = Human("Man", 30, "jerome") val (sex, age, name) = human println("sex : $sex, age : $age, name : $name") ///// sex : Man, age : 30, name : jerome ////// } } data class Human( val sex: String,..
val value = object { val x = 0 val y = 10 val z = 20 } println("value x : ${value.x}, y : ${value.y}, z : ${value.z}") //// value x : 0, y : 10, z : 20 val school: School = object : School(3), ClassGroup { override val students: Int get() = super.students override fun OnJoinClassGroup(classNumber: Int) { super.OnJoinClassGroup(3) } } println("school.students ${school.students}") //// school.stud..
val list = listOf(3, 4, 5, 6, 7, 8, 9, 10) val value = 12 val result = when (value) { in list -> "value is in the list" in 1..10 -> "It is in the range A" in 10..20 -> "It is in the range B" else -> "none fo the above" } println("result : $result") //result : It is in the range B val array = arrayOf("A", "B", "C", "D") for (i in array.indices) { println("i : ${array[i]}") } // A, B, C, D for ((i..
when you use a animation in a fragment transaction, screen would flicker. It is caused because of animation drawable. If you use animation drawable like below, obviously flickering occurs slide_in_right.xml The cause is set. Remove
val intSrc = Observable.just(1, 2, 3) intSrc.subscribe(::println) val strSrc = intSrc.map { value -> value * 10 } strSrc.subscribe(::println) val src = Observable.just("A", "B", "C", "D") src.flatMap { s -> Observable.just(s + 2, s + 3) } src.subscribe(::println) val flatMap = Observable.range(2, 3).flatMap { x -> Observable.range(1, 9).map { y -> String.format("%d*%d=%d", x, y, x * y) } } flatM..
val source = Observable.create { emitter: ObservableEmitter? -> emitter?.onNext("Hello") emitter?.onNext("android") emitter?.onComplete() }.subscribe(::println) // source.subscribe(::println) val source = Observable.just("Hello", "android") source.subscribe(::println) val stringList = listOf("A", "B", "C") val source = Observable.fromArray(stringList) source.subscribe(::println) val stringArrayL..