Skip to content

Commit

Permalink
user can select between front & rear camera
Browse files Browse the repository at this point in the history
  • Loading branch information
SidharthMudgil committed Aug 29, 2023
1 parent 9dd4269 commit 96f8464
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.sidharth.lg_motion.ui.home.fragment

//import com.sidharth.lg_motion.util.HandLandmarkerHelper
//import com.sidharth.lg_motion.util.ObjectDetectorHelper
//import com.sidharth.lg_motion.util.PoseLandmarkerHelper
import android.annotation.SuppressLint
import android.content.SharedPreferences
import android.content.res.Configuration
import android.os.Bundle
import android.util.Log
Expand All @@ -18,16 +22,14 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.navArgs
import androidx.preference.PreferenceManager
import com.sidharth.lg_motion.databinding.FragmentCameraBinding
import com.sidharth.lg_motion.domain.callback.ProgressIndicatorCallback
import com.sidharth.lg_motion.domain.model.Feature
import com.sidharth.lg_motion.util.FaceLandmarkerHelper
//import com.sidharth.lg_motion.util.HandLandmarkerHelper
import com.sidharth.lg_motion.util.LiquidGalaxyManager
import com.sidharth.lg_motion.util.SpeechLandmarkerResultParser
import com.sidharth.lg_motion.util.NetworkUtils
//import com.sidharth.lg_motion.util.ObjectDetectorHelper
//import com.sidharth.lg_motion.util.PoseLandmarkerHelper
import com.sidharth.lg_motion.util.SpeechLandmarkerResultParser
import kotlinx.coroutines.launch
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
Expand All @@ -39,7 +41,9 @@ class CameraFragment : Fragment() {
}

private var lastState: LiquidGalaxyManager.State = LiquidGalaxyManager.State.IDLE

private val preferences: SharedPreferences by lazy {
PreferenceManager.getDefaultSharedPreferences(requireContext())
}
private val args: CameraFragmentArgs by navArgs()

private lateinit var faceLandmarkerHelper: FaceLandmarkerHelper
Expand Down Expand Up @@ -138,13 +142,20 @@ class CameraFragment : Fragment() {
override fun onDestroyView() {
_fragmentCameraBinding = null
super.onDestroyView()

backgroundExecutor.shutdown()
backgroundExecutor.awaitTermination(
Long.MAX_VALUE, TimeUnit.NANOSECONDS
)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
cameraFacing = when (preferences.getBoolean("rear_facing_camera", false)) {
true -> CameraSelector.LENS_FACING_BACK
else -> CameraSelector.LENS_FACING_FRONT
}
}

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -155,7 +166,6 @@ class CameraFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

backgroundExecutor = Executors.newSingleThreadExecutor()
if (args.feature != Feature.Type.OBJECT.name) {
fragmentCameraBinding.viewFinder.post {
Expand Down Expand Up @@ -307,7 +317,8 @@ class CameraFragment : Fragment() {

private val faceLandMarkerListener = object : FaceLandmarkerHelper.LandmarkerListener {
override fun onResults(resultBundle: FaceLandmarkerHelper.ResultBundle) {
val newState = SpeechLandmarkerResultParser.getStateFromFaceLandmarkerResult(resultBundle)
val newState =
SpeechLandmarkerResultParser.getStateFromFaceLandmarkerResult(resultBundle)
if ((lastState == newState).not()) {
lastState = newState
execute(newState, null)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/facial_gestures_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<SwitchPreferenceCompat
android:defaultValue="false"
android:key="camera"
android:key="rear_facing_camera"
android:summaryOff="@string/camera_summary_off"
android:summaryOn="@string/camera_summary_on"
android:title="@string/camera_preference_title"
Expand Down

0 comments on commit 96f8464

Please sign in to comment.