1 package net.osdn.gokigen.a01d;
3 import android.Manifest;
4 import android.content.SharedPreferences;
5 import android.content.pm.PackageManager;
6 import android.graphics.Color;
7 import android.graphics.Typeface;
8 import android.os.Bundle;
9 import android.util.Log;
10 import android.view.KeyEvent;
11 import android.view.WindowManager;
12 import android.widget.TextView;
14 import net.osdn.gokigen.a01d.camera.CameraInterfaceProvider;
15 import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
16 import net.osdn.gokigen.a01d.camera.fujix.cameraproperty.FujiXCameraCommandSendDialog;
17 import net.osdn.gokigen.a01d.camera.olympus.cameraproperty.OlyCameraPropertyListFragment;
18 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
19 import net.osdn.gokigen.a01d.camera.ICameraConnection;
20 import net.osdn.gokigen.a01d.camera.olympus.wrapper.connection.ble.ICameraPowerOn;
21 import net.osdn.gokigen.a01d.camera.ptpip.operation.PtpIpCameraCommandSendDialog;
22 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpSendCommandDialog;
23 import net.osdn.gokigen.a01d.camera.panasonic.operation.PanasonicSendCommandDialog;
24 import net.osdn.gokigen.a01d.camera.ricohgr2.operation.RicohGr2SendCommandDialog;
25 import net.osdn.gokigen.a01d.camera.sony.cameraproperty.SonyCameraApiListFragment;
26 import net.osdn.gokigen.a01d.liveview.IStatusViewDrawer;
27 import net.osdn.gokigen.a01d.liveview.LiveViewFragment;
28 import net.osdn.gokigen.a01d.logcat.LogCatFragment;
29 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
30 import net.osdn.gokigen.a01d.preference.canon.CanonPreferenceFragment;
31 import net.osdn.gokigen.a01d.preference.fujix.FujiXPreferenceFragment;
32 import net.osdn.gokigen.a01d.preference.nikon.NikonPreferenceFragment;
33 import net.osdn.gokigen.a01d.preference.olympus.PreferenceFragment;
34 import net.osdn.gokigen.a01d.preference.panasonic.PanasonicPreferenceFragment;
35 import net.osdn.gokigen.a01d.preference.olympuspen.OlympusPreferenceFragment;
36 import net.osdn.gokigen.a01d.preference.ricohgr2.RicohGr2PreferenceFragment;
37 import net.osdn.gokigen.a01d.preference.sony.SonyPreferenceFragment;
38 import net.osdn.gokigen.a01d.preference.summary.PreferenceFragmentSummary;
39 import net.osdn.gokigen.a01d.preference.theta.ThetaPreferenceFragment;
41 import androidx.annotation.NonNull;
42 import androidx.appcompat.app.ActionBar;
43 import androidx.appcompat.app.AppCompatActivity;
44 import androidx.core.app.ActivityCompat;
45 import androidx.core.content.ContextCompat;
46 import androidx.fragment.app.FragmentTransaction;
47 import androidx.preference.PreferenceFragmentCompat;
48 import androidx.preference.PreferenceManager;
50 import java.util.HashMap;
57 public class A01dMain extends AppCompatActivity implements ICameraStatusReceiver, IChangeScene, ICameraPowerOn.PowerOnCameraCallback, IInformationReceiver
59 private final String TAG = toString();
60 private IInterfaceProvider interfaceProvider = null;
61 private IStatusViewDrawer statusViewDrawer = null;
63 private PreferenceFragmentCompat preferenceFragment = null;
64 private PreferenceFragmentCompat preferenceFragmentOPC = null;
65 private PreferenceFragmentCompat preferenceFragmentOlympus = null;
66 private PreferenceFragmentCompat preferenceFragmentSony = null;
67 private PreferenceFragmentCompat preferenceFragmentRicoh = null;
68 private PreferenceFragmentCompat preferenceFragmentTheta = null;
69 private PreferenceFragmentCompat preferenceFragmentFuji = null;
70 private PreferenceFragmentCompat preferenceFragmentPanasonic = null;
71 private PreferenceFragmentCompat preferenceFragmentCanon = null;
72 private PreferenceFragmentCompat preferenceFragmentNikon = null;
74 private OlyCameraPropertyListFragment propertyListFragment = null;
75 private SonyCameraApiListFragment sonyApiListFragmentSony = null;
76 private LogCatFragment logCatFragment = null;
77 private LiveViewFragment liveViewFragment = null;
80 protected void onCreate(Bundle savedInstanceState)
82 final int REQUEST_NEED_PERMISSIONS = 1010;
84 super.onCreate(savedInstanceState);
88 if (Build.VERSION.SDK_INT >= 19)
90 View decor = this.getWindow().getDecorView();
91 decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
93 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
101 setContentView(R.layout.activity_a01d_main);
103 ActionBar bar = getSupportActionBar();
108 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
111 if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
112 (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
113 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_MEDIA_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
114 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) ||
115 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) ||
116 (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) ||
117 (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) != PackageManager.PERMISSION_GRANTED) ||
118 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
119 (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED)) {
120 ActivityCompat.requestPermissions(this,
122 Manifest.permission.WRITE_EXTERNAL_STORAGE,
123 Manifest.permission.READ_EXTERNAL_STORAGE,
124 Manifest.permission.ACCESS_MEDIA_LOCATION,
125 Manifest.permission.ACCESS_NETWORK_STATE,
126 Manifest.permission.ACCESS_WIFI_STATE,
127 Manifest.permission.BLUETOOTH,
128 Manifest.permission.BLUETOOTH_ADMIN,
129 Manifest.permission.ACCESS_COARSE_LOCATION,
130 Manifest.permission.INTERNET,
132 REQUEST_NEED_PERMISSIONS);
135 initializeFragment();
140 * なぜか、onReadyClass() が有効ではなさそうなので...
144 public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
146 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
153 private void initializeClass()
157 interfaceProvider = new CameraInterfaceProvider(this, this, this);
168 private void onReadyClass()
172 // BLEでPower ONは、OPCのみ対応
173 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
175 // BLEでカメラの電源をONにする設定だった時
178 // カメラの電源ONクラスを呼び出しておく (電源ONができたら、コールバックをもらう)
179 interfaceProvider.getOlympusInterface().getCameraPowerOn().wakeup(this);
187 else if (isAutoConnectCamera())
190 changeCameraConnection();
197 private void initializeFragment()
201 //if (liveViewFragment == null)
203 liveViewFragment = LiveViewFragment.newInstance(this, interfaceProvider);
205 statusViewDrawer = liveViewFragment;
206 liveViewFragment.setRetainInstance(true);
207 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
208 transaction.replace(R.id.fragment1, liveViewFragment);
209 transaction.commitAllowingStateLoss();
221 protected void onPause()
226 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
227 ICameraConnection connection = getCameraConnection(method);
228 if (connection != null)
230 connection.stopWatchWifiStatus(this);
241 * (カメラと接続中のときのみ、接続方式が Olympusのときのみ)
244 public void changeSceneToCameraPropertyList()
248 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
249 ICameraConnection connection = getCameraConnection(method);
250 if (method == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
254 // Ricohの場合は、コマンド送信ダイアログを表示する
255 RicohGr2SendCommandDialog.newInstance().show(getSupportFragmentManager(), "RicohGr2SendCommandDialog");
262 else if (method == ICameraConnection.CameraConnectionMethod.SONY)
264 // SONYの場合は、API一覧画面へ遷移させる
265 changeSceneToApiList();
267 else if (method == ICameraConnection.CameraConnectionMethod.PANASONIC)
271 // Panasonicの場合は、コマンド送信ダイアログを表示する
272 PanasonicSendCommandDialog.newInstance(interfaceProvider.getPanasonicInterface()).show(getSupportFragmentManager(), "panasonicSendCommandDialog");
279 else if (method == ICameraConnection.CameraConnectionMethod.FUJI_X)
283 // FUJI X Seriesの場合は、コマンド送信ダイアログを表示する
284 FujiXCameraCommandSendDialog.newInstance(interfaceProvider.getFujiXInterface()).show(getSupportFragmentManager(), "sendCommandDialog");
291 else if (method == ICameraConnection.CameraConnectionMethod.OLYMPUS)
295 Map<String, String> headerMap = new HashMap<>();
296 headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
297 headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
299 // Olympus Penの場合は、コマンド送信ダイアログを表示する
300 SimpleHttpSendCommandDialog.newInstance("http://192.168.0.10/", interfaceProvider.getOlympusPenInterface().getLiveViewControl(), headerMap).show(getSupportFragmentManager(), "olympusPenSendCommandDialog");
307 else if (method == ICameraConnection.CameraConnectionMethod.THETA)
311 // THETA の場合は、HTTPコマンド送信ダイアログを表示する
312 SimpleHttpSendCommandDialog.newInstance("http://192.168.1.1/", null, null).show(getSupportFragmentManager(), "thetaSendCommandDialog");
319 else if (method == ICameraConnection.CameraConnectionMethod.CANON)
323 // CANON の場合は、PTPIPコマンド送信ダイアログを表示する
324 PtpIpCameraCommandSendDialog.newInstance(interfaceProvider.getCanonInterface(), true).show(getSupportFragmentManager(), "ptpipSendCommandDialog");
331 else if (method == ICameraConnection.CameraConnectionMethod.NIKON)
335 // NIKON の場合は、PTPIPコマンド送信ダイアログを表示する
336 PtpIpCameraCommandSendDialog.newInstance(interfaceProvider.getCanonInterface(), true).show(getSupportFragmentManager(), "ptpipSendCommandDialog");
346 if (connection != null)
348 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
349 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
351 if (propertyListFragment == null)
353 propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
355 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
356 transaction.replace(R.id.fragment1, propertyListFragment);
358 transaction.addToBackStack(null);
359 transaction.commit();
375 public void changeSceneToConfiguration()
379 if (preferenceFragment == null)
383 preferenceFragment = PreferenceFragmentSummary.newInstance(this, this);
390 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
391 transaction.replace(R.id.fragment1, preferenceFragment);
392 transaction.addToBackStack(null); // backstackに追加
393 transaction.commit();
402 public void changeSceneToConfiguration(ICameraConnection.CameraConnectionMethod connectionMethod)
406 PreferenceFragmentCompat targetFragment = null;
407 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2) {
408 if (preferenceFragmentRicoh == null)
410 preferenceFragmentRicoh = RicohGr2PreferenceFragment.newInstance(this, this);
412 targetFragment = preferenceFragmentRicoh;
413 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
414 if (preferenceFragmentSony == null)
416 preferenceFragmentSony = SonyPreferenceFragment.newInstance(this, this);
418 targetFragment = preferenceFragmentSony;
419 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC) {
420 if (preferenceFragmentPanasonic == null)
422 preferenceFragmentPanasonic = PanasonicPreferenceFragment.newInstance(this, this);
424 targetFragment = preferenceFragmentPanasonic;
425 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS) {
426 if (preferenceFragmentOlympus == null)
428 preferenceFragmentOlympus = OlympusPreferenceFragment.newInstance(this, this);
430 targetFragment = preferenceFragmentOlympus;
431 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X) {
432 if (preferenceFragmentFuji == null)
434 preferenceFragmentFuji = FujiXPreferenceFragment.newInstance(this, this);
436 targetFragment = preferenceFragmentFuji;
437 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.THETA) {
438 if (preferenceFragmentTheta == null)
440 preferenceFragmentTheta = ThetaPreferenceFragment.newInstance(this, this);
442 targetFragment = preferenceFragmentTheta;
443 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.CANON) {
444 if (preferenceFragmentCanon == null)
446 preferenceFragmentCanon = CanonPreferenceFragment.newInstance(this, this);
448 targetFragment = preferenceFragmentCanon;
449 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.NIKON) {
450 if (preferenceFragmentNikon == null)
452 preferenceFragmentNikon = NikonPreferenceFragment.newInstance(this, this);
454 targetFragment = preferenceFragmentNikon;
455 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC) {
456 if (preferenceFragmentOPC == null)
458 preferenceFragmentOPC = PreferenceFragment.newInstance(this, interfaceProvider, this);
460 targetFragment = preferenceFragmentOPC;
462 if (targetFragment != null)
464 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
465 transaction.replace(R.id.fragment1, targetFragment);
466 transaction.addToBackStack(null); // backstackに追加
467 transaction.commit();
481 public void changeSceneToDebugInformation()
483 if (logCatFragment == null)
485 logCatFragment = LogCatFragment.newInstance();
487 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
488 transaction.replace(R.id.fragment1, logCatFragment);
490 transaction.addToBackStack(null);
491 transaction.commit();
499 public void changeSceneToApiList()
501 if (sonyApiListFragmentSony == null)
503 sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
505 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
506 transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
508 transaction.addToBackStack(null);
509 transaction.commit();
516 public void changeCameraConnection()
518 if (interfaceProvider == null)
520 Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
525 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
526 if (connection != null)
528 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
529 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
532 connection.disconnect(false);
536 connection.startWatchWifiStatus(this);
549 public void exitApplication()
551 Log.v(TAG, "exitApplication()");
554 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
555 if (connection != null)
557 connection.disconnect(true);
572 public void onStatusNotify(String message)
574 Log.v(TAG, " CONNECTION MESSAGE : " + message);
577 if (statusViewDrawer != null)
579 statusViewDrawer.updateStatusView(message);
580 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
581 if (connection != null)
583 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
598 public void onCameraConnected()
600 Log.v(TAG, "onCameraConnected()");
604 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
605 if (connection != null)
607 // クラス構造をミスった...のでこんなところで、無理やりステータスを更新する
608 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
610 if (statusViewDrawer != null)
612 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
615 statusViewDrawer.startLiveView();
629 public void onCameraDisconnected()
631 Log.v(TAG, "onCameraDisconnected()");
632 if (statusViewDrawer != null)
634 statusViewDrawer.updateStatusView(getString(R.string.camera_disconnected));
635 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
644 public void onCameraOccursException(String message, Exception e)
646 Log.v(TAG, "onCameraOccursException() " + message);
650 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
651 if (connection != null)
653 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
655 if (statusViewDrawer != null)
657 statusViewDrawer.updateStatusView(message);
658 if (connection != null)
660 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
666 ee.printStackTrace();
671 * BLE経由でカメラの電源を入れるかどうか
674 private boolean isBlePowerOn()
679 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
681 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
682 ret = preferences.getBoolean(IPreferencePropertyAccessor.BLE_POWER_ON, false);
683 // Log.v(TAG, "isBlePowerOn() : " + ret);
697 private boolean isAutoConnectCamera()
702 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
703 ret = preferences.getBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
704 // Log.v(TAG, "isAutoConnectCamera() : " + ret);
718 private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod connectionMethod)
720 ICameraConnection connection;
721 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
723 connection = interfaceProvider.getRicohGr2Infterface().getRicohGr2CameraConnection();
725 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
727 connection = interfaceProvider.getSonyInterface().getSonyCameraConnection();
729 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
731 connection = interfaceProvider.getPanasonicInterface().getPanasonicCameraConnection();
733 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
735 connection = interfaceProvider.getFujiXInterface().getFujiXCameraConnection();
737 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS)
739 connection = interfaceProvider.getOlympusPenInterface().getOlyCameraConnection();
741 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.THETA)
743 connection = interfaceProvider.getThetaInterface().getCameraConnection();
745 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.CANON)
747 connection = interfaceProvider.getCanonInterface().getCameraConnection();
749 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.NIKON)
751 connection = interfaceProvider.getNikonInterface().getCameraConnection();
753 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
755 connection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
761 * カメラへのBLE接続指示が完了したとき
763 * @param isExecuted true : BLEで起動した, false : 起動していない、その他
766 public void wakeupExecuted(boolean isExecuted)
768 Log.v(TAG, "wakeupExecuted() : " + isExecuted);
769 if (isAutoConnectCamera())
771 // カメラへ自動接続する設定だった場合、カメラへWiFi接続する (BLEで起動しなくても)
772 changeCameraConnection();
778 public boolean onKeyDown(int keyCode, KeyEvent event)
780 Log.v(TAG, "onKeyDown()" + " " + keyCode);
783 if ((event.getAction() == KeyEvent.ACTION_DOWN)&&
784 ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
786 if (liveViewFragment != null)
788 return (liveViewFragment.handleKeyDown(keyCode, event));
796 return (super.onKeyDown(keyCode, event));
800 public void updateMessage(final String message, final boolean isBold, final boolean isColor, final int color)
802 Log.v(TAG, " updateMessage() : " + message);
805 final TextView messageArea = findViewById(R.id.message);
806 runOnUiThread(new Runnable() {
810 if ((messageArea != null) && (message != null))
812 messageArea.setText(message);
815 messageArea.setTypeface(Typeface.DEFAULT_BOLD);
819 messageArea.setTextColor(color);
823 messageArea.setTextColor(Color.DKGRAY);
825 messageArea.invalidate();