1 package net.osdn.gokigen.pkremote.scene;
3 import android.util.Log;
4 import android.widget.ImageButton;
5 import android.widget.TextView;
7 import com.google.android.material.bottomnavigation.BottomNavigationView;
9 import net.osdn.gokigen.pkremote.R;
10 import net.osdn.gokigen.pkremote.calendar.CalendarFragment;
11 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraConnection;
12 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentsRecognizer;
13 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusReceiver;
14 import net.osdn.gokigen.pkremote.camera.interfaces.IInterfaceProvider;
15 import net.osdn.gokigen.pkremote.logcat.LogCatFragment;
16 import net.osdn.gokigen.pkremote.playback.ImageGridViewFragment;
17 import net.osdn.gokigen.pkremote.preference.olympus.OpcPreferenceFragment;
18 import net.osdn.gokigen.pkremote.preference.ricohgr2.RicohGr2PreferenceFragment;
19 import net.osdn.gokigen.pkremote.transfer.AutoTransferFragment;
21 import androidx.annotation.NonNull;
22 import androidx.appcompat.app.AppCompatActivity;
23 import androidx.core.content.res.ResourcesCompat;
24 import androidx.fragment.app.FragmentTransaction;
25 import androidx.preference.PreferenceFragmentCompat;
31 public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene, ICameraContentsRecognizer.ICameraContentsListCallback
33 private final String TAG = toString();
34 private final AppCompatActivity activity;
35 private final BottomNavigationView bottomNavigationView;
36 private IInterfaceProvider interfaceProvider;
37 //private IStatusViewDrawer statusViewDrawer;
38 private ICameraStatusReceiver anotherStatusReceiver = null;
39 private PreferenceFragmentCompat preferenceFragment = null;
40 private LogCatFragment logCatFragment = null;
41 private CalendarFragment calendarFragment = null;
42 private ImageGridViewFragment gridViewFragment = null;
43 private AutoTransferFragment autoTransferFragment = null;
45 public static CameraSceneUpdater newInstance(@NonNull AppCompatActivity activity)
47 return (new CameraSceneUpdater(activity));
53 private CameraSceneUpdater(@NonNull AppCompatActivity activity)
55 this.activity = activity;
56 this.bottomNavigationView = activity.findViewById(R.id.navigation);
62 public void changeFirstFragment(@NonNull IInterfaceProvider interfaceProvider)
64 this.interfaceProvider = interfaceProvider;
67 bottomNavigationView.setSelectedItemId(R.id.navigation_calendar);
75 changeSceneToCalendar();
80 public void registerInterface(@NonNull IStatusViewDrawer statusViewDrawer, @NonNull IInterfaceProvider interfaceProvider)
82 Log.v(TAG, "registerInterface()");
83 this.statusViewDrawer = statusViewDrawer;
84 this.interfaceProvider = interfaceProvider;
88 // ICameraStatusReceiver
90 public void onStatusNotify(String message)
92 Log.v(TAG, " CONNECTION MESSAGE : " + message);
95 if (statusViewDrawer != null)
97 statusViewDrawer.updateStatusView(message);
98 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
99 if (connection != null) {
100 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
104 if (anotherStatusReceiver != null)
106 anotherStatusReceiver.onStatusNotify(message);
108 } catch (Exception e) {
113 // ICameraStatusReceiver
115 public void onCameraConnected() {
116 Log.v(TAG, "onCameraConnected()");
117 updateConnectionStatus(activity.getString(R.string.connect_connected), ICameraConnection.CameraConnectionStatus.CONNECTED);
119 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
120 if (connection != null) {
121 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
124 if (statusViewDrawer != null)
126 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
128 // ライブビューの開始... 今回は手動化。
129 //statusViewDrawer.startLiveView();
132 if (anotherStatusReceiver != null) {
133 anotherStatusReceiver.onCameraConnected();
135 ICameraContentsRecognizer recognizer = interfaceProvider.getCameraContentsRecognizer();
136 if (recognizer != null) {
137 // カメラ内のコンテンツ一覧を作成するように指示する
138 recognizer.getRemoteCameraContentsList(true, this);
140 } catch (Exception e) {
145 // ICameraStatusReceiver
147 public void onCameraDisconnected() {
148 Log.v(TAG, "onCameraDisconnected()");
149 String message = activity.getString(R.string.camera_disconnected);
150 updateConnectionStatus(message, ICameraConnection.CameraConnectionStatus.DISCONNECTED);
153 if (statusViewDrawer != null) {
154 statusViewDrawer.updateStatusView(activity.getString(R.string.camera_disconnected));
155 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
158 if (anotherStatusReceiver != null) {
159 anotherStatusReceiver.onCameraDisconnected();
161 } catch (Exception e) {
166 // ICameraStatusReceiver
168 public void onCameraOccursException(String message, Exception e) {
169 Log.v(TAG, "onCameraOccursException() " + message);
171 ICameraConnection.CameraConnectionStatus connectionStatus; // = ICameraConnection.CameraConnectionStatus.UNKNOWN;
174 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
175 if (connection != null) {
176 connectionStatus = connection.getConnectionStatus();
177 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
178 updateConnectionStatus(message, connectionStatus);
181 if (statusViewDrawer != null) {
182 statusViewDrawer.updateStatusView(message);
183 if (connection != null) {
184 statusViewDrawer.updateConnectionStatus(connectionStatus);
188 if (anotherStatusReceiver != null) {
189 anotherStatusReceiver.onCameraOccursException(message, e);
191 } catch (Exception ee) {
192 ee.printStackTrace();
199 private void updateConnectionStatus(final String message, final ICameraConnection.CameraConnectionStatus status) {
204 resId = R.drawable.ic_cloud_done_black_24dp;
207 resId = R.drawable.ic_cloud_queue_black_24dp;
210 resId = R.drawable.ic_cloud_off_black_24dp;
214 resId = R.drawable.ic_cloud_queue_grey_24dp;
217 final TextView messageArea = activity.findViewById(R.id.message);
218 final ImageButton buttonArea = activity.findViewById(R.id.button_wifi_connect);
219 activity.runOnUiThread(new Runnable() {
223 if (buttonArea != null) {
224 buttonArea.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(), resId, null));
225 buttonArea.invalidate();
227 if ((messageArea != null) && (message != null)) {
228 messageArea.setText(message);
229 messageArea.invalidate();
231 } catch (Exception e) {
236 } catch (Exception e) {
243 public void changeSceneToCameraPropertyList()
248 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
249 ICameraConnection connection = getCameraConnection(method);
250 if (method == ICameraConnection.CameraConnectionMethod.RICOH)
252 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
253 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
255 else if (method == ICameraConnection.CameraConnectionMethod.SONY)
257 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
258 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
263 if (connection != null)
265 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
266 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
268 if (propertyListFragment == null)
270 propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
272 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
273 transaction.replace(R.id.fragment1, propertyListFragment);
275 transaction.addToBackStack(null);
276 transaction.commit();
290 public void changeSceneToConfiguration()
293 if (preferenceFragment == null) {
295 preferenceFragment = RicohGr2PreferenceFragment.newInstance(activity, this);
296 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
297 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH) {
298 preferenceFragment = RicohGr2PreferenceFragment.newInstance(activity, this);
299 //} else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
300 // preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
301 } else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
303 preferenceFragment = OpcPreferenceFragment.newInstance(activity, interfaceProvider, this);
305 } catch (Exception e) {
307 //preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
311 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
312 transaction.replace(R.id.fragment1, preferenceFragment);
314 transaction.addToBackStack(null);
315 transaction.commit();
316 } catch (Exception e) {
323 public void changeCameraConnection()
325 if (interfaceProvider == null) {
326 Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
330 interfaceProvider.resetCameraConnectionMethod();
331 ICameraConnection connection = interfaceProvider.getCameraConnection();
332 if (connection != null) {
333 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
334 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED) {
336 connection.disconnect(false);
340 connection.startWatchWifiStatus(activity);
342 } catch (Exception e) {
349 public void reloadRemoteImageContents()
353 ICameraContentsRecognizer recognizer = interfaceProvider.getCameraContentsRecognizer();
354 if (recognizer != null) {
355 // カメラ内のコンテンツ一覧を作成するように指示する
356 recognizer.getRemoteCameraContentsList(true, this);
358 } catch (Exception e) {
365 public void changeSceneToDebugInformation()
367 if (logCatFragment == null) {
368 logCatFragment = LogCatFragment.newInstance();
370 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
371 transaction.replace(R.id.fragment1, logCatFragment);
373 transaction.addToBackStack(null);
374 transaction.commit();
379 public void changeSceneToApiList()
382 if (sonyApiListFragmentSony == null)
384 sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
386 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
387 transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
389 transaction.addToBackStack(null);
390 transaction.commit();
396 public void changeSceneToAutoTransfer()
398 if (autoTransferFragment == null)
400 autoTransferFragment = AutoTransferFragment.newInstance(activity, interfaceProvider);
402 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
403 transaction.replace(R.id.fragment1, autoTransferFragment);
405 transaction.addToBackStack(null);
406 transaction.commit();
411 public void changeSceneToCalendar()
413 if (calendarFragment == null)
415 calendarFragment = CalendarFragment.newInstance(activity, this, interfaceProvider);
417 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
418 transaction.replace(R.id.fragment1, calendarFragment);
420 transaction.addToBackStack(null);
421 transaction.commit();
426 public void changeScenceDateSelected(String filterLabel)
428 Log.v(TAG, "changeScenceDateSelected()");
430 bottomNavigationView.setSelectedItemId(R.id.navigation_photo_library);
431 changeScenceToImageList(filterLabel);
439 public void changeScenceToImageList()
441 changeScenceToImageList(null);
448 private void changeScenceToImageList(String filterLabel)
450 Log.v(TAG, "changeScenceToImageList() : " + filterLabel);
453 if (gridViewFragment == null)
455 gridViewFragment = ImageGridViewFragment.newInstance(interfaceProvider);
457 gridViewFragment.setFilterLabel(filterLabel);
458 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
459 transaction.replace(R.id.fragment1, gridViewFragment);
461 transaction.addToBackStack(null);
462 transaction.commit();
472 public void exitApplication()
474 Log.v(TAG, "exitApplication()");
477 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
478 if (connection != null)
480 connection.disconnect(true);
491 public void updateBottomNavigationMenu()
495 // ナビゲーション部分の選択状態をしたい...
497 if (calendarFragment.isFragmentActive())
499 changeId = R.id.navigation_calendar;
501 else if (gridViewFragment.isFragmentActive())
503 changeId = R.id.navigation_photo_library;
505 if ((bottomNavigationView != null)&&(changeId != 0))
507 bottomNavigationView.setSelectedItemId(changeId);
517 public void setAnotherStatusReceiver(ICameraStatusReceiver statusReceiver)
519 this.anotherStatusReceiver = statusReceiver;
522 private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod method)
524 Log.v(TAG, "method : " + method);
525 return (interfaceProvider.getCameraConnection());
529 public void contentsListCreated(int nofContents)
531 Log.v(TAG, "contentsListCreated() : " + nofContents);
533 // カレンダー画面のリフレッシュを行いたい (かなり無理やり...)
534 if ((calendarFragment != null)&&(calendarFragment.isFragmentActive()))
536 calendarFragment.contentsListCreated(nofContents);