OSDN Git Service

ConnectionMethodの違いで背景画像を変更した。
[gokigen/A01c.git] / wear / src / main / java / jp / sfjp / gokigen / a01c / MainActivity.java
index 1ec9375..14d7f9c 100644 (file)
@@ -3,18 +3,21 @@ package jp.sfjp.gokigen.a01c;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.graphics.Color;
+import android.graphics.drawable.Drawable;
 import android.os.Bundle;
+import android.os.PowerManager;
 import android.os.Vibrator;
 import android.preference.PreferenceManager;
 import android.provider.Settings;
-import android.support.wearable.activity.WearableActivity;
 import android.util.Log;
 import android.widget.ImageButton;
 import android.widget.TextView;
 import android.Manifest;
 import android.content.pm.PackageManager;
-import android.support.v4.app.ActivityCompat;
-import android.support.v4.content.ContextCompat;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
 
 import jp.sfjp.gokigen.a01c.liveview.CameraLiveImageView;
 import jp.sfjp.gokigen.a01c.liveview.CameraLiveViewListenerImpl;
@@ -23,29 +26,34 @@ import jp.sfjp.gokigen.a01c.liveview.dialog.IDialogDismissedNotifier;
 import jp.sfjp.gokigen.a01c.olycamerawrapper.dispatcher.FeatureDispatcher;
 import jp.sfjp.gokigen.a01c.liveview.ICameraStatusReceiver;
 import jp.sfjp.gokigen.a01c.liveview.IMessageDrawer;
-import jp.sfjp.gokigen.a01c.liveview.OlyCameraLiveViewOnTouchListener;
-import jp.sfjp.gokigen.a01c.olycamerawrapper.IOlyCameraCoordinator;
+import jp.sfjp.gokigen.a01c.liveview.CameraLiveViewOnTouchListener;
 import jp.sfjp.gokigen.a01c.olycamerawrapper.OlyCameraCoordinator;
 import jp.sfjp.gokigen.a01c.preference.IPreferenceCameraPropertyAccessor;
+import jp.sfjp.gokigen.a01c.preference.PreferenceAccessWrapper;
+import jp.sfjp.gokigen.a01c.thetacamerawrapper.ThetaCameraController;
 
 /**
  *   メインのActivity
  *
  */
