OSDN Git Service

カメラと通信を開始するところまで。
authorMRSa <mrsa@myad.jp>
Sun, 6 Jun 2021 13:41:15 +0000 (22:41 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 6 Jun 2021 13:41:15 +0000 (22:41 +0900)
17 files changed:
app/build.gradle
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/CameraPreference.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/ICameraPreferenceProvider.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/camerax/operation/CameraControl.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/ricohpentax/RicohPentaxCameraControl.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/ricohpentax/connection/RicohGr2CameraConnectSequence.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/ricohpentax/connection/RicohGr2Connection.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/ricohpentax/liveview/RicohGr2LiveViewControl.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/theta/ThetaCameraControl.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/constants/ICameraConnectionMethods.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/gokigenassets/liveview/image/CameraLiveViewListenerImpl.kt
app/src/main/java/jp/osdn/gokigen/gokigenassets/utils/communication/SimpleLiveViewSlicer.kt
app/src/main/java/jp/osdn/gokigen/mangle/preference/IPreferencePropertyAccessor.kt
app/src/main/java/jp/osdn/gokigen/mangle/preference/PreferenceValueInitializer.kt
app/src/main/java/jp/osdn/gokigen/mangle/scene/CameraProvider.kt [new file with mode: 0644]
app/src/main/java/jp/osdn/gokigen/mangle/scene/SceneChanger.kt
build.gradle

index f344ba2..dbdc4c6 100644 (file)
@@ -30,8 +30,8 @@ android {
 dependencies {
     implementation fileTree(dir: "libs", include: ["*.jar"])
     implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
-    implementation 'androidx.core:core-ktx:1.3.2'
-    implementation 'androidx.appcompat:appcompat:1.2.0'
+    implementation 'androidx.core:core-ktx:1.5.0'
+    implementation 'androidx.appcompat:appcompat:1.3.0'
     implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
     implementation 'androidx.preference:preference-ktx:1.1.1'
     implementation 'com.google.android.material:material:1.3.0'
@@ -40,10 +40,10 @@ dependencies {
     //androidTestImplementation 'androidx.test.ext:junit:1.1.2'
     //androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
 
-    def camerax_version = "1.1.0-alpha04"
+    def camerax_version = "1.1.0-alpha05"
     implementation "androidx.camera:camera-camera2:$camerax_version"
     implementation "androidx.camera:camera-lifecycle:$camerax_version"
 
-    implementation "androidx.camera:camera-view:1.0.0-alpha24"
+    implementation "androidx.camera:camera-view:1.0.0-alpha25"
     implementation "androidx.datastore:datastore-preferences:1.0.0-beta01"
 }
diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/CameraPreference.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/CameraPreference.kt
new file mode 100644 (file)
index 0000000..e1fc248
--- /dev/null
@@ -0,0 +1,39 @@
+package jp.osdn.gokigen.gokigenassets.camera
+
+class CameraPreference(private val method : String, private val sequence : String = "0", private val option1 : String = "", private val option2 : String = "", private val option3 : String = "", private val option4 : String = "", private val option5 : String = "") : ICameraPreferenceProvider
+{
+    override fun getCameraMethod(): String
+    {
+        return (method)
+    }
+
+    override fun getConnectionSequence(): String
+    {
+        return (sequence)
+    }
+
+    override fun getCameraOption1(): String
+    {
+        return (option1)
+    }
+
+    override fun getCameraOption2(): String
+    {
+        return (option2)
+    }
+
+    override fun getCameraOption3(): String
+    {
+        return (option3)
+    }
+
+    override fun getCameraOption4(): String
+    {
+        return (option4)
+    }
+
+    override fun getCameraOption5(): String
+    {
+        return (option5)
+    }
+}
diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/ICameraPreferenceProvider.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/ICameraPreferenceProvider.kt
new file mode 100644 (file)
index 0000000..9d2520c
--- /dev/null
@@ -0,0 +1,13 @@
+package jp.osdn.gokigen.gokigenassets.camera
+
+interface ICameraPreferenceProvider
+{
+    fun getCameraMethod() : String
+    fun getConnectionSequence() : String
+
+    fun getCameraOption1() : String
+    fun getCameraOption2() : String
+    fun getCameraOption3() : String
+    fun getCameraOption4() : String
+    fun getCameraOption5() : String
+}
index f6b0904..8882460 100644 (file)
@@ -9,6 +9,7 @@ import androidx.camera.core.ImageAnalysis
 import androidx.camera.core.Preview
 import androidx.camera.lifecycle.ProcessCameraProvider
 import androidx.core.content.ContextCompat
+import jp.osdn.gokigen.gokigenassets.camera.ICameraPreferenceProvider
 import jp.osdn.gokigen.gokigenassets.constants.IApplicationConstantConvert.Companion.ID_CAMERA_X_PREVIEW_LAYOUT
 import jp.osdn.gokigen.gokigenassets.liveview.ILiveView
 import jp.osdn.gokigen.gokigenassets.liveview.ILiveViewRefresher
@@ -19,7 +20,7 @@ import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraControl
 import java.util.concurrent.ExecutorService
 import java.util.concurrent.Executors
 
-class CameraControl(private val activity : AppCompatActivity) : ICameraControl
+class CameraControl(private val activity : AppCompatActivity, private val preference: ICameraPreferenceProvider) : ICameraControl
 {
     private lateinit var cameraExecutor: ExecutorService
     private lateinit var liveViewListener : CameraLiveViewListenerImpl
index 3d4dacf..58bf62d 100644 (file)
@@ -5,6 +5,7 @@ import android.view.View
 import androidx.appcompat.app.AppCompatActivity
 import androidx.camera.core.CameraSelector
 import androidx.fragment.app.FragmentActivity
+import jp.osdn.gokigen.gokigenassets.camera.ICameraPreferenceProvider
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.*
 import jp.osdn.gokigen.gokigenassets.camera.theta.status.ICaptureModeReceiver
 import jp.osdn.gokigen.gokigenassets.liveview.ILiveView
@@ -25,14 +26,14 @@ import jp.osdn.gokigen.gokigenassets.liveview.focusframe.IAutoFocusFrameDisplay
 import jp.osdn.gokigen.gokigenassets.liveview.image.CameraLiveViewListenerImpl
 import jp.osdn.gokigen.gokigenassets.scene.IVibrator
 
-class RicohPentaxCameraControl(private val context: AppCompatActivity, private val vibrator : IVibrator, statusReceiver : ICameraStatusReceiver)  : ILiveViewController, ICameraControl, View.OnClickListener,
+class RicohPentaxCameraControl(private val context: AppCompatActivity, private val vibrator : IVibrator, private val preference: ICameraPreferenceProvider, statusReceiver : ICameraStatusReceiver)  : ILiveViewController, ICameraControl, View.OnClickListener,
     ICaptureModeReceiver, ICameraShutter, IDisplayInjector, IUseGR2CommandNotify
 {
 
     //private final Activity activity;
     //private final ICameraStatusReceiver provider;
     private var liveViewListener = CameraLiveViewListenerImpl(context)
-    private val gr2Connection = RicohGr2Connection(context, statusReceiver, this)
+    private val gr2Connection = RicohGr2Connection(context, statusReceiver, this, this)
     private val buttonControl = RicohGr2CameraButtonControl()
     private val statusChecker = RicohGr2StatusChecker(500)
     private val playbackControl = RicohGr2PlaybackControl(communicationTimeoutMs)
@@ -72,9 +73,15 @@ class RicohPentaxCameraControl(private val context: AppCompatActivity, private v
 
     override fun stopLiveView()
     {
+        Log.v(TAG, " stopLiveView() ")
         try
         {
             liveViewControl.stopLiveView()
+            if (isStatusWatch)
+            {
+                statusChecker.stopStatusWatch()
+                isStatusWatch = false
+            }
         }
         catch (e : Exception)
         {
@@ -176,12 +183,12 @@ class RicohPentaxCameraControl(private val context: AppCompatActivity, private v
 
     override fun changeCaptureMode(mode: String)
     {
-        TODO("Not yet implemented")
+        //TODO("Not yet implemented")
     }
 
     override fun changedCaptureMode(captureMode: String)
     {
-        TODO("Not yet implemented")
+        //TODO("Not yet implemented")
     }
 
     override fun doShutter()
index e31751f..23258d0 100644 (file)
@@ -4,6 +4,7 @@ import android.app.Activity
 import android.util.Log
 import androidx.preference.PreferenceManager
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraConnection
+import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraConnectionStatus
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusReceiver
 import jp.osdn.gokigen.gokigenassets.constants.IApplicationConstantConvert.Companion.ID_PREFERENCE_RICOH_GR2_LCD_SLEEP
 import jp.osdn.gokigen.gokigenassets.constants.IApplicationConstantConvert.Companion.ID_PREFERENCE_USE_GR2_SPECIAL_COMMAND
@@ -11,7 +12,7 @@ import jp.osdn.gokigen.gokigenassets.constants.ICameraConstantConvert.Companion.
 import jp.osdn.gokigen.gokigenassets.constants.ICameraConstantConvert.Companion.ID_STRING_CONNECT_CONNECTED
 import jp.osdn.gokigen.gokigenassets.utils.communication.SimpleHttpClient
 
-class RicohGr2CameraConnectSequence(private val context: Activity, private val cameraStatusReceiver: ICameraStatusReceiver, private val cameraConnection: ICameraConnection, private val gr2CommandNotify: IUseGR2CommandNotify, private val executeUrl : String = "http://192.168.1.1") : Runnable {
+class RicohGr2CameraConnectSequence(private val context: Activity, private val cameraStatusReceiver: ICameraStatusReceiver, private val cameraConnection: ICameraConnection, private val gr2CommandNotify: IUseGR2CommandNotify, private val executeUrl : String = "http://192.168.0.1") : Runnable {
 
     companion object
     {
@@ -79,6 +80,7 @@ class RicohGr2CameraConnectSequence(private val context: Activity, private val c
                 cameraStatusReceiver.onStatusNotify(context.getString(ID_STRING_CONNECT_CONNECTED))
                 cameraStatusReceiver.onCameraConnected()
                 Log.v(TAG, "onConnectNotify()")
+                cameraConnection.forceUpdateConnectionStatus(ICameraConnectionStatus.CameraConnectionStatus.CONNECTED)
             }
             thread.start()
         }
index 5439ff4..0d52831 100644 (file)
@@ -7,9 +7,7 @@ import android.provider.Settings
 import android.util.Log
 import androidx.appcompat.app.AlertDialog
 import androidx.fragment.app.FragmentActivity
-import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraConnection
-import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraConnectionStatus
-import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusReceiver
+import jp.osdn.gokigen.gokigenassets.camera.interfaces.*
 import jp.osdn.gokigen.gokigenassets.constants.ICameraConstantConvert.Companion.ID_STRING_CONNECT_CHECK_WIFI
 import jp.osdn.gokigen.gokigenassets.constants.ICameraConstantConvert.Companion.ID_STRING_DIALOG_BUTTON_NETWORK_SETTINGS
 import jp.osdn.gokigen.gokigenassets.constants.ICameraConstantConvert.Companion.ID_STRING_DIALOG_BUTTON_RETRY
@@ -17,12 +15,11 @@ import jp.osdn.gokigen.gokigenassets.constants.ICameraConstantConvert.Companion.
 import java.util.concurrent.Executor
 import java.util.concurrent.Executors
 
-
 /**
  *
  *
  */
-class RicohGr2Connection(private val context: FragmentActivity, private val statusReceiver: ICameraStatusReceiver, private val gr2CommandNotify: IUseGR2CommandNotify) : ICameraConnection
+class RicohGr2Connection(private val context: FragmentActivity, private val statusReceiver: ICameraStatusReceiver, private val liveViewControl: ILiveViewController, private val gr2CommandNotify: IUseGR2CommandNotify) : ICameraConnection
 {
     companion object
     {
@@ -44,41 +41,42 @@ class RicohGr2Connection(private val context: FragmentActivity, private val stat
     private fun onReceiveBroadcastOfConnection(context: Context, intent: Intent) {
         statusReceiver.onStatusNotify(context.getString(ID_STRING_CONNECT_CHECK_WIFI))
         Log.v(TAG, context.getString(ID_STRING_CONNECT_CHECK_WIFI))
-        val action = intent.action
-        if (action == null) {
-            Log.v(TAG, "intent.getAction() : null")
-            return
-        }
         try
         {
+            val action = intent.action
+            if (action == null)
+            {
+                Log.v(TAG, "intent.getAction() : null")
+                return
+            }
+
             @Suppress("DEPRECATION")
             if (action == ConnectivityManager.CONNECTIVITY_ACTION)
             {
                 Log.v(TAG, "onReceiveBroadcastOfConnection() : CONNECTIVITY_ACTION")
                 val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
-                if (wifiManager != null) {
-                    val info = wifiManager.connectionInfo
-                    if (wifiManager.isWifiEnabled && info != null) {
-                        if (info.networkId == -1) {
-                            Log.v(TAG, "Network ID is -1, there is no currently connected network.")
-                        } else {
-                            Log.v(TAG, "Network ID is " + info.networkId)
-                        }
-                        // 自動接続が指示されていた場合は、カメラとの接続処理を行う
-                        connectToCamera()
-                    } else {
-                        if (info == null) {
-                            Log.v(TAG, "NETWORK INFO IS NULL.")
-                        } else {
-                            Log.v(
-                                TAG,
-                                "isWifiEnabled : " + wifiManager.isWifiEnabled + " NetworkId : " + info.networkId
-                            )
-                        }
+                val info = wifiManager.connectionInfo
+                if (wifiManager.isWifiEnabled && info != null)
+                {
+                    Log.v(TAG, "Network ID is " + info.networkId)
+                    // 自動接続が指示されていた場合は、カメラとの接続処理を行う
+                    connectToCamera()
+                }
+                else
+                {
+                    if (info == null)
+                    {
+                        Log.v(TAG, "NETWORK INFO IS NULL.")
+                    }
+                    else
+                    {
+                        Log.v(TAG, "isWifiEnabled : " + wifiManager.isWifiEnabled + " NetworkId : " + info.networkId)
                     }
                 }
             }
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             Log.w(TAG, "onReceiveBroadcastOfConnection() EXCEPTION" + e.message)
             e.printStackTrace()
         }
@@ -132,17 +130,19 @@ class RicohGr2Connection(private val context: FragmentActivity, private val stat
      *
      *
      */
-    override fun alertConnectingFailed(message: String?) {
+    override fun alertConnectingFailed(message: String?)
+    {
         Log.v(TAG, "alertConnectingFailed() : $message")
-        if (context != null) {
+        try
+        {
             val builder: AlertDialog.Builder = AlertDialog.Builder(context)
                 .setTitle(context.getString(ID_STRING_DIALOG_TITLE_CONNECT_FAILED))
                 .setMessage(message)
                 .setPositiveButton(
                     context.getString(ID_STRING_DIALOG_BUTTON_RETRY)
-                ) { dialog, which -> connect() }
+                ) { _, _ -> connect() }
                 .setNeutralButton(ID_STRING_DIALOG_BUTTON_NETWORK_SETTINGS
-                ) { dialog, which ->
+                ) { _, _ ->
                     try {
                         // Wifi 設定画面を表示する
                         context.startActivity(Intent(Settings.ACTION_WIFI_SETTINGS))
@@ -156,7 +156,11 @@ class RicohGr2Connection(private val context: FragmentActivity, private val stat
                         e.printStackTrace()
                     }
                 }
-            context.runOnUiThread({ builder.show() })
+            context.runOnUiThread { builder.show() }
+        }
+        catch (e : Exception)
+        {
+            e.printStackTrace()
         }
     }
 
@@ -169,9 +173,20 @@ class RicohGr2Connection(private val context: FragmentActivity, private val stat
      *
      *
      */
-    override fun forceUpdateConnectionStatus(status: ICameraConnectionStatus.CameraConnectionStatus) {
+    override fun forceUpdateConnectionStatus(status: ICameraConnectionStatus.CameraConnectionStatus)
+    {
         Log.v(TAG, "forceUpdateConnectionStatus()")
         connectionStatus = status
+        if (status == ICameraConnectionStatus.CameraConnectionStatus.CONNECTED)
+        {
+            liveViewControl.startLiveView()
+        }
+        else if (status == ICameraConnectionStatus.CameraConnectionStatus.DISCONNECTED)
+        {
+            liveViewControl.stopLiveView()
+        }
+
+
     }
 
     /**
index e56bd1c..9e4e05d 100644 (file)
@@ -29,95 +29,119 @@ class RicohGr2LiveViewControl(context: Context, executeUrl : String = "http://19
         private const val FETCH_ERROR_MAX = 30
     }
 
-    override fun setUseGR2Command(useGR2cmd: Boolean, useCameraScreen: Boolean) {
-        this.useGR2command = useGR2cmd
+    override fun setUseGR2Command(useGR2Command: Boolean, useCameraScreen: Boolean)
+    {
+        this.useGR2command = useGR2Command
         this.useCameraScreen = useCameraScreen
     }
 
-/*
-    fun changeLiveViewSize(size: String?) {
-        //
-    }
-*/
-
-    override fun startLiveView() {
+    override fun startLiveView()
+    {
         val isCameraScreen = useGR2command && useCameraScreen
-        Log.v(TAG, "startLiveView()")
-        try {
+        Log.v(TAG, "startLiveView() : $isCameraScreen ($useGR2command)")
+        try
+        {
             val thread = Thread {
-                try {
-                    if (isCameraScreen) {
+                try
+                {
+                    if (isCameraScreen)
+                    {
                         start(cameraDisplayUrl)
-                    } else {
+                    }
+                    else
+                    {
                         start(liveViewUrl)
                     }
-                } catch (e: Exception) {
+                }
+                catch (e: Exception)
+                {
                     e.printStackTrace()
                 }
             }
             thread.start()
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
     }
 
-    override fun stopLiveView() {
+    override fun stopLiveView()
+    {
         Log.v(TAG, "stopLiveView()")
         whileFetching = false
     }
 
-    private fun start(streamUrl: String) {
-        if (whileFetching) {
+    private fun start(streamUrl: String)
+    {
+        if (whileFetching)
+        {
             Log.v(TAG, "start() already starting.")
         }
         whileFetching = true
 
-        // A thread for retrieving liveview data from server.
-        try {
+        try
+        {
             val thread = Thread {
                 Log.d(TAG, "Starting retrieving streaming data from server.")
                 var slicer: SimpleLiveViewSlicer? = null
                 var continuousNullDataReceived = 0
-                try {
-                    // Create Slicer to open the stream and parse it.
+                try
+                {
                     slicer = SimpleLiveViewSlicer()
                     slicer.open(streamUrl)
-                    while (whileFetching) {
+                    while (whileFetching)
+                    {
                         val payload: SimpleLiveViewSlicer.Payload? = slicer.nextPayloadForMotionJpeg()
-                        if (payload == null) {
-                            //Log.v(TAG, "Liveview Payload is null.");
+                        if (payload == null)
+                        {
+                            Log.v(TAG, "Liveview Payload is null.")
                             continuousNullDataReceived++
-                            if (continuousNullDataReceived > FETCH_ERROR_MAX) {
+                            if (continuousNullDataReceived > FETCH_ERROR_MAX)
+                            {
                                 Log.d(TAG, " FETCH ERROR MAX OVER ")
                                 break
                             }
                             continue
                         }
                         val jpegData = payload.getJpegData()
-                        if (jpegData != null) {
+                        if (jpegData != null)
+                        {
                             liveViewListener.onUpdateLiveView(jpegData, null)
                         }
+                        else
+                        {
+                            Log.v(TAG, " jpegData is NULL...")
+                        }
                         continuousNullDataReceived = 0
                     }
-                } catch (e: Exception) {
+                }
+                catch (e: Exception)
+                {
                     e.printStackTrace()
-                } finally {
-                    try {
+                }
+                finally
+                {
+                    try
+                    {
                         slicer?.close()
-                    } catch (e: Exception) {
+                    }
+                    catch (e: Exception)
+                    {
                         e.printStackTrace()
                     }
-                    //mJpegQueue.clear();
-                    if (!whileFetching && continuousNullDataReceived > FETCH_ERROR_MAX) {
+                    if (!whileFetching && continuousNullDataReceived > FETCH_ERROR_MAX)
+                    {
                         // 再度ライブビューのスタートをやってみる。
                         whileFetching = false
-                        //continuousNullDataReceived = 0;
                         start(streamUrl)
                     }
                 }
             }
             thread.start()
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
     }
index ecddc0e..395c5d5 100644 (file)
@@ -4,6 +4,7 @@ import android.util.Log
 import android.view.View
 import androidx.appcompat.app.AppCompatActivity
 import androidx.camera.core.CameraSelector
+import jp.osdn.gokigen.gokigenassets.camera.ICameraPreferenceProvider
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraConnectionStatus
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusReceiver
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ILiveViewController
@@ -30,7 +31,7 @@ import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraControl
 import jp.osdn.gokigen.gokigenassets.preference.PreferenceAccessWrapper
 import jp.osdn.gokigen.gokigenassets.scene.IVibrator
 
-class ThetaCameraControl(private val context: AppCompatActivity, private val vibrator : IVibrator, statusReceiver : ICameraStatusReceiver) : ILiveViewController,
+class ThetaCameraControl(private val context: AppCompatActivity, private val vibrator : IVibrator, private val preference: ICameraPreferenceProvider, statusReceiver : ICameraStatusReceiver) : ILiveViewController,
     ICameraControl, View.OnClickListener, ICaptureModeReceiver, ICameraShutter
 {
     private val sessionIdHolder = ThetaSessionHolder()
diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/constants/ICameraConnectionMethods.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/constants/ICameraConnectionMethods.kt
new file mode 100644 (file)
index 0000000..0bd96c4
--- /dev/null
@@ -0,0 +1,13 @@
+package jp.osdn.gokigen.gokigenassets.constants
+
+interface ICameraConnectionMethods
+{
+    companion object
+    {
+        // --- CONNECTION METHOD
+        const val PREFERENCE_CAMERA_METHOD_NONE = "none"
+        const val PREFERENCE_CAMERA_METHOD_CAMERAX = "camerax"
+        const val PREFERENCE_CAMERA_METHOD_THETA = "THETA"
+        const val PREFERENCE_CAMERA_METHOD_PENTAX = "RICOH"
+    }
+}
index cc87e77..07024f7 100644 (file)
@@ -49,7 +49,6 @@ class CameraLiveViewListenerImpl(private val context: Context) : IImageDataRecei
     {
         try
         {
-            //Log.v(TAG, "onUpdateLiveView()")
             insertCache(data, 0)
             isImageReceived = true
             refresh()
@@ -60,7 +59,7 @@ class CameraLiveViewListenerImpl(private val context: Context) : IImageDataRecei
         }
     }
 
-    @SuppressLint("UnsafeExperimentalUsageError")
+    @SuppressLint("UnsafeExperimentalUsageError", "UnsafeOptInUsageError")
     override fun analyze(imageProxy: ImageProxy)
     {
         try
index ba5ae1d..51fc9a7 100644 (file)
@@ -89,8 +89,13 @@ class SimpleLiveViewSlicer
             mHttpConn?.connect()
             if (mHttpConn?.responseCode == HttpURLConnection.HTTP_OK)
             {
+                Log.v(TAG, " LIVEVIEW REQUEST ACCEPTED : ${mHttpConn?.responseCode}")
                 mInputStream = mHttpConn?.inputStream
             }
+            else
+            {
+                Log.v(TAG, " LIVEVIEW REQUEST RESPONSE NG : ${mHttpConn?.responseCode}")
+            }
         }
         catch (e: Exception)
         {
index fb99d3e..b871d0f 100644 (file)
@@ -50,9 +50,6 @@ interface IPreferencePropertyAccessor
         // --- RICOH/PENTAX
         const val GR2_LCD_SLEEP = "gr2_lcd_sleep"
         const val USE_GR2_SPECIAL_COMMAND = "use_gr2_command"
-
-        // --- CONNECTION METHOD
-        const val PREFERENCE_CAMERA_METHOD_NONE = "none"
         const val PREFERENCE_CONNECTION_METHOD = "connection_method"
 
         // --- CAMERA 1  PREFERENCES
index 57b8f02..e5bce1b 100644 (file)
@@ -105,6 +105,8 @@ class PreferenceValueInitializer() : IPreferenceValueInitializer
             {
                 editor.putString(IPreferencePropertyAccessor.THETA_LIVEVIEW_RESOLUTION, IPreferencePropertyAccessor.THETA_LIVEVIEW_RESOLUTION_DEFAULT_VALUE)
             }
+
+            ///// CAMERA METHOD /////
             if (!items.containsKey(IPreferencePropertyAccessor.PREFERENCE_CAMERA_METHOD_1))
             {
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_METHOD_1, IPreferencePropertyAccessor.PREFERENCE_CAMERA_METHOD_1_DEFAULT_VALUE)
@@ -121,6 +123,8 @@ class PreferenceValueInitializer() : IPreferenceValueInitializer
             {
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_METHOD_4, IPreferencePropertyAccessor.PREFERENCE_CAMERA_METHOD_4_DEFAULT_VALUE)
             }
+
+            ///// CONNECTION SEQUENCE /////
             if (!items.containsKey(IPreferencePropertyAccessor.PREFERENCE_CAMERA_SEQUENCE_1))
             {
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_SEQUENCE_1, IPreferencePropertyAccessor.PREFERENCE_CAMERA_SEQUENCE_1_DEFAULT_VALUE)
@@ -138,6 +142,7 @@ class PreferenceValueInitializer() : IPreferenceValueInitializer
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_SEQUENCE_4, IPreferencePropertyAccessor.PREFERENCE_CAMERA_SEQUENCE_4_DEFAULT_VALUE)
             }
 
+            ////////// CAMERA 1 //////////
             if (!items.containsKey(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_1))
             {
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_1, IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_1_DEFAULT_VALUE)
@@ -159,6 +164,7 @@ class PreferenceValueInitializer() : IPreferenceValueInitializer
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION5_1, IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION5_1_DEFAULT_VALUE)
             }
 
+            ////////// CAMERA 2 //////////
             if (!items.containsKey(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_2))
             {
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_2, IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_2_DEFAULT_VALUE)
@@ -180,6 +186,7 @@ class PreferenceValueInitializer() : IPreferenceValueInitializer
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION5_2, IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION5_2_DEFAULT_VALUE)
             }
 
+            ////////// CAMERA 3 //////////
             if (!items.containsKey(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_3))
             {
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_3, IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_3_DEFAULT_VALUE)
@@ -201,6 +208,7 @@ class PreferenceValueInitializer() : IPreferenceValueInitializer
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION5_3, IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION5_3_DEFAULT_VALUE)
             }
 
+            ////////// CAMERA 4 //////////
             if (!items.containsKey(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_4))
             {
                 editor.putString(IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_4, IPreferencePropertyAccessor.PREFERENCE_CAMERA_OPTION1_4_DEFAULT_VALUE)
diff --git a/app/src/main/java/jp/osdn/gokigen/mangle/scene/CameraProvider.kt b/app/src/main/java/jp/osdn/gokigen/mangle/scene/CameraProvider.kt
new file mode 100644 (file)
index 0000000..5b39c7a
--- /dev/null
@@ -0,0 +1,198 @@
+package jp.osdn.gokigen.mangle.scene
+
+import androidx.appcompat.app.AppCompatActivity
+import jp.osdn.gokigen.gokigenassets.camera.CameraPreference
+import jp.osdn.gokigen.gokigenassets.camera.DummyCameraControl
+import jp.osdn.gokigen.gokigenassets.camera.ICameraPreferenceProvider
+import jp.osdn.gokigen.gokigenassets.camera.camerax.operation.CameraControl
+import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraControl
+import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusReceiver
+import jp.osdn.gokigen.gokigenassets.camera.ricohpentax.RicohPentaxCameraControl
+import jp.osdn.gokigen.gokigenassets.camera.theta.ThetaCameraControl
+import jp.osdn.gokigen.gokigenassets.constants.ICameraConnectionMethods.Companion.PREFERENCE_CAMERA_METHOD_CAMERAX
+import jp.osdn.gokigen.gokigenassets.constants.ICameraConnectionMethods.Companion.PREFERENCE_CAMERA_METHOD_NONE
+import jp.osdn.gokigen.gokigenassets.constants.ICameraConnectionMethods.Companion.PREFERENCE_CAMERA_METHOD_PENTAX
+import jp.osdn.gokigen.gokigenassets.constants.ICameraConnectionMethods.Companion.PREFERENCE_CAMERA_METHOD_THETA
+import jp.osdn.gokigen.gokigenassets.preference.PreferenceAccessWrapper
+import jp.osdn.gokigen.gokigenassets.scene.IInformationReceiver
+import jp.osdn.gokigen.gokigenassets.scene.IVibrator
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_METHOD_1
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_METHOD_1_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_METHOD_2
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_METHOD_2_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_METHOD_3
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_METHOD_3_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_METHOD_4
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_METHOD_4_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION1_1
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION1_1_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION1_2
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION1_2_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION1_3
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION1_3_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION1_4
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION1_4_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION2_1
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION2_1_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION2_2
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION2_2_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION2_3
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION2_3_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION2_4
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION2_4_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION3_1
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION3_1_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION3_2
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION3_2_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION3_3
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION3_3_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION3_4
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION3_4_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION4_1
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION4_1_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION4_2
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION4_2_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION4_3
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION4_3_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION4_4
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION4_4_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION5_1
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION5_1_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION5_2
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION5_2_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION5_3
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION5_3_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION5_4
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_OPTION5_4_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_SEQUENCE_1
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_SEQUENCE_1_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_SEQUENCE_2
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_SEQUENCE_2_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_SEQUENCE_3
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_SEQUENCE_3_DEFAULT_VALUE
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_SEQUENCE_4
+import jp.osdn.gokigen.mangle.preference.IPreferencePropertyAccessor.Companion.PREFERENCE_CAMERA_SEQUENCE_4_DEFAULT_VALUE
+
+class CameraProvider(private val activity: AppCompatActivity, private val informationNotify: IInformationReceiver, private val vibrator : IVibrator, private val statusReceiver : ICameraStatusReceiver)
+{
+    private var cameraXisCreated = false
+    private lateinit var cameraXControl: ICameraControl
+
+    fun decideCameraControl(preferenceKey : String) : ICameraControl
+    {
+        try
+        {
+            val wrapper = PreferenceAccessWrapper(activity)
+            val cameraPreference = when (preferenceKey) {
+                PREFERENCE_CAMERA_METHOD_1 -> setupCameraPreference1(wrapper)
+                PREFERENCE_CAMERA_METHOD_2 -> setupCameraPreference2(wrapper)
+                PREFERENCE_CAMERA_METHOD_3 -> setupCameraPreference3(wrapper)
+                PREFERENCE_CAMERA_METHOD_4 -> setupCameraPreference4(wrapper)
+                else -> setupCameraPreference0()
+            }
+            return (when (cameraPreference.getCameraMethod()) {
+                PREFERENCE_CAMERA_METHOD_NONE -> DummyCameraControl()
+                PREFERENCE_CAMERA_METHOD_CAMERAX -> prepareCameraXControl(cameraPreference)
+                PREFERENCE_CAMERA_METHOD_THETA -> prepareThetaCameraControl(cameraPreference)
+                PREFERENCE_CAMERA_METHOD_PENTAX -> preparePentaxCameraControl(cameraPreference)
+                else -> DummyCameraControl()
+            })
+        }
+        catch (e : Exception)
+        {
+            e.printStackTrace()
+        }
+        return (DummyCameraControl())
+    }
+
+    fun getCameraXControl() : ICameraControl
+    {
+        try
+        {
+            return (prepareCameraXControl(setupCameraPreference0()))
+        }
+        catch (e : Exception)
+        {
+            e.printStackTrace()
+        }
+        return (DummyCameraControl())
+    }
+
+    private fun setupCameraPreference0() : ICameraPreferenceProvider
+    {
+        return (CameraPreference(PREFERENCE_CAMERA_METHOD_NONE))
+    }
+
+    private fun setupCameraPreference1(wrapper : PreferenceAccessWrapper) : ICameraPreferenceProvider
+    {
+        val method  = wrapper.getString(PREFERENCE_CAMERA_METHOD_1, PREFERENCE_CAMERA_METHOD_1_DEFAULT_VALUE)
+        val sequence  = wrapper.getString(PREFERENCE_CAMERA_SEQUENCE_1, PREFERENCE_CAMERA_SEQUENCE_1_DEFAULT_VALUE)
+        val option1  = wrapper.getString(PREFERENCE_CAMERA_OPTION1_1, PREFERENCE_CAMERA_OPTION1_1_DEFAULT_VALUE)
+        val option2  = wrapper.getString(PREFERENCE_CAMERA_OPTION2_1, PREFERENCE_CAMERA_OPTION2_1_DEFAULT_VALUE)
+        val option3  = wrapper.getString(PREFERENCE_CAMERA_OPTION3_1, PREFERENCE_CAMERA_OPTION3_1_DEFAULT_VALUE)
+        val option4  = wrapper.getString(PREFERENCE_CAMERA_OPTION4_1, PREFERENCE_CAMERA_OPTION4_1_DEFAULT_VALUE)
+        val option5  = wrapper.getString(PREFERENCE_CAMERA_OPTION5_1, PREFERENCE_CAMERA_OPTION5_1_DEFAULT_VALUE)
+
+        return (CameraPreference(method, sequence, option1, option2, option3, option4, option5))
+    }
+
+    private fun setupCameraPreference2(wrapper : PreferenceAccessWrapper) : ICameraPreferenceProvider
+    {
+        val method  = wrapper.getString(PREFERENCE_CAMERA_METHOD_2, PREFERENCE_CAMERA_METHOD_2_DEFAULT_VALUE)
+        val sequence  = wrapper.getString(PREFERENCE_CAMERA_SEQUENCE_2, PREFERENCE_CAMERA_SEQUENCE_2_DEFAULT_VALUE)
+        val option1  = wrapper.getString(PREFERENCE_CAMERA_OPTION1_2, PREFERENCE_CAMERA_OPTION1_2_DEFAULT_VALUE)
+        val option2  = wrapper.getString(PREFERENCE_CAMERA_OPTION2_2, PREFERENCE_CAMERA_OPTION2_2_DEFAULT_VALUE)
+        val option3  = wrapper.getString(PREFERENCE_CAMERA_OPTION3_2, PREFERENCE_CAMERA_OPTION3_2_DEFAULT_VALUE)
+        val option4  = wrapper.getString(PREFERENCE_CAMERA_OPTION4_2, PREFERENCE_CAMERA_OPTION4_2_DEFAULT_VALUE)
+        val option5  = wrapper.getString(PREFERENCE_CAMERA_OPTION5_2, PREFERENCE_CAMERA_OPTION5_2_DEFAULT_VALUE)
+
+        return (CameraPreference(method, sequence, option1, option2, option3, option4, option5))
+    }
+
+    private fun setupCameraPreference3(wrapper : PreferenceAccessWrapper) : ICameraPreferenceProvider
+    {
+        val method  = wrapper.getString(PREFERENCE_CAMERA_METHOD_3, PREFERENCE_CAMERA_METHOD_3_DEFAULT_VALUE)
+        val sequence  = wrapper.getString(PREFERENCE_CAMERA_SEQUENCE_3, PREFERENCE_CAMERA_SEQUENCE_3_DEFAULT_VALUE)
+        val option1  = wrapper.getString(PREFERENCE_CAMERA_OPTION1_3, PREFERENCE_CAMERA_OPTION1_3_DEFAULT_VALUE)
+        val option2  = wrapper.getString(PREFERENCE_CAMERA_OPTION2_3, PREFERENCE_CAMERA_OPTION2_3_DEFAULT_VALUE)
+        val option3  = wrapper.getString(PREFERENCE_CAMERA_OPTION3_3, PREFERENCE_CAMERA_OPTION3_3_DEFAULT_VALUE)
+        val option4  = wrapper.getString(PREFERENCE_CAMERA_OPTION4_3, PREFERENCE_CAMERA_OPTION4_3_DEFAULT_VALUE)
+        val option5  = wrapper.getString(PREFERENCE_CAMERA_OPTION5_3, PREFERENCE_CAMERA_OPTION5_3_DEFAULT_VALUE)
+
+        return (CameraPreference(method, sequence, option1, option2, option3, option4, option5))
+    }
+
+    private fun setupCameraPreference4(wrapper : PreferenceAccessWrapper) : ICameraPreferenceProvider
+    {
+        val method  = wrapper.getString(PREFERENCE_CAMERA_METHOD_4, PREFERENCE_CAMERA_METHOD_4_DEFAULT_VALUE)
+        val sequence  = wrapper.getString(PREFERENCE_CAMERA_SEQUENCE_4, PREFERENCE_CAMERA_SEQUENCE_4_DEFAULT_VALUE)
+        val option1  = wrapper.getString(PREFERENCE_CAMERA_OPTION1_4, PREFERENCE_CAMERA_OPTION1_4_DEFAULT_VALUE)
+        val option2  = wrapper.getString(PREFERENCE_CAMERA_OPTION2_4, PREFERENCE_CAMERA_OPTION2_4_DEFAULT_VALUE)
+        val option3  = wrapper.getString(PREFERENCE_CAMERA_OPTION3_4, PREFERENCE_CAMERA_OPTION3_4_DEFAULT_VALUE)
+        val option4  = wrapper.getString(PREFERENCE_CAMERA_OPTION4_4, PREFERENCE_CAMERA_OPTION4_4_DEFAULT_VALUE)
+        val option5  = wrapper.getString(PREFERENCE_CAMERA_OPTION5_4, PREFERENCE_CAMERA_OPTION5_4_DEFAULT_VALUE)
+
+        return (CameraPreference(method, sequence, option1, option2, option3, option4, option5))
+    }
+
+    private fun prepareThetaCameraControl(cameraPreference : ICameraPreferenceProvider) : ICameraControl
+    {
+        return (ThetaCameraControl(activity, vibrator, cameraPreference, statusReceiver))
+    }
+
+    private fun preparePentaxCameraControl(cameraPreference : ICameraPreferenceProvider) : ICameraControl
+    {
+        return (RicohPentaxCameraControl(activity, vibrator, cameraPreference, statusReceiver))
+    }
+
+    private fun prepareCameraXControl(cameraPreference : ICameraPreferenceProvider): ICameraControl
+    {
+        if ((cameraXisCreated)&&(::cameraXControl.isInitialized))
+        {
+            return (cameraXControl)
+        }
+        cameraXControl = CameraControl(activity, cameraPreference)
+        cameraXisCreated = true
+        return (cameraXControl)
+    }
+}
\ No newline at end of file
index 4d36836..19e8228 100644 (file)
@@ -6,11 +6,8 @@ import androidx.appcompat.app.AppCompatActivity
 import androidx.camera.core.CameraSelector
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.FragmentTransaction
-import jp.osdn.gokigen.gokigenassets.camera.DummyCameraControl
 import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusReceiver
-import jp.osdn.gokigen.gokigenassets.camera.theta.ThetaCameraControl
 import jp.osdn.gokigen.gokigenassets.liveview.LiveImageViewFragment
-import jp.osdn.gokigen.gokigenassets.camera.camerax.operation.CameraControl
 import jp.osdn.gokigen.gokigenassets.preference.MainPreferenceFragment
 import jp.osdn.gokigen.gokigenassets.preference.PreferenceAccessWrapper
 import jp.osdn.gokigen.gokigenassets.camera.camerax.preview.PreviewFragment
@@ -31,8 +28,9 @@ import jp.osdn.gokigen.mangle.preference.PreferenceValueInitializer
 
 class SceneChanger(private val activity: AppCompatActivity, private val informationNotify: IInformationReceiver, vibrator : IVibrator, statusReceiver : ICameraStatusReceiver) : IChangeScene, IChangeSceneBasic
 {
-    private var cameraXisCreated = false
-    private lateinit var cameraControl: ICameraControl
+    private val cameraProvider = CameraProvider(activity, informationNotify, vibrator, statusReceiver)
+
+    private val cameraControl0 = cameraProvider.getCameraXControl()
     private val cameraControl1: ICameraControl
     private val cameraControl2: ICameraControl
     private val cameraControl3: ICameraControl
@@ -48,10 +46,10 @@ class SceneChanger(private val activity: AppCompatActivity, private val informat
     {
         Log.v(TAG, " SceneChanger is created. ")
 
-        cameraControl1 = DummyCameraControl() //decideCameraControl(PREFERENCE_CAMERA_METHOD_1, activity, vibrator, statusReceiver)
-        cameraControl2 = decideCameraControl(PREFERENCE_CAMERA_METHOD_2, activity, vibrator, statusReceiver)
-        cameraControl3 = decideCameraControl(PREFERENCE_CAMERA_METHOD_3, activity, vibrator, statusReceiver)
-        cameraControl4 = DummyCameraControl() //decideCameraControl(PREFERENCE_CAMERA_METHOD_4, activity, vibrator, statusReceiver)
+        cameraControl1 = cameraProvider.decideCameraControl(PREFERENCE_CAMERA_METHOD_1)
+        cameraControl2 = cameraProvider.decideCameraControl(PREFERENCE_CAMERA_METHOD_2)
+        cameraControl3 = cameraProvider.decideCameraControl(PREFERENCE_CAMERA_METHOD_3)
+        cameraControl4 = cameraProvider.decideCameraControl(PREFERENCE_CAMERA_METHOD_4)
 
         cameraControl1.initialize()
         cameraControl2.initialize()
@@ -59,39 +57,14 @@ class SceneChanger(private val activity: AppCompatActivity, private val informat
         cameraControl4.initialize()
     }
 
-    private fun decideCameraControl(preferenceKey : String, activity: AppCompatActivity, vibrator : IVibrator, statusReceiver : ICameraStatusReceiver) : ICameraControl
-    {
-        try
-        {
-            if ((cameraXisCreated)&&(::cameraControl.isInitialized))
-            {
-                return (cameraControl)
-            }
-            cameraControl = CameraControl(activity)
-            cameraXisCreated = true
-            return (cameraControl)
-        }
-        catch (e : Exception)
-        {
-            e.printStackTrace()
-        }
-        return (DummyCameraControl())
-    }
-
-
     private fun initializeFragmentForPreview()
     {
-        if (!::cameraControl.isInitialized)
-        {
-            cameraControl = CameraControl(activity)
-            cameraXisCreated = true
-        }
         if (!::previewFragment.isInitialized)
         {
-            previewFragment = PreviewFragment.newInstance(cameraControl)
+            previewFragment = PreviewFragment.newInstance(cameraControl0)
         }
         setDefaultFragment(previewFragment)
-        cameraControl.startCamera()
+        cameraControl0.startCamera()
 
         val msg = activity.getString(R.string.app_name) + " : " + " camerax"
         informationNotify.updateMessage(msg, isBold = false, isColor = true, color = Color.LTGRAY)
index 0a86da2..cfe15c8 100644 (file)
@@ -1,6 +1,6 @@
 // Top-level build file where you can add configuration options common to all sub-projects/modules.
 buildscript {
-    ext.kotlin_version = "1.5.0"
+    ext.kotlin_version = "1.5.10"
     repositories {
         google()
         jcenter()