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;
7 import android.widget.Toast;
9 import jp.co.olympus.camerakit.OLYCamera;
10 import jp.co.olympus.camerakit.OLYCameraLiveViewListener;
11 import jp.co.olympus.camerakit.OLYCameraStatusListener;
13 import jp.sfjp.gokigen.a01c.IShowInformation;
14 import jp.sfjp.gokigen.a01c.R;
15 import jp.sfjp.gokigen.a01c.liveview.IAutoFocusFrameDisplay;
16 import jp.sfjp.gokigen.a01c.liveview.ICameraStatusReceiver;
17 import jp.sfjp.gokigen.a01c.olycamerawrapper.indicator.CameraStatusDisplay;
18 import jp.sfjp.gokigen.a01c.olycamerawrapper.indicator.ICameraStatusDisplay;
19 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraPropertyListenerImpl;
20 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraRecordingListenerImpl;
21 import jp.sfjp.gokigen.a01c.olycamerawrapper.listeners.CameraStatusListenerImpl;
22 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ICameraPropertyLoadSaveOperations;
23 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.ILoadSaveCameraProperties;
24 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.IOlyCameraProperty;
25 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.IOlyCameraPropertyProvider;
26 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.LoadSaveCameraProperties;
27 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.OlyCameraPropertyProxy;
28 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.AutoFocusControl;
29 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.BracketingShotControl;
30 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.MovieRecordingControl;
31 import jp.sfjp.gokigen.a01c.olycamerawrapper.takepicture.SingleShotControl;
32 import jp.sfjp.gokigen.a01c.olycamerawrapper.property.CameraPropertyLoadSaveOperations;
33 import jp.sfjp.gokigen.a01c.preference.IPreferenceCameraPropertyAccessor;
36 * OlyCameraCoordinator : Olympus Air との接続、切断の間をとりもつクラス。
37 * (OLYCameraクラスの実体を保持する)
40 * 2. connectWifi() でカメラと接続する
41 * 3. disconnect() でカメラと切断する
43 * X. onDisconnectedByError() でカメラの通信状態が変更されたことを受信する
44 * o. CameraInteractionCoordinator.ICameraCallback でカメラとの接続状態を通知する
47 public class OlyCameraCoordinator implements IOlyCameraCoordinator, IIndicatorControl, ICameraRunMode, IOLYCameraObjectProvider
49 private final String TAG = toString();
50 private final IAutoFocusFrameDisplay focusFrameDisplay;
51 private final OLYCamera camera;
52 private final Activity context;
55 private final AutoFocusControl autoFocus;
56 private final SingleShotControl singleShot;
57 private final MovieRecordingControl movieControl;
58 private final BracketingShotControl bracketingShot;
59 private final OlyCameraPropertyProxy propertyProxy;
60 private final CameraPropertyLoadSaveOperations loadSaveOperations;
61 private final LoadSaveCameraProperties loadSaveCameraProperties;
62 private final OlyCameraConnection cameraConnection;
63 private final ICameraStatusDisplay cameraStatusDisplay;
64 private final LevelMeterHolder levelMeter;
66 private boolean isManualFocus = false;
67 private boolean isAutoFocusLocked = false;
68 //private boolean isExposureLocked = false;
74 public OlyCameraCoordinator(Activity context, IAutoFocusFrameDisplay focusFrameDisplay, IShowInformation showInformation, ICameraStatusReceiver receiver)
76 this.context = context;
77 this.focusFrameDisplay = focusFrameDisplay;
79 // OLYMPUS CAMERA クラスの初期化、リスナの設定
80 camera = new OLYCamera();
81 camera.setContext(context.getApplicationContext());
83 this.cameraConnection = new OlyCameraConnection(context, camera, receiver);
84 camera.setConnectionListener(cameraConnection);
86 // 本クラスの配下のカメラ制御クラス群の設定
87 autoFocus = new AutoFocusControl(camera, focusFrameDisplay, this); // AF制御
88 singleShot = new SingleShotControl(camera, focusFrameDisplay, this, showInformation); // 1枚撮影
89 movieControl = new MovieRecordingControl(context, camera, showInformation); // ムービー撮影
90 bracketingShot = new BracketingShotControl(camera, focusFrameDisplay, this, showInformation); // ブラケッティング&インターバル撮影
91 propertyProxy = new OlyCameraPropertyProxy(camera); // カメラプロパティ
92 cameraStatusDisplay = new CameraStatusDisplay(propertyProxy, showInformation); // 画面表示
93 this.levelMeter = new LevelMeterHolder(showInformation, android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(IPreferenceCameraPropertyAccessor.SHOW_LEVEL_GAUGE_STATUS, false)); // デジタル水準器
94 camera.setCameraStatusListener(new CameraStatusListenerImpl(context, cameraStatusDisplay, levelMeter));
95 camera.setCameraPropertyListener(new CameraPropertyListenerImpl(cameraStatusDisplay));
96 camera.setRecordingListener(new CameraRecordingListenerImpl(context, showInformation));
97 loadSaveCameraProperties = new LoadSaveCameraProperties(context, propertyProxy, this);
98 loadSaveOperations = new CameraPropertyLoadSaveOperations(context, loadSaveCameraProperties, cameraStatusDisplay);
104 public void setLiveViewListener(OLYCameraLiveViewListener listener)
106 Log.v(TAG, "setLiveViewListener()");
109 camera.setLiveViewListener(listener);
122 public void changeLiveViewSize(String size)
124 Log.v(TAG, "changeLiveViewSize() : " + size);
127 camera.changeLiveViewSize(CameraPropertyUtilities.toLiveViewSizeType(size));
140 public void startLiveView()
142 Log.v(TAG, "startLiveView()");
145 camera.startLiveView();
158 public void stopLiveView()
160 Log.v(TAG, "stopLiveView()");
163 camera.stopLiveView();
176 public void updateTakeMode()
178 cameraStatusDisplay.updateTakeMode();
184 public boolean driveAutoFocus(MotionEvent event)
186 if (event.getAction() != MotionEvent.ACTION_DOWN)
190 PointF point = focusFrameDisplay.getPointWithEvent(event);
191 return ((focusFrameDisplay.isContainsPoint(point)) && autoFocus.lockAutoFocus(point));
197 public void unlockAutoFocus()
199 autoFocus.unlockAutoFocus();
200 focusFrameDisplay.hideFocusFrame();
201 isAutoFocusLocked = false;
208 public void singleShot()
210 singleShot.singleShot();
212 // 撮影の表示をToastで行う (成功とか失敗とか言っていない)
213 Toast.makeText(context, R.string.shoot_camera, Toast.LENGTH_SHORT).show();
221 public void movieControl()
223 movieControl.movieControl();
227 * インターバル&ブラケッティング撮影の実行
229 * @param bracketingStyle : ブラケッティングスタイル
230 * @param bracketingCount : 撮影枚数
231 * @param durationSeconds : 撮影間隔(単位:秒)
235 public void bracketingShot(int bracketingStyle, int bracketingCount, int durationSeconds)
237 bracketingShot.bracketingShot(bracketingStyle, bracketingCount, durationSeconds);
245 public void setRecViewMode(boolean isRecViewMode)
249 String value = "<" + IOlyCameraProperty.REC_PREVIEW + "/";
252 value = value + "ON>";
256 value = value + "OFF>";
258 propertyProxy.setCameraPropertyValue(IOlyCameraProperty.REC_PREVIEW, value);
268 public void toggleAutoExposure()
274 Log.v(TAG, "toggleAutoExposure() : unlockAutoExposure()");
275 camera.unlockAutoExposure();
279 Log.v(TAG, "toggleAutoExposure() : lockAutoExposure()");
280 camera.lockAutoExposure();
282 updateIndicatorScreen(false);
288 cameraStatusDisplay.updateAeLockState();
296 public void toggleManualFocus()
300 boolean isHideFocusFrame = false;
301 String property_name = IOlyCameraProperty.FOCUS_STILL;
302 String poverty_value = "<" + IOlyCameraProperty.FOCUS_STILL + "/";
307 // AF -> MF : オートフォーカスを解除して設定する
308 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_MF);
309 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_MF + ">";
310 camera.unlockAutoFocus();
311 camera.setCameraPropertyValue(property_name, poverty_value);
312 isHideFocusFrame = true;
317 Log.v(TAG, "toggleManualFocus() : to " + IOlyCameraProperty.FOCUS_SAF);
318 poverty_value = poverty_value + IOlyCameraProperty.FOCUS_SAF + ">";
319 camera.setCameraPropertyValue(property_name, poverty_value);
321 updateIndicatorScreen(isHideFocusFrame);
329 private void updateIndicatorScreen(boolean isHideFocusFrame)
332 if (isHideFocusFrame)
334 isAutoFocusLocked = false;
335 focusFrameDisplay.hideFocusFrame();
337 cameraStatusDisplay.updateCameraStatus();
341 public boolean isManualFocus()
343 isManualFocus = propertyProxy.isManualFocus();
344 return (isManualFocus);
348 public boolean isAFLock()
350 return (isAutoFocusLocked);
354 public boolean isAELock()
356 return (propertyProxy.isExposureLocked());
360 public void setCameraStatusListener(OLYCameraStatusListener listener)
362 camera.setCameraStatusListener(listener);
366 public String getCameraStatusSummary(ICameraStatusSummary decoder)
368 return (decoder.getCameraStatusMessage(camera, ""));
376 public void updateStatusAll()
378 cameraStatusDisplay.updateCameraStatusAll();
382 public void changeRunMode(boolean isRecording)
384 OLYCamera.RunMode runMode = (isRecording) ? OLYCamera.RunMode.Recording : OLYCamera.RunMode.Playback;
385 Log.v(TAG, "changeRunMode() : " + runMode);
388 camera.changeRunMode(runMode);
397 public boolean isRecordingMode()
399 boolean isRecordingMode = false;
402 OLYCamera.RunMode runMode = camera.getRunMode();
403 isRecordingMode = (runMode == OLYCamera.RunMode.Recording);
410 return (isRecordingMode);
414 public IOlyCameraPropertyProvider getCameraPropertyProvider()
416 return (propertyProxy);
420 public ICameraPropertyLoadSaveOperations getCameraPropertyLoadSaveOperations()
422 return (loadSaveOperations);
426 public ILoadSaveCameraProperties getLoadSaveCameraProperties()
428 return (loadSaveCameraProperties);
432 public ICameraRunMode getChangeRunModeExecutor()
438 public IOlyCameraConnection getConnectionInterface()
440 return (cameraConnection);
444 public ILevelGauge getLevelGauge()
450 public void onAfLockUpdate(boolean isAfLocked)
452 isAutoFocusLocked = isAfLocked;
453 updateIndicatorScreen(false);
457 public OLYCamera getOLYCamera()