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.os.Bundle;
7 import android.support.annotation.NonNull;
8 import android.support.v4.app.Fragment;
9 import android.support.v4.content.res.ResourcesCompat;
10 import android.support.v7.app.ActionBar;
11 import android.support.v7.app.AppCompatActivity;
12 import android.support.v7.preference.PreferenceManager;
13 import android.util.Log;
14 import android.view.LayoutInflater;
15 import android.view.View;
16 import android.view.ViewGroup;
17 import android.widget.Button;
18 import android.widget.ImageButton;
19 import android.widget.ImageView;
20 import android.widget.TextView;
22 import net.osdn.gokigen.gr2control.R;
23 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
24 import net.osdn.gokigen.gr2control.camera.ICameraInformation;
25 import net.osdn.gokigen.gr2control.camera.ICameraStatusWatcher;
26 import net.osdn.gokigen.gr2control.camera.IDisplayInjector;
27 import net.osdn.gokigen.gr2control.camera.IFocusingModeNotify;
28 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
29 import net.osdn.gokigen.gr2control.camera.ILiveViewControl;
30 import net.osdn.gokigen.gr2control.camera.IZoomLensControl;
31 import net.osdn.gokigen.gr2control.liveview.liveviewlistener.ILiveViewListener;
32 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
33 import net.osdn.gokigen.gr2control.scene.IChangeScene;
40 public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker, ICameraStatusUpdateNotify
42 private final String TAG = this.toString();
43 private static final int COMMAND_MY_PROPERTY = 0x00000100;
45 private ILiveViewControl liveViewControl = null;
46 private IZoomLensControl zoomLensControl = null;
47 private IInterfaceProvider interfaceProvider = null;
48 private IDisplayInjector interfaceInjector = null;
49 //private OlympusCameraLiveViewListenerImpl liveViewListener = null;
50 private IChangeScene changeScene = null;
51 private ICameraInformation cameraInformation = null;
52 private ICameraStatusWatcher statusWatcher = null;
53 private LiveViewClickTouchListener onClickTouchListener = null;
54 private LiveViewControlPanelClickListener onPanelClickListener = null;
55 private LiveViewKeyPanelClickListener onKeyPanelClickListener = null;
57 private TextView statusArea = null;
58 private TextView focalLengthArea = null;
59 private CameraLiveImageView imageView = null;
61 private ImageView manualFocus = null;
62 private ImageButton showGrid = null;
63 private ImageView connectStatus = null;
64 private Button changeLiveViewScale = null;
66 private boolean imageViewCreated = false;
67 private View myView = null;
68 private String messageValue = "";
70 private ICameraConnection.CameraConnectionStatus currentConnectionStatus = ICameraConnection.CameraConnectionStatus.UNKNOWN;
72 public static LiveViewFragment newInstance(IChangeScene sceneSelector, @NonNull IInterfaceProvider provider)
74 LiveViewFragment instance = new LiveViewFragment();
75 instance.prepare(sceneSelector, provider);
77 // パラメータはBundleにまとめておく
78 Bundle arguments = new Bundle();
79 //arguments.putString("title", title);
80 //arguments.putString("message", message);
81 instance.setArguments(arguments);
91 public void onCreate(Bundle savedInstanceState)
93 super.onCreate(savedInstanceState);
94 Log.v(TAG, "onCreate()");
96 if (liveViewListener == null)
98 liveViewListener = new OlympusCameraLiveViewListenerImpl();
108 public void onAttach(Context context)
110 super.onAttach(context);
111 Log.v(TAG, "onAttach()");
119 public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
121 super.onCreateView(inflater, container, savedInstanceState);
123 Log.v(TAG, "onCreateView()");
124 if ((imageViewCreated)&&(myView != null))
127 Log.v(TAG, "onCreateView() : called again, so do nothing... : " + myView);
131 View view = inflater.inflate(R.layout.fragment_live_view, container, false);
133 imageViewCreated = true;
137 imageView = view.findViewById(R.id.cameraLiveImageView);
138 if (interfaceInjector != null)
140 interfaceInjector.injectDisplay(imageView, imageView, this);
144 Log.v(TAG, "interfaceInjector is NULL...");
146 if (onClickTouchListener == null)
148 onClickTouchListener = new LiveViewClickTouchListener(this.getActivity(), imageView, this, changeScene, interfaceProvider, this);
150 imageView.setOnClickListener(onClickTouchListener);
151 imageView.setOnTouchListener(onClickTouchListener);
153 setOnClickListener(view, R.id.hideControlPanelTextView);
154 setOnClickListener(view, R.id.showControlPanelTextView);
155 setOnClickListener(view, R.id.showKeyPanelImageView);
156 setOnClickListener(view, R.id.hideKeyPanelTextView);
157 setOnClickListener(view, R.id.shutter_button);
158 setOnClickListener(view, R.id.focusUnlockImageView);
159 setOnClickListener(view, R.id.show_images_button);
160 setOnClickListener(view, R.id.camera_power_off_button);
161 setOnClickListener(view, R.id.show_preference_button);
163 if (onPanelClickListener == null)
165 onPanelClickListener = new LiveViewControlPanelClickListener(this.getActivity(), interfaceProvider);
167 setPanelClickListener(view, R.id.takemodeTextView);
168 setPanelClickListener(view, R.id.shutterSpeedTextView);
169 setPanelClickListener(view, R.id.apertureValueTextView);
170 setPanelClickListener(view, R.id.exposureCompensationTextView);
171 setPanelClickListener(view, R.id.aeModeTextView);
172 setPanelClickListener(view, R.id.whiteBalanceImageView);
173 setPanelClickListener(view, R.id.setEffectImageView);
175 if (onKeyPanelClickListener == null)
177 onKeyPanelClickListener = new LiveViewKeyPanelClickListener(interfaceProvider);
179 setKeyPanelClickListener(view, R.id.button_front_left);
180 setKeyPanelClickListener(view, R.id.button_front_right);
181 setKeyPanelClickListener(view, R.id.button_adjust_left);
182 setKeyPanelClickListener(view, R.id.button_adjust_enter);
183 setKeyPanelClickListener(view, R.id.button_adjust_right);
184 setKeyPanelClickListener(view, R.id.button_toggle_aeaf);
185 setKeyPanelClickListener(view, R.id.lever_ael_caf);
186 setKeyPanelClickListener(view, R.id.button_up);
187 setKeyPanelClickListener(view, R.id.button_left);
188 setKeyPanelClickListener(view, R.id.button_center_enter);
189 setKeyPanelClickListener(view, R.id.button_right);
190 setKeyPanelClickListener(view, R.id.button_down);
191 setKeyPanelClickListener(view, R.id.button_function_1);
192 setKeyPanelClickListener(view, R.id.button_function_2);
193 setKeyPanelClickListener(view, R.id.button_function_3);
194 setKeyPanelClickListener(view, R.id.button_plus);
195 setKeyPanelClickListener(view, R.id.button_minus);
196 setKeyPanelClickListener(view, R.id.button_playback);
199 view.findViewById(R.id.show_preference_button).setOnClickListener(onClickTouchListener);
200 view.findViewById(R.id.camera_property_settings_button).setOnClickListener(onClickTouchListener);
201 view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
202 view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
203 view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
205 manualFocus = view.findViewById(R.id.focusing_button);
206 changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
208 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
210 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
212 view.findViewById(R.id.show_favorite_settings_button).setOnClickListener(onClickTouchListener);
216 // お気に入りボタン(とMFボタン)は、SONYモード, RICOH GR2モードのときには表示しない
217 final View favoriteButton = view.findViewById(R.id.show_favorite_settings_button);
218 final View propertyButton = view.findViewById(R.id.camera_property_settings_button);
219 if ((favoriteButton != null)&&(manualFocus != null))
221 runOnUiThread(new Runnable()
226 favoriteButton.setVisibility(View.INVISIBLE);
227 if (manualFocus != null)
229 manualFocus.setVisibility(View.INVISIBLE);
231 propertyButton.setVisibility(View.INVISIBLE);
235 if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
237 if (changeLiveViewScale != null)
239 changeLiveViewScale.setVisibility(View.INVISIBLE);
242 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
244 if (changeLiveViewScale != null)
246 changeLiveViewScale.setVisibility(View.VISIBLE);
251 if (manualFocus != null)
253 manualFocus.setOnClickListener(onClickTouchListener);
255 changedFocusingMode();
257 if (changeLiveViewScale != null)
259 changeLiveViewScale.setOnClickListener(onClickTouchListener);
262 showGrid = view.findViewById(R.id.show_hide_grid_button);
263 showGrid.setOnClickListener(onClickTouchListener);
266 updateConnectionStatus(ICameraConnection.CameraConnectionStatus.UNKNOWN);
268 statusArea = view.findViewById(R.id.informationMessageTextView);
269 focalLengthArea = view.findViewById(R.id.focal_length_with_digital_zoom_view);
271 connectStatus = view.findViewById(R.id.connect_disconnect_button);
272 if (connectStatus != null)
274 connectStatus.setOnClickListener(onClickTouchListener);
285 private void setOnClickListener(View view, int id)
289 View button = view.findViewById(id);
292 button.setOnClickListener(onClickTouchListener);
301 private void setPanelClickListener(View view, int id)
305 View button = view.findViewById(id);
308 button.setOnClickListener(onPanelClickListener);
317 private void setKeyPanelClickListener(View view, int id)
321 View button = view.findViewById(id);
324 button.setOnClickListener(onKeyPanelClickListener);
336 private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
338 Log.v(TAG, "prepare()");
340 IDisplayInjector interfaceInjector;
341 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
343 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
344 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
346 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
348 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
350 interfaceInjector = interfaceProvider.getSonyInterface().getDisplayInjector();
352 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
354 interfaceInjector = interfaceProvider.getOlympusInterface().getDisplayInjector();
357 this.changeScene = sceneSelector;
358 this.interfaceProvider = interfaceProvider;
359 this.interfaceInjector = interfaceInjector;
361 //if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
363 this.liveViewControl = interfaceProvider.getRicohGr2Infterface().getLiveViewControl();
364 this.zoomLensControl = interfaceProvider.getRicohGr2Infterface().getZoomLensControl();
365 this.cameraInformation = interfaceProvider.getRicohGr2Infterface().getCameraInformation();
366 this.statusWatcher = interfaceProvider.getRicohGr2Infterface().getCameraStatusWatcher();
369 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
371 this.liveViewControl = interfaceProvider.getSonyInterface().getSonyLiveViewControl();
372 this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
373 this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
375 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
377 this.liveViewControl = interfaceProvider.getOlympusInterface().getLiveViewControl();
378 this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
379 this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
389 public void updateConnectionStatus(final ICameraConnection.CameraConnectionStatus connectionStatus)
393 currentConnectionStatus = connectionStatus;
394 runOnUiThread(new Runnable()
399 int id = R.drawable.ic_cloud_off_black_24dp;
400 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
402 id = R.drawable.ic_cloud_queue_black_24dp;
404 else if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
406 id = R.drawable.ic_cloud_done_black_24dp;
408 if (connectStatus != null)
410 connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
411 connectStatus.invalidate();
413 if (imageView != null)
415 imageView.invalidate();
432 public void updateGridIcon()
436 int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
437 showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
438 showGrid.invalidate();
439 imageView.invalidate();
452 public void changedFocusingMode()
456 if ((cameraInformation == null)||(manualFocus == null))
460 runOnUiThread(new Runnable()
465 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
467 manualFocus.setSelected(cameraInformation.isManualFocus());
468 manualFocus.invalidate();
480 public void updateLiveViewScale(boolean isChangeScale)
484 Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
487 liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
490 float scale = liveViewControl.getMagnifyingLiveViewScale();
491 final String datavalue = "LV: " + scale;
494 float digitalZoom = liveViewControl.getDigitalZoomScale();
495 final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
498 runOnUiThread(new Runnable()
503 changeLiveViewScale.setText(datavalue);
504 changeLiveViewScale.postInvalidate();
506 focalLengthArea.setText(digitalValue);
507 focalLengthArea.postInvalidate();
523 public void onStart()
526 Log.v(TAG, "onStart()");
534 public void onResume()
537 Log.v(TAG, "onResume() Start");
539 AppCompatActivity activity = (AppCompatActivity)getActivity();
540 if (activity != null)
542 ActionBar bar = activity.getSupportActionBar();
545 bar.hide(); // ActionBarの表示を消す
550 // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
551 if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
553 // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。
554 changeRunModeExecutor.changeRunMode(true);
558 camera.setCameraStatusListener(statusListener);
560 // 画面下部の表示エリアの用途を切り替える
561 setupLowerDisplayArea();
566 Context context = getContext();
569 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
571 // グリッド・フォーカスアシストの情報を戻す
572 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
573 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
574 imageView.toggleShowGridFrame();
575 imageView.postInvalidate();
578 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
587 Log.v(TAG, "onResume() End");
595 public void onPause()
598 Log.v(TAG, "onPause() Start");
603 liveViewControl.stopLiveView();
611 Log.v(TAG, "onPause() End");
619 public void updateStatusView(String message)
621 messageValue = message;
622 runOnUiThread(new Runnable()
625 * カメラの状態(ステータステキスト)を更新する
626 * (ステータステキストは、プライベート変数で保持して、書き換える)
631 if (statusArea != null)
633 statusArea.setText(messageValue);
634 statusArea.invalidate();
645 public void startLiveView()
647 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
648 if (liveViewControl == null)
650 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
652 Log.v(TAG, "startLiveView() : liveViewControl is null.");
658 prepare(changeScene, interfaceProvider);
664 Context context = getContext();
665 boolean isCameraScreen = true;
668 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
669 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
670 isCameraScreen = preferences.getBoolean(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW, true);
672 ILiveViewListener lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
674 ILiveViewListener lvListener;
675 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
677 lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
679 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
681 lvListener = interfaceProvider.getSonyInterface().getLiveViewListener();
683 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
685 interfaceProvider.getOlympusLiveViewListener().setOlympusLiveViewListener(liveViewListener);
686 lvListener = liveViewListener;
690 lvListener.setCameraLiveImageView(imageView);
691 liveViewControl.startLiveView(isCameraScreen); // false : ライブビューのみ、 true : カメラ画面をミラー
703 public void showFavoriteSettingDialog()
707 Log.v(TAG, "showFavoriteSettingDialog()");
709 LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
710 dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
711 dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
712 FragmentManager manager = getFragmentManager();
715 dialog.show(manager, "my_dialog");
729 private void startWatchStatus()
731 if (statusWatcher != null)
733 statusWatcher.startStatusWatch(this);
741 private void stopWatchStatus()
743 if (statusWatcher != null)
745 statusWatcher.stoptStatusWatch();
753 private void runOnUiThread(Runnable action)
755 Activity activity = getActivity();
756 if (activity == null)
760 activity.runOnUiThread(action);
764 public void updatedTakeMode(final String mode)
768 final Activity activity = getActivity();
769 if (activity == null)
773 activity.runOnUiThread(new Runnable()
778 TextView view = activity.findViewById(R.id.takemodeTextView);
794 public void updatedShutterSpeed(final String tv)
798 final String shutterSpeed = tv.replace(".", "/");
799 final Activity activity = getActivity();
800 if (activity == null)
804 activity.runOnUiThread(new Runnable()
809 TextView view = activity.findViewById(R.id.shutterSpeedTextView);
811 view.setText(shutterSpeed);
825 public void updatedAperture(final String av)
829 final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
830 final Activity activity = getActivity();
831 if (activity == null)
835 activity.runOnUiThread(new Runnable()
840 TextView view = activity.findViewById(R.id.apertureValueTextView);
843 view.setText(apertureValue);
856 public void updatedExposureCompensation(final String xv)
860 final Activity activity = getActivity();
861 if (activity == null)
865 activity.runOnUiThread(new Runnable()
870 TextView view = activity.findViewById(R.id.exposureCompensationTextView);
886 public void updatedMeteringMode(final String meteringMode)
890 final Activity activity = getActivity();
891 if (activity == null)
895 activity.runOnUiThread(new Runnable()
900 TextView view = activity.findViewById(R.id.aeModeTextView);
903 view.setText(meteringMode);
916 public void updatedWBMode(final String wbMode)
918 // とりあえず何もしない... 選択肢は以下
919 // auto, multiAuto, daylight, shade, cloud, tungsten, warmWhiteFluorescent, daylightFluorescent, dayWhiteFluorescent, coolWhiteFluorescent, incandescent,manual1, cte, custom
927 public void updateRemainBattery(int percentage)
931 final Activity activity = getActivity();
932 if (activity == null)
939 iconId = R.drawable.ic_battery_alert_black_24dp;
941 else if (percentage < 60)
943 iconId = R.drawable.ic_battery_20_black_24dp;
945 else if (percentage < 80)
947 iconId = R.drawable.ic_battery_60_black_24dp;
951 iconId = R.drawable.ic_battery_full_black_24dp;
953 final int id = iconId;
954 activity.runOnUiThread(new Runnable()
959 ImageView view = activity.findViewById(R.id.currentBatteryImageView);
962 view.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));