1 package net.osdn.gokigen.gr2control.scene;
3 import android.util.Log;
5 import net.osdn.gokigen.gr2control.R;
6 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
7 import net.osdn.gokigen.gr2control.camera.ICameraStatusReceiver;
8 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
9 import net.osdn.gokigen.gr2control.liveview.IStatusViewDrawer;
10 import net.osdn.gokigen.gr2control.logcat.LogCatFragment;
11 import net.osdn.gokigen.gr2control.playback.ImageGridViewFragment;
12 import net.osdn.gokigen.gr2control.preference.fuji_x.FujiXPreferenceFragment;
13 import net.osdn.gokigen.gr2control.preference.olympus.PreferenceFragment;
14 import net.osdn.gokigen.gr2control.preference.ricohgr2.RicohGr2PreferenceFragment;
16 import androidx.annotation.NonNull;
17 import androidx.appcompat.app.AppCompatActivity;
18 import androidx.fragment.app.FragmentTransaction;
19 import androidx.preference.PreferenceFragmentCompat;
25 public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene
27 private final String TAG = toString();
28 private final AppCompatActivity activity;
29 private IInterfaceProvider interfaceProvider;
30 private IStatusViewDrawer statusViewDrawer;
32 private PreferenceFragmentCompat preferenceFragment = null;
33 private LogCatFragment logCatFragment = null;
34 private ImageGridViewFragment imageGridViewFragment = null;
36 public static CameraSceneUpdater newInstance(@NonNull AppCompatActivity activity)
38 return (new CameraSceneUpdater(activity));
45 private CameraSceneUpdater(@NonNull AppCompatActivity activity)
47 this.activity = activity;
51 public void registerInterface(@NonNull IStatusViewDrawer statusViewDrawer, @NonNull IInterfaceProvider interfaceProvider)
53 Log.v(TAG, "registerInterface()");
54 this.statusViewDrawer = statusViewDrawer;
55 this.interfaceProvider = interfaceProvider;
58 // ICameraStatusReceiver
60 public void onStatusNotify(String message)
62 Log.v(TAG, " CONNECTION MESSAGE : " + message);
65 if (statusViewDrawer != null)
67 statusViewDrawer.updateStatusView(message);
68 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
69 if (connection != null)
71 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
81 // ICameraStatusReceiver
83 public void onCameraConnected()
85 Log.v(TAG, "onCameraConnected()");
89 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
90 if (connection != null)
92 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
94 if (statusViewDrawer != null)
96 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
99 statusViewDrawer.startLiveView();
108 // ICameraStatusReceiver
110 public void onCameraDisconnected()
112 Log.v(TAG, "onCameraDisconnected()");
113 if (statusViewDrawer != null)
115 statusViewDrawer.updateStatusView(activity.getString(R.string.camera_disconnected));
116 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
120 // ICameraStatusReceiver
122 public void onCameraOccursException(String message, Exception e)
124 Log.v(TAG, "onCameraOccursException() " + message);
128 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
129 if (connection != null)
131 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
133 if (statusViewDrawer != null)
135 statusViewDrawer.updateStatusView(message);
136 if (connection != null)
138 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
144 ee.printStackTrace();
150 public void changeSceneToCameraPropertyList()
155 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
156 ICameraConnection connection = getCameraConnection(method);
157 if (method == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
159 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
160 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
162 else if (method == ICameraConnection.CameraConnectionMethod.SONY)
164 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
165 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
170 if (connection != null)
172 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
173 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
175 if (propertyListFragment == null)
177 propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
179 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
180 transaction.replace(R.id.fragment1, propertyListFragment);
182 transaction.addToBackStack(null);
183 transaction.commit();
197 public void changeSceneToConfiguration()
201 if (preferenceFragment == null)
205 //preferenceFragment = RicohGr2PreferenceFragment.newInstance(activity, this);
206 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
207 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2) {
208 preferenceFragment = RicohGr2PreferenceFragment.newInstance(activity, this);
209 //} else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
210 // preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
212 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
214 preferenceFragment = FujiXPreferenceFragment.newInstance(activity, this);
216 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
218 preferenceFragment = PreferenceFragment.newInstance(activity, interfaceProvider, this);
224 //preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
228 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
229 transaction.replace(R.id.fragment1, preferenceFragment);
231 transaction.addToBackStack(null);
232 transaction.commit();
242 public void changeCameraConnection()
244 if (interfaceProvider == null)
246 Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
251 interfaceProvider.resetCameraConnectionMethod();
252 ICameraConnection connection = interfaceProvider.getCameraConnection();
253 if (connection != null)
255 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
256 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
259 connection.disconnect(false);
263 connection.startWatchWifiStatus(activity);
274 public void changeSceneToDebugInformation()
276 if (logCatFragment == null)
278 logCatFragment = LogCatFragment.newInstance();
280 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
281 transaction.replace(R.id.fragment1, logCatFragment);
283 transaction.addToBackStack(null);
284 transaction.commit();
289 public void changeSceneToApiList()
292 if (sonyApiListFragmentSony == null)
294 sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
296 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
297 transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
299 transaction.addToBackStack(null);
300 transaction.commit();
310 public void changeScenceToImageList()
312 Log.v(TAG, "changeScenceToImageList()");
315 if (imageGridViewFragment == null)
317 imageGridViewFragment = ImageGridViewFragment.newInstance(interfaceProvider.getPlaybackControl(), interfaceProvider.getCameraRunMode());
319 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
320 transaction.replace(R.id.fragment1, imageGridViewFragment);
322 transaction.addToBackStack(null);
323 transaction.commit();
333 public void exitApplication()
335 Log.v(TAG, "exitApplication()");
338 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
339 if (connection != null)
341 connection.disconnect(true);
351 private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod method)
353 Log.v(TAG, "method : " + method);
354 return (interfaceProvider.getCameraConnection());