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);
156 setOnClickListener(view, R.id.camera_power_off_button);
159 view.findViewById(R.id.show_preference_button).setOnClickListener(onClickTouchListener);
160 view.findViewById(R.id.camera_property_settings_button).setOnClickListener(onClickTouchListener);
161 view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
162 view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
163 view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
165 manualFocus = view.findViewById(R.id.focusing_button);
166 changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
168 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
170 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
172 view.findViewById(R.id.show_favorite_settings_button).setOnClickListener(onClickTouchListener);
176 // お気に入りボタン(とMFボタン)は、SONYモード, RICOH GR2モードのときには表示しない
177 final View favoriteButton = view.findViewById(R.id.show_favorite_settings_button);
178 final View propertyButton = view.findViewById(R.id.camera_property_settings_button);
179 if ((favoriteButton != null)&&(manualFocus != null))
181 runOnUiThread(new Runnable()
186 favoriteButton.setVisibility(View.INVISIBLE);
187 if (manualFocus != null)
189 manualFocus.setVisibility(View.INVISIBLE);
191 propertyButton.setVisibility(View.INVISIBLE);
195 if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
197 if (changeLiveViewScale != null)
199 changeLiveViewScale.setVisibility(View.INVISIBLE);
202 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
204 if (changeLiveViewScale != null)
206 changeLiveViewScale.setVisibility(View.VISIBLE);
211 if (manualFocus != null)
213 manualFocus.setOnClickListener(onClickTouchListener);
215 changedFocusingMode();
217 if (changeLiveViewScale != null)
219 changeLiveViewScale.setOnClickListener(onClickTouchListener);
222 showGrid = view.findViewById(R.id.show_hide_grid_button);
223 showGrid.setOnClickListener(onClickTouchListener);
226 updateConnectionStatus(ICameraConnection.CameraConnectionStatus.UNKNOWN);
228 statusArea = view.findViewById(R.id.informationMessageTextView);
229 focalLengthArea = view.findViewById(R.id.focal_length_with_digital_zoom_view);
231 connectStatus = view.findViewById(R.id.connect_disconnect_button);
232 if (connectStatus != null)
234 connectStatus.setOnClickListener(onClickTouchListener);
245 private void setOnClickListener(View view, int id)
249 View button = view.findViewById(id);
252 button.setOnClickListener(onClickTouchListener);
264 private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
266 Log.v(TAG, "prepare()");
268 IDisplayInjector interfaceInjector;
269 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
271 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
272 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
274 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
276 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
278 interfaceInjector = interfaceProvider.getSonyInterface().getDisplayInjector();
280 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
282 interfaceInjector = interfaceProvider.getOlympusInterface().getDisplayInjector();
285 this.changeScene = sceneSelector;
286 this.interfaceProvider = interfaceProvider;
287 this.interfaceInjector = interfaceInjector;
289 //if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
291 this.liveViewControl = interfaceProvider.getRicohGr2Infterface().getLiveViewControl();
292 this.zoomLensControl = interfaceProvider.getRicohGr2Infterface().getZoomLensControl();
293 this.cameraInformation = interfaceProvider.getRicohGr2Infterface().getCameraInformation();
294 this.statusWatcher = interfaceProvider.getRicohGr2Infterface().getCameraStatusWatcher();
297 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
299 this.liveViewControl = interfaceProvider.getSonyInterface().getSonyLiveViewControl();
300 this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
301 this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
303 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
305 this.liveViewControl = interfaceProvider.getOlympusInterface().getLiveViewControl();
306 this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
307 this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
317 public void updateConnectionStatus(final ICameraConnection.CameraConnectionStatus connectionStatus)
321 currentConnectionStatus = connectionStatus;
322 runOnUiThread(new Runnable()
327 int id = R.drawable.ic_cloud_off_black_24dp;
328 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
330 id = R.drawable.ic_cloud_queue_black_24dp;
332 else if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
334 id = R.drawable.ic_cloud_done_black_24dp;
336 if (connectStatus != null)
338 connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
339 connectStatus.invalidate();
341 if (imageView != null)
343 imageView.invalidate();
360 public void updateGridIcon()
364 int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
365 showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
366 showGrid.invalidate();
367 imageView.invalidate();
380 public void changedFocusingMode()
384 if ((cameraInformation == null)||(manualFocus == null))
388 runOnUiThread(new Runnable()
393 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
395 manualFocus.setSelected(cameraInformation.isManualFocus());
396 manualFocus.invalidate();
408 public void updateLiveViewScale(boolean isChangeScale)
412 Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
415 liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
418 float scale = liveViewControl.getMagnifyingLiveViewScale();
419 final String datavalue = "LV: " + scale;
422 float digitalZoom = liveViewControl.getDigitalZoomScale();
423 final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
426 runOnUiThread(new Runnable()
431 changeLiveViewScale.setText(datavalue);
432 changeLiveViewScale.postInvalidate();
434 focalLengthArea.setText(digitalValue);
435 focalLengthArea.postInvalidate();
451 public void onStart()
454 Log.v(TAG, "onStart()");
462 public void onResume()
465 Log.v(TAG, "onResume() Start");
467 // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
468 if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
470 // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。
471 changeRunModeExecutor.changeRunMode(true);
475 camera.setCameraStatusListener(statusListener);
477 // 画面下部の表示エリアの用途を切り替える
478 setupLowerDisplayArea();
483 Context context = getContext();
486 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
488 // グリッド・フォーカスアシストの情報を戻す
489 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
490 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
491 imageView.toggleShowGridFrame();
492 imageView.postInvalidate();
495 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
504 Log.v(TAG, "onResume() End");
512 public void onPause()
515 Log.v(TAG, "onPause() Start");
520 liveViewControl.stopLiveView();
528 Log.v(TAG, "onPause() End");
536 public void updateStatusView(String message)
538 messageValue = message;
539 runOnUiThread(new Runnable()
542 * カメラの状態(ステータステキスト)を更新する
543 * (ステータステキストは、プライベート変数で保持して、書き換える)
548 if (statusArea != null)
550 statusArea.setText(messageValue);
551 statusArea.invalidate();
562 public void startLiveView()
564 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
566 if (liveViewControl == null)
568 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
570 Log.v(TAG, "startLiveView() : liveViewControl is null.");
576 prepare(changeScene, interfaceProvider);
582 Context context = getContext();
585 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
586 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
588 ILiveViewListener lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
590 ILiveViewListener lvListener;
591 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
593 lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
595 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
597 lvListener = interfaceProvider.getSonyInterface().getLiveViewListener();
599 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
601 interfaceProvider.getOlympusLiveViewListener().setOlympusLiveViewListener(liveViewListener);
602 lvListener = liveViewListener;
605 lvListener.setCameraLiveImageView(imageView);
606 liveViewControl.startLiveView();
618 public void showFavoriteSettingDialog()
622 Log.v(TAG, "showFavoriteSettingDialog()");
624 LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
625 dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
626 dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
627 FragmentManager manager = getFragmentManager();
630 dialog.show(manager, "my_dialog");
644 private void startWatchStatus()
646 if (statusWatcher != null)
648 statusWatcher.startStatusWatch(this);
656 private void stopWatchStatus()
658 if (statusWatcher != null)
660 statusWatcher.stoptStatusWatch();
668 private void runOnUiThread(Runnable action)
670 Activity activity = getActivity();
671 if (activity == null)
675 activity.runOnUiThread(action);
679 public void updatedTakeMode(final String mode)
683 final Activity activity = getActivity();
684 if (activity == null)
688 activity.runOnUiThread(new Runnable()
693 TextView view = activity.findViewById(R.id.takemodeTextView);
709 public void updatedShutterSpeed(final String tv)
713 final String shutterSpeed = tv.replace(".", "/");
714 final Activity activity = getActivity();
715 if (activity == null)
719 activity.runOnUiThread(new Runnable()
724 TextView view = activity.findViewById(R.id.shutterSpeedTextView);
726 view.setText(shutterSpeed);
740 public void updatedAperture(final String av)
744 final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
745 final Activity activity = getActivity();
746 if (activity == null)
750 activity.runOnUiThread(new Runnable()
755 TextView view = activity.findViewById(R.id.apertureValueTextView);
758 view.setText(apertureValue);
771 public void updatedExposureCompensation(final String xv)
775 final Activity activity = getActivity();
776 if (activity == null)
780 activity.runOnUiThread(new Runnable()
785 TextView view = activity.findViewById(R.id.exposureCompensationTextView);
801 public void updatedMeteringMode(final String meteringMode)
805 final Activity activity = getActivity();
806 if (activity == null)
810 activity.runOnUiThread(new Runnable()
815 TextView view = activity.findViewById(R.id.aeModeTextView);
818 view.setText(meteringMode);
831 public void updatedWBMode(final String wbMode)
841 public void updateRemainBattery(int percentage)
845 final Activity activity = getActivity();
846 if (activity == null)
853 iconId = R.drawable.ic_battery_alert_black_24dp;
855 else if (percentage < 60)
857 iconId = R.drawable.ic_battery_20_black_24dp;
859 else if (percentage < 80)
861 iconId = R.drawable.ic_battery_60_black_24dp;
865 iconId = R.drawable.ic_battery_full_black_24dp;
867 final int id = iconId;
868 activity.runOnUiThread(new Runnable()
873 ImageView view = activity.findViewById(R.id.currentBatteryImageView);
876 view.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));