Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ dependencies {
implementation project(':utils')

// Kotlin lang
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.core:core-ktx:1.10.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.1'

// App compat and UI things
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation "androidx.viewpager2:viewpager2:1.0.0"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

// Navigation library
def nav_version = '2.2.2'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

// EXIF Interface
implementation 'androidx.exifinterface:exifinterface:1.2.0'
implementation 'androidx.exifinterface:exifinterface:1.3.6'

// Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
Expand Down
58 changes: 27 additions & 31 deletions app/src/main/java/com/samsung/android/scan3d/CameraActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,23 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.samsung.android.scan3d.databinding.ActivityCameraBinding
import com.samsung.android.scan3d.http.HttpService
import com.samsung.android.scan3d.serv.Cam
import kotlinx.coroutines.channels.Channel
import com.samsung.android.scan3d.serv.CameraActionState
import com.samsung.android.scan3d.serv.CameraActionState.ON_PAUSE
import com.samsung.android.scan3d.serv.CameraActionState.ON_RESUME
import com.samsung.android.scan3d.serv.CameraActionState.START
import com.samsung.android.scan3d.serv.CameraActionState.STOP

const val KILL_THE_APP = "KILL"

class CameraActivity : AppCompatActivity() {

private lateinit var activityCameraBinding: ActivityCameraBinding
private var _binding: ActivityCameraBinding? = null
private val binding get() = _binding!!

private val receiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
Expand All @@ -45,44 +47,38 @@ class CameraActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.i("CAMERAACTIVITY", "CAMERAACTIVITY onCreate")
activityCameraBinding = ActivityCameraBinding.inflate(layoutInflater)
setContentView(activityCameraBinding.root)
sendCam {
it.action = "start"
}
registerReceiver(receiver, IntentFilter("KILL"))
_binding = ActivityCameraBinding.inflate(layoutInflater)
setContentView(binding.root)

setCameraForegroundServiceState(START)
registerReceiver(receiver, IntentFilter(KILL_THE_APP))
}

override fun onPause() {
super.onPause()
sendCam {
it.action = "onPause"
}
}

fun sendCam(extra: (Intent) -> Unit) {
var intent = Intent(this, Cam::class.java)
extra(intent)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent)
} else {
startService(intent)
}
setCameraForegroundServiceState(ON_PAUSE)
}

override fun onDestroy() {
_binding = null
super.onDestroy()
sendCam {
it.action = "stop"
}
setCameraForegroundServiceState(STOP)
unregisterReceiver(receiver)
}

override fun onResume() {
super.onResume()
sendCam {
it.action = "onResume"
setCameraForegroundServiceState(ON_RESUME)
}

fun setCameraForegroundServiceState(action: CameraActionState, extra: ((Intent) -> Unit)? = null) {
try {
val intent = Intent(this, Cam::class.java).also { it.action = action.name }
if (extra != null) extra(intent)

startForegroundService(intent)
} catch (exc: Throwable) {
Log.e("CameraFragment.TAG", "Error closing camera", exc)
}
}
}
Loading