OSDN Git Service

・アプリが裏に回ったとき、カメラの電源を切るようにした。
authorMRSa <mrsa@myad.jp>
Sat, 11 Mar 2017 13:47:03 +0000 (22:47 +0900)
committerMRSa <mrsa@myad.jp>
Sat, 11 Mar 2017 13:47:03 +0000 (22:47 +0900)
・グリッドのON/OFF切り替えを実装。

app/src/main/java/jp/sfjp/gokigen/a01c/MainActivity.java
app/src/main/java/jp/sfjp/gokigen/a01c/liveview/CameraLiveImageView.java
app/src/main/java/jp/sfjp/gokigen/a01c/liveview/ILiveImageStatusNotify.java
app/src/main/java/jp/sfjp/gokigen/a01c/liveview/OlyCameraLiveViewOnTouchListener.java
app/src/main/java/jp/sfjp/gokigen/a01c/preference/ICameraPropertyAccessor.java

index 6d7bf01..7777b33 100644 (file)
@@ -1,7 +1,9 @@
 package jp.sfjp.gokigen.a01c;
 
+import android.content.SharedPreferences;
 import android.graphics.Color;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
 import android.support.wearable.activity.WearableActivity;
 import android.util.Log;
 import android.widget.ImageButton;
@@ -18,6 +20,7 @@ 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;
 
 /**
  *   メインのActivity
@@ -31,7 +34,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     private CameraLiveImageView liveView = null;
     private IOlyCameraCoordinator coordinator = null;
     private IMessageDrawer messageDrawer = null;
-
+    private OlyCameraLiveViewOnTouchListener listener = null;
     /**
      *
      */
@@ -39,6 +42,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     protected void onCreate(Bundle savedInstanceState)
     {
         super.onCreate(savedInstanceState);
+        Log.v(TAG, "onCreate()");
 
         //  画面全体の設定
         setContentView(R.layout.activity_main);
@@ -65,6 +69,8 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
                     REQUEST_NEED_PERMISSIONS);
         }
 
+        listener = new OlyCameraLiveViewOnTouchListener(this);
+
         setupCameraCoordinator();
         setupActionListener();
     }
@@ -88,8 +94,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         super.onPause();
         Log.v(TAG, "onPause()");
 
-        //coordinator.stopLiveView();
-        //exitApplication();
+
     }
 
     /**
@@ -100,6 +105,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     public void onStart()
     {
         super.onStart();
+        Log.v(TAG, "onStart()");
     }
 
     /**
@@ -110,6 +116,8 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     public void onStop()
     {
         super.onStop();
+        Log.v(TAG, "onStop()");
+        exitApplication();
     }
 
     /**
@@ -120,6 +128,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
      public void onEnterAmbient(Bundle ambientDetails)
      {
          super.onEnterAmbient(ambientDetails);
+         Log.v(TAG, "onEnterAmbient()");
      }
 
     /**
@@ -130,6 +139,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     public void onExitAmbient()
     {
         super.onExitAmbient();
+        Log.v(TAG, "onExitAmbient()");
     }
 
     /**
@@ -140,17 +150,15 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     public void onUpdateAmbient()
     {
         super.onUpdateAmbient();
+        Log.v(TAG, "onUpdateAmbient()");
     }
 
-
     /**
      *   ボタンが押された、画面がタッチされた、、は、リスナクラスで処理するよう紐づける
      *
      */
     private void setupActionListener()
     {
-        final OlyCameraLiveViewOnTouchListener listener = new OlyCameraLiveViewOnTouchListener(this);
-
         final ImageButton btn1 = (ImageButton) findViewById(R.id.btn_1);
         btn1.setOnClickListener(listener);
 
@@ -187,7 +195,7 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
         }
         liveView.setOnTouchListener(listener);
         messageDrawer = liveView.getMessageDrawer();
