1 package jp.sfjp.gokigen.a01c.olycamerawrapper;
3 import android.app.Activity;
4 import android.graphics.PointF;
5 import android.graphics.RectF;
6 import android.util.Log;
7 import android.view.MotionEvent;
8 import android.widget.Toast;
10 import jp.co.olympus.camerakit.OLYCamera;
11 import jp.co.olympus.camerakit.OLYCameraLiveViewListener;
12 import jp.co.olympus.camerakit.OLYCameraStatusListener;
14 import jp.sfjp.gokigen.a01c.IShowInformation;
15 import jp.sfjp.gokigen.a01c.R;
16 import jp.sfjp.gokigen.a01c.liveview.IAutoFocusFrameDisplay;
17 import jp.sfjp.gokigen.a01c.liveview.ICameraStatusReceiver;
18 import jp.sfjp.gokigen.a01c.olycamerawrapper.indicator.CameraStatusDisplay;
19 import jp.sfjp.gokigen.a01c.olycamerawrapper.indicator.ICameraStatusDisplay;
20 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraPropertyListenerImpl;
21 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraRecordingListenerImpl;
22 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraStatusListenerImpl;
23 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ICameraPropertyLoadSaveOperations;
24 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ILoadSaveCameraProperties;
25 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.IOlyCameraProperty;
26 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.IOlyCameraPropertyProvider;
27 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.LoadSaveCameraProperties;
28 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.OlyCameraPropertyProxy;
29 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.AutoFocusControl;
30 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.BracketingShotControl;
31 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.MovieRecordingControl;
32 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.SingleShotControl;
33 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.CameraPropertyLoadSaveOperations;
34 import jp.sfjp.gokigen.a01c.preference.IPreferenceCameraPropertyAccessor;
37 * OlyCameraCoordinator : Olympus Air との接続、切断の間をとりもつクラス。
38 * (OLYCameraクラスの実体を保持する)
41 * 2. connectWifi() でカメラと接続する
42 * 3. disconnect() でカメラと切断する
44 * X. onDisconnectedByError() でカメラの通信状態が変更されたことを受信する
45 * o. CameraInteractionCoordinator.ICameraCallback でカメラとの接続状態を通知する
48 public class OlyCameraCoordinator implements IOlyCameraCoordinator, IIndicatorControl, ICameraRunMode, IOLYCameraObjectProvider
50 private final String TAG = toString();
51 private final IAutoFocusFrameDisplay focusFrameDisplay;
52 private final OLYCamera camera;
53 private final Activity context;
56 private final AutoFocusControl autoFocus;
57 private final SingleShotControl singleShot;
58 private final MovieRecordingControl movieControl;
59 private final BracketingShotControl bracketingShot;
60 private final OlyCameraPropertyProxy propertyProxy;
61 private final CameraPropertyLoadSaveOperations loadSaveOperations;
62 private final LoadSaveCameraProperties loadSaveCameraProperties;
63 private final OlyCameraConnection cameraConnection;
64 private final ICameraStatusDisplay cameraStatusDisplay;
65 private final LevelMeterHolder levelMeter;
66 private final ZoomLensHolder zoomLensHolder;
68 private boolean isManualFocus = false;
69 private boolean isAutoFocusLocked = false;
70 //private boolean isExposureLocked = false;
76 public OlyCameraCoordinator(Activity context, IAutoFocusFrameDisplay focusFrameDisplay, IShowInformation showInformation, ICameraStatusReceiver receiver)
78 this.context = context;
79 this.focusFrameDisplay = focusFrameDisplay;
81 // OLYMPUS CAMERA クラスの初期化、リスナの設定
82 camera = new OLYCamera();
83 camera.setContext(context.getApplicationContext());
85 this.cameraConnection = new OlyCameraConnection(context, camera, receiver);
86 camera.setConnectionListener(cameraConnection);
88 // 本クラスの配下のカメラ制御クラス群の設定
89 autoFocus = new AutoFocusControl(camera, focusFrameDisplay, this); // AF制御
90 singleShot = new SingleShotControl(camera, focusFrameDisplay, this, showInformation); // 1枚撮影
91 movieControl = new MovieRecordingControl(context, camera, showInformation); // ムービー撮影
92 bracketingShot = new BracketingShotControl(camera, focusFrameDisplay, this, showInformation); // ブラケッティング&インターバル撮影
93 propertyProxy = new OlyCameraPropertyProxy(camera); // カメラプロパティ
94 cameraStatusDisplay = new CameraStatusDisplay(propertyProxy, showInformation); // 画面表示
95 this.levelMeter = new LevelMeterHolder(showInformation, android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(IPreferenceCameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, false)); // デジタル水準器
96 camera.setCameraStatusListener(new CameraStatusListenerImpl(context, cameraStatusDisplay, levelMeter));
97 camera.setCameraPropertyListener(new CameraPropertyListenerImpl(cameraStatusDisplay));
98 camera.setRecordingListener(new CameraRecordingListenerImpl(context, showInformation));
99 loadSaveCameraProperties = new LoadSaveCameraProperties(context, propertyProxy, this);
100 loadSaveOperations = new CameraPropertyLoadSaveOperations(context, loadSaveCameraProperties, cameraStatusDisplay);
101 zoomLensHolder = new ZoomLensHolder(camera);
107 public void setLiveViewListener(OLYCameraLiveViewListener listener)
109 Log.v(TAG, "setLiveViewListener()");
112 camera.setLiveViewListener(listener);
125 public void changeLiveViewSize(String size)
127 Log.v(TAG, "changeLiveViewSize() : " + size);
130 camera.changeLiveViewSize(CameraPropertyUtilities.toLiveViewSizeType(size));
143 public void startLiveView()
145 Log.v(TAG, "startLiveView()");
148 camera.startLiveView();
161 public void stopLiveView()
163 Log.v(TAG, "stopLiveView()");
166 camera.stopLiveView();
179 public void updateTakeMode()
181 cameraStatusDisplay.updateTakeMode();
187 public boolean driveAutoFocus(MotionEvent event)
189 if (event.getAction() != MotionEvent.ACTION_DOWN)
193 PointF point = focusFrameDisplay.getPointWithEvent(event);
194 return ((focusFrameDisplay.isContainsPoint(point)) && autoFocus.lockAutoFocus(point));
198 * オートフォーカスのポイントに含まれているか確認する (trueだったら含まれる)
202 public boolean isContainsAutoFocusPoint(MotionEvent event)
204 //// 以下の機能は、タッチイベントの受信時のみ動作させる
205 //if (event.getAction() != MotionEvent.ACTION_DOWN)
212 PointF point = focusFrameDisplay.getPointWithEvent(event);
215 RectF rect = camera.getAutoFocusEffectiveArea();
216 //Log.v(TAG, "AF POINT (" + point.x + "," + point.y + ")");
217 //Log.v(TAG, "AF EFFECTIVE AREA (" + rect.left + "," + rect.left + ") - (" + rect.right + "," + rect.bottom + ")");
218 return (rect.contains(point.x, point.y));
230 public void unlockAutoFocus()
232 autoFocus.unlockAutoFocus();
233 focusFrameDisplay.hideFocusFrame();
234 isAutoFocusLocked = false;
241 public void singleShot()
243 singleShot.singleShot();
245 // 撮影の表示をToastで行う (成功とか失敗とか言っていない)
246 Toast.makeText(context, R.string.shoot_camera, Toast.LENGTH_SHORT).show();
254 public void movieControl()
256 movieControl.movieControl();
260 * インターバル&ブラケッティング撮影の実行
262 * @param bracketingStyle : ブラケッティングスタイル
263 * @param bracketingCount : 撮影枚数
264 * @param durationSeconds : 撮影間隔(単位:秒)
268 public void bracketingShot(int bracketingStyle, int bracketingCount, int durationSeconds)
270 bracketingShot.bracketingShot(bracketingStyle, bracketingCount, durationSeconds);
278 public void setRecViewMode(boolean isRecViewMode)
282 String value = "<" + IOlyCameraProperty.REC_PREVIEW + "/";
285 value = value + "ON>";
289 value = value + "OFF>";
291 propertyProxy.setCameraPropertyValue(IOlyCameraProperty.REC_PREVIEW, value);
301 public void toggleAutoExposure()
307 Log.v(TAG, "toggleAutoExposure() : unlockAutoExposure()");
308 camera.unlockAutoExposure();
312 Log.v(TAG, "toggleAutoExposure() : lockAutoExposure()");
313 camera.lockAutoExposure();
315 updateIndicatorScreen(false);
321 cameraStatusDisplay.updateAeLockState();
329 public void toggleManualFocus()
333 boolean isHideFocusFrame = false;
334 String property_name = IOlyCameraProperty.FOCUS_STILL;
335 String poverty_value = "<" + IOlyCameraProperty.FOCUS_STILL + "/";
340 // AF -> MF : オートフォーカスを解除して設定する
341 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_MF);
342 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_MF + ">";
343 camera.unlockAutoFocus();
344 camera.setCameraPropertyValue(property_name, poverty_value);
345 isHideFocusFrame = true;
350 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_SAF);
351 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_SAF + ">";
352 camera.setCameraPropertyValue(property_name, poverty_value);
354 updateIndicatorScreen(isHideFocusFrame);
362 private void updateIndicatorScreen(boolean isHideFocusFrame)
365 if (isHideFocusFrame)
367 isAutoFocusLocked = false;
368 focusFrameDisplay.hideFocusFrame();
370 cameraStatusDisplay.updateCameraStatus();
374 public boolean isManualFocus()
376 isManualFocus = propertyProxy.isManualFocus();
377 return (isManualFocus);
381 public boolean isAFLock()
383 return (isAutoFocusLocked);
387 public boolean isAELock()
389 return (propertyProxy.isExposureLocked());
393 public void setCameraStatusListener(OLYCameraStatusListener listener)
395 camera.setCameraStatusListener(listener);
399 public String getCameraStatusSummary(ICameraStatusSummary decoder)
401 return (decoder.getCameraStatusMessage(camera, ""));
409 public void updateStatusAll()
411 cameraStatusDisplay.updateCameraStatusAll();
415 public void changeRunMode(boolean isRecording)
417 OLYCamera.RunMode runMode = (isRecording) ? OLYCamera.RunMode.Recording : OLYCamera.RunMode.Playback;
418 Log.v(TAG, "changeRunMode() : " + runMode);
421 camera.changeRunMode(runMode);
430 public boolean isRecordingMode()
432 boolean isRecordingMode = false;
435 OLYCamera.RunMode runMode = camera.getRunMode();
436 isRecordingMode = (runMode == OLYCamera.RunMode.Recording);
443 return (isRecordingMode);
447 public IOlyCameraPropertyProvider getCameraPropertyProvider()
449 return (propertyProxy);
453 public ICameraPropertyLoadSaveOperations getCameraPropertyLoadSaveOperations()
455 return (loadSaveOperations);
459 public ILoadSaveCameraProperties getLoadSaveCameraProperties()
461 return (loadSaveCameraProperties);
465 public ICameraRunMode getChangeRunModeExecutor()
471 public IOlyCameraConnection getConnectionInterface()
473 return (cameraConnection);
477 public IZoomLensHolder getZoomLensHolder()
479 return (zoomLensHolder);
483 public ILevelGauge getLevelGauge()
489 public void onAfLockUpdate(boolean isAfLocked)
491 isAutoFocusLocked = isAfLocked;
492 updateIndicatorScreen(false);
496 public OLYCamera getOLYCamera()