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();
281 public void bracketingControl()
287 * インターバル&ブラケッティング撮影の実行
289 * @param bracketingStyle : ブラケッティングスタイル
290 * @param bracketingCount : 撮影枚数
291 * @param durationSeconds : 撮影間隔(単位:秒)
295 public void bracketingShot(int bracketingStyle, int bracketingCount, int durationSeconds)
297 bracketingShot.bracketingShot(bracketingStyle, bracketingCount, durationSeconds);
305 public void setRecViewMode(boolean isRecViewMode)
309 String value = "<" + IOlyCameraProperty.REC_PREVIEW + "/";
312 value = value + "ON>";
316 value = value + "OFF>";
318 propertyProxy.setCameraPropertyValue(IOlyCameraProperty.REC_PREVIEW, value);
328 public void toggleAutoExposure()
334 Log.v(TAG, "toggleAutoExposure() : unlockAutoExposure()");
335 camera.unlockAutoExposure();
339 Log.v(TAG, "toggleAutoExposure() : lockAutoExposure()");
340 camera.lockAutoExposure();
342 updateIndicatorScreen(false);
348 cameraStatusDisplay.updateAeLockState();
356 public void toggleManualFocus()
360 boolean isHideFocusFrame = false;
361 String property_name = IOlyCameraProperty.FOCUS_STILL;
362 String poverty_value = "<" + IOlyCameraProperty.FOCUS_STILL + "/";
367 // AF -> MF : オートフォーカスを解除して設定する
368 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_MF);
369 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_MF + ">";
370 camera.unlockAutoFocus();
371 camera.setCameraPropertyValue(property_name, poverty_value);
372 isHideFocusFrame = true;
377 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_SAF);
378 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_SAF + ">";
379 camera.setCameraPropertyValue(property_name, poverty_value);
381 updateIndicatorScreen(isHideFocusFrame);
389 private void updateIndicatorScreen(boolean isHideFocusFrame)
392 if (isHideFocusFrame)
394 isAutoFocusLocked = false;
395 focusFrameDisplay.hideFocusFrame();
397 cameraStatusDisplay.updateCameraStatus();
401 public boolean isManualFocus()
403 isManualFocus = propertyProxy.isManualFocus();
404 return (isManualFocus);
408 public boolean isAFLock()
410 return (isAutoFocusLocked);
414 public boolean isAELock()
416 return (propertyProxy.isExposureLocked());
421 public void setCameraStatusListener(OLYCameraStatusListener listener)
423 camera.setCameraStatusListener(listener);
427 public String getCameraStatusSummary(ICameraStatusSummary decoder)
429 return (decoder.getCameraStatusMessage(camera, ""));
438 public void updateStatusAll()
440 cameraStatusDisplay.updateCameraStatusAll();
445 public ICameraStatusWatcher getStatusWatcher()
451 public void changeRunMode(boolean isRecording)
453 OLYCamera.RunMode runMode = (isRecording) ? OLYCamera.RunMode.Recording : OLYCamera.RunMode.Playback;
454 Log.v(TAG, "changeRunMode() : " + runMode);
457 camera.changeRunMode(runMode);
466 public boolean isRecordingMode()
468 boolean isRecordingMode = false;
471 OLYCamera.RunMode runMode = camera.getRunMode();
472 isRecordingMode = (runMode == OLYCamera.RunMode.Recording);
479 return (isRecordingMode);
483 public IOlyCameraPropertyProvider getCameraPropertyProvider()
485 return (propertyProxy);
489 public ICameraPropertyLoadSaveOperations getCameraPropertyLoadSaveOperations()
491 return (loadSaveOperations);
495 public ILoadSaveCameraProperties getLoadSaveCameraProperties()
497 return (loadSaveCameraProperties);
501 public ICameraRunMode getChangeRunModeExecutor()
507 public ICameraConnection getConnectionInterface()
509 return (cameraConnection);
513 public IZoomLensHolder getZoomLensHolder()
515 return (zoomLensHolder);
519 public ILevelGauge getLevelGauge()
525 public @NonNull ICameraFeatureDispatcher getFeatureDispatcher(@NonNull AppCompatActivity context, @NonNull IShowInformation statusDrawer, @NonNull ICameraController camera, @NonNull PreferenceDataStore preferenceAccessWrapper, @NonNull ILiveImageStatusNotify liveImageView)
527 if (featureDispatcher == null)
529 featureDispatcher = new FeatureDispatcher(context, statusDrawer, camera, preferenceAccessWrapper, liveImageView);
531 return (featureDispatcher);
535 public void onAfLockUpdate(boolean isAfLocked)
537 isAutoFocusLocked = isAfLocked;
538 updateIndicatorScreen(false);
542 public void onShootingStatusUpdate(shootingStatus status)
544 Log.v(TAG, " ShootingStatus : " + status);
548 public OLYCamera getOLYCamera()