1 package jp.sfjp.gokigen.a01c.olycamerawrapper;
3 import android.app.Activity;
4 import android.graphics.PointF;
5 import android.util.Log;
6 import android.view.MotionEvent;
8 import jp.co.olympus.camerakit.OLYCamera;
9 import jp.co.olympus.camerakit.OLYCameraLiveViewListener;
10 import jp.co.olympus.camerakit.OLYCameraStatusListener;
12 import jp.sfjp.gokigen.a01c.IShowInformation;
13 import jp.sfjp.gokigen.a01c.liveview.IAutoFocusFrameDisplay;
14 import jp.sfjp.gokigen.a01c.liveview.ICameraStatusReceiver;
15 import jp.sfjp.gokigen.a01c.preference.ICameraPropertyAccessor;
18 * OlyCameraCoordinator : Olympus Air との接続、切断の間をとりもつクラス。
19 * (OLYCameraクラスの実体を保持する)
22 * 2. connectWifi() でカメラと接続する
23 * 3. disconnect() でカメラと切断する
25 * X. onDisconnectedByError() でカメラの通信状態が変更されたことを受信する
26 * o. CameraInteractionCoordinator.ICameraCallback でカメラとの接続状態を通知する
29 public class OlyCameraCoordinator implements IOlyCameraCoordinator, IIndicatorControl, ICameraRunMode, IOLYCameraObjectProvider
31 private final String TAG = toString();
32 private final IAutoFocusFrameDisplay focusFrameDisplay;
33 private final OLYCamera camera;
36 private final AutoFocusControl autoFocus;
37 private final SingleShotControl singleShot;
38 private final OlyCameraPropertyProxy propertyProxy;
39 private final LoadSaveCameraProperties loadSaveCameraProperties;
40 private final OlyCameraConnection cameraConnection;
41 private final ICameraStatusDisplay cameraStatusDisplay;
42 private final LevelMeterHolder levelMeter;
44 private boolean isManualFocus = false;
45 private boolean isAutoFocusLocked = false;
46 private boolean isExposureLocked = false;
51 public OlyCameraCoordinator(Activity context, IAutoFocusFrameDisplay focusFrameDisplay, IShowInformation showInformation, ICameraStatusReceiver receiver)
53 this.focusFrameDisplay = focusFrameDisplay;
55 // OLYMPUS CAMERA クラスの初期化、リスナの設定
56 camera = new OLYCamera();
57 camera.setContext(context.getApplicationContext());
59 this.cameraConnection = new OlyCameraConnection(context, camera, receiver);
60 camera.setConnectionListener(cameraConnection);
62 // 本クラスの配下のカメラ制御クラス群の設定
63 autoFocus = new AutoFocusControl(camera, focusFrameDisplay, this); // AF制御
64 singleShot = new SingleShotControl(camera, focusFrameDisplay, this); // 撮影
65 propertyProxy = new OlyCameraPropertyProxy(camera); // カメラプロパティ
66 cameraStatusDisplay = new CameraStatusDisplay(propertyProxy, showInformation); // 画面表示
67 this.levelMeter = new LevelMeterHolder(showInformation, android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(ICameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, false)); // デジタル水準器
68 setCameraStatusListener(new CameraStatusListenerImpl(context, cameraStatusDisplay, levelMeter));
69 camera.setCameraPropertyListener(new CameraPropertyListenerImpl(cameraStatusDisplay));
70 loadSaveCameraProperties = new LoadSaveCameraProperties(context, propertyProxy, this);
76 public void setLiveViewListener(OLYCameraLiveViewListener listener)
78 Log.v(TAG, "setLiveViewListener()");
81 camera.setLiveViewListener(listener);
94 public void changeLiveViewSize(String size)
96 Log.v(TAG, "changeLiveViewSize() : " + size);
99 camera.changeLiveViewSize(CameraPropertyUtilities.toLiveViewSizeType(size));
112 public void startLiveView()
114 Log.v(TAG, "startLiveView()");
117 camera.startLiveView();
130 public void stopLiveView()
132 Log.v(TAG, "stopLiveView()");
135 camera.stopLiveView();
148 public void updateTakeMode()
150 cameraStatusDisplay.updateTakeMode();
156 public boolean driveAutoFocus(MotionEvent event)
158 if (event.getAction() != MotionEvent.ACTION_DOWN)
162 PointF point = focusFrameDisplay.getPointWithEvent(event);
163 return ((focusFrameDisplay.isContainsPoint(point)) && autoFocus.lockAutoFocus(point));
169 public void unlockAutoFocus()
171 autoFocus.unlockAutoFocus();
172 focusFrameDisplay.hideFocusFrame();
173 isAutoFocusLocked = false;
180 public void singleShot() {
181 singleShot.singleShot();
189 public void setRecViewMode(boolean isRecViewMode)
193 String value = "<" + IOlyCameraProperty.REC_PREVIEW + "/";
196 value = value + "ON>";
200 value = value + "OFF>";
202 propertyProxy.setCameraPropertyValue(IOlyCameraProperty.REC_PREVIEW, value);
212 public void toggleAutoExposure()
218 Log.v(TAG, "toggleAutoExposure() : unlockAutoExposure()");
219 camera.unlockAutoExposure();
223 Log.v(TAG, "toggleAutoExposure() : lockAutoExposure()");
224 camera.lockAutoExposure();
226 updateIndicatorScreen(false);
232 cameraStatusDisplay.updateAeLockState();
240 public void toggleManualFocus()
244 boolean isHideFocusFrame = false;
245 String property_name = IOlyCameraProperty.FOCUS_STILL;
246 String poverty_value = "<" + IOlyCameraProperty.FOCUS_STILL + "/";
251 // AF -> MF : オートフォーカスを解除して設定する
252 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_MF);
253 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_MF + ">";
254 camera.unlockAutoFocus();
255 camera.setCameraPropertyValue(property_name, poverty_value);
256 isHideFocusFrame = true;
261 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_SAF);
262 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_SAF + ">";
263 camera.setCameraPropertyValue(property_name, poverty_value);
265 updateIndicatorScreen(isHideFocusFrame);
273 private void updateIndicatorScreen(boolean isHideFocusFrame)
276 if (isHideFocusFrame)
278 isAutoFocusLocked = false;
279 focusFrameDisplay.hideFocusFrame();
281 cameraStatusDisplay.updateCameraStatus();
285 public boolean isManualFocus()
287 isManualFocus = propertyProxy.isManualFocus();
288 return (isManualFocus);
292 public boolean isAFLock()
294 return (isAutoFocusLocked);
298 public boolean isAELock()
300 isExposureLocked = propertyProxy.isExposureLocked();
301 return (isExposureLocked);
305 public void setCameraStatusListener(OLYCameraStatusListener listener)
307 camera.setCameraStatusListener(listener);
311 public String getCameraStatusSummary(ICameraStatusSummary decoder)
313 return (decoder.getCameraStatusMessage(camera, ""));
321 public void updateStatusAll()
323 cameraStatusDisplay.updateCameraStatusAll();
327 public void changeRunMode(boolean isRecording)
329 OLYCamera.RunMode runMode = (isRecording) ? OLYCamera.RunMode.Recording : OLYCamera.RunMode.Playback;
330 Log.v(TAG, "changeRunMode() : " + runMode);
333 camera.changeRunMode(runMode);
342 public boolean isRecordingMode()
344 boolean isRecordingMode = false;
347 OLYCamera.RunMode runMode = camera.getRunMode();
348 isRecordingMode = (runMode == OLYCamera.RunMode.Recording);
355 return (isRecordingMode);
359 public IOlyCameraPropertyProvider getCameraPropertyProvider()
361 return (propertyProxy);
365 public ILoadSaveCameraProperties getLoadSaveCameraProperties()
367 return (loadSaveCameraProperties);
371 public ICameraRunMode getChangeRunModeExecutor()
377 public IOlyCameraConnection getConnectionInterface()
379 return (cameraConnection);
383 public ILevelGauge getLevelGauge()
389 public void onAfLockUpdate(boolean isAfLocked)
391 isAutoFocusLocked = isAfLocked;
392 updateIndicatorScreen(false);
396 public OLYCamera getOLYCamera()