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.preference.PreferenceManager;
11 import android.util.Log;
12 import android.view.LayoutInflater;
13 import android.view.View;
14 import android.view.ViewGroup;
15 import android.widget.Button;
16 import android.widget.ImageButton;
17 import android.widget.ImageView;
18 import android.widget.TextView;
20 import net.osdn.gokigen.gr2control.R;
21 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
22 import net.osdn.gokigen.gr2control.camera.ICameraInformation;
23 import net.osdn.gokigen.gr2control.camera.ICameraStatusWatcher;
24 import net.osdn.gokigen.gr2control.camera.IDisplayInjector;
25 import net.osdn.gokigen.gr2control.camera.IFocusingModeNotify;
26 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
27 import net.osdn.gokigen.gr2control.camera.ILiveViewControl;
28 import net.osdn.gokigen.gr2control.camera.IZoomLensControl;
29 import net.osdn.gokigen.gr2control.liveview.liveviewlistener.ILiveViewListener;
30 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
31 import net.osdn.gokigen.gr2control.scene.IChangeScene;
38 public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker, ICameraStatusUpdateNotify
40 private final String TAG = this.toString();
41 private static final int COMMAND_MY_PROPERTY = 0x00000100;
43 private ILiveViewControl liveViewControl = null;
44 private IZoomLensControl zoomLensControl = null;
45 private IInterfaceProvider interfaceProvider = null;
46 private IDisplayInjector interfaceInjector = null;
47 //private OlympusCameraLiveViewListenerImpl liveViewListener = null;
48 private IChangeScene changeScene = null;
49 private ICameraInformation cameraInformation = null;
50 private ICameraStatusWatcher statusWatcher = null;
51 private LiveViewClickTouchListener onClickTouchListener = null;
53 private TextView statusArea = null;
54 private TextView focalLengthArea = null;
55 private CameraLiveImageView imageView = null;
57 private ImageView manualFocus = null;
58 private ImageButton showGrid = null;
59 private ImageView connectStatus = null;
60 private Button changeLiveViewScale = null;
62 private boolean imageViewCreated = false;
63 private View myView = null;
64 private String messageValue = "";
66 private ICameraConnection.CameraConnectionStatus currentConnectionStatus = ICameraConnection.CameraConnectionStatus.UNKNOWN;
68 public static LiveViewFragment newInstance(IChangeScene sceneSelector, @NonNull IInterfaceProvider provider)
70 LiveViewFragment instance = new LiveViewFragment();
71 instance.prepare(sceneSelector, provider);
73 // パラメータはBundleにまとめておく
74 Bundle arguments = new Bundle();
75 //arguments.putString("title", title);
76 //arguments.putString("message", message);
77 instance.setArguments(arguments);
87 public void onCreate(Bundle savedInstanceState)
89 super.onCreate(savedInstanceState);
90 Log.v(TAG, "onCreate()");
92 if (liveViewListener == null)
94 liveViewListener = new OlympusCameraLiveViewListenerImpl();
104 public void onAttach(Context context)
106 super.onAttach(context);
107 Log.v(TAG, "onAttach()");
115 public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
117 super.onCreateView(inflater, container, savedInstanceState);
119 Log.v(TAG, "onCreateView()");
120 if ((imageViewCreated)&&(myView != null))
123 Log.v(TAG, "onCreateView() : called again, so do nothing... : " + myView);
127 View view = inflater.inflate(R.layout.fragment_live_view, container, false);
129 imageViewCreated = true;
133 imageView = view.findViewById(R.id.cameraLiveImageView);
134 if (interfaceInjector != null)
136 interfaceInjector.injectDisplay(imageView, imageView, this);
140 Log.v(TAG, "interfaceInjector is NULL...");
142 if (onClickTouchListener == null)
144 onClickTouchListener = new LiveViewClickTouchListener(this.getActivity(), imageView, this, changeScene, interfaceProvider, this);
146 imageView.setOnClickListener(onClickTouchListener);
147 imageView.setOnTouchListener(onClickTouchListener);
149 setOnClickListener(view, R.id.hideControlPanelTextView);
150 setOnClickListener(view, R.id.showControlPanelTextView);
151 setOnClickListener(view, R.id.showKeyPanelImageView);
152 setOnClickListener(view, R.id.hideKeyPanelTextView);
153 setOnClickListener(view, R.id.shutter_button);
154 setOnClickListener(view, R.id.focusUnlockImageView);
155 setOnClickListener(view, R.id.show_images_button);
158 view.findViewById(R.id.show_preference_button).setOnClickListener(onClickTouchListener);
159 view.findViewById(R.id.camera_property_settings_button).setOnClickListener(onClickTouchListener);
160 view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
161 view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
162 view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
164 manualFocus = view.findViewById(R.id.focusing_button);
165 changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
167 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
169 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
171 view.findViewById(R.id.show_favorite_settings_button).setOnClickListener(onClickTouchListener);
175 // お気に入りボタン(とMFボタン)は、SONYモード, RICOH GR2モードのときには表示しない
176 final View favoriteButton = view.findViewById(R.id.show_favorite_settings_button);
177 final View propertyButton = view.findViewById(R.id.camera_property_settings_button);
178 if ((favoriteButton != null)&&(manualFocus != null))
180 runOnUiThread(new Runnable()
185 favoriteButton.setVisibility(View.INVISIBLE);
186 if (manualFocus != null)
188 manualFocus.setVisibility(View.INVISIBLE);
190 propertyButton.setVisibility(View.INVISIBLE);
194 if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
196 if (changeLiveViewScale != null)
198 changeLiveViewScale.setVisibility(View.INVISIBLE);
201 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
203 if (changeLiveViewScale != null)
205 changeLiveViewScale.setVisibility(View.VISIBLE);
210 if (manualFocus != null)
212 manualFocus.setOnClickListener(onClickTouchListener);
214 changedFocusingMode();
216 if (changeLiveViewScale != null)
218 changeLiveViewScale.setOnClickListener(onClickTouchListener);
221 showGrid = view.findViewById(R.id.show_hide_grid_button);
222 showGrid.setOnClickListener(onClickTouchListener);
225 updateConnectionStatus(ICameraConnection.CameraConnectionStatus.UNKNOWN);
227 statusArea = view.findViewById(R.id.informationMessageTextView);
228 focalLengthArea = view.findViewById(R.id.focal_length_with_digital_zoom_view);
230 connectStatus = view.findViewById(R.id.connect_disconnect_button);
231 if (connectStatus != null)
233 connectStatus.setOnClickListener(onClickTouchListener);
244 private void setOnClickListener(View view, int id)
248 View button = view.findViewById(id);
251 button.setOnClickListener(onClickTouchListener);
263 private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
265 Log.v(TAG, "prepare()");
267 IDisplayInjector interfaceInjector;
268 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
270 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
271 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
273 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
275 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
277 interfaceInjector = interfaceProvider.getSonyInterface().getDisplayInjector();
279 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
281 interfaceInjector = interfaceProvider.getOlympusInterface().getDisplayInjector();
284 this.changeScene = sceneSelector;
285 this.interfaceProvider = interfaceProvider;
286 this.interfaceInjector = interfaceInjector;
288 //if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
290 this.liveViewControl = interfaceProvider.getRicohGr2Infterface().getLiveViewControl();
291 this.zoomLensControl = interfaceProvider.getRicohGr2Infterface().getZoomLensControl();
292 this.cameraInformation = interfaceProvider.getRicohGr2Infterface().getCameraInformation();
293 this.statusWatcher = interfaceProvider.getRicohGr2Infterface().getCameraStatusWatcher();
296 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
298 this.liveViewControl = interfaceProvider.getSonyInterface().getSonyLiveViewControl();
299 this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
300 this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
302 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
304 this.liveViewControl = interfaceProvider.getOlympusInterface().getLiveViewControl();
305 this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
306 this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
316 public void updateConnectionStatus(final ICameraConnection.CameraConnectionStatus connectionStatus)
320 currentConnectionStatus = connectionStatus;
321 runOnUiThread(new Runnable()
326 int id = R.drawable.ic_cloud_off_black_24dp;
327 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
329 id = R.drawable.ic_cloud_queue_black_24dp;
331 else if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
333 id = R.drawable.ic_cloud_done_black_24dp;
335 if (connectStatus != null)
337 connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
338 connectStatus.invalidate();
340 if (imageView != null)
342 imageView.invalidate();
359 public void updateGridIcon()
363 int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
364 showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
365 showGrid.invalidate();
366 imageView.invalidate();
379 public void changedFocusingMode()
383 if ((cameraInformation == null)||(manualFocus == null))
387 runOnUiThread(new Runnable()
392 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
394 manualFocus.setSelected(cameraInformation.isManualFocus());
395 manualFocus.invalidate();
407 public void updateLiveViewScale(boolean isChangeScale)
411 Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
414 liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
417 float scale = liveViewControl.getMagnifyingLiveViewScale();
418 final String datavalue = "LV: " + scale;
421 float digitalZoom = liveViewControl.getDigitalZoomScale();
422 final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
425 runOnUiThread(new Runnable()
430 changeLiveViewScale.setText(datavalue);
431 changeLiveViewScale.postInvalidate();
433 focalLengthArea.setText(digitalValue);
434 focalLengthArea.postInvalidate();
450 public void onStart()
453 Log.v(TAG, "onStart()");
461 public void onResume()
464 Log.v(TAG, "onResume() Start");
466 // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
467 if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
469 // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。
470 changeRunModeExecutor.changeRunMode(true);
474 camera.setCameraStatusListener(statusListener);
476 // 画面下部の表示エリアの用途を切り替える
477 setupLowerDisplayArea();
482 Context context = getContext();
485 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
487 // グリッド・フォーカスアシストの情報を戻す
488 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
489 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
490 imageView.toggleShowGridFrame();
491 imageView.postInvalidate();
494 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
503 Log.v(TAG, "onResume() End");
511 public void onPause()
514 Log.v(TAG, "onPause() Start");
519 liveViewControl.stopLiveView();
527 Log.v(TAG, "onPause() End");
535 public void updateStatusView(String message)
537 messageValue = message;
538 runOnUiThread(new Runnable()
541 * カメラの状態(ステータステキスト)を更新する
542 * (ステータステキストは、プライベート変数で保持して、書き換える)
547 if (statusArea != null)
549 statusArea.setText(messageValue);
550 statusArea.invalidate();
561 public void startLiveView()
563 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
565 if (liveViewControl == null)
567 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
569 Log.v(TAG, "startLiveView() : liveViewControl is null.");
575 prepare(changeScene, interfaceProvider);
581 Context context = getContext();
584 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
585 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
587 ILiveViewListener lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
589 ILiveViewListener lvListener;
590 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
592 lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
594 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
596 lvListener = interfaceProvider.getSonyInterface().getLiveViewListener();
598 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
600 interfaceProvider.getOlympusLiveViewListener().setOlympusLiveViewListener(liveViewListener);
601 lvListener = liveViewListener;
604 lvListener.setCameraLiveImageView(imageView);
605 liveViewControl.startLiveView();
617 public void showFavoriteSettingDialog()
621 Log.v(TAG, "showFavoriteSettingDialog()");
623 LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
624 dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
625 dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
626 FragmentManager manager = getFragmentManager();
629 dialog.show(manager, "my_dialog");
643 private void startWatchStatus()
645 if (statusWatcher != null)
647 statusWatcher.startStatusWatch(this);
655 private void stopWatchStatus()
657 if (statusWatcher != null)
659 statusWatcher.stoptStatusWatch();
667 private void runOnUiThread(Runnable action)
669 Activity activity = getActivity();
670 if (activity == null)
674 activity.runOnUiThread(action);
678 public void updatedTakeMode(final String mode)
682 final Activity activity = getActivity();
683 if (activity == null)
687 activity.runOnUiThread(new Runnable()
692 TextView view = activity.findViewById(R.id.takemodeTextView);
708 public void updatedShutterSpeed(final String tv)
712 final String shutterSpeed = tv.replace(".", "/");
713 final Activity activity = getActivity();
714 if (activity == null)
718 activity.runOnUiThread(new Runnable()
723 TextView view = activity.findViewById(R.id.shutterSpeedTextView);
725 view.setText(shutterSpeed);
739 public void updatedAperture(final String av)
743 final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
744 final Activity activity = getActivity();
745 if (activity == null)
749 activity.runOnUiThread(new Runnable()
754 TextView view = activity.findViewById(R.id.apertureValueTextView);
757 view.setText(apertureValue);
770 public void updatedExposureCompensation(final String xv)
774 final Activity activity = getActivity();
775 if (activity == null)
779 activity.runOnUiThread(new Runnable()
784 TextView view = activity.findViewById(R.id.exposureCompensationTextView);
800 public void updatedMeteringMode(final String meteringMode)
804 final Activity activity = getActivity();
805 if (activity == null)
809 activity.runOnUiThread(new Runnable()
814 TextView view = activity.findViewById(R.id.aeModeTextView);
817 view.setText(meteringMode);
830 public void updatedWBMode(final String wbMode)
840 public void updateRemainBattery(int percentage)
844 final Activity activity = getActivity();
845 if (activity == null)
852 iconId = R.drawable.ic_battery_alert_black_24dp;
854 else if (percentage < 60)
856 iconId = R.drawable.ic_battery_20_black_24dp;
858 else if (percentage < 80)
860 iconId = R.drawable.ic_battery_60_black_24dp;
864 iconId = R.drawable.ic_battery_full_black_24dp;
866 final int id = iconId;
867 activity.runOnUiThread(new Runnable()
872 ImageView view = activity.findViewById(R.id.currentBatteryImageView);
875 view.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));