OSDN Git Service

Nikon用に受信待ち時間を設定できるようにした。
authorMRSa <mrsa@myad.jp>
Tue, 3 Dec 2019 15:38:12 +0000 (00:38 +0900)
committerMRSa <mrsa@myad.jp>
Tue, 3 Dec 2019 15:38:12 +0000 (00:38 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/nikon/wrapper/playback/NikonFullImageReceiver.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/nikon/wrapper/playback/NikonImageObjectReceiver.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/nikon/wrapper/playback/NikonPlaybackControl.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/nikon/wrapper/playback/NikonSmallImageReceiver.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/nikon/wrapper/playback/NikonStorageContentHolder.java
app/src/main/java/net/osdn/gokigen/pkremote/preference/IPreferencePropertyAccessor.java
app/src/main/java/net/osdn/gokigen/pkremote/preference/nikon/NikonPreferenceFragment.java
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences_nikon.xml

index 55e13e5..b209b7e 100644 (file)
@@ -1,6 +1,5 @@
 package net.osdn.gokigen.pkremote.camera.vendor.nikon.wrapper.playback;
 
-import android.app.Activity;
 import android.util.Log;
 
 import androidx.annotation.NonNull;
@@ -19,23 +18,22 @@ public class NikonFullImageReceiver implements IPtpIpCommandCallback
 {
     private static final String TAG = NikonFullImageReceiver.class.getSimpleName();
 
-    private final Activity activity;
     private final IPtpIpCommandPublisher publisher;
     private IDownloadContentCallback callback = null;
 
     private boolean isReceiveMulti = true;
     private int objectId = 0;
-
+    private int delayMs;
     private int received_total_bytes = 0;
     private int received_remain_bytes = 0;
 
     private int target_image_size = 0;
     private boolean receivedFirstData = false;
 
-    NikonFullImageReceiver(@NonNull Activity activity, @NonNull IPtpIpCommandPublisher publisher)
+    NikonFullImageReceiver(@NonNull IPtpIpCommandPublisher publisher, int delayMs)
     {
-        this.activity = activity;
         this.publisher = publisher;
+        this.delayMs = delayMs;
     }
 
     void issueCommand(int objectId, int imageSize, IDownloadContentCallback callback)
@@ -53,7 +51,7 @@ public class NikonFullImageReceiver implements IPtpIpCommandCallback
         this.receivedFirstData = false;
 
         Log.v(TAG, " getPartialObject (id : " + objectId + ", size:" + imageSize + ")");
-        publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_PARTIAL_OBJECT, 75, true, 0, 0x101b, 12, objectId, 0, imageSize, 0));  // GetPartialObject (0x101b)
+        publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_PARTIAL_OBJECT, delayMs, true, 0, 0x101b, 12, objectId, 0, imageSize, 0));  // GetPartialObject (0x101b)
     }
 
     @Override
index 984ede1..ebdffd7 100644 (file)
@@ -21,13 +21,15 @@ public class NikonImageObjectReceiver implements IPtpIpCommandCallback, NikonSto
 {
     private final String TAG = toString();
     private final NikonInterfaceProvider provider;
+    private final int delayMs;
     private boolean isDumpLog = true;
     private ICameraContentListCallback callback = null;
     private SparseArray<NikonStorageContentHolder> storageIdList;
 
-    NikonImageObjectReceiver(NikonInterfaceProvider provider)
+    NikonImageObjectReceiver(NikonInterfaceProvider provider, int delayMs)
     {
         this.provider = provider;
+        this.delayMs = delayMs;
         this.storageIdList = new SparseArray<>();
     }
 
@@ -50,7 +52,7 @@ public class NikonImageObjectReceiver implements IPtpIpCommandCallback, NikonSto
                                  ((int) rx_body[readPosition + 1] << 8) +
                                  ((int) rx_body[readPosition + 2] << 16) +
                                  ((int) rx_body[readPosition + 3] << 24);
-                storageIdList.append(storageId, new NikonStorageContentHolder(provider, storageId, this));
+                storageIdList.append(storageId, new NikonStorageContentHolder(provider, storageId, this, delayMs));
                 readPosition = readPosition + 4;
             }
             Log.v(TAG, " NOF STORAGE IDs : " + storageIdList.size() + " ");
