--- app/build.gradle.kts
+++ app/build.gradle.kts
... | ... | @@ -38,12 +38,16 @@ |
| 38 | 38 |
dependencies {
|
| 39 | 39 |
implementation(platform(libs.androidx.compose.bom)) |
| 40 | 40 |
implementation(libs.androidx.activity.compose) |
| 41 |
+ implementation(libs.androidx.compose.animation) |
|
| 42 |
+ implementation(libs.androidx.compose.animation.core) |
|
| 41 | 43 |
implementation(libs.androidx.compose.material3) |
| 42 | 44 |
implementation(libs.androidx.compose.ui) |
| 43 | 45 |
implementation(libs.androidx.compose.ui.graphics) |
| 44 | 46 |
implementation(libs.androidx.compose.ui.tooling.preview) |
| 45 | 47 |
implementation(libs.androidx.core.ktx) |
| 46 | 48 |
implementation(libs.androidx.lifecycle.runtime.ktx) |
| 49 |
+ implementation("io.coil-kt:coil-compose:2.6.0")
|
|
| 50 |
+ implementation("androidx.exifinterface:exifinterface:1.3.7")
|
|
| 47 | 51 |
testImplementation(libs.junit) |
| 48 | 52 |
androidTestImplementation(platform(libs.androidx.compose.bom)) |
| 49 | 53 |
androidTestImplementation(libs.androidx.compose.ui.test.junit4) |
--- app/src/main/java/kr/co/app4ad/photoslide/MainActivity.kt
+++ app/src/main/java/kr/co/app4ad/photoslide/MainActivity.kt
... | ... | @@ -1,21 +1,53 @@ |
| 1 | 1 |
package kr.co.app4ad.photoslide |
| 2 | 2 |
|
| 3 |
+import android.content.Context |
|
| 4 |
+import android.net.Uri |
|
| 3 | 5 |
import android.os.Bundle |
| 6 |
+import android.util.Log |
|
| 4 | 7 |
import androidx.activity.ComponentActivity |
| 8 |
+import androidx.activity.compose.rememberLauncherForActivityResult |
|
| 5 | 9 |
import androidx.activity.compose.setContent |
| 6 | 10 |
import androidx.activity.enableEdgeToEdge |
| 11 |
+import androidx.activity.result.PickVisualMediaRequest |
|
| 12 |
+import androidx.activity.result.contract.ActivityResultContracts |
|
| 13 |
+import androidx.compose.animation.Crossfade |
|
| 14 |
+import androidx.compose.animation.core.Animatable |
|
| 15 |
+import androidx.compose.animation.core.LinearEasing |
|
| 16 |
+import androidx.compose.animation.core.tween |
|
| 7 | 17 |
import androidx.compose.foundation.Image |
| 18 |
+import androidx.compose.foundation.background |
|
| 19 |
+import androidx.compose.foundation.layout.Arrangement |
|
| 8 | 20 |
import androidx.compose.foundation.layout.Box |
| 21 |
+import androidx.compose.foundation.layout.BoxWithConstraints |
|
| 22 |
+import androidx.compose.foundation.layout.Column |
|
| 23 |
+import androidx.compose.foundation.layout.Row |
|
| 9 | 24 |
import androidx.compose.foundation.layout.fillMaxSize |
| 25 |
+import androidx.compose.foundation.layout.fillMaxWidth |
|
| 26 |
+import androidx.compose.foundation.layout.height |
|
| 27 |
+import androidx.compose.foundation.layout.padding |
|
| 28 |
+import androidx.compose.material3.Button |
|
| 29 |
+import androidx.compose.material3.LinearProgressIndicator |
|
| 10 | 30 |
import androidx.compose.material3.Surface |
| 11 | 31 |
import androidx.compose.material3.Text |
| 12 | 32 |
import androidx.compose.runtime.Composable |
| 33 |
+import androidx.compose.runtime.LaunchedEffect |
|
| 34 |
+import androidx.compose.runtime.getValue |
|
| 35 |
+import androidx.compose.runtime.mutableIntStateOf |
|
| 36 |
+import androidx.compose.runtime.mutableStateOf |
|
| 37 |
+import androidx.compose.runtime.remember |
|
| 38 |
+import androidx.compose.runtime.setValue |
|
| 13 | 39 |
import androidx.compose.ui.Alignment |
| 14 | 40 |
import androidx.compose.ui.Modifier |
| 41 |
+import androidx.compose.ui.draw.rotate |
|
| 15 | 42 |
import androidx.compose.ui.graphics.Color |
| 16 | 43 |
import androidx.compose.ui.layout.ContentScale |
| 17 |
-import androidx.compose.ui.res.painterResource |
|
| 18 |
-import androidx.compose.ui.tooling.preview.Preview |
|
| 44 |
+import androidx.compose.ui.platform.LocalContext |
|
| 45 |
+import androidx.compose.ui.unit.Dp |
|
| 46 |
+import androidx.compose.ui.unit.dp |
|
| 47 |
+import androidx.compose.ui.unit.sp |
|
| 48 |
+import androidx.exifinterface.media.ExifInterface |
|
| 49 |
+import coil.compose.rememberAsyncImagePainter |
|
| 50 |
+import coil.request.ImageRequest |
|
| 19 | 51 |
import kr.co.app4ad.photoslide.ui.theme.PhotoSlideTheme |
| 20 | 52 |
|
| 21 | 53 |
class MainActivity : ComponentActivity() {
|
... | ... | @@ -24,45 +56,283 @@ |
| 24 | 56 |
enableEdgeToEdge() |
| 25 | 57 |
setContent {
|
| 26 | 58 |
PhotoSlideTheme {
|
| 27 |
- Surface(modifier = Modifier.fillMaxSize(), color = Color.Black) {
|
|
| 28 |
- Box( |
|
| 29 |
- modifier = Modifier.fillMaxSize(), |
|
| 30 |
- contentAlignment = Alignment.Center |
|
| 31 |
- ){
|
|
| 32 |
- Text( |
|
| 33 |
- text = "포토 슬라이스 준비 중...", |
|
| 34 |
- color = Color.White |
|
| 35 |
- ) |
|
| 36 |
- } |
|
| 59 |
+ Surface( |
|
| 60 |
+ modifier = Modifier.fillMaxSize(), |
|
| 61 |
+ color = Color.Black |
|
| 62 |
+ ) {
|
|
| 63 |
+ PhotoSlideApp() |
|
| 37 | 64 |
} |
| 38 | 65 |
} |
| 39 | 66 |
} |
| 40 | 67 |
} |
| 41 | 68 |
} |
| 69 |
+ |
|
| 70 |
+/** |
|
| 71 |
+ * 1. 전체 앱 상태 관리 및 라우팅 담당 (State Holder) |
|
| 72 |
+ */ |
|
| 42 | 73 |
@Composable |
| 43 |
-fun PhotoSlideScreen() {
|
|
| 74 |
+fun PhotoSlideApp() {
|
|
| 75 |
+ var selectedImageUris by remember { mutableStateOf<List<Uri>>(emptyList()) }
|
|
| 76 |
+ var currentIndex by remember { mutableIntStateOf(0) }
|
|
| 77 |
+ |
|
| 78 |
+ val photoPickerLauncher = rememberImagePickerLauncher { uris ->
|
|
| 79 |
+ if (uris.isNotEmpty()) {
|
|
| 80 |
+ selectedImageUris = uris |
|
| 81 |
+ currentIndex = 0 |
|
| 82 |
+ } |
|
| 83 |
+ } |
|
| 84 |
+ |
|
| 44 | 85 |
Box( |
| 45 | 86 |
modifier = Modifier.fillMaxSize(), |
| 46 | 87 |
contentAlignment = Alignment.Center |
| 47 | 88 |
) {
|
| 48 |
- // res/drawable에 넣은 이미지 파일 이름 (확장자 제외) |
|
| 49 |
- Image( |
|
| 50 |
- painter = painterResource(id = R.drawable.flow02), |
|
| 51 |
- contentDescription = "슬라이드쇼 샘플 이미지", |
|
| 52 |
- modifier = Modifier.fillMaxSize(), |
|
| 53 |
- contentScale = ContentScale.Fit ) |
|
| 89 |
+ if (selectedImageUris.isEmpty()) {
|
|
| 90 |
+ EmptyPhotoView( |
|
| 91 |
+ onPickClick = {
|
|
| 92 |
+ photoPickerLauncher.launch( |
|
| 93 |
+ PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly) |
|
| 94 |
+ ) |
|
| 95 |
+ } |
|
| 96 |
+ ) |
|
| 97 |
+ } else {
|
|
| 98 |
+ ActiveSlideView( |
|
| 99 |
+ imageUris = selectedImageUris, |
|
| 100 |
+ currentIndex = currentIndex, |
|
| 101 |
+ onNextClick = {
|
|
| 102 |
+ currentIndex = (currentIndex + 1) % selectedImageUris.size |
|
| 103 |
+ }, |
|
| 104 |
+ onChangePhotosClick = {
|
|
| 105 |
+ photoPickerLauncher.launch( |
|
| 106 |
+ PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly) |
|
| 107 |
+ ) |
|
| 108 |
+ } |
|
| 109 |
+ ) |
|
| 110 |
+ } |
|
| 54 | 111 |
} |
| 55 | 112 |
} |
| 56 | 113 |
|
| 57 |
-@Preview(showBackground = true) |
|
| 114 |
+/** |
|
| 115 |
+ * 2. 사진 불러오기 (Picker) 로직 모듈 |
|
| 116 |
+ */ |
|
| 58 | 117 |
@Composable |
| 59 |
-fun PhotoSlidePreview() {
|
|
| 60 |
- PhotoSlideTheme {
|
|
| 61 |
- Surface( |
|
| 62 |
- modifier = Modifier.fillMaxSize(), |
|
| 63 |
- color = Color.Black |
|
| 118 |
+fun rememberImagePickerLauncher(onUrisSelected: (List<Uri>) -> Unit) = |
|
| 119 |
+ rememberLauncherForActivityResult( |
|
| 120 |
+ contract = ActivityResultContracts.PickMultipleVisualMedia(), |
|
| 121 |
+ onResult = onUrisSelected |
|
| 122 |
+ ) |
|
| 123 |
+ |
|
| 124 |
+/** |
|
| 125 |
+ * 3. 사진이 없을 때 안내 및 선택 화면 모듈 |
|
| 126 |
+ */ |
|
| 127 |
+@Composable |
|
| 128 |
+fun EmptyPhotoView(onPickClick: () -> Unit) {
|
|
| 129 |
+ Column( |
|
| 130 |
+ horizontalAlignment = Alignment.CenterHorizontally, |
|
| 131 |
+ verticalArrangement = Arrangement.Center, |
|
| 132 |
+ modifier = Modifier.fillMaxSize() |
|
| 133 |
+ ) {
|
|
| 134 |
+ Text( |
|
| 135 |
+ text = "슬라이드쇼에 사용할 사진을 선택해 주세요", |
|
| 136 |
+ color = Color.White, |
|
| 137 |
+ modifier = Modifier.padding(bottom = 16.dp) |
|
| 138 |
+ ) |
|
| 139 |
+ Button(onClick = onPickClick) {
|
|
| 140 |
+ Text("사진 여러 장 고르기")
|
|
| 141 |
+ } |
|
| 142 |
+ } |
|
| 143 |
+} |
|
| 144 |
+/** |
|
| 145 |
+ * 4. 사진 슬라이드 쇼 렌더링, 타이머 프로그레스바 및 전환 애니메이션 모듈 |
|
| 146 |
+ */ |
|
| 147 |
+@Composable |
|
| 148 |
+fun ActiveSlideView( |
|
| 149 |
+ imageUris: List<Uri>, |
|
| 150 |
+ currentIndex: Int, |
|
| 151 |
+ onNextClick: () -> Unit, |
|
| 152 |
+ onChangePhotosClick: () -> Unit |
|
| 153 |
+) {
|
|
| 154 |
+ val slideDuration = 10000L // 사진 한 장당 표시 시간 (3초) |
|
| 155 |
+ val progress = remember { Animatable(0f) }
|
|
| 156 |
+ |
|
| 157 |
+ // 사진이 2장 이상일 때, 인덱스가 바뀔 때마다 0부터 1까지 차오르는 타이머 애니메이션 실행 |
|
| 158 |
+ LaunchedEffect(currentIndex, imageUris) {
|
|
| 159 |
+ if (imageUris.size > 1) {
|
|
| 160 |
+ progress.snapTo(0f) |
|
| 161 |
+ progress.animateTo( |
|
| 162 |
+ targetValue = 1f, |
|
| 163 |
+ animationSpec = tween(durationMillis = slideDuration.toInt(), easing = LinearEasing) |
|
| 164 |
+ ) |
|
| 165 |
+ onNextClick() |
|
| 166 |
+ } |
|
| 167 |
+ } |
|
| 168 |
+ |
|
| 169 |
+ val currentUri = imageUris[currentIndex] |
|
| 170 |
+ |
|
| 171 |
+ BoxWithConstraints( |
|
| 172 |
+ modifier = Modifier |
|
| 173 |
+ .fillMaxSize() |
|
| 174 |
+ .background(Color.Black), |
|
| 175 |
+ contentAlignment = Alignment.Center |
|
| 176 |
+ ) {
|
|
| 177 |
+ val maxWidth = maxWidth |
|
| 178 |
+ val maxHeight = maxHeight |
|
| 179 |
+ |
|
| 180 |
+ // Crossfade를 적용하여 사진이 바뀔 때 부드럽게 페이드 인/아웃 되도록 전환 효과 부여 |
|
| 181 |
+ Crossfade( |
|
| 182 |
+ targetState = currentUri, |
|
| 183 |
+ animationSpec = tween(durationMillis = 1000), // 전환에 걸리는 시간 (0.6초) |
|
| 184 |
+ label = "PhotoTransition" |
|
| 185 |
+ ) { uri ->
|
|
| 186 |
+ PhotoImageView( |
|
| 187 |
+ uri = uri, |
|
| 188 |
+ maxWidth = maxWidth, |
|
| 189 |
+ maxHeight = maxHeight |
|
| 190 |
+ ) |
|
| 191 |
+ } |
|
| 192 |
+ |
|
| 193 |
+ // 화면 상단에 남은 시간을 시각적으로 보여주는 프로그레스 인디케이터 바 |
|
| 194 |
+ if (imageUris.size > 1) {
|
|
| 195 |
+ LinearProgressIndicator( |
|
| 196 |
+ progress = { progress.value },
|
|
| 197 |
+ modifier = Modifier |
|
| 198 |
+ .fillMaxWidth() |
|
| 199 |
+ .height(4.dp) |
|
| 200 |
+ .align(Alignment.TopCenter), |
|
| 201 |
+ color = Color.White, |
|
| 202 |
+ trackColor = Color.Gray.copy(alpha = 0.3f) |
|
| 203 |
+ ) |
|
| 204 |
+ } |
|
| 205 |
+ |
|
| 206 |
+ SlideControlBar( |
|
| 207 |
+ currentIndex = currentIndex, |
|
| 208 |
+ totalSize = imageUris.size, |
|
| 209 |
+ onNextClick = onNextClick, |
|
| 210 |
+ onChangePhotosClick = onChangePhotosClick |
|
| 211 |
+ ) |
|
| 212 |
+ } |
|
| 213 |
+} |
|
| 214 |
+ |
|
| 215 |
+/** |
|
| 216 |
+ * 5. 단일 사진 렌더링, getPhotoOrientation 함수 반영 및 오버레이 표시 모듈 |
|
| 217 |
+ */ |
|
| 218 |
+@Composable |
|
| 219 |
+fun PhotoImageView( |
|
| 220 |
+ uri: Uri, |
|
| 221 |
+ maxWidth: Dp, |
|
| 222 |
+ maxHeight: Dp |
|
| 223 |
+) {
|
|
| 224 |
+ val context = LocalContext.current |
|
| 225 |
+ |
|
| 226 |
+ // getPhotoOrientation 함수를 사용하여 회전 각도 추출 |
|
| 227 |
+ var rotation = remember(uri) {
|
|
| 228 |
+ getPhotoOrientation(context, uri) |
|
| 229 |
+ } |
|
| 230 |
+ rotation = 0F |
|
| 231 |
+ Log.d ("tag rotation" +
|
|
| 232 |
+ "", "rotation = $rotation" ) |
|
| 233 |
+ // EXIF orientation 값을 로그 또는 디버그 표시용으로 읽기 위한 추가 로직 |
|
| 234 |
+ val orientationVal = remember(uri) {
|
|
| 235 |
+ try {
|
|
| 236 |
+ context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
|
| 237 |
+ ExifInterface(inputStream).getAttributeInt( |
|
| 238 |
+ ExifInterface.TAG_ORIENTATION, |
|
| 239 |
+ ExifInterface.ORIENTATION_NORMAL |
|
| 240 |
+ ) |
|
| 241 |
+ } ?: 1 |
|
| 242 |
+ } catch (e: Exception) {
|
|
| 243 |
+ 1 |
|
| 244 |
+ } |
|
| 245 |
+ } |
|
| 246 |
+ |
|
| 247 |
+ val painter = rememberAsyncImagePainter( |
|
| 248 |
+ model = ImageRequest.Builder(context) |
|
| 249 |
+ .data(uri) |
|
| 250 |
+ .crossfade(true) |
|
| 251 |
+ .build() |
|
| 252 |
+ ) |
|
| 253 |
+ |
|
| 254 |
+ Box( |
|
| 255 |
+ modifier = Modifier |
|
| 256 |
+ .fillMaxSize() |
|
| 257 |
+ .background(Color.Black), |
|
| 258 |
+ contentAlignment = Alignment.Center |
|
| 259 |
+ ) {
|
|
| 260 |
+ val isRotated = rotation == 90f || rotation == 270f |
|
| 261 |
+ |
|
| 262 |
+ Image( |
|
| 263 |
+ painter = painter, |
|
| 264 |
+ contentDescription = "슬라이드 사진", |
|
| 265 |
+ modifier = Modifier |
|
| 266 |
+ .fillMaxSize() |
|
| 267 |
+ .rotate(rotation), |
|
| 268 |
+ contentScale = if (isRotated) ContentScale.Inside else ContentScale.Fit |
|
| 269 |
+ ) |
|
| 270 |
+ |
|
| 271 |
+ // 사진 위에 orientation 값과 회전 각도 표시 |
|
| 272 |
+ Box( |
|
| 273 |
+ modifier = Modifier |
|
| 274 |
+ .align(Alignment.TopStart) |
|
| 275 |
+ .padding(16.dp) |
|
| 276 |
+ .background(Color.Black.copy(alpha = 0.6f)) |
|
| 277 |
+ .padding(horizontal = 8.dp, vertical = 4.dp) |
|
| 64 | 278 |
) {
|
| 65 |
- PhotoSlideScreen() |
|
| 279 |
+ Text( |
|
| 280 |
+ text = "Orientation: $orientationVal (Rotation: ${rotation.toInt()}°)",
|
|
| 281 |
+ color = Color.White, |
|
| 282 |
+ fontSize = 14.sp |
|
| 283 |
+ ) |
|
| 284 |
+ } |
|
| 285 |
+ } |
|
| 286 |
+} |
|
| 287 |
+/** |
|
| 288 |
+ * 5-1 EXIF 정보로 회전각 읽어오기 |
|
| 289 |
+ */ |
|
| 290 |
+fun getPhotoOrientation(context: Context, uri: Uri): Float {
|
|
| 291 |
+ return try {
|
|
| 292 |
+ context.contentResolver.openInputStream(uri)?.use { inputStream ->
|
|
| 293 |
+ val exif = ExifInterface(inputStream) |
|
| 294 |
+ val orientation = exif.getAttributeInt( |
|
| 295 |
+ ExifInterface.TAG_ORIENTATION, |
|
| 296 |
+ ExifInterface.ORIENTATION_NORMAL |
|
| 297 |
+ ) |
|
| 298 |
+ |
|
| 299 |
+ when (orientation) {
|
|
| 300 |
+ ExifInterface.ORIENTATION_ROTATE_90 -> 90f |
|
| 301 |
+ ExifInterface.ORIENTATION_ROTATE_180 -> 180f |
|
| 302 |
+ ExifInterface.ORIENTATION_ROTATE_270 -> 270f |
|
| 303 |
+ else -> 0f |
|
| 304 |
+ } |
|
| 305 |
+ } ?: 0f |
|
| 306 |
+ } catch (e: Exception) {
|
|
| 307 |
+ 0f |
|
| 308 |
+ } |
|
| 309 |
+} |
|
| 310 |
+/** |
|
| 311 |
+ * 6. 하단 제어 바 (사진 전환 및 재선택 버튼) 모듈 |
|
| 312 |
+ */ |
|
| 313 |
+@Composable |
|
| 314 |
+fun SlideControlBar( |
|
| 315 |
+ currentIndex: Int, |
|
| 316 |
+ totalSize: Int, |
|
| 317 |
+ onNextClick: () -> Unit, |
|
| 318 |
+ onChangePhotosClick: () -> Unit |
|
| 319 |
+) {
|
|
| 320 |
+ Box( |
|
| 321 |
+ modifier = Modifier |
|
| 322 |
+ .fillMaxSize() |
|
| 323 |
+ .padding(16.dp), |
|
| 324 |
+ contentAlignment = Alignment.BottomCenter |
|
| 325 |
+ ) {
|
|
| 326 |
+ Row( |
|
| 327 |
+ horizontalArrangement = Arrangement.spacedBy(8.dp), |
|
| 328 |
+ verticalAlignment = Alignment.CenterVertically |
|
| 329 |
+ ) {
|
|
| 330 |
+ Button(onClick = onChangePhotosClick) {
|
|
| 331 |
+ Text("사진 다시 고르기")
|
|
| 332 |
+ } |
|
| 333 |
+ Button(onClick = onNextClick) {
|
|
| 334 |
+ Text("다음 사진 (${currentIndex + 1}/$totalSize)")
|
|
| 335 |
+ } |
|
| 66 | 336 |
} |
| 67 | 337 |
} |
| 68 | 338 |
}(No newline at end of file) |
--- gradle/libs.versions.toml
+++ gradle/libs.versions.toml
... | ... | @@ -8,6 +8,8 @@ |
| 8 | 8 |
activityCompose = "1.8.0" |
| 9 | 9 |
kotlin = "2.2.10" |
| 10 | 10 |
composeBom = "2026.02.01" |
| 11 |
+animationCore = "1.12.0" |
|
| 12 |
+animation = "1.12.0" |
|
| 11 | 13 |
|
| 12 | 14 |
[libraries] |
| 13 | 15 |
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
... | ... | @@ -24,6 +26,8 @@ |
| 24 | 26 |
androidx-compose-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
|
| 25 | 27 |
androidx-compose-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
|
| 26 | 28 |
androidx-compose-material3 = { group = "androidx.compose.material3", name = "material3" }
|
| 29 |
+androidx-compose-animation-core = { group = "androidx.compose.animation", name = "animation-core", version.ref = "animationCore" }
|
|
| 30 |
+androidx-compose-animation = { group = "androidx.compose.animation", name = "animation", version.ref = "animation" }
|
|
| 27 | 31 |
|
| 28 | 32 |
[plugins] |
| 29 | 33 |
android-application = { id = "com.android.application", version.ref = "agp" }
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?