OSDN Git Service

Ricoh Theta対応準備。(その3) 通信の確認。
authorMRSa <mrsa@myad.jp>
Thu, 16 Jan 2020 15:30:50 +0000 (00:30 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 16 Jan 2020 15:30:50 +0000 (00:30 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/camera/utils/SimpleHttpSendCommandDialog.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/theta/wrapper/connection/ThetaCameraConnectSequence.java
app/src/main/java/net/osdn/gokigen/pkremote/preference/IPreferencePropertyAccessor.java
app/src/main/java/net/osdn/gokigen/pkremote/preference/theta/ThetaPreferenceFragment.java
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences_theta.xml

index 0b76b06..c41d852 100644 (file)
@@ -42,7 +42,7 @@ public class SimpleHttpSendCommandDialog extends DialogFragment implements View.
      *
      *
      */
-    public static SimpleHttpSendCommandDialog newInstance(@Nullable String urlToSend, @NonNull ILiveViewControl liveViewControl,  @Nullable Map<String, String> headerMap)
+    public static SimpleHttpSendCommandDialog newInstance(@Nullable String urlToSend, @Nullable ILiveViewControl liveViewControl,  @Nullable Map<String, String> headerMap)
     {
         SimpleHttpSendCommandDialog instance = new SimpleHttpSendCommandDialog();
         instance.prepare(urlToSend, liveViewControl, headerMap);
@@ -60,7 +60,7 @@ public class SimpleHttpSendCommandDialog extends DialogFragment implements View.
      *
      *
      */
-    private void prepare(@Nullable String urlToSend, @NonNull ILiveViewControl liveViewControl, @Nullable Map<String, String> headerMap)
+    private void prepare(@Nullable String urlToSend, @Nullable ILiveViewControl liveViewControl, @Nullable Map<String, String> headerMap)
     {
         if ((urlToSend == null)||(!urlToSend.contains("http://")))
         {
@@ -127,8 +127,17 @@ public class SimpleHttpSendCommandDialog extends DialogFragment implements View.
         final Button toRunningButton = alertView.findViewById(R.id.change_to_liveview);
         final Button toPlaybackButton = alertView.findViewById(R.id.change_to_playback);
 
-        toRunningButton.setOnClickListener(this);
-        toPlaybackButton.setOnClickListener(this);
+        if (liveViewControl != null)
+        {
+            toRunningButton.setOnClickListener(this);
+            toPlaybackButton.setOnClickListener(this);
+        }
+        else
+        {
+            // ライブビューのオン・オフ切り替えボタンを非表示にする
+            toRunningButton.setVisibility(View.GONE);
+            toPlaybackButton.setVisibility(View.GONE);
+        }
         sendButton.setOnClickListener(this);
         alertDialog.setCancelable(true);
         try
@@ -292,7 +301,7 @@ public class SimpleHttpSendCommandDialog extends DialogFragment implements View.
                             {
                                 reply = SimpleHttpClient.httpGetWithHeader(url, headerMap, null, TIMEOUT_MS);
                             }
-                            Log.v(TAG, "URL : " + url + " RESPONSE : " + reply);
+                            Log.v(TAG, "URL : " + url + " "+ param + " RESP : " + reply);
                             final String response = reply;
                             activity.runOnUiThread(new Runnable() {
                                 @Override
index 2615791..dc404d2 100644 (file)
@@ -10,9 +10,10 @@ import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraConnection;
 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusReceiver;
 import net.osdn.gokigen.pkremote.camera.utils.SimpleHttpClient;
 
-import java.util.HashMap;
-import java.util.Map;
-
+/**
+ *   Thetaとの接続シーケンス
+ *
+ */
 public class ThetaCameraConnectSequence implements Runnable
 {
     private final String TAG = this.toString();
@@ -31,26 +32,24 @@ public class ThetaCameraConnectSequence implements Runnable
     @Override
     public void run()
     {
-        final String camInfoUrl = "http://192.168.0.10/get_caminfo.cgi";
-        final String getCommandListUrl = "http://192.168.0.10/get_commandlist.cgi";
-        final String getConnectModeUrl = "http://192.168.0.10/get_connectmode.cgi";
+        final String oscInfoUrl = "http://192.168.1.1/osc/info";
+        final String commandsExecuteUrl = "http://192.168.1.1/osc/commands/execute";
+        final String startSessionData = "{\"name\":\"camera.startSession\",\"parameters\":{\"timeout\":0}}";
+        final String getStateUrl = "http://192.168.1.1/osc/state";
 
         final int TIMEOUT_MS = 5000;
         try
         {
-            Map<String, String> headerMap = new HashMap<>();
-            headerMap.put("User-Agent", "OlympusCameraKit"); // "OI.Share"
-            headerMap.put("X-Protocol", "OlympusCameraKit"); // "OI.Share"
-
-            String response = SimpleHttpClient.httpGetWithHeader(getConnectModeUrl, headerMap, null, TIMEOUT_MS);
-            Log.v(TAG, " " + getConnectModeUrl + " " + response);
+            String response = SimpleHttpClient.httpGet(oscInfoUrl, TIMEOUT_MS);
+            Log.v(TAG, " " + oscInfoUrl + " " + response);
             if (response.length() > 0)
             {
-                String response2 = SimpleHttpClient.httpGetWithHeader(getCommandListUrl, headerMap, null, TIMEOUT_MS);
-                Log.v(TAG, " " + getCommandListUrl + " " + response2);
 
-                String response3 = SimpleHttpClient.httpGetWithHeader(camInfoUrl, headerMap, null, TIMEOUT_MS);
-                Log.v(TAG, " " + camInfoUrl + " " + response3);
+                String response2 = SimpleHttpClient.httpPost(commandsExecuteUrl, startSessionData, TIMEOUT_MS);
+                Log.v(TAG, " " + commandsExecuteUrl + " " + startSessionData + " " + response2);
+
+                String response3 = SimpleHttpClient.httpPost(getStateUrl, "", TIMEOUT_MS);
+                Log.v(TAG, " " + getStateUrl + " " + response3);
 
                 onConnectNotify();
             }
index a6c4bb1..551256e 100644 (file)
@@ -115,6 +115,8 @@ public interface IPreferencePropertyAccessor
     String CANON_RECEIVE_WAIT = "nikon_receive_wait";
     String CANON_RECEIVE_WAIT_DEFAULT_VALUE = "20";
 
+    String HTTP_COMMAND_SEND_DIALOG = "send_command_dialog";
+
     /*
     //String GR2_DISPLAY_MODE = "gr2_display_mode";
     //String GR2_DISPLAY_MODE_DEFAULT_VALUE = "0";
index 48d26e1..fceaa02 100644 (file)
@@ -17,6 +17,7 @@ import androidx.preference.PreferenceFragmentCompat;
 import androidx.preference.PreferenceManager;
 
 import net.osdn.gokigen.pkremote.R;
+import net.osdn.gokigen.pkremote.camera.utils.SimpleHttpSendCommandDialog;
 import net.osdn.gokigen.pkremote.camera.vendor.theta.operation.ThetaCameraPowerOff;
 import net.osdn.gokigen.pkremote.logcat.LogCatViewer;
 import net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor;
@@ -26,6 +27,7 @@ import java.util.Map;
 
 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.DEBUG_INFO;
 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.EXIT_APPLICATION;
+import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.HTTP_COMMAND_SEND_DIALOG;
 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.WIFI_SETTINGS;
 
 /**
@@ -179,7 +181,7 @@ public class ThetaPreferenceFragment  extends PreferenceFragmentCompat implement
         try
         {
             //super.onCreate(savedInstanceState);
-            addPreferencesFromResource(R.xml.preferences_panasonic);
+            addPreferencesFromResource(R.xml.preferences_theta);
 
             ListPreference connectionMethod = findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
             connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -194,6 +196,7 @@ public class ThetaPreferenceFragment  extends PreferenceFragmentCompat implement
             findPreference(EXIT_APPLICATION).setOnPreferenceClickListener(powerOffController);
             findPreference(DEBUG_INFO).setOnPreferenceClickListener(logCatViewer);
             findPreference(WIFI_SETTINGS).setOnPreferenceClickListener(this);
+            findPreference(HTTP_COMMAND_SEND_DIALOG).setOnPreferenceClickListener(this);
             //findPreference("panasonic_api_list").setOnPreferenceClickListener(cameraApiListViewer);
         }
         catch (Exception e)
@@ -331,15 +334,20 @@ public class ThetaPreferenceFragment  extends PreferenceFragmentCompat implement
         try
         {
             String preferenceKey = preference.getKey();
+            Log.v(TAG, " onPreferenceClick : " + preferenceKey);
             if (preferenceKey.contains(WIFI_SETTINGS))
             {
                 // Wifi 設定画面を表示する
-                Log.v(TAG, " onPreferenceClick : " + preferenceKey);
                 if (context != null)
                 {
                     context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
                 }
             }
+            else if (preferenceKey.contains(HTTP_COMMAND_SEND_DIALOG))
+            {
+                // HTTP送信ダイアログを表示する
+                SimpleHttpSendCommandDialog.newInstance("http://192.168.1.1/", null, null).show(context.getSupportFragmentManager(), "sendCommandDialog");
+            }
             return (true);
         }
         catch (Exception e)
index 02c1e40..4b9dd82 100644 (file)
     <string name="pref_canon_receive_wait">応答受信待ち時間(単位:ms)</string>
     <string name="pref_summary_canon_receive_wait">おかしい場合に値を大きくします</string>
 
+    <string name="pref_show_send_dialog">HTTP送信</string>
+    <string name="pref_summary_show_send_dialog"> </string>
     <string name="dialog_http_command_title_command">HTTP送信</string>
-    <string name="http_dialog_http_url_hint">http://192.168.0.10/</string>
+    <string name="http_dialog_http_url_hint">http://192.168.1.1/</string>
     <string name="http_dialog_method_hint">GET/POST/PUT</string>
     <string name="http_dialog_service_hint">(service)</string>
     <string name="http_dialog_command_hint">(command)</string>
index 5a4c761..10e8b18 100644 (file)
     <string name="pref_canon_receive_wait">Receive reply wait(ms)</string>
     <string name="pref_summary_canon_receive_wait"> </string>
 
+    <string name="pref_show_send_dialog">HTTP Send Message</string>
+    <string name="pref_summary_show_send_dialog"> </string>
     <string name="dialog_http_command_title_command">HTTP Send Message</string>
-    <string name="http_dialog_http_url_hint">http://192.168.0.10/</string>
+    <string name="http_dialog_http_url_hint">http://192.168.1.1/</string>
     <string name="http_dialog_method_hint">GET/POST/PUT</string>
     <string name="http_dialog_service_hint">(service)</string>
     <string name="http_dialog_command_hint">(command)</string>
index 7351c73..2f8c022 100644 (file)
 
     </PreferenceCategory>
 
-<!--
     <PreferenceCategory
         android:title="@string/pref_cat_camera">
 
+        <PreferenceScreen
+            android:key="send_command_dialog"
+            android:title="@string/pref_show_send_dialog"
+            android:summary="@string/pref_summary_show_send_dialog" />
+
+<!--
         <CheckBoxPreference
             android:key="capture_both_camera_and_live_view"
             android:title="@string/pref_capture_both_camera_and_live_view" />
-
-    </PreferenceCategory>
 -->
+    </PreferenceCategory>
 
     <PreferenceCategory
         android:title="@string/pref_cat_initialize">