OSDN Git Service

やっぱり、OPCのSDKを入れてOlympus Airでも使えるようにする。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / camera / olympus / operation / takepicture / SequentialShotControl.java
1 package net.osdn.gokigen.gr2control.camera.olympus.operation.takepicture;
2
3 import android.graphics.RectF;
4 import android.util.Log;
5
6 import net.osdn.gokigen.gr2control.liveview.IAutoFocusFrameDisplay;
7 import net.osdn.gokigen.gr2control.liveview.IIndicatorControl;
8
9 import jp.co.olympus.camerakit.OLYCamera;
10 import jp.co.olympus.camerakit.OLYCameraAutoFocusResult;
11
12 /**
13  *   連続撮影用のクラス
14  *
15  */
16 public class SequentialShotControl implements OLYCamera.TakePictureCallback
17 {
18     private final String TAG = toString();
19     //private final Context context;
20     private final OLYCamera camera;
21     private final IIndicatorControl indicator;
22     private IAutoFocusFrameDisplay frameDisplayer;
23
24     private IIndicatorControl.shootingStatus currentStatus = IIndicatorControl.shootingStatus.Unknown;
25
26     /**
27      *   コンストラクタ
28      *
29      */
30     //public SequentialShotControl(Context context, OLYCamera camera, IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator)
31     public SequentialShotControl(OLYCamera camera, IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator)
32     {
33         //this.context = context;
34         this.camera = camera;
35         this.frameDisplayer = frameDisplayer;
36         this.indicator = indicator;
37     }
38
39     /**
40      *   撮影の開始と終了
41      *
42      */
43     public void shotControl()
44     {
45         if (camera.isRecordingVideo())
46         {
47             // ビデオ撮影中の場合は、何もしない(モード異常なので)
48             return;
49         }
50         try
51         {
52            if (!camera.isTakingPicture())
53             {
54                 // 連続撮影の開始
55                 currentStatus = IIndicatorControl.shootingStatus.Starting;
56                 camera.startTakingPicture(null, this);
57                 indicator.onShootingStatusUpdate(currentStatus);
58             }
59             else
60             {
61                 // 連続撮影の終了
62                 currentStatus = IIndicatorControl.shootingStatus.Stopping;
63                 camera.stopTakingPicture(this);
64                 indicator.onShootingStatusUpdate(currentStatus);
65             }
66         }
67         catch (Exception e)
68         {
69             e.printStackTrace();
70         }
71     }
72
73     /**
74      *
75      *
76      */
77     @Override
78     public void onProgress(OLYCamera olyCamera, OLYCamera.TakingProgress takingProgress, OLYCameraAutoFocusResult olyCameraAutoFocusResult)
79     {
80         if (currentStatus == IIndicatorControl.shootingStatus.Stopping)
81         {
82             // 終了中の時にはなにもしない
83             return;
84         }
85
86         // 撮影中の更新処理
87         if (takingProgress != OLYCamera.TakingProgress.EndFocusing)
88         {
89             return;
90         }
91
92         String result = olyCameraAutoFocusResult.getResult();
93         if (result == null)
94         {
95             Log.v(TAG, "FocusResult is null.");
96         }
97         else switch (result)
98         {
99             case "ok":
100                 RectF postFocusFrameRect = olyCameraAutoFocusResult.getRect();
101                 if (postFocusFrameRect != null)
102                 {
103                     showFocusFrame(postFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Focused, 0.0);
104                 }
105                 break;
106
107             case "none":
108             default:
109                 hideFocusFrame();
110                 break;
111         }
112     }
113
114     /**
115      *
116      *
117      */
118     @Override
119     public void onCompleted()
120     {
121         Log.v(TAG, "SequentialShotControl::onCompleted()");
122         indicator.onShootingStatusUpdate(currentStatus);
123         if (currentStatus != IIndicatorControl.shootingStatus.Stopping)
124         {
125             // 撮影停止中以外ではなにもしない。
126             return;
127         }
128
129         // 撮影停止処理...
130         try
131         {
132             camera.clearAutoFocusPoint();
133             hideFocusFrame();
134         }
135         catch (Exception e)
136         {
137             e.printStackTrace();
138         }
139         currentStatus = IIndicatorControl.shootingStatus.Unknown;
140         indicator.onShootingStatusUpdate(currentStatus);
141     }
142
143     /**
144      *
145      *
146      */
147     @Override
148     public void onErrorOccurred(Exception e)
149     {
150         try
151         {
152             camera.clearAutoFocusPoint();
153             hideFocusFrame();
154         }
155         catch (Exception ee)
156         {
157             ee.printStackTrace();
158         }
159         e.printStackTrace();
160         currentStatus = IIndicatorControl.shootingStatus.Unknown;
161     }
162
163     /**
164      *
165      *
166      */
167     private void showFocusFrame(RectF rect, IAutoFocusFrameDisplay.FocusFrameStatus status, double duration)
168     {
169         if (frameDisplayer != null)
170         {
171             frameDisplayer.showFocusFrame(rect, status, duration);
172         }
173         indicator.onAfLockUpdate(IAutoFocusFrameDisplay.FocusFrameStatus.Focused == status);
174     }
175
176     /**
177      *
178      *
179      */
180     private void hideFocusFrame()
181     {
182         if (frameDisplayer != null)
183         {
184             frameDisplayer.hideFocusFrame();
185         }
186         indicator.onAfLockUpdate(false);
187     }
188 }