1 package net.osdn.gokigen.gr2control.liveview;
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;
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;
28 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener
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;
44 LiveViewClickTouchListener(Activity context, ILiveImageStatusNotify imageStatusNotify, IStatusViewDrawer statusView, IChangeScene changeScene, IInterfaceProvider interfaceProvider, IFavoriteSettingDialogKicker dialogKicker)
46 this.context = context;
47 this.statusNotify = imageStatusNotify;
48 //this.statusViewDrawer = statusView;
49 this.changeScene = changeScene;
50 this.interfaceProvider = interfaceProvider;
52 //ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
53 //if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
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();
63 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
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();
72 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
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();
82 this.dialogKicker = dialogKicker;
90 public void onClick(View view)
92 int id = view.getId();
93 //Log.v(TAG, "onClick() : " + id);
98 case R.id.hideControlPanelTextView:
100 showHideControlPanel(false);
103 case R.id.showControlPanelTextView:
105 showHideControlPanel(true);
108 case R.id.showKeyPanelImageView:
110 showHideKeyPanel(true);
113 case R.id.hideKeyPanelTextView:
115 showHideKeyPanel(false);
118 case R.id.connect_disconnect_button:
119 // カメラと接続・切断のボタンが押された
120 changeScene.changeCameraConnection();
123 case R.id.shutter_button:
124 // シャッターボタンが押された (撮影)
125 pushedShutterButton();
128 case R.id.focusUnlockImageView:
129 // フォーカスアンロックボタンが押された
133 case R.id.show_images_button:
134 // 画像一覧表示ボタンが押された...画像一覧画面を開く
135 changeScene.changeScenceToImageList();
138 case R.id.camera_power_off_button:
139 // 電源ボタンが押された...終了してよいか確認して、終了する
140 confirmExitApplication();
143 case R.id.show_preference_button:
145 changeScene.changeSceneToConfiguration();
150 case R.id.show_hide_grid_button:
152 statusNotify.toggleShowGridFrame();
153 statusViewDrawer.updateGridIcon();
156 case R.id.camera_property_settings_button:
158 changeScene.changeSceneToCameraPropertyList();
161 case R.id.focusing_button:
162 // AF と MFの切り替えボタンが押された
163 changeFocusingMode();
166 case R.id.live_view_scale_button:
168 statusViewDrawer.updateLiveViewScale(true);
171 case R.id.show_favorite_settings_button:
172 // お気に入り設定のダイアログを表示する
173 showFavoriteDialog();
176 case R.id.btn_zoomin:
180 case R.id.btn_zoomout:
186 Log.v(TAG, "onClick() : " + id);
200 private void showHideControlPanel(boolean isShow)
204 View target = context.findViewById(R.id.controlPanelLayout);
205 View target2 = context.findViewById(R.id.showControlPanelTextView);
208 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
212 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
213 target2.invalidate();
227 private void showHideKeyPanel(boolean isShow)
231 View target = context.findViewById(R.id.keyPanelLayout);
232 View target2 = context.findViewById(R.id.showKeyPanelImageView);
235 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
239 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
240 target2.invalidate();
250 private void confirmExitApplication()
255 ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
256 dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, new ConfirmationDialog.Callback() {
258 public void confirm()
260 changeScene.exitApplication();
270 private void actionZoomin()
272 Log.v(TAG, "actionZoomin()");
276 if (zoomLensControl.canZoom())
278 zoomLensControl.driveZoomLens(true);
287 private void actionZoomout()
289 Log.v(TAG, "actionZoomout()");
293 if (zoomLensControl.canZoom())
295 zoomLensControl.driveZoomLens(false);
310 private void pushedShutterButton()
312 Log.v(TAG, "pushedShutterButton()");
316 captureControl.doCapture(0);
318 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
319 if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
322 statusNotify.takePicture();
332 * フォーカスアンロックボタンが押された時の処理
335 private void pushedFocusUnlock()
337 Log.v(TAG, "pushedFocusUnlock()");
341 focusingControl.unlockAutoFocus();
353 private void showFavoriteDialog()
355 Log.v(TAG, "showFavoriteDialog()");
358 if (interfaceProvider.getCammeraConnectionMethod() != ICameraConnection.CameraConnectionMethod.OPC)
360 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
361 Toast.makeText(context, context.getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
365 if (cameraConnection.getConnectionStatus() == ICameraConnection.CameraConnectionStatus.CONNECTED)
367 // お気に入り設定のダイアログを表示する
368 dialogKicker.showFavoriteSettingDialog();
382 public boolean onTouch(View view, MotionEvent motionEvent)
384 int id = view.getId();
385 if (focusingControl == null)
387 Log.v(TAG, "focusingControl is NULL.");
388 view.performClick(); // ダミー処理...
391 Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
392 return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));