- xml RemoteViews 방식의 위젯 구성 중에 컴포넌트를 통해 구분선을 만들려고 하는데, 빌드하고 나니 '위젯을 표시할 수 없습니다'라는 오류가 발생했다. - 이것은 같은 ViewGroup 계층이어도 RemoteViews에서 지원 가능한 View 종류가 한정되어 있기 때문이다. A class that describes a view hierarchy that can be displayed in another process. The hierarchy is inflated from a layout resource file, and this class provides some basic operations for modifying the content of the inflated hierarchy.R..
Android
- 기존의 RemoteViews XML 기반 위젯에서는 PendingIntent를 통해 Activity를 열었다. - 하지만 Glance에서는 actionStartActivity() 함수를 사용한다.fun actionStartActivity( intent: Intent, parameters: ActionParameters = actionParametersOf(),): Action = StartActivityIntentAction(intent, parameters, null)- Glance 위젯에서 특정 Activity를 시작하기 위한 Action 객체를 생성하는 함수다. - 즉, Glance의 Modifier.clickable 안에서 사용할 수 있는 동작(Action)을 만들어서 연결해 준다..
- Glance에서는 일반 Compose와는 다르게 Glance 전용 패키지로 UI 구성 요소를 제공한다.import androidx.glance.GlanceIdimport androidx.glance.GlanceModifierimport androidx.glance.Imageimport androidx.glance.ImageProviderimport androidx.glance.LocalContextimport androidx.glance.action.Actionimport androidx.glance.action.clickableimport androidx.glance.appwidget.GlanceAppWidgetimport androidx.glance.appwidget.GlanceAppWidgetM..

- 자사 서비스에서 신규 위젯을 추가하기로 했는데, 기존의 RemoteViews 방식이 아닌 Compose Glance 기반으로 위젯 구현을 진행해 봤다. - RemoteViews의 경우에는 XML 레이아웃을 조작해서 화면에 표시하는 방식이다. 클릭 이벤트는 PendingIntent로 처리 - Glance의 경우에는 Compose 기반인데, 백그라운드에서는 RemoteViews 기반이지만 개발자가 직접 코드로 다룰 필요가 없음. 가독성도 좋고 onClick 처리도 GlanceModifier를 통해 간단하지만 역시 위젯 특유의 제한 사항은 존재한다. - 먼저 아래 설정을 Gradle에 추가해 준다.implementation("androidx.glance:glance:1.1.1")implementation(..
- 지정된 Ratio 조건을 가지는 둥근 테두리 모양의 이미지 렌더링 컴포넌트를 작업했다. - Ratio는 가로 세로 비율인데, 디자인 가이드에 1:2, 16:9 형식처럼 디자이너분이 지정을 해주셨고, 그에 따라 Enum Class로 정리했다.enum class CustomRatio(val width: Int, val height: Int, ...) { RATIO_1_1(1, 1, ...), RATIO_4_5(4, 5, ...), ... - 그리고 Float 타입으로 Ratio 값을 구하는 공식 함수도 선언해 준다.val value: Float get() = width.toFloat() / height - 둥근 테두리 구성을 위해 Modifier의 border를 사용했다. width..

- 안드로이드 테스트 코드 작성에 대한 각종 내용을 기록하는 말머리 [Android Test] - 아래와 같이 원주율을 활용한 계산 Class가 있다.class MyCalc : Calculations { private val pi = 3.14 override fun calculateCircumference(redius: Double): Double { return 2 * pi * redius } override fun calculateArea(redius: Double): Double { return pi * redius * redius }} - JUnit4 기반 test 코드를 작성해 본다. - 먼저 클래스명에서 오른쪽 마우스 - 생성 - 테스트를 통..

- 얼마 전에 리플 효과를 적용시킨 FAB 버튼을 구현했었다.- 리플 내부에는 클릭 상태를 감지하는 interactionSource를 포함하고 있다. 이를 통해 리플뿐만 아니라 버튼 자체의 스케일이 변하는 애니메이션까지 추가해 보겠다.interactionSource = interactionSource,indication = rememberRipple( color = colorResource(R.color.color_system_label_default_light).copy(alpha = 0.16f), bounded = true),onClick = onClick - 먼저 아래 값들을 선언해 준다. 모두 pressed 상태를 감지하기 위한 요소이다.val interactionSource = rem..
- 기존에 아래와 같이 메모 데이터를 저장하는 테이블이 있다.@Entity(tableName = "save_model")data class Memo( @PrimaryKey(autoGenerate = true) val id: Int = 0, var title: String, var detail: String, val dtCreated: Long, var dtUpdated: Long, var color: String)- 링크 데이터를 추가하기 위해 String 타입 필드를 추가하려고 한다. @Entity(tableName = "save_model")data class Memo( @PrimaryKey(autoGenerate = true) val id: Int = 0, ..
- 기존의 XML 화면에서 Compose 기반 컴포넌트 활용을 위해 ComposeView를 사용하고 있었다. - 그리고 인앱 지정 컬러를 변경할 때마다 ComposeView에 걸린 컴포저블의 tint도 변경을 해줘야 했는데, 프로퍼티로 들어가는 속성 값은 변경되지만 실제 컴포저블 set 로직까지는 진입이 안 되는 것을 확인했다.mainAddBtn.setContent { TbFloatingActionButton( androidx.compose.ui.graphics.Color(AppColor()), ... - 이유는 setContent {} 자체가 최초 한 번만 컴포지션을 설정하도록 구성되어 있는 것이다. 따라서 이미 컴포지션이 설정된 ComposeView에 대해서는 발동하지 ..
- 보통 버튼이나 FAB 클릭하면 명암이 짙어지는 Ripple 효과가 발생하는 것을 볼 수 있다. - 이번엔 Text를 가진 상위 컴포저블로부터 onClick 이벤트를 받아 하위 Text의 굵기를 변경하는 작업을 진행했다. - 일단 아래 두 개 값이 pressed 상태를 경신하고 체크하는 기본 요소가 된다.val interactionSource = remember { MutableInteractionSource() }val isPressed by interactionSource.collectIsPressedAsState() - MutableInteractionSource : InteractionSource는 컴포넌트에서 발생하는 사용자 상호작용을 감지하는 채널로서 Pressed, Focused, Drag..