build: Task 23 완료 - :feature:feature-player 1차 모듈 분리 (NativePlayer, PageIndexer, ImageViewerActivity)
- feature/feature-player 모듈 신규 생성 (namespace: bums.lunatic.launcher.feature.player): * NativePlayer.kt, PageIndexer.kt, ImageViewerActivity.kt를 :app에서 :feature:feature-player로 이동 * activity_image_viewer.xml 레이아웃을 feature/feature-player/src/main/res/layout/로 이동 및 R 네임스페이스 분리 - settings.gradle.kts, app/build.gradle.kts, ARCHITECTURE.md, TODO.md(6-3 1차 완료) 갱신 - 검증: ./gradlew :app:compileDebugKotlin 빌드 성공 확인 (20s, 109 actionable tasks)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
id("kotlin-android")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "bums.lunatic.launcher.feature.player"
|
||||
compileSdk = 35
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 26
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":core:core-common"))
|
||||
implementation("androidx.appcompat:appcompat:1.7.1")
|
||||
implementation("androidx.core:core-ktx:1.15.0")
|
||||
implementation("androidx.exifinterface:exifinterface:1.3.6")
|
||||
implementation("com.github.bumptech.glide:glide:4.11.0")
|
||||
implementation("com.github.chrisbanes:PhotoView:2.3.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest />
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package bums.lunatic.launcher.player
|
||||
|
||||
import android.media.ExifInterface
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.View
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import bums.lunatic.launcher.feature.player.R
|
||||
import com.bumptech.glide.Glide
|
||||
import java.io.File
|
||||
|
||||
class ImageViewerActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var layoutMetaInfo: View
|
||||
private val hideHandler = Handler(Looper.getMainLooper())
|
||||
private val hideRunnable = Runnable { hideMetaInfo() }
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_image_viewer)
|
||||
|
||||
val photoView = findViewById<com.github.chrisbanes.photoview.PhotoView>(R.id.photoView)
|
||||
layoutMetaInfo = findViewById(R.id.layoutMetaInfo)
|
||||
val btnToggleMeta = findViewById<ImageButton>(R.id.btnToggleMeta)
|
||||
|
||||
val imagePath = intent.getStringExtra("IMAGE_PATH") ?: return
|
||||
|
||||
// 1. 이미지 로드
|
||||
Glide.with(this).load(File(imagePath)).into(photoView)
|
||||
|
||||
// 2. 메타데이터(Exif) 추출 및 표시
|
||||
displayExifInfo(imagePath)
|
||||
|
||||
// 3. 초기 실행 시 3초간 보여주기
|
||||
showMetaInfoWithDelay()
|
||||
|
||||
// 4. 버튼 클릭 리스너
|
||||
btnToggleMeta.setOnClickListener {
|
||||
if (layoutMetaInfo.visibility == View.VISIBLE) {
|
||||
hideMetaInfo()
|
||||
} else {
|
||||
showMetaInfoWithDelay()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getAllExifDetails(path: String): String {
|
||||
val exif = androidx.exifinterface.media.ExifInterface(path)
|
||||
val sb = StringBuilder()
|
||||
|
||||
// 1. 리플렉션을 사용하여 ExifInterface의 모든 TAG_ 필드를 가져옴
|
||||
val fields = androidx.exifinterface.media.ExifInterface::class.java.fields
|
||||
|
||||
for (field in fields) {
|
||||
if (field.name.startsWith("TAG_")) {
|
||||
try {
|
||||
val tagName = field.get(null) as String
|
||||
val value = exif.getAttribute(tagName)
|
||||
|
||||
// 값이 있는 태그만 추가
|
||||
if (!value.isNullOrBlank()) {
|
||||
// 태그명에서 "TAG_" 접두어 제거하고 읽기 쉽게 변환 (예: TAG_MODEL -> Model)
|
||||
val friendlyName = field.name.removePrefix("TAG_").replace("_", " ")
|
||||
sb.append("**$friendlyName**: $value\n")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// 특정 태그 접근 실패 시 무시
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 위치 정보는 별도 계산 (문자열보다 좌표값이 정확함)
|
||||
val latLong = FloatArray(2)
|
||||
if (exif.getLatLong(latLong)) {
|
||||
sb.append("\n📍 **위치(GPS)**: ${latLong[0]}, ${latLong[1]}")
|
||||
}
|
||||
|
||||
return if (sb.isEmpty()) "메타데이터 정보가 없습니다." else sb.toString()
|
||||
}
|
||||
|
||||
private fun displayExifInfo(path: String) {
|
||||
val exif = androidx.exifinterface.media.ExifInterface(path)
|
||||
val info = StringBuilder().apply {
|
||||
appendLine("모델: ${exif.getAttribute(ExifInterface.TAG_MODEL) ?: "알 수 없음"}\n")
|
||||
appendLine("날짜: ${exif.getAttribute(ExifInterface.TAG_DATETIME) ?: "-"}\n")
|
||||
appendLine("해상도: ${exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH)}x${exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH)}\n")
|
||||
appendLine("조리개: f/${exif.getAttribute(ExifInterface.TAG_F_NUMBER) ?: "-"}")
|
||||
appendLine(getAllExifDetails(path))
|
||||
}.toString()
|
||||
|
||||
findViewById<TextView>(R.id.tvMetaTitle).text = File(path).name
|
||||
findViewById<TextView>(R.id.tvMetaData).text = info
|
||||
}
|
||||
|
||||
private fun showMetaInfoWithDelay() {
|
||||
hideHandler.removeCallbacks(hideRunnable) // 기존 예약된 숨김 제거
|
||||
layoutMetaInfo.visibility = View.VISIBLE
|
||||
layoutMetaInfo.animate().alpha(1f).setDuration(300).start()
|
||||
|
||||
// 3초 후 숨김 예약
|
||||
hideHandler.postDelayed(hideRunnable, 5000)
|
||||
}
|
||||
|
||||
private fun hideMetaInfo() {
|
||||
layoutMetaInfo.animate().alpha(0f).setDuration(300).withEndAction {
|
||||
layoutMetaInfo.visibility = View.GONE
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package bums.lunatic.launcher.player
|
||||
|
||||
import android.view.Surface
|
||||
|
||||
class NativePlayer {
|
||||
private var nativeHandle: Long = 0
|
||||
private var subtitleCallback: ((String) -> Unit)? = null
|
||||
private var videoSizeCallback: ((Int, Int) -> Unit)? = null
|
||||
|
||||
// 💡 JNI로부터 받을 콜백 리스너 설정
|
||||
var onPreparedListener: (() -> Unit)? = null
|
||||
var onErrorListener: ((Int, String) -> Unit)? = null
|
||||
|
||||
fun initialize(): Boolean {
|
||||
nativeHandle = nativeInit()
|
||||
return nativeHandle != 0L
|
||||
}
|
||||
|
||||
fun setDataSource(videoFd: Int, subFd: Int) = nativeSetDataSource(nativeHandle, videoFd, subFd)
|
||||
fun prepareAsync() { if (nativeHandle != 0L) nativePrepareAsync(nativeHandle) }
|
||||
fun play(surface: Surface) = nativePlay(nativeHandle, surface)
|
||||
fun pause() { if (nativeHandle != 0L) nativePause(nativeHandle) }
|
||||
fun stop() = nativeStop(nativeHandle)
|
||||
fun seekBy(sec: Double) = nativeSeekBy(nativeHandle, sec)
|
||||
fun setSpeed(speed: Float) = nativeSetSpeed(nativeHandle, speed)
|
||||
|
||||
// 외부 함수 호출 정의
|
||||
fun getDuration(): Double {
|
||||
return if (nativeHandle != 0L) nativeGetDuration(nativeHandle) else 0.0
|
||||
}
|
||||
|
||||
fun seekTo(sec: Double) {
|
||||
if (nativeHandle != 0L) nativeSeekTo(nativeHandle, sec)
|
||||
}
|
||||
|
||||
// 하단에 external fun 추가
|
||||
private external fun nativeGetDuration(h: Long): Double
|
||||
private external fun nativeSeekTo(h: Long, s: Double)
|
||||
|
||||
@Suppress("unused")
|
||||
private fun onSubtitleTextDecoded(text: String) {
|
||||
subtitleCallback?.invoke(text)
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
private fun onVideoSizeChanged(w: Int, h: Int) {
|
||||
videoSizeCallback?.invoke(w, h)
|
||||
}
|
||||
|
||||
// 💡 C++에서 준비 완료 시 호출
|
||||
@Suppress("unused")
|
||||
private fun onNativePrepared() {
|
||||
onPreparedListener?.invoke()
|
||||
}
|
||||
|
||||
// 💡 C++에서 오류 발생 시 호출
|
||||
@Suppress("unused")
|
||||
private fun onNativeError(errorCode: Int, errorMessage: String) {
|
||||
onErrorListener?.invoke(errorCode, errorMessage)
|
||||
}
|
||||
|
||||
fun setSubtitleCallback(cb: (String) -> Unit) { subtitleCallback = cb }
|
||||
fun setVideoSizeCallback(cb: (Int, Int) -> Unit) { videoSizeCallback = cb }
|
||||
|
||||
fun destroy() {
|
||||
if (nativeHandle != 0L) {
|
||||
nativeDestroy(nativeHandle)
|
||||
nativeHandle = 0L
|
||||
}
|
||||
}
|
||||
|
||||
data class SubtitleTrack(
|
||||
val id: String,
|
||||
val name: String,
|
||||
val isExternal: Boolean
|
||||
)
|
||||
|
||||
fun getInternalSubtitleTracks(): List<SubtitleTrack> {
|
||||
if (nativeHandle == 0L) return emptyList()
|
||||
val rawStr = nativeGetSubtitleTracks(nativeHandle) ?: return emptyList()
|
||||
return rawStr.split(",").filter { it.isNotBlank() }.mapNotNull {
|
||||
val parts = it.split(":")
|
||||
if (parts.size >= 2) SubtitleTrack(parts[0], parts[1], false) else null
|
||||
}
|
||||
}
|
||||
|
||||
fun setInternalSubtitleTrack(streamIndex: Int) {
|
||||
if (nativeHandle != 0L) nativeSetSubtitleTrack(nativeHandle, streamIndex)
|
||||
}
|
||||
|
||||
fun getCurrentPosition(): Double {
|
||||
return if (nativeHandle != 0L) nativeGetCurrentPosition(nativeHandle) else 0.0
|
||||
}
|
||||
|
||||
private external fun nativeInit(): Long
|
||||
private external fun nativeSetDataSource(h: Long, videoFd: Int, subFd: Int)
|
||||
private external fun nativePrepareAsync(h: Long)
|
||||
private external fun nativePlay(h: Long, s: Surface)
|
||||
private external fun nativePause(h: Long)
|
||||
private external fun nativeStop(h: Long)
|
||||
private external fun nativeDestroy(h: Long)
|
||||
private external fun nativeSeekBy(h: Long, s: Double)
|
||||
private external fun nativeSetSpeed(h: Long, sp: Float)
|
||||
private external fun nativeGetCurrentPosition(h: Long): Double
|
||||
private external fun nativeGetSubtitleTracks(h: Long): String
|
||||
private external fun nativeSetSubtitleTrack(h: Long, index: Int)
|
||||
|
||||
companion object {
|
||||
init { System.loadLibrary("native_renderer") }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package bums.lunatic.launcher.player
|
||||
|
||||
import android.os.Build
|
||||
import android.text.Layout
|
||||
import android.text.StaticLayout
|
||||
import android.text.TextPaint
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import java.io.RandomAccessFile
|
||||
import java.nio.charset.Charset
|
||||
import java.util.regex.Pattern
|
||||
|
||||
data class Chapter(
|
||||
val title: String,
|
||||
val pageIndex: Int
|
||||
)
|
||||
|
||||
class PageIndexer(
|
||||
private val file: File,
|
||||
private val encoding: String,
|
||||
private val paint: TextPaint,
|
||||
private val viewWidth: Int,
|
||||
private val viewHeight: Int
|
||||
) {
|
||||
val pageOffsets = ArrayList<Long>()
|
||||
val chapters = ArrayList<Chapter>()
|
||||
private val charset = Charset.forName(encoding)
|
||||
fun getChapterForPage(currentPageIndex: Int): Chapter? {
|
||||
// 현재 페이지보다 작거나 같은 시작 페이지를 가진 챕터 중, 가장 마지막 챕터를 찾습니다.
|
||||
return chapters.lastOrNull { it.pageIndex <= currentPageIndex }
|
||||
}
|
||||
private val chapterPattern = Pattern.compile(
|
||||
"(?:제\\s*)?\\d+\\s*[화|장|막|절|편]"
|
||||
)
|
||||
|
||||
suspend fun buildIndex(onProgress: (Int) -> Unit) = withContext(Dispatchers.Default) {
|
||||
val raf = RandomAccessFile(file, "r")
|
||||
val fileLength = raf.length()
|
||||
var currentOffset = 0L
|
||||
var lastProgress = -1
|
||||
pageOffsets.add(currentOffset)
|
||||
|
||||
val bufferSize = 40000
|
||||
val buffer = ByteArray(bufferSize)
|
||||
|
||||
while (currentOffset < fileLength) {
|
||||
raf.seek(currentOffset)
|
||||
val bytesRead = raf.read(buffer)
|
||||
if (bytesRead == -1) break
|
||||
|
||||
val chunkText = String(buffer, 0, bytesRead, charset)
|
||||
if (chunkText.isEmpty()) break
|
||||
|
||||
val layout = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
StaticLayout.Builder.obtain(chunkText, 0, chunkText.length, paint, viewWidth)
|
||||
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
|
||||
.setIncludePad(false)
|
||||
.build()
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
StaticLayout(chunkText, paint, viewWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 1.0f, false)
|
||||
}
|
||||
|
||||
val totalLines = layout.lineCount
|
||||
var startLine = 0
|
||||
var chunkConsumedOffset = 0
|
||||
|
||||
while (startLine < totalLines) {
|
||||
val pageTopY = layout.getLineTop(startLine)
|
||||
val targetBottomY = pageTopY + viewHeight
|
||||
var endLine = layout.getLineForVertical(targetBottomY)
|
||||
|
||||
if (layout.getLineBottom(endLine) > targetBottomY) {
|
||||
endLine--
|
||||
}
|
||||
if (endLine < startLine) endLine = startLine
|
||||
|
||||
val endCharOffset = layout.getLineEnd(endLine)
|
||||
var pageText = chunkText.substring(chunkConsumedOffset, endCharOffset)
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// [수정 구간] 챕터 탐지 및 강제 페이지 분할 로직
|
||||
// -------------------------------------------------------------------------
|
||||
val matcher = chapterPattern.matcher(pageText)
|
||||
if (matcher.find()) {
|
||||
val matchStart = matcher.start()
|
||||
|
||||
// 챕터 제목 줄의 시작 위치 계산
|
||||
val lineStart = pageText.lastIndexOf('\n', matchStart).let { if (it == -1) 0 else it + 1 }
|
||||
val lineEnd = pageText.indexOf('\n', matchStart).let { if (it == -1) pageText.length else it }
|
||||
val chapterTitle = pageText.substring(lineStart, lineEnd).trim()
|
||||
|
||||
// 글자수 제한 체크 (40자 미만 정상 챕터인 경우)
|
||||
if (chapterTitle.isNotEmpty() && chapterTitle.length < 40) {
|
||||
|
||||
// 만약 챕터가 페이지의 맨 처음(lineStart == 0)이 아니라면,
|
||||
// 즉, 챕터 앞에 이전 장의 본문 내용이 포함되어 있다면 강제로 쪼갭니다.
|
||||
if (lineStart > 0) {
|
||||
// 1. 챕터 직전 내용까지만 현재 페이지 텍스트로 인정합니다.
|
||||
val previousSectionText = pageText.substring(0, lineStart)
|
||||
val previousSectionBytes = previousSectionText.toByteArray(charset).size
|
||||
|
||||
// 2. 현재 오프셋에 이전 내용 크기를 더해 "새 페이지(챕터 시작점)" 오프셋을 구합니다.
|
||||
currentOffset += previousSectionBytes
|
||||
|
||||
// 3. 페이지 목록에 새 오프셋(챕터의 시작점)을 즉시 추가합니다.
|
||||
pageOffsets.add(currentOffset)
|
||||
|
||||
// 4. 다음 루프를 위해 chunk 내 소비된 문자 인덱스를 업데이트합니다.
|
||||
chunkConsumedOffset += lineStart
|
||||
|
||||
// 5. StaticLayout 상에서 이 챕터 줄이 속한 실제 Line을 찾아서 루프의 startLine을 갱신합니다.
|
||||
// layout.getLineForOffset은 전체 chunkText 기준이므로 chunkConsumedOffset을 대입합니다.
|
||||
startLine = layout.getLineForOffset(chunkConsumedOffset)
|
||||
|
||||
// 중요: 이번 루프는 여기서 끊고, 쪼개진 새 페이지 기준으로 다음 루프에서 처리하도록 넘깁니다.
|
||||
continue
|
||||
} else {
|
||||
// 이미 페이지의 맨 첫 줄이 챕터인 경우 바로 리스트에 등록합니다.
|
||||
val currentPageIndex = pageOffsets.size - 1
|
||||
if (chapters.isEmpty() || chapters.last().pageIndex != currentPageIndex) {
|
||||
chapters.add(Chapter(chapterTitle, currentPageIndex))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// 챕터 분할이 일어나지 않은 일반적인 페이지 처리 flow
|
||||
val pageBytesSize = pageText.toByteArray(charset).size
|
||||
currentOffset += pageBytesSize
|
||||
chunkConsumedOffset = endCharOffset
|
||||
|
||||
if (currentOffset < fileLength) {
|
||||
pageOffsets.add(currentOffset)
|
||||
}
|
||||
|
||||
val progress = ((currentOffset * 100) / fileLength).toInt()
|
||||
if (progress != lastProgress) {
|
||||
onProgress(progress)
|
||||
lastProgress = progress
|
||||
}
|
||||
|
||||
startLine = endLine + 1
|
||||
}
|
||||
}
|
||||
raf.close()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#000000">
|
||||
|
||||
<com.github.chrisbanes.photoview.PhotoView
|
||||
android:id="@+id/photoView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/layoutMetaInfo"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="250dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="#AA000000"
|
||||
android:padding="16dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvMetaTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#FFBB00"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvMetaData"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:lineSpacingExtra="4dp"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/btnToggleMeta"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="top|end"
|
||||
android:layout_margin="16dp"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@android:drawable/ic_menu_info_details"
|
||||
android:contentDescription="정보 보기" />
|
||||
|
||||
</FrameLayout>
|
||||
Reference in New Issue
Block a user