OSDN Git Service

e17480209058d7a894a0738f29a31d1ebd34ca77
[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.olympus.IOlympusInterfaceProvider;
14 import net.osdn.gokigen.a01d.camera.olympus.operation.ICaptureControl;
15 import net.osdn.gokigen.a01d.camera.olympus.operation.IFocusingControl;
16 import net.osdn.gokigen.a01d.camera.olympus.wrapper.ICameraInformation;
17 import net.osdn.gokigen.a01d.camera.ICameraConnection;
18 import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraProperty;
19 import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraPropertyProvider;
20 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
21
22 /**
23  *
24  *
25  */
26 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener
27 {
28     private final String TAG = toString();
29     private final Context context;
30     private final ILiveImageStatusNotify statusNotify;
31     private final IStatusViewDrawer statusViewDrawer;
32     private final IChangeScene changeScene;
33     private final IFocusingControl focusingControl;
34     private final ICaptureControl captureControl;
35     private final IOlyCameraPropertyProvider propertyProvider;
36     private final ICameraInformation cameraInformation;
37     private final ICameraConnection cameraConnection;
38     private final IFavoriteSettingDialogKicker dialogKicker;
39
40     LiveViewClickTouchListener(Context context, ILiveImageStatusNotify imageStatusNotify, IStatusViewDrawer statusView, IChangeScene changeScene, IOlympusInterfaceProvider interfaceProvider, IFavoriteSettingDialogKicker dialogKicker)
41     {
42         this.context = context;
43         this.statusNotify = imageStatusNotify;
44         this.statusViewDrawer = statusView;
45         this.changeScene = changeScene;
46         this.focusingControl = interfaceProvider.getFocusingControl();
47         this.captureControl = interfaceProvider.getCaptureControl();
48         this.propertyProvider = interfaceProvider.getCameraPropertyProvider();
49         this.cameraInformation = interfaceProvider.getCameraInformation();
50         this.cameraConnection = interfaceProvider.getOlyCameraConnection();
51         this.dialogKicker = dialogKicker;
52     }
53
54     /**
55      *   オブジェクトをクリックする処理
56      *
57      */
58     @Override
59     public void onClick(View view)
60     {
61         int id = view.getId();
62         //Log.v(TAG, "onClick() : " + id);
63         try
64         {
65             switch (id)
66             {
67                 case R.id.show_hide_grid_button:
68                     // グリッドの ON/OFF
69                     statusNotify.toggleShowGridFrame();
70                     statusViewDrawer.updateGridIcon();
71                     break;
72
73                 case R.id.show_preference_button:
74                     // カメラの設定
75                     changeScene.changeSceneToConfiguration();
76                     break;
77
78                 case R.id.camera_property_settings_button:
79                     // カメラのプロパティ設定
80                     changeScene.changeSceneToCameraPropertyList();
81                     break;
82
83                 case R.id.connect_disconnect_button:
84                     // カメラと接続・切断のボタンが押された
85                     changeScene.changeCameraConnection();
86                     break;
87
88                 case R.id.shutter_button:
89                     // シャッターボタンが押された (撮影)
90                     pushedShutterButton();
91                     break;
92
93                 case R.id.focusing_button:
94                     // AF と MFの切り替えボタンが押された
95                     changeFocusingMode();
96                     break;
97
98                 case R.id.live_view_scale_button:
99                     //  ライブビューの倍率を更新する
100                     statusViewDrawer.updateLiveViewScale(true);
101                     break;
102
103                 case R.id.show_favorite_settings_button:
104                     // お気に入り設定のダイアログを表示する
105                     showFavoriteDialog();
106                     break;
107
108                 default:
109                     Log.v(TAG, "onClick() : " + id);
110                     break;
111             }
112         }
113         catch (Exception e)
114         {
115             e.printStackTrace();
116         }
117     }
118
119     /**
120      *   シャッターボタンが押された時の処理
121      *
122      *
123      */
124     private void pushedShutterButton()
125     {
126         Log.v(TAG, "pushedShutterButton()");
127         try
128         {
129             // カメラで撮影する
130             captureControl.doCapture(0);
131
132             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
133             if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
134             {
135                 // ライブビュー画像も保管する
136                 statusNotify.takePicture();
137             }
138         }
139         catch (Exception e)
140         {
141             e.printStackTrace();
142         }
143     }
144
145     /**
146      *   AF/MFの切り替えを行う
147      *
148      */
149     private void changeFocusingMode()
150     {
151         if ((propertyProvider == null)||(cameraInformation == null))
152         {
153             Log.v(TAG, "changeFocusingMode() : OBJECT IS NULL.");
154             return;
155         }
156         try
157         {
158             boolean isManualFocus = cameraInformation.isManualFocus();
159             if (!isManualFocus)
160             {
161                 // AF ⇒ MF時には、オートフォーカスのロックを解除する
162                 focusingControl.unlockAutoFocus();
163             }
164             String value = (isManualFocus) ? IOlyCameraProperty.STILL_AF :  IOlyCameraProperty.STILL_MF;
165             propertyProvider.setCameraPropertyValue(IOlyCameraProperty.FOCUS_STILL, value);
166         }
167         catch (Exception e)
168         {
169             e.printStackTrace();
170         }
171     }
172
173     /**
174      *   お気に入り設定ダイアログの表示
175      *
176      */
177     private void showFavoriteDialog()
178     {
179         Log.v(TAG, "showFavoriteDialog()");
180         try
181         {
182             if (!useOlympusCamera())
183             {
184                 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
185                 Toast.makeText(context, context.getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
186                 return;
187             }
188
189             if (cameraConnection.getConnectionStatus() == ICameraConnection.CameraConnectionStatus.CONNECTED)
190             {
191                 //  お気に入り設定のダイアログを表示する
192                 dialogKicker.showFavoriteSettingDialog();
193             }
194         }
195         catch (Exception e)
196         {
197             e.printStackTrace();
198         }
199     }
200
201     /**
202      *   オブジェクトをタッチする処理
203      *
204      */
205     @Override
206     public boolean onTouch(View view, MotionEvent motionEvent)
207     {
208         int id = view.getId();
209         //Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
210         return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));
211     }
212
213     /**
214      *   OPCカメラを使用するかどうか
215      *
216      * @return  true : OPCカメラ /  false : OPCカメラではない
217      */
218     private boolean useOlympusCamera()
219     {
220         boolean ret = true;
221         try
222         {
223             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
224             String connectionMethod = preferences.getString(IPreferencePropertyAccessor.CONNECTION_METHOD, "OPC");
225             ret = connectionMethod.contains("OPC");
226         }
227         catch (Exception e)
228         {
229             e.printStackTrace();
230         }
231         return (ret);
232     }
233
234
235 }