-public class MainActivity extends WearableActivity implements  IChangeScene, IShowInformation, ICameraStatusReceiver, IDialogDismissedNotifier
+public class MainActivity extends AppCompatActivity implements  IChangeScene, IShowInformation, ICameraStatusReceiver, IDialogDismissedNotifier
 {
     private final String TAG = toString();
     static final int REQUEST_NEED_PERMISSIONS = 1010;
-    static final int COMMAND_MY_PROPERTY = 0x00000100;
+    //static final int COMMAND_MY_PROPERTY = 0x00000100;
 
+    private PreferenceAccessWrapper preferences = null;
+    private PowerManager powerManager = null;
     private CameraLiveImageView liveView = null;
-    private IOlyCameraCoordinator coordinator = null;
+    private ICameraController currentCoordinator = null;
+    private ICameraController olyAirCoordinator = null;
+    private ICameraController thetaCoordinator = null;
     private IMessageDrawer messageDrawer = null;
-    private OlyCameraLiveViewOnTouchListener listener = null;
+    private CameraLiveViewOnTouchListener listener = null;
     private FavoriteSettingSelectionDialog selectionDialog = null;
     private Vibrator vibrator = null;
     private boolean cameraDisconnectedHappened = false;
-    private boolean ambientMode = false;
+    //private boolean ambientMode = false;
 
     /**
      *
@@ -57,7 +65,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         Log.v(TAG, "onCreate()");
 
         // Ambientモードを許してみる...
-        setAmbientEnabled();
+        //setAmbientEnabled();
 
         //  画面全体の設定
         setContentView(R.layout.activity_main);
@@ -85,20 +93,30 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
                     REQUEST_NEED_PERMISSIONS);
         }
 
-        if (!hasGps())
+        try
         {
-            // GPS機能が搭載されていない場合...
-            Log.d(TAG, "This hardware doesn't have GPS.");
-            // Fall back to functionality that does not use location or
-            // warn the user that location function is not available.
-        }
+            if (!hasGps())
+            {
+                // GPS機能が搭載されていない場合...
+                Log.d(TAG, "This hardware doesn't have GPS.");
+                // Fall back to functionality that does not use location or
+                // warn the user that location function is not available.
+            }
 
-        // バイブレータをつかまえる
-        vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
+            // バイブレータをつかまえる
+            vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
 
-        setupCameraCoordinator();
-        setupInitialButtonIcons();
-        setupActionListener();
+            // パワーマネージャをつかまえる
+            powerManager = (PowerManager) getSystemService(POWER_SERVICE);
+
+            setupCameraCoordinator();
+            setupInitialButtonIcons();
+            setupActionListener();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -144,10 +162,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         exitApplication();
     }
 
-    /**
-     *
-     *
-     */
+/*
      @Override
      public void onEnterAmbient(Bundle ambientDetails)
      {
@@ -156,10 +171,6 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
          ambientMode =true;
      }
 
-    /**
-     *
-     *
-     */
     @Override
     public void onExitAmbient()
     {
@@ -168,16 +179,13 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         ambientMode = false;
     }
 
-    /**
-     *
-     *
-     */
     @Override
     public void onUpdateAmbient()
     {
         super.onUpdateAmbient();
         Log.v(TAG, "onUpdateAmbient()");
     }
+*/
 
     /**
      *   ボタンが押された、画面がタッチされた、、は、リスナクラスで処理するよう紐づける
@@ -185,53 +193,60 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
      */
     private void setupActionListener()
     {
-        final ImageButton btn1 = (ImageButton) findViewById(R.id.btn_1);
-        btn1.setOnClickListener(listener);
-        btn1.setOnLongClickListener(listener);
+        try
+        {
+            final ImageButton btn1 = findViewById(R.id.btn_1);
+            btn1.setOnClickListener(listener);
+            btn1.setOnLongClickListener(listener);
 
-        final ImageButton btn2 = (ImageButton) findViewById(R.id.btn_2);
-        btn2.setOnClickListener(listener);
-        btn2.setOnLongClickListener(listener);
+            final ImageButton btn2 = findViewById(R.id.btn_2);
+            btn2.setOnClickListener(listener);
+            btn2.setOnLongClickListener(listener);
 
-        final ImageButton btn3 = (ImageButton) findViewById(R.id.btn_3);
-        btn3.setOnClickListener(listener);
-        btn3.setOnLongClickListener(listener);
+            final ImageButton btn3 = findViewById(R.id.btn_3);
+            btn3.setOnClickListener(listener);
+            btn3.setOnLongClickListener(listener);
 
-        final ImageButton btn4 = (ImageButton) findViewById(R.id.btn_4);
-        btn4.setOnClickListener(listener);
-        btn4.setOnLongClickListener(listener);
+            final ImageButton btn4 = findViewById(R.id.btn_4);
+            btn4.setOnClickListener(listener);
+            btn4.setOnLongClickListener(listener);
 
-        final ImageButton btn5 = (ImageButton) findViewById(R.id.btn_5);
-        btn5.setOnClickListener(listener);
-        btn5.setOnLongClickListener(listener);
+            final ImageButton btn5 = findViewById(R.id.btn_5);
+            btn5.setOnClickListener(listener);
+            btn5.setOnLongClickListener(listener);
 
-        final ImageButton btn6 = (ImageButton) findViewById(R.id.btn_6);
-        btn6.setOnClickListener(listener);
-        btn6.setOnLongClickListener(listener);
+            final ImageButton btn6 = findViewById(R.id.btn_6);
+            btn6.setOnClickListener(listener);
+            btn6.setOnLongClickListener(listener);
 
-        final TextView textArea1 = (TextView) findViewById(R.id.text_1);
-        textArea1.setOnClickListener(listener);
-        textArea1.setOnLongClickListener(listener);
+            final TextView textArea1 = findViewById(R.id.text_1);
+            textArea1.setOnClickListener(listener);
+            textArea1.setOnLongClickListener(listener);
 
-        final TextView textArea2 = (TextView) findViewById(R.id.text_2);
-        textArea2.setOnClickListener(listener);
-        textArea2.setOnLongClickListener(listener);
+            final TextView textArea2 = findViewById(R.id.text_2);
+            textArea2.setOnClickListener(listener);
+            textArea2.setOnLongClickListener(listener);
 
-        final TextView textArea3 = (TextView) findViewById(R.id.text_3);
-        textArea3.setOnClickListener(listener);
-        textArea3.setOnLongClickListener(listener);
+            final TextView textArea3 = findViewById(R.id.text_3);
+            textArea3.setOnClickListener(listener);
+            textArea3.setOnLongClickListener(listener);
 
-        final TextView textArea4 = (TextView) findViewById(R.id.text_4);
-        textArea4.setOnClickListener(listener);
-        textArea4.setOnLongClickListener(listener);
+            final TextView textArea4 = findViewById(R.id.text_4);
+            textArea4.setOnClickListener(listener);
+            textArea4.setOnLongClickListener(listener);
 
-        if (liveView == null)
+            if (liveView == null)
+            {
+                liveView = findViewById(R.id.liveview);
+            }
+            liveView.setOnTouchListener(listener);
+            messageDrawer = liveView.getMessageDrawer();
+            messageDrawer.setLevelGauge(currentCoordinator.getLevelGauge());
+        }
+        catch (Exception e)
         {
-            liveView = (CameraLiveImageView) findViewById(R.id.liveview);
+            e.printStackTrace();
         }
-        liveView.setOnTouchListener(listener);
-        messageDrawer = liveView.getMessageDrawer();
-        messageDrawer.setLevelGauge(coordinator.getLevelGauge());
     }
 
     /**
@@ -240,21 +255,25 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
      */
     private void setupInitialButtonIcons()
     {
-        if (coordinator != null)
+        try
         {
-            int resId;
-            SharedPreferences preferences = android.support.v7.preference.PreferenceManager.getDefaultSharedPreferences(this);
-            if (preferences.getBoolean(IPreferenceCameraPropertyAccessor.SHOW_GRID_STATUS, true))
-            {
-                // ボタンをGrid OFFアイコンにする
-                resId = R.drawable.btn_ic_grid_off;
-            }
-            else
+            if (currentCoordinator != null)
             {
-                // ボタンをGrid ONアイコンにする
-                resId = R.drawable.btn_ic_grid_on;
+                int resId;
+                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
+                if (preferences.getBoolean(IPreferenceCameraPropertyAccessor.SHOW_GRID_STATUS, true)) {
+                    // ボタンをGrid OFFアイコンにする
+                    resId = R.drawable.btn_ic_grid_off;
+                } else {
+                    // ボタンをGrid ONアイコンにする
+                    resId = R.drawable.btn_ic_grid_on;
+                }
+                setButtonDrawable(IShowInformation.BUTTON_1, resId);
             }
-            setButtonDrawable(IShowInformation.BUTTON_1, resId);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
         }
     }
 
@@ -264,44 +283,58 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
      */
     private boolean launchWifiSettingScreen()
     {
+        Log.v(TAG, "launchWifiSettingScreen()");
         try
         {
             // Wifi 設定画面を表示する... (SONY Smart Watch 3では開かないけど...)
             startActivity(new Intent("com.google.android.clockwork.settings.connectivity.wifi.ADD_NETWORK_SETTINGS"));
             return (true);
         }
-        catch (android.content.ActivityNotFoundException ex)
+        catch (Exception ex)
         {
-            Log.v(TAG, "android.content.ActivityNotFoundException... " + "com.google.android.clockwork.settings.connectivity.wifi.ADD_NETWORK_SETTINGS");
             try
             {
-                // SONY Smart Watch 3で開く場合のIntent...
-                Intent intent = new Intent("com.google.android.clockwork.settings.connectivity.wifi.ADD_NETWORK_SETTINGS");
-                intent.setClassName("com.google.android.apps.wearable.settings", "com.google.android.clockwork.settings.wifi.WifiSettingsActivity");
-                startActivity(intent);
+                Log.v(TAG, "launchWifiSettingScreen() : ACTION_WIFI_SETTINGS");
+                startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                 return (true);
             }
-            catch (android.content.ActivityNotFoundException ex2)
+            catch (Exception e)
             {
+                Log.v(TAG, "android.content.ActivityNotFoundException... " + "com.google.android.clockwork.settings.connectivity.wifi.ADD_NETWORK_SETTINGS");
                 try
                 {
-                    // Wifi 設定画面を表示する...普通のAndroidの場合
-                    startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
+                    // SONY Smart Watch 3で開く場合のIntent...
+                    Intent intent = new Intent("com.google.android.clockwork.settings.connectivity.wifi.ADD_NETWORK_SETTINGS");
+                    intent.setClassName("com.google.android.apps.wearable.settings", "com.google.android.clockwork.settings.wifi.WifiSettingsActivity");
+                    startActivity(intent);
                     return (true);
                 }
-                catch (Exception ee)
+                catch (Exception ex2)
                 {
-                    ee.printStackTrace();
+                    try
+                    {
+                        // Wifi 設定画面を表示する...普通のAndroidの場合
+                        startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
+                        return (true);
+                    }
+                    catch (Exception ee)
+                    {
+                        ee.printStackTrace();
+                        try
+                        {
+                            // LG G Watch Rで開く場合のIntent...
+                            Intent intent = new Intent("android.intent.action.MAIN");
+                            intent.setClassName("com.google.android.apps.wearable.settings", "com.google.android.clockwork.settings.MainSettingsActivity");
+                            startActivity(intent);
+                            return (true);
+                        }
+                        catch (android.content.ActivityNotFoundException ex3)
+                        {
+                            ex3.printStackTrace();
+                        }
+                    }
                 }
             }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-        }
-        catch (Exception e2)
-        {
-            e2.printStackTrace();
         }
         return (false);
     }
@@ -312,16 +345,27 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
      */
     private void setupCameraCoordinator()
     {
-        if (liveView == null)
+        try
+        {
+            preferences = new PreferenceAccessWrapper(this);
+            preferences.initialize();
+            String connectionMethod = preferences.getString(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD, IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
+            if (liveView == null)
+            {
+                liveView = findViewById(R.id.liveview);
+            }
+            olyAirCoordinator = new OlyCameraCoordinator(this, liveView, this, this);
+            thetaCoordinator = new ThetaCameraController(this, liveView, this, this);
+            currentCoordinator = olyAirCoordinator; // (connectionMethod.contains(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA)) ? thetaCoordinator : olyAirCoordinator;
+            currentCoordinator.setLiveViewListener(new CameraLiveViewListenerImpl(liveView));
+            listener = new CameraLiveViewOnTouchListener(this, new FeatureDispatcher(this, this, currentCoordinator, preferences, liveView), this);
+            selectionDialog = new FavoriteSettingSelectionDialog(this, currentCoordinator.getCameraPropertyLoadSaveOperations(), this);
+            connectToCamera();
+        }
+        catch (Exception e)
         {
-            liveView = (CameraLiveImageView) findViewById(R.id.liveview);
+            e.printStackTrace();
         }
-        coordinator = null;
-        coordinator = new OlyCameraCoordinator(this, liveView, this, this);
-        coordinator.setLiveViewListener(new CameraLiveViewListenerImpl(liveView));
-        listener = new OlyCameraLiveViewOnTouchListener(this, new FeatureDispatcher(this, coordinator, liveView), this);
-        selectionDialog = new FavoriteSettingSelectionDialog(this, coordinator.getCameraPropertyLoadSaveOperations(), this);
-        connectToCamera();
     }
 
     /**
@@ -335,7 +379,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
             @Override
             public void run()
             {
-                coordinator.getConnectionInterface().connect();
+                currentCoordinator.getConnectionInterface().connect();
             }
         });
         try
@@ -355,36 +399,52 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     @Override
     public void exitApplication()
     {
-        Log.v(TAG, "exitApplication()");
-        if (ambientMode)
+        try
         {
-            // アンビエントモードの時(≒自分でアプリを終了しなかったとき)は、何もしない
-            // (接続したままとする)
-            Log.v(TAG, "keep liveview.");
-            return;
-        }
+            Log.v(TAG, "exitApplication()");
+/*
+            if (ambientMode)
+            {
+                // アンビエントモードの時(≒自分でアプリを終了しなかったとき)は、何もしない
+                // (接続したままとする)
+                Log.v(TAG, "keep liveview.");
+                return;
+            }
+*/
 
-        // ライブビューを停止させる
-        coordinator.stopLiveView();
+            // パワーマネージャを確認し、interactive modeではない場合は、ライブビューも止めず、カメラの電源も切らない
+            if ((powerManager != null) && (!powerManager.isInteractive()))
+            {
+                Log.v(TAG, "not interactive, keep liveview.");
+                return;
+            }
 
-        //  パラメータを確認し、カメラの電源を切る
-        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(IPreferenceCameraPropertyAccessor.EXIT_APPLICATION_WITH_DISCONNECT, true))
-        {
-            Log.v(TAG, "Shutdown camera...");
+            // ライブビューを停止させる
+            currentCoordinator.stopLiveView();
 
-            // カメラの電源をOFFにする
-            coordinator.getConnectionInterface().disconnect(true);
+            //  パラメータを確認し、カメラの電源を切る
+            if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(IPreferenceCameraPropertyAccessor.EXIT_APPLICATION_WITH_DISCONNECT, true))
+            {
+                Log.v(TAG, "Shutdown camera...");
+
+                // カメラの電源をOFFにする
+                currentCoordinator.getConnectionInterface().disconnect(true);
+            }
+            //finish();
+            //finishAndRemoveTask();
+            //android.os.Process.killProcess(android.os.Process.myPid());
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
         }
