1 package net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.playback;
3 import android.app.Activity;
4 import android.graphics.BitmapFactory;
5 import android.os.Environment;
6 import android.util.Log;
8 import net.osdn.gokigen.pkremote.R;
9 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
10 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
11 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandPublisher;
12 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
13 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.messages.specific.CanonRequestInnerDevelopEnd;
15 import java.io.ByteArrayInputStream;
17 import java.io.FileOutputStream;
18 import java.text.SimpleDateFormat;
19 import java.util.Calendar;
20 import java.util.Locale;
22 import static net.osdn.gokigen.pkremote.camera.utils.SimpleLogDumper.binaryOutputToFile;
25 public class PtpIpScreennailImageReceiver implements IPtpIpCommandCallback
27 private static final String TAG = PtpIpScreennailImageReceiver.class.getSimpleName();
28 private final Activity activity;
29 private final IDownloadThumbnailImageCallback callback;
30 private final IPtpIpCommandPublisher publisher;
31 private final int objectId;
33 PtpIpScreennailImageReceiver(Activity activity, int objectId, IPtpIpCommandPublisher publisher, IDownloadThumbnailImageCallback callback)
35 this.activity = activity;
36 this.callback = callback;
37 this.publisher = publisher;
38 this.objectId = objectId;
39 Log.v(TAG, "PtpIpScreennailImageReceiver CREATED : " + objectId);
44 public void receivedMessage(int id, byte[] rx_body)
50 Log.v(TAG, " receivedMessage() : " + id + " " + rx_body.length + " bytes.");
54 Log.v(TAG, " receivedMessage() : " + id + " NULL.");
58 requestGetPartialObject();
60 else if (id == objectId + 1)
62 getPartialObject(rx_body);
64 else if (id == objectId + 2)
66 requestInnerDevelopEnd();
68 else if (id == objectId + 3)
70 finishedGetScreeennail();
72 else if (id == objectId + 4)
74 Log.v(TAG, " RECEIVED : " + id);
78 Log.v(TAG, " RECEIVED UNKNOWN ID : " + id);
85 callback.onErrorOccurred(e);
91 public void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body)
93 int length = (rx_body == null) ? 0 : rx_body.length;
94 Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes + " (" + length + " bytes.)");
98 public boolean isReceiveMulti()
103 private void requestGetPartialObject()
105 Log.v(TAG, " requestGetPartialObject() : " + objectId);
106 //publisher.enqueueCommand(new PtpIpCommandGeneric(this, false, (objectId + 1), 0x9107, 12, 0x01, 0x00, 0x00200000));
109 private void getPartialObject(byte[] rx_body)
111 Log.v(TAG, " getPartialObject(), id : " + objectId + " size: " + rx_body.length);
112 callback.onCompleted(BitmapFactory.decodeStream(new ByteArrayInputStream(rx_body)), null);
113 //publisher.enqueueCommand(new PtpIpCommandGeneric(this, false, (objectId + 2), 0x9117, 4,0x01));
115 // ファイルにバイナリデータをダンプする
116 //binaryOutputToFile(activity, objectId + "_", rx_body);
119 private void requestInnerDevelopEnd()
121 Log.v(TAG, " requestInnerDevelopEnd() : " + objectId);
122 //publisher.enqueueCommand(new CanonRequestInnerDevelopEnd(this, true, (objectId + 3)));
125 private void finishedGetScreeennail()
127 Log.v(TAG, " --- SCREENNAIL RECV FINISHED. : " + objectId + " --- ");
130 publisher.enqueueCommand(new PtpIpCommandGeneric(this, false, (objectId + 4), 0x902f));