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.os.Vibrator;
8 import android.support.annotation.NonNull;
9 import android.support.v4.app.Fragment;
10 import android.support.v4.content.res.ResourcesCompat;
11 import android.support.v7.app.ActionBar;
12 import android.support.v7.app.AppCompatActivity;
13 import android.support.v7.preference.PreferenceManager;
14 import android.util.Log;
15 import android.view.LayoutInflater;
16 import android.view.View;
17 import android.view.ViewGroup;
18 import android.widget.Button;
19 import android.widget.ImageButton;
20 import android.widget.ImageView;
21 import android.widget.TextView;
23 import net.osdn.gokigen.gr2control.R;
24 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
25 import net.osdn.gokigen.gr2control.camera.ICameraInformation;
26 import net.osdn.gokigen.gr2control.camera.ICameraRunMode;
27 import net.osdn.gokigen.gr2control.camera.ICameraStatusWatcher;
28 import net.osdn.gokigen.gr2control.camera.IDisplayInjector;
29 import net.osdn.gokigen.gr2control.camera.IFocusingModeNotify;
30 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
31 import net.osdn.gokigen.gr2control.camera.ILiveViewControl;
32 import net.osdn.gokigen.gr2control.liveview.liveviewlistener.ILiveViewListener;
33 import net.osdn.gokigen.gr2control.preference.IPreferencePropertyAccessor;
34 import net.osdn.gokigen.gr2control.scene.IChangeScene;
36 import static android.content.Context.VIBRATOR_SERVICE;
42 public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFocusingModeNotify, IFavoriteSettingDialogKicker, ICameraStatusUpdateNotify
44 private final String TAG = this.toString();
46 private ILiveViewControl liveViewControl = null;
47 //private IZoomLensControl zoomLensControl = null;
48 private IInterfaceProvider interfaceProvider = null;
49 private IDisplayInjector interfaceInjector = null;
50 //private OlympusCameraLiveViewListenerImpl liveViewListener = null;
51 private IChangeScene changeScene = null;
52 private ICameraInformation cameraInformation = null;
53 private ICameraStatusWatcher statusWatcher = null;
54 private LiveViewClickTouchListener onClickTouchListener = null;
55 private LiveViewControlPanelClickListener onPanelClickListener = null;
56 private LiveViewKeyPanelClickListener onKeyPanelClickListener = null;
58 private TextView statusArea = null;
59 private TextView focalLengthArea = null;
60 private CameraLiveImageView imageView = null;
62 private ImageView manualFocus = null;
63 private ImageButton showGrid = null;
64 private ImageView connectStatus = null;
65 private Button changeLiveViewScale = null;
67 private boolean imageViewCreated = false;
68 private View myView = null;
69 private String messageValue = "";
71 private ICameraConnection.CameraConnectionStatus currentConnectionStatus = ICameraConnection.CameraConnectionStatus.UNKNOWN;
73 public static LiveViewFragment newInstance(IChangeScene sceneSelector, @NonNull IInterfaceProvider provider)
75 LiveViewFragment instance = new LiveViewFragment();
76 instance.prepare(sceneSelector, provider);
78 // パラメータはBundleにまとめておく
79 Bundle arguments = new Bundle();
80 //arguments.putString("title", title);
81 //arguments.putString("message", message);
82 instance.setArguments(arguments);
92 public void onCreate(Bundle savedInstanceState)
94 super.onCreate(savedInstanceState);
95 Log.v(TAG, "onCreate()");
97 if (liveViewListener == null)
99 liveViewListener = new OlympusCameraLiveViewListenerImpl();
109 public void onAttach(Context context)
111 super.onAttach(context);
112 Log.v(TAG, "onAttach()");
120 public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
122 super.onCreateView(inflater, container, savedInstanceState);
124 Log.v(TAG, "onCreateView()");
125 if ((imageViewCreated)&&(myView != null))
128 Log.v(TAG, "onCreateView() : called again, so do nothing... : " + myView);
132 View view = inflater.inflate(R.layout.fragment_live_view, container, false);
134 imageViewCreated = true;
138 imageView = view.findViewById(R.id.cameraLiveImageView);
139 if (interfaceInjector != null)
141 interfaceInjector.injectDisplay(imageView, imageView, this);
145 Log.v(TAG, "interfaceInjector is NULL...");
147 Activity activity = this.getActivity();
148 Vibrator vibrator = (activity != null) ? (Vibrator) activity.getSystemService(VIBRATOR_SERVICE) : null;
149 if ((onClickTouchListener == null)&&(activity != null))
151 onClickTouchListener = new LiveViewClickTouchListener(activity, imageView, this, changeScene, interfaceProvider, this);
153 imageView.setOnClickListener(onClickTouchListener);
154 imageView.setOnTouchListener(onClickTouchListener);
156 setOnClickListener(view, R.id.hideControlPanelTextView);
157 setOnClickListener(view, R.id.showControlPanelTextView);
158 setOnClickListener(view, R.id.showKeyPanelImageView);
159 setOnClickListener(view, R.id.hideKeyPanelTextView);
160 setOnClickListener(view, R.id.shutter_button);
161 setOnClickListener(view, R.id.focusUnlockImageView);
162 setOnClickListener(view, R.id.show_images_button);
163 setOnClickListener(view, R.id.camera_power_off_button);
164 setOnClickListener(view, R.id.show_preference_button);
166 if (onPanelClickListener == null)
168 onPanelClickListener = new LiveViewControlPanelClickListener(activity, interfaceProvider);
170 setPanelClickListener(view, R.id.takemodeTextView);
171 setPanelClickListener(view, R.id.shutterSpeedTextView);
172 setPanelClickListener(view, R.id.apertureValueTextView);
173 setPanelClickListener(view, R.id.exposureCompensationTextView);
174 setPanelClickListener(view, R.id.aeModeTextView);
175 setPanelClickListener(view, R.id.whiteBalanceImageView);
176 setPanelClickListener(view, R.id.setEffectImageView);
178 if (onKeyPanelClickListener == null)
180 onKeyPanelClickListener = new LiveViewKeyPanelClickListener(interfaceProvider, vibrator);
182 setKeyPanelClickListener(view, R.id.button_front_left);
183 setKeyPanelClickListener(view, R.id.button_front_right);
184 setKeyPanelClickListener(view, R.id.button_adjust_left);
185 setKeyPanelClickListener(view, R.id.button_adjust_enter);
186 setKeyPanelClickListener(view, R.id.button_adjust_right);
187 setKeyPanelClickListener(view, R.id.button_toggle_aeaf);
188 setKeyPanelClickListener(view, R.id.lever_ael_caf);
189 setKeyPanelClickListener(view, R.id.button_up);
190 setKeyPanelClickListener(view, R.id.button_left);
191 setKeyPanelClickListener(view, R.id.button_center_enter);
192 setKeyPanelClickListener(view, R.id.button_right);
193 setKeyPanelClickListener(view, R.id.button_down);
194 setKeyPanelClickListener(view, R.id.button_function_1);
195 setKeyPanelClickListener(view, R.id.button_function_2);
196 setKeyPanelClickListener(view, R.id.button_function_3);
197 setKeyPanelClickListener(view, R.id.button_plus);
198 setKeyPanelClickListener(view, R.id.button_minus);
199 setKeyPanelClickListener(view, R.id.button_playback);
202 view.findViewById(R.id.show_preference_button).setOnClickListener(onClickTouchListener);
203 view.findViewById(R.id.camera_property_settings_button).setOnClickListener(onClickTouchListener);
204 view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
205 view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
206 view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
208 manualFocus = view.findViewById(R.id.focusing_button);
209 changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
211 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
213 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
215 view.findViewById(R.id.show_favorite_settings_button).setOnClickListener(onClickTouchListener);
219 // お気に入りボタン(とMFボタン)は、SONYモード, RICOH GR2モードのときには表示しない
220 final View favoriteButton = view.findViewById(R.id.show_favorite_settings_button);
221 final View propertyButton = view.findViewById(R.id.camera_property_settings_button);
222 if ((favoriteButton != null)&&(manualFocus != null))
224 runOnUiThread(new Runnable()
229 favoriteButton.setVisibility(View.INVISIBLE);
230 if (manualFocus != null)
232 manualFocus.setVisibility(View.INVISIBLE);
234 propertyButton.setVisibility(View.INVISIBLE);
238 if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
240 if (changeLiveViewScale != null)
242 changeLiveViewScale.setVisibility(View.INVISIBLE);
245 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
247 if (changeLiveViewScale != null)
249 changeLiveViewScale.setVisibility(View.VISIBLE);
254 if (manualFocus != null)
256 manualFocus.setOnClickListener(onClickTouchListener);
258 changedFocusingMode();
260 if (changeLiveViewScale != null)
262 changeLiveViewScale.setOnClickListener(onClickTouchListener);
265 showGrid = view.findViewById(R.id.show_hide_grid_button);
266 showGrid.setOnClickListener(onClickTouchListener);
269 updateConnectionStatus(ICameraConnection.CameraConnectionStatus.UNKNOWN);
271 statusArea = view.findViewById(R.id.informationMessageTextView);
272 focalLengthArea = view.findViewById(R.id.focal_length_with_digital_zoom_view);
274 connectStatus = view.findViewById(R.id.connect_disconnect_button);
275 if (connectStatus != null)
277 connectStatus.setOnClickListener(onClickTouchListener);
288 private void setOnClickListener(View view, int id)
292 View button = view.findViewById(id);
295 button.setOnClickListener(onClickTouchListener);
304 private void setPanelClickListener(View view, int id)
308 View button = view.findViewById(id);
311 button.setOnClickListener(onPanelClickListener);
320 private void setKeyPanelClickListener(View view, int id)
324 View button = view.findViewById(id);
327 button.setOnClickListener(onKeyPanelClickListener);
339 private void prepare(IChangeScene sceneSelector, IInterfaceProvider interfaceProvider)
341 Log.v(TAG, "prepare()");
343 this.changeScene = sceneSelector;
344 this.interfaceProvider = interfaceProvider;
345 this.interfaceInjector = interfaceProvider.getDisplayInjector();
346 this.liveViewControl = interfaceProvider.getLiveViewControl();
347 //this.zoomLensControl = interfaceProvider.getZoomLensControl();
348 this.cameraInformation = interfaceProvider.getCameraInformation();
349 this.statusWatcher = interfaceProvider.getCameraStatusWatcher();
357 public void updateConnectionStatus(final ICameraConnection.CameraConnectionStatus connectionStatus)
361 currentConnectionStatus = connectionStatus;
362 runOnUiThread(new Runnable()
367 int id = R.drawable.ic_cloud_off_black_24dp;
368 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTING)
370 id = R.drawable.ic_cloud_queue_black_24dp;
372 else if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
374 id = R.drawable.ic_cloud_done_black_24dp;
376 if (connectStatus != null)
378 connectStatus.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
379 connectStatus.invalidate();
381 if (imageView != null)
383 imageView.invalidate();
400 public void updateGridIcon()
404 int id = (imageView.isShowGrid()) ? R.drawable.ic_grid_off_black_24dp : R.drawable.ic_grid_on_black_24dp;
405 showGrid.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
406 showGrid.invalidate();
407 imageView.invalidate();
420 public void changedFocusingMode()
424 if ((cameraInformation == null)||(manualFocus == null))
428 runOnUiThread(new Runnable()
433 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
435 manualFocus.setSelected(cameraInformation.isManualFocus());
436 manualFocus.invalidate();
448 public void updateLiveViewScale(boolean isChangeScale)
452 Log.v(TAG, "updateLiveViewScale() : " + isChangeScale);
455 liveViewControl.updateMagnifyingLiveViewScale(isChangeScale);
458 float scale = liveViewControl.getMagnifyingLiveViewScale();
459 final String datavalue = "LV: " + scale;
462 float digitalZoom = liveViewControl.getDigitalZoomScale();
463 final String digitalValue = (digitalZoom > 1.0f) ? "D x" + digitalZoom : "";
466 runOnUiThread(new Runnable()
471 changeLiveViewScale.setText(datavalue);
472 changeLiveViewScale.postInvalidate();
474 focalLengthArea.setText(digitalValue);
475 focalLengthArea.postInvalidate();
491 public void onStart()
494 Log.v(TAG, "onStart()");
502 public void onResume()
505 Log.v(TAG, "onResume() Start");
507 AppCompatActivity activity = (AppCompatActivity)getActivity();
508 if (activity != null)
510 ActionBar bar = activity.getSupportActionBar();
513 bar.hide(); // ActionBarの表示を消す
517 // 撮影モードかどうかを確認して、撮影モードではなかったら撮影モードに切り替える
518 ICameraRunMode changeRunModeExecutor = interfaceProvider.getCameraRunMode();
519 if ((changeRunModeExecutor != null)&&(!changeRunModeExecutor.isRecordingMode()))
521 // Runモードを切り替える。(でも切り替えると、設定がクリアされてしまう...。)
522 changeRunModeExecutor.changeRunMode(true);
527 camera.setCameraStatusListener(statusListener);
529 // 画面下部の表示エリアの用途を切り替える
530 setupLowerDisplayArea();
535 Context context = getContext();
538 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
540 // グリッド・フォーカスアシストの情報を戻す
541 boolean showGrid = preferences.getBoolean(IPreferencePropertyAccessor.SHOW_GRID_STATUS, false);
542 if ((imageView != null) && (imageView.isShowGrid() != showGrid)) {
543 imageView.toggleShowGridFrame();
544 imageView.postInvalidate();
547 if (currentConnectionStatus == ICameraConnection.CameraConnectionStatus.CONNECTED)
556 Log.v(TAG, "onResume() End");
564 public void onPause()
567 Log.v(TAG, "onPause() Start");
572 liveViewControl.stopLiveView();
580 Log.v(TAG, "onPause() End");
588 public void updateStatusView(String message)
590 messageValue = message;
591 runOnUiThread(new Runnable()
594 * カメラの状態(ステータステキスト)を更新する
595 * (ステータステキストは、プライベート変数で保持して、書き換える)
600 if (statusArea != null)
602 statusArea.setText(messageValue);
603 statusArea.invalidate();
614 public void startLiveView()
616 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
617 if (liveViewControl == null)
619 if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
621 Log.v(TAG, "startLiveView() : liveViewControl is null.");
627 prepare(changeScene, interfaceProvider);
633 Context context = getContext();
634 boolean isCameraScreen = true;
637 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
638 liveViewControl.changeLiveViewSize(preferences.getString(IPreferencePropertyAccessor.LIVE_VIEW_QUALITY, IPreferencePropertyAccessor.LIVE_VIEW_QUALITY_DEFAULT_VALUE));
639 isCameraScreen = preferences.getBoolean(IPreferencePropertyAccessor.GR2_DISPLAY_CAMERA_VIEW, true);
641 ILiveViewListener lvListener = interfaceProvider.getLiveViewListener();
642 if (lvListener != null)
644 lvListener.setCameraLiveImageView(imageView);
646 liveViewControl.startLiveView(isCameraScreen); // false : ライブビューのみ、 true : カメラ画面をミラー
658 public void showFavoriteSettingDialog()
662 Log.v(TAG, "showFavoriteSettingDialog()");
664 LoadSaveMyCameraPropertyDialog dialog = new LoadSaveMyCameraPropertyDialog();
665 dialog.setTargetFragment(this, COMMAND_MY_PROPERTY);
666 dialog.setPropertyOperationsHolder(new LoadSaveCameraProperties(getActivity(), interfaceProvider.getOlympusInterface()));
667 FragmentManager manager = getFragmentManager();
670 dialog.show(manager, "my_dialog");
684 private void startWatchStatus()
686 if (statusWatcher != null)
688 statusWatcher.startStatusWatch(this);
696 private void stopWatchStatus()
698 if (statusWatcher != null)
700 statusWatcher.stoptStatusWatch();
708 private void runOnUiThread(Runnable action)
710 Activity activity = getActivity();
711 if (activity == null)
715 activity.runOnUiThread(action);
719 public void updatedTakeMode(final String mode)
723 final Activity activity = getActivity();
724 if (activity == null)
728 activity.runOnUiThread(new Runnable()
733 TextView view = activity.findViewById(R.id.takemodeTextView);
749 public void updatedShutterSpeed(final String tv)
753 final String shutterSpeed = tv.replace(".", "/");
754 final Activity activity = getActivity();
755 if (activity == null)
759 activity.runOnUiThread(new Runnable()
764 TextView view = activity.findViewById(R.id.shutterSpeedTextView);
766 view.setText(shutterSpeed);
780 public void updatedAperture(final String av)
784 final String apertureValue = (av.length() > 1) ? ("F" + av) : "";
785 final Activity activity = getActivity();
786 if (activity == null)
790 activity.runOnUiThread(new Runnable()
795 TextView view = activity.findViewById(R.id.apertureValueTextView);
798 view.setText(apertureValue);
811 public void updatedExposureCompensation(final String xv)
815 final Activity activity = getActivity();
816 if (activity == null)
820 activity.runOnUiThread(new Runnable()
825 TextView view = activity.findViewById(R.id.exposureCompensationTextView);
841 public void updatedMeteringMode(final String meteringMode)
845 final Activity activity = getActivity();
846 if (activity == null)
850 activity.runOnUiThread(new Runnable()
855 TextView view = activity.findViewById(R.id.aeModeTextView);
858 view.setText(meteringMode);
871 public void updatedWBMode(final String wbMode)
873 // とりあえず何もしない... 選択肢は以下
874 // auto, multiAuto, daylight, shade, cloud, tungsten, warmWhiteFluorescent, daylightFluorescent, dayWhiteFluorescent, coolWhiteFluorescent, incandescent,manual1, cte, custom
882 public void updateRemainBattery(int percentage)
886 final Activity activity = getActivity();
887 if (activity == null)
894 iconId = R.drawable.ic_battery_alert_black_24dp;
896 else if (percentage < 60)
898 iconId = R.drawable.ic_battery_20_black_24dp;
900 else if (percentage < 80)
902 iconId = R.drawable.ic_battery_60_black_24dp;
906 iconId = R.drawable.ic_battery_full_black_24dp;
908 final int id = iconId;
909 activity.runOnUiThread(new Runnable()
914 ImageView view = activity.findViewById(R.id.currentBatteryImageView);
917 view.setImageDrawable(ResourcesCompat.getDrawable(getResources(), id, null));
930 public void updateIsoSensitivity(String sv)
932 Log.v(TAG, "updateIsoSensitivity : " + sv);
936 public void updateWarning(String warning)
938 Log.v(TAG, "updateWarning : " + warning);
942 public void updateStorageStatus(String status)
944 Log.v(TAG, "updateStorageStatus : " + status);