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.appcompat.app.AppCompatActivity;
12 import androidx.preference.PreferenceDataStore;
13 import androidx.preference.PreferenceManager;
15 import jp.co.olympus.camerakit.OLYCamera;
17 import jp.co.olympus.camerakit.OLYCameraLiveViewListener;
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.IShowInformation;
22 import jp.sfjp.gokigen.a01c.R;
23 import jp.sfjp.gokigen.a01c.liveview.CameraLiveViewListenerImpl;
24 import jp.sfjp.gokigen.a01c.liveview.IAutoFocusFrameDisplay;
25 import jp.sfjp.gokigen.a01c.liveview.ICameraStatusReceiver;
26 import jp.sfjp.gokigen.a01c.liveview.ILiveImageStatusNotify;
27 import jp.sfjp.gokigen.a01c.olycamerawrapper.dispatcher.FeatureDispatcher;
28 import jp.sfjp.gokigen.a01c.olycamerawrapper.indicator.CameraStatusDisplay;
29 import jp.sfjp.gokigen.a01c.olycamerawrapper.indicator.ICameraStatusDisplay;
30 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraPropertyListenerImpl;
31 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraRecordingListenerImpl;
32 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraStatusListenerImpl;
33 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ICameraPropertyLoadSaveOperations;
34 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ILoadSaveCameraProperties;
35 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.IOlyCameraProperty;
36 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.IOlyCameraPropertyProvider;
37 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.LoadSaveCameraProperties;
38 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.OlyCameraPropertyProxy;
39 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.AutoFocusControl;
40 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.BracketingShotControl;
41 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.MovieRecordingControl;
42 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.SingleShotControl;
43 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.CameraPropertyLoadSaveOperations;
44 import jp.sfjp.gokigen.a01c.preference.IPreferenceCameraPropertyAccessor;
47 * OlyCameraCoordinator : Olympus Air との接続、切断の間をとりもつクラス。
48 * (OLYCameraクラスの実体を保持する)
51 * 2. connectWifi() でカメラと接続する
52 * 3. disconnect() でカメラと切断する
54 * X. onDisconnectedByError() でカメラの通信状態が変更されたことを受信する
55 * o. CameraInteractionCoordinator.ICameraCallback でカメラとの接続状態を通知する
58 public class OlyCameraCoordinator implements ICameraController, IIndicatorControl, ICameraRunMode, IOLYCameraObjectProvider
60 private final String TAG = toString();
61 private final IAutoFocusFrameDisplay focusFrameDisplay;
62 private final OLYCamera camera;
63 private final Activity context;
66 private final AutoFocusControl autoFocus;
67 private final SingleShotControl singleShot;
68 private final MovieRecordingControl movieControl;
69 private final BracketingShotControl bracketingShot;
70 private final OlyCameraPropertyProxy propertyProxy;
71 private final CameraPropertyLoadSaveOperations loadSaveOperations;
72 private final LoadSaveCameraProperties loadSaveCameraProperties;
73 private final OlyCameraConnection cameraConnection;
74 private final ICameraStatusDisplay cameraStatusDisplay;
75 private final LevelMeterHolder levelMeter;
76 private final ZoomLensHolder zoomLensHolder;
78 private boolean isManualFocus = false;
79 private boolean isAutoFocusLocked = false;
80 //private boolean isExposureLocked = false;
82 private FeatureDispatcher featureDispatcher = null;
88 public OlyCameraCoordinator(Activity context, IAutoFocusFrameDisplay focusFrameDisplay, IShowInformation showInformation, ICameraStatusReceiver receiver)
90 this.context = context;
91 this.focusFrameDisplay = focusFrameDisplay;
93 // OLYMPUS CAMERA クラスの初期化、リスナの設定
94 camera = new OLYCamera();
95 camera.setContext(context.getApplicationContext());
97 this.cameraConnection = new OlyCameraConnection(context, camera, receiver);
98 camera.setConnectionListener(cameraConnection);
100 // 本クラスの配下のカメラ制御クラス群の設定
101 autoFocus = new AutoFocusControl(camera, focusFrameDisplay, this); // AF制御
102 singleShot = new SingleShotControl(camera, focusFrameDisplay, this, showInformation); // 1枚撮影
103 movieControl = new MovieRecordingControl(context, camera, showInformation); // ムービー撮影
104 bracketingShot = new BracketingShotControl(camera, focusFrameDisplay, this, showInformation); // ブラケッティング&インターバル撮影
105 propertyProxy = new OlyCameraPropertyProxy(camera); // カメラプロパティ
106 cameraStatusDisplay = new CameraStatusDisplay(propertyProxy, showInformation); // 画面表示
107 this.levelMeter = new LevelMeterHolder(showInformation, PreferenceManager.getDefaultSharedPreferences(context).getBoolean(IPreferenceCameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, false)); // デジタル水準器
108 camera.setCameraStatusListener(new CameraStatusListenerImpl(context, cameraStatusDisplay, levelMeter));
109 camera.setCameraPropertyListener(new CameraPropertyListenerImpl(cameraStatusDisplay));
110 camera.setRecordingListener(new CameraRecordingListenerImpl(context, showInformation));
111 loadSaveCameraProperties = new LoadSaveCameraProperties(context, propertyProxy, this);
112 loadSaveOperations = new CameraPropertyLoadSaveOperations(context, loadSaveCameraProperties, cameraStatusDisplay);
113 zoomLensHolder = new ZoomLensHolder(camera);
117 public void setLiveViewListener(@NonNull CameraLiveViewListenerImpl listener)
119 Log.v(TAG, "setLiveViewListener()");
122 camera.setLiveViewListener(listener);
135 public void changeLiveViewSize(String size)
137 Log.v(TAG, "changeLiveViewSize() : " + size);
140 camera.changeLiveViewSize(CameraPropertyUtilities.toLiveViewSizeType(size));
153 public void startLiveView()
155 Log.v(TAG, "startLiveView()");
158 camera.startLiveView();
171 public void stopLiveView()
173 Log.v(TAG, "stopLiveView()");
176 camera.stopLiveView();
189 public void updateTakeMode()
191 cameraStatusDisplay.updateTakeMode();
197 public boolean driveAutoFocus(MotionEvent event)
199 if (event.getAction() != MotionEvent.ACTION_DOWN)
203 PointF point = focusFrameDisplay.getPointWithEvent(event);
204 return ((focusFrameDisplay.isContainsPoint(point)) && autoFocus.lockAutoFocus(point));
208 * オートフォーカスのポイントに含まれているか確認する (trueだったら含まれる)
212 public boolean isContainsAutoFocusPoint(MotionEvent event)
214 //// 以下の機能は、タッチイベントの受信時のみ動作させる
215 //if (event.getAction() != MotionEvent.ACTION_DOWN)
222 PointF point = focusFrameDisplay.getPointWithEvent(event);
225 RectF rect = camera.getAutoFocusEffectiveArea();
226 //Log.v(TAG, "AF POINT (" + point.x + "," + point.y + ")");
227 //Log.v(TAG, "AF EFFECTIVE AREA (" + rect.left + "," + rect.left + ") - (" + rect.right + "," + rect.bottom + ")");
228 return (rect.contains(point.x, point.y));
240 public void unlockAutoFocus()
242 autoFocus.unlockAutoFocus();
243 focusFrameDisplay.hideFocusFrame();
244 isAutoFocusLocked = false;
251 public void singleShot()
253 singleShot.singleShot();
255 // 撮影の表示をToastで行う (成功とか失敗とか言っていない)
256 Toast.makeText(context, R.string.shoot_camera, Toast.LENGTH_SHORT).show();
264 public void movieControl()
266 movieControl.movieControl();
270 * インターバル&ブラケッティング撮影の実行
272 * @param bracketingStyle : ブラケッティングスタイル
273 * @param bracketingCount : 撮影枚数
274 * @param durationSeconds : 撮影間隔(単位:秒)
278 public void bracketingShot(int bracketingStyle, int bracketingCount, int durationSeconds)
280 bracketingShot.bracketingShot(bracketingStyle, bracketingCount, durationSeconds);
288 public void setRecViewMode(boolean isRecViewMode)
292 String value = "<" + IOlyCameraProperty.REC_PREVIEW + "/";
295 value = value + "ON>";
299 value = value + "OFF>";
301 propertyProxy.setCameraPropertyValue(IOlyCameraProperty.REC_PREVIEW, value);
311 public void toggleAutoExposure()
317 Log.v(TAG, "toggleAutoExposure() : unlockAutoExposure()");
318 camera.unlockAutoExposure();
322 Log.v(TAG, "toggleAutoExposure() : lockAutoExposure()");
323 camera.lockAutoExposure();
325 updateIndicatorScreen(false);
331 cameraStatusDisplay.updateAeLockState();
339 public void toggleManualFocus()
343 boolean isHideFocusFrame = false;
344 String property_name = IOlyCameraProperty.FOCUS_STILL;
345 String poverty_value = "<" + IOlyCameraProperty.FOCUS_STILL + "/";
350 // AF -> MF : オートフォーカスを解除して設定する
351 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_MF);
352 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_MF + ">";
353 camera.unlockAutoFocus();
354 camera.setCameraPropertyValue(property_name, poverty_value);
355 isHideFocusFrame = true;
360 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_SAF);
361 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_SAF + ">";
362 camera.setCameraPropertyValue(property_name, poverty_value);
364 updateIndicatorScreen(isHideFocusFrame);
372 private void updateIndicatorScreen(boolean isHideFocusFrame)
375 if (isHideFocusFrame)
377 isAutoFocusLocked = false;
378 focusFrameDisplay.hideFocusFrame();
380 cameraStatusDisplay.updateCameraStatus();
384 public boolean isManualFocus()
386 isManualFocus = propertyProxy.isManualFocus();
387 return (isManualFocus);
391 public boolean isAFLock()
393 return (isAutoFocusLocked);
397 public boolean isAELock()
399 return (propertyProxy.isExposureLocked());
404 public void setCameraStatusListener(OLYCameraStatusListener listener)
406 camera.setCameraStatusListener(listener);
410 public String getCameraStatusSummary(ICameraStatusSummary decoder)
412 return (decoder.getCameraStatusMessage(camera, ""));
421 public void updateStatusAll()
423 cameraStatusDisplay.updateCameraStatusAll();
427 public void changeRunMode(boolean isRecording)
429 OLYCamera.RunMode runMode = (isRecording) ? OLYCamera.RunMode.Recording : OLYCamera.RunMode.Playback;
430 Log.v(TAG, "changeRunMode() : " + runMode);
433 camera.changeRunMode(runMode);
442 public boolean isRecordingMode()
444 boolean isRecordingMode = false;
447 OLYCamera.RunMode runMode = camera.getRunMode();
448 isRecordingMode = (runMode == OLYCamera.RunMode.Recording);
455 return (isRecordingMode);
459 public IOlyCameraPropertyProvider getCameraPropertyProvider()
461 return (propertyProxy);
465 public ICameraPropertyLoadSaveOperations getCameraPropertyLoadSaveOperations()
467 return (loadSaveOperations);
471 public ILoadSaveCameraProperties getLoadSaveCameraProperties()
473 return (loadSaveCameraProperties);
477 public ICameraRunMode getChangeRunModeExecutor()
483 public ICameraConnection getConnectionInterface()
485 return (cameraConnection);
489 public IZoomLensHolder getZoomLensHolder()
491 return (zoomLensHolder);
495 public ILevelGauge getLevelGauge()
501 public @NonNull ICameraFeatureDispatcher getFeatureDispatcher(@NonNull AppCompatActivity context, @NonNull IShowInformation statusDrawer, @NonNull ICameraController camera, @NonNull PreferenceDataStore preferenceAccessWrapper, @NonNull ILiveImageStatusNotify liveImageView)
503 if (featureDispatcher == null)
505 featureDispatcher = new FeatureDispatcher(context, statusDrawer, camera, preferenceAccessWrapper, liveImageView);
507 return (featureDispatcher);
511 public void onAfLockUpdate(boolean isAfLocked)
513 isAutoFocusLocked = isAfLocked;
514 updateIndicatorScreen(false);
518 public void onShootingStatusUpdate(shootingStatus status)
520 Log.v(TAG, " ShootingStatus : " + status);
524 public OLYCamera getOLYCamera()