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.camera.vendor.sony.cameraproperty.SonyCameraApiListFragment;
16 import net.osdn.gokigen.pkremote.logcat.LogCatFragment;
17 import net.osdn.gokigen.pkremote.playback.ImageGridViewFragment;
18 import net.osdn.gokigen.pkremote.preference.canon.CanonPreferenceFragment;
19 import net.osdn.gokigen.pkremote.preference.fujix.FujiXPreferenceFragment;
20 import net.osdn.gokigen.pkremote.preference.nikon.NikonPreferenceFragment;
21 import net.osdn.gokigen.pkremote.preference.olympus.OpcPreferenceFragment;
22 import net.osdn.gokigen.pkremote.preference.olympuspen.OlympusPenPreferenceFragment;
23 import net.osdn.gokigen.pkremote.preference.panasonic.PanasonicPreferenceFragment;
24 import net.osdn.gokigen.pkremote.preference.ricohgr2.RicohGr2PreferenceFragment;
25 import net.osdn.gokigen.pkremote.preference.sony.SonyPreferenceFragment;
26 import net.osdn.gokigen.pkremote.transfer.AutoTransferFragment;
28 import androidx.annotation.NonNull;
29 import androidx.appcompat.app.AppCompatActivity;
30 import androidx.core.content.res.ResourcesCompat;
31 import androidx.fragment.app.FragmentTransaction;
32 import androidx.preference.PreferenceFragmentCompat;
38 public class CameraSceneUpdater implements ICameraStatusReceiver, IChangeScene, ICameraContentsRecognizer.ICameraContentsListCallback
40 private final String TAG = toString();
41 private final AppCompatActivity activity;
42 private final BottomNavigationView bottomNavigationView;
43 private IInterfaceProvider interfaceProvider;
44 //private IStatusViewDrawer statusViewDrawer;
45 private ICameraStatusReceiver anotherStatusReceiver = null;
46 private PreferenceFragmentCompat preferenceFragment = null;
47 private LogCatFragment logCatFragment = null;
48 private CalendarFragment calendarFragment = null;
49 private ImageGridViewFragment gridViewFragment = null;
50 private AutoTransferFragment autoTransferFragment = null;
51 private SonyCameraApiListFragment sonyApiListFragmentSony = null;
53 public static CameraSceneUpdater newInstance(@NonNull AppCompatActivity activity)
55 return (new CameraSceneUpdater(activity));
61 private CameraSceneUpdater(@NonNull AppCompatActivity activity)
63 this.activity = activity;
64 this.bottomNavigationView = activity.findViewById(R.id.navigation);
70 public void changeFirstFragment(@NonNull IInterfaceProvider interfaceProvider)
72 this.interfaceProvider = interfaceProvider;
75 bottomNavigationView.setSelectedItemId(R.id.navigation_calendar);
83 changeSceneToCalendar();
88 public void registerInterface(@NonNull IStatusViewDrawer statusViewDrawer, @NonNull IInterfaceProvider interfaceProvider)
90 Log.v(TAG, "registerInterface()");
91 this.statusViewDrawer = statusViewDrawer;
92 this.interfaceProvider = interfaceProvider;
96 // ICameraStatusReceiver
98 public void onStatusNotify(String message)
100 Log.v(TAG, " CONNECTION MESSAGE : " + message);
103 if (statusViewDrawer != null)
105 statusViewDrawer.updateStatusView(message);
106 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
107 if (connection != null) {
108 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
112 if (anotherStatusReceiver != null)
114 anotherStatusReceiver.onStatusNotify(message);
116 } catch (Exception e) {
121 // ICameraStatusReceiver
123 public void onCameraConnected() {
124 Log.v(TAG, "onCameraConnected()");
125 updateConnectionStatus(activity.getString(R.string.connect_connected), ICameraConnection.CameraConnectionStatus.CONNECTED);
127 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
128 if (connection != null) {
129 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
132 if (statusViewDrawer != null)
134 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
136 // ライブビューの開始... 今回は手動化。
137 //statusViewDrawer.startLiveView();
140 if (anotherStatusReceiver != null) {
141 anotherStatusReceiver.onCameraConnected();
143 ICameraContentsRecognizer recognizer = interfaceProvider.getCameraContentsRecognizer();
144 if (recognizer != null) {
145 // カメラ内のコンテンツ一覧を作成するように指示する
146 recognizer.getRemoteCameraContentsList(true, this);
148 } catch (Exception e) {
153 // ICameraStatusReceiver
155 public void onCameraDisconnected() {
156 Log.v(TAG, "onCameraDisconnected()");
157 String message = activity.getString(R.string.camera_disconnected);
158 updateConnectionStatus(message, ICameraConnection.CameraConnectionStatus.DISCONNECTED);
161 if (statusViewDrawer != null) {
162 statusViewDrawer.updateStatusView(activity.getString(R.string.camera_disconnected));
163 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
166 if (anotherStatusReceiver != null) {
167 anotherStatusReceiver.onCameraDisconnected();
169 } catch (Exception e) {
174 // ICameraStatusReceiver
176 public void onCameraOccursException(String message, Exception e) {
177 Log.v(TAG, "onCameraOccursException() " + message);
179 ICameraConnection.CameraConnectionStatus connectionStatus; // = ICameraConnection.CameraConnectionStatus.UNKNOWN;
182 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
183 if (connection != null) {
184 connectionStatus = connection.getConnectionStatus();
185 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
186 updateConnectionStatus(message, connectionStatus);
189 if (statusViewDrawer != null) {
190 statusViewDrawer.updateStatusView(message);
191 if (connection != null) {
192 statusViewDrawer.updateConnectionStatus(connectionStatus);
196 if (anotherStatusReceiver != null) {
197 anotherStatusReceiver.onCameraOccursException(message, e);
199 } catch (Exception ee) {
200 ee.printStackTrace();
207 private void updateConnectionStatus(final String message, final ICameraConnection.CameraConnectionStatus status) {
212 resId = R.drawable.ic_cloud_done_black_24dp;
215 resId = R.drawable.ic_cloud_queue_black_24dp;
218 resId = R.drawable.ic_cloud_off_black_24dp;
222 resId = R.drawable.ic_cloud_queue_grey_24dp;
225 final TextView messageArea = activity.findViewById(R.id.message);
226 final ImageButton buttonArea = activity.findViewById(R.id.button_wifi_connect);
227 activity.runOnUiThread(new Runnable() {
231 if (buttonArea != null) {
232 buttonArea.setImageDrawable(ResourcesCompat.getDrawable(activity.getResources(), resId, null));
233 buttonArea.invalidate();
235 if ((messageArea != null) && (message != null)) {
236 messageArea.setText(message);
237 messageArea.invalidate();
239 } catch (Exception e) {
244 } catch (Exception e) {
251 public void changeSceneToCameraPropertyList()
256 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
257 ICameraConnection connection = getCameraConnection(method);
258 if (method == ICameraConnection.CameraConnectionMethod.RICOH)
260 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
261 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
263 else if (method == ICameraConnection.CameraConnectionMethod.SONY)
265 // OPCカメラでない場合には、「OPCカメラのみ有効です」表示をして画面遷移させない
266 Toast.makeText(getApplicationContext(), getText(R.string.only_opc_feature), Toast.LENGTH_SHORT).show();
271 if (connection != null)
273 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
274 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
276 if (propertyListFragment == null)
278 propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
280 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
281 transaction.replace(R.id.fragment1, propertyListFragment);
283 transaction.addToBackStack(null);
284 transaction.commit();
298 public void changeSceneToConfiguration()
302 if (preferenceFragment == null)
306 //preferenceFragment = RicohGr2PreferenceFragment.newInstance(activity, this);
307 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
308 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH)
310 preferenceFragment = RicohGr2PreferenceFragment.newInstance(activity, this);
312 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
314 preferenceFragment = FujiXPreferenceFragment.newInstance(activity, this);
315 //} else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
316 // preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
318 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
320 preferenceFragment = PanasonicPreferenceFragment.newInstance(activity, this);
322 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
324 preferenceFragment = SonyPreferenceFragment.newInstance(activity, this);
326 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.CANON)
328 preferenceFragment = CanonPreferenceFragment.newInstance(activity, this);
330 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.NIKON)
332 preferenceFragment = NikonPreferenceFragment.newInstance(activity, this);
334 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS)
336 preferenceFragment = OlympusPenPreferenceFragment.newInstance(activity, this);
338 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
340 preferenceFragment = OpcPreferenceFragment.newInstance(activity, interfaceProvider, this);
346 //preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
349 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
350 transaction.replace(R.id.fragment1, preferenceFragment);
352 transaction.addToBackStack(null);
353 transaction.commit();
363 public void changeCameraConnection()
365 if (interfaceProvider == null)
367 Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
372 interfaceProvider.resetCameraConnectionMethod();
373 ICameraConnection connection = interfaceProvider.getCameraConnection();
374 if (connection != null)
376 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
377 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
380 connection.disconnect(false);
384 connection.startWatchWifiStatus(activity);
395 public void reloadRemoteImageContents()
399 ICameraContentsRecognizer recognizer = interfaceProvider.getCameraContentsRecognizer();
400 if (recognizer != null)
402 // カメラ内のコンテンツ一覧を作成するように指示する
403 recognizer.getRemoteCameraContentsList(true, this);
405 if (gridViewFragment != null)
407 // サムネイル画像のキャッシュをクリアする
408 gridViewFragment.clearImageCache();
419 public void changeSceneToDebugInformation()
421 if (logCatFragment == null) {
422 logCatFragment = LogCatFragment.newInstance();
424 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
425 transaction.replace(R.id.fragment1, logCatFragment);
427 transaction.addToBackStack(null);
428 transaction.commit();
433 public void changeSceneToApiList()
435 if (sonyApiListFragmentSony == null)
437 sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
439 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
440 transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
442 transaction.addToBackStack(null);
443 transaction.commit();
448 public void changeSceneToAutoTransfer()
450 if (autoTransferFragment == null)
452 autoTransferFragment = AutoTransferFragment.newInstance(activity, interfaceProvider);
454 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
455 transaction.replace(R.id.fragment1, autoTransferFragment);
457 transaction.addToBackStack(null);
458 transaction.commit();
463 public void changeSceneToCalendar()
465 if (calendarFragment == null)
467 calendarFragment = CalendarFragment.newInstance(activity, this, interfaceProvider);
469 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
470 transaction.replace(R.id.fragment1, calendarFragment);
472 transaction.addToBackStack(null);
473 transaction.commit();
478 public void changeScenceDateSelected(String filterLabel)
480 Log.v(TAG, "changeScenceDateSelected()");
482 bottomNavigationView.setSelectedItemId(R.id.navigation_photo_library);
483 changeScenceToImageList(filterLabel);
491 public void changeScenceToImageList()
493 changeScenceToImageList(null);
500 private void changeScenceToImageList(String filterLabel)
502 Log.v(TAG, "changeScenceToImageList() : " + filterLabel);
505 if (gridViewFragment == null)
507 gridViewFragment = ImageGridViewFragment.newInstance(interfaceProvider);
509 gridViewFragment.setFilterLabel(filterLabel);
510 FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
511 transaction.replace(R.id.fragment1, gridViewFragment);
513 transaction.addToBackStack(null);
514 transaction.commit();
524 public void exitApplication()
526 Log.v(TAG, "exitApplication()");
529 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
530 if (connection != null)
532 connection.disconnect(true);
543 public void updateBottomNavigationMenu()
547 // ナビゲーション部分の選択状態をしたい...
549 if (calendarFragment.isFragmentActive())
551 changeId = R.id.navigation_calendar;
553 else if (gridViewFragment.isFragmentActive())
555 changeId = R.id.navigation_photo_library;
557 if ((bottomNavigationView != null)&&(changeId != 0))
559 bottomNavigationView.setSelectedItemId(changeId);
569 public void setAnotherStatusReceiver(ICameraStatusReceiver statusReceiver)
571 this.anotherStatusReceiver = statusReceiver;
574 private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod method)
576 Log.v(TAG, "method : " + method);
577 return (interfaceProvider.getCameraConnection());
581 public void contentsListCreated(int nofContents)
583 Log.v(TAG, "contentsListCreated() : " + nofContents);
585 // カレンダー画面のリフレッシュを行いたい (かなり無理やり...)
586 if ((calendarFragment != null)&&(calendarFragment.isFragmentActive()))
588 calendarFragment.contentsListCreated(nofContents);