package net.osdn.gokigen.cameratest.camtest;
import android.app.Activity;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Environment;
import android.util.Log;
import android.view.View;
+import android.widget.ImageView;
import android.widget.TextView;
import com.google.android.material.snackbar.Snackbar;
import net.osdn.gokigen.cameratest.R;
import net.osdn.gokigen.cameratest.fuji.Connection;
+import net.osdn.gokigen.cameratest.fuji.ILiveViewImage;
+import net.osdn.gokigen.cameratest.fuji.ReceivedDataHolder;
import androidx.annotation.NonNull;
-public class CamTest implements View.OnClickListener
+import java.io.File;
+import java.io.FileOutputStream;
+
+public class CamTest implements View.OnClickListener, ILiveViewImage
{
private String TAG = toString();
private final Activity activity;
private TextView textview;
private Connection connection;
+ private FileOutputStream outputStream = null;
+
public CamTest(@NonNull Activity activity)
{
this.activity = activity;
- this.connection = new Connection();
+ this.connection = new Connection(this);
}
public void connect()
Log.v(TAG, "connect request");
try
{
+ //prepareFile();
+
Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.connect, Snackbar.LENGTH_SHORT).show();
showMessageText("START CONNECT");
}
}
-
private void doShutter()
{
Log.v(TAG, "execute shutter");
}
}
+ @Override
+ public void updateImage(ReceivedDataHolder receivedData)
+ {
+ try
+ {
+ final byte[] dataValue = receivedData.getData();
+ byte[] startJpegMarker = {(byte)0xff, (byte)0xd8};
+ byte[] endJpegMarker = {(byte)0xff, (byte)0xd9};
+
+ Log.v(TAG, "Image : "+ dataValue.length + " bytes.");
+
+ // ダミーの記録ファイルが開いていたらファイルに書いておく。
+ if (outputStream != null)
+ {
+ outputStream.write(dataValue, 0, dataValue.length);
+ }
+
+ /////// 画像を作る
+ final Bitmap imageData = BitmapFactory.decodeByteArray(dataValue, 18, (dataValue.length - 18));
+ if (imageData == null)
+ {
+ Log.v(TAG, "imageData is null...");
+ }
+ else
+ {
+ Log.v(TAG, "imageData : " + imageData.getByteCount() + " bytes.");
+ }
+
+ ////// 画像を更新する
+ activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ try
+ {
+ // ビットマップイメージを表示する。
+ ImageView view = activity.findViewById(R.id.imageView);
+ view.setImageBitmap(imageData);
+ view.invalidate();
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void prepareFile()
+ {
+ try
+ {
+ final String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/AirA01a/";
+ final String outputFileName = "camtest.bin";
+ File filepath = new File(directoryPath.toLowerCase(), outputFileName.toLowerCase());
+ outputStream = new FileOutputStream(filepath);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ outputStream = null;
+ }
+ }
+
}
import android.util.Log;
+import androidx.annotation.NonNull;
+
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
private final FujiStreamReceiver stream;
private final FujiAsyncResponseReceiver response;
- Communication()
+ Communication(@NonNull ILiveViewImage imageViewer)
{
- this.stream = new FujiStreamReceiver(CAMERA_IP, STREAM_PORT);
+ this.stream = new FujiStreamReceiver(CAMERA_IP, STREAM_PORT, imageViewer);
this.response = new FujiAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
}
package net.osdn.gokigen.cameratest.fuji;
import android.util.Log;
+
+import androidx.annotation.NonNull;
+
import java.io.InputStreamReader;
import java.net.Socket;
private final String TAG = toString();
private final String ipAddress;
private final int portNumber;
+ private final ILiveViewImage imageViewer;
private static final int BUFFER_SIZE = 1280 * 1024 + 8;
private static final int WAIT_MS = 50;
private boolean isStart = false;
- FujiStreamReceiver(String ip, int portNumber)
+ FujiStreamReceiver(String ip, int portNumber, @NonNull ILiveViewImage imageViewer)
{
this.ipAddress = ip;
this.portNumber = portNumber;
+ this.imageViewer = imageViewer;
}
void start()
try
{
int read_bytes = isr.read(char_array, 0, BUFFER_SIZE);
- Log.v(TAG, "RECEIVE STREAM : " + read_bytes + " bytes.");
- //return (new ReceivedDataHolder(char_array, read_bytes));
+ imageViewer.updateImage(new ReceivedDataHolder(char_array, read_bytes));
Thread.sleep(WAIT_MS);
}