1 package net.osdn.gokigen.gr2control.liveview;
3 import android.app.Activity;
4 import android.content.SharedPreferences;
5 import android.support.annotation.NonNull;
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.ICaptureControl;
15 import net.osdn.gokigen.gr2control.camera.IFocusingControl;
16 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
17 import net.osdn.gokigen.gr2control.camera.IZoomLensControl;
18 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
19 import net.osdn.gokigen.gr2control.scene.ConfirmationDialog;
20 import net.osdn.gokigen.gr2control.scene.IChangeScene;
26 class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchListener
28 private final String TAG = toString();
29 private final Activity context;
30 private final ILiveImageStatusNotify statusNotify;
31 private final IStatusViewDrawer statusViewDrawer;
32 private final IChangeScene changeScene;
33 private final IInterfaceProvider interfaceProvider;
34 private final IFocusingControl focusingControl;
35 private final ICaptureControl captureControl;
36 //private final IOlyCameraPropertyProvider propertyProvider;
37 //private final ICameraInformation cameraInformation;
38 private final ICameraConnection cameraConnection;
39 private final IFavoriteSettingDialogKicker dialogKicker;
40 private final IZoomLensControl zoomLensControl;
42 LiveViewClickTouchListener(@NonNull Activity context, @NonNull ILiveImageStatusNotify imageStatusNotify, @NonNull IStatusViewDrawer statusView, @NonNull IChangeScene changeScene, @NonNull IInterfaceProvider interfaceProvider, @NonNull IFavoriteSettingDialogKicker dialogKicker)
44 this.context = context;
45 this.statusNotify = imageStatusNotify;
46 this.statusViewDrawer = statusView;
47 this.changeScene = changeScene;
48 this.interfaceProvider = interfaceProvider;
50 this.focusingControl = interfaceProvider.getFocusingControl();
51 this.captureControl = interfaceProvider.getCaptureControl();
52 this.cameraConnection = interfaceProvider.getCameraConnection();
53 this.zoomLensControl = interfaceProvider.getZoomLensControl();
55 this.dialogKicker = dialogKicker;
63 public void onClick(View view)
65 int id = view.getId();
66 //Log.v(TAG, "onClick() : " + id);
71 case R.id.hideControlPanelTextView:
73 showHideControlPanel(false);
76 case R.id.showControlPanelTextView:
78 showHideControlPanel(true);
81 case R.id.showKeyPanelImageView:
83 showHideKeyPanel(true);
86 case R.id.hideKeyPanelTextView:
88 showHideKeyPanel(false);
91 case R.id.connect_disconnect_button:
93 changeScene.changeCameraConnection();
96 case R.id.shutter_button:
98 pushedShutterButton();
101 case R.id.focusUnlockImageView:
102 // フォーカスアンロックボタンが押された
106 case R.id.show_images_button:
107 // 画像一覧表示ボタンが押された...画像一覧画面を開く
108 changeScene.changeScenceToImageList();
111 case R.id.camera_power_off_button:
112 // 電源ボタンが押された...終了してよいか確認して、終了する
113 confirmExitApplication();
116 case R.id.show_preference_button:
118 changeScene.changeSceneToConfiguration();
121 case R.id.show_hide_grid_button:
123 statusNotify.toggleShowGridFrame();
124 statusViewDrawer.updateGridIcon();
126 case R.id.zoom_in_button:
130 case R.id.zoom_out_button:
135 case R.id.camera_property_settings_button:
137 changeScene.changeSceneToCameraPropertyList();
140 case R.id.focusing_button:
141 // AF と MFの切り替えボタンが押された
142 changeFocusingMode();
145 case R.id.live_view_scale_button:
147 statusViewDrawer.updateLiveViewScale(true);
150 case R.id.show_favorite_settings_button:
151 // お気に入り設定のダイアログを表示する
152 showFavoriteDialog();
156 Log.v(TAG, "onClick() : " + id);
170 private void showHideControlPanel(boolean isShow)
174 View target = context.findViewById(R.id.controlPanelLayout);
175 View target2 = context.findViewById(R.id.showControlPanelTextView);
178 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
182 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
183 target2.invalidate();
197 private void showHideKeyPanel(boolean isShow)
201 View target = context.findViewById(R.id.keyPanelLayout);
202 View target2 = context.findViewById(R.id.showKeyPanelImageView);
205 target.setVisibility((isShow) ? View.VISIBLE : View.INVISIBLE);
209 target2.setVisibility((isShow) ? View.INVISIBLE : View.VISIBLE);
210 target2.invalidate();
220 private void confirmExitApplication()
225 ConfirmationDialog dialog = ConfirmationDialog.newInstance(context);
226 dialog.show(R.string.dialog_title_confirmation, R.string.dialog_message_power_off, new ConfirmationDialog.Callback() {
228 public void confirm()
230 changeScene.exitApplication();
240 private void actionZoomin()
242 Log.v(TAG, "actionZoomin()");
246 if (zoomLensControl.canZoom())
248 zoomLensControl.driveZoomLens(true);
257 private void actionZoomout()
259 Log.v(TAG, "actionZoomout()");
263 if (zoomLensControl.canZoom())
265 zoomLensControl.driveZoomLens(false);
280 private void pushedShutterButton()
282 Log.v(TAG, "pushedShutterButton()");
286 captureControl.doCapture(0);
288 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
289 if (preferences.getBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true))
292 statusNotify.takePicture();
302 * フォーカスアンロックボタンが押された時の処理
305 private void pushedFocusUnlock()
307 Log.v(TAG, "pushedFocusUnlock()");
311 focusingControl.unlockAutoFocus();
323 private void showFavoriteDialog()
325 Log.v(TAG, "showFavoriteDialog()");
328 if (interfaceProvider.getCammeraConnectionMethod() != ICameraConnection.CameraConnectionMethod.OPC)
330 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
331 Toast.makeText(context, context.getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
335 if (cameraConnection.getConnectionStatus() == ICameraConnection.CameraConnectionStatus.CONNECTED)
337 // お気に入り設定のダイアログを表示する
338 dialogKicker.showFavoriteSettingDialog();
352 public boolean onTouch(View view, MotionEvent motionEvent)
354 int id = view.getId();
355 if (focusingControl == null)
357 Log.v(TAG, "focusingControl is NULL.");
358 view.performClick(); // ダミー処理...
361 Log.v(TAG, "onTouch() : " + id + " (" + motionEvent.getX() + "," + motionEvent.getY() + ")");
362 return ((id == R.id.cameraLiveImageView)&&(focusingControl.driveAutoFocus(motionEvent)));