OSDN Git Service

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