1 package net.osdn.gokigen.a01d.liveview;
3 import android.content.Context;
4 import android.content.SharedPreferences;
5 import android.util.Log;
6 import android.view.KeyEvent;
7 import android.view.MotionEvent;
8 import android.view.View;
9 import android.widget.Toast;
11 import net.osdn.gokigen.a01d.IChangeScene;
12 import net.osdn.gokigen.a01d.R;
13 import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
14 import net.osdn.gokigen.a01d.camera.ICaptureControl;
15 import net.osdn.gokigen.a01d.camera.IFocusingControl;
16 import net.osdn.gokigen.a01d.camera.ICameraInformation;
17 import net.osdn.gokigen.a01d.camera.ICameraConnection;
18 import net.osdn.gokigen.a01d.camera.IZoomLensControl;
19 import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraProperty;
20 import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraPropertyProvider;
21 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
23 import androidx.annotation.NonNull;
24 import androidx.preference.PreferenceManager;
30 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener, View.OnKeyListener
32 private final String TAG = toString();
33 private final Context context;
34 private final ILiveImageStatusNotify statusNotify;
35 private final IStatusViewDrawer statusViewDrawer;
36 private final IChangeScene changeScene;
37 private final IInterfaceProvider interfaceProvider;
38 private final IFocusingControl focusingControl;
39 private final ICaptureControl captureControl;
40 private final IOlyCameraPropertyProvider propertyProvider;
41 private final ICameraInformation cameraInformation;
42 private final ICameraConnection cameraConnection;
43 private final IDialogKicker dialogKicker;
44 private final IZoomLensControl zoomLensControl;
46 LiveViewClickTouchListener(Context context, ILiveImageStatusNotify imageStatusNotify, IStatusViewDrawer statusView, IChangeScene changeScene, IInterfaceProvider interfaceProvider, IDialogKicker dialogKicker)
48 this.context = context;
49 this.statusNotify = imageStatusNotify;
50 this.statusViewDrawer = statusView;
51 this.changeScene = changeScene;
52 this.interfaceProvider = interfaceProvider;
54 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
55 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
57 this.focusingControl = interfaceProvider.getRicohGr2Infterface().getFocusingControl();
58 this.captureControl = interfaceProvider.getRicohGr2Infterface().getCaptureControl();
59 this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider(); // 要変更
60 this.cameraInformation = interfaceProvider.getRicohGr2Infterface().getCameraInformation();
61 this.cameraConnection = interfaceProvider.getRicohGr2Infterface().getRicohGr2CameraConnection();
62 this.zoomLensControl = interfaceProvider.getRicohGr2Infterface().getZoomLensControl();
64 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
66 this.focusingControl = interfaceProvider.getSonyInterface().getFocusingControl();
67 this.captureControl = interfaceProvider.getSonyInterface().getCaptureControl();
68 this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider(); // 要変更
69 this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
70 this.cameraConnection = interfaceProvider.getSonyInterface().getSonyCameraConnection();
71 this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
73 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
75 this.focusingControl = interfaceProvider.getFujiXInterface().getFocusingControl();
76 this.captureControl = interfaceProvider.getFujiXInterface().getCaptureControl();
77 this.cameraInformation = interfaceProvider.getFujiXInterface().getCameraInformation();
78 this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider(); // 要変更
79 this.cameraConnection = interfaceProvider.getFujiXInterface().getFujiXCameraConnection();
80 this.zoomLensControl = interfaceProvider.getFujiXInterface().getZoomLensControl();
82 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
84 this.focusingControl = interfaceProvider.getPanasonicInterface().getFocusingControl();
85 this.captureControl = interfaceProvider.getPanasonicInterface().getCaptureControl();
86 this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider(); // 要変更
87 this.cameraInformation = interfaceProvider.getPanasonicInterface().getCameraInformation();
88 this.cameraConnection = interfaceProvider.getPanasonicInterface().getPanasonicCameraConnection();
89 this.zoomLensControl = interfaceProvider.getPanasonicInterface().getZoomLensControl();
91 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS)
93 this.focusingControl = interfaceProvider.getOlympusPenInterface().getFocusingControl();
94 this.captureControl = interfaceProvider.getOlympusPenInterface().getCaptureControl();
95 this.propertyProvider = interfaceProvider.getOlympusPenInterface().getCameraPropertyProvider();
96 this.cameraInformation = interfaceProvider.getOlympusPenInterface().getCameraInformation();
97 this.cameraConnection = interfaceProvider.getOlympusPenInterface().getOlyCameraConnection();
98 this.zoomLensControl = interfaceProvider.getOlympusPenInterface().getZoomLensControl();
100 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.THETA)
102 this.focusingControl = interfaceProvider.getThetaInterface().getFocusingControl();
103 this.captureControl = interfaceProvider.getThetaInterface().getCaptureControl();
104 this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider(); // 要変更
105 this.cameraInformation = interfaceProvider.getThetaInterface().getCameraInformation();
106 this.cameraConnection = interfaceProvider.getThetaInterface().getCameraConnection();
107 this.zoomLensControl = interfaceProvider.getThetaInterface().getZoomLensControl();
109 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.CANON)
111 this.focusingControl = interfaceProvider.getCanonInterface().getFocusingControl();
112 this.captureControl = interfaceProvider.getCanonInterface().getCaptureControl();
113 this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider(); // 要変更
114 this.cameraInformation = interfaceProvider.getCanonInterface().getCameraInformation();
115 this.cameraConnection = interfaceProvider.getCanonInterface().getCameraConnection();
116 this.zoomLensControl = interfaceProvider.getCanonInterface().getZoomLensControl();
118 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.NIKON)
120 this.focusingControl = interfaceProvider.getNikonInterface().getFocusingControl();
121 this.captureControl = interfaceProvider.getNikonInterface().getCaptureControl();
122 this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider(); // 要変更
123 this.cameraInformation = interfaceProvider.getNikonInterface().getCameraInformation();
124 this.cameraConnection = interfaceProvider.getNikonInterface().getCameraConnection();
125 this.zoomLensControl = interfaceProvider.getNikonInterface().getZoomLensControl();
127 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
129 this.focusingControl = interfaceProvider.getOlympusInterface().getFocusingControl();
130 this.captureControl = interfaceProvider.getOlympusInterface().getCaptureControl();
131 this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider();
132 this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
133 this.cameraConnection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
134 this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
137 this.dialogKicker = dialogKicker;
145 public void onClick(View view)
147 int id = view.getId();
148 //Log.v(TAG, "onClick() : " + id);
153 case R.id.show_hide_grid_button:
155 statusNotify.toggleShowGridFrame();
156 statusViewDrawer.updateGridIcon();
159 case R.id.show_preference_button:
161 changeScene.changeSceneToConfiguration();
164 case R.id.camera_property_settings_button:
166 changeScene.changeSceneToCameraPropertyList();
169 case R.id.connect_disconnect_button:
170 // カメラと接続・切断のボタンが押された
171 changeScene.changeCameraConnection();
174 case R.id.shutter_button:
175 // シャッターボタンが押された (撮影)
176 pushedShutterButton();
179 case R.id.focusing_button:
180 // AF と MFの切り替えボタンが押された
181 changeFocusingMode();
184 case R.id.live_view_scale_button:
186 statusViewDrawer.updateLiveViewScale(true);
189 case R.id.show_favorite_settings_button:
190 // お気に入り設定のダイアログを表示する
191 showFavoriteDialog();
194 case R.id.btn_zoomin:
198 case R.id.btn_zoomout:
203 case R.id.focus_indicator:
204 // フォーカスインジケータをクリックした
209 Log.v(TAG, "onClick() : " + id);
219 private void actionZoomin()
221 Log.v(TAG, "actionZoomin()");
225 if (zoomLensControl.canZoom())
227 zoomLensControl.driveZoomLens(true);
236 private void actionZoomout()
238 Log.v(TAG, "actionZoomout()");
242 if (zoomLensControl.canZoom())
244 zoomLensControl.driveZoomLens(false);
261 private void pushedShutterButton()
263 Log.v(TAG, "pushedShutterButton()");
266 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
268 if (!preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_ONLY_LIVE_VIEW, false))
271 captureControl.doCapture(0);
273 if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
276 statusNotify.takePicture();
289 private void changeFocusingMode()
291 if ((propertyProvider == null)||(cameraInformation == null))
293 Log.v(TAG, "changeFocusingMode() : OBJECT IS NULL.");
298 boolean isManualFocus = cameraInformation.isManualFocus();
301 // AF ⇒ MF時には、オートフォーカスのロックを解除する
302 focusingControl.unlockAutoFocus();
304 String value = (isManualFocus) ? IOlyCameraProperty.STILL_AF : IOlyCameraProperty.STILL_MF;
305 propertyProvider.setCameraPropertyValue(IOlyCameraProperty.FOCUS_STILL, value);
317 private void actionFocusButton()
322 if (focusingControl != null)
324 boolean isHalfPress = !statusViewDrawer.isFocusLocked();
325 focusingControl.halfPressShutter(isHalfPress);
326 Log.v(TAG, " actionFocusButton() : isHalfPress " + isHalfPress);
339 private void showFavoriteDialog()
341 Log.v(TAG, "showFavoriteDialog()");
344 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.FUJI_X)
346 // FUJI X Seriesの場合は、カメラ状態を表示するダイアログを表示する
347 if (cameraConnection.getConnectionStatus() == ICameraConnection.CameraConnectionStatus.CONNECTED)
349 dialogKicker.showCameraStatusDialog();
353 else if (interfaceProvider.getCammeraConnectionMethod() != ICameraConnection.CameraConnectionMethod.OPC)
355 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
356 Toast.makeText(context, context.getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
360 if (cameraConnection.getConnectionStatus() == ICameraConnection.CameraConnectionStatus.CONNECTED)
362 // お気に入り設定のダイアログを表示する
363 dialogKicker.showFavoriteSettingDialog();
377 public boolean onTouch(View view, MotionEvent motionEvent)
379 int id = view.getId();
380 if (focusingControl == null)
382 Log.v(TAG, "focusingControl is NULL.");
385 //Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
386 return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));
394 public boolean onKey(View view, int keyCode, @NonNull KeyEvent keyEvent)
396 Log.v(TAG, "onKey() : " + keyCode);
399 if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN)&&
400 ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
402 pushedShutterButton();