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);
157 view.findViewById(R.id.show_preference_button).setOnClickListener(onClickTouchListener);
158 view.findViewById(R.id.camera_property_settings_button).setOnClickListener(onClickTouchListener);
159 view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
160 view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
161 view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
163 manualFocus = view.findViewById(R.id.focusing_button);
164 changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
166 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
168 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
170 view.findViewById(R.id.show_favorite_settings_button).setOnClickListener(onClickTouchListener);
174 // お気に入りボタン(とMFボタン)は、SONYモード, RICOH GR2モードのときには表示しない
175 final View favoriteButton = view.findViewById(R.id.show_favorite_settings_button);
176 final View propertyButton = view.findViewById(R.id.camera_property_settings_button);
177 if ((favoriteButton != null)&&(manualFocus != null))
179 runOnUiThread(new Runnable()
184 favoriteButton.setVisibility(View.INVISIBLE);
185 if (manualFocus != null)
187 manualFocus.setVisibility(View.INVISIBLE);
189 propertyButton.setVisibility(View.INVISIBLE);
193 if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
195 if (changeLiveViewScale != null)
197 changeLiveViewScale.setVisibility(View.INVISIBLE);
200 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
202 if (changeLiveViewScale != null)
204 changeLiveViewScale.setVisibility(View.VISIBLE);
209 if (manualFocus != null)
211 manualFocus.setOnClickListener(onClickTouchListener);
213 changedFocusingMode();
215 if (changeLiveViewScale != null)
217 changeLiveViewScale.setOnClickListener(onClickTouchListener);
220 showGrid = view.findViewById(R.id.show_hide_grid_button);
221 showGrid.setOnClickListener(onClickTouchListener);
224 updateConnectionStatus(ICameraConnection.CameraConnectionStatus.UNKNOWN);
226 statusArea = view.findViewById(R.id.informationMessageTextView);
227 focalLengthArea = view.findViewById(R.id.focal_length_with_digital_zoom_view);
229 connectStatus = view.findViewById(R.id.connect_disconnect_button);
230 connectStatus.setOnClickListener(onClickTouchListener);
240 private void setOnClickListener(View view, int id)
244 View button = view.findViewById(id);
247 button.setOnClickListener(onClickTouchListener);
259 private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
261 Log.v(TAG, "prepare()");
263 IDisplayInjector interfaceInjector;
264 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
266 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
267 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
269 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
271 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
273 interfaceInjector = interfaceProvider.getSonyInterface().getDisplayInjector();
275 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
277 interfaceInjector = interfaceProvider.getOlympusInterface().getDisplayInjector();
280 this.changeScene = sceneSelector;
281 this.interfaceProvider = interfaceProvider;
282 this.interfaceInjector = interfaceInjector;
284 //if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
286 this.liveViewControl = interfaceProvider.getRicohGr2Infterface().getLiveViewControl();
287 this.zoomLensControl = interfaceProvider.getRicohGr2Infterface().getZoomLensControl();
288 this.cameraInformation = interfaceProvider.getRicohGr2Infterface().getCameraInformation();
289 this.statusWatcher = interfaceProvider.getRicohGr2Infterface().getCameraStatusWatcher();
292 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
294 this.liveViewControl = interfaceProvider.getSonyInterface().getSonyLiveViewControl();
295 this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
296 this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
298 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
300 this.liveViewControl = interfaceProvider.getOlympusInterface().getLiveViewControl();
301 this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
302 this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
312 public void updateConnectionStatus(final ICameraConnection.CameraConnectionStatus connectionStatus)
316 currentConnectionStatus = connectionStatus;
317 runOnUiThread(new Runnable()
322 int id = R.drawable.ic_cloud_off_black_24dp;
323 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
325 id = R.drawable.ic_cloud_queue_black_24dp;
327 else if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
329 id = R.drawable.ic_cloud_done_black_24dp;
331 if (connectStatus != null)
333 connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
334 connectStatus.invalidate();
336 if (imageView != null)
338 imageView.invalidate();
355 public void updateGridIcon()
359 int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
360 showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
361 showGrid.invalidate();
362 imageView.invalidate();
375 public void changedFocusingMode()
379 if ((cameraInformation == null)||(manualFocus == null))
383 runOnUiThread(new Runnable()
388 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
390 manualFocus.setSelected(cameraInformation.isManualFocus());
391 manualFocus.invalidate();
403 public void updateLiveViewScale(boolean isChangeScale)
407 Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
410 liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
413 float scale = liveViewControl.getMagnifyingLiveViewScale();
414 final String datavalue = "LV: " + scale;
417 float digitalZoom = liveViewControl.getDigitalZoomScale();
418 final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
421 runOnUiThread(new Runnable()
426 changeLiveViewScale.setText(datavalue);
427 changeLiveViewScale.postInvalidate();
429 focalLengthArea.setText(digitalValue);
430 focalLengthArea.postInvalidate();
446 public void onStart()
449 Log.v(TAG, "onStart()");
457 public void onResume()
460 Log.v(TAG, "onResume() Start");
462 // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
463 if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
465 // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。
466 changeRunModeExecutor.changeRunMode(true);
470 camera.setCameraStatusListener(statusListener);
472 // 画面下部の表示エリアの用途を切り替える
473 setupLowerDisplayArea();
478 Context context = getContext();
481 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
483 // グリッド・フォーカスアシストの情報を戻す
484 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
485 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
486 imageView.toggleShowGridFrame();
487 imageView.postInvalidate();
490 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
499 Log.v(TAG, "onResume() End");
507 public void onPause()
510 Log.v(TAG, "onPause() Start");
515 liveViewControl.stopLiveView();
523 Log.v(TAG, "onPause() End");
531 public void updateStatusView(String message)
533 messageValue = message;
534 runOnUiThread(new Runnable()
537 * カメラの状態(ステータステキスト)を更新する
538 * (ステータステキストは、プライベート変数で保持して、書き換える)
543 if (statusArea != null)
545 statusArea.setText(messageValue);
546 statusArea.invalidate();
557 public void startLiveView()
559 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
561 if (liveViewControl == null)
563 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
565 Log.v(TAG, "startLiveView() : liveViewControl is null.");
571 prepare(changeScene, interfaceProvider);
577 Context context = getContext();
580 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
581 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
583 ILiveViewListener lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
585 ILiveViewListener lvListener;
586 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
588 lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
590 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
592 lvListener = interfaceProvider.getSonyInterface().getLiveViewListener();
594 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
596 interfaceProvider.getOlympusLiveViewListener().setOlympusLiveViewListener(liveViewListener);
597 lvListener = liveViewListener;
600 lvListener.setCameraLiveImageView(imageView);
601 liveViewControl.startLiveView();
613 public void showFavoriteSettingDialog()
617 Log.v(TAG, "showFavoriteSettingDialog()");
619 LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
620 dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
621 dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
622 FragmentManager manager = getFragmentManager();
625 dialog.show(manager, "my_dialog");
639 private void startWatchStatus()
641 if (statusWatcher != null)
643 statusWatcher.startStatusWatch(this);
651 private void stopWatchStatus()
653 if (statusWatcher != null)
655 statusWatcher.stoptStatusWatch();
663 private void runOnUiThread(Runnable action)
665 Activity activity = getActivity();
666 if (activity == null)
670 activity.runOnUiThread(action);
674 public void updatedTakeMode(final String mode)
678 final Activity activity = getActivity();
679 if (activity == null)
683 activity.runOnUiThread(new Runnable()
688 TextView view = activity.findViewById(R.id.takemodeTextView);
701 public void updatedShutterSpeed(final String tv)
705 final String shutterSpeed = tv.replace(".", "/");
706 final Activity activity = getActivity();
707 if (activity == null)
711 activity.runOnUiThread(new Runnable()
716 TextView view = activity.findViewById(R.id.shutterSpeedTextView);
717 view.setText(shutterSpeed);
730 public void updatedAperture(final String av)
734 final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
735 final Activity activity = getActivity();
736 if (activity == null)
740 activity.runOnUiThread(new Runnable()
745 TextView view = activity.findViewById(R.id.apertureValueTextView);
746 view.setText(apertureValue);
758 public void updatedExposureCompensation(final String xv)
762 final Activity activity = getActivity();
763 if (activity == null)
767 activity.runOnUiThread(new Runnable()
772 TextView view = activity.findViewById(R.id.exposureCompensationTextView);
785 public void updatedMeteringMode(final String meteringMode)
789 final Activity activity = getActivity();
790 if (activity == null)
794 activity.runOnUiThread(new Runnable()
799 TextView view = activity.findViewById(R.id.aeModeTextView);
800 view.setText(meteringMode);
812 public void updatedWBMode(final String wbMode)
822 public void updateRemainBattery(int percentage)
826 final Activity activity = getActivity();
827 if (activity == null)
834 iconId = R.drawable.ic_battery_alert_black_24dp;
836 else if (percentage < 60)
838 iconId = R.drawable.ic_battery_20_black_24dp;
840 else if (percentage < 80)
842 iconId = R.drawable.ic_battery_60_black_24dp;
846 iconId = R.drawable.ic_battery_full_black_24dp;
848 final int id = iconId;
849 activity.runOnUiThread(new Runnable()
854 ImageView view = activity.findViewById(R.id.currentBatteryImageView);
855 view.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));