-        //finish();
-        //finishAndRemoveTask();
-        //android.os.Process.killProcess(android.os.Process.myPid());
     }
 
     /**
      *   接続機能を確認する
      */
     @Override
-    public boolean checkConnectionFeature(int id)
+    public boolean checkConnectionFeature(int id, int btnId)
     {
         boolean ret = false;
         if (id == 0)
@@ -392,6 +452,11 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
             // Wifi 設定画面を開く
             ret = launchWifiSettingScreen();
         }
+        else if (id == 1)
+        {
+            // 接続の変更を確認する
+            changeConnectionMethod();
+        }
         return (ret);
     }
 
@@ -415,12 +480,18 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     @Override
     public boolean showConnectionStatus()
     {
-        if ((listener.isEnabledOperation() == IShowInformation.operation.ONLY_CONNECT)&&(cameraDisconnectedHappened))
+        try
         {
-            // カメラが切断されたとき、再接続を指示する
-            connectToCamera();
-            cameraDisconnectedHappened = false;
-            return (true);
+            if ((listener.isEnabledOperation() == IShowInformation.operation.ONLY_CONNECT) && (cameraDisconnectedHappened)) {
+                // カメラが切断されたとき、再接続を指示する
+                connectToCamera();
+                cameraDisconnectedHappened = false;
+                return (true);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
         }
         return (false);
     }
@@ -441,13 +512,19 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     public void onCameraConnected()
     {
         Log.v(TAG, "onCameraConnected()");
-
-        // ライブビューの開始 & タッチ/ボタンの操作を可能にする
-        coordinator.startLiveView();
-        coordinator.setRecViewMode(false);
-        listener.setEnableOperation(operation.ENABLE);
-        setMessage(IShowInformation.AREA_C, Color.WHITE, "");
-        coordinator.updateStatusAll();
+        try
+        {
+            // ライブビューの開始 & タッチ/ボタンの操作を可能にする
+            currentCoordinator.startLiveView();
+            currentCoordinator.setRecViewMode(false);
+            listener.setEnableOperation(operation.ENABLE);
+            setMessage(IShowInformation.AREA_C, Color.WHITE, "");
+            currentCoordinator.updateStatusAll();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -458,9 +535,16 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     public void onCameraDisconnected()
     {
         Log.v(TAG, "onCameraDisconnected()");
-        setMessage(IShowInformation.AREA_C, Color.YELLOW, getString(R.string.camera_disconnected));
-        listener.setEnableOperation(operation.ONLY_CONNECT);
-        cameraDisconnectedHappened = true;
+        try
+        {
+            setMessage(IShowInformation.AREA_C, Color.YELLOW, getString(R.string.camera_disconnected));
+            listener.setEnableOperation(operation.ONLY_CONNECT);
+            cameraDisconnectedHappened = true;
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
     }
 
     /**
@@ -470,9 +554,17 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     public void onCameraOccursException(String message, Exception e)
     {
         Log.v(TAG, "onCameraOccursException()");
-        setMessage(IShowInformation.AREA_C, Color.YELLOW, message);
-        listener.setEnableOperation(operation.ONLY_CONNECT);
-        cameraDisconnectedHappened = true;
+        try
+        {
+            setMessage(IShowInformation.AREA_C, Color.YELLOW, message);
+            listener.setEnableOperation(operation.ONLY_CONNECT);
+            cameraDisconnectedHappened = true;
+        }
+        catch (Exception ee)
+        {
+            e.printStackTrace();
+            ee.printStackTrace();
+        }
     }
 
     /**s
@@ -564,11 +656,15 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         runOnUiThread(new Runnable()
         {
              @Override
-             public void run() {
-                 final TextView textArea = (TextView) findViewById(areaId);
-                 textArea.setTextColor(color);
-                 textArea.setText(message);
-                 textArea.invalidate();
+             public void run()
+             {
+                 final TextView textArea = findViewById(areaId);
+                 if (textArea != null)
+                 {
+                     textArea.setTextColor(color);
+                     textArea.setText(message);
+                     textArea.invalidate();
+                 }
              }
         });
     }
@@ -610,10 +706,22 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         runOnUiThread(new Runnable()
         {
             @Override
-            public void run() {
-                final ImageButton button = (ImageButton) findViewById(areaId);
-                button.setImageDrawable(getDrawable(labelId));
-                button.invalidate();
+            public void run()
+            {
+                try
+                {
+                    final ImageButton button = findViewById(areaId);
+                    final Drawable drawTarget = ContextCompat.getDrawable(getApplicationContext(), labelId);
+                    if (button != null)
+                    {
+                        button.setImageDrawable(drawTarget);
+                        button.invalidate();
+                    }
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
             }
         });
     }
@@ -653,13 +761,13 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
                             vibrator.vibrate(150);
                             break;
                         case IShowInformation.VIBRATE_PATTERN_SIMPLE_MIDDLE:
-                            vibrator.vibrate(75);
+                            vibrator.vibrate(80);
                             break;
                         case IShowInformation.VIBRATE_PATTERN_SIMPLE_SHORT:
-                            vibrator.vibrate(20);
+                            vibrator.vibrate(30);
                             break;
                         case IShowInformation.VIBRATE_PATTERN_SHORT_DOUBLE:
-                            long[] pattern = { 10, 25, 20, 25, 0 };
+                            long[] pattern = { 10, 35, 30, 35, 0 };
                             vibrator.vibrate(pattern, -1);
                             break;
                         case IShowInformation.VIBRATE_PATTERN_NONE:
@@ -707,11 +815,95 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     @Override
     public void dialogDismissed(boolean isExecuted)
     {
-        if ((liveView != null)&&(listener != null))
+        try
         {
-            liveView.hideDialog();
-            listener.setEnableOperation(operation.ENABLE);
+            if ((liveView != null) && (listener != null))
+            {
+                liveView.hideDialog();
+                listener.setEnableOperation(operation.ENABLE);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    private void updateConnectionMethodMessage()
+    {
+        try
+        {
+            String connectionMethod = preferences.getString(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD, IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
+            int methodId = (connectionMethod.contains(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA)) ? R.string.connection_method_theta : R.string.connection_method_opc;
+            setMessage(IShowInformation.AREA_5, Color.MAGENTA, getString(methodId));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
 
+    private void updateConnectionMethod(String parameter, ICameraController method)
+    {
+        try
+        {
+            currentCoordinator = method;
+            preferences.putString(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD, parameter);
+            vibrate(IShowInformation.VIBRATE_PATTERN_SHORT_DOUBLE);
         }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     *   接続方式を変更するか確認する (OPC ⇔ THETA)
+     *
+     */
+    private void changeConnectionMethod()
+    {
+        final AppCompatActivity activity = this;
+        runOnUiThread(new Runnable() {
+            @Override
+            public void run() {
+                try
+                {
+                    int titleId = R.string.change_title_from_opc_to_theta;
+                    int messageId = R.string.change_message_from_opc_to_theta;
+                    boolean method = false;
+                    String connectionMethod = preferences.getString(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD, IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
+                    if (connectionMethod.contains(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA))
+                    {
+                        titleId = R.string.change_title_from_theta_to_opc;
+                        messageId = R.string.change_message_from_theta_to_opc;
+                        method = true;
+                    }
+                    final boolean isTheta = method;
+                    ConfirmationDialog confirmation = new ConfirmationDialog(activity);
+                    confirmation.show(titleId, messageId, new ConfirmationDialog.Callback() {
+                        @Override
+                        public void confirm() {
+                            Log.v(TAG, " --- CONFIRMED! --- (theta:" + isTheta + ")");
+                            if (isTheta)
+                            {
+                                // 接続方式を OPC に切り替える
+                                updateConnectionMethod(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_OPC, olyAirCoordinator);
+                            }
+                            else
+                            {
+                                // 接続方式を Theta に切り替える
+                                updateConnectionMethod(IPreferenceCameraPropertyAccessor.CONNECTION_METHOD_THETA, olyAirCoordinator);  // thetaCoordinator
+                            }
+                            updateConnectionMethodMessage();
+                        }
+                    });
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+            }
+        });
     }
 }