OSDN Git Service

FUJI X対応準備。
[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.MotionEvent;
7 import android.view.View;
8 import android.widget.Toast;
9
10 import net.osdn.gokigen.a01d.IChangeScene;
11 import net.osdn.gokigen.a01d.R;
12 import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
13 import net.osdn.gokigen.a01d.camera.ICaptureControl;
14 import net.osdn.gokigen.a01d.camera.IFocusingControl;
15 import net.osdn.gokigen.a01d.camera.ICameraInformation;
16 import net.osdn.gokigen.a01d.camera.ICameraConnection;
17 import net.osdn.gokigen.a01d.camera.IZoomLensControl;
18 import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraProperty;
19 import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraPropertyProvider;
20 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
21
22 import androidx.preference.PreferenceManager;
23
24 /**
25  *
26  *
27  */
28 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener
29 {
30     private final String TAG = toString();
31     private final Context context;
32     private final ILiveImageStatusNotify statusNotify;
33     private final IStatusViewDrawer statusViewDrawer;
34     private final IChangeScene changeScene;
35     private final IInterfaceProvider interfaceProvider;
36     private final IFocusingControl focusingControl;
37     private final ICaptureControl captureControl;
38     private final IOlyCameraPropertyProvider propertyProvider;
39     private final ICameraInformation cameraInformation;
40     private final ICameraConnection cameraConnection;
41     private final IFavoriteSettingDialogKicker dialogKicker;
42     private final IZoomLensControl zoomLensControl;
43
44     LiveViewClickTouchListener(Context context, ILiveImageStatusNotify imageStatusNotify, IStatusViewDrawer statusView, IChangeScene changeScene, IInterfaceProvider interfaceProvider, IFavoriteSettingDialogKicker dialogKicker)
45     {
46         this.context = context;
47         this.statusNotify = imageStatusNotify;
48         this.statusViewDrawer = statusView;
49         this.changeScene = changeScene;
50         this.interfaceProvider = interfaceProvider;
51
52         ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
53         if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
54         {
55             this.focusingControl = interfaceProvider.getRicohGr2Infterface().getFocusingControl();
56             this.captureControl = interfaceProvider.getRicohGr2Infterface().getCaptureControl();
57             this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider();  // 要変更
58             this.cameraInformation = interfaceProvider.getRicohGr2Infterface().getCameraInformation();
59             this.cameraConnection = interfaceProvider.getRicohGr2Infterface().getRicohGr2CameraConnection();
60             this.zoomLensControl = interfaceProvider.getRicohGr2Infterface().getZoomLensControl();
61         }
62         else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
63         {
64             this.focusingControl = interfaceProvider.getSonyInterface().getFocusingControl();
65             this.captureControl = interfaceProvider.getSonyInterface().getCaptureControl();
66             this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider();  // 要変更
67             this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
68             this.cameraConnection = interfaceProvider.getSonyInterface().getSonyCameraConnection();
69             this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
70         }
71         else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
72         {
73             // TODO: FUJI_X に変更
74             this.focusingControl = interfaceProvider.getSonyInterface().getFocusingControl();
75             this.captureControl = interfaceProvider.getSonyInterface().getCaptureControl();
76             this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider();  // 要変更
77             this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
78             this.cameraConnection = interfaceProvider.getSonyInterface().getSonyCameraConnection();
79             this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
80         }
81         else  // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
82         {
83             this.focusingControl = interfaceProvider.getOlympusInterface().getFocusingControl();
84             this.captureControl = interfaceProvider.getOlympusInterface().getCaptureControl();
85             this.propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider();
86             this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
87             this.cameraConnection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
88             this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
89         }
90
91         this.dialogKicker = dialogKicker;
92     }
93
94     /**
95      *   オブジェクトをクリックする処理
96      *
97      */
98     @Override
99     public void onClick(View view)
100     {
101         int id = view.getId();
102         //Log.v(TAG, "onClick() : " + id);
103         try
104         {
105             switch (id)
106             {
107                 case R.id.show_hide_grid_button:
108                     // グリッドの ON/OFF
109                     statusNotify.toggleShowGridFrame();
110                     statusViewDrawer.updateGridIcon();
111                     break;
112
113                 case R.id.show_preference_button:
114                     // カメラの設定
115                     changeScene.changeSceneToConfiguration();
116                     break;
117
118                 case R.id.camera_property_settings_button:
119                     // カメラのプロパティ設定
120                     changeScene.changeSceneToCameraPropertyList();
121                     break;
122
123                 case R.id.connect_disconnect_button:
124                     // カメラと接続・切断のボタンが押された
125                     changeScene.changeCameraConnection();
126                     break;
127
128                 case R.id.shutter_button:
129                     // シャッターボタンが押された (撮影)
130                     pushedShutterButton();
131                     break;
132
133                 case R.id.focusing_button:
134                     // AF と MFの切り替えボタンが押された
135                     changeFocusingMode();
136                     break;
137
138                 case R.id.live_view_scale_button:
139                     //  ライブビューの倍率を更新する
140                     statusViewDrawer.updateLiveViewScale(true);
141                     break;
142
143                 case R.id.show_favorite_settings_button:
144                     // お気に入り設定のダイアログを表示する
145                     showFavoriteDialog();
146                     break;
147
148                 case R.id.btn_zoomin:
149                     // ズームインのボタンが押された
150                     actionZoomin();
151                     break;
152                 case R.id.btn_zoomout:
153                     // ズームアウトのボタンが押された
154                     actionZoomout();
155                     break;
156
157                 case R.id.focus_indicator:
158                     // フォーカスインジケータをクリックした
159                     actionFocusButton();
160                     break;
161
162                 default:
163                     Log.v(TAG, "onClick() : " + id);
164                     break;
165             }
166         }
167         catch (Exception e)
168         {
169             e.printStackTrace();
170         }
171     }
172
173     private void actionZoomin()
174     {
175         Log.v(TAG, "actionZoomin()");
176         try
177         {
178             // ズーム可能な場合、ズームインする
179             if (zoomLensControl.canZoom())
180             {
181                 zoomLensControl.driveZoomLens(true);
182             }
183         }
184         catch (Exception e)
185         {
186             e.printStackTrace();
187         }
188     }
189
190     private void actionZoomout()
191     {
192         Log.v(TAG, "actionZoomout()");
193         try
194         {
195             // ズーム可能な場合、ズームアウトする
196             if (zoomLensControl.canZoom())
197             {
198                 zoomLensControl.driveZoomLens(false);
199             }
200         }
201         catch (Exception e)
202         {
203             e.printStackTrace();
204         }
205     }
206
207
208
209
210     /**
211      *   シャッターボタンが押された時の処理
212      *
213      *
214      */
215     private void pushedShutterButton()
216     {
217         Log.v(TAG, "pushedShutterButton()");
218         try
219         {
220             // カメラで撮影する
221             captureControl.doCapture(0);
222
223             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
224             if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
225             {
226                 // ライブビュー画像も保管する
227                 statusNotify.takePicture();
228             }
229         }
230         catch (Exception e)
231         {
232             e.printStackTrace();
233         }
234     }
235
236     /**
237      *   AF/MFの切り替えを行う
238      *
239      */
240     private void changeFocusingMode()
241     {
242         if ((propertyProvider == null)||(cameraInformation == null))
243         {
244             Log.v(TAG, "changeFocusingMode() : OBJECT IS NULL.");
245             return;
246         }
247         try
248         {
249             boolean isManualFocus = cameraInformation.isManualFocus();
250             if (!isManualFocus)
251             {
252                 // AF ⇒ MF時には、オートフォーカスのロックを解除する
253                 focusingControl.unlockAutoFocus();
254             }
255             String value = (isManualFocus) ? IOlyCameraProperty.STILL_AF :  IOlyCameraProperty.STILL_MF;
256             propertyProvider.setCameraPropertyValue(IOlyCameraProperty.FOCUS_STILL, value);
257         }
258         catch (Exception e)
259         {
260             e.printStackTrace();
261         }
262     }
263
264     /**
265      *   フォーカスボタンが押されたとき...
266      *
267      */
268     private void actionFocusButton()
269     {
270         try
271         {
272             // シャッターを半押しする
273             if (focusingControl != null)
274             {
275                 boolean isHalfPress = !statusViewDrawer.isFocusLocked();
276                 focusingControl.halfPressShutter(isHalfPress);
277                 Log.v(TAG, " actionFocusButton() : isHalfPress " + isHalfPress);
278             }
279         }
280         catch (Exception e)
281         {
282             e.printStackTrace();
283         }
284     }
285
286     /**
287      *   お気に入り設定ダイアログの表示
288      *
289      */
290     private void showFavoriteDialog()
291     {
292         Log.v(TAG, "showFavoriteDialog()");
293         try
294         {
295             if (interfaceProvider.getCammeraConnectionMethod() != ICameraConnection.CameraConnectionMethod.OPC)
296             {
297                 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
298                 Toast.makeText(context, context.getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
299                 return;
300             }
301
302             if (cameraConnection.getConnectionStatus() == ICameraConnection.CameraConnectionStatus.CONNECTED)
303             {
304                 //  お気に入り設定のダイアログを表示する
305                 dialogKicker.showFavoriteSettingDialog();
306             }
307         }
308         catch (Exception e)
309         {
310             e.printStackTrace();
311         }
312     }
313
314     /**
315      *   オブジェクトをタッチする処理
316      *
317      */
318     @Override
319     public boolean onTouch(View view, MotionEvent motionEvent)
320     {
321         int id = view.getId();
322         if (focusingControl == null)
323         {
324             Log.v(TAG, "focusingControl is NULL.");
325             return (false);
326         }
327         //Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
328         return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));
329     }
330
331 }