OSDN Git Service

下部ボタンを少し大きくする。。
[gokigen/A01c.git] / wear / src / main / java / jp / sfjp / gokigen / a01c / MainActivity.java
index 5ced307..9a044da 100644 (file)
@@ -1,9 +1,12 @@
 package jp.sfjp.gokigen.a01c;
 
+import android.content.Intent;
+import android.content.SharedPreferences;
 import android.graphics.Color;
 import android.os.Bundle;
 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;
@@ -15,27 +18,31 @@ import android.support.v4.content.ContextCompat;
 
 import jp.sfjp.gokigen.a01c.liveview.CameraLiveImageView;
 import jp.sfjp.gokigen.a01c.liveview.CameraLiveViewListenerImpl;
+import jp.sfjp.gokigen.a01c.liveview.dialog.FavoriteSettingSelectionDialog;
+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.olycamerawrapper.OlyCameraCoordinator;
-import jp.sfjp.gokigen.a01c.preference.ICameraPropertyAccessor;
+import jp.sfjp.gokigen.a01c.preference.IPreferenceCameraPropertyAccessor;
 
 /**
  *   メインのActivity
  *
  */
-public class MainActivity extends WearableActivity implements  IChangeScene, IShowInformation, ICameraStatusReceiver
+public class MainActivity extends WearableActivity implements  IChangeScene, IShowInformation, ICameraStatusReceiver, IDialogDismissedNotifier
 {
     private final String TAG = toString();
     static final int REQUEST_NEED_PERMISSIONS = 1010;
+    //static final int COMMAND_MY_PROPERTY = 0x00000100;
 
     private CameraLiveImageView liveView = null;
     private IOlyCameraCoordinator coordinator = null;
     private IMessageDrawer messageDrawer = null;
     private OlyCameraLiveViewOnTouchListener listener = null;
+    private FavoriteSettingSelectionDialog selectionDialog = null;
     private Vibrator vibrator = null;
     private boolean cameraDisconnectedHappened = false;
     private boolean ambientMode = false;
@@ -90,6 +97,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
 
         setupCameraCoordinator();
+        setupInitialButtonIcons();
         setupActionListener();
     }
 
@@ -227,6 +235,91 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     }
 
     /**
+     *   ボタンアイコンの初期設定
+     *
+     */
+    private void setupInitialButtonIcons()
+    {
+        if (coordinator != null)
+        {
+            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
+            {
+                // ボタンをGrid ONアイコンにする
+                resId = R.drawable.btn_ic_grid_on;
+            }
+            setButtonDrawable(IShowInformation.BUTTON_1, resId);
+        }
+    }
+
+    /**
+     *   Intentを使ってWiFi設定画面を開く
+     *
+     */
+    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)
+        {
+            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);
+                return (true);
+            }
+            catch (android.content.ActivityNotFoundException ex2)
+            {
+                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);
+    }
+
+    /**
      *   Olympus Cameraクラスとのやりとりをするクラスを準備する
      *   (カメラとの接続も、ここでスレッドを起こして開始する)
      */
@@ -240,6 +333,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         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();
     }
 
@@ -287,7 +381,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         coordinator.stopLiveView();
 
         //  パラメータを確認し、カメラの電源を切る