-        listener.prepareInterfaces(coordinator, liveView, liveView);
+        listener.prepareInterfaces(coordinator, this, liveView);
     }
 
     /**
@@ -230,23 +238,42 @@ public class MainActivity extends WearableActivity implements  IChangeScene, ISh
     {
         Log.v(TAG, "exitApplication()");
 
-        // カメラの電源をOFFにしたうえで、アプリケーションを終了する。
-        coordinator.getConnectionInterface().disconnect(true);
-        finish();
+        // ライブビューを停止させる
+        coordinator.stopLiveView();
+
+        //  パラメータを確認し、カメラの電源を切る
+        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(ICameraPropertyAccessor.EXIT_APPLICATION_WITH_DISCONNECT, true))
+        {
+            Log.v(TAG, "Shutdown camera...");
+
+            // カメラの電源をOFFにする
+            coordinator.getConnectionInterface().disconnect(true);
+        }
+        //finish();
+        //finishAndRemoveTask();
         //android.os.Process.killProcess(android.os.Process.myPid());
     }
 
+    /**
+     *
+     */
     @Override
     public void onStatusNotify(String message)
     {
         setMessage(IShowInformation.AREA_C, Color.WHITE, message);
     }
 
+    /**
+     *
+     */
     @Override
     public void onCameraConnected()
     {
         Log.v(TAG, "onCameraConnected()");
+
+        // ライブビューの開始 & タッチ/ボタンの操作を可能にする
         coordinator.startLiveView();
+        listener.setEnableOperation(true);
         setMessage(IShowInformation.AREA_C, Color.WHITE, "");
     }
 
index 2dac8c8..7136682 100644 (file)
@@ -37,7 +37,7 @@ import jp.sfjp.gokigen.a01c.preference.ICameraPropertyAccessor;
  *    (OLYMPUS の ImageCaptureSample をカスタマイズ)
  *
  */
-public class CameraLiveImageView extends View implements CameraLiveViewListenerImpl.IImageDataReceiver, IAutoFocusFrameDisplay, ILiveImageStatusNotify, IStatusViewDrawer
+public class CameraLiveImageView extends View implements CameraLiveViewListenerImpl.IImageDataReceiver, IAutoFocusFrameDisplay, ILiveImageStatusNotify
 {
     private final String TAG = this.toString();
 
@@ -727,7 +727,7 @@ public class CameraLiveImageView extends View implements CameraLiveViewListenerI
         setShowGridFrame(!showGridFeature);
     }
 
-
+    @Override
     public boolean isShowGrid()
     {
         return (showGridFeature);
@@ -741,22 +741,4 @@ public class CameraLiveImageView extends View implements CameraLiveViewListenerI
     {
         return (messageHolder);
     }
-
-    @Override
-    public void updateStatusView(String message)
-    {
-
-    }
-
-    @Override
-    public void updateGridFrameStatus()
-    {
-
-    }
-
-    @Override
-    public void showFavoriteSettingDialog()
-    {
-
-    }
 }
index 835dd35..28b7ed0 100644 (file)
@@ -7,4 +7,5 @@ package jp.sfjp.gokigen.a01c.liveview;
 public interface ILiveImageStatusNotify
 {
     void toggleShowGridFrame();
+    boolean isShowGrid();
 }
index f3605bf..c5000a4 100644 (file)
@@ -9,9 +9,10 @@ import android.view.MotionEvent;
 import android.view.View;
 import android.widget.Toast;
 
+import jp.sfjp.gokigen.a01c.IShowInformation;
 import jp.sfjp.gokigen.a01c.R;
 import jp.sfjp.gokigen.a01c.olycamerawrapper.IOlyCameraCoordinator;
-import jp.sfjp.gokigen.a01c.preference.ICameraPropertyAccessor;
+
 
 /**
  *
@@ -22,32 +23,50 @@ public class OlyCameraLiveViewOnTouchListener  implements View.OnClickListener,
     private final String TAG = toString();
     private final Context context;
     private IOlyCameraCoordinator camera = null;
-    private IStatusViewDrawer statusDrawer = null;
+    private IShowInformation statusDrawer = null;
     private ILiveImageStatusNotify liveImageView = null;
     private final SharedPreferences preferences;
 
+    private boolean prohibitOperation = true;
+
+    /**
+     *
+     */
     public OlyCameraLiveViewOnTouchListener(Context context)
     {
         this.context = context;
         preferences = PreferenceManager.getDefaultSharedPreferences(context);
     }
 
