Skip to content

Commit

Permalink
Update method name
Browse files Browse the repository at this point in the history
  • Loading branch information
whilu committed Jan 19, 2016
1 parent 3b0f47e commit dd3ab16
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ public class BluetoothManager implements BaseManager {

private BluetoothAdapter mBluetoothAdapter;
private BluetoothListener mBluetoothListener;
private BluetoothService mBluetoothService;
private BlueToothReceiver mReceiver;
private Context mContext;
private BluetoothService mBluetoothService;

private static BluetoothManager sBluetoothManager;

private static final String TAG = "BluetoothManager";

public static BluetoothManager getInstance(){
if (sBluetoothManager == null){
synchronized (BluetoothManager.class){
Expand All @@ -79,7 +77,7 @@ public BluetoothManager build(Context context){
}

/**
* Set bluetooth listener, you can check all bluetooth status with this listener's callback.
* Set bluetooth listener, you can check all bluetooth status and read data with this listener's callback.
* @param listener
*/
public void setBluetoothListener(BluetoothListener listener){
Expand Down Expand Up @@ -120,18 +118,15 @@ public boolean isEnabled(){
}

@Override
public void onOpenBluetooth(){
public void openBluetooth(){
if (!isAvaliable()){
return;
}
// Intent intent = new Intent();
// intent.setAction(BluetoothAdapter.ACTION_REQUEST_ENABLE);
// startActivityForResult(intent, REQUEST_ENABLE_BT);
mBluetoothAdapter.enable();
}

@Override
public void onCloseBluetooth(){
public void closeBluetooth(){
if (!isAvaliable() && !isEnabled()){
return;
}
Expand All @@ -150,15 +145,15 @@ public boolean setDiscoverable(int time){
}

@Override
public boolean startDiscovery() {
public boolean startScan() {
if (!isAvaliable() && !isEnabled()){
return false;
}
return mBluetoothAdapter.startDiscovery();
}

@Override
public boolean cancelDiscovery() {
public boolean cancelScan() {
if (!isAvaliable() && !isEnabled()){
return false;
}
Expand All @@ -182,7 +177,7 @@ public BluetoothDevice findDeviceByMac(String mac){
}

@Override
public void onStartAsServer() {
public void startAsServer() {
if (mBluetoothService != null){
mBluetoothService.start();
}
Expand All @@ -202,7 +197,14 @@ public void connect(String mac){
}

@Override
public void onWrite(byte[] data) {
public void disconnect() {
if (mBluetoothService != null){
mBluetoothService.stop();
}
}

@Override
public void write(byte[] data) {
if (mBluetoothService != null){
mBluetoothService.write(data);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/*
* The MIT License (MIT)
* Copyright (c) 2015 LinkMob.cc
* Contributors: lujun
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package co.lujun.lmbluetoothsdk.base;

import android.bluetooth.BluetoothDevice;
Expand Down Expand Up @@ -25,31 +51,31 @@ public interface BaseManager {
/**
* Open bluetooth.
*/
void onOpenBluetooth();
void openBluetooth();

/**
* Close bluetooth.
*/
void onCloseBluetooth();
void closeBluetooth();

/**
* Set bluetooth discoverable with specified time.
* Set bluetooth discoverable with specified time(unit s).
* @param time
* @return
*/
boolean setDiscoverable(int time);

/**
* Start discovery.
* Start scan.
* @return
*/
boolean startDiscovery();
boolean startScan();

/**
* Cancel discovery.
* Cancel scan.
* @return
*/
boolean cancelDiscovery();
boolean cancelScan();

/**
* Get paired devices.
Expand All @@ -67,17 +93,22 @@ public interface BaseManager {
/**
* Start as a server.
*/
void onStartAsServer();
void startAsServer();

/**
* Connected a bluetooth device by mac address.
* @param mac
*/
void connect(String mac);

/**
* Disconnect connection.
*/
void disconnect();

/**
* Write data to remote device.
* @param data
*/
void onWrite(byte[] data);
void write(byte[] data);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/*
* The MIT License (MIT)
* Copyright (c) 2015 LinkMob.cc
* Contributors: lujun
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package co.lujun.lmbluetoothsdk.base;

import android.bluetooth.BluetoothDevice;
Expand All @@ -10,8 +36,8 @@ public interface BluetoothListener {

void onActionStateChanged(int preState, int state);
void onActionDiscoveryStateChanged(String discoveryState);
void onActionFound(BluetoothDevice device);
void onActionScanModeChanged(int preScanMode, int scanMode);
void onBluetoothServiceStateChanged(int state);
void onActionDeviceFound(BluetoothDevice device);
void onReadData(byte[] data);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
/*
* The MIT License (MIT)
* Copyright (c) 2015 LinkMob.cc
* Contributors: lujun
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package co.lujun.lmbluetoothsdk.receiver;

import android.bluetooth.BluetoothAdapter;
Expand Down
Loading

0 comments on commit dd3ab16

Please sign in to comment.