Commit 62057b49 by onuma

計測1回ごとにBLEを切断する。長押しで接続する時に、一部の機種の為3000msのWaitを入れた。

parent ad32ff5f
package jp.agentec.abook.abv.cl.util;
import android.bluetooth.BluetoothGatt;
public interface AlcoholCheckerUtilListener {
void onConnectionError(int status); // ディバイス接続エラー
void onMeasurementError(String txt); // 吹付エラー
......
......@@ -133,7 +133,7 @@ public class BleManagerUtil {
// サービス検索が完了したときの処理(mBluetoothGatt.discoverServices()の結果として呼ばれる。)
@Override
public void onServicesDiscovered(BluetoothGatt gatt, final int status) {
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
try {
Logger.i(TAG, "onServicesDiscovered status = %s", status);
......@@ -141,15 +141,14 @@ public class BleManagerUtil {
return;
}
//mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
if (mBluetoothGatt == null) {
mBluetoothGatt = gatt;
for (BluetoothGattService svc : gatt.getServices()){
Logger.d(TAG, svc.getUuid().toString());
}
mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
//mBluetoothGatt = gatt;
//mBluetoothGatt.requestConnectionPriority(BluetoothGatt.CONNECTION_PRIORITY_HIGH);
if (mListener != null) {
// アルコールチェッカー
mListener.onServicesDiscovered(status);
mListener.onServicesDiscovered(gatt, status);
}
} catch (Exception e) {
Logger.d(TAG,e);
......@@ -182,12 +181,8 @@ public class BleManagerUtil {
@Override
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status){
Logger.d(TAG,"onDescriptorWrite");
try {
if (mListener != null) {
mListener.onDescriptorWrite(gatt, descriptor, status);
}
} catch ( Exception e) {
Logger.e(TAG,e);
if (mListener != null) {
mListener.onDescriptorWrite(gatt, descriptor, status);
}
}
};
......@@ -318,7 +313,9 @@ public class BleManagerUtil {
// ②「接続可能範囲から外れた切断」は、内部処理でmBluetoothGatt.disconnect()処理が実施される。
// 切断時のコールバックでmBluetoothGatt.connect()を呼んでおくと、接続可能範囲に入ったら自動接続する。
mBluetoothGatt.disconnect();
mBluetoothGatt.close();
mBluetoothGatt = null;
mListener = null;
}
......@@ -435,6 +432,13 @@ public class BleManagerUtil {
return true;
}
public BluetoothGatt getBluetoothGatt() {
return mBluetoothGatt;
}
public void setBluetoothGatt(BluetoothGatt gatt) {
mBluetoothGatt = gatt;
}
/**
* リスナー設定
* @param listener リスナー
......
......@@ -11,7 +11,7 @@ public interface BleManagerUtilListener {
void onDisConnectionState(); // ディバイスと切断時
void onConnectionError(int status); // ディバイス接続エラー
// アルコールチェッカーで追加
void onServicesDiscovered(int status);
void onServicesDiscovered(BluetoothGatt gatt, int status);
void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic);
void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status);
}
......@@ -3,17 +3,12 @@ package jp.agentec.abook.abv.ui.home.activity;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanResult;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
......@@ -24,7 +19,6 @@ import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -32,10 +26,8 @@ import java.util.List;
import jp.agentec.abook.abv.bl.common.Constant;
import jp.agentec.abook.abv.bl.common.Constant.DeviceType;
import jp.agentec.abook.abv.bl.common.constant.ABookKeys;
import jp.agentec.abook.abv.bl.common.log.Logger;
import jp.agentec.abook.abv.bl.dto.BluetoothPairingDeviceInfoDto;
import jp.agentec.abook.abv.cl.util.AlcoholCheckerUtil;
import jp.agentec.abook.abv.cl.util.BleManagerUtil;
import jp.agentec.abook.abv.launcher.android.R;
import jp.agentec.abook.abv.ui.common.activity.ABVUIActivity;
......@@ -45,8 +37,6 @@ import jp.agentec.abook.abv.ui.home.adapter.common.SectionHeaderData;
import jp.agentec.abook.abv.ui.home.helper.ABookPermissionHelper;
import jp.agentec.adf.util.CollectionUtil;
import static android.bluetooth.BluetoothDevice.TRANSPORT_LE;
public class BlePairingSettingActivity extends ABVUIActivity {
private static final String TAG = "BlePairingSettingActivity";
......@@ -160,6 +150,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
Logger.d(TAG, "position = " + position);
stopScan();
BleListRowData bleListRowData = (BleListRowData)parent.getItemAtPosition(position);
// 既に保存されてる場合は何もしない
if (!bleListRowData.isSaved) {
......@@ -239,7 +230,7 @@ public class BlePairingSettingActivity extends ABVUIActivity {
//端末側の位置情報許可チェック
if (!(gpsEnabled || secureLocationGpsEnabled)) {
//showSimpleAlertDialog(R.string.chino_machine, R.string.msg_location_device_no_allow);
showSimpleAlertDialog(R.string.alcohol_checker, R.string.msg_location_device_no_allow);
return;
}
......@@ -429,29 +420,8 @@ public class BlePairingSettingActivity extends ABVUIActivity {
return false;
}
////////////////////////////////////////////////////////////////////////
private BluetoothGatt bluetoothGatt = null;
private BluetoothAdapter bluetoothAdapter = null;
@Override
protected void onDestroy() {
super.onDestroy();
//unregisterReceiver(PairingRequest);
if(bluetoothGatt != null) {
bluetoothGatt.close();
bluetoothGatt = null;
}
}
BroadcastReceiver PairingRequest = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
Logger.d(TAG,"PEAR");
}
}
};
//private BluetoothDevice device = null;
private void PairingDevice(String deviceAddress) {
BluetoothManager bleMgr = (BluetoothManager) this.getSystemService( Context.BLUETOOTH_SERVICE );
......@@ -462,39 +432,6 @@ public class BlePairingSettingActivity extends ABVUIActivity {
}
}
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(deviceAddress);
//bluetoothGatt = device.connectGatt(this, false, gattcallback, TRANSPORT_LE);
device.createBond();
//IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
//registerReceiver(PairingRequest, filter);
}
private final BluetoothGattCallback gattcallback = new BluetoothGattCallback() {
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
if (newState == BluetoothProfile.STATE_CONNECTED) {
//
Logger.d(TAG, "STATE_CONNECTED");
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
//
Logger.d(TAG, "STATE_DISCONNECTED");
if (bluetoothGatt != null) {
bluetoothGatt.close();
bluetoothGatt = null;
}
}
}
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
super.onServicesDiscovered(gatt, status);
if (status == BluetoothGatt.GATT_SUCCESS) {
bluetoothGatt = gatt;
Logger.d(TAG,"BluetoothGatt.GATT_SUCCESS");
}
}
};
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment