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.olympuspen.operation.OlympusPenSendCommandDialog;
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;
46 public class A01dMain extends AppCompatActivity implements ICameraStatusReceiver, IChangeScene, ICameraPowerOn.PowerOnCameraCallback
48 private final String TAG = toString();
49 private IInterfaceProvider interfaceProvider = null;
50 private IStatusViewDrawer statusViewDrawer = null;
52 private PreferenceFragmentCompat preferenceFragment = null;
53 private OlyCameraPropertyListFragment propertyListFragment = null;
54 private SonyCameraApiListFragment sonyApiListFragmentSony = null;
55 private LogCatFragment logCatFragment = null;
56 private LiveViewFragment liveViewFragment = null;
59 protected void onCreate(Bundle savedInstanceState)
61 final int REQUEST_NEED_PERMISSIONS = 1010;
63 super.onCreate(savedInstanceState);
67 if (Build.VERSION.SDK_INT >= 19)
69 View decor = this.getWindow().getDecorView();
70 decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
72 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
80 setContentView(R.layout.activity_a01d_main);
82 ActionBar bar = getSupportActionBar();
87 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
90 if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
91 (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
92 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_MEDIA_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
93 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) ||
94 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) ||
95 (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) ||
96 (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) != PackageManager.PERMISSION_GRANTED) ||
97 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
98 (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED)) {
99 ActivityCompat.requestPermissions(this,
101 Manifest.permission.WRITE_EXTERNAL_STORAGE,
102 Manifest.permission.READ_EXTERNAL_STORAGE,
103 Manifest.permission.ACCESS_MEDIA_LOCATION,
104 Manifest.permission.ACCESS_NETWORK_STATE,
105 Manifest.permission.ACCESS_WIFI_STATE,
106 Manifest.permission.BLUETOOTH,
107 Manifest.permission.BLUETOOTH_ADMIN,
108 Manifest.permission.ACCESS_COARSE_LOCATION,
109 Manifest.permission.INTERNET,
111 REQUEST_NEED_PERMISSIONS);
114 initializeFragment();
119 * なぜか、onReadyClass() が有効ではなさそうなので...
123 public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
125 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
132 private void initializeClass()
136 interfaceProvider = new CameraInterfaceProvider(this, this);
147 private void onReadyClass()
151 // BLEでPower ONは、OPCのみ対応
152 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
154 // BLEでカメラの電源をONにする設定だった時
157 // カメラの電源ONクラスを呼び出しておく (電源ONができたら、コールバックをもらう)
158 interfaceProvider.getOlympusInterface().getCameraPowerOn().wakeup(this);
166 else if (isAutoConnectCamera())
169 changeCameraConnection();
176 private void initializeFragment()
180 //if (liveViewFragment == null)
182 liveViewFragment = LiveViewFragment.newInstance(this, interfaceProvider);
184 statusViewDrawer = liveViewFragment;
185 liveViewFragment.setRetainInstance(true);
186 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
187 transaction.replace(R.id.fragment1, liveViewFragment);
188 transaction.commitAllowingStateLoss();
200 protected void onPause()
205 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
206 ICameraConnection connection = getCameraConnection(method);
207 if (connection != null)
209 connection.stopWatchWifiStatus(this);
220 * (カメラと接続中のときのみ、接続方式が Olympusのときのみ)
223 public void changeSceneToCameraPropertyList()
227 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
228 ICameraConnection connection = getCameraConnection(method);
229 if (method == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
233 // Ricohの場合は、コマンド送信ダイアログを表示する
234 RicohGr2SendCommandDialog.newInstance().show(getSupportFragmentManager(), "RicohGr2SendCommandDialog");
241 else if (method == ICameraConnection.CameraConnectionMethod.SONY)
243 // SONYの場合は、API一覧画面へ遷移させる
244 changeSceneToApiList();
246 else if (method == ICameraConnection.CameraConnectionMethod.PANASONIC)
250 // Panasonicの場合は、コマンド送信ダイアログを表示する
251 PanasonicSendCommandDialog.newInstance(interfaceProvider.getPanasonicInterface()).show(getSupportFragmentManager(), "panasonicSendCommandDialog");
258 else if (method == ICameraConnection.CameraConnectionMethod.FUJI_X)
262 // FUJI X Seriesの場合は、コマンド送信ダイアログを表示する
263 FujiXCameraCommandSendDialog.newInstance(interfaceProvider.getFujiXInterface()).show(getSupportFragmentManager(), "sendCommandDialog");
271 else if (method == ICameraConnection.CameraConnectionMethod.OLYMPUS)
275 // Olympus Penの場合は、コマンド送信ダイアログを表示する
276 OlympusPenSendCommandDialog.newInstance(interfaceProvider.getOlympusPenInterface()).show(getSupportFragmentManager(), "olympusPenSendCommandDialog");
287 if (connection != null)
289 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
290 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
292 if (propertyListFragment == null)
294 propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
296 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
297 transaction.replace(R.id.fragment1, propertyListFragment);
299 transaction.addToBackStack(null);
300 transaction.commit();
316 public void changeSceneToConfiguration()
320 if (preferenceFragment == null)
324 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
325 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2) {
326 preferenceFragment = RicohGr2PreferenceFragment.newInstance(this, this);
327 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
328 preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
329 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC) {
330 preferenceFragment = PanasonicPreferenceFragment.newInstance(this, this);
331 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS) {
332 preferenceFragment = OlympusPreferenceFragment.newInstance(this, this);
333 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X) {
334 preferenceFragment = FujiXPreferenceFragment.newInstance(this, this);
335 } else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
337 preferenceFragment = PreferenceFragment.newInstance(this, interfaceProvider, this);
343 preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
347 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
348 transaction.replace(R.id.fragment1, preferenceFragment);
350 transaction.addToBackStack(null);
351 transaction.commit();
364 public void changeSceneToDebugInformation()
366 if (logCatFragment == null)
368 logCatFragment = LogCatFragment.newInstance();
370 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
371 transaction.replace(R.id.fragment1, logCatFragment);
373 transaction.addToBackStack(null);
374 transaction.commit();
382 public void changeSceneToApiList()
384 if (sonyApiListFragmentSony == null)
386 sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
388 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
389 transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
391 transaction.addToBackStack(null);
392 transaction.commit();
399 public void changeCameraConnection()
401 if (interfaceProvider == null)
403 Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
408 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
409 if (connection != null)
411 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
412 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
415 connection.disconnect(false);
419 connection.startWatchWifiStatus(this);
432 public void exitApplication()
434 Log.v(TAG, "exitApplication()");
437 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
438 if (connection != null)
440 connection.disconnect(true);
455 public void onStatusNotify(String message)
457 Log.v(TAG, " CONNECTION MESSAGE : " + message);
460 if (statusViewDrawer != null)
462 statusViewDrawer.updateStatusView(message);
463 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
464 if (connection != null)
466 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
481 public void onCameraConnected()
483 Log.v(TAG, "onCameraConnected()");
487 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
488 if (connection != null)
490 // クラス構造をミスった...のでこんなところで、無理やりステータスを更新する
491 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
493 if (statusViewDrawer != null)
495 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
498 statusViewDrawer.startLiveView();
512 public void onCameraDisconnected()
514 Log.v(TAG, "onCameraDisconnected()");
515 if (statusViewDrawer != null)
517 statusViewDrawer.updateStatusView(getString(R.string.camera_disconnected));
518 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
527 public void onCameraOccursException(String message, Exception e)
529 Log.v(TAG, "onCameraOccursException() " + message);
533 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
534 if (connection != null)
536 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
538 if (statusViewDrawer != null)
540 statusViewDrawer.updateStatusView(message);
541 if (connection != null)
543 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
549 ee.printStackTrace();
554 * BLE経由でカメラの電源を入れるかどうか
557 private boolean isBlePowerOn()
562 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
564 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
565 ret = preferences.getBoolean(IPreferencePropertyAccessor.BLE_POWER_ON, false);
566 // Log.v(TAG, "isBlePowerOn() : " + ret);
580 private boolean isAutoConnectCamera()
585 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
586 ret = preferences.getBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
587 // Log.v(TAG, "isAutoConnectCamera() : " + ret);
601 private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod connectionMethod)
603 ICameraConnection connection;
604 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
606 connection = interfaceProvider.getRicohGr2Infterface().getRicohGr2CameraConnection();
608 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
610 connection = interfaceProvider.getSonyInterface().getSonyCameraConnection();
612 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
614 connection = interfaceProvider.getPanasonicInterface().getPanasonicCameraConnection();
616 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
618 connection = interfaceProvider.getFujiXInterface().getFujiXCameraConnection();
620 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS)
622 connection = interfaceProvider.getOlympusPenInterface().getOlyCameraConnection();
624 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
626 connection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
632 * カメラへのBLE接続指示が完了したとき
634 * @param isExecuted true : BLEで起動した, false : 起動していない、その他
637 public void wakeupExecuted(boolean isExecuted)
639 Log.v(TAG, "wakeupExecuted() : " + isExecuted);
640 if (isAutoConnectCamera())
642 // カメラへ自動接続する設定だった場合、カメラへWiFi接続する (BLEで起動しなくても)
643 changeCameraConnection();
649 public boolean onKeyDown(int keyCode, KeyEvent event)
651 Log.v(TAG, "onKeyDown()" + " " + keyCode);
654 if ((event.getAction() == KeyEvent.ACTION_DOWN)&&
655 ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
657 if (liveViewFragment != null)
659 return (liveViewFragment.handleKeyDown(keyCode, event));
667 return (super.onKeyDown(keyCode, event));