1 package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback;
3 import android.app.Activity;
4 import android.util.Log;
5 import android.util.SparseArray;
7 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
8 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback;
9 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraFileInfo;
10 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IContentInfoCallback;
11 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
12 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentListCallback;
13 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
14 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
15 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.PtpIpInterfaceProvider;
16 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
19 import java.util.ArrayList;
20 import java.util.List;
22 public class PtpIpPlaybackControl implements IPlaybackControl, IPtpIpCommandCallback
24 private final String TAG = toString();
25 private final Activity activity;
26 private final PtpIpInterfaceProvider provider;
27 //private List<ICameraContent> imageInfo;
28 private SparseArray<PtpIpImageContentInfo> imageContentInfo;
29 private int indexNumber = 0;
30 private ICameraContentListCallback finishedCallback = null;
31 private CanonImageObjectReceiver canonImageObjectReceiver;
33 public PtpIpPlaybackControl(Activity activity, PtpIpInterfaceProvider provider)
35 this.activity = activity;
36 this.provider = provider;
37 canonImageObjectReceiver = new CanonImageObjectReceiver(activity, provider);
38 this.imageContentInfo = new SparseArray<>();
42 public String getRawFileSuffix() {
47 public void downloadContentList(IDownloadContentListCallback callback)
53 public void getContentInfo(String path, String name, IContentInfoCallback callback)
55 // showFileInformation
60 public void updateCameraFileInfo(ICameraFileInfo info)
66 public void downloadContentScreennail(String path, IDownloadThumbnailImageCallback callback)
68 // Thumbnail と同じ画像を表示する
69 downloadContentThumbnail(path, callback);
73 public void downloadContentThumbnail(String path, IDownloadThumbnailImageCallback callback)
79 if (path.indexOf("/") == 0)
83 String indexStr = path.substring(start, path.indexOf("."));
84 Log.v(TAG, "downloadContentThumbnail() : " + path + " " + indexStr);
85 int index = Integer.parseInt(indexStr);
86 if ((index > 0)&&(index <= imageContentInfo.size()))
88 IPtpIpCommandPublisher publisher = provider.getCommandPublisher();
89 PtpIpImageContentInfo contentInfo = imageContentInfo.get(index);
90 if (!contentInfo.isReceived())
92 publisher.enqueueCommand(new GetImageInfo(index, index, contentInfo));
94 publisher.enqueueCommand(new GetThumbNail(index, new PtpIpThumbnailImageReceiver(activity, callback)));
105 public void downloadContent(String path, boolean isSmallSize, IDownloadContentCallback callback)
111 if (path.indexOf("/") == 0)
115 String indexStr = path.substring(start, path.indexOf("."));
116 Log.v(TAG, "FujiX::downloadContent() : " + path + " " + indexStr);
117 int index = Integer.parseInt(indexStr);
118 //PtpIpImageContentInfo contentInfo = imageContentInfo.get(index); // 特にデータを更新しないから大丈夫か?
119 if ((index > 0)&&(index <= imageContentInfo.size()))
121 IPtpIpCommandPublisher publisher = provider.getCommandPublisher();
122 publisher.enqueueCommand(new GetFullImage(index, new PtpIpFullImageReceiver(callback)));
133 public void getCameraContentList(final ICameraContentListCallback callback)
135 if (callback == null)
142 Thread thread = new Thread(new Runnable() {
145 canonImageObjectReceiver.getCameraContents(imageContentInfo, callback);
153 callback.onErrorOccurred(e);
159 public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
161 Log.v(TAG, " " + currentBytes + "/" + totalBytes);
165 public boolean isReceiveMulti()
171 public void receivedMessage(int id, byte[] rx_body)
173 // イメージ数の一覧が取得できなかった場合にここで作る。
174 if (rx_body.length < 16)
176 // インデックスデータがなくなったことを検出...データがそろったとして応答する。
177 Log.v(TAG, "IMAGE LIST : " + imageContentInfo.size());
178 finishedCallback.onCompleted(getCameraContentList());
179 finishedCallback = null;
185 Log.v(TAG, "RECEIVED IMAGE INFO : " + indexNumber);
188 imageContentInfo.append(indexNumber, new PtpIpImageContentInfo(indexNumber, rx_body));
192 IPtpIpCommandPublisher publisher = provider.getCommandPublisher();
193 publisher.enqueueCommand(new GetImageInfo(indexNumber, indexNumber, this));
200 finishedCallback.onCompleted(getCameraContentList());
201 finishedCallback = null;
205 private List<ICameraContent> getCameraContentList()
207 /// ダサいけど...コンテナクラスを詰め替えて応答する
208 List<ICameraContent> contentList = new ArrayList<>();
209 int listSize = imageContentInfo.size();
210 for(int index = 0; index < listSize; index++)
212 contentList.add(imageContentInfo.valueAt(index));
214 return (contentList);