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.utils.SimpleHttpSendCommandDialog;
22 import net.osdn.gokigen.a01d.camera.panasonic.operation.PanasonicSendCommandDialog;
23 import net.osdn.gokigen.a01d.camera.ricohgr2.operation.RicohGr2SendCommandDialog;
24 import net.osdn.gokigen.a01d.camera.sony.cameraproperty.SonyCameraApiListFragment;
25 import net.osdn.gokigen.a01d.liveview.IStatusViewDrawer;
26 import net.osdn.gokigen.a01d.liveview.LiveViewFragment;
27 import net.osdn.gokigen.a01d.logcat.LogCatFragment;
28 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
29 import net.osdn.gokigen.a01d.preference.fujix.FujiXPreferenceFragment;
30 import net.osdn.gokigen.a01d.preference.olympus.PreferenceFragment;
31 import net.osdn.gokigen.a01d.preference.panasonic.PanasonicPreferenceFragment;
32 import net.osdn.gokigen.a01d.preference.olympuspen.OlympusPreferenceFragment;
33 import net.osdn.gokigen.a01d.preference.ricohgr2.RicohGr2PreferenceFragment;
34 import net.osdn.gokigen.a01d.preference.sony.SonyPreferenceFragment;
35 import net.osdn.gokigen.a01d.preference.theta.ThetaPreferenceFragment;
37 import androidx.annotation.NonNull;
38 import androidx.appcompat.app.ActionBar;
39 import androidx.appcompat.app.AppCompatActivity;
40 import androidx.core.app.ActivityCompat;
41 import androidx.core.content.ContextCompat;
42 import androidx.fragment.app.FragmentTransaction;
43 import androidx.preference.PreferenceFragmentCompat;
44 import androidx.preference.PreferenceManager;
46 import java.util.HashMap;
53 public class A01dMain extends AppCompatActivity implements ICameraStatusReceiver, IChangeScene, ICameraPowerOn.PowerOnCameraCallback, IInformationReceiver
55 private final String TAG = toString();
56 private IInterfaceProvider interfaceProvider = null;
57 private IStatusViewDrawer statusViewDrawer = null;
59 private PreferenceFragmentCompat preferenceFragment = null;
60 private OlyCameraPropertyListFragment propertyListFragment = null;
61 private SonyCameraApiListFragment sonyApiListFragmentSony = null;
62 private LogCatFragment logCatFragment = null;
63 private LiveViewFragment liveViewFragment = null;
66 protected void onCreate(Bundle savedInstanceState)
68 final int REQUEST_NEED_PERMISSIONS = 1010;
70 super.onCreate(savedInstanceState);
74 if (Build.VERSION.SDK_INT >= 19)
76 View decor = this.getWindow().getDecorView();
77 decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
79 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
87 setContentView(R.layout.activity_a01d_main);
89 ActionBar bar = getSupportActionBar();
94 getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
97 if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
98 (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
99 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_MEDIA_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
100 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) ||
101 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) ||
102 (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) ||
103 (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) != PackageManager.PERMISSION_GRANTED) ||
104 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
105 (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED)) {
106 ActivityCompat.requestPermissions(this,
108 Manifest.permission.WRITE_EXTERNAL_STORAGE,
109 Manifest.permission.READ_EXTERNAL_STORAGE,
110 Manifest.permission.ACCESS_MEDIA_LOCATION,
111 Manifest.permission.ACCESS_NETWORK_STATE,
112 Manifest.permission.ACCESS_WIFI_STATE,
113 Manifest.permission.BLUETOOTH,
114 Manifest.permission.BLUETOOTH_ADMIN,
115 Manifest.permission.ACCESS_COARSE_LOCATION,
116 Manifest.permission.INTERNET,
118 REQUEST_NEED_PERMISSIONS);
121 initializeFragment();
126 * なぜか、onReadyClass() が有効ではなさそうなので...
130 public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults)
132 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
139 private void initializeClass()
143 interfaceProvider = new CameraInterfaceProvider(this, this);
154 private void onReadyClass()
158 // BLEでPower ONは、OPCのみ対応
159 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
161 // BLEでカメラの電源をONにする設定だった時
164 // カメラの電源ONクラスを呼び出しておく (電源ONができたら、コールバックをもらう)
165 interfaceProvider.getOlympusInterface().getCameraPowerOn().wakeup(this);
173 else if (isAutoConnectCamera())
176 changeCameraConnection();
183 private void initializeFragment()
187 //if (liveViewFragment == null)
189 liveViewFragment = LiveViewFragment.newInstance(this, interfaceProvider);
191 statusViewDrawer = liveViewFragment;
192 liveViewFragment.setRetainInstance(true);
193 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
194 transaction.replace(R.id.fragment1, liveViewFragment);
195 transaction.commitAllowingStateLoss();
207 protected void onPause()
212 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
213 ICameraConnection connection = getCameraConnection(method);
214 if (connection != null)
216 connection.stopWatchWifiStatus(this);
227 * (カメラと接続中のときのみ、接続方式が Olympusのときのみ)
230 public void changeSceneToCameraPropertyList()
234 ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
235 ICameraConnection connection = getCameraConnection(method);
236 if (method == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
240 // Ricohの場合は、コマンド送信ダイアログを表示する
241 RicohGr2SendCommandDialog.newInstance().show(getSupportFragmentManager(), "RicohGr2SendCommandDialog");
248 else if (method == ICameraConnection.CameraConnectionMethod.SONY)
250 // SONYの場合は、API一覧画面へ遷移させる
251 changeSceneToApiList();
253 else if (method == ICameraConnection.CameraConnectionMethod.PANASONIC)
257 // Panasonicの場合は、コマンド送信ダイアログを表示する
258 PanasonicSendCommandDialog.newInstance(interfaceProvider.getPanasonicInterface()).show(getSupportFragmentManager(), "panasonicSendCommandDialog");
265 else if (method == ICameraConnection.CameraConnectionMethod.FUJI_X)
269 // FUJI X Seriesの場合は、コマンド送信ダイアログを表示する
270 FujiXCameraCommandSendDialog.newInstance(interfaceProvider.getFujiXInterface()).show(getSupportFragmentManager(), "sendCommandDialog");
277 else if (method == ICameraConnection.CameraConnectionMethod.OLYMPUS)
281 Map<String, String> headerMap = new HashMap<>();
282 headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
283 headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
285 // Olympus Penの場合は、コマンド送信ダイアログを表示する
286 SimpleHttpSendCommandDialog.newInstance("http://192.168.0.10/", interfaceProvider.getOlympusPenInterface().getLiveViewControl(), headerMap).show(getSupportFragmentManager(), "olympusPenSendCommandDialog");
293 else if (method == ICameraConnection.CameraConnectionMethod.THETA)
297 // THETA の場合は、HTTPコマンド送信ダイアログを表示する
298 SimpleHttpSendCommandDialog.newInstance("http://192.168.1.1/", null, null).show(getSupportFragmentManager(), "thetaSendCommandDialog");
308 if (connection != null)
310 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
311 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
313 if (propertyListFragment == null)
315 propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
317 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
318 transaction.replace(R.id.fragment1, propertyListFragment);
320 transaction.addToBackStack(null);
321 transaction.commit();
337 public void changeSceneToConfiguration()
341 if (preferenceFragment == null)
345 ICameraConnection.CameraConnectionMethod connectionMethod = interfaceProvider.getCammeraConnectionMethod();
346 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2) {
347 preferenceFragment = RicohGr2PreferenceFragment.newInstance(this, this);
348 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
349 preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
350 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC) {
351 preferenceFragment = PanasonicPreferenceFragment.newInstance(this, this);
352 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS) {
353 preferenceFragment = OlympusPreferenceFragment.newInstance(this, this);
354 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X) {
355 preferenceFragment = FujiXPreferenceFragment.newInstance(this, this);
356 } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.THETA) {
357 preferenceFragment = ThetaPreferenceFragment.newInstance(this, this);
358 } else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
360 preferenceFragment = PreferenceFragment.newInstance(this, interfaceProvider, this);
366 preferenceFragment = SonyPreferenceFragment.newInstance(this, this);
370 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
371 transaction.replace(R.id.fragment1, preferenceFragment);
373 transaction.addToBackStack(null);
374 transaction.commit();
387 public void changeSceneToDebugInformation()
389 if (logCatFragment == null)
391 logCatFragment = LogCatFragment.newInstance();
393 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
394 transaction.replace(R.id.fragment1, logCatFragment);
396 transaction.addToBackStack(null);
397 transaction.commit();
405 public void changeSceneToApiList()
407 if (sonyApiListFragmentSony == null)
409 sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
411 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
412 transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
414 transaction.addToBackStack(null);
415 transaction.commit();
422 public void changeCameraConnection()
424 if (interfaceProvider == null)
426 Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
431 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
432 if (connection != null)
434 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
435 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
438 connection.disconnect(false);
442 connection.startWatchWifiStatus(this);
455 public void exitApplication()
457 Log.v(TAG, "exitApplication()");
460 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
461 if (connection != null)
463 connection.disconnect(true);
478 public void onStatusNotify(String message)
480 Log.v(TAG, " CONNECTION MESSAGE : " + message);
483 if (statusViewDrawer != null)
485 statusViewDrawer.updateStatusView(message);
486 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
487 if (connection != null)
489 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
504 public void onCameraConnected()
506 Log.v(TAG, "onCameraConnected()");
510 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
511 if (connection != null)
513 // クラス構造をミスった...のでこんなところで、無理やりステータスを更新する
514 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
516 if (statusViewDrawer != null)
518 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
521 statusViewDrawer.startLiveView();
535 public void onCameraDisconnected()
537 Log.v(TAG, "onCameraDisconnected()");
538 if (statusViewDrawer != null)
540 statusViewDrawer.updateStatusView(getString(R.string.camera_disconnected));
541 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
550 public void onCameraOccursException(String message, Exception e)
552 Log.v(TAG, "onCameraOccursException() " + message);
556 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
557 if (connection != null)
559 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
561 if (statusViewDrawer != null)
563 statusViewDrawer.updateStatusView(message);
564 if (connection != null)
566 statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
572 ee.printStackTrace();
577 * BLE経由でカメラの電源を入れるかどうか
580 private boolean isBlePowerOn()
585 if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
587 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
588 ret = preferences.getBoolean(IPreferencePropertyAccessor.BLE_POWER_ON, false);
589 // Log.v(TAG, "isBlePowerOn() : " + ret);
603 private boolean isAutoConnectCamera()
608 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
609 ret = preferences.getBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
610 // Log.v(TAG, "isAutoConnectCamera() : " + ret);
624 private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod connectionMethod)
626 ICameraConnection connection;
627 if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
629 connection = interfaceProvider.getRicohGr2Infterface().getRicohGr2CameraConnection();
631 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
633 connection = interfaceProvider.getSonyInterface().getSonyCameraConnection();
635 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
637 connection = interfaceProvider.getPanasonicInterface().getPanasonicCameraConnection();
639 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
641 connection = interfaceProvider.getFujiXInterface().getFujiXCameraConnection();
643 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS)
645 connection = interfaceProvider.getOlympusPenInterface().getOlyCameraConnection();
647 else if (connectionMethod == ICameraConnection.CameraConnectionMethod.THETA)
649 connection = interfaceProvider.getThetaInterface().getCameraConnection();
651 else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
653 connection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
659 * カメラへのBLE接続指示が完了したとき
661 * @param isExecuted true : BLEで起動した, false : 起動していない、その他
664 public void wakeupExecuted(boolean isExecuted)
666 Log.v(TAG, "wakeupExecuted() : " + isExecuted);
667 if (isAutoConnectCamera())
669 // カメラへ自動接続する設定だった場合、カメラへWiFi接続する (BLEで起動しなくても)
670 changeCameraConnection();
676 public boolean onKeyDown(int keyCode, KeyEvent event)
678 Log.v(TAG, "onKeyDown()" + " " + keyCode);
681 if ((event.getAction() == KeyEvent.ACTION_DOWN)&&
682 ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
684 if (liveViewFragment != null)
686 return (liveViewFragment.handleKeyDown(keyCode, event));
694 return (super.onKeyDown(keyCode, event));
698 public void updateMessage(final String message, final boolean isBold, final boolean isColor, final int color)
700 Log.v(TAG, " updateMessage() : " + message);
703 final TextView messageArea = findViewById(R.id.message);
704 runOnUiThread(new Runnable() {
708 if ((messageArea != null) && (message != null))
710 messageArea.setText(message);
713 messageArea.setTypeface(Typeface.DEFAULT_BOLD);
717 messageArea.setTextColor(color);
721 messageArea.setTextColor(Color.DKGRAY);
723 messageArea.invalidate();