1 package net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.playback;
3 import android.app.Activity;
4 import android.util.Log;
5 import android.util.SparseArray;
7 import androidx.annotation.NonNull;
8 import androidx.annotation.Nullable;
10 import net.osdn.gokigen.gr2control.camera.ICameraFileInfo;
11 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
12 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.FujiXInterfaceProvider;
13 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.IFujiXCommandCallback;
14 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.IFujiXCommandPublisher;
15 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.GetFullImage;
16 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.GetImageInfo;
17 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.messages.GetThumbNail;
18 import net.osdn.gokigen.gr2control.camera.playback.ICameraContent;
19 import net.osdn.gokigen.gr2control.camera.playback.IContentInfoCallback;
20 import net.osdn.gokigen.gr2control.camera.playback.IDownloadContentCallback;
21 import net.osdn.gokigen.gr2control.camera.playback.ICameraContentListCallback;
22 import net.osdn.gokigen.gr2control.camera.playback.IDownloadThumbnailImageCallback;
23 import net.osdn.gokigen.gr2control.camera.playback.IPlaybackControl;
25 import java.util.ArrayList;
26 import java.util.List;
28 import static net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.values.IFujiXCameraProperties.IMAGE_FILE_COUNT_STR_ID;
30 public class FujiXPlaybackControl implements IPlaybackControl, IFujiXCommandCallback
32 private final String TAG = toString();
33 private final Activity activity;
34 private final FujiXInterfaceProvider provider;
35 //private List<ICameraContent> imageInfo;
36 private SparseArray<FujiXImageContentInfo> imageContentInfo;
38 private int indexNumber = 0;
39 private ICameraContentListCallback finishedCallback = null;
41 public FujiXPlaybackControl(Activity activity, FujiXInterfaceProvider provider)
43 this.activity = activity;
44 this.provider = provider;
45 this.imageContentInfo = new SparseArray<>();
49 public String getRawFileSuffix() {
54 public void downloadContentList(@NonNull final ICameraContentListCallback callback)
58 Thread thread = new Thread(new Runnable() {
61 getCameraContents(callback);
69 callback.onErrorOccurred(e);
74 public void getContentInfo(@Nullable String path, @NonNull String name, @NonNull IContentInfoCallback callback)
76 // showFileInformation
81 public void updateCameraFileInfo(ICameraFileInfo info)
87 public void downloadContentScreennail(@Nullable String path, @NonNull String name, @NonNull IDownloadThumbnailImageCallback callback)
89 // Thumbnail と同じ画像を表示する
90 downloadContentThumbnail(path, name, callback);
94 public void downloadContentThumbnail(@Nullable String path, @NonNull String name, @NonNull IDownloadThumbnailImageCallback callback)
99 if (path.indexOf("/") == 0)
103 String indexStr = path.substring(start, path.indexOf("."));
104 Log.v(TAG, "downloadContentThumbnail() : " + path + " " + indexStr);
105 int index = Integer.parseInt(indexStr);
106 if ((index > 0)&&(index <= imageContentInfo.size()))
108 IFujiXCommandPublisher publisher = provider.getCommandPublisher();
109 FujiXImageContentInfo contentInfo = imageContentInfo.get(index);
110 if (!contentInfo.isReceived())
112 publisher.enqueueCommand(new GetImageInfo(index, index, contentInfo));
114 publisher.enqueueCommand(new GetThumbNail(index, new FujiXThumbnailImageReceiver(activity, callback)));
124 public void downloadContent(@Nullable String path, @NonNull String name, boolean isSmallSize, @NonNull IDownloadContentCallback callback)
129 if (path.indexOf("/") == 0)
133 String indexStr = path.substring(start, path.indexOf("."));
134 Log.v(TAG, "FujiX::downloadContent() : " + path + " " + indexStr);
135 int index = Integer.parseInt(indexStr);
136 //FujiXImageContentInfo contentInfo = imageContentInfo.get(index); // 特にデータを更新しないから大丈夫か?
137 if ((index > 0)&&(index <= imageContentInfo.size()))
139 IFujiXCommandPublisher publisher = provider.getCommandPublisher();
140 publisher.enqueueCommand(new GetFullImage(index, new FujiXFullImageReceiver(callback)));
150 public void showPictureStarted()
156 public void showPictureFinished()
161 private void getCameraContents(ICameraContentListCallback callback)
165 finishedCallback = callback;
166 ICameraStatus statusListHolder = provider.getCameraStatusListHolder();
167 if (statusListHolder != null) {
168 String count = statusListHolder.getStatus(IMAGE_FILE_COUNT_STR_ID);
169 nofFiles = Integer.parseInt(count);
170 Log.v(TAG, "getCameraContents() : " + nofFiles + " (" + count + ")");
172 Log.v(TAG, "getCameraContents() : DONE.");
175 // 件数ベースで取得する(情報は、後追いで反映させる...この方式だと、キューに積みまくってるが、、、)
176 checkImageFiles(nofFiles);
180 // 件数が不明だったら、1件づつインデックスの情報を取得する
187 finishedCallback.onErrorOccurred(e);
188 finishedCallback = null;
193 * 最初から取得可能なイメージ情報を(件数ベースで)取得する
196 private void checkImageFiles(int nofFiles)
200 imageContentInfo.clear();
201 //IFujiXCommandPublisher publisher = provider.getCommandPublisher();
202 //for (int index = nofFiles; index > 0; index--)
203 for (int index = 1; index <= nofFiles; index++)
206 imageContentInfo.append(index, new FujiXImageContentInfo(index, null));
208 //ファイル名などを取得する (メッセージを積んでおく...でも遅くなるので、ここではやらない方がよいかな。)
209 //publisher.enqueueCommand(new GetImageInfo(index, index, info));
212 // インデックスデータがなくなったことを検出...データがそろったとして応答する。
213 Log.v(TAG, "IMAGE LIST : " + imageContentInfo.size() + " (" + nofFiles + ")");
214 finishedCallback.onCompleted(getCameraFileInfoList());
215 finishedCallback = null;
224 * 最初から取得可能なイメージ情報をすべて取得する
227 private void checkImageFileAll()
231 imageContentInfo.clear();
233 IFujiXCommandPublisher publisher = provider.getCommandPublisher();
234 publisher.enqueueCommand(new GetImageInfo(indexNumber, indexNumber, this));
243 public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
245 Log.v(TAG, " " + currentBytes + "/" + totalBytes);
249 public boolean isReceiveMulti()
255 public void receivedMessage(int id, byte[] rx_body)
257 // イメージ数の一覧が取得できなかった場合にここで作る。
258 if (rx_body.length < 16)
260 // インデックスデータがなくなったことを検出...データがそろったとして応答する。
261 Log.v(TAG, "IMAGE LIST : " + imageContentInfo.size());
262 finishedCallback.onCompleted(getCameraFileInfoList());
263 finishedCallback = null;
268 Log.v(TAG, "RECEIVED IMAGE INFO : " + indexNumber);
271 imageContentInfo.append(indexNumber, new FujiXImageContentInfo(indexNumber, rx_body));
275 IFujiXCommandPublisher publisher = provider.getCommandPublisher();
276 publisher.enqueueCommand(new GetImageInfo(indexNumber, indexNumber, this));
282 finishedCallback.onCompleted(getCameraFileInfoList());
283 finishedCallback = null;
287 private List<ICameraContent> getCameraContentList()
289 /// ダサいけど...コンテナクラスを詰め替えて応答する
290 List<ICameraContent> contentList = new ArrayList<>();
291 int listSize = imageContentInfo.size();
292 for(int index = 0; index < listSize; index++)
294 contentList.add(imageContentInfo.valueAt(index));
296 return (contentList);
299 private List<ICameraFileInfo> getCameraFileInfoList()
301 List<ICameraFileInfo> fileInfoList = new ArrayList<>();
304 int listSize = imageContentInfo.size();
305 for(int index = 0; index < listSize; index++)
307 FujiXImageContentInfo info = imageContentInfo.valueAt(index);
308 fileInfoList.add(info.getCameraFileInfo());
315 return (fileInfoList);