1 package net.osdn.gokigen.a01d;
3 import android.Manifest;
4 import android.content.SharedPreferences;
5 import android.content.pm.PackageManager;
6 import android.os.Bundle;
7 import android.util.Log;
8 import android.view.KeyEvent;
9 import android.view.WindowManager;
11 import net.osdn.gokigen.a01d.camera.CameraInterfaceProvider;
12 import net.osdn.gokigen.a01d.camera.IInterfaceProvider;
13 import net.osdn.gokigen.a01d.camera.fujix.cameraproperty.FujiXCameraCommandSendDialog;
14 import net.osdn.gokigen.a01d.camera.olympus.cameraproperty.OlyCameraPropertyListFragment;
15 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
16 import net.osdn.gokigen.a01d.camera.ICameraConnection;
17 import net.osdn.gokigen.a01d.camera.olympus.wrapper.connection.ble.ICameraPowerOn;
18 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpSendCommandDialog;
19 import net.osdn.gokigen.a01d.camera.panasonic.operation.PanasonicSendCommandDialog;
20 import net.osdn.gokigen.a01d.camera.ricohgr2.operation.RicohGr2SendCommandDialog;
21 import net.osdn.gokigen.a01d.camera.sony.cameraproperty.SonyCameraApiListFragment;
22 import net.osdn.gokigen.a01d.liveview.IStatusViewDrawer;
23 import net.osdn.gokigen.a01d.liveview.LiveViewFragment;
24 import net.osdn.gokigen.a01d.logcat.LogCatFragment;
25 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
26 import net.osdn.gokigen.a01d.preference.fujix.FujiXPreferenceFragment;
27 import net.osdn.gokigen.a01d.preference.olympus.PreferenceFragment;
28 import net.osdn.gokigen.a01d.preference.panasonic.PanasonicPreferenceFragment;
29 import net.osdn.gokigen.a01d.preference.olympuspen.OlympusPreferenceFragment;
30 import net.osdn.gokigen.a01d.preference.ricohgr2.RicohGr2PreferenceFragment;
31 import net.osdn.gokigen.a01d.preference.sony.SonyPreferenceFragment;
33 import androidx.annotation.NonNull;
34 import androidx.appcompat.app.ActionBar;
35 import androidx.appcompat.app.AppCompatActivity;
36 import androidx.core.app.ActivityCompat;
37 import androidx.core.content.ContextCompat;
38 import androidx.fragment.app.FragmentTransaction;
39 import androidx.preference.PreferenceFragmentCompat;
40 import androidx.preference.PreferenceManager;
42 import java.util.HashMap;
49 public class A01dMain extends AppCompatActivity implements ICameraStatusReceiver, IChangeScene, ICameraPowerOn.PowerOnCameraCallback
51 private final String TAG = toString();
52 private IInterfaceProvider interfaceProvider = null;
53 private IStatusViewDrawer statusViewDrawer = null;
55 private PreferenceFragmentCompat preferenceFragment = null;
56 private OlyCameraPropertyListFragment propertyListFragment = null;
57 private SonyCameraApiListFragment sonyApiListFragmentSony = null;
58 private LogCatFragment logCatFragment = null;
59 private LiveViewFragment liveViewFragment = null;
62 protected void onCreate(Bundle savedInstanceState)
64 final int REQUEST_NEED_PERMISSIONS = 1010;
66 super.onCreate(savedInstanceState);
70 if (Build.VERSION.SDK_INT >= 19)
72 View decor = this.getWindow().getDecorView();
73 decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
75 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
83 setContentView(R.layout.activity_a01d_main);
85 ActionBar bar = getSupportActionBar();
90 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
93 if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
94 (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
95 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_MEDIA_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
96 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) ||
97 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) ||
98 (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) ||
99 (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) != PackageManager.PERMISSION_GRANTED) ||
100 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
101 (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED)) {
102 ActivityCompat.requestPermissions(this,
104 Manifest.permission.WRITE_EXTERNAL_STORAGE,
105 Manifest.permission.READ_EXTERNAL_STORAGE,
106 Manifest.permission.ACCESS_MEDIA_LOCATION,
107 Manifest.permission.ACCESS_NETWORK_STATE,
108 Manifest.permission.ACCESS_WIFI_STATE,
109 Manifest.permission.BLUETOOTH,
110 Manifest.permission.BLUETOOTH_ADMIN,
111 Manifest.permission.ACCESS_COARSE_LOCATION,
112 Manifest.permission.INTERNET,
114 REQUEST_NEED_PERMISSIONS);
117 initializeFragment();
122 * なぜか、onReadyClass() が有効ではなさそうなので...
126 public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
128 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
135 private void initializeClass()
139 interfaceProvider = new CameraInterfaceProvider(this, this);
150 private void onReadyClass()
154 // BLEでPower ONは、OPCのみ対応
155 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
157 // BLEでカメラの電源をONにする設定だった時
160 // カメラの電源ONクラスを呼び出しておく (電源ONができたら、コールバックをもらう)
161 interfaceProvider.getOlympusInterface().getCameraPowerOn().wakeup(this);
169 else if (isAutoConnectCamera())
172 changeCameraConnection();
179 private void initializeFragment()
183 //if (liveViewFragment == null)
185 liveViewFragment = LiveViewFragment.newInstance(this, interfaceProvider);
187 statusViewDrawer = liveViewFragment;
188 liveViewFragment.setRetainInstance(true);
189 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
190 transaction.replace(R.id.fragment1, liveViewFragment);
191 transaction.commitAllowingStateLoss();
203 protected void onPause()
208 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
209 ICameraConnection connection = getCameraConnection(method);
210 if (connection != null)
212 connection.stopWatchWifiStatus(this);
223 * (カメラと接続中のときのみ、接続方式が Olympusのときのみ)
226 public void changeSceneToCameraPropertyList()
230 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
231 ICameraConnection connection = getCameraConnection(method);
232 if (method == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
236 // Ricohの場合は、コマンド送信ダイアログを表示する
237 RicohGr2SendCommandDialog.newInstance().show(getSupportFragmentManager(), "RicohGr2SendCommandDialog");
244 else if (method == ICameraConnection.CameraConnectionMethod.SONY)
246 // SONYの場合は、API一覧画面へ遷移させる
247 changeSceneToApiList();
249 else if (method == ICameraConnection.CameraConnectionMethod.PANASONIC)
253 // Panasonicの場合は、コマンド送信ダイアログを表示する
254 PanasonicSendCommandDialog.newInstance(interfaceProvider.getPanasonicInterface()).show(getSupportFragmentManager(), "panasonicSendCommandDialog");
261 else if (method == ICameraConnection.CameraConnectionMethod.FUJI_X)
265 // FUJI X Seriesの場合は、コマンド送信ダイアログを表示する
266 FujiXCameraCommandSendDialog.newInstance(interfaceProvider.getFujiXInterface()).show(getSupportFragmentManager(), "sendCommandDialog");
274 else if (method == ICameraConnection.CameraConnectionMethod.OLYMPUS)
278 Map<String, String> headerMap = new HashMap<>();
279 headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
280 headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
282 // Olympus Penの場合は、コマンド送信ダイアログを表示する
283 SimpleHttpSendCommandDialog.newInstance("http://192.168.0.10/", interfaceProvider.getOlympusPenInterface().getLiveViewControl(), headerMap).show(getSupportFragmentManager(), "olympusPenSendCommandDialog");
293 if (connection != null)
295 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
296 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
298 if (propertyListFragment == null)
300 propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
302 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
303 transaction.replace(R.id.fragment1, propertyListFragment);
305 transaction.addToBackStack(null);
306 transaction.commit();
322 public void changeSceneToConfiguration()
326 if (preferenceFragment == null)
330 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
331 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2) {
332 preferenceFragment = RicohGr2PreferenceFragment.newInstance(this, this);
333 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
334 preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
335 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC) {
336 preferenceFragment = PanasonicPreferenceFragment.newInstance(this, this);
337 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS) {
338 preferenceFragment = OlympusPreferenceFragment.newInstance(this, this);
339 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X) {
340 preferenceFragment = FujiXPreferenceFragment.newInstance(this, this);
341 } else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
343 preferenceFragment = PreferenceFragment.newInstance(this, interfaceProvider, this);
349 preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
353 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
354 transaction.replace(R.id.fragment1, preferenceFragment);
356 transaction.addToBackStack(null);
357 transaction.commit();
370 public void changeSceneToDebugInformation()
372 if (logCatFragment == null)
374 logCatFragment = LogCatFragment.newInstance();
376 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
377 transaction.replace(R.id.fragment1, logCatFragment);
379 transaction.addToBackStack(null);
380 transaction.commit();
388 public void changeSceneToApiList()
390 if (sonyApiListFragmentSony == null)
392 sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
394 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
395 transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
397 transaction.addToBackStack(null);
398 transaction.commit();
405 public void changeCameraConnection()
407 if (interfaceProvider == null)
409 Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
414 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
415 if (connection != null)
417 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
418 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
421 connection.disconnect(false);
425 connection.startWatchWifiStatus(this);
438 public void exitApplication()
440 Log.v(TAG, "exitApplication()");
443 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
444 if (connection != null)
446 connection.disconnect(true);
461 public void onStatusNotify(String message)
463 Log.v(TAG, " CONNECTION MESSAGE : " + message);
466 if (statusViewDrawer != null)
468 statusViewDrawer.updateStatusView(message);
469 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
470 if (connection != null)
472 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
487 public void onCameraConnected()
489 Log.v(TAG, "onCameraConnected()");
493 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
494 if (connection != null)
496 // クラス構造をミスった...のでこんなところで、無理やりステータスを更新する
497 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
499 if (statusViewDrawer != null)
501 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
504 statusViewDrawer.startLiveView();
518 public void onCameraDisconnected()
520 Log.v(TAG, "onCameraDisconnected()");
521 if (statusViewDrawer != null)
523 statusViewDrawer.updateStatusView(getString(R.string.camera_disconnected));
524 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
533 public void onCameraOccursException(String message, Exception e)
535 Log.v(TAG, "onCameraOccursException() " + message);
539 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
540 if (connection != null)
542 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
544 if (statusViewDrawer != null)
546 statusViewDrawer.updateStatusView(message);
547 if (connection != null)
549 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
555 ee.printStackTrace();
560 * BLE経由でカメラの電源を入れるかどうか
563 private boolean isBlePowerOn()
568 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
570 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
571 ret = preferences.getBoolean(IPreferencePropertyAccessor.BLE_POWER_ON, false);
572 // Log.v(TAG, "isBlePowerOn() : " + ret);
586 private boolean isAutoConnectCamera()
591 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
592 ret = preferences.getBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
593 // Log.v(TAG, "isAutoConnectCamera() : " + ret);
607 private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod connectionMethod)
609 ICameraConnection connection;
610 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
612 connection = interfaceProvider.getRicohGr2Infterface().getRicohGr2CameraConnection();
614 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
616 connection = interfaceProvider.getSonyInterface().getSonyCameraConnection();
618 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
620 connection = interfaceProvider.getPanasonicInterface().getPanasonicCameraConnection();
622 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
624 connection = interfaceProvider.getFujiXInterface().getFujiXCameraConnection();
626 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS)
628 connection = interfaceProvider.getOlympusPenInterface().getOlyCameraConnection();
630 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
632 connection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
638 * カメラへのBLE接続指示が完了したとき
640 * @param isExecuted true : BLEで起動した, false : 起動していない、その他
643 public void wakeupExecuted(boolean isExecuted)
645 Log.v(TAG, "wakeupExecuted() : " + isExecuted);
646 if (isAutoConnectCamera())
648 // カメラへ自動接続する設定だった場合、カメラへWiFi接続する (BLEで起動しなくても)
649 changeCameraConnection();
655 public boolean onKeyDown(int keyCode, KeyEvent event)
657 Log.v(TAG, "onKeyDown()" + " " + keyCode);
660 if ((event.getAction() == KeyEvent.ACTION_DOWN)&&
661 ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
663 if (liveViewFragment != null)
665 return (liveViewFragment.handleKeyDown(keyCode, event));
673 return (super.onKeyDown(keyCode, event));