1 package net.osdn.gokigen.a01d.liveview;
3 import android.app.Activity;
4 import android.content.Context;
5 import android.content.SharedPreferences;
6 import android.graphics.Color;
7 import android.graphics.drawable.Drawable;
8 import android.os.Bundle;
9 import android.util.Log;
10 import android.view.LayoutInflater;
11 import android.view.View;
12 import android.view.ViewGroup;
13 import android.widget.Button;
14 import android.widget.ImageButton;
15 import android.widget.ImageView;
16 import android.widget.TextView;
18 import net.osdn.gokigen.a01d.IChangeScene;
19 import net.osdn.gokigen.a01d.R;
20 import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
21 import net.osdn.gokigen.a01d.camera.IDisplayInjector;
22 import net.osdn.gokigen.a01d.camera.olympus.myolycameraprops.LoadSaveCameraProperties;
23 import net.osdn.gokigen.a01d.camera.olympus.myolycameraprops.LoadSaveMyCameraPropertyDialog;
24 import net.osdn.gokigen.a01d.camera.IZoomLensControl;
25 import net.osdn.gokigen.a01d.camera.ICameraInformation;
26 import net.osdn.gokigen.a01d.camera.IFocusingModeNotify;
27 import net.osdn.gokigen.a01d.camera.ILiveViewControl;
28 import net.osdn.gokigen.a01d.camera.ICameraConnection;
29 import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraProperty;
30 import net.osdn.gokigen.a01d.camera.olympus.wrapper.property.IOlyCameraPropertyProvider;
31 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
32 import net.osdn.gokigen.a01d.liveview.liveviewlistener.OlympusCameraLiveViewListenerImpl;
33 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
35 import androidx.annotation.NonNull;
36 import androidx.core.content.res.ResourcesCompat;
37 import androidx.core.graphics.drawable.DrawableCompat;
38 import androidx.fragment.app.Fragment;
39 import androidx.fragment.app.FragmentManager;
40 import androidx.preference.PreferenceManager;
46 public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker, ICameraStatusUpdateNotify, IFocusLockIndicator
48 private final String TAG = this.toString();
49 private static final int COMMAND_MY_PROPERTY = 0x00000100;
51 private ILiveViewControl liveViewControl = null;
52 private IZoomLensControl zoomLensControl = null;
53 private IInterfaceProvider interfaceProvider = null;
54 private IDisplayInjector interfaceInjector = null;
55 private OlympusCameraLiveViewListenerImpl liveViewListener = null;
56 private IChangeScene changeScene = null;
57 private ICameraInformation cameraInformation = null;
58 private LiveViewClickTouchListener onClickTouchListener = null;
60 private TextView statusArea = null;
61 private TextView focalLengthArea = null;
62 private CameraLiveImageView imageView = null;
64 private ImageView manualFocus = null;
65 private ImageView focusIndicator = null;
66 private ImageButton showGrid = null;
67 private ImageButton connectStatus = null;
68 private Button changeLiveViewScale = null;
70 private boolean imageViewCreated = false;
71 private View myView = null;
72 private String messageValue = "";
73 private boolean focusLocked = false;
75 private ICameraConnection.CameraConnectionStatus currentConnectionStatus = ICameraConnection.CameraConnectionStatus.UNKNOWN;
77 public static LiveViewFragment newInstance(IChangeScene sceneSelector, @NonNull IInterfaceProvider provider)
79 LiveViewFragment instance = new LiveViewFragment();
80 instance.prepare(sceneSelector, provider);
82 // パラメータはBundleにまとめておく
83 Bundle arguments = new Bundle();
84 //arguments.putString("title", title);
85 //arguments.putString("message", message);
86 instance.setArguments(arguments);
96 public void onCreate(Bundle savedInstanceState)
98 super.onCreate(savedInstanceState);
99 Log.v(TAG, "onCreate()");
100 if (liveViewListener == null)
102 liveViewListener = new OlympusCameraLiveViewListenerImpl();
111 public void onAttach(Context context)
113 super.onAttach(context);
114 Log.v(TAG, "onAttach()");
122 public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
124 super.onCreateView(inflater, container, savedInstanceState);
126 Log.v(TAG, "onCreateView()");
127 if ((imageViewCreated)&&(myView != null))
130 Log.v(TAG, "onCreateView() : called again, so do nothing... : " + myView);
134 View view = inflater.inflate(R.layout.fragment_live_view, container, false);
136 imageViewCreated = true;
139 imageView = view.findViewById(R.id.cameraLiveImageView);
140 if (interfaceInjector != null)
142 interfaceInjector.injectDisplay(imageView, imageView, this);
146 Log.v(TAG, "interfaceInjector is NULL...");
148 if (onClickTouchListener == null)
150 onClickTouchListener = new LiveViewClickTouchListener(this.getContext(), imageView, this, changeScene, interfaceProvider, this);
152 imageView.setOnClickListener(onClickTouchListener);
153 imageView.setOnTouchListener(onClickTouchListener);
154 imageView.setFocuslockIndicator(this);
156 view.findViewById(R.id.show_preference_button).setOnClickListener(onClickTouchListener);
157 view.findViewById(R.id.camera_property_settings_button).setOnClickListener(onClickTouchListener);
158 view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
159 view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
160 view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
162 focusIndicator = view.findViewById(R.id.focus_indicator);
163 if (focusIndicator != null)
165 focusIndicator.setOnClickListener(onClickTouchListener);
167 manualFocus = view.findViewById(R.id.focusing_button);
168 changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
170 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
172 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
174 view.findViewById(R.id.show_favorite_settings_button).setOnClickListener(onClickTouchListener);
176 // OPCのときには、フォーカスインジケータのマークを消す。
177 if (focusIndicator != null)
179 focusIndicator.setVisibility(View.INVISIBLE);
184 // お気に入りボタン(とMFボタン)は、SONYモード, RICOH GR2モードのときには表示しない
185 final View favoriteButton = view.findViewById(R.id.show_favorite_settings_button);
186 final View propertyButton = view.findViewById(R.id.camera_property_settings_button);
187 if ((favoriteButton != null)&&(manualFocus != null))
189 runOnUiThread(new Runnable()
194 favoriteButton.setVisibility(View.INVISIBLE);
195 if (manualFocus != null)
197 manualFocus.setVisibility(View.INVISIBLE);
199 propertyButton.setVisibility(View.INVISIBLE);
203 if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
205 if (changeLiveViewScale != null)
207 changeLiveViewScale.setVisibility(View.INVISIBLE);
209 if (focusIndicator != null)
211 focusIndicator.setVisibility(View.VISIBLE);
214 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
216 if (changeLiveViewScale != null)
218 changeLiveViewScale.setVisibility(View.VISIBLE);
220 if (focusIndicator != null)
222 focusIndicator.setVisibility(View.INVISIBLE);
225 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
227 if (changeLiveViewScale != null)
229 changeLiveViewScale.setVisibility(View.INVISIBLE);
231 if (focusIndicator != null)
233 focusIndicator.setVisibility(View.VISIBLE);
238 if (manualFocus != null)
240 manualFocus.setOnClickListener(onClickTouchListener);
242 changedFocusingMode();
244 if (changeLiveViewScale != null)
246 changeLiveViewScale.setOnClickListener(onClickTouchListener);
249 showGrid = view.findViewById(R.id.show_hide_grid_button);
250 showGrid.setOnClickListener(onClickTouchListener);
253 connectStatus = view.findViewById(R.id.connect_disconnect_button);
254 connectStatus.setOnClickListener(onClickTouchListener);
255 updateConnectionStatus(ICameraConnection.CameraConnectionStatus.UNKNOWN);
257 statusArea = view.findViewById(R.id.informationMessageTextView);
258 focalLengthArea = view.findViewById(R.id.focal_length_with_digital_zoom_view);
272 private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
274 Log.v(TAG, "prepare()");
276 IDisplayInjector interfaceInjector;
277 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
278 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
280 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
282 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
284 interfaceInjector = interfaceProvider.getSonyInterface().getDisplayInjector();
286 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
289 interfaceInjector = interfaceProvider.getSonyInterface().getDisplayInjector();
291 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
293 interfaceInjector = interfaceProvider.getOlympusInterface().getDisplayInjector();
295 this.changeScene = sceneSelector;
296 this.interfaceProvider = interfaceProvider;
297 this.interfaceInjector = interfaceInjector;
299 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
301 this.liveViewControl = interfaceProvider.getRicohGr2Infterface().getLiveViewControl();
302 this.zoomLensControl = interfaceProvider.getRicohGr2Infterface().getZoomLensControl();
303 this.cameraInformation = interfaceProvider.getRicohGr2Infterface().getCameraInformation();
305 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
307 this.liveViewControl = interfaceProvider.getSonyInterface().getSonyLiveViewControl();
308 this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
309 this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
311 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
314 this.liveViewControl = interfaceProvider.getSonyInterface().getSonyLiveViewControl();
315 this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
316 this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
318 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
320 this.liveViewControl = interfaceProvider.getOlympusInterface().getLiveViewControl();
321 this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
322 this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
324 interfaceProvider.setUpdateReceiver(this);
332 public void updateConnectionStatus(ICameraConnection.CameraConnectionStatus connectionStatus)
336 currentConnectionStatus = connectionStatus;
337 runOnUiThread(new Runnable()
342 int id = R.drawable.ic_cloud_off_black_24dp;
343 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
345 id = R.drawable.ic_cloud_queue_black_24dp;
347 else if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
349 id = R.drawable.ic_cloud_done_black_24dp;
351 connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
352 connectStatus.invalidate();
353 imageView.invalidate();
369 public void updateGridIcon()
373 int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
374 showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
375 showGrid.invalidate();
376 imageView.invalidate();
389 public void changedFocusingMode()
393 if ((cameraInformation == null)||(manualFocus == null))
397 runOnUiThread(new Runnable()
402 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
404 manualFocus.setSelected(cameraInformation.isManualFocus());
405 manualFocus.invalidate();
417 public void updateLiveViewScale(boolean isChangeScale)
421 Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
424 liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
427 float scale = liveViewControl.getMagnifyingLiveViewScale();
428 final String datavalue = "LV: " + scale;
431 float digitalZoom = liveViewControl.getDigitalZoomScale();
432 final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
435 runOnUiThread(new Runnable()
440 changeLiveViewScale.setText(datavalue);
441 changeLiveViewScale.postInvalidate();
443 focalLengthArea.setText(digitalValue);
444 focalLengthArea.postInvalidate();
460 public void onStart()
463 Log.v(TAG, "onStart()");
471 public void onResume()
474 Log.v(TAG, "onResume() Start");
476 // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
477 if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
479 // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。
480 changeRunModeExecutor.changeRunMode(true);
484 camera.setCameraStatusListener(statusListener);
486 // 画面下部の表示エリアの用途を切り替える
487 setupLowerDisplayArea();
492 Context context = getContext();
495 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
497 // グリッド・フォーカスアシストの情報を戻す
498 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
499 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
500 imageView.toggleShowGridFrame();
501 imageView.postInvalidate();
504 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
513 Log.v(TAG, "onResume() End");
521 public void onPause()
524 Log.v(TAG, "onPause() Start");
529 liveViewControl.stopLiveView();
536 Log.v(TAG, "onPause() End");
544 public void updateStatusView(String message)
546 messageValue = message;
547 runOnUiThread(new Runnable()
550 * カメラの状態(ステータステキスト)を更新する
551 * (ステータステキストは、プライベート変数で保持して、書き換える)
556 if (statusArea != null)
558 statusArea.setText(messageValue);
559 statusArea.invalidate();
570 public void startLiveView()
572 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
574 if (liveViewControl == null)
576 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
578 Log.v(TAG, "startLiveView() : liveViewControl is null.");
584 prepare(changeScene, interfaceProvider);
590 Context context = getContext();
593 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
594 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
596 ILiveViewListener lvListener;
597 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
599 lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
601 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
603 lvListener = interfaceProvider.getSonyInterface().getLiveViewListener();
605 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
608 lvListener = interfaceProvider.getSonyInterface().getLiveViewListener();
610 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
612 interfaceProvider.getOlympusLiveViewListener().setOlympusLiveViewListener(liveViewListener);
613 lvListener = liveViewListener;
615 lvListener.setCameraLiveImageView(imageView);
616 liveViewControl.startLiveView();
619 liveViewControl.updateDigitalZoom();
621 // ズームが制御できない場合は、ボタンを消す
622 if (!zoomLensControl.canZoom())
624 final Activity activity = getActivity();
625 if (activity != null)
627 activity.runOnUiThread(new Runnable()
632 activity.findViewById(R.id.btn_zoomin).setVisibility(View.INVISIBLE);
633 activity.findViewById(R.id.btn_zoomout).setVisibility(View.INVISIBLE);
640 // パワーズームの設定 (初期化位置の設定)
641 zoomLensControl.moveInitialZoomPosition();
644 // 測光モードをスポットに切り替える (OPCのみ)
645 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
651 updateLiveViewScale(false);
665 public boolean isFocusLocked()
667 return (this.focusLocked);
674 private void setAEtoSpot()
678 IOlyCameraPropertyProvider propertyProvider = interfaceProvider.getOlympusInterface().getCameraPropertyProvider();
679 if (propertyProvider != null)
681 propertyProvider.setCameraPropertyValue(IOlyCameraProperty.AE, IOlyCameraProperty.AE_PINPOINT);
691 public void showFavoriteSettingDialog()
695 Log.v(TAG, "showFavoriteSettingDialog()");
697 LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
698 dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
699 dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
700 FragmentManager manager = getFragmentManager();
703 dialog.show(manager, "my_dialog");
712 private void runOnUiThread(Runnable action)
714 Activity activity = getActivity();
715 if (activity == null)
719 activity.runOnUiThread(action);
723 public void updateDriveMode(String driveMode)
725 Log.v(TAG, "updateDriveMode() : " + driveMode);
729 public void updateAeLockState(boolean isAeLocked)
731 Log.v(TAG, "updateAeLockState() : " + isAeLocked);
735 public void updateCameraStatus(String message)
737 Log.v(TAG, "updateCameraStatus() : " + message);
741 public void updateLevelGauge(String orientation, float roll, float pitch)
743 Log.v(TAG, "updateLevelGauge() : " + orientation + " roll : " + roll + " pitch : " + pitch);
747 public void updatedTakeMode(String mode)
749 Log.v(TAG, "updatedTakeMode() : " + mode);
753 public void updatedShutterSpeed(String tv)
755 Log.v(TAG, "updatedShutterSpeed() : " + tv);
759 public void updatedAperture(String av)
761 Log.v(TAG, "updatedAperture() : " + av);
765 public void updatedExposureCompensation(String xv)
767 Log.v(TAG, "updatedExposureCompensation() : " + xv);
771 public void updatedMeteringMode(String meteringMode)
773 Log.v(TAG, "updatedExposureCompensation() : " + meteringMode);
777 public void updatedWBMode(String wbMode)
779 Log.v(TAG, "updatedWBMode() : " + wbMode);
783 public void updateRemainBattery(int percentage)
785 Log.v(TAG, "updateRemainBattery() : " + percentage);
789 public void updateFocusedStatus(final boolean focused, final boolean focusLocked)
791 Log.v(TAG, "updateFocusedStatus() : f: " + focused + " fl: " + focusLocked);
792 this.focusLocked = focusLocked;
793 Activity activity = getActivity();
794 if ((activity == null)||(focusIndicator == null)|| (focusIndicator.getVisibility() != View.VISIBLE))
796 Log.v(TAG, "updateFocusedStatus() : INVISIBLE");
802 activity.runOnUiThread(new Runnable() {
807 Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_center_focus_strong_black_24dp, null);
810 DrawableCompat.setTint(icon, Color.GREEN);
811 focusIndicator.setImageDrawable(icon);
816 Drawable icon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_crop_free_black_24dp, null);
819 int color = Color.BLACK;
824 DrawableCompat.setTint(icon, color);
825 focusIndicator.setImageDrawable(icon);
828 focusIndicator.invalidate();
839 public void updateIsoSensitivity(String sv)
841 Log.v(TAG, "updateIsoSensitivity() : " + sv);
845 public void updateWarning(String warning)
847 Log.v(TAG, "updateWarning() : " + warning);
851 public void updateStorageStatus(String status)
853 Log.v(TAG, "updateStorageStatus() : " + status);
857 public void updateFocusLockIndicator(final boolean focused, final boolean focusLocked)
859 updateFocusedStatus(focused, focusLocked);