OSDN Git Service

Thetaのライブビューと撮影機能を搭載。(ただし、ライブビューの再開に改善の余地あり。)
authorMRSa <mrsa@myad.jp>
Sat, 25 Jan 2020 12:52:37 +0000 (21:52 +0900)
committerMRSa <mrsa@myad.jp>
Sat, 25 Jan 2020 12:52:37 +0000 (21:52 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/theta/operation/ThetaSingleShotControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/theta/wrapper/ThetaCaptureControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/theta/wrapper/ThetaInterfaceProvider.java
app/src/main/java/net/osdn/gokigen/a01d/camera/theta/wrapper/ThetaLiveViewControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/theta/wrapper/connection/ThetaCameraConnectSequence.java
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml

index 12cd19e..72177a0 100644 (file)
@@ -7,6 +7,7 @@ import android.util.Log;
 
 import androidx.annotation.NonNull;
 
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
 import net.osdn.gokigen.a01d.camera.theta.wrapper.IThetaSessionIdProvider;
 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
@@ -17,15 +18,17 @@ public class ThetaSingleShotControl
 {
     private final String TAG = toString();
     private final IThetaSessionIdProvider sessionIdProvider;
-    private final IAutoFocusFrameDisplay frameDisplayer;
+    private final ILiveViewControl liveViewControl;
+    private final IIndicatorControl indicator;
     private boolean useThetaV21 = false;
     private int timeoutMs = 6000;
 
 
-    public ThetaSingleShotControl(@NonNull Context context, @NonNull final IThetaSessionIdProvider sessionIdProvider, @NonNull IAutoFocusFrameDisplay frameDisplayer, @NonNull IIndicatorControl indicator)
+    public ThetaSingleShotControl(@NonNull Context context, @NonNull final IThetaSessionIdProvider sessionIdProvider, @NonNull IIndicatorControl indicator, @NonNull ILiveViewControl liveViewControl)
     {
         this.sessionIdProvider = sessionIdProvider;
-        this.frameDisplayer = frameDisplayer;
+        this.liveViewControl = liveViewControl;
+        this.indicator = indicator;
         try
         {
             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
@@ -48,7 +51,7 @@ public class ThetaSingleShotControl
         Log.v(TAG, "singleShot()");
         try
         {
-            Thread thread = new Thread(new Runnable()
+            final Thread thread = new Thread(new Runnable()
             {
                 @Override
                 public void run()
@@ -62,12 +65,25 @@ public class ThetaSingleShotControl
                         {
                             Log.v(TAG, "singleShot() reply is null.");
                         }
+                        else
+                        {
+                            Log.v(TAG, " singleShot() : " + result);
+                            indicator.onShootingStatusUpdate(IIndicatorControl.shootingStatus.Starting);
+
+                            // TODO: 画像処理が終わるまで待つ
+                            waitMs(2000);
+
+                            // ライブビューのの再実行を指示する
+                            indicator.onShootingStatusUpdate(IIndicatorControl.shootingStatus.Stopping);
+                            liveViewControl.stopLiveView();
+                            waitMs(500);
+                            liveViewControl.startLiveView();
+                        }
                     }
                     catch (Exception e)
                     {
                         e.printStackTrace();
                     }
-                    frameDisplayer.hideFocusFrame();
                 }
             });
             thread.start();
@@ -77,4 +93,17 @@ public class ThetaSingleShotControl
             e.printStackTrace();
         }
     }
+
+    private void waitMs(int waitMs)
+    {
+        try
+        {
+            Thread.sleep(waitMs);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
 }
index e11ad86..58d74f0 100644 (file)
@@ -5,12 +5,8 @@ import android.util.Log;
 import androidx.annotation.NonNull;
 
 import net.osdn.gokigen.a01d.camera.ICaptureControl;
-import net.osdn.gokigen.a01d.camera.olympuspen.operation.OlympusPenSingleShotControl;
-import net.osdn.gokigen.a01d.camera.panasonic.operation.PanasonicCameraCaptureControl;
-import net.osdn.gokigen.a01d.camera.panasonic.operation.takepicture.SingleShotControl;
-import net.osdn.gokigen.a01d.camera.panasonic.wrapper.IPanasonicCamera;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
 import net.osdn.gokigen.a01d.camera.theta.operation.ThetaSingleShotControl;
-import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
 
 public class ThetaCaptureControl implements ICaptureControl
@@ -18,9 +14,9 @@ public class ThetaCaptureControl implements ICaptureControl
     private static final String TAG = ThetaCaptureControl.class.getSimpleName();
     private final ThetaSingleShotControl singleShotControl;
 
-    public ThetaCaptureControl(@NonNull Context context, @NonNull final IThetaSessionIdProvider sessionIdProvider, @NonNull IAutoFocusFrameDisplay frameDisplayer, @NonNull IIndicatorControl indicator)
+    ThetaCaptureControl(@NonNull Context context, @NonNull final IThetaSessionIdProvider sessionIdProvider, @NonNull IIndicatorControl indicator, @NonNull ILiveViewControl liveViewControl)
     {
-        singleShotControl = new ThetaSingleShotControl(context, sessionIdProvider, frameDisplayer, indicator);
+        singleShotControl = new ThetaSingleShotControl(context, sessionIdProvider, indicator, liveViewControl);
     }
 
     /**
index 373b180..a0683b9 100644 (file)
@@ -90,7 +90,7 @@ public class ThetaInterfaceProvider implements IThetaInterfaceProvider, IDisplay
     {
         Log.v(TAG, "injectDisplay()");
         focusControl = new ThetaFocusControl(frameDisplayer);
-        captureControl = new ThetaCaptureControl(activity, this, frameDisplayer, indicator);
+        captureControl = new ThetaCaptureControl(activity, this, indicator, liveViewControl);
     }
 
     @Override
index 6026aef..45c0a2a 100644 (file)
@@ -49,7 +49,7 @@ public class ThetaLiveViewControl implements ILiveViewControl
     @Override
     public void startLiveView()
     {
-        Log.v(TAG, "startLiveView()");
+        Log.v(TAG, " startLiveView()");
         //prepare();
         try
         {
index cc4d68f..e2a7cb4 100644 (file)
@@ -101,8 +101,23 @@ public class ThetaCameraConnectSequence implements Runnable
 
             String response2 = SimpleHttpClient.httpPost(getStateUrl, "", TIMEOUT_MS);
             Log.v(TAG, " " + getStateUrl + " " + response2);
-
-            onConnectNotify();
+           if (response2.length() > 0)
+           {
+               try
+               {
+                   JSONObject object = new JSONObject(response2);
+                   String sessionId = object.getJSONObject("state").getString("sessionId");
+                   sessionIdNotifier.receivedSessionId(sessionId);
+                   onConnectNotify();
+                   return;
+               }
+               catch (Exception e)
+               {
+                   e.printStackTrace();
+               }
+           }
+           // 応答なし、を応答する。
+           onConnectError(context.getString(R.string.theta_connect_response_ng));
         }
         catch (Exception e)
         {
index 6f8e03f..9385e37 100644 (file)
 
     <string name="pref_use_osc_theta_v21">THETA Web API v2.1の使用</string>
     <string name="pref_summary_use_osc_theta_v21"> </string>
+    <string name="theta_connect_response_ng">応答がありません。</string>
 
 </resources>
index 796534c..01e18fa 100644 (file)
 
     <string name="pref_use_osc_theta_v21">Use THETA Web API v2.1</string>
     <string name="pref_summary_use_osc_theta_v21"> </string>
+    <string name="theta_connect_response_ng">Did not receive any response.</string>
 
 </resources>