OSDN Git Service

切断・接続について少し改善する。
authorMRSa <mrsa@myad.jp>
Thu, 5 Dec 2019 14:47:16 +0000 (23:47 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 5 Dec 2019 14:47:16 +0000 (23:47 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/command/PtpIpCommandPublisher.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/command/messages/specific/NikonRegistrationMessage.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/connection/NikonCameraDisconnectSequence.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/connection/NikonConnection.java
app/src/main/java/net/osdn/gokigen/pkremote/playback/ImageGridViewFragment.java
app/src/main/java/net/osdn/gokigen/pkremote/scene/CameraSceneUpdater.java
app/src/main/res/values-ja/strings.xml

index e5905b2..2a381c3 100644 (file)
@@ -113,6 +113,8 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
         }
         socket = null;
         sequenceNumber = SEQUENCE_START_NUMBER;
+        isStart = false;
+        commandQueue.clear();
         System.gc();
     }
 
@@ -284,6 +286,12 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
     {
         try
         {
+            if (dos == null)
+            {
+                Log.v(TAG, " DataOutputStream is null.");
+                return;
+            }
+
             //dos = new DataOutputStream(socket.getOutputStream());  // ここにいたらいけない?
 
             // メッセージボディを加工: 最初に4バイトのレングス長をつける
index 29d9f11..5e07722 100644 (file)
@@ -5,6 +5,7 @@ import android.app.Activity;
 import androidx.annotation.NonNull;
 
 import net.osdn.gokigen.pkremote.camera.vendor.nikon.INikonInterfaceProvider;
+import net.osdn.gokigen.pkremote.camera.vendor.nikon.wrapper.status.NikonStatusChecker;
 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommunication;
 
 
@@ -15,13 +16,15 @@ class NikonCameraDisconnectSequence implements Runnable
     private final IPtpIpCommunication command;
     private final IPtpIpCommunication async;
     private final IPtpIpCommunication liveview;
+    private final NikonStatusChecker statusChecker;
 
-    NikonCameraDisconnectSequence(Activity activity, @NonNull INikonInterfaceProvider interfaceProvider)
+    NikonCameraDisconnectSequence(Activity activity, @NonNull INikonInterfaceProvider interfaceProvider, @NonNull NikonStatusChecker statusChecker)
     {
         this.activity = activity;
         this.command = interfaceProvider.getCommandCommunication();
         this.async = interfaceProvider.getAsyncEventCommunication();
         this.liveview = interfaceProvider.getLiveviewCommunication();
+        this.statusChecker = statusChecker;
     }
 
     @Override
@@ -29,6 +32,7 @@ class NikonCameraDisconnectSequence implements Runnable
     {
         try
         {
+            statusChecker.stopStatusWatch();
             liveview.disconnect();
             async.disconnect();
             command.disconnect();
index 6396e31..d7d7d69 100644 (file)
@@ -32,16 +32,18 @@ public class NikonConnection implements ICameraConnection
     private final INikonInterfaceProvider interfaceProvider;
     private final BroadcastReceiver connectionReceiver;
     private final Executor cameraExecutor = Executors.newFixedThreadPool(1);
-    private final NikonStatusChecker statusChecker;
+
     private CameraConnectionStatus connectionStatus = CameraConnectionStatus.UNKNOWN;
 
+    private final NikonCameraConnectSequenceForPlayback connectSequence;
+    private final NikonCameraDisconnectSequence disconnectSequence;
+
     public NikonConnection(@NonNull final Activity context, @NonNull final ICameraStatusReceiver statusReceiver, @NonNull INikonInterfaceProvider interfaceProvider, @NonNull NikonStatusChecker statusChecker)
     {
         Log.v(TAG, "NikonConnection()");
         this.context = context;
         this.statusReceiver = statusReceiver;
         this.interfaceProvider = interfaceProvider;
-        this.statusChecker = statusChecker;
         connectionReceiver = new BroadcastReceiver()
         {
             @Override
@@ -50,6 +52,8 @@ public class NikonConnection implements ICameraConnection
                 onReceiveBroadcastOfConnection(context, intent);
             }
         };
+        connectSequence = new NikonCameraConnectSequenceForPlayback(context, statusReceiver, this, interfaceProvider, statusChecker);
+        disconnectSequence = new NikonCameraDisconnectSequence(context, interfaceProvider, statusChecker);
     }
 
     /**
@@ -207,7 +211,7 @@ public class NikonConnection implements ICameraConnection
         Log.v(TAG, " disconnectFromCamera()");
         try
         {
-            cameraExecutor.execute(new NikonCameraDisconnectSequence(context, interfaceProvider));
+            cameraExecutor.execute(disconnectSequence);
         }
         catch (Exception e)
         {
@@ -224,7 +228,7 @@ public class NikonConnection implements ICameraConnection
         connectionStatus = CameraConnectionStatus.CONNECTING;
         try
         {
-            cameraExecutor.execute(new NikonCameraConnectSequenceForPlayback(context, statusReceiver, this, interfaceProvider, statusChecker));
+            cameraExecutor.execute(connectSequence);
         }
         catch (Exception e)
         {
index d9cc9a3..956cd1e 100644 (file)
@@ -805,6 +805,18 @@ public class ImageGridViewFragment extends Fragment implements AdapterView.OnIte
         }
     }
 
+    public void clearImageCache()
+    {
+        try
+        {
+            imageCache.evictAll();
+            Log.v(TAG, " clearImageCache()");
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
 
     public void setFilterLabel(String filterLabel)
     {
index a684bfa..4325b8c 100644 (file)
@@ -397,11 +397,19 @@ public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene,
         try
         {
             ICameraContentsRecognizer recognizer = interfaceProvider.getCameraContentsRecognizer();
-            if (recognizer != null) {
+            if (recognizer != null)
+            {
                 // カメラ内のコンテンツ一覧を作成するように指示する
                 recognizer.getRemoteCameraContentsList(true, this);
             }
-        } catch (Exception e) {
+            if (gridViewFragment != null)
+            {
+                // サムネイル画像のキャッシュをクリアする
+                gridViewFragment.clearImageCache();
+            }
+        }
+        catch (Exception e)
+        {
             e.printStackTrace();
         }
     }
index 147c36c..fdc45e7 100644 (file)
     <string name="time_picker_end_separator"> </string>
     <string name="information_month_picker">年・月を指定</string>
 
-    <string name="get_camera_contents_wait">画像確認&#8230;お待ちください</string>
+    <string name="get_camera_contents_wait">画像確認&#8230;お待ちください</string>
     <string name="get_camera_contents_error">画像確認&#8230; エラー</string>
     <string name="get_camera_contents_finished">画像数 </string>
     <string name="get_camera_contents_error_retry">再実行しますか?</string>