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.KeyEvent;
7 import android.view.MotionEvent;
8 import android.view.View;
10 import net.osdn.gokigen.gr2control.R;
11 import net.osdn.gokigen.gr2control.camera.ICameraButtonControl;
12 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
13 import net.osdn.gokigen.gr2control.camera.ICaptureControl;
14 import net.osdn.gokigen.gr2control.camera.IFocusingControl;
15 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
16 import net.osdn.gokigen.gr2control.camera.IZoomLensControl;
17 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
18 import net.osdn.gokigen.gr2control.scene.ConfirmationDialog;
19 import net.osdn.gokigen.gr2control.scene.IChangeScene;
21 import androidx.annotation.NonNull;
22 import androidx.preference.PreferenceManager;
28 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener, View.OnKeyListener
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(@NonNull Activity context, @NonNull ILiveImageStatusNotify imageStatusNotify, @NonNull IStatusViewDrawer statusView, @NonNull IChangeScene changeScene, @NonNull IInterfaceProvider interfaceProvider, @NonNull IFavoriteSettingDialogKicker dialogKicker)
46 this.context = context;
47 this.statusNotify = imageStatusNotify;
48 this.statusViewDrawer = statusView;
49 this.changeScene = changeScene;
50 this.interfaceProvider = interfaceProvider;
52 this.focusingControl = interfaceProvider.getFocusingControl();
53 this.captureControl = interfaceProvider.getCaptureControl();
54 this.cameraConnection = interfaceProvider.getCameraConnection();
55 this.zoomLensControl = interfaceProvider.getZoomLensControl();
57 this.dialogKicker = dialogKicker;
65 public void onClick(View view)
67 int id = view.getId();
68 //Log.v(TAG, "onClick() : " + id);
73 case R.id.hideControlPanelTextView:
75 showHideControlPanel(false);
78 case R.id.showControlPanelTextView:
80 showHideControlPanel(true);
83 case R.id.showKeyPanelImageView:
85 showHideKeyPanel(true);
88 case R.id.hideKeyPanelTextView:
90 showHideKeyPanel(false);
93 case R.id.connect_disconnect_button:
95 changeScene.changeCameraConnection();
98 case R.id.shutter_button:
100 pushedShutterButton();
103 case R.id.focusUnlockImageView:
104 // フォーカスアンロックボタンが押された
108 case R.id.show_images_button:
109 // 画像一覧表示ボタンが押された...画像一覧画面を開く
110 changeScene.changeScenceToImageList();
113 case R.id.camera_power_off_button:
114 // 電源ボタンが押された...終了してよいか確認して、終了する
115 confirmExitApplication();
118 case R.id.show_preference_button:
120 changeScene.changeSceneToConfiguration();
123 case R.id.show_hide_grid_button:
125 statusNotify.toggleShowGridFrame();
126 statusViewDrawer.updateGridIcon();
128 case R.id.zoom_in_button:
132 case R.id.zoom_out_button:
136 case R.id.specialButtonImageView:
138 pushedSpecialButton();
141 case R.id.camera_property_settings_button:
143 changeScene.changeSceneToCameraPropertyList();
146 case R.id.focusing_button:
147 // AF と MFの切り替えボタンが押された
148 changeFocusingMode();
151 case R.id.live_view_scale_button:
153 statusViewDrawer.updateLiveViewScale(true);
156 case R.id.show_favorite_settings_button:
157 // お気に入り設定のダイアログを表示する
158 showFavoriteDialog();
162 Log.v(TAG, "onClick() : " + id);
176 private void showHideControlPanel(boolean isShow)
180 View target = context.findViewById(R.id.controlPanelLayout);
181 View target2 = context.findViewById(R.id.showControlPanelTextView);
184 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
188 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
189 target2.invalidate();
203 private void showHideKeyPanel(boolean isShow)
207 View target = context.findViewById(R.id.keyPanelLayout);
208 View target2 = context.findViewById(R.id.showKeyPanelImageView);
211 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
215 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
216 target2.invalidate();
226 private void confirmExitApplication()
231 ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
232 dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, new ConfirmationDialog.Callback() {
234 public void confirm()
236 changeScene.exitApplication();
246 private void actionZoomin()
248 Log.v(TAG, "actionZoomin()");
252 if (zoomLensControl.canZoom())
254 zoomLensControl.driveZoomLens(true);
263 private void actionZoomout()
265 Log.v(TAG, "actionZoomout()");
269 if (zoomLensControl.canZoom())
271 zoomLensControl.driveZoomLens(false);
286 private void pushedShutterButton()
288 Log.v(TAG, "pushedShutterButton()");
292 captureControl.doCapture(0);
294 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
295 if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
298 statusNotify.takePicture();
308 * フォーカスアンロックボタンが押された時の処理
311 private void pushedFocusUnlock()
313 Log.v(TAG, "pushedFocusUnlock()");
317 focusingControl.unlockAutoFocus();
329 private void pushedSpecialButton()
331 showFavoriteDialog();
338 private void showFavoriteDialog()
340 Log.v(TAG, "showFavoriteDialog()");
343 if (cameraConnection.getConnectionStatus() != ICameraConnection.CameraConnectionStatus.CONNECTED)
345 // カメラと接続されていない時には、何もしない
349 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
351 // OPCカメラの場合には、お気に入り設定のダイアログを表示する
352 dialogKicker.showFavoriteSettingDialog();
357 ICameraButtonControl btnCtl = interfaceProvider.getButtonControl();
360 // 'GREEN' ボタンが押されたこととする
361 btnCtl.pushedButton(ICameraButtonControl.SPECIAL_GREEN_BUTTON, false);
375 public boolean onTouch(View view, MotionEvent motionEvent)
377 int id = view.getId();
378 if (focusingControl == null)
380 Log.v(TAG, "focusingControl is NULL.");
381 view.performClick(); // ダミー処理...
384 Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
385 return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));
393 public boolean onKey(View view, int keyCode, @NonNull KeyEvent keyEvent)
395 Log.v(TAG, "onKey() : " + keyCode);
398 if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN)&&
399 ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
401 pushedShutterButton();