OSDN Git Service

拡張準備その2。
authorMRSa <mrsa@myad.jp>
Thu, 19 Dec 2019 15:32:59 +0000 (00:32 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 19 Dec 2019 15:32:59 +0000 (00:32 +0900)
20 files changed:
app/src/main/java/net/osdn/gokigen/a01d/A01dMain.java
app/src/main/java/net/osdn/gokigen/a01d/camera/CameraInterfaceProvider.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ICameraConnection.java
app/src/main/java/net/osdn/gokigen/a01d/camera/olympus/wrapper/ICameraHardwareStatus.java
app/src/main/java/net/osdn/gokigen/a01d/camera/olympus/wrapper/OlyCameraHardwareStatus.java
app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/IOlympusPenInterfaceProvider.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/operation/OlympusPenCameraPowerOff.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/OlympusPenInterfaceProvider.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/OlympusPenRunMode.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/connection/OlympusPenCameraConnectSequence.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/connection/OlympusPenCameraDisconnectSequence.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/connection/OlympusPenConnection.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/hardware/OlympusPenHardwareStatus.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/utils/SimpleHttpClient.java
app/src/main/java/net/osdn/gokigen/a01d/preference/olympuspen/OlympusPreferenceFragment.java [moved from app/src/main/java/net/osdn/gokigen/a01d/preference/phonecamera/PhoneCameraPreferenceFragment.java with 89% similarity]
app/src/main/res/values-ja/arrays.xml
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/arrays.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences_olympuspen.xml [moved from app/src/main/res/xml/preferences_phone.xml with 97% similarity]

index 21ca20a..35f8ec1 100644 (file)
@@ -7,7 +7,6 @@ import android.os.Bundle;
 import android.util.Log;
 import android.view.KeyEvent;
 import android.view.WindowManager;
-import android.widget.Toast;
 
 import net.osdn.gokigen.a01d.camera.CameraInterfaceProvider;
 import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
@@ -26,7 +25,7 @@ import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
 import net.osdn.gokigen.a01d.preference.fujix.FujiXPreferenceFragment;
 import net.osdn.gokigen.a01d.preference.olympus.PreferenceFragment;
 import net.osdn.gokigen.a01d.preference.panasonic.PanasonicPreferenceFragment;
-import net.osdn.gokigen.a01d.preference.phonecamera.PhoneCameraPreferenceFragment;
+import net.osdn.gokigen.a01d.preference.olympuspen.OlympusPreferenceFragment;
 import net.osdn.gokigen.a01d.preference.ricohgr2.RicohGr2PreferenceFragment;
 import net.osdn.gokigen.a01d.preference.sony.SonyPreferenceFragment;
 
@@ -315,8 +314,8 @@ public class A01dMain extends AppCompatActivity implements ICameraStatusReceiver
                         preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
                     } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC) {
                         preferenceFragment = PanasonicPreferenceFragment.newInstance(this, this);
-                    } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PHONE_CAMERA) {
-                        preferenceFragment = PhoneCameraPreferenceFragment.newInstance(this, this);
+                    } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS) {
+                        preferenceFragment = OlympusPreferenceFragment.newInstance(this, this);
                     } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X) {
                         preferenceFragment = FujiXPreferenceFragment.newInstance(this, this);
                     } else //  if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
index a167667..174c293 100644 (file)
@@ -118,9 +118,9 @@ public class CameraInterfaceProvider implements IInterfaceProvider
             {
                 ret = ICameraConnection.CameraConnectionMethod.PANASONIC;
             }
-            else if (connectionMethod.contains("PHONE"))
+            else if (connectionMethod.contains("OLYMPUS"))
             {
-                ret = ICameraConnection.CameraConnectionMethod.PHONE_CAMERA;
+                ret = ICameraConnection.CameraConnectionMethod.OLYMPUS;
             }
         }
         catch (Exception e)
index 5a153c7..ee02bf1 100644 (file)
@@ -15,7 +15,7 @@ public interface ICameraConnection
         RICOH_GR2,
         FUJI_X,
         PANASONIC,
-        PHONE_CAMERA,
+        OLYMPUS,
     }
 
     enum CameraConnectionStatus
index 30c5a67..497c319 100644 (file)
@@ -8,6 +8,8 @@ import java.util.Map;
  */
 public interface ICameraHardwareStatus
 {
+    boolean isAvailableHardwareStatus();
+
     String getLensMountStatus();
     String getMediaMountStatus();
 
index 676b438..9e4bba2 100644 (file)
@@ -23,6 +23,12 @@ public class OlyCameraHardwareStatus implements ICameraHardwareStatus
     }
 
     @Override
