OSDN Git Service

4fb5196a614ea51426c942c7f91b03fc0ccac55d
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / liveview / LiveViewClickTouchListener.java
1 package net.osdn.gokigen.a01d.liveview;
2
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;
10
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;
22
23 import androidx.annotation.NonNull;
24 import androidx.preference.PreferenceManager;
25
26 /**
27  *
28  *
29  */
30 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener, View.OnKeyListener
31 {
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;
45
46     LiveViewClickTouchListener(Context context, ILiveImageStatusNotify imageStatusNotify, IStatusViewDrawer statusView, IChangeScene changeScene, IInterfaceProvider interfaceProvider, IDialogKicker dialogKicker)
47     {
48         this.context = context;
49         this.statusNotify = imageStatusNotify;
50         this.statusViewDrawer = statusView;
51         this.changeScene = changeScene;
52         this.interfaceProvider = interfaceProvider;
53
54         ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
55         if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
56         {
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();
63         }
64         else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
65         {
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();
72         }
73         else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
74         {
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();
81         }
82         else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
83         {
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();
90         }
91         else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS)
92         {
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();
99         }
100         else if (connectionMethod == ICameraConnection.CameraConnectionMethod.THETA)
101         {
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();
108         }
109         else if (connectionMethod == ICameraConnection.CameraConnectionMethod.CANON)
110         {
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();
117         }
118         else if (connectionMethod == ICameraConnection.CameraConnectionMethod.NIKON)
119         {
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();
126         }
127         else  // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
128         {
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();
135         }
136
137         this.dialogKicker = dialogKicker;
138     }
139
140     /**
141      *   オブジェクトをクリックする処理
142      *
143      */
144     @Override
145     public void onClick(View view)
146     {
147         int id = view.getId();
148         //Log.v(TAG, "onClick() : " + id);
149         try
150         {
151             switch (id)
152             {
153                 case R.id.show_hide_grid_button:
154                     // グリッドの ON/OFF
155                     statusNotify.toggleShowGridFrame();
156                     statusViewDrawer.updateGridIcon();
157                     break;
158
159                 case R.id.show_preference_button:
160                     // カメラの設定
161                     changeScene.changeSceneToConfiguration();
162                     break;
163
164                 case R.id.camera_property_settings_button:
165                     // カメラのプロパティ設定
166                     changeScene.changeSceneToCameraPropertyList();
167                     break;
168
169                 case R.id.connect_disconnect_button:
170                     // カメラと接続・切断のボタンが押された
171                     changeScene.changeCameraConnection();
172                     break;
173
174                 case R.id.shutter_button:
175                     // シャッターボタンが押された (撮影)
176                     pushedShutterButton();
177                     break;
178
179                 case R.id.focusing_button:
180                     // AF と MFの切り替えボタンが押された
181                     changeFocusingMode();
182                     break;
183
184                 case R.id.live_view_scale_button:
185                     //  ライブビューの倍率を更新する
186                     statusViewDrawer.updateLiveViewScale(true);
187                     break;
188
189                 case R.id.show_favorite_settings_button:
190                     // お気に入り設定のダイアログを表示する
191                     showFavoriteDialog();
192                     break;
193
194                 case R.id.btn_zoomin:
195                     // ズームインのボタンが押された
196                     actionZoomin();
197                     break;
198                 case R.id.btn_zoomout:
199                     // ズームアウトのボタンが押された
200                     actionZoomout();
201                     break;
202
203                 case R.id.focus_indicator:
204                     // フォーカスインジケータをクリックした
205                     actionFocusButton();
206                     break;
207
208                 default:
209                     Log.v(TAG, "onClick() : " + id);
210                     break;
211             }
212         }
213         catch (Exception e)
214         {
215             e.printStackTrace();
216         }
217     }
218
219     private void actionZoomin()
220     {
221         Log.v(TAG, "actionZoomin()");
222         try
223         {
224             // ズーム可能な場合、ズームインする
225             if (zoomLensControl.canZoom())
226             {
227                 zoomLensControl.driveZoomLens(true);
228             }
229         }
230         catch (Exception e)
231         {
232             e.printStackTrace();
233         }
234     }
235
236     private void actionZoomout()
237     {
238         Log.v(TAG, "actionZoomout()");
239         try
240         {
241             // ズーム可能な場合、ズームアウトする
242             if (zoomLensControl.canZoom())
243             {
244                 zoomLensControl.driveZoomLens(false);
245             }
246         }
247         catch (Exception e)
248         {
249             e.printStackTrace();
250         }
251     }
252
253
254
255
256     /**
257      *   シャッターボタンが押された時の処理
258      *
259      *
260      */
261     private void pushedShutterButton()
262     {
263         Log.v(TAG, "pushedShutterButton()");
264         try
265         {
266             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
267
268             if (!preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_ONLY_LIVE_VIEW, false))
269             {
270                 // カメラで撮影する
271                 captureControl.doCapture(0);
272             }
273             if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
274             {
275                 // ライブビュー画像を保管する
276                 statusNotify.takePicture();
277             }
278         }
279         catch (Exception e)
280         {
281             e.printStackTrace();
282         }
283     }
284
285     /**
286      *   AF/MFの切り替えを行う
287      *
288      */
289     private void changeFocusingMode()
290     {
291         if ((propertyProvider == null)||(cameraInformation == null))
292         {
293             Log.v(TAG, "changeFocusingMode() : OBJECT IS NULL.");
294             return;
295         }
296         try
297         {
298             boolean isManualFocus = cameraInformation.isManualFocus();
299             if (!isManualFocus)
300             {
301                 // AF ⇒ MF時には、オートフォーカスのロックを解除する
302                 focusingControl.unlockAutoFocus();
303             }
304             String value = (isManualFocus) ? IOlyCameraProperty.STILL_AF :  IOlyCameraProperty.STILL_MF;
305             propertyProvider.setCameraPropertyValue(IOlyCameraProperty.FOCUS_STILL, value);
306         }
307         catch (Exception e)
308         {
309             e.printStackTrace();
310         }
311     }
312
313     /**
314      *   フォーカスボタンが押されたとき...
315      *
316      */
317     private void actionFocusButton()
318     {
319         try
320         {
321             // シャッターを半押しする
322             if (focusingControl != null)
323             {
324                 boolean isHalfPress = !statusViewDrawer.isFocusLocked();
325                 focusingControl.halfPressShutter(isHalfPress);
326                 Log.v(TAG, " actionFocusButton() : isHalfPress " + isHalfPress);
327             }
328         }
329         catch (Exception e)
330         {
331             e.printStackTrace();
332         }
333     }
334
335     /**
336      *   お気に入り設定ダイアログの表示
337      *
338      */
339     private void showFavoriteDialog()
340     {
341         Log.v(TAG, "showFavoriteDialog()");
342         try
343         {
344             if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.FUJI_X)
345             {
346                 // FUJI X Seriesの場合は、カメラ状態を表示するダイアログを表示する
347                 if (cameraConnection.getConnectionStatus() == ICameraConnection.CameraConnectionStatus.CONNECTED)
348                 {
349                     dialogKicker.showCameraStatusDialog();
350                 }
351                 return;
352             }
353             else if (interfaceProvider.getCammeraConnectionMethod() != ICameraConnection.CameraConnectionMethod.OPC)
354             {
355                 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
356                 Toast.makeText(context, context.getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
357                 return;
358             }
359
360             if (cameraConnection.getConnectionStatus() == ICameraConnection.CameraConnectionStatus.CONNECTED)
361             {
362                 //  お気に入り設定のダイアログを表示する
363                 dialogKicker.showFavoriteSettingDialog();
364             }
365         }
366         catch (Exception e)
367         {
368             e.printStackTrace();
369         }
370     }
371
372     /**
373      *   オブジェクトをタッチする処理
374      *
375      */
376     @Override
377     public boolean onTouch(View view, MotionEvent motionEvent)
378     {
379         int id = view.getId();
380         if (focusingControl == null)
381         {
382             Log.v(TAG, "focusingControl is NULL.");
383             return (false);
384         }
385         //Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
386         return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));
387     }
388
389     /**
390      *   ボタンを押したときの対応
391      *
392      */
393     @Override
394     public boolean onKey(View view, int keyCode, @NonNull KeyEvent keyEvent)
395     {
396         Log.v(TAG, "onKey() : " + keyCode);
397         try
398         {
399             if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN)&&
400                     ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
401             {
402                 pushedShutterButton();
403                 return (true);
404             }
405         }
406         catch (Exception e)
407         {
408             e.printStackTrace();
409         }
410         return (false);
411     }
412 }