OSDN Git Service

FUJIのファイルダウンロード中、進捗ダイアログの進捗が適切に表現されていなかったのを修正。する。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / camera / fuji_x / wrapper / playback / FujiXFullImageReceiver.java
1 package net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.playback;
2
3 import android.util.Log;
4
5 import androidx.annotation.NonNull;
6
7 import net.osdn.gokigen.gr2control.camera.fuji_x.wrapper.command.IFujiXCommandCallback;
8 import net.osdn.gokigen.gr2control.camera.playback.IDownloadContentCallback;
9 import net.osdn.gokigen.gr2control.camera.playback.ProgressEvent;
10
11 public class FujiXFullImageReceiver implements IFujiXCommandCallback
12 {
13     private final String TAG = toString();
14     private final IDownloadContentCallback callback;
15     private int receivedLength;
16
17     FujiXFullImageReceiver( @NonNull IDownloadContentCallback callback)
18     {
19         this.callback = callback;
20         this.receivedLength = 0;
21     }
22
23     @Override
24     public void receivedMessage(int id, byte[] rx_body)
25     {
26         try
27         {
28             Log.v(TAG, " receivedMessage() : onCompleted. " + id + " (" + receivedLength + " bytes.)");
29             callback.onCompleted();
30         }
31         catch (Exception e)
32         {
33             e.printStackTrace();
34             {
35                 callback.onErrorOccurred(e);
36             }
37         }
38     }
39
40     @Override
41     public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] body)
42     {
43         try
44         {
45             receivedLength = receivedLength + currentBytes;
46             float percent = (totalBytes == 0) ? 0.0f : ((float) receivedLength / (float) totalBytes);
47             //Log.v(TAG, " onReceiveProgress() " + receivedLength + "/" + totalBytes + " " + percent);
48             ProgressEvent event = new ProgressEvent(percent, null);
49             callback.onProgress(body, currentBytes, event);
50         }
51         catch (Exception e)
52         {
53             e.printStackTrace();
54             callback.onErrorOccurred(e);
55         }
56     }
57
58     @Override
59     public boolean isReceiveMulti()
60     {
61         return (true);
62     }
63
64 }