OSDN Git Service

pixpro実装。画像情報の一覧取得まで。
authorMRSa <mrsa@myad.jp>
Sat, 15 Aug 2020 13:40:50 +0000 (22:40 +0900)
committerMRSa <mrsa@myad.jp>
Sat, 15 Aug 2020 13:40:50 +0000 (22:40 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/PixproInterfaceProvider.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/playback/PixproPlaybackControl.java
app/src/main/java/net/osdn/gokigen/pkremote/preference/IPreferencePropertyAccessor.java
app/src/main/java/net/osdn/gokigen/pkremote/preference/pixpro/PixproPreferenceFragment.java
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences_pixpro.xml

index 141973e..9eba94c 100644 (file)
@@ -38,6 +38,7 @@ import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.status.PixproCamer
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.status.PixproCameraInformation;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.status.PixproRunMode;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.status.PixproStatusChecker;
+import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
 
 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT;
 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT_DEFAULT_VALUE;
@@ -72,17 +73,24 @@ public class PixproInterfaceProvider implements IPixproInterfaceProvider, IDispl
     {
         String ipAddress;
         String controlPortStr;
+        int communicationTimeoutMs;
         try
         {
             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
             ipAddress = preferences.getString(PIXPRO_HOST_IP, PIXPRO_HOST_IP_DEFAULT_VALUE);
             controlPortStr = preferences.getString(PIXPRO_COMMAND_PORT, PIXPRO_COMMAND_PORT_DEFAULT_VALUE);
+            communicationTimeoutMs = parseInt(preferences.getString(IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT, IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE), 30) * 1000;
+            if (communicationTimeoutMs < 3000)
+            {
+                communicationTimeoutMs = 3000;  // 最小値は 3000msとする。
+            }
         }
         catch (Exception e)
         {
             e.printStackTrace();
             ipAddress = "172.16.0.254";
             controlPortStr = "9175";
+            communicationTimeoutMs = 30000;  // エラー時は 30000msとする。
         }
         int controlPort = parseInt(controlPortStr, 9175);
         this.commandCommunicator = new PixproCommandCommunicator(this, ipAddress, controlPort, true, false);
@@ -93,7 +101,7 @@ public class PixproInterfaceProvider implements IPixproInterfaceProvider, IDispl
         this.pixproConnection = new PixproConnection(activity, provider, this, statusChecker);
         this.hardwarestatus = new PixproCameraHardwareStatus();
         this.runMode = new PixproRunMode();
-        this.playbackControl = new PixproPlaybackControl(this);
+        this.playbackControl = new PixproPlaybackControl(ipAddress, communicationTimeoutMs,this);
     }
 
     private int parseInt(@NonNull String key, int defaultValue)
index 27a5cef..f961595 100644 (file)
@@ -4,6 +4,7 @@ import android.util.Log;
 
 import androidx.annotation.NonNull;
 
+import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraFileInfo;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IContentInfoCallback;
@@ -11,17 +12,29 @@ import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCall
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentListCallback;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
+import net.osdn.gokigen.pkremote.camera.utils.SimpleHttpClient;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.IConnectionKeyProvider;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class PixproPlaybackControl implements IPlaybackControl
 {
     private final String TAG = toString();
+    private static final int DEFAULT_TIMEOUT = 3000;
 
+    private final String ipAddress;
     private final IConnectionKeyProvider keyProvider;
+    private final int timeoutValue;
+
+    private List<ICameraContent> cameraContentList;
 
-    public PixproPlaybackControl(@NonNull IConnectionKeyProvider keyProvider)
+    public PixproPlaybackControl(@NonNull String ipAddress, int timeoutMs, @NonNull IConnectionKeyProvider keyProvider)
     {
+        this.ipAddress = ipAddress;
         this.keyProvider = keyProvider;
+        this.timeoutValue  = Math.max(timeoutMs, DEFAULT_TIMEOUT);
+        cameraContentList = new ArrayList<>();
 
     }
 
@@ -71,9 +84,39 @@ public class PixproPlaybackControl implements IPlaybackControl
     @Override
     public void getCameraContentList(ICameraContentListCallback callback)
     {
+        try
+        {
+            String imageListurl = "http://" + ipAddress + "/?custom=1&" + getConnectionString();
+            String receivedMessage = SimpleHttpClient.httpGet(imageListurl, timeoutValue);
+            if (receivedMessage == null)
+            {
+                // ぬるぽ発行
+                callback.onErrorOccurred(new NullPointerException());
+                cameraContentList.clear();
+                return;
+            }
+            // 応答を受信した場合...
+            Log.v(TAG, " RECEIVED CONTENT REPLY : " + receivedMessage.length());
+            parseContentList(receivedMessage);
+            callback.onCompleted(cameraContentList);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+
+            // 例外時にはぬるぽを発行する
+            callback.onErrorOccurred(new NullPointerException());
+        }
+    }
+
+    private void parseContentList(@NonNull String receivedMessage)
+    {
+        // 受信したボディを解析して、画像一覧を cameraContentList に入れる
+
 
     }
 
+
     @Override
     public void showPictureStarted()
     {
index ef715ca..8563ac4 100644 (file)
@@ -125,6 +125,9 @@ public interface IPreferencePropertyAccessor
     String PIXPRO_COMMAND_PORT = "pixpro_command_port";
     String PIXPRO_COMMAND_PORT_DEFAULT_VALUE = "9175";
 
+    String PIXPRO_GET_PICS_LIST_TIMEOUT = "pixpro_get_pics_list_timeout";
+    String PIXPRO_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE = "30";
+
 /*
     //String GR2_DISPLAY_MODE = "gr2_display_mode";
     //String GR2_DISPLAY_MODE_DEFAULT_VALUE = "0";
index 60ede1b..f51c0d8 100644 (file)
@@ -137,6 +137,10 @@ public class PixproPreferenceFragment  extends PreferenceFragmentCompat implemen
             {
                 editor.putString(IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT, IPreferencePropertyAccessor.PIXPRO_COMMAND_PORT_DEFAULT_VALUE);
             }
+            if (!items.containsKey(IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT))
+            {
+                editor.putString(IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT, IPreferencePropertyAccessor.PIXPRO_GET_PICS_LIST_TIMEOUT_DEFAULT_VALUE);
+            }
             editor.apply();
         }
         catch (Exception e)
index 566c35a..a9f145a 100644 (file)
     <string name="pixpro_command_line_disconnected">カメラへのコマンド送信回線が切断されました。再試行してください。</string>
     <string name="dialog_title_connect_failed_pixpro">接続失敗(PIXPRO)</string>
 
+    <string name="pref_pixpro_get_pics_list_timeout">撮影画像一覧取得時のタイムアウト(単位:秒)</string>
+    <string name="pref_summary_pixpro_get_pics_list_timeout">通常、変更は不要です (初期値:30)</string>
+
 </resources>
index 49d3944..eea2c67 100644 (file)
     <string name="pixpro_command_line_disconnected">The command communication line is disconnected. (RETRY please.)</string>
     <string name="dialog_title_connect_failed_pixpro">Connect failed (PIXPRO)</string>
 
+    <string name="pref_pixpro_get_pics_list_timeout">Get Pics List Timeout(unit: sec.)</string>
+    <string name="pref_summary_pixpro_get_pics_list_timeout">If the camera has many number of Pics, increase number.</string>
+
 </resources>
index 3de06ac..1d7290b 100644 (file)
             android:title="@string/pref_pixpro_control_port"
             android:defaultValue="9175"
             android:summary="@string/pref_summary_pixpro_control_port" />
+
+        <EditTextPreference
+            android:key="pixpro_get_pics_list_timeout"
+            android:title="@string/pref_pixpro_get_pics_list_timeout"
+            android:defaultValue="30"
+            android:inputType="number"
+            android:summary="@string/pref_summary_pixpro_get_pics_list_timeout" />
+
 <!--
         <CheckBoxPreference
             android:key="capture_both_camera_and_live_view"