1 package net.osdn.gokigen.gr2control.scene;
3 import android.support.annotation.NonNull;
4 import android.support.v4.app.FragmentTransaction;
5 import android.support.v7.app.AppCompatActivity;
6 import android.support.v7.preference.PreferenceFragmentCompat;
7 import android.util.Log;
9 import net.osdn.gokigen.gr2control.R;
10 import net.osdn.gokigen.gr2control.camera.ICameraConnection;
11 import net.osdn.gokigen.gr2control.camera.ICameraStatusReceiver;
12 import net.osdn.gokigen.gr2control.camera.IInterfaceProvider;
13 import net.osdn.gokigen.gr2control.liveview.IStatusViewDrawer;
14 import net.osdn.gokigen.gr2control.logcat.LogCatFragment;
15 import net.osdn.gokigen.gr2control.playback.ImageGridViewFragment;
16 import net.osdn.gokigen.gr2control.preference.ricohgr2.RicohGr2PreferenceFragment;
22 public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene
24 private final String TAG = toString();
25 private final AppCompatActivity activity;
26 private IInterfaceProvider interfaceProvider;
27 private IStatusViewDrawer statusViewDrawer;
29 private PreferenceFragmentCompat preferenceFragment = null;
30 private LogCatFragment logCatFragment = null;
32 public static CameraSceneUpdater newInstance(@NonNull AppCompatActivity activity)
34 return (new CameraSceneUpdater(activity));
41 private CameraSceneUpdater(@NonNull AppCompatActivity activity)
43 this.activity = activity;
47 public void registerInterface(@NonNull IStatusViewDrawer statusViewDrawer, @NonNull IInterfaceProvider interfaceProvider)
49 Log.v(TAG, "registerInterface()");
50 this.statusViewDrawer = statusViewDrawer;
51 this.interfaceProvider = interfaceProvider;
54 // ICameraStatusReceiver
56 public void onStatusNotify(String message)
58 Log.v(TAG, " CONNECTION MESSAGE : " + message);
61 if (statusViewDrawer != null)
63 statusViewDrawer.updateStatusView(message);
64 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
65 if (connection != null)
67 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
77 // ICameraStatusReceiver
79 public void onCameraConnected()
81 Log.v(TAG, "onCameraConnected()");
85 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
86 if (connection != null)
88 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
90 if (statusViewDrawer != null)
92 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
95 statusViewDrawer.startLiveView();
104 // ICameraStatusReceiver
106 public void onCameraDisconnected()
108 Log.v(TAG, "onCameraDisconnected()");
109 if (statusViewDrawer != null)
111 statusViewDrawer.updateStatusView(activity.getString(R.string.camera_disconnected));
112 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
116 // ICameraStatusReceiver
118 public void onCameraOccursException(String message, Exception e)
120 Log.v(TAG, "onCameraOccursException() " + message);
124 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
125 if (connection != null)
127 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
129 if (statusViewDrawer != null)
131 statusViewDrawer.updateStatusView(message);
132 if (connection != null)
134 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
140 ee.printStackTrace();
146 public void changeSceneToCameraPropertyList()
151 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
152 ICameraConnection connection = getCameraConnection(method);
153 if (method == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
155 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
156 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
158 else if (method == ICameraConnection.CameraConnectionMethod.SONY)
160 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
161 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
166 if (connection != null)
168 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
169 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
171 if (propertyListFragment == null)
173 propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
175 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
176 transaction.replace(R.id.fragment1, propertyListFragment);
178 transaction.addToBackStack(null);
179 transaction.commit();
193 public void changeSceneToConfiguration()
197 if (preferenceFragment == null)
201 preferenceFragment = RicohGr2PreferenceFragment.newInstance(activity, this);
203 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
204 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2) {
205 preferenceFragment = RicohGr2PreferenceFragment.newInstance(this, this);
206 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
207 preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
208 } else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
210 preferenceFragment = PreferenceFragment.newInstance(this, interfaceProvider, this);
217 //preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
221 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
222 transaction.replace(R.id.fragment1, preferenceFragment);
224 transaction.addToBackStack(null);
225 transaction.commit();
235 public void changeCameraConnection()
237 if (interfaceProvider == null)
239 Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
244 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
245 if (connection != null)
247 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
248 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
251 connection.disconnect(false);
255 connection.startWatchWifiStatus(activity);
266 public void changeSceneToDebugInformation()
268 if (logCatFragment == null)
270 logCatFragment = LogCatFragment.newInstance();
272 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
273 transaction.replace(R.id.fragment1, logCatFragment);
275 transaction.addToBackStack(null);
276 transaction.commit();
281 public void changeSceneToApiList()
284 if (sonyApiListFragmentSony == null)
286 sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
288 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
289 transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
291 transaction.addToBackStack(null);
292 transaction.commit();
302 public void changeScenceToImageList()
304 Log.v(TAG, "changeScenceToImageList()");
307 ImageGridViewFragment fragment = ImageGridViewFragment.newInstance(interfaceProvider.getRicohGr2Infterface().getPlaybackControl());
308 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
309 transaction.replace(R.id.fragment1, fragment);
311 transaction.addToBackStack(null);
312 transaction.commit();
322 public void exitApplication()
324 Log.v(TAG, "exitApplication()");
327 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
328 if (connection != null)
330 connection.disconnect(true);
340 private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod method)
342 Log.v(TAG, "method : " + method);
343 return (interfaceProvider.getRicohGr2Infterface().getRicohGr2CameraConnection());