@@ -189,7 +191,7 @@ public class NikonImageObjectReceiver implements IPtpIpCommandCallback, NikonSto
             if (publisher != null)
             {
                 // オブジェクト一覧をクリアする
-                publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_STORAGE_ID, 50, isDumpLog, 0, 0x1004, 0, 0, 0, 0, 0));  // GetStorageIDs
+                publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_STORAGE_ID, delayMs, isDumpLog, 0, 0x1004, 0, 0, 0, 0, 0));  // GetStorageIDs
                 this.callback = callback;
             }
         }
index 74193a5..deff21b 100644 (file)
@@ -5,12 +5,10 @@ import android.content.SharedPreferences;
 import android.graphics.Color;
 import android.util.Log;
 
-import androidx.annotation.NonNull;
 import androidx.preference.PreferenceManager;
 
 import net.osdn.gokigen.pkremote.IInformationReceiver;
 import net.osdn.gokigen.pkremote.R;
-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;
@@ -40,35 +38,44 @@ public class NikonPlaybackControl implements IPlaybackControl
     private final Activity activity;
     private final NikonInterfaceProvider provider;
     private final NikonFullImageReceiver fullImageReceiver;
-    //private final NikonSmallImageReceiver smallImageReciever;
-   // private String raw_suffix = "NEF";
+    private int delayMs = 50;
+    private final NikonSmallImageReceiver smallImageReciever;
     private boolean use_screennail_image = false;
     private NikonImageObjectReceiver nikonImageObjectReceiver;
 
     public NikonPlaybackControl(Activity activity, NikonInterfaceProvider provider)
     {
-        this.activity = activity;
-        this.provider = provider;
-        nikonImageObjectReceiver = new NikonImageObjectReceiver(provider);
-        this.fullImageReceiver = new NikonFullImageReceiver(activity, provider.getCommandPublisher());
-        //this.smallImageReciever = new NikonSmallImageReceiver(activity, provider.getCommandPublisher());
-
         try
         {
             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
-            //raw_suffix = preferences.getString(IPreferencePropertyAccessor.CANON_RAW_SUFFIX, IPreferencePropertyAccessor.CANON_RAW_SUFFIX_DEFAULT_VALUE);
             use_screennail_image = preferences.getBoolean(IPreferencePropertyAccessor.NIKON_USE_SCREENNAIL_AS_SMALL, false);
+
+            try
+            {
+                delayMs = Integer.parseInt(preferences.getString(IPreferencePropertyAccessor.NIKON_RECEIVE_WAIT, IPreferencePropertyAccessor.NIKON_RECEIVE_WAIT_DEFAULT_VALUE));
+            }
+            catch (Exception ee)
+            {
+                delayMs = 50;
+                ee.printStackTrace();
+            }
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
+
+        this.activity = activity;
+        this.provider = provider;
+        nikonImageObjectReceiver = new NikonImageObjectReceiver(provider, delayMs);
+        this.fullImageReceiver = new NikonFullImageReceiver(provider.getCommandPublisher(), delayMs);
+        this.smallImageReciever = new NikonSmallImageReceiver(provider.getCommandPublisher(), delayMs);
+
     }
 
     @Override
     public String getRawFileSuffix()
     {
-        //return (raw_suffix);
         return ("NEF");
     }
 
@@ -124,7 +131,7 @@ public class NikonPlaybackControl implements IPlaybackControl
                 }
 
                 // 画像を取得する
-                publisher.enqueueCommand(new PtpIpCommandGeneric(new NikonScreennailImageReceiver(activity, callback), objectId, 75, false, 0, 0x90c4, 4, objectId, 0, 0, 0));
+                publisher.enqueueCommand(new PtpIpCommandGeneric(new NikonScreennailImageReceiver(activity, callback), objectId, delayMs, false, 0, 0x90c4, 4, objectId, 0, 0, 0));
             }
         }
         catch (Exception e)
@@ -172,7 +179,7 @@ public class NikonPlaybackControl implements IPlaybackControl
                 }
 
                 // Log.v(TAG, "downloadContentThumbnail() " + indexStr + " [" + objectId + "] (" + storageId + ")");
-                publisher.enqueueCommand(new PtpIpCommandGeneric(new PtpIpThumbnailImageReceiver(activity, callback), objectId, 75, false, 0, 0x100a, 4, objectId, 0, 0, 0));  // getThumb
+                publisher.enqueueCommand(new PtpIpCommandGeneric(new PtpIpThumbnailImageReceiver(activity, callback), objectId, delayMs, false, 0, 0x100a, 4, objectId, 0, 0, 0));  // getThumb
             }
         }
         catch (Exception e)
