ScreenNameViewer는 현재 표시 중인 화면의 클래스명을 오버레이로 보여주는 디버깅 도구입니다.
어떤 화면이 활성화되어 있는지 직관적으로 확인할 수 있으며, Compose 환경에서는 Screen Route까지 함께 표시할 수 있습니다.
이를 통해 원하는 화면의 코드를 빠르게 찾아 접근할 수 있어 디버깅과 개발 효율을 높여줍니다.
- 실시간 클래스명 표시: Activity와 Fragment 클래스명을 화면에 실시간 표시
- 자동 생명주기 관리: Application 레벨에서 모든 Activity와 Fragment를 자동으로 추적
- 디버그 전용: Release 빌드에서는 자동으로 비활성화되어 안전
- UI 커스터마이징: 텍스트 크기, 색상, 위치 등 자유롭게 설정 가능
- 메모리 안전: WeakReference 사용으로 메모리 누수 방지
- 터치 상호작용: 오버레이 터치 시 Toast로 전체 클래스명 표시
모듈의 build.gradle.kts에 라이브러리를 추가하세요:
dependencies {
debugImplementation("io.github.dongx0915:screennameviewer-compose:{latestVersion}")
releaseImplementation("io.github.dongx0915:screennameviewer-compose-noop:{latestVersion}")
}- Android API 21 (Android 5.0) 이상
한 번만 설정하면 모든 Activity와 Fragment가 자동으로 추적됩니다:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
initScreenNameViewer(this) {
settings {
debugModeCondition = BuildConfig.DEBUG
enableCondition = PreferenceManager
.getDefaultSharedPreferences(this@MyApplication)
.getBoolean("debug_overlay_enabled", true)
}
config {
textStyle {
size = 12f
color = Color.WHITE
}
background {
color = Color.argb(128, 0, 0, 0)
padding = 16
}
position {
topMargin = 64
activity = Gravity.TOP or Gravity.START
fragment = Gravity.TOP or Gravity.END
composeRoute = Gravity.TOP or Gravity.END
}
}
}
}
} ScreenNameTracker(navController) {
NavHost() { /*...*/ }
}간단한 DSL(Domain Specific Language)을 사용하여 라이브러리를 설정할 수 있습니다:
initScreenNameViewer(this) {
settings {
debugModeCondition = BuildConfig.DEBUG
enableCondition = PreferenceManager
.getDefaultSharedPreferences(this@MyApplication)
.getBoolean("debug_overlay_enabled", true)
}
config {
textStyle {
size = 12f // Text size
color = Color.WHITE // Text color
}
background {
color = Color.argb(128, 0, 0, 0) // Background color
padding = 16 // Padding
}
position {
topMargin = 64 // Top margin
activity = Gravity.TOP or Gravity.START // Activity display position
fragment = Gravity.TOP or Gravity.END // Fragment display position
composeRoute = Gravity.TOP or Gravity.END // Compose Route display position
}
}
}-
settings: 활성화 조건 설정
debugModeCondition: 디버그 모드 조건enableCondition: 오버레이 기능 활성화 조건
-
config: 오버레이 모양 커스터마이징
textStyle: 텍스트 크기와 색상background: 배경색과 패딩position: 여백과 각 컴포넌트의 표시 위치
|
Donghyeon Kim |
JUNWON LEE |
