public class ConnectManager extends java.lang.Object implements BTConnectThread.Listener, WifiConnectHelper.ConnectListener, LocationHelper.LocationApplyListener
Modifier and Type | Class and Description |
---|---|
static class |
ConnectManager.ALERT |
static interface |
ConnectManager.Listener |
static class |
ConnectManager.PARING |
static class |
ConnectManager.STATE |
static class |
ConnectManager.STATUS |
static class |
ConnectManager.STEP |
Modifier and Type | Field and Description |
---|---|
private BTConnectHelper |
mBTConnectHelper |
private android.bluetooth.BluetoothDevice |
mConnectedBluetoothDevice |
private ConnectHelper |
mConnectHelper |
private android.content.Context |
mContext |
private ConnectManager.STEP |
mCurrentStep |
private static ConnectManager |
mInstance |
private ConnectManager.Listener |
mListener |
private LocationHelper |
mLocationHelper |
private StoreDataHelper |
mSDH |
private WifiStatusItem |
mTargetWifiP2pDevice |
private WifiConnectHelper |
mWifiConnectHelper |
Modifier | Constructor and Description |
---|---|
private |
ConnectManager(android.content.Context context) |
Modifier and Type | Method and Description |
---|---|
void |
completedConnectBluetooth(android.bluetooth.BluetoothSocket socket,
boolean success) |
void |
completedConnectP2p(android.net.wifi.p2p.WifiP2pInfo info)
wifi p2p connected then this function will be called.
|
void |
disconnect()
disconnect() make unregister about bluetooth, wifi p2p, location service and disconnect bluetooth, wifi p2p
|
void |
disconnectBluetooth(android.bluetooth.BluetoothDevice device,
int tryCnt,
int maxCnt) |
void |
disconnectP2p(boolean forceClose,
int p2pState,
android.net.wifi.p2p.WifiP2pInfo info,
java.lang.String targetWifiP2pName)
wifi p2p disconnected then this function will be called.
|
void |
discoveryP2pTryCnt(int p2pState,
int tryCnt)
this is not normal function because wifi p2p discovery no need to call several times. but sometimes cannot find neckbands's wifi p2p ssid
because neckband's wifi p2p can not recognize to disconnected opponent device sometimes.
|
static ConnectManager |
getInstance(android.content.Context context) |
private boolean |
isConnected() |
private boolean |
isDisconnected() |
private boolean |
isTryToConnecting() |
void |
locationState(int state) |
void |
readyP2pConnect(WifiStatusItem item)
after connected bluetooth, it will get wifi p2p ssid from bluetooth socket to connect wifi p2p automatically
|
ConnectManager |
setListener(ConnectManager.Listener listener) |
void |
start(java.lang.String selectedBTAddress,
android.bluetooth.BluetoothDevice device) |
private void |
startConnect() |
void |
tryReconnectBluetooth(android.bluetooth.BluetoothSocket socket,
int cnt) |
private static ConnectManager mInstance
private android.content.Context mContext
private ConnectManager.Listener mListener
private StoreDataHelper mSDH
private ConnectHelper mConnectHelper
private WifiConnectHelper mWifiConnectHelper
private BTConnectHelper mBTConnectHelper
private android.bluetooth.BluetoothDevice mConnectedBluetoothDevice
private WifiStatusItem mTargetWifiP2pDevice
private LocationHelper mLocationHelper
private ConnectManager.STEP mCurrentStep
public static ConnectManager getInstance(android.content.Context context)
context
- this context have to be applicationContext because bluetooth, wifi, location service used broadcast receiver if you used activity's context,
broadcast receiver will be make error in register receiver or unregister receiverpublic ConnectManager setListener(ConnectManager.Listener listener)
listener
- this listener will get all event about bluetooth, wifi p2p, location servicepublic void start(java.lang.String selectedBTAddress, android.bluetooth.BluetoothDevice device)
selectedBTAddress
- if you cached bluetooth address already, you need not show bluetooth device list.
search and connect will be trigger with bluetooth address.device
- if you clicked bluetooth device from list, you need not find again so just connectpublic void disconnect()
private void startConnect()
private boolean isTryToConnecting()
private boolean isConnected()
private boolean isDisconnected()
public void locationState(int state)
locationState
in interface LocationHelper.LocationApplyListener
public void completedConnectBluetooth(android.bluetooth.BluetoothSocket socket, boolean success)
completedConnectBluetooth
in interface BTConnectThread.Listener
socket
- connected bluetooth socket. it can be null.success
- if success is false, bluetooth socket is null.public void tryReconnectBluetooth(android.bluetooth.BluetoothSocket socket, int cnt)
tryReconnectBluetooth
in interface BTConnectThread.Listener
socket
- reconnected bluetooth socketcnt
- reconnect count, you can make disconnect bluetooth with this.public void disconnectBluetooth(android.bluetooth.BluetoothDevice device, int tryCnt, int maxCnt)
disconnectBluetooth
in interface BTConnectThread.Listener
device
- disconnected bluetooth devicetryCnt
- reconnected countmaxCnt
- reconnect max count, and if tryCnt is not reached maxCnt, it means that force closed.public void readyP2pConnect(WifiStatusItem item)
BTConnectThread.Listener
readyP2pConnect
in interface BTConnectThread.Listener
item
- WifiStatusItem has wifi p2p informationpublic void completedConnectP2p(android.net.wifi.p2p.WifiP2pInfo info)
WifiConnectHelper.ConnectListener
completedConnectP2p
in interface WifiConnectHelper.ConnectListener
info
- wifi p2p informationpublic void discoveryP2pTryCnt(int p2pState, int tryCnt)
WifiConnectHelper.ConnectListener
discoveryP2pTryCnt
in interface WifiConnectHelper.ConnectListener
p2pState
- this parameter has WifiP2pManager.WIFI_P2P_STATE_DISABLED, WifiP2pManager.WIFI_P2P_STATE_ENABLED value.tryCnt
- actually this is start and stop count.public void disconnectP2p(boolean forceClose, int p2pState, android.net.wifi.p2p.WifiP2pInfo info, java.lang.String targetWifiP2pName)
WifiConnectHelper.ConnectListener
disconnectP2p
in interface WifiConnectHelper.ConnectListener
forceClose
- if disconnected by connection changed or retry discovery p2p, this parameter has false and reconnect again. but forceClose is true then
cannot start reconnect.p2pState
- this parameter has WifiP2pManager.WIFI_P2P_STATE_DISABLED, WifiP2pManager.WIFI_P2P_STATE_ENABLED value.info
- wifi p2p informationtargetWifiP2pName
- discovery target wifi p2p ssid