1 package net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.playback;
3 import android.graphics.Bitmap;
4 import android.util.Log;
6 import androidx.annotation.NonNull;
8 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContent;
9 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback;
10 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraFileInfo;
11 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IContentInfoCallback;
12 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
13 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentListCallback;
14 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
15 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
16 import net.osdn.gokigen.pkremote.camera.playback.ProgressEvent;
17 import net.osdn.gokigen.pkremote.camera.utils.SimpleHttpClient;
18 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.IConnectionKeyProvider;
20 import java.util.HashMap;
21 import java.util.List;
23 public class PixproPlaybackControl implements IPlaybackControl
25 private final String TAG = toString();
26 private static final int DEFAULT_TIMEOUT = 3000;
28 private final String ipAddress;
29 private final IConnectionKeyProvider keyProvider;
30 private final int timeoutValue;
32 private PixproContentListParser contentListParser;
34 public PixproPlaybackControl(@NonNull String ipAddress, int timeoutMs, @NonNull IConnectionKeyProvider keyProvider)
36 this.ipAddress = ipAddress;
37 this.keyProvider = keyProvider;
38 this.timeoutValue = Math.max(timeoutMs, DEFAULT_TIMEOUT);
39 contentListParser = new PixproContentListParser();
44 public String getRawFileSuffix()
50 public void downloadContentList(IDownloadContentListCallback callback)
52 Log.v(TAG, " downloadContentList()");
56 public void getContentInfo(String path, String name, IContentInfoCallback callback)
58 Log.v(TAG, " getContentInfo() : " + path + " / " + name);
62 public void updateCameraFileInfo(ICameraFileInfo info)
64 Log.v(TAG, " updateCameraFileInfo() : " + info.getFilename());
68 public void downloadContentScreennail(String path, IDownloadThumbnailImageCallback callback)
70 downloadContentThumbnail(path, callback);
74 int index = path.indexOf(".");
75 String urlToGet = "http://" + ipAddress + path.substring(0, index) + ".scn?" + getConnectionString();
76 Log.v(TAG, "downloadContentThumbnail() : " + urlToGet);
78 Bitmap bmp = SimpleHttpClient.httpGetBitmap(urlToGet, null, timeoutValue);
79 HashMap<String, Object> map = new HashMap<>();
80 map.put("Orientation", 0);
81 callback.onCompleted(bmp, map);
86 callback.onErrorOccurred(new NullPointerException());
92 public void downloadContentThumbnail(String path, IDownloadThumbnailImageCallback callback)
96 int index = path.indexOf(".");
97 String urlToGet = "http://" + ipAddress + path.substring(0, index) + ".thm?" + getConnectionString();
98 Log.v(TAG, "downloadContentThumbnail() : " + urlToGet);
100 Bitmap bmp = SimpleHttpClient.httpGetBitmap(urlToGet, null, timeoutValue);
101 HashMap<String, Object> map = new HashMap<>();
102 map.put("Orientation", 0);
103 callback.onCompleted(bmp, map);
108 callback.onErrorOccurred(new NullPointerException());
113 public void downloadContent(String path, boolean isSmallSize, final IDownloadContentCallback callback)
117 String urlToGet = "http://" + ipAddress + path + "?" + getConnectionString();
120 int index = path.indexOf(".");
121 urlToGet = "http://" + ipAddress + path.substring(0, index) + ".scn?" + getConnectionString();
122 urlToGet = urlToGet.toLowerCase();
123 urlToGet = urlToGet.replace("dcim", "scn");
125 SimpleHttpClient.httpGetBytes(urlToGet, null, timeoutValue, new SimpleHttpClient.IReceivedMessageCallback() {
127 public void onCompleted() {
128 callback.onCompleted();
132 public void onErrorOccurred(Exception e) {
133 callback.onErrorOccurred(e);
137 public void onReceive(int readBytes, int length, int size, byte[] data) {
138 float percent = (length == 0) ? 0.0f : ((float) readBytes / (float) length);
139 //Log.v(TAG, " onReceive : " + readBytes + " " + length + " " + size);
140 ProgressEvent event = new ProgressEvent(percent, null);
141 callback.onProgress(data, size, event);
148 callback.onErrorOccurred(new NullPointerException());
153 public void getCameraContentList(ICameraContentListCallback callback)
157 String imageListurl = "http://" + ipAddress + "/?custom=1&" + getConnectionString();
158 String receivedMessage = SimpleHttpClient.httpGet(imageListurl, timeoutValue);
159 if (receivedMessage == null)
162 callback.onErrorOccurred(new NullPointerException());
165 // 応答を受信した場合...受信データを parseして応答する。
166 Log.v(TAG, " RECEIVED CONTENT REPLY : " + receivedMessage.length());
167 List<ICameraContent> cameraContentList = contentListParser.parseContentList(receivedMessage);
168 callback.onCompleted(cameraContentList);
176 callback.onErrorOccurred(new NullPointerException());
181 public void showPictureStarted()
187 public void showPictureFinished()
192 private String getConnectionString()
194 return (keyProvider.getUserString() + "&" + keyProvider.getPasswordString());
195 // Log.v(TAG, " connectionString : " + connectionString);
196 //return (connectionString);