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;
55 private TextView statusArea = null;
56 private TextView focalLengthArea = null;
57 private CameraLiveImageView imageView = null;
59 private ImageView manualFocus = null;
60 private ImageButton showGrid = null;
61 private ImageView connectStatus = null;
62 private Button changeLiveViewScale = null;
64 private boolean imageViewCreated = false;
65 private View myView = null;
66 private String messageValue = "";
68 private ICameraConnection.CameraConnectionStatus currentConnectionStatus = ICameraConnection.CameraConnectionStatus.UNKNOWN;
70 public static LiveViewFragment newInstance(IChangeScene sceneSelector, @NonNull IInterfaceProvider provider)
72 LiveViewFragment instance = new LiveViewFragment();
73 instance.prepare(sceneSelector, provider);
75 // パラメータはBundleにまとめておく
76 Bundle arguments = new Bundle();
77 //arguments.putString("title", title);
78 //arguments.putString("message", message);
79 instance.setArguments(arguments);
89 public void onCreate(Bundle savedInstanceState)
91 super.onCreate(savedInstanceState);
92 Log.v(TAG, "onCreate()");
94 if (liveViewListener == null)
96 liveViewListener = new OlympusCameraLiveViewListenerImpl();
106 public void onAttach(Context context)
108 super.onAttach(context);
109 Log.v(TAG, "onAttach()");
117 public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
119 super.onCreateView(inflater, container, savedInstanceState);
121 Log.v(TAG, "onCreateView()");
122 if ((imageViewCreated)&&(myView != null))
125 Log.v(TAG, "onCreateView() : called again, so do nothing... : " + myView);
129 View view = inflater.inflate(R.layout.fragment_live_view, container, false);
131 imageViewCreated = true;
135 imageView = view.findViewById(R.id.cameraLiveImageView);
136 if (interfaceInjector != null)
138 interfaceInjector.injectDisplay(imageView, imageView, this);
142 Log.v(TAG, "interfaceInjector is NULL...");
144 if (onClickTouchListener == null)
146 onClickTouchListener = new LiveViewClickTouchListener(this.getActivity(), imageView, this, changeScene, interfaceProvider, this);
148 imageView.setOnClickListener(onClickTouchListener);
149 imageView.setOnTouchListener(onClickTouchListener);
151 setOnClickListener(view, R.id.hideControlPanelTextView);
152 setOnClickListener(view, R.id.showControlPanelTextView);
153 setOnClickListener(view, R.id.showKeyPanelImageView);
154 setOnClickListener(view, R.id.hideKeyPanelTextView);
155 setOnClickListener(view, R.id.shutter_button);
156 setOnClickListener(view, R.id.focusUnlockImageView);
157 setOnClickListener(view, R.id.show_images_button);
158 setOnClickListener(view, R.id.camera_power_off_button);
159 setOnClickListener(view, R.id.show_preference_button);
162 view.findViewById(R.id.show_preference_button).setOnClickListener(onClickTouchListener);
163 view.findViewById(R.id.camera_property_settings_button).setOnClickListener(onClickTouchListener);
164 view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
165 view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
166 view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
168 manualFocus = view.findViewById(R.id.focusing_button);
169 changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
171 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
173 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
175 view.findViewById(R.id.show_favorite_settings_button).setOnClickListener(onClickTouchListener);
179 // お気に入りボタン(とMFボタン)は、SONYモード, RICOH GR2モードのときには表示しない
180 final View favoriteButton = view.findViewById(R.id.show_favorite_settings_button);
181 final View propertyButton = view.findViewById(R.id.camera_property_settings_button);
182 if ((favoriteButton != null)&&(manualFocus != null))
184 runOnUiThread(new Runnable()
189 favoriteButton.setVisibility(View.INVISIBLE);
190 if (manualFocus != null)
192 manualFocus.setVisibility(View.INVISIBLE);
194 propertyButton.setVisibility(View.INVISIBLE);
198 if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
200 if (changeLiveViewScale != null)
202 changeLiveViewScale.setVisibility(View.INVISIBLE);
205 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
207 if (changeLiveViewScale != null)
209 changeLiveViewScale.setVisibility(View.VISIBLE);
214 if (manualFocus != null)
216 manualFocus.setOnClickListener(onClickTouchListener);
218 changedFocusingMode();
220 if (changeLiveViewScale != null)
222 changeLiveViewScale.setOnClickListener(onClickTouchListener);
225 showGrid = view.findViewById(R.id.show_hide_grid_button);
226 showGrid.setOnClickListener(onClickTouchListener);
229 updateConnectionStatus(ICameraConnection.CameraConnectionStatus.UNKNOWN);
231 statusArea = view.findViewById(R.id.informationMessageTextView);
232 focalLengthArea = view.findViewById(R.id.focal_length_with_digital_zoom_view);
234 connectStatus = view.findViewById(R.id.connect_disconnect_button);
235 if (connectStatus != null)
237 connectStatus.setOnClickListener(onClickTouchListener);
248 private void setOnClickListener(View view, int id)
252 View button = view.findViewById(id);
255 button.setOnClickListener(onClickTouchListener);
267 private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
269 Log.v(TAG, "prepare()");
271 IDisplayInjector interfaceInjector;
272 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
274 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
275 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
277 interfaceInjector = interfaceProvider.getRicohGr2Infterface().getDisplayInjector();
279 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
281 interfaceInjector = interfaceProvider.getSonyInterface().getDisplayInjector();
283 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
285 interfaceInjector = interfaceProvider.getOlympusInterface().getDisplayInjector();
288 this.changeScene = sceneSelector;
289 this.interfaceProvider = interfaceProvider;
290 this.interfaceInjector = interfaceInjector;
292 //if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
294 this.liveViewControl = interfaceProvider.getRicohGr2Infterface().getLiveViewControl();
295 this.zoomLensControl = interfaceProvider.getRicohGr2Infterface().getZoomLensControl();
296 this.cameraInformation = interfaceProvider.getRicohGr2Infterface().getCameraInformation();
297 this.statusWatcher = interfaceProvider.getRicohGr2Infterface().getCameraStatusWatcher();
300 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
302 this.liveViewControl = interfaceProvider.getSonyInterface().getSonyLiveViewControl();
303 this.zoomLensControl = interfaceProvider.getSonyInterface().getZoomLensControl();
304 this.cameraInformation = interfaceProvider.getSonyInterface().getCameraInformation();
306 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
308 this.liveViewControl = interfaceProvider.getOlympusInterface().getLiveViewControl();
309 this.zoomLensControl = interfaceProvider.getOlympusInterface().getZoomLensControl();
310 this.cameraInformation = interfaceProvider.getOlympusInterface().getCameraInformation();
320 public void updateConnectionStatus(final ICameraConnection.CameraConnectionStatus connectionStatus)
324 currentConnectionStatus = connectionStatus;
325 runOnUiThread(new Runnable()
330 int id = R.drawable.ic_cloud_off_black_24dp;
331 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
333 id = R.drawable.ic_cloud_queue_black_24dp;
335 else if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
337 id = R.drawable.ic_cloud_done_black_24dp;
339 if (connectStatus != null)
341 connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
342 connectStatus.invalidate();
344 if (imageView != null)
346 imageView.invalidate();
363 public void updateGridIcon()
367 int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
368 showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
369 showGrid.invalidate();
370 imageView.invalidate();
383 public void changedFocusingMode()
387 if ((cameraInformation == null)||(manualFocus == null))
391 runOnUiThread(new Runnable()
396 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
398 manualFocus.setSelected(cameraInformation.isManualFocus());
399 manualFocus.invalidate();
411 public void updateLiveViewScale(boolean isChangeScale)
415 Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
418 liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
421 float scale = liveViewControl.getMagnifyingLiveViewScale();
422 final String datavalue = "LV: " + scale;
425 float digitalZoom = liveViewControl.getDigitalZoomScale();
426 final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
429 runOnUiThread(new Runnable()
434 changeLiveViewScale.setText(datavalue);
435 changeLiveViewScale.postInvalidate();
437 focalLengthArea.setText(digitalValue);
438 focalLengthArea.postInvalidate();
454 public void onStart()
457 Log.v(TAG, "onStart()");
465 public void onResume()
468 Log.v(TAG, "onResume() Start");
470 AppCompatActivity activity = (AppCompatActivity)getActivity();
471 if (activity != null)
473 ActionBar bar = activity.getSupportActionBar();
476 bar.hide(); // ActionBarの表示を消す
481 // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
482 if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
484 // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。
485 changeRunModeExecutor.changeRunMode(true);
489 camera.setCameraStatusListener(statusListener);
491 // 画面下部の表示エリアの用途を切り替える
492 setupLowerDisplayArea();
497 Context context = getContext();
500 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
502 // グリッド・フォーカスアシストの情報を戻す
503 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
504 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
505 imageView.toggleShowGridFrame();
506 imageView.postInvalidate();
509 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
518 Log.v(TAG, "onResume() End");
526 public void onPause()
529 Log.v(TAG, "onPause() Start");
534 liveViewControl.stopLiveView();
542 Log.v(TAG, "onPause() End");
550 public void updateStatusView(String message)
552 messageValue = message;
553 runOnUiThread(new Runnable()
556 * カメラの状態(ステータステキスト)を更新する
557 * (ステータステキストは、プライベート変数で保持して、書き換える)
562 if (statusArea != null)
564 statusArea.setText(messageValue);
565 statusArea.invalidate();
576 public void startLiveView()
578 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
579 if (liveViewControl == null)
581 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
583 Log.v(TAG, "startLiveView() : liveViewControl is null.");
589 prepare(changeScene, interfaceProvider);
595 Context context = getContext();
598 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
599 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
601 ILiveViewListener lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
603 ILiveViewListener lvListener;
604 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
606 lvListener = interfaceProvider.getRicohGr2Infterface().getLiveViewListener();
608 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
610 lvListener = interfaceProvider.getSonyInterface().getLiveViewListener();
612 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
614 interfaceProvider.getOlympusLiveViewListener().setOlympusLiveViewListener(liveViewListener);
615 lvListener = liveViewListener;
618 lvListener.setCameraLiveImageView(imageView);
619 liveViewControl.startLiveView();
631 public void showFavoriteSettingDialog()
635 Log.v(TAG, "showFavoriteSettingDialog()");
637 LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
638 dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
639 dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
640 FragmentManager manager = getFragmentManager();
643 dialog.show(manager, "my_dialog");
657 private void startWatchStatus()
659 if (statusWatcher != null)
661 statusWatcher.startStatusWatch(this);
669 private void stopWatchStatus()
671 if (statusWatcher != null)
673 statusWatcher.stoptStatusWatch();
681 private void runOnUiThread(Runnable action)
683 Activity activity = getActivity();
684 if (activity == null)
688 activity.runOnUiThread(action);
692 public void updatedTakeMode(final String mode)
696 final Activity activity = getActivity();
697 if (activity == null)
701 activity.runOnUiThread(new Runnable()
706 TextView view = activity.findViewById(R.id.takemodeTextView);
722 public void updatedShutterSpeed(final String tv)
726 final String shutterSpeed = tv.replace(".", "/");
727 final Activity activity = getActivity();
728 if (activity == null)
732 activity.runOnUiThread(new Runnable()
737 TextView view = activity.findViewById(R.id.shutterSpeedTextView);
739 view.setText(shutterSpeed);
753 public void updatedAperture(final String av)
757 final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
758 final Activity activity = getActivity();
759 if (activity == null)
763 activity.runOnUiThread(new Runnable()
768 TextView view = activity.findViewById(R.id.apertureValueTextView);
771 view.setText(apertureValue);
784 public void updatedExposureCompensation(final String xv)
788 final Activity activity = getActivity();
789 if (activity == null)
793 activity.runOnUiThread(new Runnable()
798 TextView view = activity.findViewById(R.id.exposureCompensationTextView);
814 public void updatedMeteringMode(final String meteringMode)
818 final Activity activity = getActivity();
819 if (activity == null)
823 activity.runOnUiThread(new Runnable()
828 TextView view = activity.findViewById(R.id.aeModeTextView);
831 view.setText(meteringMode);
844 public void updatedWBMode(final String wbMode)
854 public void updateRemainBattery(int percentage)
858 final Activity activity = getActivity();
859 if (activity == null)
866 iconId = R.drawable.ic_battery_alert_black_24dp;
868 else if (percentage < 60)
870 iconId = R.drawable.ic_battery_20_black_24dp;
872 else if (percentage < 80)
874 iconId = R.drawable.ic_battery_60_black_24dp;
878 iconId = R.drawable.ic_battery_full_black_24dp;
880 final int id = iconId;
881 activity.runOnUiThread(new Runnable()
886 ImageView view = activity.findViewById(R.id.currentBatteryImageView);
889 view.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));