OSDN Git Service

シャッター半押し機能を追加する途中。
authorMRSa <mrsa@myad.jp>
Thu, 4 Oct 2018 15:05:11 +0000 (00:05 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 4 Oct 2018 15:05:11 +0000 (00:05 +0900)
14 files changed:
app/src/main/java/net/osdn/gokigen/a01d/camera/IFocusingControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/olympus/wrapper/OlyCameraFocusControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/operation/RicohGr2CameraFocusControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/operation/takepicture/RicohGr2AutoFocusControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/sony/operation/SonyCameraFocusControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/sony/operation/takepicture/SonyAutoFocusControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/sony/wrapper/ISonyCameraApi.java
app/src/main/java/net/osdn/gokigen/a01d/camera/sony/wrapper/SonyCameraApi.java
app/src/main/java/net/osdn/gokigen/a01d/liveview/LiveViewClickTouchListener.java
app/src/main/java/net/osdn/gokigen/a01d/liveview/LiveViewFragment.java
app/src/main/res/drawable/ic_center_focus_strong_black_24dp.xml [new file with mode: 0644]
app/src/main/res/drawable/ic_crop_free_black_24dp.xml [new file with mode: 0644]
app/src/main/res/layout-land/fragment_live_view.xml
app/src/main/res/layout/fragment_live_view.xml

index 31ecd85..ffae454 100644 (file)
@@ -10,4 +10,5 @@ public interface IFocusingControl
 {
     boolean driveAutoFocus(MotionEvent motionEvent);
     void unlockAutoFocus();
+    void halfPressShutter(boolean isPressed);
 }
index a3e1159..a729208 100644 (file)
@@ -69,4 +69,39 @@ public class OlyCameraFocusControl implements IFocusingControl
         }
     }
 
+    @Override
+    public void halfPressShutter(boolean isPressed)
+    {
+        if (isPressed)
+        {
+            // 中心にフォーカスを合わせる
+            if (frameDisplay != null)
+            {
+                Thread thread = new Thread(new Runnable() {
+                    @Override
+                    public void run() {
+                        PointF point = new PointF(0.5f, 0.5f);
+                        if (frameDisplay.isContainsPoint(point))
+                        {
+                            afControl.lockAutoFocus(point);
+                        }
+                    }
+                });
+                try
+                {
+                    thread.start();
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
+            }
+        }
+        else
+        {
+            // フォーカスを解除する
+            unlockAutoFocus();
+        }
+    }
+
 }
index a688c7d..25e5bab 100644 (file)
@@ -50,4 +50,10 @@ public class RicohGr2CameraFocusControl implements IFocusingControl
     {
         afControl.unlockAutoFocus();
     }
+
+    @Override
+    public void halfPressShutter(boolean isPressed)
+    {
+        afControl.halfPressShutter(isPressed);
+    }
 }
index fc4a846..d415c2f 100644 (file)
@@ -5,7 +5,6 @@ import android.graphics.RectF;
 import android.support.annotation.NonNull;
 import android.util.Log;
 
-import net.osdn.gokigen.a01d.camera.sony.operation.takepicture.SonyAutoFocusControl;
 import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
@@ -17,8 +16,9 @@ public class RicohGr2AutoFocusControl
     private static final String TAG = RicohGr2AutoFocusControl.class.getSimpleName();
     private final IIndicatorControl indicator;
     private final IAutoFocusFrameDisplay frameDisplayer;
-    private String lockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus/lock";
+    private String lockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus/lock";    // Pentax機の場合は /v1/lens/focus
     private String unlockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus/unlock";
+    private String halfPressShutterUrl = "http://192.168.0.1/_gr";
     private int timeoutMs = 6000;
 
 
@@ -132,6 +132,43 @@ public class RicohGr2AutoFocusControl
      *
      *
      */
