안드로이드 40

안드로이드 PIP 모드 커스텀 버튼 추가

안드로이드 PIP 모드에서 커스텀 버튼을 추가하는 방법 1. PendingIntent.getActivity 를 이용해 onNewIntent 에서 action 에 대해 기능 정의 방법 예제 코드private fun enterPipModeWithActions() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val aspectRatio = Rational(16, 9) // PIP 모드에서 사용할 액션 버튼 정의 val intent = Intent(this, PipActivity::class.java).apply { action = "ACTION_DO_SOME..

안드로이드 PIP 모드 설정

안드로이드에서 Picture-In-Picture 모드로 현재 화면과 독립적으로 움직일 수 있는 Activity 를 띄울 수 있습니다.코드 중심으로 설명을 하겠습니다.1. PIP 모드를 사용할 Activity 클래스 생성package im.metrex.oa.features.sendbirdimport android.app.PictureInPictureParamsimport android.content.res.Configurationimport android.net.Uriimport android.os.Bundleimport android.util.Rationalimport androidx.activity.ComponentActivityimport androidx.activity.OnBackPressedCal..

[Chapter 6] CoroutineContext

CoroutineContext 란?코루틴을 실행하는 실행 환경을 설정하고 관리하는 인터페이스이다.CoroutineName, CoroutineDispatcher, Job, CoroutineExceptionHandler 를 조합해 코루틴의 실행 환경을 설정한다. 1. CoroutineContext 구성 키값CoroutineName 키CoroutineName 객체CoroutineDispatcher 키CoroutineDispatcher 객체Job 키Job 객체CoroutineExceptionHandler 키CoroutineExceptionHandler 객체 각 구성요소는 고유한 키를 가지며, 키에 대해 중복된 값은 허용되지 않는다. 코드 예제)import kotlinx.coroutines.*import kotl..

[Chapter 5] async와 Deferred

launch 코루틴 빌더를 통해 생성되는 코루틴은 기본적으로 작업 실행 후 결과를 반환하지 않는다. 하지만 우리가 코루틴을 다룰 때는 코루틴으로부터 결과를 수신해야 하는 경우가 빈번하다!비동기 작업으로부터 결과를 수신해야 하는 경우를 위해 async 코루틴 빌더를 통해 코루틴으로부터 결과값을 수신받을 수 있다.launch 를 사용하면 결과값이 없는 Job 객체가 반환되는 것과 다르게 async 함수를 사용하면 결과값이 있는 Deferred 객체가 반환이 된다!1. async 를 사용해 Deferred 만들기 (await 를 사용해 결과값을 수신 해보기)예시 코드를 보자import kotlinx.coroutines.*fun main() = runBlocking { val networkDeferred: D..

Closure(클로저)

정의람다를 실행 시점에 표현하는 데이터 구조는 람다에서 시작하는 모든 참조가 포함된 닫힌(closed) 객체 그래프를 람다 코드와 함께 저장해야 한다.그런 데이터 구조를 클로저(closure)라고 부른다.(출처: Kotlin in Action) 정의를 보고 무슨말인가 싶은데 아래 코드를 보자.fun View.throttleClick( interval: Long = 1500L, onClick: () -> Unit) { var lastClickTime = 0L // 로컬 변수 this.setOnClickListener { val currentTime = SystemClock.elapsedRealtime() if (currentTime - lastClickTime..

삐져나오는 이미지 영역을 감싸는 방법

예시로 위와 같은 이미지 위로 투명도가 있는 액체이미지를 넣으려고 합니다. 하지만 액체 이미지는 radius 가 없어서 담기는게 아닌 삐져나오게 됩니다. ex.)   그래서 어떻게 하면 저 이미지 안으로 액체 이미지를 넣을 수 있을까 고민을 했습니다. 1. 해당 이미지를 ViewGroup 으로 감싸서 나오지 않게 해봤지만 결론적으로 ViewGroup 의 width 나 height 를 결국 저 사이즈에 맞게 늘리면 삐져 나오는건 마찬가지였습니다.  2. ViewGroup 으로 감싸되 CardView 를 사용하면 가능했습니다.  CardView 를 부모뷰로 감싸면 이미지와 같이 그 영역 만큼 이미지가 잘려서 들어갈 수 있습니다.  코드   주의할점!CardView는 기본적으..

상단 StatusBar 색상 및 상단 아이콘 light, dark 설정

Compose 에서는 상단 StatusBar 색상을 변경하기 위해서 3가지 정도의 방법이 있습니다.  1. accompanist 라이브러리 활용 (현재 deprecated 됨.) @Composableprivate fun setBarColors() { val systemUiController = rememberSystemUiController() val useDarkIcons = !isSystemInDarkTheme() val statusBarLight = Color.Green val statusBarDark = Color.Blue val navigationBarLight = Color.Green val navigationBarDark = Color.Blue Dispo..

AppBarLayout 과 CollapsingToolBarLayout 의 상속 구조

먼저 해당 내용의 글을 쓰게 된 이유는 Coordinatorlayout 과 AppBarLayout 및 CollapsingToolBarLayout 을 개발할 때AppBarLayout 의 자식 View 들의 레이아웃 배치 와 CoolapsingToolBarLayout 의 자식 View 들의 레이아웃 배치 가 어떤식으로 되는지 찾아보게 되면서 다르다는 것을 알게 되었고 포스팅을 하게 됐다. 1. AppBarLayout  공식문서 내용에서 확인할 수 있듯이 LinearLayout 을 상속 받은 구조이다. 그러므로 자식 View 의 배치와 관련해서는 LinearLayout 과 똑같이 된다고 볼 수 있다.  2. CollapsingToolBarLayout   CollapsingToolBarLayout 같은 경우는 ..

build-logic rebuild project 시 에러 관련

이구아나 버전으로 업데이트를 하고 clean project 후 rebuild project 를 했는데 오류가 발생했습니다. Unable to make progress running work. There are items queued for execution but none of them can be started. 해당 이슈는 buildSrc 또는 build-logic 을 적용한 프로젝트에서 발생할 수 있다고 합니다. 이와 관련하여 Gradle 팀이 적극적으로 솔루션을 개발하면서 문제가 해결될 예정입니다. 일단 이미지에서 문제가 되는 build-logic:convention:testClasses 에 대해서 gradle 에서 excludedTask 하는 방식으로 해결을 할 수 있었습니다. root proj..

Version Catalog 도입기 (3)

이제 마지막으로 Convention 모듈을 만들어 커스텀 플러그인 설정을 하는 방법을 설명 하겠습니다. 예를 들어 모듈별로 필요한 플러그인 들을 여러개 추가 할 때 마다 build.gradle에 중복 코드가 많아지는데 커스텀 플러그인 을 통해서 효과적으로 관리를 할 수 있게 됩니다. 1. build-logic 모듈을 생성하고 settings.gradle.kts 만 남겨 놓습니다. 2. build-logic 모듈 안에 convention 모듈을 생성 합니다. 3. root 디렉토리의 setting.gradle 에서 build-logic , convention 모듈을 지웁니다. pluginManagement { includeBuild("build-logic") // 필수 repositories { googl..

안드로이드 2024.03.30