OSDN Git Service

18ba1c88f53e434f79addb730f8cd0c600a3c97b
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / liveview / LiveViewClickTouchListener.java
1 package net.osdn.gokigen.gr2control.liveview;
2
3 import android.app.Activity;
4 import android.content.SharedPreferences;
5 import android.util.Log;
6 import android.view.MotionEvent;
7 import android.view.View;
8
9 import net.osdn.gokigen.gr2control.R;
10 import net.osdn.gokigen.gr2control.camera.ICameraButtonControl;
11 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
12 import net.osdn.gokigen.gr2control.camera.ICaptureControl;
13 import net.osdn.gokigen.gr2control.camera.IFocusingControl;
14 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
15 import net.osdn.gokigen.gr2control.camera.IZoomLensControl;
16 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
17 import net.osdn.gokigen.gr2control.scene.ConfirmationDialog;
18 import net.osdn.gokigen.gr2control.scene.IChangeScene;
19
20 import androidx.annotation.NonNull;
21 import androidx.preference.PreferenceManager;
22
23 /**
24  *
25  *
26  */
27 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener
28 {
29     private final String TAG = toString();
30     private final Activity context;
31     private final ILiveImageStatusNotify statusNotify;
32     private final IStatusViewDrawer statusViewDrawer;
33     private final IChangeScene changeScene;
34     private final IInterfaceProvider interfaceProvider;
35     private final IFocusingControl focusingControl;
36     private final ICaptureControl captureControl;
37     //private final IOlyCameraPropertyProvider propertyProvider;
38     //private final ICameraInformation cameraInformation;
39     private final ICameraConnection cameraConnection;
40     private final IFavoriteSettingDialogKicker dialogKicker;
41     private final IZoomLensControl zoomLensControl;
42
43     LiveViewClickTouchListener(@NonNull Activity context, @NonNull ILiveImageStatusNotify imageStatusNotify, @NonNull IStatusViewDrawer statusView, @NonNull IChangeScene changeScene, @NonNull IInterfaceProvider interfaceProvider, @NonNull IFavoriteSettingDialogKicker dialogKicker)
44     {
45         this.context = context;
46         this.statusNotify = imageStatusNotify;
47         this.statusViewDrawer = statusView;
48         this.changeScene = changeScene;
49         this.interfaceProvider = interfaceProvider;
50
51         this.focusingControl = interfaceProvider.getFocusingControl();
52         this.captureControl = interfaceProvider.getCaptureControl();
53         this.cameraConnection = interfaceProvider.getCameraConnection();
54         this.zoomLensControl = interfaceProvider.getZoomLensControl();
55
56         this.dialogKicker = dialogKicker;
57     }
58
59     /**
60      *   オブジェクトをクリックする処理
61      *
62      */
63     @Override
64     public void onClick(View view)
65     {
66         int id = view.getId();
67         //Log.v(TAG, "onClick() : " + id);
68         try
69         {
70             switch (id)
71             {
72                 case R.id.hideControlPanelTextView:
73                     // 制御パネルを隠す
74                     showHideControlPanel(false);
75                     break;
76
77                 case R.id.showControlPanelTextView:
78                     // 制御パネルを表示する
79                     showHideControlPanel(true);
80                     break;
81
82                 case R.id.showKeyPanelImageView:
83                     // キーパネルを表示する
84                     showHideKeyPanel(true);
85                     break;
86
87                 case R.id.hideKeyPanelTextView:
88                     // キーパネルを隠す
89                     showHideKeyPanel(false);
90                     break;
91
92                 case R.id.connect_disconnect_button:
93                     // カメラと接続・切断のボタンが押された
94                     changeScene.changeCameraConnection();
95                     break;
96
97                 case R.id.shutter_button:
98                     // シャッターボタンが押された (撮影)
99                     pushedShutterButton();
100                     break;
101
102                 case R.id.focusUnlockImageView:
103                     // フォーカスアンロックボタンが押された
104                     pushedFocusUnlock();
105                     break;
106
107                 case R.id.show_images_button:
108                     // 画像一覧表示ボタンが押された...画像一覧画面を開く
109                     changeScene.changeScenceToImageList();
110                     break;
111
112                 case R.id.camera_power_off_button:
113                     // 電源ボタンが押された...終了してよいか確認して、終了する
114                     confirmExitApplication();
115                     break;
116
117                 case R.id.show_preference_button:
118                     // カメラの設定
119                     changeScene.changeSceneToConfiguration();
120                     break;
121
122                 case R.id.show_hide_grid_button:
123                     // グリッドの ON/OFF
124                     statusNotify.toggleShowGridFrame();
125                     statusViewDrawer.updateGridIcon();
126                     break;
127                 case R.id.zoom_in_button:
128                     // ズームインのボタンが押された
129                     actionZoomin();
130                     break;
131                 case R.id.zoom_out_button:
132                     // ズームアウトのボタンが押された
133                     actionZoomout();
134                     break;
135                 case R.id.specialButtonImageView:
136                     // スペシャルボタンが押された
137                     pushedSpecialButton();
138                     break;
139 /*
140                 case R.id.camera_property_settings_button:
141                     // カメラのプロパティ設定
142                     changeScene.changeSceneToCameraPropertyList();
143                     break;
144
145                 case R.id.focusing_button:
146                     // AF と MFの切り替えボタンが押された
147                     changeFocusingMode();
148                     break;
149
150                 case R.id.live_view_scale_button:
151                     //  ライブビューの倍率を更新する
152                     statusViewDrawer.updateLiveViewScale(true);
153                     break;
154
155                 case R.id.show_favorite_settings_button:
156                     // お気に入り設定のダイアログを表示する
157                     showFavoriteDialog();
158                     break;
159 */
160                 default:
161                     Log.v(TAG, "onClick() : " + id);
162                     break;
163             }
164         }
165         catch (Exception e)
166         {
167             e.printStackTrace();
168         }
169     }
170
171     /**
172      *   コントロールパネルの表示・非表示
173      *
174      */
175     private void showHideControlPanel(boolean isShow)
176     {
177         try
178         {
179             View target = context.findViewById(R.id.controlPanelLayout);
180             View target2 = context.findViewById(R.id.showControlPanelTextView);
181             if (target != null)
182             {
183                 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
184                 target.invalidate();
185                 if (target2 != null)
186                 {
187                     target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
188                     target2.invalidate();
189                 }
190             }
191         }
192         catch (Exception e)
193         {
194             e.printStackTrace();
195         }
196     }
197
198     /**
199      *   キー操作パネルの表示・非表示
200      *
201      */
202     private void showHideKeyPanel(boolean isShow)
203     {
204         try
205         {
206             View target = context.findViewById(R.id.keyPanelLayout);
207             View target2 = context.findViewById(R.id.showKeyPanelImageView);
208             if (target != null)
209             {
210                 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
211                 target.invalidate();
212                 if (target2 != null)
213                 {
214                     target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
215                     target2.invalidate();
216                 }
217             }
218         }
219         catch (Exception e)
220         {
221             e.printStackTrace();
222         }
223     }
224
225     private void confirmExitApplication()
226     {
227         try
228         {
229             // 確認ダイアログの生成と表示
230             ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
231             dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, new ConfirmationDialog.Callback() {
232                 @Override
233                 public void confirm()
234                 {
235                     changeScene.exitApplication();
236                 }
237             });
238         }
239         catch (Exception e)
240         {
241             e.printStackTrace();
242         }
243     }
244
245     private void actionZoomin()
246     {
247         Log.v(TAG, "actionZoomin()");
248         try
249         {
250             // ズーム可能な場合、ズームインする
251             if (zoomLensControl.canZoom())
252             {
253                 zoomLensControl.driveZoomLens(true);
254             }
255         }
256         catch (Exception e)
257         {
258             e.printStackTrace();
259         }
260     }
261
262     private void actionZoomout()
263     {
264         Log.v(TAG, "actionZoomout()");
265         try
266         {
267             // ズーム可能な場合、ズームアウトする
268             if (zoomLensControl.canZoom())
269             {
270                 zoomLensControl.driveZoomLens(false);
271             }
272         }
273         catch (Exception e)
274         {
275             e.printStackTrace();
276         }
277     }
278
279
280     /**
281      *   シャッターボタンが押された時の処理
282      *
283      *
284      */
285     private void pushedShutterButton()
286     {
287         Log.v(TAG, "pushedShutterButton()");
288         try
289         {
290             // カメラで撮影する
291             captureControl.doCapture(0);
292
293             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
294             if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
295             {
296                 // ライブビュー画像も保管する
297                 statusNotify.takePicture();
298             }
299         }
300         catch (Exception e)
301         {
302             e.printStackTrace();
303         }
304     }
305
306     /**
307      *   フォーカスアンロックボタンが押された時の処理
308      *
309      */
310     private void pushedFocusUnlock()
311     {
312         Log.v(TAG, "pushedFocusUnlock()");
313         try
314         {
315             // フォーカスアンロックする
316             focusingControl.unlockAutoFocus();
317         }
318         catch (Exception e)
319         {
320             e.printStackTrace();
321         }
322     }
323
324     /**
325      *   スペシャルボタンが押された時の処理
326      *
327      */
328     private void pushedSpecialButton()
329     {
330         showFavoriteDialog();
331     }
332
333     /**
334      *   お気に入り設定ダイアログの表示
335      *
336      */
337     private void showFavoriteDialog()
338     {
339         Log.v(TAG, "showFavoriteDialog()");
340         try
341         {
342             if (cameraConnection.getConnectionStatus() != ICameraConnection.CameraConnectionStatus.CONNECTED)
343             {
344                 // カメラと接続されていない時には、何もしない
345                 return;
346             }
347
348             if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
349             {
350                 //  OPCカメラの場合には、お気に入り設定のダイアログを表示する
351                 dialogKicker.showFavoriteSettingDialog();
352                 return;
353             }
354
355
356             ICameraButtonControl btnCtl = interfaceProvider.getButtonControl();
357             if (btnCtl != null)
358             {
359                 // 'GREEN' ボタンが押されたこととする
360                 btnCtl.pushedButton(ICameraButtonControl.SPECIAL_GREEN_BUTTON, false);
361             }
362         }
363         catch (Exception e)
364         {
365             e.printStackTrace();
366         }
367     }
368
369     /**
370      *   オブジェクトをタッチする処理
371      *
372      */
373     @Override
374     public boolean onTouch(View view, MotionEvent motionEvent)
375     {
376         int id = view.getId();
377         if (focusingControl == null)
378         {
379             Log.v(TAG, "focusingControl is NULL.");
380             view.performClick();  // ダミー処理...
381             return (false);
382         }
383         Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
384         return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));
385     }
386 }