@@ -256,8 +263,8 @@ public class NikonPlaybackControl implements IPlaybackControl
                 if (isSmallSize)
                 {
                     // スモールサイズの画像取得コマンド(シーケンス)を発行する
-                    //smallImageReciever.issueCommand(content.getObjectId(), callback);
-                    fullImageReceiver.issueCommand(content.getObjectId(), content.getOriginalSize(), callback);
+                    smallImageReciever.issueCommand(content.getObjectId(), callback);
+                    //fullImageReceiver.issueCommand(content.getObjectId(), content.getOriginalSize(), callback);
                 }
                 else
                 {
index 1baa4d0..b0c880a 100644 (file)
@@ -1,6 +1,5 @@
 package net.osdn.gokigen.pkremote.camera.vendor.nikon.wrapper.playback;
 
-import android.app.Activity;
 import android.util.Log;
 
 import androidx.annotation.NonNull;
@@ -19,7 +18,6 @@ public class NikonSmallImageReceiver implements IPtpIpCommandCallback
 {
     private static final String TAG = NikonFullImageReceiver.class.getSimpleName();
 
-    private final Activity activity;
     private final IPtpIpCommandPublisher publisher;
     private IDownloadContentCallback callback = null;
 
@@ -31,11 +29,12 @@ public class NikonSmallImageReceiver implements IPtpIpCommandCallback
 
     private int target_image_size = 0;
     private boolean receivedFirstData = false;
+    private int delayMs;
 
-    NikonSmallImageReceiver(@NonNull Activity activity, @NonNull IPtpIpCommandPublisher publisher)
+    NikonSmallImageReceiver(@NonNull IPtpIpCommandPublisher publisher, int delayMs)
     {
-        this.activity = activity;
         this.publisher = publisher;
+        this.delayMs = delayMs;
     }
 
     void issueCommand(int objectId, IDownloadContentCallback callback)
@@ -52,7 +51,7 @@ public class NikonSmallImageReceiver implements IPtpIpCommandCallback
         this.receivedFirstData = false;
         //Log.v(TAG, " getPartialObject (id : " + objectId + ", size:" + imageSize + ")");
         //publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_PARTIAL_OBJECT, true, 0, 0x101b, 12, objectId, 0, imageSize));  // GetPartialObject 0x101b
-        publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_PARTIAL_OBJECT, 75, true, 0, 0x90c4, 4, objectId, 0, 0, 0));  // GetLargeThumb
+        publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_PARTIAL_OBJECT, delayMs, true, 0, 0x90c4, 4, objectId, 0, 0, 0));  // GetLargeThumb
     }
 
     @Override
index 4db7331..e330195 100644 (file)
@@ -26,14 +26,16 @@ public class NikonStorageContentHolder  implements IPtpIpCommandCallback
     private boolean isDumpLog = false;
     private int subDirectoryCount = 0;
     private int receivedDirectoryCount = 0;
+    private int delayMs;
     private boolean isObjectReceived = false;
     private SparseArray<NikonImageContentInfo> imageObjectList;
 
-    NikonStorageContentHolder(@NonNull NikonInterfaceProvider provider, int storageId, @NonNull ImageObjectReceivedCallback callback)
+    NikonStorageContentHolder(@NonNull NikonInterfaceProvider provider, int storageId, @NonNull ImageObjectReceivedCallback callback, int delayMs)
     {
         this.provider = provider;
         this.storageId = storageId;
         this.callback = callback;
+        this.delayMs = delayMs;
         this.imageObjectList = new SparseArray<>();
     }
 
@@ -43,7 +45,7 @@ public class NikonStorageContentHolder  implements IPtpIpCommandCallback
         {
             isObjectReceived = false;
             IPtpIpCommandPublisher publisher = provider.getCommandPublisher();
-            publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_STORAGE_HANDLE1, 35, isDumpLog, 0, 0x1007, 12, storageId, 0x00003001, 0xffffffff, 0));
+            publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_STORAGE_HANDLE1, delayMs, isDumpLog, 0, 0x1007, 12, storageId, 0x00003001, 0xffffffff, 0));
             imageObjectList.clear();
         }
         catch (Exception e)