+    public void halfPressShutter(final boolean isPressed)
+    {
+        Log.v(TAG, "halfPressShutter() " + isPressed);
+        try
+        {
+            Thread thread = new Thread(new Runnable()
+            {
+                @Override
+                public void run()
+                {
+                    try
+                    {
+                        String postData = (isPressed) ? "cmd=baf 1" : "cmd=baf 0";
+                        String result = SimpleHttpClient.httpPost(halfPressShutterUrl, postData, timeoutMs);
+                        if ((result == null)||(result.length() < 1))
+                        {
+                            Log.v(TAG, "halfPressShutter() [" + isPressed + "] reply is null.");
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            });
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     *
+     *
+     */
     private void showFocusFrame(RectF rect, IAutoFocusFrameDisplay.FocusFrameStatus status, double duration)
     {
         frameDisplayer.showFocusFrame(rect, status, duration);
index f51ef65..e22972c 100644 (file)
@@ -65,4 +65,18 @@ public class SonyCameraFocusControl  implements IFocusingControl
             e.printStackTrace();
         }
     }
+
+    @Override
+    public void halfPressShutter(boolean isPressed)
+    {
+        Log.v(TAG, "halfPressShutter() " + isPressed);
+        try
+        {
+            afControl.halfPressShutter(isPressed);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
 }
index c816a76..5d0674b 100644 (file)
@@ -111,6 +111,47 @@ public class SonyAutoFocusControl
     }
 
     /**
+     *   シャッター半押し処理
+     *
+     */
+    public void halfPressShutter(final boolean isPressed)
+    {
+        Log.v(TAG, "halfPressShutter() : " + isPressed);
+        if (cameraApi == null)
+        {
+            Log.v(TAG, "ISonyCameraApi is null...");
+            return;
+        }
+        try
+        {
+            Thread thread = new Thread(new Runnable()
+            {
+                @Override
+                public void run()
+                {
+                    try
+                    {
+                        JSONObject resultsObj = (isPressed) ? cameraApi.actHalfPressShutter() : cameraApi.cancelHalfPressShutter();
+                        if (resultsObj == null)
+                        {
+                            Log.v(TAG, "lockAutoFocus() [" + isPressed + "] reply is null.");
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        e.printStackTrace();
+                    }
+                }
+            });
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    /**
      *
      *
      */
index ee0d8ad..97ed280 100644 (file)
@@ -21,6 +21,9 @@ public interface ISonyCameraApi
     JSONObject getTouchAFPosition();
     JSONObject cancelTouchAFPosition();
 
+    JSONObject actHalfPressShutter();
+    JSONObject cancelHalfPressShutter();
+
     JSONObject setFocusMode(String focusMode);
     JSONObject getFocusMode();
     JSONObject getSupportedFocusMode();
index 7bfce4e..b67b5a5 100644 (file)
@@ -209,6 +209,34 @@ class SonyCameraApi implements ISonyCameraApi
     }
 
     @Override
+    public JSONObject actHalfPressShutter()
+    {
+        try
+        {
+            return (communicateJSON("camera", "actHalfPressShutter", new JSONArray(), "1.0", -1));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (new JSONObject());
+    }
+
+    @Override
+    public JSONObject cancelHalfPressShutter()
+    {
+        try
+        {
+            return (communicateJSON("camera", "cancelHalfPressShutter", new JSONArray(), "1.0", -1));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (new JSONObject());
+    }
+
+    @Override
     public JSONObject setFocusMode(String focusMode)
     {
         try
index 73719c6..74c5e9c 100644 (file)
@@ -143,6 +143,11 @@ class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchLi
                     actionZoomout();
                     break;
 
+                case R.id.focus_indicator:
+                    // フォーカスインジケータをクリックした
+                    actionFocusButton();
+                    break;
+
                 default:
                     Log.v(TAG, "onClick() : " + id);
                     break;
@@ -246,6 +251,17 @@ class LiveViewClickTouchListener implements View.OnClickListener, View.OnTouchLi
     }
 
     /**
+     *   フォーカスボタンが押されたとき...
+     *
+     */
+    private void actionFocusButton()
+    {
+
+
+
+    }
+
+    /**
      *   お気に入り設定ダイアログの表示
      *
      */
index 4325a6a..62f34a2 100644 (file)
@@ -151,6 +151,7 @@ public class LiveViewFragment extends Fragment implements IStatusViewDrawer, IFo
             view.findViewById(R.id.shutter_button).setOnClickListener(onClickTouchListener);
             view.findViewById(R.id.btn_zoomin).setOnClickListener(onClickTouchListener);
             view.findViewById(R.id.btn_zoomout).setOnClickListener(onClickTouchListener);
+            view.findViewById(R.id.focus_indicator).setOnClickListener(onClickTouchListener);
 
             manualFocus = view.findViewById(R.id.focusing_button);
             changeLiveViewScale = view.findViewById(R.id.live_view_scale_button);
diff --git a/app/src/main/res/drawable/ic_center_focus_strong_black_24dp.xml b/app/src/main/res/drawable/ic_center_focus_strong_black_24dp.xml
new file mode 100644 (file)
index 0000000..ab723e8
--- /dev/null
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M12,8c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4 -1.79,-4 -4,-4zM5,15L3,15v4c0,1.1 0.9,2 2,2h4v-2L5,19v-4zM5,5h4L9,3L5,3c-1.1,0 -2,0.9 -2,2v4h2L5,5zM19,3h-4v2h4v4h2L21,5c0,-1.1 -0.9,-2 -2,-2zM19,19h-4v2h4c1.1,0 2,-0.9 2,-2v-4h-2v4z"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_crop_free_black_24dp.xml b/app/src/main/res/drawable/ic_crop_free_black_24dp.xml
new file mode 100644 (file)
index 0000000..9b37938
--- /dev/null
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24.0"
+        android:viewportHeight="24.0">
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M3,5v4h2L5,5h4L9,3L5,3c-1.1,0 -2,0.9 -2,2zM5,15L3,15v4c0,1.1 0.9,2 2,2h4v-2L5,19v-4zM19,19h-4v2h4c1.1,0 2,-0.9 2,-2v-4h-2v4zM19,3h-4v2h4v4h2L21,5c0,-1.1 -0.9,-2 -2,-2z"/>
+</vector>
index fa00ffd..43221aa 100644 (file)
                 android:visibility="visible"
                 />
 
+            <ImageView
+                android:id="@+id/focus_indicator"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_alignLeft="@id/live_view_scale_button"
+                android:layout_alignStart="@id/live_view_scale_button"
+                android:layout_marginStart="8pt"
+                android:layout_marginLeft="8pt"
+                android:layout_marginBottom="3pt"
+                android:layout_above="@id/live_view_scale_button"
+                android:clickable="true"
+                android:contentDescription="@string/button"
+                android:focusable="true"
+                android:gravity="center"
+                android:scaleType="fitCenter"
+                android:src="@drawable/ic_crop_free_black_24dp"
+                android:visibility="visible" />
+
             <TextView
                 android:id="@+id/focal_length_with_digital_zoom_view"
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_marginRight="2pt"
                 android:layout_marginEnd="2pt"
-                android:layout_above="@id/live_view_scale_button"
+                android:layout_above="@id/focus_indicator"
                 android:layout_alignLeft="@id/live_view_scale_button"
                 android:layout_alignStart="@id/live_view_scale_button"
                 android:layout_marginLeft="4pt"
index 0b00237..eac2cf9 100644 (file)
         <ImageView
             android:id="@+id/focusing_button"
             android:layout_width="wrap_content"
-            android:layout_height="match_parent"
+            android:layout_height="wrap_content"
             android:layout_alignParentLeft="true"
             android:layout_alignParentStart="true"
-            android:layout_alignParentTop="true"
+            android:layout_alignParentBottom="true"
             android:layout_marginLeft="2pt"
             android:layout_marginStart="2pt"
             android:clickable="true"
             android:visibility="visible"
             android:src="@drawable/ic_zoom_in_black_24dp" />
 
+        <ImageView
+            android:id="@+id/focus_indicator"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignTop="@id/live_view_scale_button"
+            android:layout_alignParentStart="true"
+            android:layout_alignParentLeft="true"
+            android:layout_marginStart="4pt"
+            android:layout_marginLeft="4pt"
+            android:clickable="true"
+            android:contentDescription="@string/button"
+            android:focusable="true"
+            android:gravity="center"
+            android:scaleType="fitEnd"
+            android:src="@drawable/ic_crop_free_black_24dp"
+            android:visibility="visible" />
+
     </RelativeLayout>
 
     <RelativeLayout