OSDN Git Service

接続ボタン制御を追加した。(カメラとの接続後にボタンを出すようにした。)
authorMRSa <mrsa@myad.jp>
Sat, 28 Mar 2020 10:03:58 +0000 (19:03 +0900)
committerMRSa <mrsa@myad.jp>
Sat, 28 Mar 2020 10:03:58 +0000 (19:03 +0900)
app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connection/ITextDataUpdater.java
app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connection/fv100/FV100Communicator.java
app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connection/fv100/FV100SendMessageProvider.java
app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/fv100/FV100DeviceQuery.java
app/src/main/res/layout/fragment_fv100.xml

index d3672d9..dedd15e 100644 (file)
@@ -25,7 +25,7 @@ import java.util.List;
 import java.util.UUID;
 
 @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
-class FV100Communicator  extends BluetoothGattCallback implements FV100ObjectPaser.ReceivedDataNotify, WifiConnector.WifiConnectNotify
+class FV100Communicator  extends BluetoothGattCallback implements FV100ObjectPaser.ReceivedDataNotify, WifiConnector.WifiConnectNotify, FV100SendMessageProvider.MessageSequenceNotify
 {
     private String TAG = toString();
     private final FragmentActivity context;
@@ -52,7 +52,7 @@ class FV100Communicator  extends BluetoothGattCallback implements FV100ObjectPas
         this.messageToShow = messageToShow;
         this.receiveBuffer = new ByteArrayOutputStream();
         this.objectParser = new FV100ObjectPaser(this);
-        this.sendMessageProvider = new FV100SendMessageProvider();
+        this.sendMessageProvider = new FV100SendMessageProvider(this);
         this.wifiConnector = new WifiConnector(context, messageToShow);
     }
 
@@ -148,7 +148,7 @@ class FV100Communicator  extends BluetoothGattCallback implements FV100ObjectPas
             });
             return;
         }
-        if ((setPropertyMessage != null)||(!sendMessageProvider.isMessageFinished()))
+        if ((setPropertyMessage != null)||(sendMessageProvider.isMessageSending()))
         {
             // ただいま通信中なので何もしないで終わる
             context.runOnUiThread(new Runnable() {
@@ -336,7 +336,7 @@ class FV100Communicator  extends BluetoothGattCallback implements FV100ObjectPas
             String value = characteristic.getStringValue(0);
             Log.v(TAG, " W: BluetoothGatt.GATT_SUCCESS " + characteristic.getUuid() + "  (" + value + ") ");
 
-            if (!sendMessageProvider.isMessageFinished())
+            if (sendMessageProvider.isMessageSending())
             {
                 try
                 {
@@ -457,6 +457,12 @@ class FV100Communicator  extends BluetoothGattCallback implements FV100ObjectPas
 
     }
 
+    @Override
+    public void messageFinished(boolean isFinished)
+    {
+        dataUpdater.enableOperation(isFinished);
+    }
+
 /*
     @Override
     public void onMtuChanged(BluetoothGatt gatt, int mtu, int status)
@@ -490,5 +496,4 @@ class FV100Communicator  extends BluetoothGattCallback implements FV100ObjectPas
         }
     }
 */
-
 }
index 1c5c124..788f7e0 100644 (file)
@@ -2,6 +2,7 @@ package net.osdn.gokigen.blecontrol.lib.ble.connection.fv100;
 
 import android.util.Log;
 
+import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
 
 import java.io.ByteArrayOutputStream;
@@ -12,6 +13,7 @@ import java.util.List;
 class FV100SendMessageProvider
 {
     private final String TAG = toString();
+    private final MessageSequenceNotify notifier;
     private List<Integer> msgIdList;
     private List<String> typeList;
     private List<String> paramList;
@@ -19,13 +21,11 @@ class FV100SendMessageProvider
     private int tokenId = 0;
     private int index = 0;
     private int offset = 0;
-
-    private int sequene = 0;
     private boolean isMessageFinished = false;
 
-
-    FV100SendMessageProvider()
+    FV100SendMessageProvider(@NonNull MessageSequenceNotify notifier)
     {
+        this.notifier = notifier;
         initializeMsgIdList();
     }
 
@@ -34,6 +34,7 @@ class FV100SendMessageProvider
         index = 0;
         offset = 0;
         isMessageFinished = false;
+        notifier.messageFinished(false);
     }
 
     void setTokenId(int tokenId)
@@ -87,6 +88,7 @@ class FV100SendMessageProvider
                 {
                     index = 0;
                     isMessageFinished = true;
+                    notifier.messageFinished(true);
                     Log.v(TAG, " - - - - - - -  STATUS GET SEQUENCE FINISHED  - - - - - - - ");
                 }
             }
@@ -100,9 +102,9 @@ class FV100SendMessageProvider
         return (message);
     }
 
-    boolean isMessageFinished()
+    boolean isMessageSending()
     {
-        return (isMessageFinished);
+        return (!isMessageFinished);
     }
 
     private void initializeMsgIdList()
@@ -205,35 +207,8 @@ class FV100SendMessageProvider
         return (messageArray);
     }
 
