Pentax DSLR Remote Control app.
Revision | 604d58d5cf166e7ac418cdaa82c13ca59f537901 (tree) |
---|---|
Zeit | 2019-09-22 14:57:39 |
Autor | MRSa <mrsa@myad...> |
Commiter | MRSa |
データ読み込み詰まりを抑止したつもり。
@@ -316,6 +316,13 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm | ||
316 | 316 | Log.v(TAG, "--- RECEIVE AGAIN --- [" + length + "(" + read_bytes + ") " + byte_array[4]+ "] "); |
317 | 317 | } |
318 | 318 | sleep(delayMs); |
319 | + int availableReadBytes = is.available(); | |
320 | + if (availableReadBytes <= 0) | |
321 | + { | |
322 | + // 読めるデータ数がない...よみだし終了にする。 | |
323 | + Log.v(TAG, " is.availableReadBytes() : " + availableReadBytes); | |
324 | + break; | |
325 | + } | |
319 | 326 | int read_bytes2 = is.read(byte_array, read_bytes, receive_message_buffer_size - read_bytes); |
320 | 327 | if (read_bytes2 > 0) |
321 | 328 | { |
@@ -362,7 +369,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm | ||
362 | 369 | Log.v(TAG, "receive_from_camera() : " + read_bytes + " bytes."); |
363 | 370 | dump_bytes("RECV[" + receive_body.length + "] ", receive_body); |
364 | 371 | } |
365 | - if (callback != null) | |
372 | + if (callback != null) | |
366 | 373 | { |
367 | 374 | if (callback.isReceiveMulti()) |
368 | 375 | { |
@@ -1,10 +1,10 @@ | ||
1 | 1 | package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback; |
2 | 2 | |
3 | 3 | import android.app.Activity; |
4 | -import android.graphics.BitmapFactory; | |
5 | -import android.util.Log; | |
4 | +import android.content.SharedPreferences; | |
5 | + | |
6 | +import androidx.preference.PreferenceManager; | |
6 | 7 | |
7 | -import net.osdn.gokigen.pkremote.R; | |
8 | 8 | import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback; |
9 | 9 | import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraFileInfo; |
10 | 10 | import net.osdn.gokigen.pkremote.camera.interfaces.playback.IContentInfoCallback; |
@@ -13,9 +13,9 @@ import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentList | ||
13 | 13 | import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback; |
14 | 14 | import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl; |
15 | 15 | import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.PtpIpInterfaceProvider; |
16 | -import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback; | |
17 | 16 | import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandPublisher; |
18 | 17 | import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.PtpIpCommandGeneric; |
18 | +import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor; | |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * |
@@ -26,10 +26,7 @@ public class PtpIpPlaybackControl implements IPlaybackControl | ||
26 | 26 | private final String TAG = toString(); |
27 | 27 | private final Activity activity; |
28 | 28 | private final PtpIpInterfaceProvider provider; |
29 | - //private List<ICameraContent> imageInfo; | |
30 | - //private SparseArray<PtpIpImageContentInfo> imageContentInfo; | |
31 | - //private int indexNumber = 0; | |
32 | - //private ICameraContentListCallback finishedCallback = null; | |
29 | + private String raw_suffix = "CR2"; | |
33 | 30 | private CanonImageObjectReceiver canonImageObjectReceiver; |
34 | 31 | |
35 | 32 | public PtpIpPlaybackControl(Activity activity, PtpIpInterfaceProvider provider) |
@@ -37,13 +34,22 @@ public class PtpIpPlaybackControl implements IPlaybackControl | ||
37 | 34 | this.activity = activity; |
38 | 35 | this.provider = provider; |
39 | 36 | canonImageObjectReceiver = new CanonImageObjectReceiver(provider); |
40 | - //this.imageContentInfo = new SparseArray<>(); | |
37 | + | |
38 | + try | |
39 | + { | |
40 | + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); | |
41 | + raw_suffix = preferences.getString(IPreferencePropertyAccessor.CANON_RAW_SUFFIX, IPreferencePropertyAccessor.CANON_RAW_SUFFIX_DEFAULT_VALUE); | |
42 | + } | |
43 | + catch (Exception e) | |
44 | + { | |
45 | + e.printStackTrace(); | |
46 | + } | |
41 | 47 | } |
42 | 48 | |
43 | 49 | @Override |
44 | 50 | public String getRawFileSuffix() |
45 | 51 | { |
46 | - return (null); | |
52 | + return (raw_suffix); | |
47 | 53 | } |
48 | 54 | |
49 | 55 | @Override |
@@ -95,19 +101,6 @@ public class PtpIpPlaybackControl implements IPlaybackControl | ||
95 | 101 | // Log.v(TAG, "downloadContentThumbnail() " + indexStr + " [" + objectId + "] (" + storageId + ")"); |
96 | 102 | publisher.enqueueCommand(new PtpIpCommandGeneric(new PtpIpThumbnailImageReceiver(activity, callback), false, objectId, 0x910a, 8, objectId, 0x00032000)); |
97 | 103 | } |
98 | -/* | |
99 | - int index = Integer.parseInt(indexStr); | |
100 | - if ((index > 0)&&(index <= imageContentInfo.size())) | |
101 | - { | |
102 | - IPtpIpCommandPublisher publisher = provider.getCommandPublisher(); | |
103 | - PtpIpImageContentInfo contentInfo = imageContentInfo.get(index); | |
104 | - if (!contentInfo.isReceived()) | |
105 | - { | |
106 | - publisher.enqueueCommand(new GetImageInfo(index, index, contentInfo)); | |
107 | - } | |
108 | - publisher.enqueueCommand(new GetThumbNail(index, new PtpIpThumbnailImageReceiver(activity, callback))); | |
109 | - } | |
110 | - */ | |
111 | 104 | } |
112 | 105 | catch (Exception e) |
113 | 106 | { |
@@ -6,12 +6,9 @@ import android.util.Log; | ||
6 | 6 | |
7 | 7 | import androidx.annotation.NonNull; |
8 | 8 | |
9 | -import net.osdn.gokigen.pkremote.R; | |
10 | 9 | import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback; |
11 | -import net.osdn.gokigen.pkremote.camera.utils.SimpleLogDumper; | |
12 | 10 | import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback; |
13 | 11 | |
14 | -import java.io.ByteArrayInputStream; | |
15 | 12 | import java.util.Arrays; |
16 | 13 | |
17 | 14 | public class PtpIpThumbnailImageReceiver implements IPtpIpCommandCallback |
@@ -31,11 +28,11 @@ public class PtpIpThumbnailImageReceiver implements IPtpIpCommandCallback | ||
31 | 28 | { |
32 | 29 | try |
33 | 30 | { |
34 | - /////// 受信データから、先頭(0xff 0xd8)を検索 ///// | |
35 | 31 | //Log.v(TAG, " RECV THUMBNAIL START : " + id + " [" + rx_body.length + "] "); |
36 | 32 | //SimpleLogDumper.dump_bytes("[THUMB]", rx_body); |
37 | 33 | //Log.v(TAG, " RECV THUMBNAIL END : " + id + " [" + rx_body.length + "] "); |
38 | 34 | |
35 | + /////// 受信データから、サムネイルの先頭(0xff 0xd8)を検索する ///// | |
39 | 36 | int offset = rx_body.length - 22; |
40 | 37 | //byte[] thumbnail0 = Arrays.copyOfRange(rx_body, 0, rx_body.length); |
41 | 38 | while (offset > 32) |
@@ -46,21 +43,8 @@ public class PtpIpThumbnailImageReceiver implements IPtpIpCommandCallback | ||
46 | 43 | } |
47 | 44 | offset--; |
48 | 45 | } |
49 | - if (rx_body.length > offset) | |
50 | - { | |
51 | - byte[] thumbnail = Arrays.copyOfRange(rx_body, offset, rx_body.length - 22); | |
52 | - callback.onCompleted(BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length), null); | |
53 | - | |
54 | - //callback.onCompleted(BitmapFactory.decodeByteArray(rx_body, 0, rx_body.length), null); | |
55 | - //callback.onCompleted(BitmapFactory.decodeByteArray(rx_body, offset, rx_body.length - offset - 22), null); | |
56 | - //callback.onCompleted(BitmapFactory.decodeStream(new ByteArrayInputStream(rx_body, offset, rx_body.length)), null); | |
57 | - //callback.onCompleted(BitmapFactory.decodeStream(new ByteArrayInputStream(rx_body, 0, rx_body.length)), null); | |
58 | - } | |
59 | - else | |
60 | - { | |
61 | - Log.v(TAG, "BITMAP IS NONE... : " + rx_body.length); | |
62 | - callback.onCompleted(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_broken_image_black_24dp), null); | |
63 | - } | |
46 | + byte[] thumbnail = Arrays.copyOfRange(rx_body, offset, rx_body.length - 22); | |
47 | + callback.onCompleted(BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length), null); | |
64 | 48 | } |
65 | 49 | catch (Exception e) |
66 | 50 | { |
@@ -87,6 +87,9 @@ public interface IPreferencePropertyAccessor | ||
87 | 87 | |
88 | 88 | String USE_SMARTPHONE_TRANSFER_MODE = "use_smartphone_transfer_mode"; |
89 | 89 | |
90 | + String CANON_RAW_SUFFIX = "canon_raw_suffix"; | |
91 | + String CANON_RAW_SUFFIX_DEFAULT_VALUE = "CR2"; | |
92 | + | |
90 | 93 | /* |
91 | 94 | //String GR2_DISPLAY_MODE = "gr2_display_mode"; |
92 | 95 | //String GR2_DISPLAY_MODE_DEFAULT_VALUE = "0"; |
@@ -1,26 +1,26 @@ | ||
1 | 1 | package net.osdn.gokigen.pkremote.preference.canon; |
2 | 2 | |
3 | -import android.content.Context; | |
4 | -import android.content.SharedPreferences; | |
5 | -import android.os.Bundle; | |
6 | -import android.util.Log; | |
7 | - | |
8 | -import java.util.Map; | |
9 | - | |
10 | -import androidx.annotation.NonNull; | |
11 | -import androidx.appcompat.app.AppCompatActivity; | |
12 | -import androidx.fragment.app.FragmentActivity; | |
13 | -import androidx.preference.CheckBoxPreference; | |
14 | -import androidx.preference.ListPreference; | |
15 | -import androidx.preference.Preference; | |
16 | -import androidx.preference.PreferenceFragmentCompat; | |
17 | -import androidx.preference.PreferenceManager; | |
18 | - | |
19 | -import net.osdn.gokigen.pkremote.R; | |
20 | -import net.osdn.gokigen.pkremote.camera.vendor.ptpip.operation.PtpIpCameraPowerOff; | |
21 | -import net.osdn.gokigen.pkremote.logcat.LogCatViewer; | |
22 | -import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor; | |
23 | -import net.osdn.gokigen.pkremote.scene.IChangeScene; | |
3 | + import android.content.Context; | |
4 | + import android.content.SharedPreferences; | |
5 | + import android.os.Bundle; | |
6 | + import android.util.Log; | |
7 | + | |
8 | + import java.util.Map; | |
9 | + | |
10 | + import androidx.annotation.NonNull; | |
11 | + import androidx.appcompat.app.AppCompatActivity; | |
12 | + import androidx.fragment.app.FragmentActivity; | |
13 | + import androidx.preference.CheckBoxPreference; | |
14 | + import androidx.preference.ListPreference; | |
15 | + import androidx.preference.Preference; | |
16 | + import androidx.preference.PreferenceFragmentCompat; | |
17 | + import androidx.preference.PreferenceManager; | |
18 | + | |
19 | + import net.osdn.gokigen.pkremote.R; | |
20 | + import net.osdn.gokigen.pkremote.camera.vendor.ptpip.operation.PtpIpCameraPowerOff; | |
21 | + import net.osdn.gokigen.pkremote.logcat.LogCatViewer; | |
22 | + import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor; | |
23 | + import net.osdn.gokigen.pkremote.scene.IChangeScene; | |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * |
@@ -117,6 +117,9 @@ public class CanonPreferenceFragment extends PreferenceFragmentCompat implement | ||
117 | 117 | if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD)) { |
118 | 118 | editor.putString(IPreferencePropertyAccessor.CONNECTION_METHOD, IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE); |
119 | 119 | } |
120 | + if (!items.containsKey(IPreferencePropertyAccessor.CANON_RAW_SUFFIX)) { | |
121 | + editor.putString(IPreferencePropertyAccessor.CANON_RAW_SUFFIX, IPreferencePropertyAccessor.CANON_RAW_SUFFIX_DEFAULT_VALUE); | |
122 | + } | |
120 | 123 | editor.apply(); |
121 | 124 | } |
122 | 125 | catch (Exception e) |
@@ -167,7 +170,7 @@ public class CanonPreferenceFragment extends PreferenceFragmentCompat implement | ||
167 | 170 | try |
168 | 171 | { |
169 | 172 | //super.onCreate(savedInstanceState); |
170 | - addPreferencesFromResource(R.xml.preferences_fuji_x); | |
173 | + addPreferencesFromResource(R.xml.preferences_canon); | |
171 | 174 | |
172 | 175 | ListPreference connectionMethod = (ListPreference) findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD); |
173 | 176 | connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { |
@@ -181,7 +184,7 @@ public class CanonPreferenceFragment extends PreferenceFragmentCompat implement | ||
181 | 184 | |
182 | 185 | findPreference("exit_application").setOnPreferenceClickListener(powerOffController); |
183 | 186 | findPreference("debug_info").setOnPreferenceClickListener(logCatViewer); |
184 | - } | |
187 | + } | |
185 | 188 | catch (Exception e) |
186 | 189 | { |
187 | 190 | e.printStackTrace(); |
@@ -293,6 +293,9 @@ | ||
293 | 293 | <string name="pref_sony_use_smartphone_transfer">スマートフォン転送モードを使う</string> |
294 | 294 | <string name="pref_summary_sony_use_smartphone_transfer">うまく通信できない場合にチェックを入れてください。</string> |
295 | 295 | |
296 | + <string name="pref_canon_raw_suffix">RAW拡張子</string> | |
297 | + <string name="pref_summary_canon_raw_suffix">カメラのRAW拡張子を設定してください。</string> | |
298 | + | |
296 | 299 | <string name="connect_start_2">準備中…</string> |
297 | 300 | <string name="canon_connect_connecting1">接続中…(1/5)</string> |
298 | 301 | <string name="canon_connect_connecting2">接続中…(2/5)</string> |
@@ -295,6 +295,9 @@ | ||
295 | 295 | <string name="pref_sony_use_smartphone_transfer">Do use SmartPhone transfer mode.</string> |
296 | 296 | <string name="pref_summary_sony_use_smartphone_transfer">If you cannot communicate, please check this.</string> |
297 | 297 | |
298 | + <string name="pref_canon_raw_suffix">RAW Suffix</string> | |
299 | + <string name="pref_summary_canon_raw_suffix">Please set your camera RAW suffix.</string> | |
300 | + | |
298 | 301 | <string name="connect_start_2">Preparing…</string> |
299 | 302 | <string name="canon_connect_connecting1">Connecting…(1/5)</string> |
300 | 303 | <string name="canon_connect_connecting2">Connecting…(2/5)</string> |
@@ -20,6 +20,14 @@ | ||
20 | 20 | <PreferenceCategory |
21 | 21 | android:title="@string/pref_cat_camera"> |
22 | 22 | |
23 | + | |
24 | + <EditTextPreference | |
25 | + android:key="canon_raw_suffix" | |
26 | + android:title="@string/pref_canon_raw_suffix" | |
27 | + android:defaultValue="CR2" | |
28 | + android:inputType="number" | |
29 | + android:summary="@string/pref_summary_canon_raw_suffix" /> | |
30 | + | |
23 | 31 | <!-- |
24 | 32 | |
25 | 33 | <PreferenceScreen |