OSDN Git Service

データ読み込み詰まりを抑止したつもり。
authorMRSa <mrsa@myad.jp>
Sun, 22 Sep 2019 05:57:39 +0000 (14:57 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 22 Sep 2019 05:57:39 +0000 (14:57 +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/playback/PtpIpPlaybackControl.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/ptpip/wrapper/playback/PtpIpThumbnailImageReceiver.java
app/src/main/java/net/osdn/gokigen/pkremote/preference/IPreferencePropertyAccessor.java
app/src/main/java/net/osdn/gokigen/pkremote/preference/canon/CanonPreferenceFragment.java
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences_canon.xml

index 3a6e4d9..dbb60d1 100644 (file)
@@ -316,6 +316,13 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
                                 Log.v(TAG, "--- RECEIVE AGAIN --- [" + length + "(" + read_bytes + ") " + byte_array[4]+ "] ");
                             }
                             sleep(delayMs);
+                            int availableReadBytes = is.available();
+                            if (availableReadBytes <= 0)
+                            {
+                                // 読めるデータ数がない...よみだし終了にする。
+                                Log.v(TAG, "  is.availableReadBytes() :  " + availableReadBytes);
+                                break;
+                            }
                             int read_bytes2 = is.read(byte_array, read_bytes, receive_message_buffer_size - read_bytes);
                             if (read_bytes2 > 0)
                             {
@@ -362,7 +369,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
                     Log.v(TAG, "receive_from_camera() : " + read_bytes + " bytes.");
                     dump_bytes("RECV[" + receive_body.length + "] ", receive_body);
                 }
-               if (callback != null)
+                if (callback != null)
                 {
                     if (callback.isReceiveMulti())
                     {
index 8cc791b..6a4d02f 100644 (file)
@@ -1,10 +1,10 @@
 package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback;
 
 import android.app.Activity;
-import android.graphics.BitmapFactory;
-import android.util.Log;
+import android.content.SharedPreferences;
+
+import androidx.preference.PreferenceManager;
 
-import net.osdn.gokigen.pkremote.R;
 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;
@@ -13,9 +13,9 @@ import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentList
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.PtpIpInterfaceProvider;
-import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandPublisher;
 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
+import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
 
 /**
  *
@@ -26,10 +26,7 @@ public class PtpIpPlaybackControl implements IPlaybackControl
     private final String TAG = toString();
     private final Activity activity;
     private final PtpIpInterfaceProvider provider;
-    //private List<ICameraContent> imageInfo;
-    //private SparseArray<PtpIpImageContentInfo> imageContentInfo;
-    //private int indexNumber = 0;
-    //private ICameraContentListCallback finishedCallback = null;
+    private String raw_suffix = "CR2";
     private CanonImageObjectReceiver canonImageObjectReceiver;
 
     public PtpIpPlaybackControl(Activity activity, PtpIpInterfaceProvider provider)
@@ -37,13 +34,22 @@ public class PtpIpPlaybackControl implements IPlaybackControl
         this.activity = activity;
         this.provider = provider;
         canonImageObjectReceiver = new CanonImageObjectReceiver(provider);
-        //this.imageContentInfo = new SparseArray<>();
+
+        try
+        {
+            SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+            raw_suffix = preferences.getString(IPreferencePropertyAccessor.CANON_RAW_SUFFIX, IPreferencePropertyAccessor.CANON_RAW_SUFFIX_DEFAULT_VALUE);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
     }
 
     @Override
     public String getRawFileSuffix()
     {
-        return (null);
+        return (raw_suffix);
     }
 
     @Override
@@ -95,19 +101,6 @@ public class PtpIpPlaybackControl implements IPlaybackControl
                 // Log.v(TAG, "downloadContentThumbnail() " + indexStr + " [" + objectId + "] (" + storageId + ")");
                 publisher.enqueueCommand(new PtpIpCommandGeneric(new PtpIpThumbnailImageReceiver(activity, callback), false, objectId, 0x910a, 8, objectId, 0x00032000));
             }
-/*
-            int index = Integer.parseInt(indexStr);
-            if ((index > 0)&&(index <= imageContentInfo.size()))
-            {
-                IPtpIpCommandPublisher publisher = provider.getCommandPublisher();
-                PtpIpImageContentInfo contentInfo = imageContentInfo.get(index);
-                if (!contentInfo.isReceived())
-                {
-                    publisher.enqueueCommand(new GetImageInfo(index, index, contentInfo));
-                }
-                publisher.enqueueCommand(new GetThumbNail(index, new PtpIpThumbnailImageReceiver(activity, callback)));
-            }
- */
         }
         catch (Exception e)
         {
index 77b68f3..4a437db 100644 (file)
@@ -6,12 +6,9 @@ import android.util.Log;
 
 import androidx.annotation.NonNull;
 
-import net.osdn.gokigen.pkremote.R;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
-import net.osdn.gokigen.pkremote.camera.utils.SimpleLogDumper;
 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
 
-import java.io.ByteArrayInputStream;
 import java.util.Arrays;
 
 public class PtpIpThumbnailImageReceiver implements IPtpIpCommandCallback
@@ -31,11 +28,11 @@ public class PtpIpThumbnailImageReceiver implements IPtpIpCommandCallback
     {
         try
         {
-            /////// 受信データから、先頭(0xff 0xd8)を検索  /////
             //Log.v(TAG, "  RECV THUMBNAIL START : " + id + " [" + rx_body.length + "] ");
             //SimpleLogDumper.dump_bytes("[THUMB]", rx_body);
             //Log.v(TAG, "  RECV THUMBNAIL END : " + id + " [" + rx_body.length + "] ");
 
+            /////// 受信データから、サムネイルの先頭(0xff 0xd8)を検索する  /////
             int offset = rx_body.length - 22;
             //byte[] thumbnail0 = Arrays.copyOfRange(rx_body, 0, rx_body.length);
             while (offset > 32)
@@ -46,21 +43,8 @@ public class PtpIpThumbnailImageReceiver implements IPtpIpCommandCallback
                 }
                 offset--;
             }
-            if (rx_body.length > offset)
-            {
-                byte[] thumbnail = Arrays.copyOfRange(rx_body, offset, rx_body.length - 22);
-                callback.onCompleted(BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length), null);
-
-                //callback.onCompleted(BitmapFactory.decodeByteArray(rx_body, 0, rx_body.length), null);
-                //callback.onCompleted(BitmapFactory.decodeByteArray(rx_body, offset, rx_body.length - offset - 22), null);
-                //callback.onCompleted(BitmapFactory.decodeStream(new ByteArrayInputStream(rx_body, offset, rx_body.length)), null);
-                //callback.onCompleted(BitmapFactory.decodeStream(new ByteArrayInputStream(rx_body, 0, rx_body.length)), null);
-            }
-            else
-            {
-                Log.v(TAG, "BITMAP IS NONE... : " + rx_body.length);
-                callback.onCompleted(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_broken_image_black_24dp), null);
-            }
+            byte[] thumbnail = Arrays.copyOfRange(rx_body, offset, rx_body.length - 22);
+            callback.onCompleted(BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length), null);
         }
         catch (Exception e)
         {
index cbf6934..41660a1 100644 (file)
@@ -87,6 +87,9 @@ public interface IPreferencePropertyAccessor
 
     String USE_SMARTPHONE_TRANSFER_MODE = "use_smartphone_transfer_mode";
 
+    String CANON_RAW_SUFFIX = "canon_raw_suffix";
+    String CANON_RAW_SUFFIX_DEFAULT_VALUE = "CR2";
+
     /*
     //String GR2_DISPLAY_MODE = "gr2_display_mode";
     //String GR2_DISPLAY_MODE_DEFAULT_VALUE = "0";
index ed8c023..6ea85bf 100644 (file)
@@ -1,26 +1,26 @@
 package net.osdn.gokigen.pkremote.preference.canon;
 
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.os.Bundle;
-import android.util.Log;
-
-import java.util.Map;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.fragment.app.FragmentActivity;
-import androidx.preference.CheckBoxPreference;
-import androidx.preference.ListPreference;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceFragmentCompat;
-import androidx.preference.PreferenceManager;
-
-import net.osdn.gokigen.pkremote.R;
-import net.osdn.gokigen.pkremote.camera.vendor.ptpip.operation.PtpIpCameraPowerOff;
-import net.osdn.gokigen.pkremote.logcat.LogCatViewer;
-import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
-import net.osdn.gokigen.pkremote.scene.IChangeScene;
+        import android.content.Context;
+        import android.content.SharedPreferences;
+        import android.os.Bundle;
+        import android.util.Log;
+
+        import java.util.Map;
+
+        import androidx.annotation.NonNull;
+        import androidx.appcompat.app.AppCompatActivity;
+        import androidx.fragment.app.FragmentActivity;
+        import androidx.preference.CheckBoxPreference;
+        import androidx.preference.ListPreference;
+        import androidx.preference.Preference;
+        import androidx.preference.PreferenceFragmentCompat;
+        import androidx.preference.PreferenceManager;
+
+        import net.osdn.gokigen.pkremote.R;
+        import net.osdn.gokigen.pkremote.camera.vendor.ptpip.operation.PtpIpCameraPowerOff;
+        import net.osdn.gokigen.pkremote.logcat.LogCatViewer;
+        import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
+        import net.osdn.gokigen.pkremote.scene.IChangeScene;
 
 /**
  *
@@ -117,6 +117,9 @@ public class CanonPreferenceFragment  extends PreferenceFragmentCompat implement
             if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD)) {
                 editor.putString(IPreferencePropertyAccessor.CONNECTION_METHOD, IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
             }
+            if (!items.containsKey(IPreferencePropertyAccessor.CANON_RAW_SUFFIX)) {
+                editor.putString(IPreferencePropertyAccessor.CANON_RAW_SUFFIX, IPreferencePropertyAccessor.CANON_RAW_SUFFIX_DEFAULT_VALUE);
+            }
             editor.apply();
         }
         catch (Exception e)
@@ -167,7 +170,7 @@ public class CanonPreferenceFragment  extends PreferenceFragmentCompat implement
         try
         {
             //super.onCreate(savedInstanceState);
-            addPreferencesFromResource(R.xml.preferences_fuji_x);
+            addPreferencesFromResource(R.xml.preferences_canon);
 
             ListPreference connectionMethod = (ListPreference) findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
             connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -181,7 +184,7 @@ public class CanonPreferenceFragment  extends PreferenceFragmentCompat implement
 
             findPreference("exit_application").setOnPreferenceClickListener(powerOffController);
             findPreference("debug_info").setOnPreferenceClickListener(logCatViewer);
-    }
+        }
         catch (Exception e)
         {
             e.printStackTrace();
index 34a3d5a..8ccf9ec 100644 (file)
     <string name="pref_sony_use_smartphone_transfer">スマートフォン転送モードを使う</string>
     <string name="pref_summary_sony_use_smartphone_transfer">うまく通信できない場合にチェックを入れてください。</string>
 
+    <string name="pref_canon_raw_suffix">RAW拡張子</string>
+    <string name="pref_summary_canon_raw_suffix">カメラのRAW拡張子を設定してください。</string>
+
     <string name="connect_start_2">準備中&#8230;</string>
     <string name="canon_connect_connecting1">接続中&#8230;(1/5)</string>
     <string name="canon_connect_connecting2">接続中&#8230;(2/5)</string>
index 495e8b1..d96489d 100644 (file)
     <string name="pref_sony_use_smartphone_transfer">Do use SmartPhone transfer mode.</string>
     <string name="pref_summary_sony_use_smartphone_transfer">If you cannot communicate, please check this.</string>
 
+    <string name="pref_canon_raw_suffix">RAW Suffix</string>
+    <string name="pref_summary_canon_raw_suffix">Please set your camera RAW suffix.</string>
+
     <string name="connect_start_2">Preparing&#8230;</string>
     <string name="canon_connect_connecting1">Connecting&#8230;(1/5)</string>
     <string name="canon_connect_connecting2">Connecting&#8230;(2/5)</string>
index 58394c3..d09200e 100644 (file)
     <PreferenceCategory
         android:title="@string/pref_cat_camera">
 
+
+        <EditTextPreference
+            android:key="canon_raw_suffix"
+            android:title="@string/pref_canon_raw_suffix"
+            android:defaultValue="CR2"
+            android:inputType="number"
+            android:summary="@string/pref_summary_canon_raw_suffix" />
+
         <!--
 
         <PreferenceScreen