-        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(ICameraPropertyAccessor.EXIT_APPLICATION_WITH_DISCONNECT, true))
+        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(IPreferenceCameraPropertyAccessor.EXIT_APPLICATION_WITH_DISCONNECT, true))
         {
             Log.v(TAG, "Shutdown camera...");
 
@@ -300,35 +394,47 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     }
 
     /**
+     *   接続機能を確認する
+     */
+    @Override
+    public boolean checkConnectionFeature(int id)
+    {
+        boolean ret = false;
+        if (id == 0)
+        {
+            // Wifi 設定画面を開く
+            ret = launchWifiSettingScreen();
+        }
+        return (ret);
+    }
+
+    /**
+     *   画面をタッチした場所を受信する
+     *
+     * @param posX  X座標位置 (0.0f - 1.0f)
+     * @param posY  Y座標位置 (0.0f - 1.0f)
+     * @return true / false
+     */
+    @Override
+    public boolean touchedPosition(float posX, float posY)
+    {
+        Log.v(TAG, "touchedPosition (" + posX + ", " + posY);
+        return ((liveView != null)&&(liveView.touchedPosition(posX, posY)));
+    }
+
+    /**
      *   接続状態を見る or 再接続する
      */
     @Override
     public boolean showConnectionStatus()
     {
-        if ((!listener.isEnabledOperation())&&(cameraDisconnectedHappened))
+        if ((listener.isEnabledOperation() == IShowInformation.operation.ONLY_CONNECT)&&(cameraDisconnectedHappened))
         {
             // カメラが切断されたとき、再接続を指示する
             connectToCamera();
             cameraDisconnectedHappened = false;
             return (true);
         }
-/*
-        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)
-        {
-            // Activity が存在しなかった...設定画面が起動できなかった
-            Log.v(TAG, "android.content.ActivityNotFoundException...");
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-*/
         return (false);
     }
 
@@ -352,7 +458,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         // ライブビューの開始 & タッチ/ボタンの操作を可能にする
         coordinator.startLiveView();
         coordinator.setRecViewMode(false);
-        listener.setEnableOperation(true);
+        listener.setEnableOperation(operation.ENABLE);
         setMessage(IShowInformation.AREA_C, Color.WHITE, "");
         coordinator.updateStatusAll();
     }
@@ -366,7 +472,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     {
         Log.v(TAG, "onCameraDisconnected()");
         setMessage(IShowInformation.AREA_C, Color.YELLOW, getString(R.string.camera_disconnected));
-        listener.setEnableOperation(false);
+        listener.setEnableOperation(operation.ONLY_CONNECT);
         cameraDisconnectedHappened = true;
     }
 
@@ -378,7 +484,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     {
         Log.v(TAG, "onCameraOccursException()");
         setMessage(IShowInformation.AREA_C, Color.YELLOW, message);
-        listener.setEnableOperation(false);
+        listener.setEnableOperation(operation.ONLY_CONNECT);
         cameraDisconnectedHappened = true;
     }
 
@@ -449,6 +555,16 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
                 messageDrawer.setMessageToShow(IMessageDrawer.MessageArea.LOWCENTER, color, IMessageDrawer.SIZE_STD, message);
                 return;
             }
+            if (area == IShowInformation.AREA_B)
+            {
+                messageDrawer.setMessageToShow(IMessageDrawer.MessageArea.CENTERLEFT, color, IMessageDrawer.SIZE_STD, message);
+                return;
+            }
+            if (area == IShowInformation.AREA_D)
+            {
+                messageDrawer.setMessageToShow(IMessageDrawer.MessageArea.CENTERRIGHT, color, IMessageDrawer.SIZE_STD, message);
+                return;
+            }
 
             if (id == 0)
             {
@@ -550,13 +666,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:
@@ -573,4 +689,42 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
             e.printStackTrace();
         }
     }
+
+    @Override
+    public void setEnabledOperation(IShowInformation.operation operation)
+    {
+        if (listener != null)
+        {
+            listener.setEnableOperation(operation);
+        }
+    }
+
+    /**
+     *   「お気に入り設定」表示画面を開く
+     *
+     */
+    @Override
+    public void showFavoriteSettingsDialog()
+    {
+        if ((liveView != null)&&(listener != null)&&(listener.isEnabledOperation() != operation.ONLY_CONNECT))
+        {
+            listener.setEnableOperation(operation.ENABLE_ONLY_TOUCHED_POSITION);
+            liveView.showDialog(selectionDialog);
+        }
+    }
+
+    /**
+     *   「お気に入り設定」表示画面を閉じる
+     *
+     */
+    @Override
+    public void dialogDismissed(boolean isExecuted)
+    {
+        if ((liveView != null)&&(listener != null))
+        {
+            liveView.hideDialog();
+            listener.setEnableOperation(operation.ENABLE);
+
+        }
+    }
 }