• R/O
  • HTTP
  • SSH
  • HTTPS

BLEControl: コミット

BLE通信を行うためのアプリ。


コミットメタ情報

リビジョン43c2e1fc38801aa5f6f97980b670fc4c955a4a05 (tree)
日時2020-03-29 23:31:56
作者MRSa <mrsa@myad...>
コミッターMRSa

ログメッセージ

BLE接続部分を少し整理。

変更サマリ

差分

--- /dev/null
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/BleDeviceFinder.java
@@ -0,0 +1,157 @@
1+package net.osdn.gokigen.blecontrol.lib.ble.connect;
2+
3+import android.bluetooth.BluetoothAdapter;
4+import android.bluetooth.BluetoothDevice;
5+import android.bluetooth.BluetoothManager;
6+import android.content.Context;
7+import android.os.Build;
8+import android.util.Log;
9+
10+import androidx.annotation.NonNull;
11+import androidx.annotation.RequiresApi;
12+import androidx.fragment.app.FragmentActivity;
13+
14+import net.osdn.gokigen.blecontrol.lib.ble.R;
15+import net.osdn.gokigen.blecontrol.lib.ui.SnackBarMessage;
16+
17+@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
18+public class BleDeviceFinder implements BluetoothAdapter.LeScanCallback
19+{
20+ private String TAG = toString();
21+ private static final int BLE_SCAN_TIMEOUT_MILLIS = 15 * 1000; // 15秒間
22+ private static final int BLE_WAIT_DURATION = 100; // 100ms間隔
23+
24+ private final FragmentActivity context;
25+ private final ITextDataUpdater dataUpdater;
26+ private String targetDeviceName = null;
27+ private final BleScanResult scanResult;
28+ private final SnackBarMessage messageToShow;
29+ private boolean foundBleDevice = false;
30+
31+ public BleDeviceFinder(@NonNull FragmentActivity context, @NonNull ITextDataUpdater dataUpdater, @NonNull BleScanResult scanResult)
32+ {
33+ this.context = context;
34+ this.dataUpdater = dataUpdater;
35+ this.scanResult = scanResult;
36+ this.messageToShow = new SnackBarMessage(context, false);
37+
38+ }
39+
40+ public void reset()
41+ {
42+ foundBleDevice = false;
43+ }
44+
45+ public void startScan(@NonNull String targetDeviceName)
46+ {
47+ try
48+ {
49+ this.targetDeviceName = targetDeviceName;
50+ BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
51+ if (!btAdapter.isEnabled())
52+ {
53+ // Bluetoothの設定がOFFだった
54+ messageToShow.showMessage(R.string.ble_setting_is_off);
55+ }
56+ BluetoothManager btMgr;
57+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
58+ {
59+ // BLE のサービスを取得
60+ btMgr = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
61+ if (btMgr != null)
62+ {
63+ // BLEデバイスをスキャンする
64+ scanBleDevice(btMgr);
65+ }
66+ else
67+ {
68+ // Bluetooth LEのサポートがない場合は、何もしない
69+ messageToShow.showMessage(R.string.not_support_ble);
70+ }
71+ }
72+ else
73+ {
74+ // Androidのバージョンが低かった
75+ messageToShow.showMessage(R.string.not_support_android_version);
76+ }
77+ }
78+ catch (Exception e)
79+ {
80+ e.printStackTrace();
81+ }
82+ }
83+
84+ private void scanBleDevice(BluetoothManager btMgr)
85+ {
86+ try
87+ {
88+ // スキャン開始
89+ foundBleDevice = false;
90+
91+ BluetoothAdapter adapter = btMgr.getAdapter();
92+ if (!adapter.startLeScan(this))
93+ {
94+ // Bluetooth LEのスキャンが開始できなかった場合...
95+ Log.v(TAG, "Bluetooth LE SCAN START fail...");
96+ messageToShow.showMessage(R.string.ble_scan_start_failure);
97+ return;
98+ }
99+ Log.v(TAG, " ----- BT SCAN STARTED ----- ");
100+ int passed = 0;
101+ while (passed < BLE_SCAN_TIMEOUT_MILLIS)
102+ {
103+ if (foundBleDevice)
104+ {
105+ // デバイス発見
106+ Log.v(TAG, "FOUND DEVICE");
107+ break;
108+ }
109+
110+ // BLEのスキャンが終わるまで待つ
111+ Thread.sleep(BLE_WAIT_DURATION);
112+ passed = passed + BLE_WAIT_DURATION;
113+ }
114+ // スキャンを止める(500ms後に)
115+ Thread.sleep(500);
116+ adapter.stopLeScan(this);
117+ Log.v(TAG, " ----- BT SCAN STOPPED ----- ");
118+ }
119+ catch (Exception e)
120+ {
121+ e.printStackTrace();
122+ Log.v(TAG, "Bluetooth LE SCAN EXCEPTION...");
123+ messageToShow.showMessage(R.string.scan_fail_via_ble);
124+ }
125+ Log.v(TAG, "Bluetooth LE SCAN STOPPED");
126+ context.runOnUiThread(new Runnable() {
127+ @Override
128+ public void run() {
129+ dataUpdater.setText(context.getString(R.string.ble_scan_finished));
130+ }
131+ });
132+ }
133+
134+ @Override
135+ public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)
136+ {
137+ try
138+ {
139+ final String btDeviceName = device.getName();
140+ if ((btDeviceName != null)&&(btDeviceName.matches(targetDeviceName)))
141+ {
142+ // device発見!
143+ foundBleDevice = true;
144+ scanResult.foundBleDevice(device);
145+ }
146+ }
147+ catch (Exception e)
148+ {
149+ e.printStackTrace();
150+ }
151+ }
152+
153+ public interface BleScanResult
154+ {
155+ void foundBleDevice(BluetoothDevice device);
156+ }
157+}
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/ITextDataUpdater.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/ITextDataUpdater.java
@@ -4,6 +4,8 @@ public interface ITextDataUpdater
44 {
55 void setText(String data);
66 void addText(String data);
7+ void showSnackBar(String message);
8+ void showSnackBar(int rscId);
79
810 void enableOperation(boolean isEnable);
911 }
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/eeg/MindWaveCommunication.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/eeg/MindWaveCommunication.java
@@ -1,34 +1,63 @@
11 package net.osdn.gokigen.blecontrol.lib.ble.connect.eeg;
22
3+import android.bluetooth.BluetoothDevice;
4+import android.os.Build;
35 import android.util.Log;
46
57 import androidx.annotation.NonNull;
68 import androidx.fragment.app.FragmentActivity;
79
810 import net.osdn.gokigen.blecontrol.lib.ble.R;
11+import net.osdn.gokigen.blecontrol.lib.ble.connect.BleDeviceFinder;
912 import net.osdn.gokigen.blecontrol.lib.ble.connect.ITextDataUpdater;
1013
11-public class MindWaveCommunication
14+
15+public class MindWaveCommunication implements BleDeviceFinder.BleScanResult
1216 {
1317 private final String TAG = toString();
18+
1419 private final FragmentActivity context;
1520 private final ITextDataUpdater dataUpdater;
21+ private BleDeviceFinder deviceFinder = null;
1622
1723 public MindWaveCommunication(@NonNull FragmentActivity context, @NonNull ITextDataUpdater dataUpdater)
1824 {
1925 this.context = context;
2026 this.dataUpdater = dataUpdater;
27+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
28+ {
29+ this.deviceFinder = new BleDeviceFinder(context, dataUpdater, this);
30+ }
2131 }
2232
2333 public void connect(@NonNull String deviceName)
2434 {
2535 Log.v(TAG, " BrainWaveMobileCommunicator::connect() : " + deviceName);
2636 setText(context.getString(R.string.start_query) + " '" + deviceName + "' ");
27-
37+ try
38+ {
39+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
40+ {
41+ // BLE のサービスを取得
42+ if (deviceFinder != null)
43+ {
44+ // BLEデバイスをスキャンする
45+ deviceFinder.reset();
46+ deviceFinder.startScan(deviceName);
47+ }
48+ }
49+ else
50+ {
51+ // Androidのバージョンが低かった
52+ dataUpdater.showSnackBar(R.string.not_support_android_version);
53+ }
54+ }
55+ catch (Exception e)
56+ {
57+ e.printStackTrace();
58+ }
2859 }
2960
30-
31-
3261 private void setText(@NonNull final String message)
3362 {
3463 dataUpdater.setText(message);
@@ -39,4 +68,27 @@ public class MindWaveCommunication
3968 dataUpdater.addText(message);
4069 }
4170
71+
72+ @Override
73+ public void foundBleDevice(BluetoothDevice device)
74+ {
75+ try
76+ {
77+ addText(" ");
78+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
79+ {
80+/*
81+ if (communicator != null)
82+ {
83+ communicator.startCommunicate(device);
84+ }
85+*/
86+ }
87+ }
88+ catch (Exception e)
89+ {
90+ e.printStackTrace();
91+ }
92+ }
93+
4294 }
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/fv100/FV100BleDeviceConnector.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/fv100/FV100BleDeviceConnector.java
@@ -1,71 +1,53 @@
11 package net.osdn.gokigen.blecontrol.lib.ble.connect.fv100;
22
3-import android.bluetooth.BluetoothAdapter;
43 import android.bluetooth.BluetoothDevice;
5-import android.bluetooth.BluetoothManager;
6-import android.content.Context;
74 import android.os.Build;
85 import android.util.Log;
96
107 import androidx.annotation.NonNull;
11-import androidx.annotation.RequiresApi;
128 import androidx.fragment.app.FragmentActivity;
139
1410 import net.osdn.gokigen.blecontrol.lib.ble.R;
11+import net.osdn.gokigen.blecontrol.lib.ble.connect.BleDeviceFinder;
1512 import net.osdn.gokigen.blecontrol.lib.ble.connect.ITextDataUpdater;
16-import net.osdn.gokigen.blecontrol.lib.ui.SnackBarMessage;
1713
18-public class FV100BleDeviceConnector implements FV100Finder.BleScanResult
14+public class FV100BleDeviceConnector implements BleDeviceFinder.BleScanResult
1915 {
2016 private String TAG = toString();
21- private static final int BLE_SCAN_TIMEOUT_MILLIS = 15 * 1000; // 15秒間
22- private static final int BLE_WAIT_DURATION = 100; // 100ms間隔
23- private final FragmentActivity context;
24- private final ITextDataUpdater dataUpdater;
25- private final SnackBarMessage messageToShow;
17+ private BleDeviceFinder deviceFinder = null;
2618 private FV100Communicator communicator = null;
27- private boolean foundBleDevice = false;
19+ private final ITextDataUpdater dataUpdater;
20+
2821
2922 public FV100BleDeviceConnector(@NonNull FragmentActivity context, @NonNull ITextDataUpdater dataUpdater)
3023 {
31- this.context = context;
3224 this.dataUpdater = dataUpdater;
33- this.messageToShow = new SnackBarMessage(context, false);
3425 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
3526 {
36- communicator = new FV100Communicator(context, dataUpdater, messageToShow);
27+ this.deviceFinder = new BleDeviceFinder(context, dataUpdater, this);
28+ this.communicator = new FV100Communicator(context, dataUpdater);
3729 }
3830 }
3931
4032 public void query_to_device(String deviceName)
4133 {
4234 Log.v(TAG, " query_to_device : '" + deviceName + "'");
43- try {
44- BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
45- if (!btAdapter.isEnabled()) {
46- // Bluetoothの設定がOFFだった
47- messageToShow.showMessage(R.string.ble_setting_is_off);
48- }
49- BluetoothManager btMgr;
35+ try
36+ {
5037 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
5138 {
5239 // BLE のサービスを取得
53- btMgr = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
54- if (btMgr != null)
40+ if (deviceFinder != null)
5541 {
5642 // BLEデバイスをスキャンする
57- scanBleDevice(btMgr, new FV100Finder(deviceName, this));
58- }
59- else
60- {
61- // Bluetooth LEのサポートがない場合は、何もしない
62- messageToShow.showMessage(R.string.not_support_ble);
43+ deviceFinder.reset();
44+ deviceFinder.startScan(deviceName);
6345 }
6446 }
6547 else
6648 {
6749 // Androidのバージョンが低かった
68- messageToShow.showMessage(R.string.not_support_android_version);
50+ dataUpdater.showSnackBar(R.string.not_support_android_version);
6951 }
7052 }
7153 catch (Exception e)
@@ -129,64 +111,11 @@ public class FV100BleDeviceConnector implements FV100Finder.BleScanResult
129111 }
130112 }
131113
132-
133- @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
134- private void scanBleDevice(BluetoothManager btMgr, FV100Finder finder)
135- {
136- try
137- {
138- // スキャン開始
139- foundBleDevice = false;
140- finder.reset();
141- BluetoothAdapter adapter = btMgr.getAdapter();
142- if (!adapter.startLeScan(finder))
143- {
144- // Bluetooth LEのスキャンが開始できなかった場合...
145- Log.v(TAG, "Bluetooth LE SCAN START fail...");
146- messageToShow.showMessage(R.string.ble_scan_start_failure);
147- return;
148- }
149- Log.v(TAG, " ----- BT SCAN STARTED ----- ");
150- int passed = 0;
151- while (passed < BLE_SCAN_TIMEOUT_MILLIS)
152- {
153- if (foundBleDevice)
154- {
155- // デバイス発見
156- Log.v(TAG, "FOUND DEVICE");
157- break;
158- }
159-
160- // BLEのスキャンが終わるまで待つ
161- Thread.sleep(BLE_WAIT_DURATION);
162- passed = passed + BLE_WAIT_DURATION;
163- }
164- // スキャンを止める
165- Thread.sleep(1000);
166- adapter.stopLeScan(finder);
167- Log.v(TAG, " ----- BT SCAN STOPPED ----- ");
168- }
169- catch (Exception e)
170- {
171- e.printStackTrace();
172- Log.v(TAG, "Bluetooth LE SCAN EXCEPTION...");
173- messageToShow.showMessage(R.string.scan_fail_via_ble);
174- }
175- Log.v(TAG, "Bluetooth LE SCAN STOPPED");
176- context.runOnUiThread(new Runnable() {
177- @Override
178- public void run() {
179- dataUpdater.setText(context.getString(R.string.ble_scan_finished));
180- }
181- });
182- }
183-
184114 @Override
185115 public void foundBleDevice(BluetoothDevice device)
186116 {
187117 try
188118 {
189- foundBleDevice = true;
190119 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
191120 {
192121 if (communicator != null)
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/fv100/FV100Communicator.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/fv100/FV100Communicator.java
@@ -17,7 +17,6 @@ import androidx.fragment.app.FragmentActivity;
1717
1818 import net.osdn.gokigen.blecontrol.lib.ble.R;
1919 import net.osdn.gokigen.blecontrol.lib.ble.connect.ITextDataUpdater;
20-import net.osdn.gokigen.blecontrol.lib.ui.SnackBarMessage;
2120 import net.osdn.gokigen.blecontrol.lib.wifi.WifiConnector;
2221
2322 import java.io.ByteArrayOutputStream;
@@ -30,7 +29,6 @@ class FV100Communicator extends BluetoothGattCallback implements FV100ObjectPas
3029 private String TAG = toString();
3130 private final FragmentActivity context;
3231 private final ITextDataUpdater dataUpdater;
33- private final SnackBarMessage messageToShow;
3432 //private boolean mtuSizeIsExpanded = false;
3533 private boolean startQuery = false;
3634 private boolean onConnected = false;
@@ -45,15 +43,14 @@ class FV100Communicator extends BluetoothGattCallback implements FV100ObjectPas
4543 private List<byte[]> setPropertyMessage = null;
4644 private int setPropertyMessageIndex = -1;
4745
48- FV100Communicator(@NonNull FragmentActivity context, @NonNull ITextDataUpdater dataUpdater, @NonNull SnackBarMessage messageToShow)
46+ FV100Communicator(@NonNull FragmentActivity context, @NonNull ITextDataUpdater dataUpdater)
4947 {
5048 this.context = context;
5149 this.dataUpdater = dataUpdater;
52- this.messageToShow = messageToShow;
5350 this.receiveBuffer = new ByteArrayOutputStream();
5451 this.objectParser = new FV100ObjectPaser(this);
5552 this.sendMessageProvider = new FV100SendMessageProvider(this);
56- this.wifiConnector = new WifiConnector(context, messageToShow);
53+ this.wifiConnector = new WifiConnector(context, dataUpdater);
5754 }
5855
5956 void startCommunicate(@Nullable final BluetoothDevice device)
@@ -143,7 +140,7 @@ class FV100Communicator extends BluetoothGattCallback implements FV100ObjectPas
143140 context.runOnUiThread(new Runnable() {
144141 @Override
145142 public void run() {
146- messageToShow.showMessage(context.getString(R.string.ble_not_connected));
143+ dataUpdater.showSnackBar(context.getString(R.string.ble_not_connected));
147144 }
148145 });
149146 return;
@@ -154,7 +151,7 @@ class FV100Communicator extends BluetoothGattCallback implements FV100ObjectPas
154151 context.runOnUiThread(new Runnable() {
155152 @Override
156153 public void run() {
157- messageToShow.showMessage(context.getString(R.string.now_ble_communicating));
154+ dataUpdater.showSnackBar(context.getString(R.string.now_ble_communicating));
158155 }
159156 });
160157 return;
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ble/connect/fv100/FV100Finder.java
+++ /dev/null
@@ -1,50 +0,0 @@
1-package net.osdn.gokigen.blecontrol.lib.ble.connect.fv100;
2-
3-import android.bluetooth.BluetoothAdapter;
4-import android.bluetooth.BluetoothDevice;
5-import android.os.Build;
6-
7-import androidx.annotation.NonNull;
8-import androidx.annotation.RequiresApi;
9-
10-@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR2)
11-public class FV100Finder implements BluetoothAdapter.LeScanCallback
12-{
13- private final String targetDeviceName;
14- private final BleScanResult scanResult;
15-
16- FV100Finder(@NonNull String targetDeviceName, @NonNull BleScanResult scanResult)
17- {
18- this.targetDeviceName = targetDeviceName;
19- this.scanResult = scanResult;
20-
21- }
22-
23- void reset()
24- {
25-
26- }
27-
28- @Override
29- public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)
30- {
31- try
32- {
33- final String btDeviceName = device.getName();
34- if ((btDeviceName != null)&&(btDeviceName.matches(targetDeviceName)))
35- {
36- // device発見!
37- scanResult.foundBleDevice(device);
38- }
39- }
40- catch (Exception e)
41- {
42- e.printStackTrace();
43- }
44- }
45-
46- interface BleScanResult
47- {
48- void foundBleDevice(BluetoothDevice device);
49- }
50-}
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/SnackBarMessage.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/SnackBarMessage.java
@@ -19,8 +19,7 @@ public class SnackBarMessage
1919 public SnackBarMessage(@NonNull FragmentActivity context, boolean isToast)
2020 {
2121 this.context = context;
22- this.isToast = false;
23-
22+ this.isToast = isToast;
2423 }
2524
2625 public void showMessage(final String message)
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/brainwave/BrainwaveConnection.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/brainwave/BrainwaveConnection.java
@@ -11,6 +11,7 @@ import androidx.fragment.app.FragmentActivity;
1111 import net.osdn.gokigen.blecontrol.lib.ble.R;
1212 import net.osdn.gokigen.blecontrol.lib.ble.connect.ITextDataUpdater;
1313 import net.osdn.gokigen.blecontrol.lib.ble.connect.eeg.MindWaveCommunication;
14+import net.osdn.gokigen.blecontrol.lib.ui.SnackBarMessage;
1415
1516 public class BrainwaveConnection implements View.OnClickListener, ITextDataUpdater
1617 {
@@ -19,6 +20,7 @@ public class BrainwaveConnection implements View.OnClickListener, ITextDataUpdat
1920 private final SelectDevice deviceSelection;
2021 private final BrainwaveMobileViewModel viewModel;
2122 private final MindWaveCommunication communicator;
23+ private final SnackBarMessage messageToShow;
2224
2325 BrainwaveConnection(@NonNull FragmentActivity context, @NonNull SelectDevice deviceSelection, @NonNull BrainwaveMobileViewModel viewModel)
2426 {
@@ -26,6 +28,7 @@ public class BrainwaveConnection implements View.OnClickListener, ITextDataUpdat
2628 this.deviceSelection = deviceSelection;
2729 this.viewModel = viewModel;
2830 this.communicator = new MindWaveCommunication(context, this);
31+ this.messageToShow = new SnackBarMessage(context, false);
2932 }
3033
3134 @Override
@@ -91,6 +94,18 @@ public class BrainwaveConnection implements View.OnClickListener, ITextDataUpdat
9194 }
9295
9396 @Override
97+ public void showSnackBar(String message)
98+ {
99+ messageToShow.showMessage(message);
100+ }
101+
102+ @Override
103+ public void showSnackBar(int rscId)
104+ {
105+ messageToShow.showMessage(rscId);
106+ }
107+
108+ @Override
94109 public void enableOperation(final boolean isEnable)
95110 {
96111 try
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/fv100/FV100DeviceQuery.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/ui/fv100/FV100DeviceQuery.java
@@ -10,6 +10,7 @@ import androidx.fragment.app.FragmentActivity;
1010 import net.osdn.gokigen.blecontrol.lib.ble.R;
1111 import net.osdn.gokigen.blecontrol.lib.ble.connect.ITextDataUpdater;
1212 import net.osdn.gokigen.blecontrol.lib.ble.connect.fv100.FV100BleDeviceConnector;
13+import net.osdn.gokigen.blecontrol.lib.ui.SnackBarMessage;
1314
1415 public class FV100DeviceQuery implements View.OnClickListener, ITextDataUpdater, FV100PropertySetting.PropertySetter
1516 {
@@ -18,6 +19,7 @@ public class FV100DeviceQuery implements View.OnClickListener, ITextDataUpdater,
1819 private final DeviceInfo deviceInfo;
1920 private final FV100ViewModel viewModel;
2021 private final FV100BleDeviceConnector deviceConnector;
22+ private final SnackBarMessage messageToShow;
2123
2224 FV100DeviceQuery(@NonNull FragmentActivity context, @NonNull DeviceInfo deviceInfo, @NonNull FV100ViewModel viewModel)
2325 {
@@ -25,6 +27,7 @@ public class FV100DeviceQuery implements View.OnClickListener, ITextDataUpdater,
2527 this.deviceInfo = deviceInfo;
2628 this.viewModel = viewModel;
2729 this.deviceConnector = new FV100BleDeviceConnector(context, this);
30+ this.messageToShow = new SnackBarMessage(context, false);
2831 }
2932
3033 private void deviceQuery()
@@ -123,6 +126,18 @@ public class FV100DeviceQuery implements View.OnClickListener, ITextDataUpdater,
123126 }
124127
125128 @Override
129+ public void showSnackBar(String message)
130+ {
131+ messageToShow.showMessage(message);
132+ }
133+
134+ @Override
135+ public void showSnackBar(int rscId)
136+ {
137+ messageToShow.showMessage(rscId);
138+ }
139+
140+ @Override
126141 public void enableOperation(final boolean isEnable)
127142 {
128143 try
--- a/app/src/main/java/net/osdn/gokigen/blecontrol/lib/wifi/WifiConnector.java
+++ b/app/src/main/java/net/osdn/gokigen/blecontrol/lib/wifi/WifiConnector.java
@@ -22,7 +22,7 @@ import androidx.annotation.RequiresApi;
2222 import androidx.fragment.app.FragmentActivity;
2323
2424 import net.osdn.gokigen.blecontrol.lib.ble.R;
25-import net.osdn.gokigen.blecontrol.lib.ui.SnackBarMessage;
25+import net.osdn.gokigen.blecontrol.lib.ble.connect.ITextDataUpdater;
2626
2727 import java.util.ArrayList;
2828 import java.util.List;
@@ -33,14 +33,14 @@ public class WifiConnector
3333 {
3434 private String TAG = toString();
3535
36- private final SnackBarMessage messageToShow;
36+ private final ITextDataUpdater dataUpdater;
3737 private final FragmentActivity context;
3838 private final BroadcastReceiver connectionReceiver;
3939
40- public WifiConnector(@NonNull FragmentActivity context, @NonNull SnackBarMessage messageToShow)
40+ public WifiConnector(@NonNull FragmentActivity context, @NonNull ITextDataUpdater dataUpdater)
4141 {
4242 this.context = context;
43- this.messageToShow = messageToShow;
43+ this.dataUpdater = dataUpdater;
4444 connectionReceiver = new BroadcastReceiver()
4545 {
4646 @Override
@@ -190,11 +190,11 @@ public class WifiConnector
190190 else
191191 {
192192 // 接続に失敗した
193- messageToShow.showMessage(context.getString(R.string.connect_wifi_failure) + " " + ssId);
193+ dataUpdater.showSnackBar(context.getString(R.string.connect_wifi_failure) + " " + ssId);
194194 callback.onWifiConnected(false);
195195 return;
196196 }
197- messageToShow.showMessage(context.getString(R.string.try_to_connect_wifi) + " " + ssId);
197+ dataUpdater.showSnackBar(context.getString(R.string.try_to_connect_wifi) + " " + ssId);
198198 isConnect = true;
199199 }
200200 catch (Exception e)
@@ -211,7 +211,7 @@ public class WifiConnector
211211 Log.v(TAG, "connectToWifiNewerVersion() : '" + wifiSsId + "' [" + wifiKey + "]");
212212 try
213213 {
214- turnOffWifieNewerVersion(wifiSsId, wifiKey);
214+ turnOffWifiNewerVersion(wifiSsId, wifiKey);
215215
216216 WifiNetworkSpecifier.Builder builder = new WifiNetworkSpecifier.Builder();
217217 builder.setSsid(wifiSsId);
@@ -238,7 +238,7 @@ public class WifiConnector
238238 }
239239
240240 @RequiresApi(api = Build.VERSION_CODES.Q)
241- private void turnOffWifieNewerVersion(@NonNull String wifiSsId, @NonNull String wifiKey)
241+ private void turnOffWifiNewerVersion(@NonNull String wifiSsId, @NonNull String wifiKey)
242242 {
243243 try
244244 {
@@ -258,7 +258,7 @@ public class WifiConnector
258258
259259 WifiNetworkSuggestion.Builder builder = new WifiNetworkSuggestion.Builder();
260260 builder.setSsid(wifiSsId);
261- //builder.setWpa2Passphrase(wifiKey);
261+ builder.setWpa2Passphrase(wifiKey);
262262 WifiNetworkSuggestion suggestion = builder.build();
263263 List<WifiNetworkSuggestion> list = new ArrayList<>();
264264 list.add(suggestion);
@@ -283,7 +283,7 @@ public class WifiConnector
283283 // WiFi を ON にする (たぶん失敗する...)
284284 if (!wifi.setWifiEnabled(true))
285285 {
286- messageToShow.showMessage(R.string.turn_on_wifi_is_failed);
286+ dataUpdater.showSnackBar(R.string.turn_on_wifi_is_failed);
287287 }
288288 }
289289 catch (Exception e)
旧リポジトリブラウザで表示