1 package net.osdn.gokigen.gr2control.liveview;
3 import android.content.SharedPreferences;
4 import android.os.Vibrator;
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.camera.fuji_x.cameraproperty.FujiXCameraCommandSendDialog;
18 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
19 import net.osdn.gokigen.gr2control.scene.ConfirmationDialog;
20 import net.osdn.gokigen.gr2control.scene.IChangeScene;
22 import androidx.annotation.NonNull;
23 import androidx.fragment.app.FragmentActivity;
24 import androidx.preference.PreferenceManager;
26 import static android.content.Context.VIBRATOR_SERVICE;
32 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener, View.OnKeyListener
34 private final String TAG = toString();
35 private final FragmentActivity context;
36 private final ILiveImageStatusNotify statusNotify;
37 private final IStatusViewDrawer statusViewDrawer;
38 private final IChangeScene changeScene;
39 private final IInterfaceProvider interfaceProvider;
40 private final IFocusingControl focusingControl;
41 private final ICaptureControl captureControl;
42 //private final IOlyCameraPropertyProvider propertyProvider;
43 //private final ICameraInformation cameraInformation;
44 private final ICameraConnection cameraConnection;
45 private final IFavoriteSettingDialogKicker dialogKicker;
46 private final IZoomLensControl zoomLensControl;
48 LiveViewClickTouchListener(@NonNull FragmentActivity context, @NonNull ILiveImageStatusNotify imageStatusNotify, @NonNull IStatusViewDrawer statusView, @NonNull IChangeScene changeScene, @NonNull IInterfaceProvider interfaceProvider, @NonNull IFavoriteSettingDialogKicker dialogKicker)
50 this.context = context;
51 this.statusNotify = imageStatusNotify;
52 this.statusViewDrawer = statusView;
53 this.changeScene = changeScene;
54 this.interfaceProvider = interfaceProvider;
56 this.focusingControl = interfaceProvider.getFocusingControl();
57 this.captureControl = interfaceProvider.getCaptureControl();
58 this.cameraConnection = interfaceProvider.getCameraConnection();
59 this.zoomLensControl = interfaceProvider.getZoomLensControl();
61 this.dialogKicker = dialogKicker;
69 public void onClick(View view)
71 int id = view.getId();
73 //Log.v(TAG, "onClick() : " + id);
78 case R.id.hideControlPanelTextView:
80 showHideControlPanel(false);
84 case R.id.showControlPanelTextView:
86 showHideControlPanel(true);
90 case R.id.showKeyPanelImageView:
92 showHideKeyPanel(true);
96 case R.id.hideKeyPanelTextView:
97 case R.id.fuji_x_hideKeyPanelTextView:
99 showHideKeyPanel(false);
103 case R.id.connect_disconnect_button:
104 // カメラと接続・切断のボタンが押された
105 changeScene.changeCameraConnection();
109 case R.id.shutter_button:
110 // シャッターボタンが押された (撮影)
111 pushedShutterButton();
115 case R.id.focusUnlockImageView:
116 // フォーカスアンロックボタンが押された
121 case R.id.show_images_button:
122 // 画像一覧表示ボタンが押された...画像一覧画面を開く
123 changeScene.changeScenceToImageList();
127 case R.id.camera_power_off_button:
128 // 電源ボタンが押された...終了してよいか確認して、終了する
129 confirmExitApplication();
133 case R.id.show_preference_button:
135 changeScene.changeSceneToConfiguration(ICameraConnection.CameraConnectionMethod.UNKNOWN);
139 case R.id.show_hide_grid_button:
141 statusNotify.toggleShowGridFrame();
142 statusViewDrawer.updateGridIcon();
145 case R.id.zoom_in_button:
151 case R.id.zoom_out_button:
157 case R.id.specialButtonImageView:
159 pushedSpecialButton();
163 case R.id.camera_property_settings_button:
165 changeScene.changeSceneToCameraPropertyList();
169 case R.id.focusing_button:
170 // AF と MFの切り替えボタンが押された
171 changeFocusingMode();
175 case R.id.live_view_scale_button:
177 statusViewDrawer.updateLiveViewScale(true);
181 case R.id.show_favorite_settings_button:
182 // お気に入り設定のダイアログを表示する
183 showFavoriteDialog();
188 Log.v(TAG, "onClick() : " + id);
207 private void showHideControlPanel(boolean isShow)
211 View target = context.findViewById(R.id.controlPanelLayout);
212 View target2 = context.findViewById(R.id.showControlPanelTextView);
215 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
219 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
220 target2.invalidate();
234 private void showHideKeyPanel(boolean isShow)
241 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
242 if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
245 target3 = context.findViewById(R.id.keyPanelLayout);
246 target2 = context.findViewById(R.id.showKeyPanelImageView);
247 target = context.findViewById(R.id.fuji_x_keyPanelLayout);
251 // FUJI Xモード以外 (GR2 / Olympus)
252 target = context.findViewById(R.id.keyPanelLayout);
253 target2 = context.findViewById(R.id.showKeyPanelImageView);
254 target3 = context.findViewById(R.id.fuji_x_keyPanelLayout);
265 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
270 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
271 target2.invalidate();
275 target3.setVisibility(View.GONE);
276 target3.invalidate();
285 private void confirmExitApplication()
290 ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
291 dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, new ConfirmationDialog.Callback() {
293 public void confirm()
295 changeScene.exitApplication();
305 private void actionZoomin()
307 Log.v(TAG, "actionZoomin()");
311 if (zoomLensControl.canZoom())
313 zoomLensControl.driveZoomLens(true);
322 private void actionZoomout()
324 Log.v(TAG, "actionZoomout()");
328 if (zoomLensControl.canZoom())
330 zoomLensControl.driveZoomLens(false);
345 private void pushedShutterButton()
347 Log.v(TAG, "pushedShutterButton()");
351 captureControl.doCapture(0);
353 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
354 if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
357 statusNotify.takePicture();
367 * フォーカスアンロックボタンが押された時の処理
370 private void pushedFocusUnlock()
372 Log.v(TAG, "pushedFocusUnlock()");
376 focusingControl.unlockAutoFocus();
388 private void pushedSpecialButton()
390 showFavoriteDialog();
397 private void showFavoriteDialog()
399 Log.v(TAG, "showFavoriteDialog()");
402 if (cameraConnection.getConnectionStatus() != ICameraConnection.CameraConnectionStatus.CONNECTED)
404 // カメラと接続されていない時には、何もしない
408 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
410 // OPCカメラの場合には、お気に入り設定のダイアログを表示する
411 dialogKicker.showFavoriteSettingDialog();
414 else if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.FUJI_X)
418 // FUJI X Seriesの場合は、コマンド送信ダイアログを表示する
419 FujiXCameraCommandSendDialog.newInstance(interfaceProvider.getFujiXInterfaceProvider()).show(context.getSupportFragmentManager(), "sendCommandDialog");
428 ICameraButtonControl btnCtl = interfaceProvider.getButtonControl();
431 // 'GREEN' ボタンが押されたこととする
432 btnCtl.pushedButton(ICameraButtonControl.SPECIAL_GREEN_BUTTON, false);
446 public boolean onTouch(View view, MotionEvent motionEvent)
448 int id = view.getId();
449 if (focusingControl == null)
451 Log.v(TAG, "focusingControl is NULL.");
452 view.performClick(); // ダミー処理...
455 Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
456 return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));
464 public boolean onKey(View view, int keyCode, @NonNull KeyEvent keyEvent)
466 Log.v(TAG, "onKey() : " + keyCode);
469 if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN)&&
470 ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
472 pushedShutterButton();
488 private void vibrate()
491 Vibrator vibrator = (Vibrator) context.getSystemService(VIBRATOR_SERVICE);
492 if (vibrator != null)
494 vibrator.vibrate(50);