OSDN Git Service

GR2 / PENTAXモードの自動認識・切り替えをできるようにした。
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / A01dMain.java
1 package net.osdn.gokigen.a01d;
2
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;
13
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;
40
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;
49
50 import java.util.HashMap;
51 import java.util.Map;
52
53 /**
54  *   A01d ;
55  *
56  */
57 public class A01dMain extends AppCompatActivity implements ICameraStatusReceiver, IChangeScene, ICameraPowerOn.PowerOnCameraCallback, IInformationReceiver
58 {
59     private final String TAG = toString();
60     private IInterfaceProvider interfaceProvider = null;
61     private IStatusViewDrawer statusViewDrawer = null;
62
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;
73
74     private OlyCameraPropertyListFragment propertyListFragment = null;
75     private SonyCameraApiListFragment sonyApiListFragmentSony = null;
76     private LogCatFragment logCatFragment = null;
77     private LiveViewFragment liveViewFragment = null;
78
79     @Override
80     protected void onCreate(Bundle savedInstanceState)
81     {
82         final int REQUEST_NEED_PERMISSIONS = 1010;
83
84         super.onCreate(savedInstanceState);
85 /*
86         try {
87             // 全画面表示...
88             if (Build.VERSION.SDK_INT >= 19)
89             {
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);
92             } else {
93                 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
94             }
95         }
96         catch (Exception e)
97         {
98             e.printStackTrace();
99         }
100 */
101         setContentView(R.layout.activity_a01d_main);
102
103         ActionBar bar = getSupportActionBar();
104         if (bar != null) {
105             // タイトルバーは表示しない
106             bar.hide();
107         }
108         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
109
110         // 外部メモリアクセス権のオプトイン
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,
121                     new String[]{
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,
131                     },
132                     REQUEST_NEED_PERMISSIONS);
133         }
134         initializeClass();
135         initializeFragment();
136         onReadyClass();
137     }
138
139     /**
140      *   なぜか、onReadyClass() が有効ではなさそうなので...
141      *
142      */
143     @Override
144     public void onRequestPermissionsResult(int requestCode, @NonNull String[]  permissions, @NonNull int[] grantResults)
145     {
146         super.onRequestPermissionsResult(requestCode, permissions, grantResults);
147         onReadyClass();
148     }
149
150     /**
151      * クラスの初期化
152      */
153     private void initializeClass()
154     {
155         try
156         {
157             interfaceProvider = new CameraInterfaceProvider(this, this, this);
158         }
159         catch (Exception e)
160         {
161             e.printStackTrace();
162         }
163     }
164
165     /**
166      * 初期化終了時の処理
167      */
168     private void onReadyClass()
169     {
170         if (isBlePowerOn())
171         {
172             // BLEでPower ONは、OPCのみ対応
173             if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
174             {
175                 // BLEでカメラの電源をONにする設定だった時
176                 try
177                 {
178                     // カメラの電源ONクラスを呼び出しておく (電源ONができたら、コールバックをもらう)
179                     interfaceProvider.getOlympusInterface().getCameraPowerOn().wakeup(this);
180                 }
181                 catch (Exception e)
182                 {
183                     e.printStackTrace();
184                 }
185             }
186         }
187         else if (isAutoConnectCamera())
188         {
189             // 自動接続の指示があったとき
190             changeCameraConnection();
191         }
192     }
193
194     /**
195      * フラグメントの初期化
196      */
197     private void initializeFragment()
198     {
199         try
200         {
201             //if (liveViewFragment == null)
202             {
203                 liveViewFragment = LiveViewFragment.newInstance(this, interfaceProvider);
204             }
205             statusViewDrawer = liveViewFragment;
206             liveViewFragment.setRetainInstance(true);
207             FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
208             transaction.replace(R.id.fragment1, liveViewFragment);
209             transaction.commitAllowingStateLoss();
210         }
211         catch (Exception e)
212         {
213             e.printStackTrace();
214         }
215     }
216
217     /**
218      *
219      */
220     @Override
221     protected void onPause()
222     {
223         super.onPause();
224         try
225         {
226             ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
227             ICameraConnection connection = getCameraConnection(method);
228             if (connection != null)
229             {
230                 connection.stopWatchWifiStatus(this);
231             }
232         }
233         catch (Exception e)
234         {
235             e.printStackTrace();
236         }
237     }
238
239     /**
240      * カメラのプロパティ一覧画面を開く
241      * (カメラと接続中のときのみ、接続方式が Olympusのときのみ)
242      */
243     @Override
244     public void changeSceneToCameraPropertyList()
245     {
246         try
247         {
248             ICameraConnection.CameraConnectionMethod method = interfaceProvider.getCammeraConnectionMethod();
249             ICameraConnection connection = getCameraConnection(method);
250             if (method == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
251             {
252                 try
253                 {
254                     // Ricohの場合は、コマンド送信ダイアログを表示する
255                     RicohGr2SendCommandDialog.newInstance().show(getSupportFragmentManager(), "RicohGr2SendCommandDialog");
256                 }
257                 catch (Exception e)
258                 {
259                     e.printStackTrace();
260                 }
261             }
262             else if (method == ICameraConnection.CameraConnectionMethod.SONY)
263             {
264                 // SONYの場合は、API一覧画面へ遷移させる
265                 changeSceneToApiList();
266             }
267             else if (method == ICameraConnection.CameraConnectionMethod.PANASONIC)
268             {
269                 try
270                 {
271                     // Panasonicの場合は、コマンド送信ダイアログを表示する
272                     PanasonicSendCommandDialog.newInstance(interfaceProvider.getPanasonicInterface()).show(getSupportFragmentManager(), "panasonicSendCommandDialog");
273                 }
274                 catch (Exception e)
275                 {
276                     e.printStackTrace();
277                 }
278             }
279             else if (method == ICameraConnection.CameraConnectionMethod.FUJI_X)
280             {
281                 try
282                 {
283                     // FUJI X Seriesの場合は、コマンド送信ダイアログを表示する
284                     FujiXCameraCommandSendDialog.newInstance(interfaceProvider.getFujiXInterface()).show(getSupportFragmentManager(), "sendCommandDialog");
285                 }
286                 catch (Exception e)
287                 {
288                     e.printStackTrace();
289                 }
290             }
291             else if (method == ICameraConnection.CameraConnectionMethod.OLYMPUS)
292             {
293                 try
294                 {
295                     Map<String, String> headerMap = new HashMap<>();
296                     headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
297                     headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
298
299                     // Olympus Penの場合は、コマンド送信ダイアログを表示する
300                     SimpleHttpSendCommandDialog.newInstance("http://192.168.0.10/", interfaceProvider.getOlympusPenInterface().getLiveViewControl(), headerMap).show(getSupportFragmentManager(), "olympusPenSendCommandDialog");
301                 }
302                 catch (Exception e)
303                 {
304                     e.printStackTrace();
305                 }
306             }
307             else if (method == ICameraConnection.CameraConnectionMethod.THETA)
308             {
309                 try
310                 {
311                     // THETA の場合は、HTTPコマンド送信ダイアログを表示する
312                     SimpleHttpSendCommandDialog.newInstance("http://192.168.1.1/", null, null).show(getSupportFragmentManager(), "thetaSendCommandDialog");
313                 }
314                 catch (Exception e)
315                 {
316                     e.printStackTrace();
317                 }
318             }
319             else if (method == ICameraConnection.CameraConnectionMethod.CANON)
320             {
321                 try
322                 {
323                     // CANON の場合は、PTPIPコマンド送信ダイアログを表示する
324                     PtpIpCameraCommandSendDialog.newInstance(interfaceProvider.getCanonInterface(), true).show(getSupportFragmentManager(), "ptpipSendCommandDialog");
325                 }
326                 catch (Exception e)
327                 {
328                     e.printStackTrace();
329                 }
330             }
331             else if (method == ICameraConnection.CameraConnectionMethod.NIKON)
332             {
333                 try
334                 {
335                     // NIKON の場合は、PTPIPコマンド送信ダイアログを表示する
336                     PtpIpCameraCommandSendDialog.newInstance(interfaceProvider.getCanonInterface(), true).show(getSupportFragmentManager(), "ptpipSendCommandDialog");
337                 }
338                 catch (Exception e)
339                 {
340                     e.printStackTrace();
341                 }
342             }
343             else
344             {
345                 // OPC カメラの場合...
346                 if (connection != null)
347                 {
348                     ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
349                     if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
350                     {
351                         if (propertyListFragment == null)
352                         {
353                             propertyListFragment = OlyCameraPropertyListFragment.newInstance(this, interfaceProvider.getOlympusInterface().getCameraPropertyProvider());
354                         }
355                         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
356                         transaction.replace(R.id.fragment1, propertyListFragment);
357                         // backstackに追加
358                         transaction.addToBackStack(null);
359                         transaction.commit();
360                     }
361                 }
362             }
363         }
364         catch (Exception e)
365         {
366             e.printStackTrace();
367         }
368     }
369
370     /**
371      *   設定画面を開く
372      *
373      */
374     @Override
375     public void changeSceneToConfiguration()
376     {
377         try
378         {
379             if (preferenceFragment == null)
380             {
381                 try
382                 {
383                     preferenceFragment = PreferenceFragmentSummary.newInstance(this, this);
384                 }
385                 catch (Exception e)
386                 {
387                     e.printStackTrace();
388                 }
389             }
390             FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
391             transaction.replace(R.id.fragment1, preferenceFragment);
392             transaction.addToBackStack(null);    // backstackに追加
393             transaction.commit();
394         }
395         catch (Exception e)
396         {
397             e.printStackTrace();
398         }
399     }
400
401     @Override
402     public void changeSceneToConfiguration(ICameraConnection.CameraConnectionMethod connectionMethod)
403     {
404         try
405         {
406             PreferenceFragmentCompat targetFragment = null;
407             if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2) {
408                 if (preferenceFragmentRicoh == null)
409                 {
410                     preferenceFragmentRicoh = RicohGr2PreferenceFragment.newInstance(this, this);
411                 }
412                 targetFragment = preferenceFragmentRicoh;
413             } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY) {
414                 if (preferenceFragmentSony == null)
415                 {
416                     preferenceFragmentSony = SonyPreferenceFragment.newInstance(this, this);
417                 }
418                 targetFragment = preferenceFragmentSony;
419             } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC) {
420                 if (preferenceFragmentPanasonic == null)
421                 {
422                     preferenceFragmentPanasonic = PanasonicPreferenceFragment.newInstance(this, this);
423                 }
424                 targetFragment = preferenceFragmentPanasonic;
425             } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS) {
426                 if (preferenceFragmentOlympus == null)
427                 {
428                     preferenceFragmentOlympus = OlympusPreferenceFragment.newInstance(this, this);
429                 }
430                 targetFragment = preferenceFragmentOlympus;
431             } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X) {
432                 if (preferenceFragmentFuji == null)
433                 {
434                     preferenceFragmentFuji = FujiXPreferenceFragment.newInstance(this, this);
435                 }
436                 targetFragment = preferenceFragmentFuji;
437             } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.THETA) {
438                 if (preferenceFragmentTheta == null)
439                 {
440                     preferenceFragmentTheta = ThetaPreferenceFragment.newInstance(this, this);
441                 }
442                 targetFragment = preferenceFragmentTheta;
443             } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.CANON) {
444                 if (preferenceFragmentCanon == null)
445                 {
446                     preferenceFragmentCanon = CanonPreferenceFragment.newInstance(this, this);
447                 }
448                 targetFragment = preferenceFragmentCanon;
449             } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.NIKON) {
450                 if (preferenceFragmentNikon == null)
451                 {
452                     preferenceFragmentNikon = NikonPreferenceFragment.newInstance(this, this);
453                 }
454                 targetFragment = preferenceFragmentNikon;
455             } else if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC) {
456                 if (preferenceFragmentOPC == null)
457                 {
458                     preferenceFragmentOPC = PreferenceFragment.newInstance(this, interfaceProvider, this);
459                 }
460                 targetFragment = preferenceFragmentOPC;
461             }
462             if (targetFragment != null)
463             {
464                 FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
465                 transaction.replace(R.id.fragment1, targetFragment);
466                 transaction.addToBackStack(null);   // backstackに追加
467                 transaction.commit();
468             }
469         }
470         catch (Exception e)
471         {
472             e.printStackTrace();
473         }
474     }
475
476     /**
477      *   デバッグ情報画面を開く
478      *
479      */
480     @Override
481     public void changeSceneToDebugInformation()
482     {
483         if (logCatFragment == null)
484         {
485             logCatFragment = LogCatFragment.newInstance();
486         }
487         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
488         transaction.replace(R.id.fragment1, logCatFragment);
489         // backstackに追加
490         transaction.addToBackStack(null);
491         transaction.commit();
492     }
493
494     /**
495      *   SonyのAPI List画面を開く
496      *
497      */
498     @Override
499     public void changeSceneToApiList()
500     {
501         if (sonyApiListFragmentSony == null)
502         {
503             sonyApiListFragmentSony = SonyCameraApiListFragment.newInstance(interfaceProvider);
504         }
505         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
506         transaction.replace(R.id.fragment1, sonyApiListFragmentSony);
507         // backstackに追加
508         transaction.addToBackStack(null);
509         transaction.commit();
510     }
511
512     /**
513      *   カメラとの接続・切断のシーケンス
514      */
515     @Override
516     public void changeCameraConnection()
517     {
518         if (interfaceProvider == null)
519         {
520             Log.v(TAG, "changeCameraConnection() : interfaceProvider is NULL");
521             return;
522         }
523         try
524         {
525             ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
526             if (connection != null)
527             {
528                 ICameraConnection.CameraConnectionStatus status = connection.getConnectionStatus();
529                 if (status == ICameraConnection.CameraConnectionStatus.CONNECTED)
530                 {
531                     // 接続中のときには切断する
532                     connection.disconnect(false);
533                     return;
534                 }
535                 // 接続中でない時は、接続中にする
536                 connection.startWatchWifiStatus(this);
537             }
538         }
539         catch (Exception e)
540         {
541             e.printStackTrace();
542         }
543     }
544
545     /**
546      * アプリを抜ける
547      */
548     @Override
549     public void exitApplication()
550     {
551         Log.v(TAG, "exitApplication()");
552         try
553         {
554             ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
555             if (connection != null)
556             {
557                 connection.disconnect(true);
558             }
559             finish();
560         }
561         catch (Exception e)
562         {
563             e.printStackTrace();
564         }
565     }
566
567     /**
568      *
569      *
570      */
571     @Override
572     public void onStatusNotify(String message)
573     {
574         Log.v(TAG, " CONNECTION MESSAGE : " + message);
575         try
576         {
577             if (statusViewDrawer != null)
578             {
579                 statusViewDrawer.updateStatusView(message);
580                 ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
581                 if (connection != null)
582                 {
583                     statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
584                 }
585             }
586         }
587         catch (Exception e)
588         {
589             e.printStackTrace();
590         }
591     }
592
593     /**
594      *
595      *
596      */
597     @Override
598     public void onCameraConnected()
599     {
600         Log.v(TAG, "onCameraConnected()");
601
602         try
603         {
604             ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
605             if (connection != null)
606             {
607                 // クラス構造をミスった...のでこんなところで、無理やりステータスを更新する
608                 connection.forceUpdateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
609             }
610             if (statusViewDrawer != null)
611             {
612                 statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.CONNECTED);
613
614                 // ライブビューの開始...
615                 statusViewDrawer.startLiveView();
616             }
617         }
618         catch (Exception e)
619         {
620             e.printStackTrace();
621         }
622     }
623
624     /**
625      *
626      *
627      */
628     @Override
629     public void onCameraDisconnected()
630     {
631         Log.v(TAG, "onCameraDisconnected()");
632         if (statusViewDrawer != null)
633         {
634             statusViewDrawer.updateStatusView(getString(R.string.camera_disconnected));
635             statusViewDrawer.updateConnectionStatus(ICameraConnection.CameraConnectionStatus.DISCONNECTED);
636         }
637     }
638
639     /**
640      *
641      *
642      */
643     @Override
644     public void onCameraOccursException(String message, Exception e)
645     {
646         Log.v(TAG, "onCameraOccursException() " + message);
647         try
648         {
649             e.printStackTrace();
650             ICameraConnection connection = getCameraConnection(interfaceProvider.getCammeraConnectionMethod());
651             if (connection != null)
652             {
653                 connection.alertConnectingFailed(message + " " + e.getLocalizedMessage());
654             }
655             if (statusViewDrawer != null)
656             {
657                 statusViewDrawer.updateStatusView(message);
658                 if (connection != null)
659                 {
660                     statusViewDrawer.updateConnectionStatus(connection.getConnectionStatus());
661                 }
662             }
663         }
664         catch (Exception ee)
665         {
666             ee.printStackTrace();
667         }
668     }
669
670     /**
671      *   BLE経由でカメラの電源を入れるかどうか
672      *
673      */
674     private boolean isBlePowerOn()
675     {
676         boolean ret = false;
677         try
678         {
679             if (interfaceProvider.getCammeraConnectionMethod() == ICameraConnection.CameraConnectionMethod.OPC)
680             {
681                 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
682                 ret = preferences.getBoolean(IPreferencePropertyAccessor.BLE_POWER_ON, false);
683                 // Log.v(TAG, "isBlePowerOn() : " + ret);
684             }
685         }
686         catch (Exception e)
687         {
688             e.printStackTrace();
689         }
690         return (ret);
691     }
692
693     /**
694      *    カメラへの自動接続を行うかどうか
695      *
696      */
697     private boolean isAutoConnectCamera()
698     {
699         boolean ret = true;
700         try
701         {
702             SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
703             ret = preferences.getBoolean(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, true);
704             // Log.v(TAG, "isAutoConnectCamera() : " + ret);
705         }
706         catch (Exception e)
707         {
708             e.printStackTrace();
709         }
710         return (ret);
711     }
712
713     /**
714      *
715      *
716      *
717      */
718     private ICameraConnection getCameraConnection(ICameraConnection.CameraConnectionMethod connectionMethod)
719     {
720         ICameraConnection connection;
721         if (connectionMethod == ICameraConnection.CameraConnectionMethod.RICOH_GR2)
722         {
723             connection = interfaceProvider.getRicohGr2Infterface().getRicohGr2CameraConnection();
724         }
725         else if  (connectionMethod == ICameraConnection.CameraConnectionMethod.SONY)
726         {
727             connection = interfaceProvider.getSonyInterface().getSonyCameraConnection();
728         }
729         else if  (connectionMethod == ICameraConnection.CameraConnectionMethod.PANASONIC)
730         {
731             connection = interfaceProvider.getPanasonicInterface().getPanasonicCameraConnection();
732         }
733         else if  (connectionMethod == ICameraConnection.CameraConnectionMethod.FUJI_X)
734         {
735             connection = interfaceProvider.getFujiXInterface().getFujiXCameraConnection();
736         }
737         else if  (connectionMethod == ICameraConnection.CameraConnectionMethod.OLYMPUS)
738         {
739             connection = interfaceProvider.getOlympusPenInterface().getOlyCameraConnection();
740         }
741         else if  (connectionMethod == ICameraConnection.CameraConnectionMethod.THETA)
742         {
743             connection = interfaceProvider.getThetaInterface().getCameraConnection();
744         }
745         else if  (connectionMethod == ICameraConnection.CameraConnectionMethod.CANON)
746         {
747             connection = interfaceProvider.getCanonInterface().getCameraConnection();
748         }
749         else if  (connectionMethod == ICameraConnection.CameraConnectionMethod.NIKON)
750         {
751             connection = interfaceProvider.getNikonInterface().getCameraConnection();
752         }
753         else // if (connectionMethod == ICameraConnection.CameraConnectionMethod.OPC)
754         {
755             connection = interfaceProvider.getOlympusInterface().getOlyCameraConnection();
756         }
757         return (connection);
758     }
759
760     /**
761      *   カメラへのBLE接続指示が完了したとき
762      *
763      * @param isExecuted  true : BLEで起動した, false : 起動していない、その他
764      */
765     @Override
766     public void wakeupExecuted(boolean isExecuted)
767     {
768         Log.v(TAG, "wakeupExecuted() : " + isExecuted);
769         if (isAutoConnectCamera())
770         {
771             // カメラへ自動接続する設定だった場合、カメラへWiFi接続する (BLEで起動しなくても)
772             changeCameraConnection();
773         }
774     }
775
776
777     @Override
778     public boolean onKeyDown(int keyCode, KeyEvent event)
779     {
780         Log.v(TAG, "onKeyDown()" + " " + keyCode);
781         try
782         {
783             if ((event.getAction() == KeyEvent.ACTION_DOWN)&&
784                     ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)||(keyCode == KeyEvent.KEYCODE_CAMERA)))
785             {
786                 if (liveViewFragment != null)
787                 {
788                     return (liveViewFragment.handleKeyDown(keyCode, event));
789                 }
790             }
791         }
792         catch (Exception e)
793         {
794             e.printStackTrace();
795         }
796         return (super.onKeyDown(keyCode, event));
797     }
798
799     @Override
800     public void updateMessage(final String message, final boolean isBold, final boolean isColor, final int color)
801     {
802         Log.v(TAG, " updateMessage() : " + message);
803 /**/
804         try {
805             final TextView messageArea = findViewById(R.id.message);
806             runOnUiThread(new Runnable() {
807                 @Override
808                 public void run() {
809                     try {
810                         if ((messageArea != null) && (message != null))
811                         {
812                             messageArea.setText(message);
813                             if (isBold)
814                             {
815                                 messageArea.setTypeface(Typeface.DEFAULT_BOLD);
816                             }
817                             if (isColor)
818                             {
819                                 messageArea.setTextColor(color);
820                             }
821                             else
822                             {
823                                 messageArea.setTextColor(Color.DKGRAY);
824                             }
825                             messageArea.invalidate();
826                         }
827                     }
828                     catch (Exception e)
829                     {
830                         e.printStackTrace();
831                     }
832                 }
833             });
834         }
835         catch (Exception e)
836         {
837             e.printStackTrace();
838         }
839 /**/
840     }
841 }