1 package net.osdn.gokigen.pkremote.camera.vendor.olympuspen.wrapper.playback;
2 import android.app.Activity;
3 import android.content.SharedPreferences;
4 import android.graphics.Bitmap;
5 import android.util.Log;
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.IDownloadContentListCallback;
11 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
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.playback.ProgressEvent;
15 import net.osdn.gokigen.pkremote.camera.utils.SimpleHttpClient;
16 import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
18 import java.util.HashMap;
21 import androidx.annotation.NonNull;
22 import androidx.preference.PreferenceManager;
28 public class OlympusPenPlaybackControl implements IPlaybackControl
30 private final String TAG = toString();
31 private static final int DEFAULT_TIMEOUT = 3000;
32 private final Activity activity;
33 private final int timeoutValue;
34 private OlympusPenObjectDataHolder imageListHolder = new OlympusPenObjectDataHolder();
36 public OlympusPenPlaybackControl(@NonNull Activity activity, int timeoutMs)
38 Log.v(TAG, "OlympusPenPlaybackControl()");
39 this.activity = activity;
40 this.timeoutValue = (timeoutMs < DEFAULT_TIMEOUT) ? DEFAULT_TIMEOUT : timeoutMs;
44 public String getRawFileSuffix()
50 public void downloadContentList(@NonNull IDownloadContentListCallback callback)
52 Log.v(TAG, " downloadContentList()");
56 public void updateCameraFileInfo(ICameraFileInfo info)
58 Log.v(TAG, " updateCameraFileInfo() : " + info.getFilename());
62 public void getContentInfo(@NonNull String path, @NonNull String name, @NonNull IContentInfoCallback callback)
64 Log.v(TAG, " getContentInfo() : " + path + " / " + name);
70 public void downloadContentScreennail(@NonNull String path, @NonNull IDownloadThumbnailImageCallback callback)
72 Log.v(TAG, "downloadContentScreennail() : " + path);
75 String url = "http://192.168.0.10/get_screennail.cgi?DIR=" + path;
77 Map<String, String> headerMap = new HashMap<>();
78 headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
79 headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
81 Bitmap bmp = SimpleHttpClient.httpGetBitmap(url, headerMap, timeoutValue);
84 HashMap<String, Object> map = new HashMap<>();
85 map.put("Orientation", 0);
86 callback.onCompleted(bmp, map);
90 // screennail取得失敗時...リカバリする
93 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
94 boolean smallSize = preferences.getBoolean(IPreferencePropertyAccessor.OLYMPUS_USE_SCREENNAIL_AS_SMALL, false);
97 // 小さい画像をscreennailとして利用する
98 url = "http://192.168.0.10/get_resizeimg.cgi?DIR=" + path + "&size=1024";
99 bmp = SimpleHttpClient.httpGetBitmap(url, headerMap, timeoutValue);
102 HashMap<String, Object> map = new HashMap<>();
103 map.put("Orientation", 0);
104 callback.onCompleted(bmp, map);
107 // それでもダメな場合はサムネイル画像を使う...
116 // サムネイルでscreennail表示...
117 downloadContentThumbnail(path, callback);
122 callback.onErrorOccurred(new NullPointerException());
127 public void downloadContentThumbnail(@NonNull String path, @NonNull IDownloadThumbnailImageCallback callback)
129 Log.v(TAG, "downloadContentThumbnail() : " + path);
132 String url = "http://192.168.0.10/get_thumbnail.cgi?DIR=" + path;
134 Map<String, String> headerMap = new HashMap<>();
135 headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
136 headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
137 Bitmap bmp = SimpleHttpClient.httpGetBitmap(url, headerMap, timeoutValue);
138 HashMap<String, Object> map = new HashMap<>();
139 map.put("Orientation", 0);
140 callback.onCompleted(bmp, map);
145 callback.onErrorOccurred(new NullPointerException());
150 public void downloadContent(@NonNull String path, boolean isSmallSize, @NonNull final IDownloadContentCallback callback)
152 Log.v(TAG, "downloadContent() : " + path + " (small :" + isSmallSize + ")");
156 if ((isSmallSize)&&(path.contains(".JPG")))
158 String smallSize = "1600";
161 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
162 smallSize = preferences.getString(IPreferencePropertyAccessor.PEN_SMALL_PICTURE_SIZE, IPreferencePropertyAccessor.PEN_SMALL_PICTURE_SIZE_DEFAULT_VALUE);
169 url = "http://192.168.0.10/get_resizeimg.cgi?DIR=" + path + "&size=" + smallSize;
173 url = "http://192.168.0.10/" + path;
176 Map<String, String> headerMap = new HashMap<>();
177 headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
178 headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
180 SimpleHttpClient.httpGetBytes(url, headerMap, timeoutValue, new SimpleHttpClient.IReceivedMessageCallback() {
182 public void onCompleted() {
183 callback.onCompleted();
187 public void onErrorOccurred(Exception e) {
188 callback.onErrorOccurred(e);
192 public void onReceive(int readBytes, int length, int size, byte[] data) {
193 float percent = (length == 0) ? 0.0f : ((float) readBytes / (float) length);
194 //Log.v(TAG, " onReceive : " + readBytes + " " + length + " " + size);
195 ProgressEvent event = new ProgressEvent(percent, null);
196 callback.onProgress(data, size, event);
208 * - フォルダ一覧を取得してから、それぞれのフォルダ内に入っている画像一覧を取得する
211 public void getCameraContentList(ICameraContentListCallback callback)
213 String imageListTopLevelUrl = "http://192.168.0.10/get_imglist.cgi?DIR=/DCIM";
214 String contentInformation;
217 Map<String, String> headerMap = new HashMap<>();
218 headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
219 headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
222 contentInformation = SimpleHttpClient.httpGetWithHeader(imageListTopLevelUrl, headerMap, null, timeoutValue);
223 Log.v(TAG, " " + imageListTopLevelUrl + " " + contentInformation);
224 imageListHolder.clear();
225 for (OlympusPenCameraContent path : imageListHolder.parsePath(contentInformation))
228 String imageListPathUrl = "http://192.168.0.10/get_imglist.cgi?DIR=/DCIM/" + path.getContentName();
229 String imgList = SimpleHttpClient.httpGetWithHeader(imageListPathUrl, headerMap, null, timeoutValue);
230 if ((imgList != null)&&(imgList.length() > 0))
232 imageListHolder.parseImage(imgList);
235 callback.onCompleted(imageListHolder.getImageList());
240 callback.onErrorOccurred(e);
245 public void showPictureStarted()
251 public void showPictureFinished()