OSDN Git Service

Panasonic用コマンド送信ダイアログ。
authorMRSa <mrsa@myad.jp>
Wed, 24 Jul 2019 15:38:39 +0000 (00:38 +0900)
committerMRSa <mrsa@myad.jp>
Wed, 24 Jul 2019 15:38:39 +0000 (00:38 +0900)
app/src/main/java/net/osdn/gokigen/a01d/A01dMain.java
app/src/main/java/net/osdn/gokigen/a01d/camera/panasonic/IPanasonicInterfaceProvider.java
app/src/main/java/net/osdn/gokigen/a01d/camera/panasonic/operation/PanasonicSendCommandDialog.java
app/src/main/java/net/osdn/gokigen/a01d/camera/panasonic/wrapper/PanasonicCameraWrapper.java
app/src/main/java/net/osdn/gokigen/a01d/camera/panasonic/wrapper/connection/PanasonicSsdpClient.java
app/src/main/res/layout-land/panasonic_request_layout.xml
app/src/main/res/layout/panasonic_request_layout.xml
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml

index d0e7eb6..04695d5 100644 (file)
@@ -234,7 +234,7 @@ public class A01dMain extends AppCompatActivity implements ICameraStatusReceiver
                 try
                 {
                     // Panasonicの場合は、コマンド送信ダイアログを表示する
-                    PanasonicSendCommandDialog.newInstance(interfaceProvider.getPanasonicInterface().getSendCommandCallback()).show(getSupportFragmentManager(), "panasonicSendCommandDialog");
+                    PanasonicSendCommandDialog.newInstance(interfaceProvider.getPanasonicInterface().getPanasonicCamera()).show(getSupportFragmentManager(), "panasonicSendCommandDialog");
                 }
                 catch (Exception e)
                 {
index d5727da..094a389 100644 (file)
@@ -7,12 +7,9 @@ import net.osdn.gokigen.a01d.camera.IFocusingControl;
 import net.osdn.gokigen.a01d.camera.ILiveViewControl;
 import net.osdn.gokigen.a01d.camera.IZoomLensControl;
 import net.osdn.gokigen.a01d.camera.IDisplayInjector;
-import net.osdn.gokigen.a01d.camera.panasonic.operation.PanasonicSendCommandDialog;
 import net.osdn.gokigen.a01d.camera.panasonic.wrapper.IPanasonicCamera;
 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
 
-import java.util.List;
-
 public interface IPanasonicInterfaceProvider
 {
     ICameraConnection getPanasonicCameraConnection();
@@ -24,7 +21,5 @@ public interface IPanasonicInterfaceProvider
     ICaptureControl getCaptureControl();
     IDisplayInjector getDisplayInjector();
 
-    PanasonicSendCommandDialog.Callback getSendCommandCallback();
-
     IPanasonicCamera getPanasonicCamera();
 }
index 1600feb..0b77e1e 100644 (file)
@@ -8,29 +8,37 @@ import android.os.Bundle;
 import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
+import android.widget.Button;
 import android.widget.EditText;
+import android.widget.TextView;
 
 
 import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
 import androidx.fragment.app.DialogFragment;
 
 import net.osdn.gokigen.a01d.R;
+import net.osdn.gokigen.a01d.camera.panasonic.wrapper.IPanasonicCamera;
+import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
 
-public class PanasonicSendCommandDialog  extends DialogFragment
+public class PanasonicSendCommandDialog  extends DialogFragment implements View.OnClickListener
 {
     private final String TAG = toString();
-    private PanasonicSendCommandDialog.Callback callback;
-    Dialog myDialog = null;
+    private IPanasonicCamera camera = null;
+    private Dialog myDialog = null;
+    private EditText service = null;
+    private EditText parameter = null;
+    private EditText command = null;
+    private TextView responseArea = null;
+    private static final int TIMEOUT_MS = 2000;
 
     /**
      *
      *
      */
-    public static PanasonicSendCommandDialog newInstance(@Nullable PanasonicSendCommandDialog.Callback callback)
+    public static PanasonicSendCommandDialog newInstance(@NonNull IPanasonicCamera camera)
     {
         PanasonicSendCommandDialog instance = new PanasonicSendCommandDialog();
-        instance.prepare(callback);
+        instance.prepare(camera);
 
         // パラメータはBundleにまとめておく
         Bundle arguments = new Bundle();
@@ -45,9 +53,10 @@ public class PanasonicSendCommandDialog  extends DialogFragment
      *
      *
      */
-    private void prepare(@Nullable PanasonicSendCommandDialog.Callback callback)
+    private void prepare(@NonNull IPanasonicCamera camera)
     {
-        this.callback = callback;
+        //
+        this.camera = camera;
     }
 
     @Override
@@ -55,9 +64,16 @@ public class PanasonicSendCommandDialog  extends DialogFragment
     {
         super.onPause();
         Log.v(TAG, "AlertDialog::onPause()");
-        if (myDialog != null)
+        try
+        {
+            if (myDialog != null)
+            {
+                myDialog.cancel();
+            }
+        }
+        catch (Exception e)
         {
-            myDialog.cancel();
+            e.printStackTrace();
         }
     }
 
@@ -79,13 +95,14 @@ public class PanasonicSendCommandDialog  extends DialogFragment
         alertDialog.setView(alertView);
 
         alertDialog.setIcon(R.drawable.ic_linked_camera_black_24dp);
-        alertDialog.setTitle(activity.getString(R.string.dialog_fujix_command_title_command));
-        //final TextView titleName = alertView.findViewById(R.id.method_name);
-        final EditText service = alertView.findViewById(R.id.edit_service);
-        final EditText parameter = alertView.findViewById(R.id.edit_parameter);
-        final EditText command = alertView.findViewById(R.id.edit_command);
+        alertDialog.setTitle(activity.getString(R.string.dialog_panasonic_command_title_command));
+        service = alertView.findViewById(R.id.edit_service);
+        parameter = alertView.findViewById(R.id.edit_parameter);
+        command = alertView.findViewById(R.id.edit_command);
+        responseArea = alertView.findViewById(R.id.panasonic_command_response_value);
+        final Button sendButton = alertView.findViewById(R.id.send_message_button);
+        sendButton.setOnClickListener(this);
         alertDialog.setCancelable(true);
-
         try
         {
             if (service != null)
@@ -103,25 +120,6 @@ public class PanasonicSendCommandDialog  extends DialogFragment
                 new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int which)
                     {
-                        try
-                        {
-                            Activity activity = getActivity();
-                            if (activity != null)
-                            {
-                                if (callback != null)
-                                {
-                                    callback.sendPanasonicCommandRequest(service.getText().toString(), command.getText().toString(), parameter.getText().toString());
-                                }
-                            }
-                        }
-                        catch (Exception e)
-                        {
-                            e.printStackTrace();
-                            if (callback != null)
-                            {
-                                callback.cancelledPanasonicCommandRequest();
-                            }
-                        }
                         dialog.dismiss();
                     }
                 });
@@ -130,10 +128,6 @@ public class PanasonicSendCommandDialog  extends DialogFragment
         alertDialog.setNegativeButton(activity.getString(R.string.dialog_negative_cancel),
                 new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int which) {
-                        if (callback != null)
-                        {
-                            callback.cancelledPanasonicCommandRequest();
-                        }
                         dialog.cancel();
                     }
                 });