-    public void prepareInterfaces(IOlyCameraCoordinator cameraCoordinator, IStatusViewDrawer statusDrawer, ILiveImageStatusNotify liveImageView)
+    /**
+     *
+     */
+    public void prepareInterfaces(IOlyCameraCoordinator cameraCoordinator, IShowInformation statusDrawer, ILiveImageStatusNotify liveImageView)
     {
         this.camera = cameraCoordinator;
         this.statusDrawer = statusDrawer;
         this.liveImageView = liveImageView;
     }
 
+    /**
+     *
+     */
     @Override
     public void onClick(View v)
     {
         int id = v.getId();
         Log.v(TAG, "onClick() : " + id);
+        if (prohibitOperation)
+        {
+            // 操作禁止の指示がされていた場合は何もしない
+            Log.v(TAG, "onClick() : prohibit operation");
+            return;
+        }
+
         switch (id)
         {
             case R.id.btn_1:
-                //pushShutterButton();
+                changeShowGrid();
                 break;
 
             case R.id.btn_2:
@@ -93,11 +112,21 @@ public class OlyCameraLiveViewOnTouchListener  implements View.OnClickListener,
         }
     }
 
+    /**
+     *
+     */
     @Override
     public boolean onTouch(View v, MotionEvent event)
     {
         int id = v.getId();
         Log.v(TAG, "onTouch() : " + id);
+        if (prohibitOperation)
+        {
+            // 操作禁止の指示がされていた場合は何もしない
+            Log.v(TAG, "onTouch() : prohibit operation");
+            return (false);
+        }
+
         if (id == R.id.liveview)
         {
             return (camera.driveAutoFocus(event));
@@ -106,6 +135,32 @@ public class OlyCameraLiveViewOnTouchListener  implements View.OnClickListener,
     }
 
     /**
+     *   操作の可否を設定する。
+     *
+     *    @param operation  true: 操作可能, false: 操作不可
+     *
+     */
+    public void setEnableOperation(boolean operation)
+    {
+        prohibitOperation = !operation;
+    }
+
+
+    /***************************************************************
+     *   ボタンが押された時の処理... あとで切り離す。
+     *
+     ***************************************************************/
+
+
+    private void changeTakeMode()
+    {
+
+
+
+    }
+
+
+    /**
      *   シャッターボタンが押された!
      *   (現在は、連続撮影モードやムービー撮影についてはまだ非対応)
      */
@@ -119,4 +174,35 @@ public class OlyCameraLiveViewOnTouchListener  implements View.OnClickListener,
             Toast.makeText(context, R.string.shoot_camera, Toast.LENGTH_SHORT).show();
         }
     }
+
+    /**
+     *   グリッド表示の ON/OFFを切り替える
+     *
+     */
+    private void changeShowGrid()
+    {
+        liveImageView.toggleShowGridFrame();
+        updateGridStatusButton(IShowInformation.BUTTON_1);
+    }
+
+    /**
+     *  グリッドフレームの表示・非表示ボタンを更新する
+     *
+     */
+    private void updateGridStatusButton(int buttonId)
+    {
+        int btnResId;
+        if (liveImageView.isShowGrid())
+        {
+            // グリッドがON状態、グリッドをOFFにするボタンを出す
+            btnResId = R.drawable.btn_ic_grid_off;
+        }
+        else
+        {
+            //  グリッドがOFF状態、グリッドをONにするボタンを出す
+            btnResId = R.drawable.btn_ic_grid_on;
+        }
+        statusDrawer.setButtonDrawable(buttonId, btnResId);
+    }
+
 }
index 1402237..0a95442 100644 (file)
@@ -53,6 +53,7 @@ public interface ICameraPropertyAccessor
     String PHONE_CAMERA_ROTATION_DEFAULT_VALUE = "90";
 
     String EXIT_APPLICATION = "exit_application";
+    String EXIT_APPLICATION_WITH_DISCONNECT = "exit_app_and_disconn";
 
     String PLAYBACK_CAMERA = "playback_camera";
     String PLAYBACK_PHONE = "playback_phone";