• R/O
  • HTTP
  • SSH
  • HTTPS

FujiCam: Commit

Fujifilm X Series Remote Control for Android (Prototype)

Fujifilm Xシリーズカメラの遠隔操作アプリ for Android (プロトタイプ)


Commit MetaInfo

Revisión31d5b79bc41b732f89f11f9ab2fcd6f5ca6d3d11 (tree)
Tiempo2019-05-25 00:57:51
AutorMRSa <mrsa@myad...>
CommiterMRSa

Log Message

ライブビューの受信間隔もパラメータ化。

Cambiar Resumen

Diferencia incremental

--- a/app/src/main/java/net/osdn/gokigen/cameratest/camtest/CamTest.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/camtest/CamTest.java
@@ -23,7 +23,6 @@ import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatus;
2323 import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusNotify;
2424
2525 import androidx.annotation.NonNull;
26-import androidx.preference.EditTextPreference;
2726 import androidx.preference.PreferenceManager;
2827
2928 public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiveViewImage, IFujiStatusNotify
@@ -46,7 +45,7 @@ public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiv
4645 public CamTest(@NonNull Activity activity)
4746 {
4847 this.activity = activity;
49- this.connection = new Connection(this, this);
48+ this.connection = new Connection(activity, this, this);
5049 }
5150
5251 public void connect()
--- a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/Communication.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/Communication.java
@@ -1,5 +1,6 @@
11 package net.osdn.gokigen.cameratest.fuji;
22
3+import android.app.Activity;
34 import android.util.Log;
45
56 import androidx.annotation.NonNull;
@@ -30,9 +31,9 @@ class Communication
3031 private final FujiStreamReceiver stream;
3132 private final FujiAsyncResponseReceiver response;
3233
33- Communication(@NonNull ILiveViewImage imageViewer)
34+ Communication(@NonNull Activity activity, @NonNull ILiveViewImage imageViewer)
3435 {
35- this.stream = new FujiStreamReceiver(CAMERA_IP, STREAM_PORT, imageViewer);
36+ this.stream = new FujiStreamReceiver(activity, CAMERA_IP, STREAM_PORT, imageViewer);
3637 this.response = new FujiAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
3738 }
3839
--- a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/Connection.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/Connection.java
@@ -1,5 +1,6 @@
11 package net.osdn.gokigen.cameratest.fuji;
22
3+import android.app.Activity;
34 import android.graphics.PointF;
45 import android.util.Log;
56
@@ -16,9 +17,9 @@ public class Connection implements IFujiStatusRequest
1617 private final Communication comm;
1718 private final FujiStatusChecker statusChecker;
1819
19- public Connection(@NonNull ILiveViewImage imageViewer, @NonNull IFujiStatusNotify notify)
20+ public Connection(@NonNull Activity activity, @NonNull ILiveViewImage imageViewer, @NonNull IFujiStatusNotify notify)
2021 {
21- this.comm = new Communication(imageViewer);
22+ this.comm = new Communication(activity, imageViewer);
2223 this.sequence = new MessageSequence();
2324 this.statusChecker = new FujiStatusChecker(this, notify);
2425 }
--- a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/FujiAsyncResponseReceiver.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/FujiAsyncResponseReceiver.java
@@ -12,6 +12,7 @@ class FujiAsyncResponseReceiver
1212 private final int portNumber;
1313 private static final int BUFFER_SIZE = 1280 + 8;
1414 private static final int WAIT_MS = 250; // 250ms
15+ private static final int ERROR_LIMIT = 30;
1516 private boolean isStart = false;
1617
1718 FujiAsyncResponseReceiver(String ip, int portNumber)
@@ -22,6 +23,11 @@ class FujiAsyncResponseReceiver
2223
2324 void start()
2425 {
26+ if (isStart)
27+ {
28+ // すでに受信スレッド動作中なので抜ける
29+ return;
30+ }
2531 isStart = true;
2632 Thread thread = new Thread(new Runnable()
2733 {
@@ -57,6 +63,7 @@ class FujiAsyncResponseReceiver
5763
5864 private void startReceive(Socket socket)
5965 {
66+ int errorCount = 0;
6067 InputStreamReader isr;
6168 char[] char_array;
6269 try
@@ -81,10 +88,17 @@ class FujiAsyncResponseReceiver
8188 //return (new ReceivedDataHolder(char_array, read_bytes));
8289
8390 Thread.sleep(WAIT_MS);
91+ errorCount = 0;
8492 }
8593 catch (Exception e)
8694 {
8795 e.printStackTrace();
96+ errorCount++;
97+ }
98+ if (errorCount > ERROR_LIMIT)
99+ {
100+ // エラーが連続でたくさん出たらループをストップさせる
101+ isStart = false;
88102 }
89103 }
90104 try
--- a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/FujiStreamReceiver.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/FujiStreamReceiver.java
@@ -1,29 +1,59 @@
11 package net.osdn.gokigen.cameratest.fuji;
22
3+import android.app.Activity;
4+import android.content.SharedPreferences;
35 import android.util.Log;
46 import androidx.annotation.NonNull;
7+import androidx.preference.PreferenceManager;
8+
59 import java.io.InputStream;
610 import java.net.Socket;
711
12+import static net.osdn.gokigen.cameratest.fuji.preference.IPreferencePropertyAccessor.FUJIX_LIVEVIEW_WAIT;
13+import static net.osdn.gokigen.cameratest.fuji.preference.IPreferencePropertyAccessor.FUJIX_LIVEVIEW_WAIT_DEFAULT_VALUE;
14+
815 class FujiStreamReceiver
916 {
1017 private final String TAG = toString();
1118 private final String ipAddress;
1219 private final int portNumber;
1320 private final ILiveViewImage imageViewer;
14- private static final int WAIT_MS = 80;
21+ private int waitMs = 80;
1522 private static final int BUFFER_SIZE = 1280 * 1024 + 8;
23+ private static final int ERROR_LIMIT = 30;
1624 private boolean isStart = false;
1725
18- FujiStreamReceiver(String ip, int portNumber, @NonNull ILiveViewImage imageViewer)
26+ FujiStreamReceiver(@NonNull Activity activity, String ip, int portNumber, @NonNull ILiveViewImage imageViewer)
1927 {
2028 this.ipAddress = ip;
2129 this.portNumber = portNumber;
2230 this.imageViewer = imageViewer;
31+
32+ try
33+ {
34+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
35+ String waitMsStr = preferences.getString(FUJIX_LIVEVIEW_WAIT, FUJIX_LIVEVIEW_WAIT_DEFAULT_VALUE);
36+ int wait = Integer.parseInt(waitMsStr);
37+ if ((wait >= 10)&&(wait <= 800))
38+ {
39+ waitMs = wait;
40+ }
41+ }
42+ catch (Exception e)
43+ {
44+ e.printStackTrace();
45+ waitMs = 80;
46+ }
47+ Log.v(TAG, "LOOP WAIT : " + waitMs + " ms");
2348 }
2449
2550 void start()
2651 {
52+ if (isStart)
53+ {
54+ // すでに受信スレッド動作中なので抜ける
55+ return;
56+ }
2757 isStart = true;
2858 Thread thread = new Thread(new Runnable()
2959 {
@@ -59,6 +89,7 @@ class FujiStreamReceiver
5989
6090 private void startReceive(Socket socket)
6191 {
92+ int errorCount = 0;
6293 InputStream isr;
6394 byte[] byteArray;
6495 try
@@ -78,11 +109,18 @@ class FujiStreamReceiver
78109 {
79110 int read_bytes = isr.read(byteArray, 0, BUFFER_SIZE);
80111 imageViewer.updateImage(new ReceivedDataHolder(byteArray, read_bytes));
81- Thread.sleep(WAIT_MS);
112+ Thread.sleep(waitMs);
113+ errorCount = 0;
82114 }
83115 catch (Exception e)
84116 {
85117 e.printStackTrace();
118+ errorCount++;
119+ }
120+ if (errorCount > ERROR_LIMIT)
121+ {
122+ // エラーが連続でたくさん出たらループをストップさせる
123+ isStart = false;
86124 }
87125 }
88126 try
--- a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/preference/FujiPreferenceFragment.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/preference/FujiPreferenceFragment.java
@@ -17,7 +17,6 @@ import androidx.preference.PreferenceManager;
1717 import net.osdn.gokigen.cameratest.IApplicationControl;
1818 import net.osdn.gokigen.cameratest.R;
1919
20-import java.net.Inet4Address;
2120 import java.util.Map;
2221
2322 public class FujiPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener
@@ -116,6 +115,17 @@ public class FujiPreferenceFragment extends PreferenceFragmentCompat implements
116115 {
117116 e.printStackTrace();
118117 }
118+ try
119+ {
120+ EditTextPreference lvWait = (EditTextPreference) findPreference(IPreferencePropertyAccessor.FUJIX_LIVEVIEW_WAIT);
121+ String wait = lvWait.getText();
122+ int waitMs = Integer.parseInt(wait);
123+ lvWait.setText("" + waitMs);
124+ }
125+ catch (Exception e)
126+ {
127+ e.printStackTrace();
128+ }
119129 }
120130
121131 /**
@@ -141,6 +151,9 @@ public class FujiPreferenceFragment extends PreferenceFragmentCompat implements
141151 if (!items.containsKey(IPreferencePropertyAccessor.FUJIX_FOCUS_XY)) {
142152 editor.putString(IPreferencePropertyAccessor.FUJIX_FOCUS_XY, IPreferencePropertyAccessor.FUJIX_FOCUS_XY_DEFAULT_VALUE);
143153 }
154+ if (!items.containsKey(IPreferencePropertyAccessor.FUJIX_LIVEVIEW_WAIT)) {
155+ editor.putString(IPreferencePropertyAccessor.FUJIX_LIVEVIEW_WAIT, IPreferencePropertyAccessor.FUJIX_LIVEVIEW_WAIT_DEFAULT_VALUE);
156+ }
144157 editor.apply();
145158 }
146159 catch (Exception e)
--- a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/preference/IPreferencePropertyAccessor.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/preference/IPreferencePropertyAccessor.java
@@ -10,7 +10,11 @@ public interface IPreferencePropertyAccessor
1010 String CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW = "capture_both_camera_and_live_view";
1111
1212 String FUJIX_DISPLAY_CAMERA_VIEW = "fujix_display_camera_view";
13+
1314 String FUJIX_FOCUS_XY = "fujix_focus_xy";
1415 String FUJIX_FOCUS_XY_DEFAULT_VALUE = "7,7";
1516
17+ String FUJIX_LIVEVIEW_WAIT = "fujix_liveview_wait";
18+ String FUJIX_LIVEVIEW_WAIT_DEFAULT_VALUE = "80";
19+
1620 }
--- a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/FujiStatusChecker.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/statuses/FujiStatusChecker.java
@@ -12,6 +12,7 @@ public class FujiStatusChecker implements IFujiStatusReceiver
1212 private final IFujiStatusRequest comm;
1313 private final IFujiStatusNotify notify;
1414 private final FujiStatusHolder statusHolder;
15+ private static final int ERROR_LIMIT = 10;
1516 private boolean threadIsRunning = false;
1617 private final int WAIT_MS = 400;
1718
@@ -35,22 +36,28 @@ public class FujiStatusChecker implements IFujiStatusReceiver
3536 @Override
3637 public void run()
3738 {
38- try
39+
40+ int errorCount = 0;
41+ threadIsRunning = true;
42+ while (threadIsRunning)
3943 {
40- threadIsRunning = true;
41- while (threadIsRunning)
44+ try
4245 {
4346 comm.requestStatus();
4447 Thread.sleep(WAIT_MS);
48+ errorCount = 0;
49+ }
50+ catch (Exception e)
51+ {
52+ e.printStackTrace();
53+ errorCount++;
54+ }
55+ if (errorCount > ERROR_LIMIT)
56+ {
57+ threadIsRunning = false;
4558 }
4659 }
47- catch (Exception e)
48- {
49- e.printStackTrace();
50- }
51- threadIsRunning = false;
5260 Log.v(TAG, "--- FINISH STATUS WATCH ---");
53-
5461 }
5562 });
5663 try
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -37,8 +37,11 @@
3737 <string name="pref_fujix_display_camera_view">Use Camera Display</string>
3838 <string name="pref_fujix_display_camera_view_summary">Shows liveview screen both camera and smartphone.</string>
3939
40- <string name="pref_fujix_focus_xy">Focus Area X,Y (default: 7,7)</string>
41- <string name="pref_summary_fujix_focus_xy">Set Focus Area resolution X,Y (default: 7,7)</string>
40+ <string name="pref_fujix_focus_xy">Number of Focus Point X,Y (default: 7,7)</string>
41+ <string name="pref_summary_fujix_focus_xy"> </string>
42+
43+ <string name="pref_fujix_liveview_wait">Liveview receive wait (default: 80)</string>
44+ <string name="pref_summary_fujix_liveview_wait"> </string>
4245
4346 <string name="pref_special_thanks">Special Thanks to : fuji-cam-wifi-tool</string>
4447
--- a/app/src/main/res/xml/preferences_fuji_x.xml
+++ b/app/src/main/res/xml/preferences_fuji_x.xml
@@ -30,6 +30,12 @@
3030 android:defaultValue="7,7"
3131 android:summary="@string/pref_summary_fujix_focus_xy" />
3232
33+ <EditTextPreference
34+ android:key="fujix_liveview_wait"
35+ android:title="@string/pref_fujix_liveview_wait"
36+ android:defaultValue="80"
37+ android:summary="@string/pref_summary_fujix_liveview_wait" />
38+
3339 <CheckBoxPreference
3440 android:key="capture_both_camera_and_live_view"
3541 android:title="@string/pref_capture_both_camera_and_live_view" />
Show on old repository browser