OSDN Git Service

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