-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from robholmes/observable-bond-state
Added bond state observable
- Loading branch information
Showing
3 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
rxbluetooth/src/main/java/com/github/ivbaranov/rxbluetooth/BondStateEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (C) 2015 Ivan Baranov | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.ivbaranov.rxbluetooth; | ||
|
||
import android.bluetooth.BluetoothDevice; | ||
|
||
/** | ||
* Event container class. Contains bond state (whether the device is unbonded, bonding, or bonded), | ||
* previous bond state, and {@link BluetoothDevice}. | ||
* | ||
* Possible state values are: | ||
* {@link BluetoothDevice#BOND_NONE}, | ||
* {@link BluetoothDevice#BOND_BONDING}, | ||
* {@link BluetoothDevice#BOND_BONDED} | ||
*/ | ||
public class BondStateEvent { | ||
|
||
private int mState; | ||
private int mPreviousState; | ||
private BluetoothDevice mBluetoothDevice; | ||
|
||
public BondStateEvent(int state, int previousState, BluetoothDevice bluetoothDevice) { | ||
mState = state; | ||
mPreviousState = previousState; | ||
mBluetoothDevice = bluetoothDevice; | ||
} | ||
|
||
public int getState() { | ||
return mState; | ||
} | ||
|
||
public int getPreviousState() { | ||
return mState; | ||
} | ||
|
||
public BluetoothDevice getBluetoothDevice() { | ||
return mBluetoothDevice; | ||
} | ||
|
||
@Override public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
BondStateEvent that = (BondStateEvent) o; | ||
|
||
if (mState != that.mState) return false; | ||
if (mPreviousState != that.mPreviousState) return false; | ||
return !(mBluetoothDevice != null ? !mBluetoothDevice.equals(that.mBluetoothDevice) | ||
: that.mBluetoothDevice != null); | ||
} | ||
|
||
@Override public int hashCode() { | ||
int result = mState; | ||
result = 31 * result + mPreviousState; | ||
result = 31 * result + (mBluetoothDevice != null ? mBluetoothDevice.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override public String toString() { | ||
return "BondStateEvent{" + | ||
"mState=" + mState + | ||
", mPreviousState=" + mPreviousState + | ||
", mBluetoothDevice=" + mBluetoothDevice + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters