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.preference.ricohgr2.RicohGr2PreferenceFragment;
21 public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene
23 private final String TAG = toString();
24 private final AppCompatActivity activity;
25 private IInterfaceProvider interfaceProvider;
26 private IStatusViewDrawer statusViewDrawer;
28 private PreferenceFragmentCompat preferenceFragment = null;
29 private LogCatFragment logCatFragment = null;
31 public static CameraSceneUpdater newInstance(@NonNull AppCompatActivity activity)
33 return (new CameraSceneUpdater(activity));
40 private CameraSceneUpdater(@NonNull AppCompatActivity activity)
42 this.activity = activity;
46 public void registerInterface(@NonNull IStatusViewDrawer statusViewDrawer, @NonNull IInterfaceProvider interfaceProvider)
48 Log.v(TAG, "registerInterface()");
49 this.statusViewDrawer = statusViewDrawer;
50 this.interfaceProvider = interfaceProvider;
53 // ICameraStatusReceiver
55 public void onStatusNotify(String message)
57 Log.v(TAG, " CONNECTION MESSAGE : " + message);
60 if (statusViewDrawer != null)
62 statusViewDrawer.updateStatusView(message);
63 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
64 if (connection != null)
66 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
76 // ICameraStatusReceiver
78 public void onCameraConnected()
80 Log.v(TAG, "onCameraConnected()");
84 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
85 if (connection != null)
87 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
89 if (statusViewDrawer != null)
91 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
94 statusViewDrawer.startLiveView();
103 // ICameraStatusReceiver
105 public void onCameraDisconnected()
107 Log.v(TAG, "onCameraDisconnected()");
108 if (statusViewDrawer != null)
110 statusViewDrawer.updateStatusView(activity.getString(R.string.camera_disconnected));
111 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
115 // ICameraStatusReceiver
117 public void onCameraOccursException(String message, Exception e)
119 Log.v(TAG, "onCameraOccursException() " + message);
123 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
124 if (connection != null)
126 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
128 if (statusViewDrawer != null)
130 statusViewDrawer.updateStatusView(message);
131 if (connection != null)
133 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
139 ee.printStackTrace();
145 public void changeSceneToCameraPropertyList()
150 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
151 ICameraConnection connection = getCameraConnection(method);
152 if (method == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
154 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
155 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
157 else if (method == ICameraConnection.CameraConnectionMethod.SONY)
159 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
160 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
165 if (connection != null)
167 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
168 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
170 if (propertyListFragment == null)
172 propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
174 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
175 transaction.replace(R.id.fragment1, propertyListFragment);
177 transaction.addToBackStack(null);
178 transaction.commit();
192 public void changeSceneToConfiguration()
196 if (preferenceFragment == null)
200 preferenceFragment = RicohGr2PreferenceFragment.newInstance(activity, this);
202 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
203 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2) {
204 preferenceFragment = RicohGr2PreferenceFragment.newInstance(this, this);
205 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
206 preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
207 } else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
209 preferenceFragment = PreferenceFragment.newInstance(this, interfaceProvider, this);
216 //preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
220 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
221 transaction.replace(R.id.fragment1, preferenceFragment);
223 transaction.addToBackStack(null);
224 transaction.commit();
234 public void changeCameraConnection()
236 if (interfaceProvider == null)
238 Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
243 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
244 if (connection != null)
246 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
247 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
250 connection.disconnect(false);
254 connection.startWatchWifiStatus(activity);
265 public void changeSceneToDebugInformation()
267 if (logCatFragment == null)
269 logCatFragment = LogCatFragment.newInstance();
271 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
272 transaction.replace(R.id.fragment1, logCatFragment);
274 transaction.addToBackStack(null);
275 transaction.commit();
280 public void changeSceneToApiList()
283 if (sonyApiListFragmentSony == null)
285 sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
287 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
288 transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
290 transaction.addToBackStack(null);
291 transaction.commit();
297 public void exitApplication()
299 Log.v(TAG, "exitApplication()");
302 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
303 if (connection != null)
305 connection.disconnect(true);
315 private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod method)
317 Log.v(TAG, "method : " + method);
318 return (interfaceProvider.getRicohGr2Infterface().getRicohGr2CameraConnection());