OSDN Git Service

GR2 / PENTAXモードの自動認識・切り替えをできるようにした。
authorMRSa <mrsa@myad.jp>
Mon, 1 Jun 2020 14:25:27 +0000 (23:25 +0900)
committerMRSa <mrsa@myad.jp>
Mon, 1 Jun 2020 14:25:27 +0000 (23:25 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/operation/RicohGr2CameraCaptureControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/operation/RicohGr2CameraFocusControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/operation/takepicture/RicohGr2AutoFocusControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/operation/takepicture/RicohGr2SingleShotControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/wrapper/IUsePentaxCommand.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/wrapper/RicohGr2InterfaceProvider.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/wrapper/RicohGr2LiveViewControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/wrapper/connection/RicohGr2CameraConnectSequence.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/wrapper/connection/RicohGr2Connection.java

index 0faf62e..cd6ac3a 100644 (file)
@@ -1,8 +1,8 @@
 package net.osdn.gokigen.a01d.camera.ricohgr2.operation;
 
 package net.osdn.gokigen.a01d.camera.ricohgr2.operation;
 
-import android.content.Context;
 import net.osdn.gokigen.a01d.camera.ICaptureControl;
 import net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture.RicohGr2SingleShotControl;
 import net.osdn.gokigen.a01d.camera.ICaptureControl;
 import net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture.RicohGr2SingleShotControl;
+import net.osdn.gokigen.a01d.camera.ricohgr2.wrapper.IUsePentaxCommand;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 
 import androidx.annotation.NonNull;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 
 import androidx.annotation.NonNull;
@@ -11,9 +11,9 @@ public class RicohGr2CameraCaptureControl implements ICaptureControl
 {
     private final RicohGr2SingleShotControl singleShotControl;
 
 {
     private final RicohGr2SingleShotControl singleShotControl;
 
-    public RicohGr2CameraCaptureControl(@NonNull Context context, @NonNull IAutoFocusFrameDisplay frameDisplayer)
+    public RicohGr2CameraCaptureControl(@NonNull IAutoFocusFrameDisplay frameDisplayer, @NonNull IUsePentaxCommand usePentaxCommand)
     {
     {
-        singleShotControl = new RicohGr2SingleShotControl(context, frameDisplayer);
+        singleShotControl = new RicohGr2SingleShotControl(frameDisplayer, usePentaxCommand);
     }
 
     @Override
     }
 
     @Override
index cf88d30..78b86bd 100644 (file)
@@ -1,12 +1,12 @@
 package net.osdn.gokigen.a01d.camera.ricohgr2.operation;
 
 package net.osdn.gokigen.a01d.camera.ricohgr2.operation;
 
-import android.content.Context;
 import android.graphics.PointF;
 import android.util.Log;
 import android.view.MotionEvent;
 
 import net.osdn.gokigen.a01d.camera.IFocusingControl;
 import net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture.RicohGr2AutoFocusControl;
 import android.graphics.PointF;
 import android.util.Log;
 import android.view.MotionEvent;
 
 import net.osdn.gokigen.a01d.camera.IFocusingControl;
 import net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture.RicohGr2AutoFocusControl;
+import net.osdn.gokigen.a01d.camera.ricohgr2.wrapper.IUsePentaxCommand;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
 
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
 
@@ -18,10 +18,10 @@ public class RicohGr2CameraFocusControl implements IFocusingControl
     private final RicohGr2AutoFocusControl afControl;
     private final IAutoFocusFrameDisplay frameDisplay;
 
     private final RicohGr2AutoFocusControl afControl;
     private final IAutoFocusFrameDisplay frameDisplay;
 
-    public RicohGr2CameraFocusControl(@NonNull Context context, @NonNull final IAutoFocusFrameDisplay frameDisplayer, @NonNull final IIndicatorControl indicator)
+    public RicohGr2CameraFocusControl(@NonNull final IAutoFocusFrameDisplay frameDisplayer, @NonNull final IIndicatorControl indicator, @NonNull IUsePentaxCommand usePentaxCommand)
     {
         this.frameDisplay = frameDisplayer;
     {
         this.frameDisplay = frameDisplayer;
-        this.afControl = new RicohGr2AutoFocusControl(context, frameDisplayer, indicator);
+        this.afControl = new RicohGr2AutoFocusControl(frameDisplayer, indicator, usePentaxCommand);
     }
 
     @Override
     }
 
     @Override
index 55df4c1..14dd0c9 100644 (file)
@@ -1,16 +1,13 @@
 package net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture;
 
 package net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture;
 
-import android.content.Context;
-import android.content.SharedPreferences;
 import android.graphics.PointF;
 import android.graphics.RectF;
 import android.graphics.PointF;
 import android.graphics.RectF;
-import android.preference.PreferenceManager;
 import android.util.Log;
 
 import android.util.Log;
 
+import net.osdn.gokigen.a01d.camera.ricohgr2.wrapper.IUsePentaxCommand;
 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
-import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
 
 import org.json.JSONObject;
 
 
 import org.json.JSONObject;
 
@@ -25,7 +22,7 @@ public class RicohGr2AutoFocusControl
     private static final String TAG = RicohGr2AutoFocusControl.class.getSimpleName();
     private final IIndicatorControl indicator;
     private final IAutoFocusFrameDisplay frameDisplayer;
     private static final String TAG = RicohGr2AutoFocusControl.class.getSimpleName();
     private final IIndicatorControl indicator;
     private final IAutoFocusFrameDisplay frameDisplayer;
-    private String lockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus/lock";    // Pentax機の場合は /v1/lens/focus
+    private final IUsePentaxCommand usePentaxCommand;
     private String unlockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus/unlock";
     private String halfPressShutterUrl = "http://192.168.0.1/_gr";
     private int timeoutMs = 6000;
     private String unlockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus/unlock";
     private String halfPressShutterUrl = "http://192.168.0.1/_gr";
     private int timeoutMs = 6000;
@@ -35,34 +32,11 @@ public class RicohGr2AutoFocusControl
      *
      *
      */
      *
      *
      */
-    public RicohGr2AutoFocusControl(@NonNull Context context, @NonNull final IAutoFocusFrameDisplay frameDisplayer, final IIndicatorControl indicator)
+    public RicohGr2AutoFocusControl(@NonNull final IAutoFocusFrameDisplay frameDisplayer, final IIndicatorControl indicator, @NonNull IUsePentaxCommand usePentaxCommand)
     {
         this.frameDisplayer = frameDisplayer;
         this.indicator = indicator;
     {
         this.frameDisplayer = frameDisplayer;
         this.indicator = indicator;
-
-        prepare(context);
-    }
-
-    /**
-     *
-     *
-     */
-    private void prepare(@NonNull Context context)
-    {
-        lockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus/lock";
-        try
-        {
-            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
-            if (preferences.getBoolean(IPreferencePropertyAccessor.USE_PENTAX_AUTOFOCUS, false))
-            {
-                lockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus";
-            }
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-        Log.v(TAG, "FOCUS LOCK URL : " + lockAutoFocusUrl);
+        this.usePentaxCommand = usePentaxCommand;
     }
 
     /**
     }
 
     /**
@@ -84,6 +58,7 @@ public class RicohGr2AutoFocusControl
                     {
                         showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Running, 0.0);
 
                     {
                         showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Running, 0.0);
 
+                        String lockAutoFocusUrl = (usePentaxCommand.getUsePentaxCommand()) ? "http://192.168.0.1/v1/lens/focus" : "http://192.168.0.1/v1/lens/focus/lock";
                         //int posX = (int) (Math.round(point.x * 100.0));
                         //int posY = (int) (Math.round(point.y * 100.0));
                         String postData = "pos=" + ( (int) (Math.round(point.x * 100.0))) + "," + ((int) (Math.round(point.y * 100.0)));
                         //int posX = (int) (Math.round(point.x * 100.0));
                         //int posY = (int) (Math.round(point.y * 100.0));
                         String postData = "pos=" + ( (int) (Math.round(point.x * 100.0))) + "," + ((int) (Math.round(point.y * 100.0)));
index 1d70406..117c072 100644 (file)
@@ -1,13 +1,10 @@
 package net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture;
 
 package net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture;
 
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
 import android.util.Log;
 
 import android.util.Log;
 
+import net.osdn.gokigen.a01d.camera.ricohgr2.wrapper.IUsePentaxCommand;
 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
-import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
 
 import androidx.annotation.NonNull;
 
 
 import androidx.annotation.NonNull;
 
@@ -21,35 +18,17 @@ public class RicohGr2SingleShotControl
     private static final String TAG = RicohGr2SingleShotControl.class.getSimpleName();
     private final String shootUrl = "http://192.168.0.1/v1/camera/shoot";
     private final IAutoFocusFrameDisplay frameDisplayer;
     private static final String TAG = RicohGr2SingleShotControl.class.getSimpleName();
     private final String shootUrl = "http://192.168.0.1/v1/camera/shoot";
     private final IAutoFocusFrameDisplay frameDisplayer;
-    private boolean usePentaxDslr = false;
+    private final IUsePentaxCommand usePentaxCommand;
     private int timeoutMs = 6000;
 
     /**
      *
      *
      */
     private int timeoutMs = 6000;
 
     /**
      *
      *
      */
-    public RicohGr2SingleShotControl(@NonNull Context context, @NonNull IAutoFocusFrameDisplay frameDisplayer)
+    public RicohGr2SingleShotControl(IAutoFocusFrameDisplay frameDisplayer, @NonNull IUsePentaxCommand usePentaxCommand)
     {
         this.frameDisplayer = frameDisplayer;
     {
         this.frameDisplayer = frameDisplayer;
-        prepare(context);
-    }
-
-    /**
-     *
-     *
-     */
-    private void prepare(@NonNull Context context)
-    {
-        try
-        {
-            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
-            usePentaxDslr = preferences.getBoolean(IPreferencePropertyAccessor.USE_PENTAX_AUTOFOCUS, false);
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-        Log.v(TAG, "USE PENTAX DSLR : " + usePentaxDslr);
+        this.usePentaxCommand = usePentaxCommand;
     }
 
     /**
     }
 
     /**
@@ -68,7 +47,7 @@ public class RicohGr2SingleShotControl
                 {
                     try
                     {
                 {
                     try
                     {
-                        String postData = (usePentaxDslr) ? "" : "af=camera";
+                        String postData = (usePentaxCommand.getUsePentaxCommand()) ? "" : "af=camera";
                         String result = SimpleHttpClient.httpPost(shootUrl, postData, timeoutMs);
                         if ((result == null)||(result.length() < 1))
                         {
                         String result = SimpleHttpClient.httpPost(shootUrl, postData, timeoutMs);
                         if ((result == null)||(result.length() < 1))
                         {
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/wrapper/IUsePentaxCommand.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/wrapper/IUsePentaxCommand.java
new file mode 100644 (file)
index 0000000..7668598
--- /dev/null
@@ -0,0 +1,7 @@
+package net.osdn.gokigen.a01d.camera.ricohgr2.wrapper;
+
+public interface IUsePentaxCommand
+{
+    void setUsePentaxCommand(boolean usePentaxCommand);
+    boolean getUsePentaxCommand();
+}
index a895ad5..0e434e6 100644 (file)
@@ -1,6 +1,8 @@
 package net.osdn.gokigen.a01d.camera.ricohgr2.wrapper;
 
 import android.app.Activity;
 package net.osdn.gokigen.a01d.camera.ricohgr2.wrapper;
 
 import android.app.Activity;
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
 import android.util.Log;
 
 import net.osdn.gokigen.a01d.camera.ICameraConnection;
 import android.util.Log;
 
 import net.osdn.gokigen.a01d.camera.ICameraConnection;
@@ -20,6 +22,7 @@ import net.osdn.gokigen.a01d.camera.IDisplayInjector;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
+import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
 
 import androidx.annotation.NonNull;
 
 
 import androidx.annotation.NonNull;
 
@@ -27,7 +30,7 @@ import androidx.annotation.NonNull;
  *
  *
  */
  *
  *
  */
-public class RicohGr2InterfaceProvider implements IRicohGr2InterfaceProvider, IDisplayInjector
+public class RicohGr2InterfaceProvider implements IRicohGr2InterfaceProvider, IDisplayInjector, IUsePentaxCommand
 {
     private final String TAG = toString();
     private final Activity activity;
 {
     private final String TAG = toString();
     private final Activity activity;
@@ -38,6 +41,8 @@ public class RicohGr2InterfaceProvider implements IRicohGr2InterfaceProvider, ID
     private RicohGr2CameraZoomLensControl zoomControl;
     private RicohGr2CameraFocusControl focusControl;
 
     private RicohGr2CameraZoomLensControl zoomControl;
     private RicohGr2CameraFocusControl focusControl;
 
+    private boolean usePentaxCommand = false;
+
     /**
      *
      *
     /**
      *
      *
@@ -46,8 +51,8 @@ public class RicohGr2InterfaceProvider implements IRicohGr2InterfaceProvider, ID
     {
         this.activity = context;
         //this.provider = provider;
     {
         this.activity = context;
         //this.provider = provider;
-        gr2Connection = new RicohGr2Connection(context, provider);
-        liveViewControl = new RicohGr2LiveViewControl(context);
+        gr2Connection = new RicohGr2Connection(context, provider, this);
+        liveViewControl = new RicohGr2LiveViewControl(context, this);
         zoomControl = new RicohGr2CameraZoomLensControl();
     }
 
         zoomControl = new RicohGr2CameraZoomLensControl();
     }
 
@@ -68,8 +73,8 @@ public class RicohGr2InterfaceProvider implements IRicohGr2InterfaceProvider, ID
     public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
     {
         Log.v(TAG, "injectDisplay()");
     public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
     {
         Log.v(TAG, "injectDisplay()");
-        focusControl = new RicohGr2CameraFocusControl(activity, frameDisplayer, indicator);
-        captureControl = new RicohGr2CameraCaptureControl(activity, frameDisplayer);
+        focusControl = new RicohGr2CameraFocusControl(frameDisplayer, indicator, this);
+        captureControl = new RicohGr2CameraCaptureControl(frameDisplayer, this);
     }
 
     /**
     }
 
     /**
@@ -134,4 +139,28 @@ public class RicohGr2InterfaceProvider implements IRicohGr2InterfaceProvider, ID
     public IDisplayInjector getDisplayInjector() {
         return (this);
     }
     public IDisplayInjector getDisplayInjector() {
         return (this);
     }
+
+    @Override
+    public void setUsePentaxCommand(boolean usePentaxCommand)
+    {
+        this.usePentaxCommand = usePentaxCommand;
+        try
+        {
+            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+            SharedPreferences.Editor editor = preferences.edit();
+            editor.putBoolean(IPreferencePropertyAccessor.USE_PENTAX_AUTOFOCUS, usePentaxCommand);
+            editor.apply();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        Log.v(TAG, " setUsePentaxCommand : " + usePentaxCommand);
+    }
+
+    @Override
+    public boolean getUsePentaxCommand()
+    {
+        return (usePentaxCommand);
+    }
 }
 }
index 70f5a30..382884b 100644 (file)
@@ -22,19 +22,22 @@ public class RicohGr2LiveViewControl implements ILiveViewControl
 {
     private final String TAG = toString();
     private final Context context;
 {
     private final String TAG = toString();
     private final Context context;
+    private final IUsePentaxCommand usePentaxCommand;
     private final CameraLiveViewListenerImpl liveViewListener;
     private final CameraLiveViewListenerImpl liveViewListener;
-    private String liveViewUrl = "http://192.168.0.1/v1/display";  // "http://192.168.0.1/v1/liveview";
+    //private String liveViewUrl = "http://192.168.0.1/v1/display";  // "http://192.168.0.1/v1/liveview";
     private float cropScale = 1.0f;
     private boolean whileFetching = false;
     private float cropScale = 1.0f;
     private boolean whileFetching = false;
+    private boolean mirrorMode = false;
     private static final int FETCH_ERROR_MAX = 30;
 
     /**
      *
      *
      */
     private static final int FETCH_ERROR_MAX = 30;
 
     /**
      *
      *
      */
-    RicohGr2LiveViewControl(final Context context)
+    RicohGr2LiveViewControl(final Context context, @NonNull IUsePentaxCommand usePentaxCommand)
     {
         this.context = context;
     {
         this.context = context;
+        this.usePentaxCommand = usePentaxCommand;
         prepare();
         liveViewListener = new CameraLiveViewListenerImpl();
     }
         prepare();
         liveViewListener = new CameraLiveViewListenerImpl();
     }
@@ -45,22 +48,15 @@ public class RicohGr2LiveViewControl implements ILiveViewControl
      */
     private void prepare()
     {
      */
     private void prepare()
     {
-        liveViewUrl = "http://192.168.0.1/v1/display";
         try
         {
             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
         try
         {
             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
-            boolean mirrorMode = preferences.getBoolean(IPreferencePropertyAccessor.GR2_LIVE_VIEW, true);
-            boolean pentaxMode = preferences.getBoolean(IPreferencePropertyAccessor.USE_PENTAX_AUTOFOCUS, false);
-            if ((pentaxMode)||(!mirrorMode))
-            {
-                liveViewUrl = "http://192.168.0.1/v1/liveview";
-            }
+            mirrorMode = preferences.getBoolean(IPreferencePropertyAccessor.GR2_LIVE_VIEW, true);
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
-        Log.v(TAG, "LIVE VIEW URL : " + liveViewUrl);
     }
 
 
     }
 
 
@@ -92,6 +88,7 @@ public class RicohGr2LiveViewControl implements ILiveViewControl
                 {
                     try
                     {
                 {
                     try
                     {
+                        String liveViewUrl = ((usePentaxCommand.getUsePentaxCommand())||(!mirrorMode)) ? "http://192.168.0.1/v1/liveview" : "http://192.168.0.1/v1/display";
                         start(liveViewUrl);
                     }
                     catch (Exception e)
                         start(liveViewUrl);
                     }
                     catch (Exception e)
index 71f5107..8df3a31 100644 (file)
@@ -8,6 +8,7 @@ import android.util.Log;
 import net.osdn.gokigen.a01d.R;
 import net.osdn.gokigen.a01d.camera.ICameraConnection;
 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
 import net.osdn.gokigen.a01d.R;
 import net.osdn.gokigen.a01d.camera.ICameraConnection;
 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
+import net.osdn.gokigen.a01d.camera.ricohgr2.wrapper.IUsePentaxCommand;
 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
 
 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
 
@@ -19,13 +20,15 @@ class RicohGr2CameraConnectSequence implements Runnable
     private final Activity context;
     private final ICameraConnection cameraConnection;
     private final ICameraStatusReceiver cameraStatusReceiver;
     private final Activity context;
     private final ICameraConnection cameraConnection;
     private final ICameraStatusReceiver cameraStatusReceiver;
+    private final IUsePentaxCommand usePentaxCommand;
 
 
-    RicohGr2CameraConnectSequence(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection)
+    RicohGr2CameraConnectSequence(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection, @NonNull IUsePentaxCommand usePentaxCommand)
     {
         Log.v(TAG, "RicohGr2CameraConnectSequence");
         this.context = context;
         this.cameraConnection = cameraConnection;
         this.cameraStatusReceiver = statusReceiver;
     {
         Log.v(TAG, "RicohGr2CameraConnectSequence");
         this.context = context;
         this.cameraConnection = cameraConnection;
         this.cameraStatusReceiver = statusReceiver;
+        this.usePentaxCommand = usePentaxCommand;
     }
 
     @Override
     }
 
     @Override
@@ -42,47 +45,23 @@ class RicohGr2CameraConnectSequence implements Runnable
             {
                 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
 
             {
                 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
 
-                // 接続時、レンズロックOFF
+                // 接続時、レンズロックOFF + GR2 コマンド有効/無効の確認
                 {
                     final String postData = "cmd=acclock off";
                     String response0 = SimpleHttpClient.httpPost(grCommandUrl, postData, TIMEOUT_MS);
                     Log.v(TAG, grCommandUrl + " " + response0);
                 {
                     final String postData = "cmd=acclock off";
                     String response0 = SimpleHttpClient.httpPost(grCommandUrl, postData, TIMEOUT_MS);
                     Log.v(TAG, grCommandUrl + " " + response0);
-                }
 
 
-                // 接続時、カメラの画面を消す
-                if (preferences.getBoolean(IPreferencePropertyAccessor.GR2_LCD_SLEEP, false))
-                {
-                    final String postData = "cmd=lcd sleep on";
-                    String response0 = SimpleHttpClient.httpPost(grCommandUrl, postData, TIMEOUT_MS);
-                    Log.v(TAG, grCommandUrl + " " + response0);
-                }
+                    // GR2 専用コマンドを受け付けられるかどうかで、Preference を書き換える
+                    boolean pentaxCommand = !(response0.length() > 0);
+                    usePentaxCommand.setUsePentaxCommand(pentaxCommand);
 
 
-                // 表示するディスプレイモードを切り替える
-                String dispMode = preferences.getString(IPreferencePropertyAccessor.GR2_DISPLAY_MODE,  IPreferencePropertyAccessor.GR2_DISPLAY_MODE_DEFAULT_VALUE);
-                if (dispMode.contains("1"))
-                {
-                    // Disp. ボタンを 1回 押す
-                    final String postData = "cmd=bdisp";
-                    String response0 = SimpleHttpClient.httpPost(grCommandUrl, postData, TIMEOUT_MS);
-                    Log.v(TAG, grCommandUrl + " " + response0);
-
-                }
-                else if (dispMode.contains("2"))
-                {
-                    // Disp. ボタンを 2回 押す
-                    final String postData = "cmd=bdisp";
-                    String response0 = SimpleHttpClient.httpPost(grCommandUrl, postData, TIMEOUT_MS);
-                    String response1 = SimpleHttpClient.httpPost(grCommandUrl, postData, TIMEOUT_MS);
-                    Log.v(TAG, grCommandUrl + " " + response0 + " " + response1);
-                }
-                else if (dispMode.contains("3"))
-                {
-                    // Disp. ボタンを 3回 押す
-                    final String postData = "cmd=bdisp";
-                    String response0 = SimpleHttpClient.httpPost(grCommandUrl, postData, TIMEOUT_MS);
-                    String response1 = SimpleHttpClient.httpPost(grCommandUrl, postData, TIMEOUT_MS);
-                    String response2 = SimpleHttpClient.httpPost(grCommandUrl, postData, TIMEOUT_MS);
-                    Log.v(TAG, grCommandUrl + " " + response0 + " " + response1 + response2);
+                    // 接続時、カメラの画面を消す
+                    if ((pentaxCommand)&&(preferences.getBoolean(IPreferencePropertyAccessor.GR2_LCD_SLEEP, false)))
+                    {
+                        final String postData0 = "cmd=lcd sleep on";
+                        String response1 = SimpleHttpClient.httpPost(grCommandUrl, postData0, TIMEOUT_MS);
+                        Log.v(TAG, grCommandUrl + " " + response1);
+                    }
                 }
                 onConnectNotify();
             }
                 }
                 onConnectNotify();
             }
index 0760e0f..9cd7e46 100644 (file)
@@ -15,6 +15,7 @@ import android.util.Log;
 import net.osdn.gokigen.a01d.R;
 import net.osdn.gokigen.a01d.camera.ICameraConnection;
 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
 import net.osdn.gokigen.a01d.R;
 import net.osdn.gokigen.a01d.camera.ICameraConnection;
 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
+import net.osdn.gokigen.a01d.camera.ricohgr2.wrapper.IUsePentaxCommand;
 
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
 
 import java.util.concurrent.Executor;
 import java.util.concurrent.Executors;
@@ -32,6 +33,7 @@ public class RicohGr2Connection implements ICameraConnection
     private final String TAG = toString();
     private final Activity context;
     private final ICameraStatusReceiver statusReceiver;
     private final String TAG = toString();
     private final Activity context;
     private final ICameraStatusReceiver statusReceiver;
+    private final IUsePentaxCommand usePentaxCommand;
     private final BroadcastReceiver connectionReceiver;
     //private final ConnectivityManager connectivityManager;
     private final Executor cameraExecutor = Executors.newFixedThreadPool(1);
     private final BroadcastReceiver connectionReceiver;
     //private final ConnectivityManager connectivityManager;
     private final Executor cameraExecutor = Executors.newFixedThreadPool(1);
@@ -44,11 +46,12 @@ public class RicohGr2Connection implements ICameraConnection
      *
      *
      */
      *
      *
      */
-    public RicohGr2Connection(@NonNull final Activity context, @NonNull final ICameraStatusReceiver statusReceiver)
+    public RicohGr2Connection(@NonNull final Activity context, @NonNull final ICameraStatusReceiver statusReceiver, @NonNull IUsePentaxCommand usePentaxCommand)
     {
         Log.v(TAG, "RicohGr2Connection()");
         this.context = context;
         this.statusReceiver = statusReceiver;
     {
         Log.v(TAG, "RicohGr2Connection()");
         this.context = context;
         this.statusReceiver = statusReceiver;
+        this.usePentaxCommand = usePentaxCommand;
         connectionReceiver = new BroadcastReceiver()
         {
             @Override
         connectionReceiver = new BroadcastReceiver()
         {
             @Override
@@ -259,7 +262,7 @@ public class RicohGr2Connection implements ICameraConnection
         connectionStatus = CameraConnectionStatus.CONNECTING;
         try
         {
         connectionStatus = CameraConnectionStatus.CONNECTING;
         try
         {
-            cameraExecutor.execute(new RicohGr2CameraConnectSequence(context, statusReceiver, this));
+            cameraExecutor.execute(new RicohGr2CameraConnectSequence(context, statusReceiver, this, usePentaxCommand));
         }
         catch (Exception e)
         {
         }
         catch (Exception e)
         {