-    private byte[] createSetPropertyMessage(@Nullable String type, @Nullable String param)
+    public interface MessageSequenceNotify
     {
-        String data = "{\"msg_id\":" + 2;
-        if (param != null)
-        {
-            data = data + ",\"param\":\"" + param + "\"";
-        }
-        data = data + ",\"token\":" + tokenId;
-        if (type != null)
-        {
-            data = data + ",\"type\":\"" + type + "\"";
-        }
-        data = data + "}";
-
-        Log.v(TAG, " data to send : " + data);
-
-        ByteArrayOutputStream output = new ByteArrayOutputStream();
-        try
-        {
-            byte[] header = {(byte) 0x01, (byte) 0x00, (byte) data.length()};
-            output.write(header);
-            output.write(data.getBytes());
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-        return (output.toByteArray());
+        void messageFinished(boolean isFinished);
     }
-
-
 }
index b02a279..b4d5eb2 100644 (file)
@@ -2,6 +2,7 @@ package net.osdn.gokigen.blecontrol.lib.ui.fv100;
 
 import android.util.Log;
 import android.view.View;
+import android.widget.ImageButton;
 
 import androidx.annotation.NonNull;
 import androidx.fragment.app.FragmentActivity;
@@ -122,6 +123,44 @@ public class FV100DeviceQuery implements View.OnClickListener, ITextDataUpdater,
     }
 
     @Override
+    public void enableOperation(final boolean isEnable)
+    {
+        try
+        {
+            context.runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    final ImageButton wifiConnectButton = context.findViewById(R.id.wifi_connect_button);
+                    if (wifiConnectButton != null)
+                    {
+                        wifiConnectButton.setEnabled(isEnable);
+                        wifiConnectButton.setVisibility((isEnable? View.VISIBLE : View.INVISIBLE));
+                    }
+
+                    final ImageButton imageSizeButton = context.findViewById(R.id.change_image_size_button);
+                    if (imageSizeButton != null)
+                    {
+                        imageSizeButton.setEnabled(isEnable);
+                        imageSizeButton.setVisibility((isEnable? View.VISIBLE : View.INVISIBLE));
+                    }
+
+                    final ImageButton videoSizeButton = context.findViewById(R.id.change_video_size_button);
+                    if (videoSizeButton != null)
+                    {
+                        videoSizeButton.setEnabled(isEnable);
+                        videoSizeButton.setVisibility((isEnable? View.VISIBLE : View.INVISIBLE));
+                    }
+                    //Log.v(TAG, " >> ITextDataUpdater::enableOperation() : " + isEnable);
+                }
+            });
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    @Override
     public void setProperty(@NonNull final String propertyName, @NonNull final String propertyValue)
     {
         try
index 141ed6c..0a0d05e 100644 (file)
@@ -96,7 +96,7 @@
                 android:scaleType="fitCenter"
                 android:contentDescription="@string/blank"
                 app:srcCompat="@drawable/ic_image_aspect_ratio_black_24dp"
-                android:visibility="visible" />
+                android:visibility="invisible" />
 
             <ImageButton
                 android:id="@+id/change_video_size_button"
                 android:scaleType="fitCenter"
                 android:contentDescription="@string/blank"
                 app:srcCompat="@drawable/ic_videocam_black_24dp"
-                android:visibility="visible" />
+                android:visibility="invisible" />
 
             <ImageButton
                 android:id="@+id/dummy_button2"
                 android:scaleType="fitCenter"
                 android:contentDescription="@string/blank"
                 app:srcCompat="@drawable/ic_signal_wifi_4_bar_black_24dp"
-            android:visibility="visible" />
+            android:visibility="invisible" />
         </LinearLayout>
 
         <View