@@ -96,7 +98,7 @@ public class NikonStorageContentHolder  implements IPtpIpCommandCallback
                 for (int subDirectory : directoriesList)
                 {
                     Log.v(TAG, "  STORAGE ID : " + storageId + "  DIRECTORY ID : " + subDirectory);
-                    publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_STORAGE_HANDLE2, 35, isDumpLog, 0, 0x1007, 12, storageId, 0x00000000, subDirectory, 0)); //
+                    publisher.enqueueCommand(new PtpIpCommandGeneric(this, GET_STORAGE_HANDLE2, delayMs, isDumpLog, 0, 0x1007, 12, storageId, 0x00000000, subDirectory, 0)); //
                 }
                 return;
             }
@@ -139,7 +141,7 @@ public class NikonStorageContentHolder  implements IPtpIpCommandCallback
                         public boolean isReceiveMulti() {
                             return false;
                         }
-                    }, GET_STORAGE_HANDLE3, 35, isDumpLog, 0, 0x1007, 12, storageId, 0x00000000, subDirectory, 0));
+                    }, GET_STORAGE_HANDLE3, delayMs, isDumpLog, 0, 0x1007, 12, storageId, 0x00000000, subDirectory, 0));
 
 /*
                     //  ストレージ名称。。。ここでは利用できない
index 64a9e7f..47a61db 100644 (file)
@@ -109,6 +109,10 @@ public interface IPreferencePropertyAccessor
     String NIKON_CAMERA_IP_ADDRESS = "nikon_host_ip";
     String NIKON_CAMERA_IP_ADDRESS_DEFAULT_VALUE = "192.168.1.1";
 
+    String NIKON_RECEIVE_WAIT = "nikon_receive_wait";
+    String NIKON_RECEIVE_WAIT_DEFAULT_VALUE = "50";
+
+
     /*
     //String GR2_DISPLAY_MODE = "gr2_display_mode";
     //String GR2_DISPLAY_MODE_DEFAULT_VALUE = "0";
index e00aaaf..bb602c5 100644 (file)
@@ -129,6 +129,9 @@ public class NikonPreferenceFragment  extends PreferenceFragmentCompat implement
             if (!items.containsKey(IPreferencePropertyAccessor.NIKON_CAMERA_IP_ADDRESS)) {
                 editor.putString(IPreferencePropertyAccessor.NIKON_CAMERA_IP_ADDRESS, IPreferencePropertyAccessor.NIKON_CAMERA_IP_ADDRESS_DEFAULT_VALUE);
             }
+            if (!items.containsKey(IPreferencePropertyAccessor.NIKON_RECEIVE_WAIT)) {
+                editor.putString(IPreferencePropertyAccessor.NIKON_RECEIVE_WAIT, IPreferencePropertyAccessor.NIKON_RECEIVE_WAIT_DEFAULT_VALUE);
+            }
             if (!items.containsKey(IPreferencePropertyAccessor.NIKON_USE_SCREENNAIL_AS_SMALL)) {
                 editor.putBoolean(IPreferencePropertyAccessor.NIKON_USE_SCREENNAIL_AS_SMALL, false);
             }
index 39de67d..50affbd 100644 (file)
     <string name="pref_wifi_settings">WiFi設定</string>
     <string name="pref_summary_wifi_settings"> </string>
 
+    <string name="pref_nikon_receive_wait">応答受信待ち時間</string>
+    <string name="pref_summary_nikon_receive_wait">カメラからの応答待ち時間(単位:ms)</string>
+
 </resources>
index a53072f..3563a24 100644 (file)
     <string name="pref_wifi_settings">WIFI Settings</string>
     <string name="pref_summary_wifi_settings"> </string>
 
+    <string name="pref_nikon_receive_wait">Receive reply wait(ms)</string>
+    <string name="pref_summary_nikon_receive_wait"> </string>
+
 </resources>
index defba82..a2d3c26 100644 (file)
             android:title="@string/pref_nikon_host_ip"
             android:defaultValue="192.168.1.1"
             android:summary="@string/pref_summary_nikon_host_ip" />
+
+        <EditTextPreference
+            android:key="nikon_receive_wait"
+            android:title="@string/pref_nikon_receive_wait"
+            android:defaultValue="50"
+            android:summary="@string/pref_summary_nikon_receive_wait" />
+
 <!--
         <CheckBoxPreference
             android:key="ble_wifi_on"