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 androidx.annotation.NonNull;
11 import androidx.annotation.Nullable;
12 import androidx.appcompat.app.AppCompatActivity;
13 import androidx.preference.PreferenceDataStore;
14 import androidx.preference.PreferenceManager;
16 import jp.co.olympus.camerakit.OLYCamera;
18 import jp.sfjp.gokigen.a01c.ICameraConnection;
19 import jp.sfjp.gokigen.a01c.ICameraController;
20 import jp.sfjp.gokigen.a01c.ICameraFeatureDispatcher;
21 import jp.sfjp.gokigen.a01c.ICameraStatusWatcher;
22 import jp.sfjp.gokigen.a01c.IShowInformation;
23 import jp.sfjp.gokigen.a01c.R;
24 import jp.sfjp.gokigen.a01c.liveview.CameraLiveViewListenerImpl;
25 import jp.sfjp.gokigen.a01c.liveview.IAutoFocusFrameDisplay;
26 import jp.sfjp.gokigen.a01c.liveview.ICameraStatusReceiver;
27 import jp.sfjp.gokigen.a01c.liveview.ILiveImageStatusNotify;
28 import jp.sfjp.gokigen.a01c.olycamerawrapper.dispatcher.FeatureDispatcher;
29 import jp.sfjp.gokigen.a01c.olycamerawrapper.indicator.CameraStatusDisplay;
30 import jp.sfjp.gokigen.a01c.olycamerawrapper.indicator.ICameraStatusDisplay;
31 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraPropertyListenerImpl;
32 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraRecordingListenerImpl;
33 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraStatusListenerImpl;
34 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ICameraPropertyLoadSaveOperations;
35 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ILoadSaveCameraProperties;
36 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.IOlyCameraProperty;
37 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.IOlyCameraPropertyProvider;
38 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.LoadSaveCameraProperties;
39 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.OlyCameraPropertyProxy;
40 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.AutoFocusControl;
41 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.BracketingShotControl;
42 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.MovieRecordingControl;
43 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.SingleShotControl;
44 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.CameraPropertyLoadSaveOperations;
45 import jp.sfjp.gokigen.a01c.preference.IPreferenceCameraPropertyAccessor;
48 * OlyCameraCoordinator : Olympus Air との接続、切断の間をとりもつクラス。
49 * (OLYCameraクラスの実体を保持する)
52 * 2. connectWifi() でカメラと接続する
53 * 3. disconnect() でカメラと切断する
55 * X. onDisconnectedByError() でカメラの通信状態が変更されたことを受信する
56 * o. CameraInteractionCoordinator.ICameraCallback でカメラとの接続状態を通知する
59 public class OlyCameraCoordinator implements ICameraController, IIndicatorControl, ICameraRunMode, IOLYCameraObjectProvider
61 private final String TAG = toString();
62 private final IAutoFocusFrameDisplay focusFrameDisplay;
63 private final OLYCamera camera;
64 private final Activity context;
67 private final AutoFocusControl autoFocus;
68 private final SingleShotControl singleShot;
69 private final MovieRecordingControl movieControl;
70 private final BracketingShotControl bracketingShot;
71 private final OlyCameraPropertyProxy propertyProxy;
72 private final CameraPropertyLoadSaveOperations loadSaveOperations;
73 private final LoadSaveCameraProperties loadSaveCameraProperties;
74 private final OlyCameraConnection cameraConnection;
75 private final ICameraStatusDisplay cameraStatusDisplay;
76 private final LevelMeterHolder levelMeter;
77 private final ZoomLensHolder zoomLensHolder;
79 private boolean isManualFocus = false;
80 private boolean isAutoFocusLocked = false;
81 //private boolean isExposureLocked = false;
83 private FeatureDispatcher featureDispatcher = null;
89 public OlyCameraCoordinator(Activity context, IAutoFocusFrameDisplay focusFrameDisplay, IShowInformation showInformation, ICameraStatusReceiver receiver)
91 this.context = context;
92 this.focusFrameDisplay = focusFrameDisplay;
94 // OLYMPUS CAMERA クラスの初期化、リスナの設定
95 camera = new OLYCamera();
96 camera.setContext(context.getApplicationContext());
98 this.cameraConnection = new OlyCameraConnection(context, camera, receiver);
99 camera.setConnectionListener(cameraConnection);
101 // 本クラスの配下のカメラ制御クラス群の設定
102 autoFocus = new AutoFocusControl(camera, focusFrameDisplay, this); // AF制御
103 singleShot = new SingleShotControl(camera, focusFrameDisplay, this, showInformation); // 1枚撮影
104 movieControl = new MovieRecordingControl(context, camera, showInformation); // ムービー撮影
105 bracketingShot = new BracketingShotControl(camera, focusFrameDisplay, this, showInformation); // ブラケッティング&インターバル撮影
106 propertyProxy = new OlyCameraPropertyProxy(camera); // カメラプロパティ
107 cameraStatusDisplay = new CameraStatusDisplay(propertyProxy, showInformation); // 画面表示
108 this.levelMeter = new LevelMeterHolder(showInformation, PreferenceManager.getDefaultSharedPreferences(context).getBoolean(IPreferenceCameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, false)); // デジタル水準器
109 camera.setCameraStatusListener(new CameraStatusListenerImpl(context, cameraStatusDisplay, levelMeter));
110 camera.setCameraPropertyListener(new CameraPropertyListenerImpl(cameraStatusDisplay));
111 camera.setRecordingListener(new CameraRecordingListenerImpl(context, showInformation));
112 loadSaveCameraProperties = new LoadSaveCameraProperties(context, propertyProxy, this);
113 loadSaveOperations = new CameraPropertyLoadSaveOperations(context, loadSaveCameraProperties, cameraStatusDisplay);
114 zoomLensHolder = new ZoomLensHolder(camera);
118 public void connectFinished()
124 public void setLiveViewListener(@NonNull CameraLiveViewListenerImpl listener)
126 Log.v(TAG, "setLiveViewListener()");
129 camera.setLiveViewListener(listener);
142 public void changeLiveViewSize(String size)
144 Log.v(TAG, "changeLiveViewSize() : " + size);
147 camera.changeLiveViewSize(CameraPropertyUtilities.toLiveViewSizeType(size));
160 public void startLiveView()
162 Log.v(TAG, "startLiveView()");
165 camera.startLiveView();
178 public void stopLiveView()
180 Log.v(TAG, "stopLiveView()");
183 camera.stopLiveView();
196 public void updateTakeMode()
198 cameraStatusDisplay.updateTakeMode();
204 public boolean driveAutoFocus(MotionEvent event)
206 if (event.getAction() != MotionEvent.ACTION_DOWN)
210 PointF point = focusFrameDisplay.getPointWithEvent(event);
211 return ((focusFrameDisplay.isContainsPoint(point)) && autoFocus.lockAutoFocus(point));
215 * オートフォーカスのポイントに含まれているか確認する (trueだったら含まれる)
219 public boolean isContainsAutoFocusPoint(MotionEvent event)
221 //// 以下の機能は、タッチイベントの受信時のみ動作させる
222 //if (event.getAction() != MotionEvent.ACTION_DOWN)
229 PointF point = focusFrameDisplay.getPointWithEvent(event);
232 RectF rect = camera.getAutoFocusEffectiveArea();
233 //Log.v(TAG, "AF POINT (" + point.x + "," + point.y + ")");
234 //Log.v(TAG, "AF EFFECTIVE AREA (" + rect.left + "," + rect.left + ") - (" + rect.right + "," + rect.bottom + ")");
235 return (rect.contains(point.x, point.y));
247 public void unlockAutoFocus()
249 autoFocus.unlockAutoFocus();
250 focusFrameDisplay.hideFocusFrame();
251 isAutoFocusLocked = false;
258 public void singleShot()
260 singleShot.singleShot();
262 // 撮影の表示をToastで行う (成功とか失敗とか言っていない)
263 Toast.makeText(context, R.string.shoot_camera, Toast.LENGTH_SHORT).show();
271 public void movieControl()
273 movieControl.movieControl();
277 * インターバル&ブラケッティング撮影の実行
279 * @param bracketingStyle : ブラケッティングスタイル
280 * @param bracketingCount : 撮影枚数
281 * @param durationSeconds : 撮影間隔(単位:秒)
285 public void bracketingShot(int bracketingStyle, int bracketingCount, int durationSeconds)
287 bracketingShot.bracketingShot(bracketingStyle, bracketingCount, durationSeconds);
295 public void setRecViewMode(boolean isRecViewMode)
299 String value = "<" + IOlyCameraProperty.REC_PREVIEW + "/";
302 value = value + "ON>";
306 value = value + "OFF>";
308 propertyProxy.setCameraPropertyValue(IOlyCameraProperty.REC_PREVIEW, value);
318 public void toggleAutoExposure()
324 Log.v(TAG, "toggleAutoExposure() : unlockAutoExposure()");
325 camera.unlockAutoExposure();
329 Log.v(TAG, "toggleAutoExposure() : lockAutoExposure()");
330 camera.lockAutoExposure();
332 updateIndicatorScreen(false);
338 cameraStatusDisplay.updateAeLockState();
346 public void toggleManualFocus()
350 boolean isHideFocusFrame = false;
351 String property_name = IOlyCameraProperty.FOCUS_STILL;
352 String poverty_value = "<" + IOlyCameraProperty.FOCUS_STILL + "/";
357 // AF -> MF : オートフォーカスを解除して設定する
358 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_MF);
359 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_MF + ">";
360 camera.unlockAutoFocus();
361 camera.setCameraPropertyValue(property_name, poverty_value);
362 isHideFocusFrame = true;
367 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_SAF);
368 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_SAF + ">";
369 camera.setCameraPropertyValue(property_name, poverty_value);
371 updateIndicatorScreen(isHideFocusFrame);
379 private void updateIndicatorScreen(boolean isHideFocusFrame)
382 if (isHideFocusFrame)
384 isAutoFocusLocked = false;
385 focusFrameDisplay.hideFocusFrame();
387 cameraStatusDisplay.updateCameraStatus();
391 public boolean isManualFocus()
393 isManualFocus = propertyProxy.isManualFocus();
394 return (isManualFocus);
398 public boolean isAFLock()
400 return (isAutoFocusLocked);
404 public boolean isAELock()
406 return (propertyProxy.isExposureLocked());
411 public void setCameraStatusListener(OLYCameraStatusListener listener)
413 camera.setCameraStatusListener(listener);
417 public String getCameraStatusSummary(ICameraStatusSummary decoder)
419 return (decoder.getCameraStatusMessage(camera, ""));
428 public void updateStatusAll()
430 cameraStatusDisplay.updateCameraStatusAll();
435 public ICameraStatusWatcher getStatusWatcher()
441 public void changeRunMode(boolean isRecording)
443 OLYCamera.RunMode runMode = (isRecording) ? OLYCamera.RunMode.Recording : OLYCamera.RunMode.Playback;
444 Log.v(TAG, "changeRunMode() : " + runMode);
447 camera.changeRunMode(runMode);
456 public boolean isRecordingMode()
458 boolean isRecordingMode = false;
461 OLYCamera.RunMode runMode = camera.getRunMode();
462 isRecordingMode = (runMode == OLYCamera.RunMode.Recording);
469 return (isRecordingMode);
473 public IOlyCameraPropertyProvider getCameraPropertyProvider()
475 return (propertyProxy);
479 public ICameraPropertyLoadSaveOperations getCameraPropertyLoadSaveOperations()
481 return (loadSaveOperations);
485 public ILoadSaveCameraProperties getLoadSaveCameraProperties()
487 return (loadSaveCameraProperties);
491 public ICameraRunMode getChangeRunModeExecutor()
497 public ICameraConnection getConnectionInterface()
499 return (cameraConnection);
503 public IZoomLensHolder getZoomLensHolder()
505 return (zoomLensHolder);
509 public ILevelGauge getLevelGauge()
515 public @NonNull ICameraFeatureDispatcher getFeatureDispatcher(@NonNull AppCompatActivity context, @NonNull IShowInformation statusDrawer, @NonNull ICameraController camera, @NonNull PreferenceDataStore preferenceAccessWrapper, @NonNull ILiveImageStatusNotify liveImageView)
517 if (featureDispatcher == null)
519 featureDispatcher = new FeatureDispatcher(context, statusDrawer, camera, preferenceAccessWrapper, liveImageView);
521 return (featureDispatcher);
525 public void onAfLockUpdate(boolean isAfLocked)
527 isAutoFocusLocked = isAfLocked;
528 updateIndicatorScreen(false);
532 public void onShootingStatusUpdate(shootingStatus status)
534 Log.v(TAG, " ShootingStatus : " + status);
538 public OLYCamera getOLYCamera()