본문 바로가기

728x90
반응형

Android

(80)
[Java/kotlin] Hex String의 Int 변환 16bit Hex String to Signed Int java int i = (short) Integer.parseInt("FFFF", 16); kotlin val i: Short = Integer.parseInt("FFFF",16).toShort() 16bit Hex String to Unsigned Int java int i = Integer.parseUnsignedInt("FFFF", 16); kotlin val i = "FFFF".toLong(16) 32bit Hex String to Signed Int java int x = (int)Long.parseLong("FFFFFFFC", 16); // x = -4 kotlin val x = "FFFFFFFC".toLong(16).toInt() // ..
[안드로이드] RxJava Flowable 알아보기 (위키 번역) Flowable (RxJava Javadoc 2.2.21) Returns a Flowable that emits the results of a specified combiner function applied to combinations of five items emitted, in sequence, by five other Publishers. zip applies this function in strict sequence, so the first item emitted by the new Publisher wi reactivex.io Flowable class는 팩토리 메서드와 중간 오퍼레이터, reactive dataflow를 소비할 수 있는 기능을 제공하고, Reactive Stream패턴을 구현한..
[안드로이드] Koin으로 주입된 viewModel 쉽게 Unit 테스트 하기 dependency 추가 기본으로 추가되어있는 dependency 외에 mockito, truth를 추가하였습니다. dependencies { implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.3.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1..
[안드로이드] Cold flows, Hot channels(번역) Cold flows, Hot channels Cold flows, hot channels Kotlin coroutines were missing a primitive to represent cold asynchronous streams of data. Not anymore. Welcome Kotlin Flows. elizarov.medium.com 비동기식, 장기 또는 원격 작업들은 future type을 통해 표현될 수 있으므로, 값을 반환하는 함수는 다음과 같이 구현될 수 있습니다. fun fooAsync(p: Params): CompletableFuture = CompletableFuture.supplyAsync { bar(p) } fooAsync(p)를 호출하면 미래에 값을 제공하겠다는 약속을 가..
[안드로이드] (둥근/사각) 테두리 있는 ImageView 간단히 만들기 안드로이드에서 이미지를 테두리안에 집어넣고 싶을 때가 있는데요. 구현해 보았습니다. 먼저 drawable폴더에 (둥근 테두리)round_backgroud_border_black 혹은 (사각 테두리)square_background_border_black 파일을 추가하겠습니다. 하얀 바탕에 검은색 테두리로 하였습니다. 둥근 테두리 사각 테두리 파일을 만들었으면, 이미지뷰를 수정합니다. 사각 테두리 사각테두리의 경우 ImageView layout에 background 설정을하고, padding을 약간 집어넣어주면 됩니다. 둥근 테두리 ImageView.setClipToOutline(true) 를 이용합니다. setClipToOutline을 이용하면 이미지를 배경에 맞게 자를 수 있습니다. 다만, 테두리가 보이..
[안드로이드] 특정/모든 Fragment backstack에서 제거 supportFragmentManager.beginTransaction().apply { replace(R.id.container, calibrationFragment) addToBackStack("calibration") commit() } 위와 같이 "calibration" 이란 이름을 지정하여 backstack에 추가한 후, fragment를 교체할 수 있습니다. 만약 backstack에 위 이름의 fragment만 지워주고 싶다면, 다음과 같이 사용하면 됩니다. supportFragmentManager.popBackStack("calibration", FragmentManager.POP_BACK_STACK_INCLUSIVE) 만약 모든 backstack을 제거하고 싶다면, 다음과 같이 사용합니다...
[안드로이드] Fragment 안의 Fragment 처리(교체, 백스택, Back 버튼 클릭 등) ― parentFragmentManager vs childFragmentManager Fragment안에 Fragment를 추가하여 더 관리할 경우가 생기는데요, 예를들어 ViewPager나 TabLayout의 Fragmet중 하나에서 Fragment를 여러개 교체하거나 관리할 수 있습니다. MainActivity에 Fragment1과 Fragment2가 있고, Fragment1 에서 ChildFrag1. ChildFrag2, ChildFrag3 을 추가하거나 교체한다고 생각해보겠습니다. MainActivity > Fragment1, Fragment2 Fragment1 > ChildFrag1,ChildFrag2,ChildFrag3 Fragment 추가/교체 MainActivity에 Fragment1을 추가 val fragment1 = Fragment1().getInstance() supp..
[안드로이드] MediatorLiveData를 이용하여 여러개의 LiveData를 하나의 LiveData로 합치기 Next 버튼의 활성화/비활성화를 LiveData로 만들고 싶은데, 이에 영향을 주는 LiveData가 2개 이상입니다. MediatorLiveData를 사용하면 여러개의 LiveData를 다시 mapping할 수 있습니다. 저는 무려 4개였습니다 ..ㅎㅎ class MyViewModel(private val repository: Repository): ViewModel() { val emg1Connected: LiveData = repository.deviceEmg1.connected val emg2Connected: LiveData = repository.deviceEmg2.connected val emg1Calibrated: LiveData = repository.deviceEmg1.calibrat..

728x90
반응형