Skip to content

Commit

Permalink
Code cleanup. Get rid of Hungarian notation.
Browse files Browse the repository at this point in the history
  • Loading branch information
IvBaranov committed Dec 7, 2017
1 parent efe8c09 commit 3006379
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class BluetoothConnection {
private InputStream inputStream;
private OutputStream outputStream;

private Flowable<Byte> mObserveInputStream;
private Flowable<Byte> observeInputStream;

private boolean connected = false;

Expand Down Expand Up @@ -77,8 +77,8 @@ public BluetoothConnection(BluetoothSocket socket) throws Exception {
* @return RxJava Observable with {@link Byte}
*/
public Flowable<Byte> observeByteStream() {
if (mObserveInputStream == null) {
mObserveInputStream = Flowable.create(new FlowableOnSubscribe<Byte>() {
if (observeInputStream == null) {
observeInputStream = Flowable.create(new FlowableOnSubscribe<Byte>() {
@Override public void subscribe(final FlowableEmitter<Byte> subscriber) {
while (!subscriber.isCancelled()) {
try {
Expand All @@ -96,7 +96,7 @@ public Flowable<Byte> observeByteStream() {
}, BackpressureStrategy.BUFFER).share();
}

return mObserveInputStream;
return observeInputStream;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@
* Enables clients to listen to bluetooth events using RxJava Observables.
*/
public class RxBluetooth {
private BluetoothAdapter mBluetoothAdapter;
private BluetoothAdapter bluetoothAdapter;
private Context context;

public RxBluetooth(Context context) {
this.mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
this.bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
this.context = context;
}

/**
* Return true if Bluetooth is available.
*
* @return true if mBluetoothAdapter is not null or it's address is empty, otherwise Bluetooth is
* @return true if bluetoothAdapter is not null or it's address is empty, otherwise Bluetooth is
* not supported on this hardware platform
*/
public boolean isBluetoothAvailable() {
return !(mBluetoothAdapter == null || TextUtils.isEmpty(mBluetoothAdapter.getAddress()));
return !(bluetoothAdapter == null || TextUtils.isEmpty(bluetoothAdapter.getAddress()));
}

/**
Expand All @@ -73,7 +73,7 @@ public boolean isBluetoothAvailable() {
* @return true if the local adapter is turned on
*/
public boolean isBluetoothEnabled() {
return mBluetoothAdapter.isEnabled();
return bluetoothAdapter.isEnabled();
}

/**
Expand All @@ -84,7 +84,7 @@ public boolean isBluetoothEnabled() {
* @param requestCode request code
*/
public void enableBluetooth(Activity activity, int requestCode) {
if (!mBluetoothAdapter.isEnabled()) {
if (!bluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
activity.startActivityForResult(enableBtIntent, requestCode);
}
Expand All @@ -99,7 +99,7 @@ public void enableBluetooth(Activity activity, int requestCode) {
* @see BluetoothAdapter#enable()
*/
public boolean enable() {
return mBluetoothAdapter.enable();
return bluetoothAdapter.enable();
}

/**
Expand All @@ -111,7 +111,7 @@ public boolean enable() {
* @see BluetoothAdapter#enable()
*/
public boolean disable() {
return mBluetoothAdapter.disable();
return bluetoothAdapter.disable();
}

/**
Expand All @@ -126,7 +126,7 @@ public boolean disable() {
* @return unmodifiable set of {@link BluetoothDevice}, or null on error
*/
public Set<BluetoothDevice> getBondedDevices() {
return mBluetoothAdapter.getBondedDevices();
return bluetoothAdapter.getBondedDevices();
}

/**
Expand All @@ -135,7 +135,7 @@ public Set<BluetoothDevice> getBondedDevices() {
* @return true on success, false on error
*/
public boolean startDiscovery() {
return mBluetoothAdapter.startDiscovery();
return bluetoothAdapter.startDiscovery();
}

/**
Expand All @@ -145,7 +145,7 @@ public boolean startDiscovery() {
* @return true if discovering
*/
public boolean isDiscovering() {
return mBluetoothAdapter.isDiscovering();
return bluetoothAdapter.isDiscovering();
}

/**
Expand All @@ -154,7 +154,7 @@ public boolean isDiscovering() {
* @return true on success, false on error
*/
public boolean cancelDiscovery() {
return mBluetoothAdapter.cancelDiscovery();
return bluetoothAdapter.cancelDiscovery();
}

/**
Expand Down Expand Up @@ -277,7 +277,7 @@ public Observable<Integer> observeBluetoothState() {
throws Exception {
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
emitter.onNext(mBluetoothAdapter.getState());
emitter.onNext(bluetoothAdapter.getState());
}
};

Expand Down Expand Up @@ -314,7 +314,7 @@ public Observable<Integer> observeScanMode() {
throws Exception {
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override public void onReceive(Context context, Intent intent) {
emitter.onNext(mBluetoothAdapter.getScanMode());
emitter.onNext(bluetoothAdapter.getScanMode());
}
};

Expand Down Expand Up @@ -346,7 +346,7 @@ public Observable<ServiceEvent> observeBluetoothProfile(final int bluetoothProfi
return Observable.create(new ObservableOnSubscribe<ServiceEvent>() {
@Override public void subscribe(@NonNull final ObservableEmitter<ServiceEvent> emitter)
throws Exception {
if (!mBluetoothAdapter.getProfileProxy(context, new BluetoothProfile.ServiceListener() {
if (!bluetoothAdapter.getProfileProxy(context, new BluetoothProfile.ServiceListener() {
@Override public void onServiceConnected(int profile, BluetoothProfile proxy) {
emitter.onNext(new ServiceEvent(ServiceEvent.State.CONNECTED, profile, proxy));
}
Expand Down Expand Up @@ -376,7 +376,7 @@ public Observable<ServiceEvent> observeBluetoothProfile(final int bluetoothProfi
* @param proxy profile proxy object
*/
public void closeProfileProxy(int profile, BluetoothProfile proxy) {
mBluetoothAdapter.closeProfileProxy(profile, proxy);
bluetoothAdapter.closeProfileProxy(profile, proxy);
}

/**
Expand Down Expand Up @@ -478,7 +478,7 @@ public Observable<BluetoothSocket> observeBluetoothSocket(final String name, fin
throws Exception {
try {
BluetoothServerSocket bluetoothServerSocket =
mBluetoothAdapter.listenUsingRfcommWithServiceRecord(name, uuid);
bluetoothAdapter.listenUsingRfcommWithServiceRecord(name, uuid);
emitter.onNext(bluetoothServerSocket.accept());
bluetoothServerSocket.close();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@
*/
public class AclEvent {

private String mAction;
private BluetoothDevice mBluetoothDevice;
private String action;
private BluetoothDevice bluetoothDevice;

public AclEvent(String action, BluetoothDevice bluetoothDevice) {
mAction = action;
mBluetoothDevice = bluetoothDevice;
this.action = action;
this.bluetoothDevice = bluetoothDevice;
}

public String getAction() {
return mAction;
return action;
}

public BluetoothDevice getBluetoothDevice() {
return mBluetoothDevice;
return bluetoothDevice;
}

@Override public boolean equals(Object o) {
Expand All @@ -49,21 +49,21 @@ public BluetoothDevice getBluetoothDevice() {

AclEvent that = (AclEvent) o;

if (mAction != null && !mAction.equals(that.mAction)) return false;
return !(mBluetoothDevice != null ? !mBluetoothDevice.equals(that.mBluetoothDevice)
: that.mBluetoothDevice != null);
if (action != null && !action.equals(that.action)) return false;
return !(bluetoothDevice != null ? !bluetoothDevice.equals(that.bluetoothDevice)
: that.bluetoothDevice != null);
}

@Override public int hashCode() {
int result = mAction != null ? mAction.hashCode() : 0;
result = 31 * result + (mBluetoothDevice != null ? mBluetoothDevice.hashCode() : 0);
int result = action != null ? action.hashCode() : 0;
result = 31 * result + (bluetoothDevice != null ? bluetoothDevice.hashCode() : 0);
return result;
}

@Override public String toString() {
return "AclEvent{" +
"mAction=" + mAction +
", mBluetoothDevice=" + mBluetoothDevice +
"action=" + action +
", bluetoothDevice=" + bluetoothDevice +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.ivbaranov.rxbluetooth.events;
package com.github.ivbaranov.rxbluetooth.events;

import android.bluetooth.BluetoothDevice;

Expand All @@ -28,26 +28,26 @@
*/
public class BondStateEvent {

private int mState;
private int mPreviousState;
private BluetoothDevice mBluetoothDevice;
private int state;
private int previousState;
private BluetoothDevice bluetoothDevice;

public BondStateEvent(int state, int previousState, BluetoothDevice bluetoothDevice) {
mState = state;
mPreviousState = previousState;
mBluetoothDevice = bluetoothDevice;
this.state = state;
this.previousState = previousState;
this.bluetoothDevice = bluetoothDevice;
}

public int getState() {
return mState;
return state;
}

public int getPreviousState() {
return mPreviousState;
return previousState;
}

public BluetoothDevice getBluetoothDevice() {
return mBluetoothDevice;
return bluetoothDevice;
}

@Override public boolean equals(Object o) {
Expand All @@ -56,24 +56,24 @@ public BluetoothDevice getBluetoothDevice() {

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);
if (state != that.state) return false;
if (previousState != that.previousState) return false;
return !(bluetoothDevice != null ? !bluetoothDevice.equals(that.bluetoothDevice)
: that.bluetoothDevice != null);
}

@Override public int hashCode() {
int result = mState;
result = 31 * result + mPreviousState;
result = 31 * result + (mBluetoothDevice != null ? mBluetoothDevice.hashCode() : 0);
int result = state;
result = 31 * result + previousState;
result = 31 * result + (bluetoothDevice != null ? bluetoothDevice.hashCode() : 0);
return result;
}

@Override public String toString() {
return "BondStateEvent{" +
"mState=" + mState +
", mPreviousState=" + mPreviousState +
", mBluetoothDevice=" + mBluetoothDevice +
"state=" + state +
", previousState=" + previousState +
", bluetoothDevice=" + bluetoothDevice +
'}';
}
}
Loading

0 comments on commit 3006379

Please sign in to comment.