OSDN Git Service

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