import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.PointF;
import android.os.Environment;
import android.util.Log;
+import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.io.FileInputStream;
-public class CamTest implements View.OnClickListener, ILiveViewImage
+public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiveViewImage
{
private String TAG = toString();
private final Activity activity;
doShutter();
break;
case R.id.button2:
- //readImageFile("sampledata1.bin");
- //showMessageText("show 'sampledata1.bin'.");
+ unlockFocus();
break;
case R.id.button3:
//readImageFile("sampledata2.bin");
}
}
+ private void driveAutoFocus(final PointF point)
+ {
+ if (point == null)
+ {
+ return;
+ }
+ try
+ {
+ Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.drive_af, Snackbar.LENGTH_SHORT).show();
+ showMessageText("AF : " + point.x + "," + point.y);
+ Thread thread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ boolean ret = connection.execute_focus_point(point);
+ if (!ret)
+ {
+ showMessageText("Auto Focus FAILURE...");
+ }
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ private void unlockFocus()
+ {
+ try
+ {
+ Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.unlock_focus, Snackbar.LENGTH_SHORT).show();
+ Thread thread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ boolean ret = connection.execute_unlock_focus();
+ if (!ret)
+ {
+ showMessageText("Unlock Focus FAILURE...");
+ }
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
@Override
public void updateImage(ReceivedDataHolder receivedData)
{
}
return (null);
}
+
+ @Override
+ public boolean onTouch(View v, MotionEvent event)
+ {
+ try
+ {
+ int id = v.getId();
+ Log.v(TAG, "onTouch() : " + id);
+ if (event.getAction() == MotionEvent.ACTION_DOWN)
+ {
+ driveAutoFocus(getPointWithEvent(event));
+ return (true);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (false);
+ }
+
+ private PointF getPointWithEvent(MotionEvent event)
+ {
+ if (event == null)
+ {
+ return (null);
+ }
+ try
+ {
+ ImageView imageView = activity.findViewById(R.id.imageView);
+ return (new PointF(((event.getX() / (float) imageView.getWidth()) * 100.0f), ((event.getY() / (float) imageView.getHeight()) * 100.0f)));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (null);
+ }
}
package net.osdn.gokigen.cameratest.fuji;
+import android.graphics.PointF;
import android.util.Log;
import androidx.annotation.NonNull;
System.gc();
}
+ public boolean execute_focus_point(PointF point)
+ {
+ try
+ {
+ byte x = (byte) (0x000000ff & Math.round(point.x));
+ byte y = (byte) (0x000000ff & Math.round(point.y));
+ Log.v(TAG, "DRIVE AF (" + x + "," + y + ")");
+
+ comm.send_to_camera(sequence.execute_focus_lock(x, y), true);
+
+ ReceivedDataHolder rx_bytes = comm.receive_from_camera();
+ dump_bytes(16, rx_bytes);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (false);
+ }
+
+ public boolean execute_unlock_focus()
+ {
+ try
+ {
+ comm.send_to_camera(sequence.execute_focus_unlock(), true);
+
+ ReceivedDataHolder rx_bytes = comm.receive_from_camera();
+ dump_bytes(17, rx_bytes);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (false);
+ }
+
public boolean execute_shutter()
{
try
private final String ipAddress;
private final int portNumber;
private final ILiveViewImage imageViewer;
- private static final int WAIT_MS = 75;
+ private static final int WAIT_MS = 80;
private static final int BUFFER_SIZE = 1280 * 1024 + 8;
private boolean isStart = false;
});
}
+
+
+ byte[] execute_focus_lock(byte pointX, byte pointY)
+ {
+ return (new byte[] {
+
+ // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+ (byte)0x01, (byte)0x00,
+
+ // message_header.type : focus_point (0x9026)
+ (byte)0x26, (byte)0x90,
+
+ // message_id (0~1づつ繰り上がる...
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+
+ // data ...
+ pointY, pointX, (byte)0x00, (byte)0x00,
+
+ });
+ }
+
+
+ byte[] execute_focus_unlock()
+ {
+ return (new byte[] {
+
+ // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+ (byte)0x01, (byte)0x00,
+
+ // message_header.type : focus_unlock (0x9027)
+ (byte)0x27, (byte)0x90,
+
+ // message_id (0~1づつ繰り上がる...
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+ });
+ }
+
}
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
+import android.widget.ImageView;
import android.widget.TextView;
import net.osdn.gokigen.cameratest.R;
{
if (testTarget != null)
{
+ ImageView imageView = rootView.findViewById(R.id.imageView);
Button btn1 = rootView.findViewById(R.id.button1);
Button btn2 = rootView.findViewById(R.id.button2);
Button btn3 = rootView.findViewById(R.id.button3);
btn2.setOnClickListener(testTarget);
btn3.setOnClickListener(testTarget);
btn4.setOnClickListener(testTarget);
+ imageView.setOnTouchListener(testTarget);
}
}
catch (Exception e)
<ImageView
android:id="@+id/imageView"
- android:layout_width="wrap_content"
- android:layout_height="320dp"
+ android:layout_width="fill_parent"
+ android:layout_height="0dip"
android:layout_marginTop="2dp"
android:contentDescription="@string/blank"
android:scaleType="fitCenter"
<string name="action_exit_app">Exit</string>
<string name="action_settings">Settings</string>
<string name="action_wifi_settings">WiFi Settings</string>
- <string name="section_format">Hello World from section: %1$d</string>
+ <string name="section_format">%1$d</string>
<string name="connect">Try connect</string>
<string name="shutter">Execute Shutter</string>
+ <string name="drive_af">Drive AF</string>
+ <string name="unlock_focus">Focus Unlock</string>
<string name="label_button1">1</string>
<string name="label_button2">2</string>
<string name="label_button3">3</string>