Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abook_check
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abook_android
abook_check
Commits
39e4fbdc
Commit
39e4fbdc
authored
Jul 29, 2020
by
onuma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bluetooth未接続時に、フォームから作業一覧に戻る時にスキャンを停止するように修正した
parent
c074517c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
155 additions
and
102 deletions
+155
-102
ABVJE_Res_Default_Android/res/values/strings.xml
+2
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
+14
-0
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/TR41BluetoothUtil.java
+22
-85
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/activity/ABVCheckContentViewActivity.java
+116
-17
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/activity/ABVContentViewActivity.java
+1
-0
No files found.
ABVJE_Res_Default_Android/res/values/strings.xml
View file @
39e4fbdc
...
...
@@ -1438,5 +1438,6 @@
<string
name=
"msg_no_nfc_setting"
>
端末の設定からNFCを有効にする必要があります。\n端末の設定画面へ遷移しますか?
</string>
<string
name=
"select_spp_device_title"
>
シリアル通信機器選択
</string>
<string
name=
"msg_bluetooth_connect_timeout_error"
>
%1$s with the central thermometer has been lost. Check the power and distance of %1$s and try again.(%2$s)
</string>
<string
name=
"tr41_thermometer"
>
TR41温度センサー
</string>
</resources>
\ No newline at end of file
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/BleManagerUtil.java
View file @
39e4fbdc
...
...
@@ -326,6 +326,18 @@ public class BleManagerUtil {
// 切断
public
void
disconnect
(
boolean
listenerFlg
)
{
// 接続されていない。検索中の場合はスキャン停止
if
(
listenerFlg
)
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
// スキャン停止
mHandler
.
removeCallbacksAndMessages
(
null
);
mBluetoothAdapter
.
getBluetoothLeScanner
().
stopScan
(
mScanCallback
);
}
});
}
if
(
mBluetoothGatt
==
null
)
{
return
;
}
...
...
@@ -339,6 +351,7 @@ public class BleManagerUtil {
mBluetoothGatt
.
disconnect
();
// mBluetoothGatt.close();
mBluetoothGatt
=
null
;
/**
if (listenerFlg) {
runOnUiThread( new Runnable() {
@Override
...
...
@@ -348,6 +361,7 @@ public class BleManagerUtil {
}
});
}
*/
}
// キャラクタリスティックの読み込み
...
...
ABVJE_UI_Android/src/jp/agentec/abook/abv/cl/util/TR41BluetoothUtil.java
View file @
39e4fbdc
...
...
@@ -62,15 +62,10 @@ public class TR41BluetoothUtil {
*
*/
public
interface
TR41BluetoothUtilLeScanner
{
//void onGetDeviceInfo(String strTemperature); // ディバイスから渡す情報
//void onGetDeviceInfoFailed(int status); // ディバイスと接続失敗時の情報渡す。
//void onConnectionState(); // ディバイスと接続された時情報渡す。
//void onDisConnectionState(); // ディバイスと切断時
//void onConnectionError(int status); // ディバイス接続エラー
void
onBatchScanResults
(
List
<
ScanResult
>
results
);
//void onBatchScanResults(List<ScanResult> results);
void
onScanFailed
(
int
errorCode
);
void
onScanResult
(
int
callbackType
,
ScanResult
result
);
//void onScanResult(int callbackType, ScanResult result);
void
onScanResult
(
String
strTemperature
);
// デバイスから温度を渡す
}
public
TR41BluetoothUtil
(
Context
context
,
TR41BluetoothUtilLeScanner
listener
)
...
...
@@ -108,7 +103,7 @@ public class TR41BluetoothUtil {
///////////////////////////////////////////////////////////////////////////////////////////////
/** BLE機器を検索する */
p
rivate
void
Sb_
Scan
()
p
ublic
void
Sb_Start
Scan
()
{
Sb_Init_Ble_Scan
()
;
...
...
@@ -131,6 +126,11 @@ public class TR41BluetoothUtil {
},
SCAN_PERIOD
);
}
public
void
Sb_StopScan
()
{
mBluetoothLeScanner
.
stopScan
(
mScanCallback
)
;
}
private
ScanCallback
mScanCallback
=
new
ScanCallback
()
{
@Override
...
...
@@ -140,12 +140,14 @@ public class TR41BluetoothUtil {
@Override
public
void
onBatchScanResults
(
final
List
<
ScanResult
>
results
)
{
Logger
.
d
(
TAG
,
"onBatchScanResults"
);
/**
runOnUiThread( new Runnable() {
@Override
public void run() {
mListener.onBatchScanResults(results);
}
});
*/
};
@Override
...
...
@@ -160,12 +162,10 @@ public class TR41BluetoothUtil {
};
@Override
public
void
onScanResult
(
final
int
callbackType
,
final
ScanResult
result
)
{
Logger
.
d
(
TAG
,
"onScanResult"
);
public
void
onScanResult
(
int
callbackType
,
ScanResult
result
)
{
BluetoothDevice
device
=
result
.
getDevice
()
;
byte
[]
scanRecord
=
result
.
getScanRecord
().
getBytes
()
;
Logger
.
d
(
""
,
"getBoundState = "
+
device
.
getBondState
());
if
(
device
.
getBondState
()
!=
BluetoothDevice
.
BOND_BONDED
)
{
long
serial
[]
=
new
long
[
1
]
;
int
security
[]
=
new
int
[
1
]
;
...
...
@@ -173,7 +173,6 @@ public class TR41BluetoothUtil {
int
ch2Data
[]
=
new
int
[
1
]
;
int
batLevel
[]
=
new
int
[
1
]
;
StringBuffer
localName
=
new
StringBuffer
()
;
//int found ;
int
rtn
;
String
devName
=
device
.
getName
()
;
...
...
@@ -182,43 +181,29 @@ public class TR41BluetoothUtil {
return
;
}
// 近くにあるTR4だけを検索したい場合
// 近くにあるTR4だけを検索したい場合
( getRssiは、電波強度を返す。dBm マイナスが小さいほど電波が強い)
//if(result.getRssi() < -50)
// return ;
rtn
=
Sb_Parse_ScanRecord
(
scanRecord
,
serial
,
localName
,
security
,
ch1Data
,
ch2Data
,
batLevel
)
;
if
(
rtn
==
0
)
{
devName
=
localName
.
toString
().
trim
()
;
// すでに登録されたシリアル番号を調べる
//found = 0 ;
/**
for(int i=0; i< mDeviceList.getCount(); i++) {
Logger.d("","" + mDeviceList.infoList.get(i).getSerial());
if(mDeviceList.infoList.get(i).getSerial() == serial[0]) {
found = 1 ;
break ;
}
}
if(found == 0) {
mDeviceList.addDeviceInfo(serial[0], devName, device.getAddress(),
device, ch1Data[0], mScanTime/1000);
mListView.setAdapter(mDeviceList) ;
mDeviceList.notifyDataSetChanged() ;
final
String
ch1Str
;
if
(
ch1Data
[
0
]
==
0xEEEE
)
ch1Str
=
"----"
;
else
if
(
ch1Data
[
0
]
==
0xEEE0
)
ch1Str
=
""
;
else
ch1Str
=
String
.
format
(
"%.1f"
,
(
double
)(
ch1Data
[
0
]-
1000
)/
10.0
)
;
//mScanStop.cancel();
//mScanStop = null;
//mBluetoothLeScanner.stopScan(mScanCallback) ;
}
*/
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
mListener
.
onScanResult
(
c
allbackType
,
result
);
mListener
.
onScanResult
(
c
h1Str
);
}
});
mBluetoothLeScanner
.
stopScan
(
mScanCallback
)
;
//
mBluetoothLeScanner.stopScan(mScanCallback) ;
}
}
};
...
...
@@ -426,51 +411,4 @@ public class TR41BluetoothUtil {
return
retStr
;
}
//デバイスの名前とアドレスを持つクラス
private
class
DeviceInfo
{
private
long
serial
;
private
String
name
;
private
String
address
;
private
BluetoothDevice
bltDevice
;
private
int
ch1Data
;
private
long
dataTime
;
private
long
rssi
;
private
DeviceInfo
(
long
serial
,
String
name
,
String
address
,
BluetoothDevice
bltDevice
,
int
ch1Data
,
long
dataTime
,
long
rssi
)
{
this
.
serial
=
serial
;
this
.
name
=
name
;
this
.
address
=
address
;
this
.
bltDevice
=
bltDevice
;
this
.
ch1Data
=
ch1Data
;
this
.
dataTime
=
dataTime
;
this
.
rssi
=
rssi
;
}
private
long
getSerial
()
{
return
serial
;
}
private
String
getName
()
{
return
(
name
)
+
" "
+
rssi
;
}
private
String
getAddress
()
{
return
address
;
}
private
BluetoothDevice
getBluetoothDevice
()
{
return
bltDevice
;
}
private
int
getCh1Data
()
{
return
ch1Data
;
}
private
long
getDataTime
()
{
return
dataTime
;
}
}
}
\ No newline at end of file
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/activity/ABVCheckContentViewActivity.java
View file @
39e4fbdc
...
...
@@ -46,6 +46,7 @@ import jp.agentec.abook.abv.bl.data.dao.SppDeviceDao;
import
jp.agentec.abook.abv.bl.dto.SppDeviceDto
;
import
jp.agentec.abook.abv.cl.util.BleManagerUtil
;
import
jp.agentec.abook.abv.cl.util.SppBluetoothConnectThread
;
import
jp.agentec.abook.abv.cl.util.TR41BluetoothUtil
;
import
jp.agentec.abook.abv.cl.util.YamatoBluetoothReceiveTask
;
import
jp.agentec.abook.abv.launcher.android.R
;
import
jp.agentec.abook.abv.ui.common.dialog.ABookAlertDialog
;
...
...
@@ -82,7 +83,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
private
static
final
int
REQUEST_CODE_BARCODE_READER
=
2003
;
// バーコードリーダの職別コード
private
static
final
int
REQUEST_CODE_ENABLEBLUETOOTH_RADIATION_TEMPERATURE
=
2004
;
// Bluetooth機能の有効化要求時の識別コード(放射温度計)
private
static
final
int
REQUEST_CODE_ENABLEBLUETOOTH_SPP_MACHINE
=
2005
;
// Bluetooth機能の有効化要求時の識別コード(SPP通信機器)
private
static
final
int
REQUEST_CODE_ENABLEBLUETOOTH_TR41
=
2006
;
// Bluetooth機能の有効化要求時の識別コード(TR41温度センサー)
// メンバー変数
private
BleManagerUtil
bleManagerUtil
;
// Bluetoothの接続
...
...
@@ -125,7 +126,16 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
private
Integer
mSppDeviceId
;
// Bluetoothの接続状態
private
boolean
isConnection
;
private
boolean
mIsConnection
;
// TR41温度センサーを扱うためのクラス
private
TR41BluetoothUtil
mTR41BluetoothUtil
;
// TR41 スキャン中フラグ
private
boolean
mIsTR41Scaning
;
// TR41 スキャン対象デバイスのシリアルNo.
private
String
mTR41SerialNo
;
/**
* Beaconスキャン結果受信Receiver.
...
...
@@ -236,6 +246,8 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
}
// onuma
bleManagerDisconnect
(
true
);
// ダイアログは消す
dismissWaitngDialog
();
}
@Override
...
...
@@ -261,7 +273,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
bleManagerDisconnect
(
true
);
}
else
{
// onuma
i
sConnection
=
true
;
mI
sConnection
=
true
;
mWaitingDialog
.
setMessage
(
message
);
}
}
...
...
@@ -274,7 +286,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
// setThermometerData("");
// onuma 何もしない。オリジナルコードもダイアログを消すだけで、何もしていない
i
sConnection
=
false
;
mI
sConnection
=
false
;
dismissWaitngDialog
();
}
...
...
@@ -334,9 +346,46 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
Logger
.
e
(
TAG
,
"BluetoothAdapter is null."
);
}
// TR41温度
計
// TR41温度
センサー
if
(
mBluetoothAdapter
!=
null
){
mTR41BluetoothUtil
=
new
TR41BluetoothUtil
(
this
,
new
TR41BluetoothUtil
.
TR41BluetoothUtilLeScanner
()
{
@Override
public
void
onScanFailed
(
int
errorCode
)
{
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
Logger
.
e
(
TAG
,
"onScanFailed : "
+
errorCode
);
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
String
errorMessage
=
errorMessage
=
String
.
format
(
getString
(
R
.
string
.
msg_bluetooth_connect_error
),
getString
(
R
.
string
.
center_thermometer
));
//if (StringUtil.isNullOrEmpty(errorMessage)) {
// errorAfterAbookCheckAip(errorMessage);
//}
// TR41スキャン停止
stopTR41BeaconScan
();
// ダイアログを閉じる
dismissWaitngDialog
();
}
@Override
public
void
onScanResult
(
String
strTemperature
)
{
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
Logger
.
d
(
TAG
,
"onScanResult temperature [%s]"
,
strTemperature
);
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
// 値取得待ちのダイアログ表示中のみ値を取得、設定する
if
(
mWaitingDialog
!=
null
)
{
//setThermometerData(strTemperature);
// まだ、項目がないので、NFCとしてデータを返す
setNfcData
(
strTemperature
);
// 取得できたら、ダイアログ消す。
dismissWaitngDialog
();
// TR41スキャン停止
stopTR41BeaconScan
();
}
}
});
}
}
...
...
@@ -355,15 +404,17 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
//Beacon受信停止
unregisterReceiver
(
mReceiver
);
}
catch
(
Exception
e
){
// 重量計・放射温度計を切断後に実行
したところ
// 重量計・放射温度計を切断後に実行
すると発生する
// IllegalArgumentException
Logger
.
e
(
TAG
,
"disconnectBluetoothDevice error"
,
e
);
}
// 接続されている機器と切断する。
// onuma
bleManagerDisconnect
(
true
);
// TR41温度センサースキャン停止
stopTR41BeaconScan
();
super
.
onDestroy
();
}
...
...
@@ -501,6 +552,14 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
setSppBluetoothDeviceInfo
();
}
break
;
case
REQUEST_CODE_ENABLEBLUETOOTH_TR41:
// TR41温度センサー
if
(
Activity
.
RESULT_CANCELED
==
resultCode
)
{
// 有効にされなかった
errorAfterAbookCheckAip
(
String
.
format
(
getString
(
R
.
string
.
msg_connect_bluetooth_no_allow
),
getString
(
R
.
string
.
tr41_thermometer
)));
return
;
}
else
{
startTR41BeaconScan
();
}
break
;
}
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
}
...
...
@@ -556,9 +615,17 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
// NFC アタゴ糖度計・濃度計
setNfcDeviceInfo
();
}
else
if
(
mDeviceType
==
DeviceType
.
tr41
){
// TR41温度
計
// TR41温度
センサー
// param1はシリアルNo.
String
param1
=
abookCheckParam
.
get
(
ABookKeys
.
TASK_DEVICE_TYPE_PARAM1
);
if
(
StringUtil
.
isNullOrEmpty
(
param1
)
)
{
// パラメータが存在しない場合
errorAfterAbookCheckAip
(
getString
(
R
.
string
.
msg_not_found_parameter
));
return
;
}
mTR41SerialNo
=
param1
;
startTR41BeaconScan
();
}
else
{
Logger
.
e
(
"外部デバイスタイプ不正 deviceType = "
+
mDeviceType
);
...
...
@@ -625,6 +692,34 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
}
/**
* TR41 温度センサースキャン開始
*/
private
void
startTR41BeaconScan
()
{
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
Logger
.
d
(
TAG
,
"startTR41BeaconScan"
);
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
if
(
requestBluetoothFeature
(
REQUEST_CODE_ENABLEBLUETOOTH_TR41
))
{
//端末のBluetooth設定を確認
if
(!
mIsTR41Scaning
)
{
mTR41BluetoothUtil
.
Sb_StartScan
();
mIsTR41Scaning
=
true
;
}
}
}
/**
* TR41 温度センサースキャン停止
*/
private
void
stopTR41BeaconScan
(){
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
Logger
.
d
(
TAG
,
"stopTR41BeaconScan"
);
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
if
(
mIsTR41Scaning
)
{
mTR41BluetoothUtil
.
Sb_StopScan
();
mIsTR41Scaning
=
false
;
}
}
/**
* 中心温度計、置くだけセンサー接続の待機ダイヤログ表示
* @param title タイトル
* @param message 内容
...
...
@@ -646,8 +741,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
Logger
.
d
(
TAG
,
"中止"
);
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
//onuma
bleManagerDisconnect
(
true
);
// 中心温度計接続切断
bleManagerDisconnect
(
true
);
// 放射温度計、中心温度計接続切断
break
;
case
DeviceType
.
sensor
:
stopOkudakeBeaconScan
();
// 置くだけセンサースキャン中止
...
...
@@ -667,7 +761,8 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
// Activityがバックグラウンドになったときは、受け取らない
mNfcAdapter
.
disableForegroundDispatch
(
ABVCheckContentViewActivity
.
this
);
break
;
case
DeviceType
.
tr41
:
// TR41温度計
case
DeviceType
.
tr41
:
// TR41温度センサー
stopTR41BeaconScan
();
break
;
}
successAfterAbookCheckAip
(
""
);
...
...
@@ -699,7 +794,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
return
;
// 以下の処理にかからないようにreturnする
}
if
(
i
sConnection
)
{
if
(
mI
sConnection
)
{
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
Logger
.
d
(
TAG
,
"isConnection = true"
);
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
...
...
@@ -731,7 +826,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
return
;
// 以下の処理にかからないようにreturnする
}
if
(
i
sConnection
)
{
if
(
mI
sConnection
)
{
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
Logger
.
d
(
TAG
,
"isConnection = true"
);
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
...
...
@@ -976,7 +1071,7 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
Logger
.
d
(
TAG
,
"bleManagerDisconnect = "
+
disconnect
);
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
if
(
disconnect
){
i
sConnection
=
false
;
mI
sConnection
=
false
;
bleManagerUtil
.
disconnect
(
true
);
}
else
{
// 何もしない
...
...
@@ -1106,7 +1201,9 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
}
// すべてのBluetooth機器から切断
// onPause処理 -> onDestroy処理の順番を一度に行う
// onStop処理 -> onDestroy処理の順番を一度に行う
// ABVContentViewActivity::commonShouldOverrideUrlLoading (Uri uri, OperationTaskDto operationTaskDto) から実行される
// 作業一覧に戻る時に実行
@Override
protected
void
disconnectBluetoothDevice
()
{
...
...
@@ -1114,17 +1211,19 @@ public class ABVCheckContentViewActivity extends ABVContentViewActivity {
Logger
.
d
(
TAG
,
"disconnectBluetoothDevice"
);
Logger
.
d
(
TAG
,
"-------------------------------------------------"
);
stopTR41BeaconScan
();
disConnectSppBluetooth
();
try
{
disConnectSppBluetooth
();
unregisterReceiver
(
mReceiver
);
bleManagerDisconnect
(
true
);
}
catch
(
Exception
e
){
// 重量計・放射温度計を切断後に実行したところ
// IllegalArgumentException
Logger
.
e
(
TAG
,
"disconnectBluetoothDevice error"
,
e
);
}
bleManagerDisconnect
(
true
);
}
@Override
...
...
ABVJE_UI_Android/src/jp/agentec/abook/abv/ui/common/activity/ABVContentViewActivity.java
View file @
39e4fbdc
...
...
@@ -991,6 +991,7 @@ public abstract class ABVContentViewActivity extends ABVAuthenticatedActivity {
if
(
StringUtil
.
equalsAny
(
mCmd
,
ABookKeys
.
CMD_INSERT_TASK_REPORT
,
ABookKeys
.
CMD_UPDATE_TASK_REPORT
,
ABookKeys
.
CMD_DELETE_TASK_REPORT
,
ABookKeys
.
CMD_CANCEL_TASK_REPORT
)
){
// 作業一覧に戻る時
disconnectBluetoothDevice
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment