• R/O
  • HTTP
  • SSH
  • HTTPS

FujiCam: Commit

Fujifilm X Series Remote Control for Android (Prototype)

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


Commit MetaInfo

Revisãoe53e8901bec2e5e15c1c8c78ba68cad63530e971 (tree)
Hora2019-05-22 00:39:13
AutorMRSa <mrsa@myad...>
CommiterMRSa

Mensagem de Log

接続シーケンスの改良で、LV同時出力も実施してみた。

Mudança Sumário

Diff

--- a/app/src/main/java/net/osdn/gokigen/cameratest/camtest/CamTest.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/camtest/CamTest.java
@@ -1,6 +1,7 @@
11 package net.osdn.gokigen.cameratest.camtest;
22
33 import android.app.Activity;
4+import android.content.SharedPreferences;
45 import android.graphics.Bitmap;
56 import android.graphics.BitmapFactory;
67 import android.graphics.PointF;
@@ -17,10 +18,12 @@ import net.osdn.gokigen.cameratest.fuji.Connection;
1718 import net.osdn.gokigen.cameratest.fuji.preference.FujiPreferenceFragment;
1819 import net.osdn.gokigen.cameratest.fuji.ILiveViewImage;
1920 import net.osdn.gokigen.cameratest.fuji.ReceivedDataHolder;
21+import net.osdn.gokigen.cameratest.fuji.preference.IPreferencePropertyAccessor;
2022 import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatus;
2123 import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusNotify;
2224
2325 import androidx.annotation.NonNull;
26+import androidx.preference.PreferenceManager;
2427
2528 public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiveViewImage, IFujiStatusNotify
2629 {
@@ -53,14 +56,17 @@ public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiv
5356 //prepareFile();
5457 Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.connect, Snackbar.LENGTH_SHORT).show();
5558
59+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
60+ final boolean isBothLiveView = preferences.getBoolean(IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW, false);
61+
5662 showMessageText("START CONNECT");
5763 Thread thread = new Thread(new Runnable() {
5864 @Override
5965 public void run() {
60- boolean ret = connection.start_connect();
66+ boolean ret = connection.start_connect(isBothLiveView);
6167 if (!ret)
6268 {
63- showMessageText("CONNECT FAILURE...");
69+ showMessageText("CONNECT FAILURE... : " + isBothLiveView);
6470 }
6571 }
6672 });
--- a/app/src/main/java/net/osdn/gokigen/cameratest/fuji/Connection.java
+++ b/app/src/main/java/net/osdn/gokigen/cameratest/fuji/Connection.java
@@ -23,11 +23,11 @@ public class Connection implements IFujiStatusRequest
2323 this.statusChecker = new FujiStatusChecker(this, notify);
2424 }
2525
26- public boolean start_connect()
26+ public boolean start_connect(boolean isBothLiveView)
2727 {
2828 boolean ret = false;
2929
30- if (connect_to_camera())
30+ if (connect_to_camera(isBothLiveView))
3131 {
3232 ret = requestStatus();
3333 if (ret)
@@ -39,7 +39,7 @@ public class Connection implements IFujiStatusRequest
3939 return (ret);
4040 }
4141
42- private boolean connect_to_camera()
42+ private boolean connect_to_camera(boolean isBothLiveView)
4343 {
4444 try
4545 {
@@ -70,67 +70,66 @@ public class Connection implements IFujiStatusRequest
7070 dump_bytes(1, rx_bytes);
7171 Thread.sleep(50);
7272
73-/**/
7473 // なんだろう?? (送信が必要なようだが)
7574 comm.send_to_camera(sequence.start_message2(), true);
7675 rx_bytes = comm.receive_from_camera();
7776 dump_bytes(2, rx_bytes);
7877 Thread.sleep(50);
79-/**/
80-/**/
78+
8179 // two_part messageを発行 (その1)
8280 comm.send_to_camera(sequence.start_message3_1(), true);
8381 rx_bytes = comm.receive_from_camera();
8482 dump_bytes(3, rx_bytes);
8583 Thread.sleep(50);
8684
87- // two_part messageを発行 (その2)
88- comm.send_to_camera(sequence.start_message3_2(), false);
89- rx_bytes = comm.receive_from_camera();
90- dump_bytes(4, rx_bytes);
91- Thread.sleep(50);
92-/**/
85+ if (rx_bytes.getData().length <= 50)
86+ {
87+ // two_part messageを発行 (その2)
88+ comm.send_to_camera(sequence.start_message3_2(), false);
89+ rx_bytes = comm.receive_from_camera();
90+ dump_bytes(4, rx_bytes);
91+ Thread.sleep(50);
92+ }
9393
94-/**/
9594 // remote mode
9695 comm.send_to_camera(sequence.start_message4(), true);
9796 rx_bytes = comm.receive_from_camera();
9897 dump_bytes(5, rx_bytes);
9998 Thread.sleep(50);
100-/**/
101-/**/
102- // two_part messageを発行 (その1)
103- comm.send_to_camera(sequence.start_message5_1(), true);
104- rx_bytes = comm.receive_from_camera();
105- dump_bytes(6, rx_bytes);
106- Thread.sleep(50);
10799
108- // two_part messageを発行 (その2)
109- comm.send_to_camera(sequence.start_message5_2(), false);
110- rx_bytes = comm.receive_from_camera();
111- dump_bytes(7, rx_bytes);
112- Thread.sleep(50);
113-/**/
114-/**/
115- // ????
116- comm.send_to_camera(sequence.start_message6(), true);
117- rx_bytes = comm.receive_from_camera();
118- dump_bytes(8, rx_bytes);
119- Thread.sleep(50);
100+ if (!isBothLiveView)
101+ {
102+ // two_part messageを発行 (その1)
103+ comm.send_to_camera(sequence.start_message5_1(), true);
104+ rx_bytes = comm.receive_from_camera();
105+ dump_bytes(6, rx_bytes);
106+ Thread.sleep(50);
107+
108+ // two_part messageを発行 (その2)
109+ comm.send_to_camera(sequence.start_message5_2(), false);
110+ rx_bytes = comm.receive_from_camera();
111+ dump_bytes(7, rx_bytes);
112+ Thread.sleep(50);
113+
114+ // ????
115+ comm.send_to_camera(sequence.start_message6(), true);
116+ rx_bytes = comm.receive_from_camera();
117+ dump_bytes(8, rx_bytes);
118+ Thread.sleep(50);
119+
120+ // ????
121+ comm.send_to_camera(sequence.start_message7(), true);
122+ rx_bytes = comm.receive_from_camera();
123+ dump_bytes(9, rx_bytes);
124+ Thread.sleep(50);
125+
126+ // ????
127+ comm.send_to_camera(sequence.start_message8(), true);
128+ rx_bytes = comm.receive_from_camera();
129+ dump_bytes(10, rx_bytes);
130+ Thread.sleep(50);
131+ }
120132
121- // ????
122- comm.send_to_camera(sequence.start_message7(), true);
123- rx_bytes = comm.receive_from_camera();
124- dump_bytes(9, rx_bytes);
125- Thread.sleep(50);
126-/**/
127-/**/
128- // ????
129- comm.send_to_camera(sequence.start_message8(), true);
130- rx_bytes = comm.receive_from_camera();
131- dump_bytes(10, rx_bytes);
132- Thread.sleep(50);
133-/**/
134133 // リモート制御の開始!
135134 comm.send_to_camera(sequence.camera_remote_message(), true);
136135
--- 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
@@ -1,18 +1,27 @@
11 package net.osdn.gokigen.cameratest.fuji.preference;
22
33 import android.content.Context;
4+import android.content.SharedPreferences;
45 import android.os.Bundle;
6+import android.util.Log;
57
68 import androidx.annotation.NonNull;
9+import androidx.fragment.app.FragmentActivity;
10+import androidx.preference.CheckBoxPreference;
711 import androidx.preference.ListPreference;
812 import androidx.preference.Preference;
913 import androidx.preference.PreferenceFragmentCompat;
14+import androidx.preference.PreferenceManager;
1015
1116 import net.osdn.gokigen.cameratest.IApplicationControl;
1217 import net.osdn.gokigen.cameratest.R;
1318
14-public class FujiPreferenceFragment extends PreferenceFragmentCompat
19+import java.util.Map;
20+
21+public class FujiPreferenceFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener
1522 {
23+ private final String TAG = toString();
24+ private SharedPreferences preferences = null;
1625 private PowerOffController powerOffController = null;
1726
1827 /**
@@ -38,6 +47,31 @@ public class FujiPreferenceFragment extends PreferenceFragmentCompat
3847 powerOffController = new PowerOffController(context, control);
3948 }
4049
50+ /**
51+ *
52+ *
53+ */
54+ @Override
55+ public void onAttach(@NonNull Context activity)
56+ {
57+ super.onAttach(activity);
58+ Log.v(TAG, "onAttach()");
59+ try
60+ {
61+ // Preference をつかまえる
62+ preferences = PreferenceManager.getDefaultSharedPreferences(activity);
63+
64+ // Preference を初期設定する
65+ initializePreferences();
66+
67+ preferences.registerOnSharedPreferenceChangeListener(this);
68+ }
69+ catch (Exception e)
70+ {
71+ e.printStackTrace();
72+ }
73+ }
74+
4175 @Override
4276 public void onCreatePreferences(Bundle savedInstanceState, String rootKey)
4377 {
@@ -56,4 +90,179 @@ public class FujiPreferenceFragment extends PreferenceFragmentCompat
5690 findPreference("exit_application").setOnPreferenceClickListener(powerOffController);
5791
5892 }
93+
94+ /**
95+ * Preferenceの初期化...
96+ *
97+ */
98+ private void initializePreferences()
99+ {
100+ try
101+ {
102+ Map<String, ?> items = preferences.getAll();
103+ SharedPreferences.Editor editor = preferences.edit();
104+
105+ if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD)) {
106+ editor.putString(IPreferencePropertyAccessor.CONNECTION_METHOD, IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
107+ }
108+ if (!items.containsKey(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW)) {
109+ editor.putBoolean(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true);
110+ }
111+ if (!items.containsKey(IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW)) {
112+ editor.putBoolean(IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW, false);
113+ }
114+ editor.apply();
115+ }
116+ catch (Exception e)
117+ {
118+ e.printStackTrace();
119+ }
120+ }
121+
122+
123+ @Override
124+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
125+ {
126+ Log.v(TAG, "onSharedPreferenceChanged() : " + key);
127+ boolean value;
128+ if (key != null)
129+ {
130+ switch (key)
131+ {
132+ case IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW:
133+ value = preferences.getBoolean(key, true);
134+ Log.v(TAG, " " + key + " , " + value);
135+ break;
136+
137+ case IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW:
138+ value = preferences.getBoolean(key, false);
139+ Log.v(TAG, " " + key + " , " + value);
140+ break;
141+
142+ default:
143+ String strValue = preferences.getString(key, "");
144+ setListPreference(key, key, strValue);
145+ break;
146+ }
147+ }
148+ }
149+
150+ /**
151+ *
152+ *
153+ */
154+ @Override
155+ public void onResume()
156+ {
157+ super.onResume();
158+ Log.v(TAG, "onResume() Start");
159+ try
160+ {
161+ synchronizedProperty();
162+ }
163+ catch (Exception e)
164+ {
165+ e.printStackTrace();
166+ }
167+
168+ Log.v(TAG, "onResume() End");
169+ }
170+
171+ /**
172+ *
173+ *
174+ */
175+ @Override
176+ public void onPause()
177+ {
178+ super.onPause();
179+ Log.v(TAG, "onPause() Start");
180+ try
181+ {
182+ // Preference変更のリスナを解除
183+ preferences.unregisterOnSharedPreferenceChangeListener(this);
184+ }
185+ catch (Exception e)
186+ {
187+ e.printStackTrace();
188+ }
189+
190+ Log.v(TAG, "onPause() End");
191+ }
192+
193+ /**
194+ * ListPreference の表示データを設定
195+ *
196+ * @param pref_key Preference(表示)のキー
197+ * @param key Preference(データ)のキー
198+ * @param defaultValue Preferenceのデフォルト値
199+ */
200+ private void setListPreference(String pref_key, String key, String defaultValue)
201+ {
202+ try
203+ {
204+ ListPreference pref;
205+ pref = (ListPreference) findPreference(pref_key);
206+ String value = preferences.getString(key, defaultValue);
207+ if (pref != null)
208+ {
209+ pref.setValue(value);
210+ pref.setSummary(value);
211+ }
212+ }
213+ catch (Exception e)
214+ {
215+ e.printStackTrace();
216+ }
217+ }
218+
219+ /**
220+ * BooleanPreference の表示データを設定
221+ *
222+ * @param pref_key Preference(表示)のキー
223+ * @param key Preference(データ)のキー
224+ * @param defaultValue Preferenceのデフォルト値
225+ */
226+ private void setBooleanPreference(String pref_key, String key, boolean defaultValue)
227+ {
228+ try
229+ {
230+ CheckBoxPreference pref = (CheckBoxPreference) findPreference(pref_key);
231+ if (pref != null) {
232+ boolean value = preferences.getBoolean(key, defaultValue);
233+ pref.setChecked(value);
234+ }
235+ }
236+ catch (Exception e)
237+ {
238+ e.printStackTrace();
239+ }
240+ }
241+
242+ /**
243+ *
244+ *
245+ */
246+ private void synchronizedProperty()
247+ {
248+ final FragmentActivity activity = getActivity();
249+ if (activity != null)
250+ {
251+ activity.runOnUiThread(new Runnable() {
252+ @Override
253+ public void run() {
254+ try
255+ {
256+ // Preferenceの画面に反映させる
257+ setBooleanPreference(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, true);
258+ setBooleanPreference(IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW, IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW, false);
259+ }
260+ catch (Exception e)
261+ {
262+ e.printStackTrace();
263+ }
264+ }
265+ });
266+ }
267+ }
59268 }
--- 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
@@ -3,8 +3,13 @@ package net.osdn.gokigen.cameratest.fuji.preference;
33 public interface IPreferencePropertyAccessor
44 {
55 String EXIT_APPLICATION = "exit_application";
6+
67 String CONNECTION_METHOD = "connection_method";
78 String CONNECTION_METHOD_DEFAULT_VALUE = "FUJI_X";
89
10+ String CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW = "capture_both_camera_and_live_view";
11+
12+ String FUJIX_DISPLAY_CAMERA_VIEW = "fujix_display_camera_view";
13+
914
1015 }
--- 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
@@ -80,6 +80,12 @@ public class FujiStatusChecker implements IFujiStatusReceiver
8080 boolean isStatusUpdated = false;
8181 try
8282 {
83+ if (data.length < 14)
84+ {
85+ Log.v(TAG, "received status length is short. (" + data.length + " bytes.)");
86+ return;
87+ }
88+
8389 int nofStatus = (data[13] * 256) + data[12];
8490 //Log.v(TAG, "status Received. " + data.length + " bytes. [status : " + nofStatus + "]");
8591
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -34,6 +34,9 @@
3434 <string name="pref_degug_info">Debug Information</string>
3535 <string name="pref_summary_debug_info">LogCat Information</string>
3636
37+ <string name="pref_fujix_display_camera_view">Use Camera Display</string>
38+ <string name="pref_fujix_display_camera_view_summary">Shows liveview screen both camera and smartphone.</string>
39+
3740 <string name="pref_special_thanks">Special Thanks to : fuji-cam-wifi-tool</string>
3841
3942
--- a/app/src/main/res/xml/preferences_fuji_x.xml
+++ b/app/src/main/res/xml/preferences_fuji_x.xml
@@ -19,6 +19,10 @@
1919
2020 <PreferenceCategory
2121 android:title="@string/pref_cat_camera">
22+ <CheckBoxPreference
23+ android:key="fujix_display_camera_view"
24+ android:title="@string/pref_fujix_display_camera_view"
25+ android:summary="@string/pref_fujix_display_camera_view_summary"/>
2226
2327 <CheckBoxPreference
2428 android:key="capture_both_camera_and_live_view"
Show on old repository browser