package net.osdn.gokigen.cameratest.camtest;
import android.app.Activity;
+import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PointF;
import net.osdn.gokigen.cameratest.R;
import net.osdn.gokigen.cameratest.fuji.Connection;
+import net.osdn.gokigen.cameratest.fuji.preference.FujiPreferenceFragment;
import net.osdn.gokigen.cameratest.fuji.ILiveViewImage;
import net.osdn.gokigen.cameratest.fuji.ReceivedDataHolder;
+import net.osdn.gokigen.cameratest.fuji.preference.IPreferencePropertyAccessor;
import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatus;
import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusNotify;
import androidx.annotation.NonNull;
+import androidx.preference.EditTextPreference;
+import androidx.preference.PreferenceManager;
public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiveViewImage, IFujiStatusNotify
{
private final Activity activity;
private TextView textview;
private Connection connection;
+
+ private FujiPreferenceFragment preferenceFragment = null;
//private FileOutputStream outputStream = null;
private static final int offsetSize = 18; // 4byte: データサイズ、14byte: (謎の)ヘッダ
+ private float maxPointLimitWidth = 7.0f;
+ private float maxPointLimitHeight = 7.0f;
+ private float widthOffset = 1.0f;
+ private float heightOffset = 1.0f;
+
+
public CamTest(@NonNull Activity activity)
{
this.activity = activity;
//prepareFile();
Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.connect, Snackbar.LENGTH_SHORT).show();
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
+ final boolean isBothLiveView = preferences.getBoolean(IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW, false);
+
+ // フォーカス解像度を変えたい
+ String focusPoint = preferences.getString(IPreferencePropertyAccessor.FUJIX_FOCUS_XY, IPreferencePropertyAccessor.FUJIX_FOCUS_XY_DEFAULT_VALUE);
+ try
+ {
+ String[] focus = focusPoint.split(",");
+ if (focus.length == 2)
+ {
+ maxPointLimitWidth = Integer.parseInt(focus[0]);
+ maxPointLimitHeight = Integer.parseInt(focus[1]);
+ }
+ Log.v(TAG, "FOCUS RESOLUTION : " + maxPointLimitWidth + "," + maxPointLimitHeight);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ maxPointLimitWidth = 7.0f;
+ maxPointLimitHeight = 7.0f;
+ }
+
showMessageText("START CONNECT");
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
- boolean ret = connection.start_connect();
+ boolean ret = connection.start_connect(isBothLiveView);
if (!ret)
{
- showMessageText("CONNECT FAILURE...");
+ showMessageText("CONNECT FAILURE... : " + isBothLiveView);
}
}
});
public void disconnect()
{
+ Log.v(TAG, "Disconnect");
+
+ showMessageText("DISCONNECT");
try
{
- connection.disconnect();
+ Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.action_disconnect, Snackbar.LENGTH_SHORT).show();
+ Thread thread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ connection.disconnect();
+ }
+ });
+ thread.start();
}
catch (Exception e)
{
{
e.printStackTrace();
}
-
}
+
/*
public void settings()
{
- Log.v(TAG, "settings menu");
+ Log.v(TAG, "Show settings menu");
+
+ if (preferenceFragment == null)
+ {
+ preferenceFragment = FujiPreferenceFragment.newInstance();
+ }
+ FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
+ transaction.replace(R.id.fragment1, logCatFragment);
+ // backstackに追加
+ transaction.addToBackStack(null);
+ transaction.commit();
+
showMessageText("BBBB");
}
}
}
+ public void setFocusLimitWidth(float max, float offset)
+ {
+ maxPointLimitWidth = max;
+ widthOffset = offset;
+ }
+
+
+ public void setFocusLimitHeight(float max, float offset)
+ {
+ maxPointLimitHeight = max;
+ heightOffset = offset;
+ }
+
private void driveAutoFocus(final PointF point)
{
if (point == null)
{
try
{
- final byte[] dataValue = receivedData.getData();
+ //final byte[] dataValue = receivedData.getData();
//byte[] startJpegMarker = {(byte)0xff, (byte)0xd8};
//byte[] endJpegMarker = {(byte)0xff, (byte)0xd9};
- Log.v(TAG, "Image : "+ dataValue.length + " bytes.");
+ //Log.v(TAG, "Image : "+ dataValue.length + " bytes.");
// ダミーの記録ファイルが開いていたらファイルに書いておく。
//outputFile(receivedData);
final Bitmap imageData = getBitmap(receivedData);
if (imageData != null)
{
- ////// 画像を更新する
- 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();
+ // int width = imageData.getWidth();
+ // int height = imageData.getHeight();
+ //if ((width > 300)&&(height > 300))
+ {
+ //Log.v(TAG, "bitmap (" + width + "," + height + ")");
+
+ ////// 表示画像を更新する
+ 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)
final Bitmap imageData = BitmapFactory.decodeByteArray(data, offsetSize, (data.length - offsetSize));
if (imageData == null)
{
- Log.v(TAG, "getBitmap() : NULL. (offset : " + offsetSize + ")");
+ //Log.v(TAG, "getBitmap() : NULL. (offset : " + offsetSize + ")");
return (null);
}
return (imageData);
try
{
ImageView imageView = activity.findViewById(R.id.imageView);
- return (new PointF(((event.getX() / (float) imageView.getWidth()) * 255.0f), ((event.getY() / (float) imageView.getHeight()) * 255.0f)));
+ return (new PointF((((event.getX() / (float) imageView.getWidth()) * maxPointLimitWidth) + widthOffset), (((event.getY() / (float) imageView.getHeight()) * maxPointLimitHeight) + heightOffset)));
}
catch (Exception e)
{
{
try
{
- Log.v(TAG, "statusUpdated()");
+ //Log.v(TAG, "statusUpdated()");
// 情報エリアの内容を更新する
final InformationView view = activity.findViewById(R.id.information_view);