@@ -143,13 +137,69 @@ public class PanasonicSendCommandDialog  extends DialogFragment
         return (myDialog);
     }
 
-    /**
-     * コールバックインタフェース
-     *
-     */
-    public interface Callback
+    @Override
+    public void onClick(View view)
     {
-        void sendPanasonicCommandRequest(String service, String command, String parameter); // OKを選択したとき
-        void cancelledPanasonicCommandRequest();   // キャンセルしたとき
+        try
+        {
+            String serviceStr = "";
+            String commandStr = "";
+            final Activity activity = getActivity();
+            if (activity != null)
+            {
+                if (service != null)
+                {
+                    serviceStr = service.getText().toString();
+                }
+                if (command != null)
+                {
+                    commandStr = command.getText().toString();
+                }
+                if (parameter != null)
+                {
+                    String parameterStr = parameter.getText().toString();
+                    if (parameterStr.length() > 0)
+                    {
+                        commandStr = commandStr + "&" + parameterStr;
+                    }
+                }
+                final String sendString = serviceStr + "?" + commandStr;
+
+                Thread thread = new Thread(new Runnable() {
+                    @Override
+                    public void run()
+                    {
+                        try
+                        {
+                            String url = camera.getCmdUrl() + sendString;
+                            final String response = SimpleHttpClient.httpGet(url, TIMEOUT_MS);
+                            Log.v(TAG, "URL : " + url + " RESPONSE : " + response);
+                            activity.runOnUiThread(new Runnable() {
+                                @Override
+                                public void run() {
+                                    if (responseArea != null)
+                                    {
+                                        responseArea.setText(response);
+                                    }
+                                }
+                            });
+                        }
+                        catch (Exception e)
+                        {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+                thread.start();
+            }
+            else
+            {
+                Log.v(TAG, "getActivity() Fail...");
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
     }
 }
index 7f817b8..bf73062 100644 (file)
@@ -17,7 +17,6 @@ import net.osdn.gokigen.a01d.camera.panasonic.IPanasonicInterfaceProvider;
 import net.osdn.gokigen.a01d.camera.panasonic.operation.PanasonicCameraCaptureControl;
 import net.osdn.gokigen.a01d.camera.panasonic.operation.PanasonicCameraFocusControl;
 import net.osdn.gokigen.a01d.camera.panasonic.operation.PanasonicCameraZoomLensControl;
-import net.osdn.gokigen.a01d.camera.panasonic.operation.PanasonicSendCommandDialog;
 import net.osdn.gokigen.a01d.camera.panasonic.wrapper.connection.PanasonicCameraConnection;
 import net.osdn.gokigen.a01d.camera.panasonic.wrapper.eventlistener.CameraEventObserver;
 import net.osdn.gokigen.a01d.camera.panasonic.wrapper.eventlistener.ICameraEventObserver;
@@ -190,12 +189,6 @@ public class PanasonicCameraWrapper implements IPanasonicCameraHolder, IPanasoni
     }
 
     @Override
-    public PanasonicSendCommandDialog.Callback getSendCommandCallback()
-    {
-        return (null);
-    }
-
-    @Override
     public IPanasonicCamera getPanasonicCamera()
     {
         return (panasonicCamera);
index 6dd5b4d..a4b55a5 100644 (file)
@@ -30,7 +30,7 @@ class PanasonicSsdpClient
     private final String TAG = toString();
     private static final int SEND_TIMES_DEFAULT = 3;
     private static final int SEND_WAIT_DURATION_MS = 100;
-    private static final int SSDP_RECEIVE_TIMEOUT = 10 * 1000; // msec
+    private static final int SSDP_RECEIVE_TIMEOUT = 4 * 1000; // msec
     private static final int PACKET_BUFFER_SIZE = 2048;
     private static final int SSDP_PORT = 1900;
     private static final int SSDP_MX = 2;
index ac3d911..e5cc39e 100644 (file)
                 android:inputType="text"
                 android:hint="@string/dialog_parameter_hint"
                 />
+
+            <Button
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:tag="button"
+                android:id="@+id/send_message_button"
+                android:text="@string/dialog_send_message"
+                android:layout_gravity="center"
+                android:textSize="6pt" />
+
+            <View
+                android:layout_width="fill_parent"
+                android:layout_height="2dp"
+                android:background="@android:color/darker_gray"/>
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:id="@+id/panasonic_command_response_value"
+                android:text="@string/blank"
+                />
+
+            <View
+                android:layout_width="fill_parent"
+                android:layout_height="2dp"
+                android:background="@android:color/darker_gray"/>
+
         </LinearLayout>
     </ScrollView>
 </LinearLayout>
index 8da4952..952f4ce 100644 (file)
                 android:inputType="text"
                 android:hint="@string/dialog_parameter_hint"
                 />
+
+            <Button
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:tag="button"
+                android:id="@+id/send_message_button"
+                android:text="@string/dialog_send_message"
+                android:layout_gravity="center"
+                android:textSize="6pt" />
+
+            <View
+                android:layout_width="fill_parent"
+                android:layout_height="2dp"
+                android:background="@android:color/darker_gray"/>
+
+            <TextView
+                android:layout_width="fill_parent"
+                android:layout_height="wrap_content"
+                android:id="@+id/panasonic_command_response_value"
+                android:text="@string/blank"
+                />
+
+            <View
+                android:layout_width="fill_parent"
+                android:layout_height="2dp"
+                android:background="@android:color/darker_gray"/>
         </LinearLayout>
     </ScrollView>
 </LinearLayout>
index b627fb8..dc989cc 100644 (file)
     <string name="pref_use_pentax_autofocus_summary">PENTAX一眼カメラ用の命令を使って制御します。</string>
 
 
-    <string name="dialog_fujix_command_title_command">メッセージ送信</string>
+    <string name="dialog_panasonic_command_title_command">メッセージ送信(Panasonic)</string>
+    <string name="dialog_fujix_command_title_command">メッセージ送信(FUJI)</string>
     <string name="dialog_title_command">コマンド</string>
     <string name="dialog_command_id_hint">0x####</string>
     <string name="dialog_message_type_name">メッセージ種別</string>
index edf3b55..0585f41 100644 (file)
     <string name="pref_use_pentax_autofocus_summary">Uses PENTAX DSLR control commands.</string>
 
 
-    <string name="dialog_fujix_command_title_command">Send Message</string>
+    <string name="dialog_panasonic_command_title_command">Send Message(Panasonic)</string>
+    <string name="dialog_fujix_command_title_command">Send Message(FUJI)</string>
     <string name="dialog_title_command">Command</string>
     <string name="dialog_command_id_hint">0x####</string>
     <string name="dialog_message_type_name">Message Type</string>