1 package net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper;
3 import android.app.Activity;
4 import android.util.Log;
6 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
7 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback;
8 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraFileInfo;
9 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IContentInfoCallback;
10 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
11 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentListCallback;
12 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
13 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
14 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatus;
15 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommandCallback;
16 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommandPublisher;
17 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.messages.GetFullImage;
18 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.messages.GetImageInfo;
19 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.messages.GetThumbNail;
21 import java.util.ArrayList;
22 import java.util.List;
24 import static net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.status.IFujiXCameraProperties.IMAGE_FILE_COUNT_STR_ID;
26 public class FujiXPlaybackControl implements IPlaybackControl, IFujiXCommandCallback
28 private final String TAG = toString();
29 private final Activity activity;
30 private final FujiXInterfaceProvider provider;
31 private List<ICameraContent> imageInfo;
32 private int indexNumber = 0;
33 private ICameraContentListCallback finishedCallback = null;
35 FujiXPlaybackControl(Activity activity, FujiXInterfaceProvider provider)
37 this.activity = activity;
38 this.provider = provider;
39 this.imageInfo = new ArrayList<>();
44 public String getRawFileSuffix() {
49 public void downloadContentList(IDownloadContentListCallback callback)
55 public void getContentInfo(String path, String name, IContentInfoCallback callback)
57 // showFileInformation
62 public void updateCameraFileInfo(ICameraFileInfo info)
68 public void downloadContentScreennail(String path, IDownloadThumbnailImageCallback callback)
70 // Thumbnail と同じ画像を表示する
71 downloadContentThumbnail(path, callback);
75 public void downloadContentThumbnail(String path, IDownloadThumbnailImageCallback callback)
80 if (path.indexOf("/") == 0)
84 String indexStr = path.substring(start, path.indexOf("."));
85 Log.v(TAG, "downloadContentThumbnail() : " + path + " " + indexStr);
86 int index = Integer.parseInt(indexStr);
87 if ((index > 0)&&(index <= imageInfo.size()))
89 IFujiXCommandPublisher publisher = provider.getCommandPublisher();
90 ICameraContent contentInfo = imageInfo.get(index - 1);
91 publisher.enqueueCommand(new GetImageInfo(indexNumber, indexNumber, (FujiXImageContentInfo) contentInfo));
92 publisher.enqueueCommand(new GetThumbNail(index, new FujiXThumbnailImageReceiver(activity, callback)));
102 public void downloadContent(String path, boolean isSmallSize, IDownloadContentCallback callback)
107 if (path.indexOf("/") == 0)
111 String indexStr = path.substring(start, path.indexOf("."));
112 Log.v(TAG, "FujiX::downloadContent() : " + path + " " + indexStr);
113 int index = Integer.parseInt(indexStr);
114 if ((index > 0)&&(index <= imageInfo.size()))
116 IFujiXCommandPublisher publisher = provider.getCommandPublisher();
117 publisher.enqueueCommand(new GetFullImage(index, new FujiXFullImageReceiver(callback)));
127 public void getCameraContentList(final ICameraContentListCallback callback)
129 if (callback == null) {
133 Thread thread = new Thread(new Runnable() {
136 getCameraContents(callback);
140 } catch (Exception e) {
142 callback.onErrorOccurred(e);
146 private void getCameraContents(ICameraContentListCallback callback)
150 finishedCallback = callback;
151 ICameraStatus statusListHolder = provider.getCameraStatusListHolder();
152 if (statusListHolder != null) {
153 String count = statusListHolder.getStatus(IMAGE_FILE_COUNT_STR_ID);
154 nofFiles = Integer.parseInt(count);
155 Log.v(TAG, "getCameraContents() : " + nofFiles + " (" + count + ")");
157 Log.v(TAG, "getCameraContents() : DONE.");
160 // 件数ベースで取得する(情報は、後追いで反映させる...この方式だと、キューに積みまくってるが、、、)
161 checkImageFiles(nofFiles);
171 finishedCallback.onErrorOccurred(e);
172 finishedCallback = null;
177 * 最初から取得可能なイメージ情報を(件数ベースで)取得する
180 private void checkImageFiles(int nofFiles)
185 //IFujiXCommandPublisher publisher = provider.getCommandPublisher();
186 for (int index = 1; index <= nofFiles; index++)
188 FujiXImageContentInfo info = new FujiXImageContentInfo(index, null);
190 //publisher.enqueueCommand(new GetImageInfo(index, index, info));
194 // インデックスデータがなくなったことを検出...データがそろったとして応答する。
195 Log.v(TAG, "IMAGE LIST : " + imageInfo.size() + " (" + nofFiles + ")");
196 finishedCallback.onCompleted(imageInfo);
197 finishedCallback = null;
206 * 最初から取得可能なイメージ情報をすべて取得する
209 private void checkImageFileAll()
215 IFujiXCommandPublisher publisher = provider.getCommandPublisher();
216 publisher.enqueueCommand(new GetImageInfo(indexNumber, indexNumber, this));
225 public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
227 Log.v(TAG, " " + currentBytes + "/" + totalBytes);
231 public boolean isReceiveMulti()
237 public void receivedMessage(int id, byte[] rx_body)
239 // イメージ数の一覧が取得できなかった場合にここで作る。
240 if (rx_body.length < 16)
242 // インデックスデータがなくなったことを検出...データがそろったとして応答する。
243 Log.v(TAG, "IMAGE LIST : " + imageInfo.size());
244 finishedCallback.onCompleted(imageInfo);
245 finishedCallback = null;
250 Log.v(TAG, "RECEIVED IMAGE INFO : " + indexNumber);
253 imageInfo.add(new FujiXImageContentInfo(indexNumber, rx_body));
257 IFujiXCommandPublisher publisher = provider.getCommandPublisher();
258 publisher.enqueueCommand(new GetImageInfo(indexNumber, indexNumber, this));
264 finishedCallback.onCompleted(imageInfo);
265 finishedCallback = null;