Skip to content

Commit

Permalink
Double check for listeners nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
a.wieckowski committed Sep 5, 2018
1 parent db1df73 commit 50aebe2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ private synchronized void connected(BluetoothSocket socket, final BluetoothDevic
@RequiresPermission(Manifest.permission.BLUETOOTH)
@Override
public void run() {
onEventCallback.onDeviceName(device.getName());
if (onEventCallback != null)
onEventCallback.onDeviceName(device.getName());
}

});
Expand Down Expand Up @@ -193,7 +194,8 @@ private void connectionFailed() {
runOnMainThread(new Runnable() {
@Override
public void run() {
onEventCallback.onToast("Could not connect to device");
if (onEventCallback != null)
onEventCallback.onToast("Could not connect to device");
}
});
}
Expand All @@ -210,7 +212,8 @@ private void connectionLost() {
runOnMainThread(new Runnable() {
@Override
public void run() {
onEventCallback.onToast("Connection lost");
if (onEventCallback != null)
onEventCallback.onToast("Connection lost");
}
});
}
Expand Down Expand Up @@ -365,7 +368,8 @@ private void dispatchBuffer(byte[] buffer, int i) {
runOnMainThread(new Runnable() {
@Override
public void run() {
onEventCallback.onDataRead(data, data.length);
if (onEventCallback != null)
onEventCallback.onDataRead(data, data.length);
}
});
}
Expand All @@ -385,7 +389,8 @@ public void write(final byte[] buffer) {
runOnMainThread(new Runnable() {
@Override
public void run() {
onEventCallback.onDataWrite(buffer);
if (onEventCallback != null)
onEventCallback.onDataWrite(buffer);
}
});
} catch (Exception e) {
Expand Down Expand Up @@ -433,7 +438,8 @@ public void onReceive(Context context, Intent intent) {
runOnMainThread(new Runnable() {
@Override
public void run() {
onScanCallback.onDeviceDiscovered(device, RSSI);
if (onScanCallback != null)
onScanCallback.onDeviceDiscovered(device, RSSI);
}
});
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
Expand All @@ -449,7 +455,8 @@ public void startScan() {
runOnMainThread(new Runnable() {
@Override
public void run() {
onScanCallback.onStartScan();
if (onScanCallback != null)
onScanCallback.onStartScan();
}
});

Expand Down Expand Up @@ -485,7 +492,8 @@ public void stopScan() {
runOnMainThread(new Runnable() {
@Override
public void run() {
onScanCallback.onStopScan();
if (onScanCallback != null)
onScanCallback.onStopScan();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ protected synchronized void updateState(final BluetoothStatus status) {
runOnMainThread(new Runnable() {
@Override
public void run() {
onEventCallback.onStatusChange(status);
if (onEventCallback != null)
onEventCallback.onStatusChange(status);
}
});
}
Expand Down

0 comments on commit 50aebe2

Please sign in to comment.