1 package net.osdn.gokigen.gr2control.liveview;
3 import android.app.Activity;
4 import android.content.SharedPreferences;
5 import android.util.Log;
6 import android.view.MotionEvent;
7 import android.view.View;
9 import net.osdn.gokigen.gr2control.R;
10 import net.osdn.gokigen.gr2control.camera.ICameraButtonControl;
11 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
12 import net.osdn.gokigen.gr2control.camera.ICaptureControl;
13 import net.osdn.gokigen.gr2control.camera.IFocusingControl;
14 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
15 import net.osdn.gokigen.gr2control.camera.IZoomLensControl;
16 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
17 import net.osdn.gokigen.gr2control.scene.ConfirmationDialog;
18 import net.osdn.gokigen.gr2control.scene.IChangeScene;
20 import androidx.annotation.NonNull;
21 import androidx.preference.PreferenceManager;
27 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener
29 private final String TAG = toString();
30 private final Activity 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;
43 LiveViewClickTouchListener(@NonNull Activity context, @NonNull ILiveImageStatusNotify imageStatusNotify, @NonNull IStatusViewDrawer statusView, @NonNull IChangeScene changeScene, @NonNull IInterfaceProvider interfaceProvider, @NonNull IFavoriteSettingDialogKicker dialogKicker)
45 this.context = context;
46 this.statusNotify = imageStatusNotify;
47 this.statusViewDrawer = statusView;
48 this.changeScene = changeScene;
49 this.interfaceProvider = interfaceProvider;
51 this.focusingControl = interfaceProvider.getFocusingControl();
52 this.captureControl = interfaceProvider.getCaptureControl();
53 this.cameraConnection = interfaceProvider.getCameraConnection();
54 this.zoomLensControl = interfaceProvider.getZoomLensControl();
56 this.dialogKicker = dialogKicker;
64 public void onClick(View view)
66 int id = view.getId();
67 //Log.v(TAG, "onClick() : " + id);
72 case R.id.hideControlPanelTextView:
74 showHideControlPanel(false);
77 case R.id.showControlPanelTextView:
79 showHideControlPanel(true);
82 case R.id.showKeyPanelImageView:
84 showHideKeyPanel(true);
87 case R.id.hideKeyPanelTextView:
89 showHideKeyPanel(false);
92 case R.id.connect_disconnect_button:
94 changeScene.changeCameraConnection();
97 case R.id.shutter_button:
99 pushedShutterButton();
102 case R.id.focusUnlockImageView:
103 // フォーカスアンロックボタンが押された
107 case R.id.show_images_button:
108 // 画像一覧表示ボタンが押された...画像一覧画面を開く
109 changeScene.changeScenceToImageList();
112 case R.id.camera_power_off_button:
113 // 電源ボタンが押された...終了してよいか確認して、終了する
114 confirmExitApplication();
117 case R.id.show_preference_button:
119 changeScene.changeSceneToConfiguration();
122 case R.id.show_hide_grid_button:
124 statusNotify.toggleShowGridFrame();
125 statusViewDrawer.updateGridIcon();
127 case R.id.zoom_in_button:
131 case R.id.zoom_out_button:
135 case R.id.specialButtonImageView:
137 pushedSpecialButton();
140 case R.id.camera_property_settings_button:
142 changeScene.changeSceneToCameraPropertyList();
145 case R.id.focusing_button:
146 // AF と MFの切り替えボタンが押された
147 changeFocusingMode();
150 case R.id.live_view_scale_button:
152 statusViewDrawer.updateLiveViewScale(true);
155 case R.id.show_favorite_settings_button:
156 // お気に入り設定のダイアログを表示する
157 showFavoriteDialog();
161 Log.v(TAG, "onClick() : " + id);
175 private void showHideControlPanel(boolean isShow)
179 View target = context.findViewById(R.id.controlPanelLayout);
180 View target2 = context.findViewById(R.id.showControlPanelTextView);
183 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
187 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
188 target2.invalidate();
202 private void showHideKeyPanel(boolean isShow)
206 View target = context.findViewById(R.id.keyPanelLayout);
207 View target2 = context.findViewById(R.id.showKeyPanelImageView);
210 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
214 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
215 target2.invalidate();
225 private void confirmExitApplication()
230 ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
231 dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, new ConfirmationDialog.Callback() {
233 public void confirm()
235 changeScene.exitApplication();
245 private void actionZoomin()
247 Log.v(TAG, "actionZoomin()");
251 if (zoomLensControl.canZoom())
253 zoomLensControl.driveZoomLens(true);
262 private void actionZoomout()
264 Log.v(TAG, "actionZoomout()");
268 if (zoomLensControl.canZoom())
270 zoomLensControl.driveZoomLens(false);
285 private void pushedShutterButton()
287 Log.v(TAG, "pushedShutterButton()");
291 captureControl.doCapture(0);
293 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
294 if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
297 statusNotify.takePicture();
307 * フォーカスアンロックボタンが押された時の処理
310 private void pushedFocusUnlock()
312 Log.v(TAG, "pushedFocusUnlock()");
316 focusingControl.unlockAutoFocus();
328 private void pushedSpecialButton()
330 showFavoriteDialog();
337 private void showFavoriteDialog()
339 Log.v(TAG, "showFavoriteDialog()");
342 if (cameraConnection.getConnectionStatus() != ICameraConnection.CameraConnectionStatus.CONNECTED)
344 // カメラと接続されていない時には、何もしない
348 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
350 // OPCカメラの場合には、お気に入り設定のダイアログを表示する
351 dialogKicker.showFavoriteSettingDialog();
356 ICameraButtonControl btnCtl = interfaceProvider.getButtonControl();
359 // 'GREEN' ボタンが押されたこととする
360 btnCtl.pushedButton(ICameraButtonControl.SPECIAL_GREEN_BUTTON, false);
374 public boolean onTouch(View view, MotionEvent motionEvent)
376 int id = view.getId();
377 if (focusingControl == null)
379 Log.v(TAG, "focusingControl is NULL.");
380 view.performClick(); // ダミー処理...
383 Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
384 return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));