OSDN Git Service

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