OSDN Git Service

一覧取得部分を改修。
authorMRSa <mrsa@myad.jp>
Sat, 21 Sep 2019 14:06:52 +0000 (23:06 +0900)
committerMRSa <mrsa@myad.jp>
Sat, 21 Sep 2019 14:06:52 +0000 (23:06 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/playback/CanonImageObjectReceiver.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/playback/PtpIpImageContentInfo.java

index f619e41..22bc08d 100644 (file)
@@ -139,7 +139,7 @@ public class CanonImageObjectReceiver implements IPtpIpCommandCallback
                 id = id + ((rx_body[dataIndex + 2] & 0xff) << 16);
                 id = id + ((rx_body[dataIndex + 3] & 0xff) << 24);
 
-                PtpIpImageContentInfo content = new PtpIpImageContentInfo(id, rx_body, dataIndex, objectSize);
+                PtpIpImageContentInfo content = new PtpIpImageContentInfo(id, "", rx_body, dataIndex, objectSize);
                 result.add(content);
                 dataIndex = dataIndex + objectSize;
                 if (result.size() >= nofObjects)
index f757b2d..0867e62 100644 (file)
@@ -3,41 +3,48 @@ package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback;
 import android.util.Log;
 
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
-import net.osdn.gokigen.pkremote.camera.utils.SimpleLogDumper;
 
 import java.util.Arrays;
 import java.util.Date;
+import java.util.TimeZone;
 
 
-
-/*
-  --- CONTENT (IMAGE OBJECTS) ---
-  0000:91 99 b8 01 01 00 01 00 01 38 00 00 00 00 00 00
-  0010:20 00 00 00 69 42 58 00 00 00 b8 01 90 99 b8 01
-  0020:49 4d 47 5f 32 34 35 37 2e 4a 50 47 00 00 00 00
-  0030:e6 6b 86 5d
-*/
-
 public class PtpIpImageContentInfo implements ICameraContent
 {
     private final String TAG = toString();
     private final int indexNumber;
+    private final String contentPath;
     private boolean isDateValid;
     private Date date;
-    private String realFileName;
-    private byte[] rx_body;
+    private final byte[] rx_body;
 
-    PtpIpImageContentInfo(int indexNumber, byte[] binaryData, int offset, int length)
+    PtpIpImageContentInfo(int indexNumber, String contentPath, byte[] binaryData, int offset, int length)
     {
         this.indexNumber = indexNumber;
+        this.contentPath = contentPath;
         this.rx_body = Arrays.copyOfRange(binaryData, offset, offset + length);
-        Log.v(TAG, " --- CONTENT ---");
-        SimpleLogDumper.dump_bytes(" [(" + length + ")] ", this.rx_body);
+        try
+        {
+            //  撮影日時を解析
+            long objectDate = (rx_body[0x30] & 0xff) + ((rx_body[0x31] & 0xff) << 8);
+            objectDate = objectDate + ((rx_body[0x32] & 0xff) << 16) + ((rx_body[0x33] & 0xff) << 24);
 
-        //  動作用...
+            //  UTC から 端末のタイムゾーンに変換する(オフセット時間をとる)
+            TimeZone tz = TimeZone.getDefault();
+            Date now = new Date();
+            long offsetFromUtc = tz.getOffset(now.getTime());
+
+            date = new Date(objectDate * 1000 - offsetFromUtc);
+            isDateValid = true;
+            return;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
         date = new Date();
         isDateValid = false;
-        realFileName = "";
+        Log.v(TAG, "  > CONTENT : " + date + " ");
     }
 
     @Override
@@ -55,7 +62,7 @@ public class PtpIpImageContentInfo implements ICameraContent
     @Override
     public String getContentPath()
     {
-        return ("");
+        return (contentPath);
     }
 
     @Override
@@ -63,15 +70,14 @@ public class PtpIpImageContentInfo implements ICameraContent
     {
         try
         {
-            if ((realFileName != null)&&(realFileName.contains(".MOV")))
-            {
-                return ("" + indexNumber + ".MOV");
-            }
+            byte[] fileNameArray = Arrays.copyOfRange(rx_body, 0x20, 0x20 + 8 + 1 + 3);
+            return (new String(fileNameArray));
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
+        Log.v(TAG, "    > File Name : " + indexNumber + ".JPG");
         return ("" + indexNumber + ".JPG");
     }
 
@@ -105,48 +111,4 @@ public class PtpIpImageContentInfo implements ICameraContent
     {
         return (indexNumber);
     }
-
-/*
-    public boolean isReceived()
-    {
-        return (isReceived);
-    }
-
-    private void updateInformation(byte[] rx_body)
-    {
-        try
-        {
-            if (rx_body.length >= 166)
-            {
-                // データの切り出し
-                realFileName = new String(pickupString(rx_body, 65, 12));
-                String dateString = new String(pickupString(rx_body, 92, 15));
-                //char orientation = Character.(rx_body[151]);
-                Log.v(TAG, "[" + indexNumber + "] FILE NAME : " + realFileName + "  DATE : '" + dateString + "'");
-                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss", Locale.ENGLISH);
-                date = dateFormat.parse(dateString);
-                isDateValid = true;
-                isReceived = true;
-            }
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-    }
-
- */
-    /**
-     *   文字列を無理やり切り出す...
-     *
-     */
-    private byte[] pickupString(byte[] data, int start, int length)
-    {
-        byte[] result = new byte[length];
-        for (int index = 0; index < length; index++)
-        {
-            result[index] = data[start + index * 2];
-        }
-        return (result);
-    }
 }