OSDN Git Service

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