+    public boolean isAvailableHardwareStatus()
+    {
+        return (true);
+    }
+
+    @Override
     public String getLensMountStatus()
     {
         String message;
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/IOlympusPenInterfaceProvider.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/IOlympusPenInterfaceProvider.java
new file mode 100644 (file)
index 0000000..fa603c3
--- /dev/null
@@ -0,0 +1,36 @@
+package net.osdn.gokigen.a01d.camera.olympuspen;
+
+import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ICameraInformation;
+import net.osdn.gokigen.a01d.camera.ICameraStatus;
+import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
+import net.osdn.gokigen.a01d.camera.ICaptureControl;
+import net.osdn.gokigen.a01d.camera.IDisplayInjector;
+import net.osdn.gokigen.a01d.camera.IFocusingControl;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.IZoomLensControl;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraHardwareStatus;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraRunMode;
+import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
+
+/**
+ *
+ */
+public interface IOlympusPenInterfaceProvider
+{
+    ICameraConnection getOlyCameraConnection();
+    ILiveViewControl getLiveViewControl();
+    ILiveViewListener getLiveViewListener();
+    IFocusingControl getFocusingControl();
+    ICameraInformation getCameraInformation();
+    IZoomLensControl getZoomLensControl();
+    ICaptureControl getCaptureControl();
+    IDisplayInjector getDisplayInjector();
+
+    ICameraStatus getCameraStatusListHolder();
+    ICameraStatusWatcher getCameraStatusWatcher();
+    //IPlaybackControl getPlaybackControl();
+
+    ICameraHardwareStatus getHardwareStatus();
+    ICameraRunMode getCameraRunMode();
+}
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/operation/OlympusPenCameraPowerOff.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/operation/OlympusPenCameraPowerOff.java
new file mode 100644 (file)
index 0000000..8ac6b23
--- /dev/null
@@ -0,0 +1,80 @@
+package net.osdn.gokigen.a01d.camera.olympuspen.operation;
+
+import android.content.Context;
+
+import androidx.preference.Preference;
+
+import net.osdn.gokigen.a01d.ConfirmationDialog;
+import net.osdn.gokigen.a01d.IChangeScene;
+import net.osdn.gokigen.a01d.R;
+import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
+
+/**
+ *  Preferenceがクリックされた時に処理するクラス
+ *
+ */
+public class OlympusPenCameraPowerOff implements Preference.OnPreferenceClickListener, ConfirmationDialog.Callback
+{
+    private final Context context;
+    private final IChangeScene changeScene;
+    private String preferenceKey = null;
+
+    /**
+     *   コンストラクタ
+     *
+     */
+    public OlympusPenCameraPowerOff(Context context, IChangeScene changeScene)
+    {
+        this.context = context;
+        this.changeScene = changeScene;
+    }
+
+    /**
+     *   クラスの準備
+     *
+     */
+    public void prepare()
+    {
+        // 何もしない
+    }
+
+    /**
+     *
+     *
+     * @param preference クリックしたpreference
+     * @return false : ハンドルしない / true : ハンドルした
+     */
+    @Override
+    public boolean onPreferenceClick(Preference preference)
+    {
+        if (!preference.hasKey())
+        {
+            return (false);
+        }
+
+        preferenceKey = preference.getKey();
+        if (preferenceKey.contains(IPreferencePropertyAccessor.EXIT_APPLICATION))
+        {
+
+            // 確認ダイアログの生成と表示
+            ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
+            dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, this);
+            return (true);
+        }
+        return (false);
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void confirm()
+    {
+        if (preferenceKey.contains(IPreferencePropertyAccessor.EXIT_APPLICATION))
+        {
+            // カメラの電源をOFFにしたうえで、アプリケーションを終了する。
+            changeScene.exitApplication();
+        }
+    }
+}
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/OlympusPenInterfaceProvider.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/OlympusPenInterfaceProvider.java
new file mode 100644 (file)
index 0000000..0266d75
--- /dev/null
@@ -0,0 +1,151 @@
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.preference.PreferenceManager;
+
+import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ICameraInformation;
+import net.osdn.gokigen.a01d.camera.ICameraStatus;
+import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
+import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
+import net.osdn.gokigen.a01d.camera.ICaptureControl;
+import net.osdn.gokigen.a01d.camera.IDisplayInjector;
+import net.osdn.gokigen.a01d.camera.IFocusingControl;
+import net.osdn.gokigen.a01d.camera.IFocusingModeNotify;
+import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.IZoomLensControl;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraHardwareStatus;
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraRunMode;
+import net.osdn.gokigen.a01d.camera.olympuspen.IOlympusPenInterfaceProvider;
+import net.osdn.gokigen.a01d.camera.olympuspen.wrapper.connection.OlympusPenConnection;
+import net.osdn.gokigen.a01d.camera.olympuspen.wrapper.hardware.OlympusPenHardwareStatus;
+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;
+
+/**
+ *
+ *
+ */
+public class OlympusPenInterfaceProvider implements IOlympusPenInterfaceProvider, IDisplayInjector
+{
+    private final String TAG = toString();
+    private final OlympusPenConnection olympusPenConnection;
+    private final OlympusPenHardwareStatus hardwareStatus;
+    private final OlympusPenRunMode runMode;
+
+    /**
+     *
+     *
+     */
+    public OlympusPenInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider)
+    {
+/*
+        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+        int communicationTimeoutMs = 10000;  // デフォルトは 10000ms とする
+        try
+        {
+            communicationTimeoutMs = Integer.parseInt(preferences.getString(IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT, IPreferencePropertyAccessor.RICOH_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE)) * 1000;
+            if (communicationTimeoutMs < 3000)
+            {
+                communicationTimeoutMs = 3000;  // 最小値は 3000msとする。
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+*/
+        //this.activity = context;
+        //this.provider = provider;
+        olympusPenConnection = new OlympusPenConnection(context, provider);
+        hardwareStatus = new OlympusPenHardwareStatus();
+        runMode = new OlympusPenRunMode();
+    }
+
+    public void prepare()
+    {
+        Log.v(TAG, "prepare()");
+    }
+
+    @Override
+    public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
+    {
+        Log.v(TAG, "injectDisplay()");
+    }
+
+    @Override
+    public ICameraConnection getOlyCameraConnection()
+    {
+        return (olympusPenConnection);
+    }
+
+    @Override
+    public ILiveViewControl getLiveViewControl()
+    {
+        return (null);
+    }
+
+    @Override
+    public ILiveViewListener getLiveViewListener()
+    {
+        return (null);
+    }
+
+    @Override
+    public IFocusingControl getFocusingControl()
+    {
+        return (null);
+    }
+
+    @Override
+    public ICameraInformation getCameraInformation()
+    {
+        return (null);
+    }
+
+    @Override
+    public IZoomLensControl getZoomLensControl()
+    {
+        return (null);
+    }
+
+    @Override
+    public ICaptureControl getCaptureControl()
+    {
+        return (null);
+    }
+
+    @Override
+    public IDisplayInjector getDisplayInjector() {
+        return (this);
+    }
+
+    @Override
+    public ICameraStatus getCameraStatusListHolder()
+    {
+        return (null);
+    }
+
+    @Override
+    public ICameraStatusWatcher getCameraStatusWatcher() {
+        return (null);
+    }
+
+    @Override
+    public ICameraHardwareStatus getHardwareStatus()
+    {
+        return (hardwareStatus);
+    }
+
+    @Override
+    public ICameraRunMode getCameraRunMode()
+    {
+        return (runMode);
+    }
+}
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/OlympusPenRunMode.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/OlympusPenRunMode.java
new file mode 100644 (file)
index 0000000..4d0274f
--- /dev/null
@@ -0,0 +1,57 @@
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper;
+
+import android.util.Log;
+
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraRunMode;
+import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class OlympusPenRunMode implements ICameraRunMode
+{
+    private final String TAG = this.toString();
+
+    @Override
+    public void changeRunMode(final boolean isRecording)
+    {
+        final int TIMEOUT_MS = 5000;
+        try
+        {
+            final Thread thread = new Thread(new Runnable()
+            {
+                @Override
+                public void run()
+                {
+                    // カメラとの接続確立を通知する
+                    Map<String, String> headerMap = new HashMap<>();
+                    headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
+                    headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
+
+                    String playModeUrl = "http://192.168.0.10/switch_cameramode.cgi";
+                    if (isRecording)
+                    {
+                        playModeUrl = playModeUrl + "?mode=rec";
+                    }
+                    else
+                    {
+                        playModeUrl = playModeUrl + "?mode=play";
+                    }
+                    String response = SimpleHttpClient.httpGetWithHeader(playModeUrl, headerMap, null, TIMEOUT_MS);
+                    Log.v(TAG, " " + playModeUrl + " " + response);
+                }
+            });
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
+    public boolean isRecordingMode()
+    {
+        return (true);
+    }
+}
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/connection/OlympusPenCameraConnectSequence.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/connection/OlympusPenCameraConnectSequence.java
new file mode 100644 (file)
index 0000000..019356d
--- /dev/null
@@ -0,0 +1,96 @@
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper.connection;
+
+import android.app.Activity;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+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.utils.SimpleHttpClient;
+
+import java.util.HashMap;
+import java.util.Map;
+
+class OlympusPenCameraConnectSequence implements Runnable
+{
+    private final String TAG = this.toString();
+    private final Activity context;
+    private final ICameraConnection cameraConnection;
+    private final ICameraStatusReceiver cameraStatusReceiver;
+
+    OlympusPenCameraConnectSequence(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection)
+    {
+        Log.v(TAG, "OlympusPenCameraConnectSequence");
+        this.context = context;
+        this.cameraConnection = cameraConnection;
+        this.cameraStatusReceiver = statusReceiver;
+    }
+
+    @Override
+    public void run()
+    {
+        final String camInfoUrl = "http://192.168.0.10/get_caminfo.cgi";
+        final String getCommandListUrl = "http://192.168.0.10/get_commandlist.cgi";
+        final String getConnectModeUrl = "http://192.168.0.10/get_connectmode.cgi";
+
+        final int TIMEOUT_MS = 5000;
+        try
+        {
+            Map<String, String> headerMap = new HashMap<>();
+            headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
+            headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
+
+            String response = SimpleHttpClient.httpGetWithHeader(getConnectModeUrl, headerMap, null, TIMEOUT_MS);
+            Log.v(TAG, " " + getConnectModeUrl + " " + response);
+            if (response.length() > 0)
+            {
+                String response2 = SimpleHttpClient.httpGetWithHeader(getCommandListUrl, headerMap, null, TIMEOUT_MS);
+                Log.v(TAG, " " + getCommandListUrl + " " + response2);
+
+                String response3 = SimpleHttpClient.httpGetWithHeader(camInfoUrl, headerMap, null, TIMEOUT_MS);
+                Log.v(TAG, " " + camInfoUrl + " " + response3);
+
+                onConnectNotify();
+            }
+            else
+            {
+                onConnectError(context.getString(R.string.camera_not_found));
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            onConnectError(e.getLocalizedMessage());
+        }
+    }
+
+    private void onConnectNotify()
+    {
+        try
+        {
+            final Thread thread = new Thread(new Runnable()
+            {
+                @Override
+                public void run()
+                {
+                    // カメラとの接続確立を通知する
+                    cameraStatusReceiver.onStatusNotify(context.getString(R.string.connect_connected));
+                    cameraStatusReceiver.onCameraConnected();
+                    Log.v(TAG, "onConnectNotify()");
+                }
+            });
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    private void onConnectError(String reason)
+    {
+        cameraConnection.alertConnectingFailed(reason);
+    }
+}
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/connection/OlympusPenCameraDisconnectSequence.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/connection/OlympusPenCameraDisconnectSequence.java
new file mode 100644 (file)
index 0000000..202f67f
--- /dev/null
@@ -0,0 +1,47 @@
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper.connection;
+
+
+import android.app.Activity;
+import android.util.Log;
+
+import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class OlympusPenCameraDisconnectSequence  implements Runnable
+{
+    private final String TAG = this.toString();
+    private final Activity activity;
+    private final boolean powerOff;
+
+    OlympusPenCameraDisconnectSequence(Activity activity, boolean isOff)
+    {
+        this.activity = activity;
+        this.powerOff = isOff;
+    }
+
+    @Override
+    public void run()
+    {
+        // カメラをPowerOffして接続を切る
+        try
+        {
+            Map<String, String> headerMap = new HashMap<>();
+            headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
+            headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
+
+            if (powerOff)
+            {
+                final String cameraPowerOffUrl = "http://192.168.0.10/exec_pwoff.cgi";
+                final int TIMEOUT_MS = 5000;
+                String response = SimpleHttpClient.httpGetWithHeader(cameraPowerOffUrl, headerMap, null, TIMEOUT_MS);
+                Log.v(TAG, " " + cameraPowerOffUrl + " " + response);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/connection/OlympusPenConnection.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/connection/OlympusPenConnection.java
new file mode 100644 (file)
index 0000000..a952e2e
--- /dev/null
@@ -0,0 +1,277 @@
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper.connection;
+
+
+import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.ConnectivityManager;
+import android.net.wifi.WifiInfo;
+import android.net.wifi.WifiManager;
+import android.provider.Settings;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AlertDialog;
+
+import net.osdn.gokigen.a01d.R;
+import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
+
+/**
+ *
+ *
+ */
+public class OlympusPenConnection implements ICameraConnection
+{
+    private final String TAG = toString();
+    private final Activity context;
+    private final ICameraStatusReceiver statusReceiver;
+    private final BroadcastReceiver connectionReceiver;
+    //private final ConnectivityManager connectivityManager;
+    private final Executor cameraExecutor = Executors.newFixedThreadPool(1);
+    //private final Handler networkConnectionTimeoutHandler;
+    //private static final int MESSAGE_CONNECTIVITY_TIMEOUT = 1;
+    private CameraConnectionStatus connectionStatus = CameraConnectionStatus.UNKNOWN;
+
+
+    /**
+     *
+     *
+     */
+    public OlympusPenConnection(@NonNull final Activity context, @NonNull final ICameraStatusReceiver statusReceiver)
+    {
+        Log.v(TAG, "OlympusPenConnection()");
+        this.context = context;
+        this.statusReceiver = statusReceiver;
+        connectionReceiver = new BroadcastReceiver()
+        {
+            @Override
+            public void onReceive(Context context, Intent intent)
+            {
+                onReceiveBroadcastOfConnection(context, intent);
+            }
+        };
+    }
+
+    /**
+     *
+     *
+     */
+    private void onReceiveBroadcastOfConnection(Context context, Intent intent)
+    {
+        statusReceiver.onStatusNotify(context.getString(R.string.connect_check_wifi));
+        Log.v(TAG,context.getString(R.string.connect_check_wifi));
+
+        String action = intent.getAction();
+        if (action == null)
+        {
+            //
+            Log.v(TAG, "intent.getAction() : null");
+            return;
+        }
+
+        try
+        {
+            if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION))
+            {
+                Log.v(TAG, "onReceiveBroadcastOfConnection() : CONNECTIVITY_ACTION");
+
+                WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+                if (wifiManager != null) {
+                    WifiInfo info = wifiManager.getConnectionInfo();
+                    if (wifiManager.isWifiEnabled() && info != null)
+                    {
+                        if (info.getNetworkId() != -1)
+                        {
+                            Log.v(TAG, "Network ID is -1, there is no currently connected network.");
+                        }
+                        // 自動接続が指示されていた場合は、カメラとの接続処理を行う
+                        connectToCamera();
+                    } else {
+                        if (info == null)
+                        {
+                            Log.v(TAG, "NETWORK INFO IS NULL.");
+                        } else {
+                            Log.v(TAG, "isWifiEnabled : " + wifiManager.isWifiEnabled() + " NetworkId : " + info.getNetworkId());
+                        }
+                    }
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            Log.w(TAG, "onReceiveBroadcastOfConnection() EXCEPTION" + e.getMessage());
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void startWatchWifiStatus(Context context)
+    {
+        Log.v(TAG, "startWatchWifiStatus()");
+        statusReceiver.onStatusNotify("prepare");
+
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+        context.registerReceiver(connectionReceiver, filter);
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void stopWatchWifiStatus(Context context)
+    {
+        Log.v(TAG, "stopWatchWifiStatus()");
+        context.unregisterReceiver(connectionReceiver);
+        disconnect(false);
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void disconnect(boolean powerOff)
+    {
+        Log.v(TAG, "disconnect()");
+        disconnectFromCamera(powerOff);
+        connectionStatus = CameraConnectionStatus.DISCONNECTED;
+        statusReceiver.onCameraDisconnected();
+    }
+
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void connect()
+    {
+        Log.v(TAG, "connect()");
+        connectToCamera();
+    }
+
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void alertConnectingFailed(String message)
+    {
+        Log.v(TAG, "alertConnectingFailed() : " + message);
+        final AlertDialog.Builder builder = new AlertDialog.Builder(context)
+                .setTitle(context.getString(R.string.dialog_title_connect_failed))
+                .setMessage(message)
+                .setPositiveButton(context.getString(R.string.dialog_title_button_retry), new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which)
+                    {
+                        connect();
+                    }
+                })
+                .setNeutralButton(R.string.dialog_title_button_network_settings, new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface dialog, int which)
+                    {
+                        try
+                        {
+                            // Wifi 設定画面を表示する
+                            context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
+                        }
+                        catch (android.content.ActivityNotFoundException ex)
+                        {
+                            // Activity が存在しなかった...設定画面が起動できなかった
+                            Log.v(TAG, "android.content.ActivityNotFoundException...");
+
+                            // この場合は、再試行と等価な動きとする
+                            connect();
+                        }
+                        catch (Exception e)
+                        {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+        context.runOnUiThread(new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                try
+                {
+                    builder.show();
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+            }
+        });
+    }
+
+    @Override
+    public CameraConnectionStatus getConnectionStatus()
+    {
+        Log.v(TAG, "getConnectionStatus()");
+        return (connectionStatus);
+    }
+
+    /**
+     *
+     *
+     */
+    @Override
+    public void forceUpdateConnectionStatus(CameraConnectionStatus status)
+    {
+        Log.v(TAG, "forceUpdateConnectionStatus()");
+        connectionStatus = status;
+    }
+
+    /**
+     * カメラとの切断処理
+     */
+    private void disconnectFromCamera(final boolean powerOff)
+    {
+        Log.v(TAG, "disconnectFromCamera()");
+        try
+        {
+            cameraExecutor.execute(new OlympusPenCameraDisconnectSequence(context, powerOff));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * カメラとの接続処理
+     */
+    private void connectToCamera()
+    {
+        Log.v(TAG, "connectToCamera()");
+        connectionStatus = CameraConnectionStatus.CONNECTING;
+        try
+        {
+            cameraExecutor.execute(new OlympusPenCameraConnectSequence(context, statusReceiver, this));
+        }
+        catch (Exception e)
+        {
+            Log.v(TAG, "connectToCamera() EXCEPTION : " + e.getMessage());
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/hardware/OlympusPenHardwareStatus.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/olympuspen/wrapper/hardware/OlympusPenHardwareStatus.java
new file mode 100644 (file)
index 0000000..e382a89
--- /dev/null
@@ -0,0 +1,52 @@
+package net.osdn.gokigen.a01d.camera.olympuspen.wrapper.hardware;
+
+
+import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraHardwareStatus;
+
+import java.util.Map;
+
+public class OlympusPenHardwareStatus implements ICameraHardwareStatus
+{
+    @Override
+    public boolean isAvailableHardwareStatus()
+    {
+        return (false);
+    }
+
+    @Override
+    public String getLensMountStatus()
+    {
+        return (null);
+    }
+
+    @Override
+    public String getMediaMountStatus()
+    {
+        return (null);
+    }
+
+    @Override
+    public float getMinimumFocalLength()
+    {
+        return (0);
+    }
+
+    @Override
+    public float getMaximumFocalLength()
+    {
+        return (0);
+    }
+
+    @Override
+    public float getActualFocalLength()
+    {
+        return (0);
+    }
+
+    @Override
+    public Map<String, Object> inquireHardwareInformation()
+    {
+        return (null);
+    }
+
+}
index 5671fcd..dc2c7a9 100644 (file)
@@ -12,6 +12,8 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.net.HttpURLConnection;
 import java.net.URL;
+import java.util.List;
+import java.util.Map;
 
 import androidx.annotation.NonNull;
 
@@ -128,7 +130,7 @@ public class SimpleHttpClient
      *
      *
      */
-    public static void httpGetBytes(String url, int timeoutMs, @NonNull IReceivedMessageCallback callback)
+    public static void httpGetBytes(String url, Map<String, String> setProperty, int timeoutMs, @NonNull IReceivedMessageCallback callback)
     {
         HttpURLConnection httpConn = null;
         InputStream inputStream = null;
@@ -144,6 +146,14 @@ public class SimpleHttpClient
             final URL urlObj = new URL(url);
             httpConn = (HttpURLConnection) urlObj.openConnection();
             httpConn.setRequestMethod("GET");
+            if (setProperty != null)
+            {
+                for (String key : setProperty.keySet())
+                {
+                    String value = setProperty.get(key);
+                    httpConn.setRequestProperty(key, value);
+                }
+            }
             httpConn.setConnectTimeout(timeout);
             httpConn.setReadTimeout(timeout);
             httpConn.connect();
@@ -178,6 +188,42 @@ public class SimpleHttpClient
         try
         {
             int contentLength = httpConn.getContentLength();
+            if (contentLength < 0)
+            {
+                // コンテンツ長が取れない場合の処理...
+                try
+                {
+                    Map<String, List<String>> headers = httpConn.getHeaderFields();
+
+                    /*
+                    // 応答ヘッダをすべてダンプするロジック...
+                    for (String key : headers.keySet())
+                    {
+                        final List<String> valueList = headers.get(key);
+                        Log.v(TAG, " " + key + " : " + getValue(valueList));
+                    }
+                    */
+
+                    // コンテンツ長さが取れない場合は、HTTP応答ヘッダから取得する
+                    List<String> valueList = headers.get("X-FILE_SIZE");
+                    try
+                    {
+                        if (valueList != null)
+                        {
+                            contentLength = Integer.parseInt(getValue(valueList));
+                        }
+                    }
+                    catch (Exception ee)
+                    {
+                        ee.printStackTrace();
+                    }
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+            }
+
             byte[] buffer = new byte[BUFFER_SIZE];
             int readBytes = 0;
             int readSize = inputStream.read(buffer, 0, BUFFER_SIZE);
@@ -210,12 +256,32 @@ public class SimpleHttpClient
         callback.onCompleted();
     }
 
+    public static String getValue(List<String> valueList)
+    {
+        // 応答ヘッダの値切り出し用...
+        boolean isFirst = true;
+        final StringBuilder values = new StringBuilder();
+        for (String value : valueList)
+        {
+            values.append(value);
+            if (isFirst)
+            {
+                isFirst = false;
+            }
+            else
+            {
+                values.append(" ");
+            }
+        }
+        return (values.toString());
+    }
+
     /**
      *
      *
      *
      */
-    public static Bitmap httpGetBitmap(String url, int timeoutMs)
+    public static Bitmap httpGetBitmap(String url, Map<String, String> setProperty, int timeoutMs)
     {
         HttpURLConnection httpConn = null;
         InputStream inputStream = null;
@@ -233,6 +299,14 @@ public class SimpleHttpClient
             final URL urlObj = new URL(url);
             httpConn = (HttpURLConnection) urlObj.openConnection();
             httpConn.setRequestMethod("GET");
+            if (setProperty != null)
+            {
+                for (String key : setProperty.keySet())
+                {
+                    String value = setProperty.get(key);
+                    httpConn.setRequestProperty(key, value);
+                }
+            }
             httpConn.setConnectTimeout(timeout);
             httpConn.setReadTimeout(timeout);
             httpConn.connect();
@@ -273,7 +347,28 @@ public class SimpleHttpClient
      */
     public static String httpPost(String url, String postData, int timeoutMs)
     {
-        return (httpCommand(url, "POST", postData, timeoutMs));
+        return (httpCommand(url, "POST", postData, null, null, timeoutMs));
+    }
+
+
+    /**
+     *
+     *
+     *
+     */
+    public static String httpGetWithHeader(String url, Map<String, String> headerMap, String contentType, int timeoutMs)
+    {
+        return (httpCommand(url, "GET", null, headerMap, contentType, timeoutMs));
+    }
+
+    /**
+     *
+     *
+     *
+     */
+    public static String httpPostWithHeader(String url, String postData, Map<String, String> headerMap, String contentType, int timeoutMs)
+    {
+        return (httpCommand(url, "POST", postData, headerMap, contentType, timeoutMs));
     }
 
     /**
@@ -283,7 +378,7 @@ public class SimpleHttpClient
      */
     public static String httpPut(String url, String postData, int timeoutMs)
     {
-        return (httpCommand(url, "PUT", postData, timeoutMs));
+        return (httpCommand(url, "PUT", postData, null, null, timeoutMs));
     }
 
     /**
@@ -293,7 +388,7 @@ public class SimpleHttpClient
      */
     public static String httpOptions(String url, String postData, int timeoutMs)
     {
-        return (httpCommand(url, "OPTIONS", postData, timeoutMs));
+        return (httpCommand(url, "OPTIONS", postData, null, null, timeoutMs));
     }
 
     /**
@@ -301,7 +396,7 @@ public class SimpleHttpClient
      *
      *
      */
-    private static String httpCommand(String url, String requestMethod, String postData, int timeoutMs)
+    private static String httpCommand(String url, String requestMethod, String postData, Map<String, String> setProperty, String contentType, int timeoutMs)
     {
         HttpURLConnection httpConn = null;
         OutputStream outputStream = null;
@@ -320,20 +415,38 @@ public class SimpleHttpClient
             final URL urlObj = new URL(url);
             httpConn = (HttpURLConnection) urlObj.openConnection();
             httpConn.setRequestMethod(requestMethod);
+            if (setProperty != null)
+            {
+                for (String key : setProperty.keySet())
+                {
+                    String value = setProperty.get(key);
+                    httpConn.setRequestProperty(key, value);
+                }
+            }
+            if (contentType != null)
+            {
+                httpConn.setRequestProperty("Content-Type", contentType);
+            }
             httpConn.setConnectTimeout(timeout);
             httpConn.setReadTimeout(timeout);
-            httpConn.setDoInput(true);
-            httpConn.setDoOutput(true);
-
-            outputStream = httpConn.getOutputStream();
-            writer = new OutputStreamWriter(outputStream, "UTF-8");
-            writer.write(postData);
-            writer.flush();
-            writer.close();
-            writer = null;
-            outputStream.close();
-            outputStream = null;
 
+            if (postData == null)
+            {
+                httpConn.connect();
+            }
+            else
+            {
+                httpConn.setDoInput(true);
+                httpConn.setDoOutput(true);
+                outputStream = httpConn.getOutputStream();
+                writer = new OutputStreamWriter(outputStream, "UTF-8");
+                writer.write(postData);
+                writer.flush();
+                writer.close();
+                writer = null;
+                outputStream.close();
+                outputStream = null;
+            }
             int responseCode = httpConn.getResponseCode();
             if (responseCode == HttpURLConnection.HTTP_OK)
             {
@@ -1,4 +1,4 @@
-package net.osdn.gokigen.a01d.preference.phonecamera;
+package net.osdn.gokigen.a01d.preference.olympuspen;
 
 import android.content.Context;
 import android.content.SharedPreferences;
@@ -16,7 +16,7 @@ import androidx.preference.PreferenceManager;
 
 import net.osdn.gokigen.a01d.IChangeScene;
 import net.osdn.gokigen.a01d.R;
-import net.osdn.gokigen.a01d.camera.panasonic.operation.CameraPowerOffPanasonic;
+import net.osdn.gokigen.a01d.camera.olympuspen.operation.OlympusPenCameraPowerOff;
 import net.osdn.gokigen.a01d.logcat.LogCatViewer;
 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
 
@@ -26,11 +26,11 @@ import java.util.Map;
  *
  *
  */
-public class PhoneCameraPreferenceFragment  extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener
+public class OlympusPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener
 {
     private final String TAG = toString();
     private SharedPreferences preferences = null;
-    private CameraPowerOffPanasonic powerOffController = null;
+    private OlympusPenCameraPowerOff powerOffController = null;
     private LogCatViewer logCatViewer = null;
     //private PanasonicCameraApiListViewer cameraApiListViewer = null;
 
@@ -38,9 +38,9 @@ public class PhoneCameraPreferenceFragment  extends PreferenceFragmentCompat imp
      *
      *
      */
-    public static PhoneCameraPreferenceFragment newInstance(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
+    public static OlympusPreferenceFragment newInstance(@NonNull AppCompatActivity context, @NonNull IChangeScene changeScene)
     {
-        PhoneCameraPreferenceFragment instance = new PhoneCameraPreferenceFragment();
+        OlympusPreferenceFragment instance = new OlympusPreferenceFragment();
         instance.prepare(context, changeScene);
 
         // パラメータはBundleにまとめておく
@@ -60,7 +60,7 @@ public class PhoneCameraPreferenceFragment  extends PreferenceFragmentCompat imp
     {
         try
         {
-            powerOffController = new CameraPowerOffPanasonic(context, changeScene);
+            powerOffController = new OlympusPenCameraPowerOff(context, changeScene);
             powerOffController.prepare();
 
             logCatViewer = new LogCatViewer(changeScene);
@@ -80,7 +80,7 @@ public class PhoneCameraPreferenceFragment  extends PreferenceFragmentCompat imp
      *
      */
     @Override
-    public void onAttach(Context activity)
+    public void onAttach(@NonNull Context activity)
     {
         super.onAttach(activity);
         Log.v(TAG, "onAttach()");
@@ -171,9 +171,9 @@ public class PhoneCameraPreferenceFragment  extends PreferenceFragmentCompat imp
         try
         {
             //super.onCreate(savedInstanceState);
-            addPreferencesFromResource(R.xml.preferences_panasonic);
+            addPreferencesFromResource(R.xml.preferences_olympuspen);
 
-            ListPreference connectionMethod = (ListPreference) findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
+            ListPreference connectionMethod = findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
             connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                 @Override
                 public boolean onPreferenceChange(Preference preference, Object newValue) {
@@ -276,7 +276,7 @@ public class PhoneCameraPreferenceFragment  extends PreferenceFragmentCompat imp
     {
         try
         {
-            CheckBoxPreference pref = (CheckBoxPreference) findPreference(pref_key);
+            CheckBoxPreference pref = findPreference(pref_key);
             if (pref != null) {
                 boolean value = preferences.getBoolean(key, defaultValue);
                 pref.setChecked(value);
index 2f15c47..83bd31e 100644 (file)
         <item>Ricoh GR Series / PENTAX</item>
         <item >Fuji X Series</item>
         <item >Panasonic</item>
-        <item >Phone</item>
+        <item >Olympus Pen/OM-D</item>
     </string-array>
 
     <string-array name="connection_method_value">
         <item >RICOH_GR2</item>
         <item >FUJI_X</item>
         <item >PANASONIC</item>
-        <item >PHONE</item>
+        <item >OLYMPUS</item>
     </string-array>
 
 
index 2893dba..b5259aa 100644 (file)
@@ -27,7 +27,7 @@
     <string name="pref_exit_power_off">アプリ終了(とカメラOFF)</string>
     <string name="pref_exit_power_off_sony">アプリ終了</string>
     <string name="pref_exit_power_off_panasonic">アプリ終了</string>
-    <string name="pref_exit_power_off_camera">アプリ終了</string>
+    <string name="pref_exit_power_off_olympuspen">アプリ終了(とカメラOFF)</string>
 
     <string name="pref_exit_power_off_fujix">アプリ終了</string>
     <string name="pref_fujix_display_camera_view">LVをカメラでも表示</string>
index ef3ceba..be9df74 100644 (file)
         <item>Ricoh GR Series / PENTAX</item>
         <item >Fuji X Series</item>
         <item >Panasonic</item>
-        <item >Phone</item>
+        <item >Olympus Pen/OM-D</item>
     </string-array>
 
     <string-array name="connection_method_value">
         <item >RICOH_GR2</item>
         <item >FUJI_X</item>
         <item >PANASONIC</item>
-        <item >PHONE</item>
+        <item >OLYMPUS</item>
     </string-array>
 
     <string-array name="gr2_display_mode">
index 922be1b..6f3a545 100644 (file)
@@ -28,7 +28,7 @@
     <string name="pref_exit_power_off">Exit Application(and Camera OFF)</string>
     <string name="pref_exit_power_off_sony">Exit Application</string>
     <string name="pref_exit_power_off_panasonic">Exit Application</string>
-    <string name="pref_exit_power_off_camera">Exit Application</string>
+    <string name="pref_exit_power_off_olympuspen">Exit Application(and Camera OFF)</string>
 
     <string name="pref_exit_power_off_fujix">Exit Application</string>
     <string name="pref_fujix_display_camera_view">Use Camera Display</string>
similarity index 97%
rename from app/src/main/res/xml/preferences_phone.xml
rename to app/src/main/res/xml/preferences_olympuspen.xml
index 003105e..7f3aee6 100644 (file)
@@ -6,7 +6,7 @@
         <PreferenceScreen
             android:key="exit_application"
             android:icon="@drawable/ic_power_settings_new_black_24dp"
-            android:title="@string/pref_exit_power_off_camera" />
+            android:title="@string/pref_exit_power_off_olympuspen" />
 
         <ListPreference
             android:title="@string/pref_connection_method"